1 /*
2 * main.cpp
3 * Copyright 2010, Thorbjørn Lindeijer <thorbjorn@lindeijer.nl>
4 *
5 * This file is part of the TMX Viewer example.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
20 * EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include "tmxviewer.h"
30
31 #include <QApplication>
32 #include <QCommandLineParser>
33 #include <QDebug>
34
35 #ifdef Q_OS_WIN
36 #include <windows.h>
37 #endif
38
main(int argc,char * argv[])39 int main(int argc, char *argv[])
40 {
41 #if defined(Q_OS_WIN) && (!defined(Q_CC_MINGW) || __MINGW32_MAJOR_VERSION >= 5)
42 // Make console output work on Windows, if running in a console.
43 if (AttachConsole(ATTACH_PARENT_PROCESS)) {
44 FILE *dummy = nullptr;
45 freopen_s(&dummy, "CONOUT$", "w", stdout);
46 freopen_s(&dummy, "CONOUT$", "w", stderr);
47 }
48 #endif
49
50 QApplication a(argc, argv);
51
52 a.setOrganizationDomain(QLatin1String("mapeditor.org"));
53 a.setApplicationName(QLatin1String("TmxViewer"));
54 a.setApplicationVersion(QLatin1String("1.0"));
55
56 QCommandLineParser parser;
57 parser.setApplicationDescription(QCoreApplication::translate("main", "Displays a Tiled map (TMX format)."));
58 parser.addHelpOption();
59 parser.addVersionOption();
60 parser.addPositionalArgument("file", QCoreApplication::translate("main", "Map file to display."));
61 parser.process(a);
62
63 const QStringList args = parser.positionalArguments();
64 if (args.size() != 1)
65 parser.showHelp(1);
66
67 TmxViewer w;
68 if (!w.viewMap(args.first()))
69 return 1;
70
71 w.show();
72 return a.exec();
73 }
74