-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
213 lines (184 loc) · 5.93 KB
/
main.cpp
File metadata and controls
213 lines (184 loc) · 5.93 KB
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*
Mod manager for Planetary Annihilation. Based of raevn's Windows-only version.
Copyright (C) 2013 DeathByDenim <jarno@jarno.ca>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QtGui/QApplication>
#include <QFile>
#include <QDir>
#include <QString>
#include <QStringList>
#include <QMessageBox>
#include <QTranslator>
#include <QLocale>
#include <QLibraryInfo>
#include <iostream>
#include <cstdlib>
#include "pamm.h"
#include "modmanager.h"
const char *strModInfoJson =
"{\n"
" \"context\": \"client\",\n"
" \"identifier\": \"com.pa.deathbydenim.dpamm\",\n"
" \"display_name\": \"PA Mod Manager UI Mods List\",\n"
" \"description\": \"Install and manage mods with ease. Based heavily on raevn's mod manager\",\n"
" \"forum\": \"https://forums.uberent.com/threads/rel-raevns-ui-mod-manager-for-linux-and-mac-os-x-version-1-8-1.50958/\",\n"
" \"author\": \"DeathByDenim\",\n"
" \"version\": \"" PAMM_VERSION "\",\n"
" \"date\": \"2014/01/21\",\n"
" \"build\": \"59607\",\n"
" \"signature\": \"not yet implemented\",\n"
" \"priority\": 1,\n"
" \"enabled\": true,\n"
" \"id\": \"PAMM\"\n"
"}\n";
QString findPAPath(QString configPath)
{
QString papath;
QString logdir = configPath + "/log";
QDir dir(logdir, "PA*.txt", QDir::NoSort, QDir::Files);
QStringList filelist = dir.entryList();
for(QStringList::const_iterator filename = filelist.begin(); filename != filelist.constEnd(); ++filename)
{
QFile logfile(logdir + "/" + *filename);
if(!logfile.open(QIODevice::ReadOnly | QIODevice::Text))
continue;
int pos;
while(!logfile.atEnd())
{
QString line = logfile.readLine();
pos = line.indexOf("INFO Coherent host dir");
if(pos != -1)
{ // What the?? Pos equals 1? Hmm, better use the C++ version instead...
papath = line.mid(line.toStdString().find_first_of("INFO Coherent host dir") + 26);
papath = papath.left(papath.size() - 6);
break;
}
}
}
return papath;
}
int main(int argc, char** argv)
{
QApplication app(argc, argv);
QString configPath = QDir::homePath();
#ifdef __APPLE__
configPath += "/Library/Application Support/Uber Entertainment/Planetary Annihilation/";
#else
configPath += "/.local/Uber Entertainment/Planetary Annihilation/";
#endif
// Where is this program installed?
QString progdir(argv[0]);
int pos = progdir.lastIndexOf(QRegExp("[/\\\\]"));
if(pos > 0)
{
progdir = progdir.left(pos);
}
else
progdir = ".";
// Where is PA installed? Check the log files first
QString paPath = findPAPath(configPath);
if(paPath.isEmpty())
{
// Not found in the log files, eh? Then assume the same dir as pamm.
paPath = progdir;
}
for(int i = 0; i < argc; i++)
{
if(QString(argv[i]).compare("--papath", Qt::CaseInsensitive) == 0 && i+1 < argc)
{
paPath = QString(argv[i+1]);
}
}
QString modPath = configPath + "/client_mods";
bool custommoddir = false;
for(int i = 0; i < argc; i++)
{
if(QString(argv[i]).compare("--modpath", Qt::CaseInsensitive) == 0 && i+1 < argc)
{
custommoddir = true;
modPath = QString(argv[i+1]);
break;
}
}
if(!custommoddir)
{
QDir(configPath).mkdir("client_mods");
QDir(configPath).mkdir("server_mods");
}
QString imgPath = progdir + "/img/";
#ifdef __APPLE__
if(!QFileInfo(imgPath).exists())
{
QDir imgDir(progdir);
imgDir.cd("../Resources");
imgPath = imgDir.canonicalPath() + '/';
}
#endif
QString i18nPath = progdir + "/i18n/";
#ifdef __APPLE__
if(!QFileInfo(i18nPath).exists())
{
QDir i18nDir(progdir);
i18nDir.cd("../Resources");
i18nPath = i18nDir.canonicalPath() + '/';
}
#endif
QLocale locale;
QString language = getenv("LANG");
if(language.length() > 0)
locale = QLocale(language);
else
{
language = QString(getenv("LANGUAGE")).split(':')[0];
if(language.length() > 0)
locale = QLocale(language);
}
std::cout << "Expecting configdir in: \"" << configPath.toStdString() << "\"." << std::endl;
std::cout << "Expecting executable in: \"" << paPath.toStdString() << "\"." << std::endl;
std::cout << "Expecting client moddir at: \"" << modPath.toStdString() << "\"." << std::endl;
std::cout << "Expecting locale dir at: \"" << i18nPath.toStdString() << "\"." << std::endl;
std::cout << "Locale: " << QLocale::languageToString(locale.language()).toStdString() << std::endl;
QTranslator translator_specific;
if(translator_specific.load(locale.name(), i18nPath))
QCoreApplication::installTranslator(&translator_specific);
QTranslator translator_qt;
if(translator_qt.load("qt_" + locale.name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
QCoreApplication::installTranslator(&translator_qt);
// Install the pamm mod.
QDir modDir(modPath);
modDir.mkdir("PAMM");
modDir.mkdir("PAMM/ui");
modDir.mkdir("PAMM/ui/client_mods");
QFile modinfojson(modPath + "/PAMM/modinfo.json");
if(modinfojson.open(QIODevice::WriteOnly | QIODevice::Text))
{
modinfojson.write(strModInfoJson);
modinfojson.close();
}
else
{
QMessageBox msgBox;
msgBox.setText("Couldn't write to \"" + modPath + "\"");
msgBox.setIcon(QMessageBox::Warning);
msgBox.exec();
}
ModManager manager(configPath, paPath, modPath, imgPath, locale);
manager.findInstalledMods();
manager.loadAvailableMods(false);
PAMM pamm(&manager, imgPath);
QIcon icon(imgPath + "/icon.png");
pamm.setWindowIcon(icon);
pamm.setWindowTitle("PA Mod Manager");
pamm.show();
return app.exec();
}