Sun, 11 Aug 2013 13:38:12 +0300
Qt4 has QChar::toLatin1() as well so we don't need to use toAscii() in Qt4.
13
9bdddd2ccde6
now with 3691% extra legalese!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
1 | /* |
9bdddd2ccde6
now with 3691% extra legalese!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
2 | * ZanDemo: Zandronum demo launcher |
9bdddd2ccde6
now with 3691% extra legalese!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
3 | * Copyright (C) 2013 Santeri Piippo |
9bdddd2ccde6
now with 3691% extra legalese!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
4 | * |
9bdddd2ccde6
now with 3691% extra legalese!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
9bdddd2ccde6
now with 3691% extra legalese!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
9bdddd2ccde6
now with 3691% extra legalese!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
9bdddd2ccde6
now with 3691% extra legalese!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
8 | * (at your option) any later version. |
9bdddd2ccde6
now with 3691% extra legalese!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
9 | * |
9bdddd2ccde6
now with 3691% extra legalese!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
9bdddd2ccde6
now with 3691% extra legalese!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
9bdddd2ccde6
now with 3691% extra legalese!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
9bdddd2ccde6
now with 3691% extra legalese!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
13 | * GNU General Public License for more details. |
9bdddd2ccde6
now with 3691% extra legalese!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
14 | * |
9bdddd2ccde6
now with 3691% extra legalese!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
9bdddd2ccde6
now with 3691% extra legalese!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
9bdddd2ccde6
now with 3691% extra legalese!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
17 | */ |
9bdddd2ccde6
now with 3691% extra legalese!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
11
diff
changeset
|
18 | |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | #include <QFile> |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | #include <QDataStream> |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | #include <QMessageBox> |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | #include <QProcess> |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | #include "demo.h" |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | #include "bytestream.h" |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | #include "misc.h" |
8
e8f645d9f28f
Added a prompt for demo information
Teemu Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
26 | #include "ui_demoprompt.h" |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
27 | #include "prompts.h" |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
29 | static const uint32 g_demoSignature = makeByteID ('Z', 'C', 'L', 'D'); |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | // ============================================================================= |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | // ----------------------------------------------------------------------------- |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
33 | str uncolorize (const str& in) { |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
34 | str out; |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
35 | int skip = 0; |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
36 | |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
37 | for (const qchar& c : in) { |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
38 | if (skip-- > 0) |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
39 | continue; |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
40 | |
17
b41d74bacdea
Qt4 has QChar::toLatin1() as well so we don't need to use toAscii() in Qt4.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
41 | if (c.toLatin1() == '\034') { |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
42 | skip = 1; |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
43 | continue; |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
44 | } |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
45 | |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
46 | out += c; |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
47 | } |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
48 | |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
49 | return out; |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | } |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | // ============================================================================= |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
53 | // ----------------------------------------------------------------------------- |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
54 | static str tr (const char* msg) { |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
55 | return QObject::tr (msg); |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
56 | } |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
58 | // ============================================================================= |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | // ----------------------------------------------------------------------------- |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
60 | static void error (str msg) { |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
61 | QMessageBox::critical (null, "Error", msg); |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
62 | } |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
63 | |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
64 | // ============================================================================= |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | // ----------------------------------------------------------------------------- |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
66 | static bool isKnownVersion (str ver) { |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
67 | QSettings cfg; |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
68 | list<var> versions = getVersionsList(); |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
69 | |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
70 | for (const var& it : versions) |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
71 | if (it.toString() == ver || it.toString() + 'M' == ver) |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
72 | return true; |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
73 | |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
74 | return false; |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
75 | } |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
76 | |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
77 | // ============================================================================= |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
78 | // ----------------------------------------------------------------------------- |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
79 | static str findWAD (str name) { |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
80 | QSettings cfg; |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
81 | list<var> paths = cfg.value ("wads/paths", list<var>()).toList(); |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
82 | |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
83 | if (paths.size() == 0) { |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
84 | error (tr ("No WAD paths configured!")); |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
85 | |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
86 | // Cannot just return an empty string here since that'd trigger |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
87 | // another error prompt - skip ahead and exit. |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
88 | exit (9); |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
89 | } |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
90 | |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
91 | for (const var& it : paths) { |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
92 | str fullpath = fmt ("%1/%2", it.toString(), name); |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
93 | QFile f (fullpath); |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
94 | |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
95 | if (f.exists()) |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
96 | return fullpath; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
97 | } |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
98 | |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
99 | return ""; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
100 | } |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
101 | |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
102 | // ============================================================================= |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
103 | // ----------------------------------------------------------------------------- |
15
3d3e5f0fc4cc
made it compile on windows/qt5
Teemu Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
104 | #ifdef _WIN32 |
3d3e5f0fc4cc
made it compile on windows/qt5
Teemu Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
105 | # define FILE_FLAGS "rb" |
3d3e5f0fc4cc
made it compile on windows/qt5
Teemu Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
106 | #else |
3d3e5f0fc4cc
made it compile on windows/qt5
Teemu Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
107 | # define FILE_FLAGS "r" |
3d3e5f0fc4cc
made it compile on windows/qt5
Teemu Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
108 | #endif // _WIN32 |
3d3e5f0fc4cc
made it compile on windows/qt5
Teemu Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
109 | |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
110 | int launchDemo (str path) { |
15
3d3e5f0fc4cc
made it compile on windows/qt5
Teemu Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
111 | FILE* fp = fopen (path.toStdString().c_str(), FILE_FLAGS); |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
112 | |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
113 | if (!fp) { |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
114 | error (fmt (tr ("Couldn't open '%1' for reading: %2"), path, strerror (errno))); |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
115 | return 1; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
116 | } |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
117 | |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
118 | fseek (fp, 0, SEEK_END); |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
119 | const size_t fsize = ftell (fp); |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
120 | rewind (fp); |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
121 | |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
122 | char* buf = new char[fsize]; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
123 | |
15
3d3e5f0fc4cc
made it compile on windows/qt5
Teemu Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
124 | const size_t bytesRead = fread (buf, 1, fsize, fp); |
3d3e5f0fc4cc
made it compile on windows/qt5
Teemu Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
125 | if (bytesRead != fsize) { |
3d3e5f0fc4cc
made it compile on windows/qt5
Teemu Piippo <crimsondusk64@gmail.com>
parents:
13
diff
changeset
|
126 | error (fmt (tr ("I/O error: %1 / %2 bytes read"), bytesRead, fsize)); |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
127 | delete[] buf; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
128 | return 2; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
129 | } |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
130 | |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
131 | Bytestream s (buf, fsize); |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
132 | delete[] buf; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
133 | |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
134 | uint8 offset; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
135 | uint32 length; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
136 | |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
137 | struct { |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
138 | str netname, skin, className; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
139 | uint8 gender, handicap, unlagged, respawnOnFire, ticsPerUpdate, connectionType; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
140 | uint32 color, aimdist, railcolor; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
141 | } userinfo; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
142 | |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
143 | // Check signature |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
144 | { |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
145 | uint32 sig; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
146 | |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
147 | if (!s.readLong (sig) || sig != g_demoSignature) { |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
148 | error (fmt (tr ("'%1' is not a Zandronum demo file!"), path)); |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
149 | return 3; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
150 | } |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
151 | } |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
152 | |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
153 | // Zandronum stores CLD_DEMOLENGTH after the signature. This is also the |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
154 | // first demo enumerator, so we can determine the offset (which is variable!) |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
155 | // from this byte |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
156 | s.readByte (offset); |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
157 | s.readLong (length); |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
158 | |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
159 | uint16 zanversionID, numWads; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
160 | uint32 longSink; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
161 | str zanversion; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
162 | list<str> wads; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
163 | bool ready = false; |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
164 | uint8 buildID; |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
165 | |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
166 | // Read the demo header and get data |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
167 | for (;;) { |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
168 | uint8 header; |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
169 | |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
170 | if (!s.readByte (header)) |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
171 | break; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
172 | |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
173 | if (header == DemoBodyStart + offset) { |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
174 | ready = true; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
175 | break; |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
176 | } elif (header == DemoVersion + offset) { |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
177 | s.readShort (zanversionID); |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
178 | s.readString (zanversion); |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
179 | |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
180 | if (zanversion.left (4) != "1.1-" && zanversion.left (6) != "1.1.1-") |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
181 | s.readByte (buildID); |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
182 | else |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
183 | buildID = 1; |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
184 | |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
185 | s.readLong (longSink); // rng seed - we don't need it |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
186 | } elif (header == DemoUserInfo + offset) { |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
187 | s.readString (userinfo.netname); |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
188 | s.readByte (userinfo.gender); |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
189 | s.readLong (userinfo.color); |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
190 | s.readLong (userinfo.aimdist); |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
191 | s.readString (userinfo.skin); |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
192 | s.readLong (userinfo.railcolor); |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
193 | s.readByte (userinfo.handicap); |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
194 | s.readByte (userinfo.unlagged); |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
195 | s.readByte (userinfo.respawnOnFire); |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
196 | s.readByte (userinfo.ticsPerUpdate); |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
197 | s.readByte (userinfo.connectionType); |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
198 | s.readString (userinfo.className); |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
199 | } elif (header == DemoWads + offset) { |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
200 | str sink; |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
201 | s.readShort (numWads); |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
202 | |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
203 | for (uint8 i = 0; i < numWads; ++i) { |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
204 | str wad; |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
205 | s.readString (wad); |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
206 | wads << wad; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
207 | } |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
208 | |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
209 | // The demo has two checksum strings. We're not interested |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
210 | // in them though. |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
211 | for (int i = 0; i < 2; ++i) |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
212 | s.readString (sink); |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
213 | } else { |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
214 | error (fmt (tr ("Unknown header %1!\n"), (int) header)); |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
215 | return 3; |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
216 | } |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
217 | } |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
218 | |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
219 | if (!ready) { |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
220 | error (fmt (tr ("Incomplete demo header in '%s'!"), path)); |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
221 | return 3; |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
222 | } |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
223 | |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
224 | if (!isKnownVersion (zanversion)) { |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
225 | UnknownVersionPrompt* prompt = new UnknownVersionPrompt (path, zanversion, (buildID == 1)); |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
226 | if (!prompt->exec()) |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
227 | return 6; |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
228 | |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
229 | if (!isKnownVersion (zanversion)) { |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
230 | error (tr ("Failure in configuration! This shouldn't happen.")); |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
231 | return 6; |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
232 | } |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
233 | } |
11
3ddebf76105e
made style more consistent
Teemu Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
234 | |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
235 | QSettings cfg; |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
236 | str binarypath = cfg.value (binaryConfigName (zanversion)).toString(); |
11
3ddebf76105e
made style more consistent
Teemu Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
237 | |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
238 | if (binarypath.isEmpty()) { |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
239 | error (fmt (tr ("No binary path specified for Zandronum version %1!"), zanversion)); |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
240 | return 7; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
241 | } |
11
3ddebf76105e
made style more consistent
Teemu Piippo <crimsondusk64@gmail.com>
parents:
10
diff
changeset
|
242 | |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
243 | str iwadpath; |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
244 | list<str> pwadpaths; |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
245 | |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
246 | // Find the WADs |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
247 | for (const str& wad : wads) { |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
248 | str path = findWAD (wad); |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
249 | |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
250 | // IWAD names can appear in uppercase too. Linux is case-sensitive, so.. |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
251 | if (&wad == &wads[0] && path.isEmpty()) |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
252 | path = findWAD (wad.toUpper()); |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
253 | |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
254 | if (path.isEmpty()) { |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
255 | error (fmt (tr ("Couldn't find %1!"), wad)); |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
256 | return 8; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
257 | } |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
258 | |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
259 | if (&wad == &wads[0]) |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
260 | iwadpath = path; |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
261 | else |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
262 | pwadpaths << path; |
8
e8f645d9f28f
Added a prompt for demo information
Teemu Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
263 | } |
e8f645d9f28f
Added a prompt for demo information
Teemu Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
264 | |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
265 | if (!cfg.value ("nodemoprompt", false).toBool()) { |
8
e8f645d9f28f
Added a prompt for demo information
Teemu Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
266 | str pwadtext; |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
267 | |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
268 | for (const str& pwad : wads) { |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
269 | if (&pwad == &wads[0]) |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
270 | continue; // skip the IWAD |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
271 | |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
272 | if (!pwadtext.isEmpty()) |
8
e8f645d9f28f
Added a prompt for demo information
Teemu Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
273 | pwadtext += "<br />"; |
e8f645d9f28f
Added a prompt for demo information
Teemu Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
274 | |
e8f645d9f28f
Added a prompt for demo information
Teemu Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
275 | pwadtext += pwad; |
e8f645d9f28f
Added a prompt for demo information
Teemu Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
276 | } |
e8f645d9f28f
Added a prompt for demo information
Teemu Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
277 | |
e8f645d9f28f
Added a prompt for demo information
Teemu Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
278 | QDialog* dlg = new QDialog; |
e8f645d9f28f
Added a prompt for demo information
Teemu Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
279 | Ui_DemoPrompt ui; |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
280 | ui.setupUi (dlg); |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
281 | ui.demoNameLabel->setText (basename (path)); |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
282 | ui.demoRecorder->setText (uncolorize (userinfo.netname)); |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
283 | ui.versionLabel->setText (zanversion); |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
284 | ui.iwadLabel->setText (wads[0]); |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
285 | ui.pwadsLabel->setText (pwadtext); |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
286 | dlg->setWindowTitle (fmt (APPNAME " %1", versionString())); |
8
e8f645d9f28f
Added a prompt for demo information
Teemu Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
287 | |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
288 | if (!dlg->exec()) |
8
e8f645d9f28f
Added a prompt for demo information
Teemu Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
289 | return 1; |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
290 | } |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
291 | |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
292 | QStringList cmdlineList ( { |
8
e8f645d9f28f
Added a prompt for demo information
Teemu Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
293 | "-playdemo", path, |
e8f645d9f28f
Added a prompt for demo information
Teemu Piippo <crimsondusk64@gmail.com>
parents:
6
diff
changeset
|
294 | "-iwad", iwadpath, |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
295 | }); |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
296 | |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
297 | if (pwadpaths.size() > 0) { |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
298 | cmdlineList << "-file"; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
299 | cmdlineList << pwadpaths; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
300 | } |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
301 | |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
302 | print ("Executing: %1 %2\n", binarypath, cmdlineList.join (" ")); |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
303 | QProcess* proc = new QProcess; |
10
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
304 | proc->start (binarypath, cmdlineList); |
bc1414343e19
Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
8
diff
changeset
|
305 | proc->waitForFinished (-1); |
6
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
306 | return 0; |
67b6ef6917ba
Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
307 | } |