blob: f21f04630bd21d2f91ee6baa7c0aff5c00029bae [file] [log] [blame]
srs56943860cbe2011-09-10 20:29:53 -04001/*
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. Smith1eea9b02013-07-06 22:52:58 -040023#include <string.h>
srs56943860cbe2011-09-10 20:29:53 -040024#include "gptcurses.h"
25
26using namespace std;
27
28#define MAX_OPTIONS 50
29
30int main(int argc, char *argv[]) {
31 string device = "";
Roderick W. Smith1eea9b02013-07-06 22:52:58 -040032 int displayType = USE_CURSES;
srs56943860cbe2011-09-10 20:29:53 -040033
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. Smith1eea9b02013-07-06 22:52:58 -040045 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;
srs56943860cbe2011-09-10 20:29:53 -040057 break;
58 default:
Roderick W. Smith1eea9b02013-07-06 22:52:58 -040059 cerr << "Usage: " << argv[0] << " [-a] device_file\n";
srs56943860cbe2011-09-10 20:29:53 -040060 exit(1);
61 break;
62 } // switch
63
64 GPTDataCurses theGPT;
65
Roderick W. Smith1eea9b02013-07-06 22:52:58 -040066 theGPT.SetDisplayType(displayType);
srs56943860cbe2011-09-10 20:29:53 -040067 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. Smith84aaff62014-02-17 16:17:11 -050078 return 0;
srs56943860cbe2011-09-10 20:29:53 -040079} // main