Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
220 lines (198 loc) · 5.65 KB
/
Copy pathmain.cpp
File metadata and controls
220 lines (198 loc) · 5.65 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
214
215
216
217
218
219
220
/*
csmapfx using fox-toolkit
build fox-toolkit on linux with:
$ ./configure --with-opengl=no --enable-release --enable-threadsafe --disable-shared
$ make
$ make install (as root)
on windows (vc++ toolkit 2003) for csmapfx and fox-toolkit,
add these "Command line" parameters to the compiler in "Release" mode:
/G7 /GL /O2 /Og /Ob2 /Oi /Op /Ot /Oy
(c) 2004-2006 Thomas J. Gritzan
*/
#define CSMAP_MAIN
#include "fxwin.h"
#include "version.h"
#include "fxhelper.h"
#include "translator.h"
#include "csmap.h"
#include "calc.h"
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <fx.h>
#ifdef HAVE_PHYSFS
#include <physfs.h>
#endif
#ifdef HAVE_CURL
#include <curl/curl.h>
#endif
void showHelpText()
{
std::ostringstream help;
help <<
CSMAP_APP_TITLE_VERSION
"\n " CSMAP_APP_COPYRIGHT
"\n"
"\n"
"Syntax: csmapfx [--help] [-hc] <Haupt-CR> <Karten-CRs> [-o <CR>]\n"
"\n"
"CsMapFX ist ein Kartenbetrachter f\u00fcr das Spiel Eressea (www.eressea.de).\n"
"Das Programm \u00f6ffnet Eressea-Computer-Reporte (*.cr).\n"
"\n"
"Optionen:\n"
" -h, --help Zeigt diesen Text an.\n"
" -v, --version Zeigt Versionsinformationen.\n"
" -c Startet ein kleines Fenster mit Taschenrechner.\n"
"Diese Optionen m\u00fcssen hinter einem CR stehen:\n"
" -o <Datei> Schreibt einen CR aus den aktuellen Daten.\n"
"\n"
" <Haupt-CR> <Karten-CRs...>\n"
"Die erste Datei in der Liste wird komplett geladen.\n"
"Alle weiteren Dateien werden als Karten-CRs angesehen und\n"
"nur die Regionsdaten werden aus dem CR geladen und zum Report hinzugef\u00fcgt.\n"
"Gibt man keine Parameter an, wird CsMapFX mit einer leeren Karte gestartet."
;
showError(help.str());
}
void showVersion()
{
std::ostringstream help;
help <<
CSMAP_APP_TITLE_VERSION
"\n " CSMAP_APP_COPYRIGHT
;
showError(help.str());
}
static void ParseCommandLine(CSMap *csmap, int argc, char** argv)
{
std::vector<FXString> args;
#ifdef WIN32
LPWSTR* cmdArgs;
int numArgs;
cmdArgs = CommandLineToArgvW(GetCommandLineW(), &numArgs);
if (numArgs > 1) {
for (int arg = 1; arg != numArgs; ++arg)
{
args.push_back(FXString(cmdArgs[arg]));
}
}
LocalFree(cmdArgs);
#else
for (int arg = 1; arg != argc; ++arg)
{
args.push_back(argv[arg]);
}
#endif
std::vector<FXString> tokens;
std::vector<FXString> switches;
std::vector<FXParam> params;
FXParseCommandLine(args, tokens, switches, params);
if (!tokens.empty()) {
std::vector<FXString> errorMessages;
csmap->loadFiles(tokens, errorMessages);
}
FXColor color = FXRGB(0, 0, 0);
FXint options = 0, scale = 32;
bool quit = false;
for (const FXString &option : switches) {
if (option == "quit") {
quit = true;
}
else if (option == "islands") {
options |= CSMap::ExportOptions::exportIslands;
}
else if (option == "names") {
options |= CSMap::ExportOptions::exportNames;
}
else if (option == "coordinates") {
options |= CSMap::ExportOptions::exportCoordinates;
}
else if (option == "white") {
color = FXRGB(255, 255, 255);
}
}
for (const FXParam& param : params) {
if (param.key == "out") {
csmap->saveFile(param.value);
}
else if (param.key == "export") {
csmap->saveFile(param.value, map_type::MAP_MINIMAL);
}
else if (param.key == "scale") {
scale = FXIntVal(param.value);
}
else if (param.key == "png") {
try {
csmap->saveMapImage(param.value, "image/png", scale, color, options);
}
catch (std::runtime_error &e) {
std::cerr << e.what() << std::endl;
}
}
}
if (quit) {
exit(0);
}
}
int main(int argc, char *argv[])
{
#ifdef WIN32
HRESULT hr = SetCurrentProcessExplicitAppUserModelID(g_wszAppID);
#ifdef WITH_MAP_EXPORT
// Initialize GDI+.
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
#endif
#endif
#ifdef HAVE_PHYSFS
PHYSFS_init(argv[0]);
PHYSFS_mount(PHYSFS_getBaseDir(), NULL, 0);
PHYSFS_mount(PHYSFS_getPrefDir("Eressea", "CsMapFX"), NULL, 0);
#endif
initSystems(); // inits COM under windows
#ifdef HAVE_CURL
curl_global_init(CURL_GLOBAL_DEFAULT);
#endif
// Make application
FXApp CSApp("CSMap", "Eressea");
// Open display
CSApp.init(argc, argv);
CSApp.create();
// Make window
CSMap* csmap = new CSMap(&CSApp);
ParseCommandLine(csmap, argc, argv);
// Create it
try
{
// create all windows
for (FXWindow* child = CSApp.getRootWindow()->getFirst(); child; child = child->getNext())
if (!child->id())
child->create();
}
catch (const FXException& e)
{
FXMessageBox::error(&CSApp, MBOX_OK, "CSMap - Fehler", "CSMap konnte nicht gestartet werden:\n%s", e.what());
return -1;
}
catch (const std::exception& e)
{
FXMessageBox::error(&CSApp, MBOX_OK, "CSMap - Fehler", "CSMap konnte nicht gestartet werden:\n%s", FXString(e.what()).text());
return -1;
}
csmap->mapChange();
csmap->show(PLACEMENT_DEFAULT);
// Run
int exitcode = CSApp.run();
#ifdef HAVE_CURL
curl_global_cleanup();
#endif
#ifdef HAVE_PHYSFS
PHYSFS_deinit();
#endif
#if defined(WIN32) && defined(WITH_MAP_EXPORT)
Gdiplus::GdiplusShutdown(gdiplusToken);
#endif
return exitcode;
}