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