-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
64 lines (57 loc) · 2.21 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "Main_Window.h"
#include "Settings_Profile_Manager.h"
#include "Corruptor.h"
#include <QFileInfo>
#include <QFile>
#include <QApplication>
#include <iostream>
#include <assert.h>
int main(int argc, char *argv[]) {
if (argc == 1) { //GUI mode
QApplication a(argc, argv);
Settings settings;
QString defaultSettingsPath = QApplication::applicationDirPath()+"/Profiles/Default.rps";
QFile file(defaultSettingsPath);
bool loaded = false;
if (file.exists()) {
Settings_Profile_Manager manager(NULL, QApplication::applicationDirPath());
int ret = manager.Read_Settings(&settings, defaultSettingsPath);
if (ret == 0) {
loaded = true;
} else {
file.remove(); //delete the default settings file if it is invalid
}
}
Main_Window w(&settings, loaded, NULL);
w.show();
return a.exec();
} else if (argc == 4) { //CLI mode
QApplication a(argc, argv);
Settings settings;
Settings_Profile_Manager manager(NULL, QApplication::applicationDirPath());
//Try to load from the main profiles path first
QString settingsPath = QApplication::applicationDirPath()+"/Profiles/"+argv[3];
int ret = manager.Read_Settings(&settings, settingsPath);
if (ret == 2) {
settingsPath = QString(argv[3]);
ret = manager.Read_Settings(&settings, settingsPath);
}
if (ret != 0) {
std::cerr << "Unable to load settings profile " << argv[3] << "!" << std::endl;
return 5;
}
Corruptor corruptor(NULL, &settings, argv[1], argv[2]);
ret = corruptor.Run();
corruptor.Show_Message(ret);
if (settings.increment) {
if (manager.Save_Settings(&settings, settingsPath) != 0) {
std::cerr << "Unable to save settings!" << std::endl;
return 6;
}
}
return ret;
}
//Improper number of command line arguments
std::cout << "ROM_Poison <original file> <save location> <ROM Poison Settings File>" << std::endl;
return 7;
}