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