1 /* 2 Copyright (C) 2011 <Roderick W. Smith> 3 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation; either version 2 of the License, or 7 (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License along 15 with this program; if not, write to the Free Software Foundation, Inc., 16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 17 18 */ 19 20 /* This class implements an interactive curses-based interface atop the 21 GPTData class */ 22 23 #include <string.h> 24 #include "gptcurses.h" 25 26 using namespace std; 27 28 #define MAX_OPTIONS 50 29 30 int main(int argc, char *argv[]) { 31 string device = ""; 32 int displayType = USE_CURSES; 33 34 if (!SizesOK()) 35 exit(1); 36 37 switch (argc) { 38 case 1: 39 cout << "Type device filename, or press <Enter> to exit: "; 40 device = ReadString(); 41 if (device.length() == 0) 42 exit(0); 43 break; 44 case 2: // basic usage 45 device = (string) argv[1]; 46 break; 47 case 3: // "-a" usage or illegal 48 if (strcmp(argv[1], "-a") == 0) { 49 device = (string) argv[2]; 50 } else if (strcmp(argv[2], "-a") == 0) { 51 device = (string) argv[1]; 52 } else { 53 cerr << "Usage: " << argv[0] << " [-a] device_file\n"; 54 exit(1); 55 } // if/elseif/else 56 displayType = USE_ARROW; 57 break; 58 default: 59 cerr << "Usage: " << argv[0] << " [-a] device_file\n"; 60 exit(1); 61 break; 62 } // switch 63 64 GPTDataCurses theGPT; 65 66 theGPT.SetDisplayType(displayType); 67 if (theGPT.LoadPartitions(device)) { 68 if (theGPT.GetState() != use_gpt) { 69 Report("Warning! Non-GPT or damaged disk detected! This program will attempt to\n" 70 "convert to GPT form or repair damage to GPT data structures, but may not\n" 71 "succeed. Use gdisk or another disk repair tool if you have a damaged GPT\n" 72 "disk."); 73 } // if 74 theGPT.MainMenu(); 75 } else { 76 Report("Could not load partitions from '" + device + "'! Aborting!"); 77 } // if/else 78 return 0; 79 } // main 80