srs5694 | 3860cbe | 2011-09-10 20:29:53 -0400 | [diff] [blame] | 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 | |
Roderick W. Smith | 1eea9b0 | 2013-07-06 22:52:58 -0400 | [diff] [blame] | 23 | #include <string.h> |
srs5694 | 3860cbe | 2011-09-10 20:29:53 -0400 | [diff] [blame] | 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 = ""; |
Roderick W. Smith | 1eea9b0 | 2013-07-06 22:52:58 -0400 | [diff] [blame] | 32 | int displayType = USE_CURSES; |
srs5694 | 3860cbe | 2011-09-10 20:29:53 -0400 | [diff] [blame] | 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 |
Roderick W. Smith | 1eea9b0 | 2013-07-06 22:52:58 -0400 | [diff] [blame] | 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; |
srs5694 | 3860cbe | 2011-09-10 20:29:53 -0400 | [diff] [blame] | 57 | break; |
| 58 | default: |
Roderick W. Smith | 1eea9b0 | 2013-07-06 22:52:58 -0400 | [diff] [blame] | 59 | cerr << "Usage: " << argv[0] << " [-a] device_file\n"; |
srs5694 | 3860cbe | 2011-09-10 20:29:53 -0400 | [diff] [blame] | 60 | exit(1); |
| 61 | break; |
| 62 | } // switch |
| 63 | |
| 64 | GPTDataCurses theGPT; |
| 65 | |
Roderick W. Smith | 1eea9b0 | 2013-07-06 22:52:58 -0400 | [diff] [blame] | 66 | theGPT.SetDisplayType(displayType); |
srs5694 | 3860cbe | 2011-09-10 20:29:53 -0400 | [diff] [blame] | 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 |
Roderick W. Smith | 84aaff6 | 2014-02-17 16:17:11 -0500 | [diff] [blame] | 78 | return 0; |
srs5694 | 3860cbe | 2011-09-10 20:29:53 -0400 | [diff] [blame] | 79 | } // main |