-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
154 lines (132 loc) · 3.9 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include "mainwindow.h"
#include <QApplication>
#include <QDir>
#include <QString>
bool checkConfigEntry(QString sKey, QString sDefault, Memory* objTargetMemory)
{
//Checks if config entry is set and use default value if not
QString sTestValue = objTargetMemory->getValue(sKey);
if(sTestValue == "")
{
objTargetMemory->setKeyValueEntry(sKey, sDefault);
return true;
}
return false;
}
bool checkConfigs()
{
QString sUserSettingsFilePath = "./Config/UserSettings.conf";
Config objConfigManager;
Memory* objUserSettingsMemory = 0x0;
try
{
objUserSettingsMemory = objConfigManager.loadConfig(sUserSettingsFilePath);
}
catch(...)
{
delete objUserSettingsMemory;
return false;
}
//Check config entrys
bool bCheckLT = checkConfigEntry("LinkText", "Link", objUserSettingsMemory);
bool bCheckPT = checkConfigEntry("ProjectTableName", "VideoEntrys", objUserSettingsMemory);
bool bCheckRLP = checkConfigEntry("RemenberLastParameters", "true", objUserSettingsMemory);
//Write out if modified
if
(bCheckLT || bCheckPT || bCheckRLP)
{
try
{
objConfigManager.saveConfig(sUserSettingsFilePath, objUserSettingsMemory);
}
catch(...)
{
delete objUserSettingsMemory;
return false;
}
}
delete objUserSettingsMemory;
return true;
}
bool setupDir(QString sDirName)
{
//Checks if the target folder exist and create it, if doesn't exist
QString sDirPath = "./" + sDirName;
QDir objTargetDir(sDirPath);
bool bTargetDirExist = objTargetDir.exists();
bool bCreateTargetDirSuccess = false;
if(bTargetDirExist != true)
{
objTargetDir = QDir::current();
bCreateTargetDirSuccess = objTargetDir.mkdir(sDirName);
return bCreateTargetDirSuccess;
}
return true;
}
bool setupFile(QString sDirName, QString sFileName)
{
//Checks if the target file exist and creates the file if not
QString sSystemFilePath;
QString sRessourcesFilePath;
if(sDirName == "")
{
sSystemFilePath = "./" + sFileName;
sRessourcesFilePath = ":/" + sFileName;
}
else
{
sSystemFilePath = "./" + sDirName + "/" + sFileName;
sRessourcesFilePath = ":/" + sDirName + "/" + sFileName;
}
QFile objTargetFile(sSystemFilePath);
//If the file doesn't exist, copy the file from the ressources to the target dir
if(objTargetFile.exists() != true)
{
QFile objDefaultTargetFile(sRessourcesFilePath);
bool bCopySuccess = objDefaultTargetFile.copy(sSystemFilePath);
return bCopySuccess;
}
return true;
}
bool setupPath()
{
//Setup files and folders
bool bSetupConfigDir = setupDir("Config");
bool bSetupTemplateDir = setupDir("Template");
bool bSetupUserSettingsFile = setupFile("Config", "UserSettings.conf");
bool bSetupTemplateFile = setupFile("Template", "Template.html");
//Return false if failed
if(!bSetupConfigDir || !bSetupTemplateDir || !bSetupTemplateFile || !bSetupUserSettingsFile)
{
return false;
}
else
{
return true;
}
}
void showStartError(QString sErrorMessage)
{
QErrorMessage objErrorMessage;
objErrorMessage.showMessage(sErrorMessage);
objErrorMessage.exec();
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
bool bSetupSuccess = setupPath(); //Check and create required dirs
if(bSetupSuccess != true)
{
showStartError("Programm kann nicht gestartet werden, da benötigte Dateien und Ordner nicht vorhanden sind und zudem auch nicht angelegt werden konnten!");
return 1;
}
bool bConfigTest = checkConfigs();
if(bConfigTest != true)
{
showStartError("Fehler beim Überprüfen der Config Dateien!");
return 1;
}
MainWindow w;
w.show();
return a.exec();
}