src/demo.cpp

Fri, 05 Jun 2015 19:13:44 +0300

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Fri, 05 Jun 2015 19:13:44 +0300
changeset 38
db677d321cf4
parent 37
c82a86ea87be
child 39
2c368cf5cc19
permissions
-rw-r--r--

Fix demo launching

13
9bdddd2ccde6 now with 3691% extra legalese!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 11
diff changeset
1 /*
30
6b82f6a3ad53 renamed the project to ZCinema
Teemu Piippo <crimsondusk64@gmail.com>
parents: 26
diff changeset
2 * ZCinema: Zandronum demo launcher
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
3 * Copyright (C) 2013-2015 Teemu Piippo
13
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 "misc.h"
8
e8f645d9f28f Added a prompt for demo information
Teemu Piippo <crimsondusk64@gmail.com>
parents: 6
diff changeset
25 #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
26 #include "prompts.h"
6
67b6ef6917ba Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
28 //
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
29 // -------------------------------------------------------------------------------------------------
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
30 //
20
a5457405cc9b Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents: 18
diff changeset
31
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
32 QString uncolorize (const QString& in)
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
33 {
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
34 // TODO: Handle long-form colors like \c[Red]
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
35 QString out;
10
bc1414343e19 Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 8
diff changeset
36 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
37
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
38 for (QChar c : in)
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
39 {
10
bc1414343e19 Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 8
diff changeset
40 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
41 continue;
bc1414343e19 Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 8
diff changeset
42
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
43 if (c == QChar ('\034'))
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
44 {
10
bc1414343e19 Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 8
diff changeset
45 skip = 1;
bc1414343e19 Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 8
diff changeset
46 continue;
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 out += c;
bc1414343e19 Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 8
diff changeset
50 }
bc1414343e19 Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 8
diff changeset
51
bc1414343e19 Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 8
diff changeset
52 return out;
6
67b6ef6917ba Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 }
67b6ef6917ba Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
55 //
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
56 // -------------------------------------------------------------------------------------------------
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
57 //
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
58
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
59 static QString tr (const char* msg)
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
60 {
10
bc1414343e19 Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 8
diff changeset
61 return QObject::tr (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
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
64 //
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
65 // -------------------------------------------------------------------------------------------------
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
66 //
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
67
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
68 static void error (QString msg)
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
69 {
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
70 QMessageBox::critical (NULL, "Error", msg);
6
67b6ef6917ba Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71 }
67b6ef6917ba Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
73 //
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
74 // -------------------------------------------------------------------------------------------------
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
75 //
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
76
38
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
77 static ZandronumVersion findVersion (QString versionName)
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
78 {
21
99225eac33ba use proper names QVariant and QChar instead of ambigous/dumb "var" and "qchar"
Teemu Piippo <crimsondusk64@gmail.com>
parents: 20
diff changeset
79 for (const QVariant& it : getVersions())
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
80 {
38
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
81 ZandronumVersion version = it.value<ZandronumVersion>();
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
82
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
83 if (version.name == versionName
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
84 or version.name + "M" == versionName
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
85 or version.name == versionName + "M")
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
86 {
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
87 return version;
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
88 }
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
89 }
6
67b6ef6917ba Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90
38
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
91 return ZandronumVersion();
10
bc1414343e19 Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 8
diff changeset
92 }
bc1414343e19 Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 8
diff changeset
93
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
94 //
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
95 // -------------------------------------------------------------------------------------------------
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
96 //
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
97
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
98 static QString findWAD (QString name)
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
99 {
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
100 QStringList wadpaths = Config::get ("wadpaths").toStringList();
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
101
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
102 if (wadpaths.empty())
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
103 {
10
bc1414343e19 Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 8
diff changeset
104 error (tr ("No WAD paths configured!"));
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
105
10
bc1414343e19 Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 8
diff changeset
106 // 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
107 // 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
108 exit (9);
6
67b6ef6917ba Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109 }
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
110
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
111 for (int i = 0; i < wadpaths.size(); ++i)
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
112 {
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
113 QString fullpath = QString ("%1/%2").arg (wadpaths[i]).arg (name);
10
bc1414343e19 Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 8
diff changeset
114 QFile f (fullpath);
6
67b6ef6917ba Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
115
10
bc1414343e19 Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 8
diff changeset
116 if (f.exists())
6
67b6ef6917ba Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117 return fullpath;
67b6ef6917ba Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
118 }
67b6ef6917ba Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
119
67b6ef6917ba Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
120 return "";
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
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
123 //
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
124 // -------------------------------------------------------------------------------------------------
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
125 //
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
126
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
127 QString readString (QDataStream& stream)
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
128 {
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
129 QString out;
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
130 uint8 ch;
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
131
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
132 for (stream >> ch; ch != 0; stream >> ch)
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
133 out += QChar (ch);
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
134
22
2fe0b7e0da7b For some God-knows-why reason, adding operator>> overloads to QDataStream leads into crashes with QFileDialog. Fixed by removing these overloads.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
135 return out;
18
6bf57b4f42cd Replaced the Bytestream class with QDataStream
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
136 }
15
3d3e5f0fc4cc made it compile on windows/qt5
Teemu Piippo <crimsondusk64@gmail.com>
parents: 13
diff changeset
137
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
138 //
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
139 // -------------------------------------------------------------------------------------------------
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
140 //
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
141
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
142 struct UserInfo
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
143 {
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
144 QString netname;
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
145 QString skin;
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
146 QString className;
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
147 uint32 color;
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
148 uint32 aimdist;
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
149 uint32 railcolor;
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
150 uint8 gender;
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
151 uint8 handicap;
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
152 uint8 unlagged;
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
153 uint8 respawnOnFire;
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
154 uint8 ticsPerUpdate;
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
155 uint8 connectionType;
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
156 };
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
157
38
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
158 struct DemoHeaders
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
159 {
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
160 uint8 length;
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
161 uint8 version;
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
162 uint8 userInfo;
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
163 uint8 bodyStart;
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
164 uint8 wads;
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
165 };
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
166
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
167 int launchDemo (QString path)
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
168 {
18
6bf57b4f42cd Replaced the Bytestream class with QDataStream
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
169 QFile f (path);
6
67b6ef6917ba Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
170
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
171 if (not f.open (QIODevice::ReadOnly))
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
172 {
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
173 error (tr ("Couldn't open '%1' for reading: %2").arg (path).arg (strerror (errno)));
6
67b6ef6917ba Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
174 return 1;
67b6ef6917ba Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
175 }
67b6ef6917ba Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
176
18
6bf57b4f42cd Replaced the Bytestream class with QDataStream
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
177 QDataStream stream (&f);
6bf57b4f42cd Replaced the Bytestream class with QDataStream
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
178 stream.setByteOrder (QDataStream::LittleEndian);
38
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
179
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
180 DemoHeaders headers;
6
67b6ef6917ba Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
181 uint32 length;
18
6bf57b4f42cd Replaced the Bytestream class with QDataStream
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
182 uint16 zanversionID, numWads;
6bf57b4f42cd Replaced the Bytestream class with QDataStream
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
183 uint32 longSink;
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
184 QString zanversion;
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
185 QStringList wads;
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
186 UserInfo userinfo;
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
187
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
188 // Assume a release build if the build ID not supplied. The demo only got the "ZCLD" signature
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
189 // in the 1.1 release build, 1.1.1 had no testing binaries and the build ID is included in 1.2
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
190 // onward.
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
191 BuildType buildID = ReleaseBuild;
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
192
18
6bf57b4f42cd Replaced the Bytestream class with QDataStream
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
193 bool ready = false;
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
194
6
67b6ef6917ba Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
195 // Check signature
67b6ef6917ba Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
196 {
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
197 uint32 demosignature;
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
198 stream >> demosignature;
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
199
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
200 if (demosignature != makeByteID ('Z', 'C', 'L', 'D'))
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
201 {
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
202 error (tr ("'%1' is not a valid Zandronum demo file!").arg (path));
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
203 return 1;
6
67b6ef6917ba Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
204 }
67b6ef6917ba Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
205 }
38
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
206
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
207 stream >> headers.length
18
6bf57b4f42cd Replaced the Bytestream class with QDataStream
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
208 >> length;
38
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
209
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
210 // The remaining headers are variable and relative to the length header.
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
211 headers.version = headers.length + 1;
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
212 headers.userInfo = headers.length + 3,
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
213 headers.bodyStart = headers.length + 4;
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
214 headers.wads = headers.length + 10;
6
67b6ef6917ba Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
215
10
bc1414343e19 Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 8
diff changeset
216 // Read the demo header and get data
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
217 for (;;)
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
218 {
6
67b6ef6917ba Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
219 uint8 header;
18
6bf57b4f42cd Replaced the Bytestream class with QDataStream
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
220 stream >> header;
6
67b6ef6917ba Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
221
38
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
222 if (header == headers.bodyStart)
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
223 {
6
67b6ef6917ba Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
224 ready = true;
67b6ef6917ba Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
225 break;
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
226 }
38
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
227 else if (header == headers.version)
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
228 {
22
2fe0b7e0da7b For some God-knows-why reason, adding operator>> overloads to QDataStream leads into crashes with QFileDialog. Fixed by removing these overloads.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
229 stream >> zanversionID;
2fe0b7e0da7b For some God-knows-why reason, adding operator>> overloads to QDataStream leads into crashes with QFileDialog. Fixed by removing these overloads.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
230 zanversion = readString (stream);
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
231
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
232 if (not zanversion.startsWith ("1.1-") and not zanversion.startsWith ("1.1.1-"))
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
233 {
22
2fe0b7e0da7b For some God-knows-why reason, adding operator>> overloads to QDataStream leads into crashes with QFileDialog. Fixed by removing these overloads.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
234 uint8 a;
2fe0b7e0da7b For some God-knows-why reason, adding operator>> overloads to QDataStream leads into crashes with QFileDialog. Fixed by removing these overloads.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
235 stream >> a;
2fe0b7e0da7b For some God-knows-why reason, adding operator>> overloads to QDataStream leads into crashes with QFileDialog. Fixed by removing these overloads.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
236 buildID = (BuildType) a;
18
6bf57b4f42cd Replaced the Bytestream class with QDataStream
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
237 }
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
238
38
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
239 // The demo wads header accidentally changed in 1.3. :(
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
240 if (zanversion.left(1).toInt() >= 2 or zanversion.startsWith ("1.3"))
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
241 headers.wads = headers.length + 8;
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
242
18
6bf57b4f42cd Replaced the Bytestream class with QDataStream
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
243 stream >> longSink; // rng seed - we don't need it
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
244 }
38
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
245 else if (header == headers.userInfo)
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
246 {
22
2fe0b7e0da7b For some God-knows-why reason, adding operator>> overloads to QDataStream leads into crashes with QFileDialog. Fixed by removing these overloads.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
247 userinfo.netname = readString (stream);
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
248 stream >> userinfo.gender;
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
249 stream >> userinfo.color;
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
250 stream >> userinfo.aimdist;
22
2fe0b7e0da7b For some God-knows-why reason, adding operator>> overloads to QDataStream leads into crashes with QFileDialog. Fixed by removing these overloads.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
251 userinfo.skin = readString (stream);
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
252 stream >> userinfo.railcolor;
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
253 stream >> userinfo.handicap;
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
254 stream >> userinfo.unlagged;
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
255 stream >> userinfo.respawnOnFire;
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
256 stream >> userinfo.ticsPerUpdate;
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
257 stream >> userinfo.connectionType;
22
2fe0b7e0da7b For some God-knows-why reason, adding operator>> overloads to QDataStream leads into crashes with QFileDialog. Fixed by removing these overloads.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 21
diff changeset
258 userinfo.className = readString (stream);
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
259 }
38
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
260 else if (header == headers.wads)
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
261 {
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
262 QString sink;
18
6bf57b4f42cd Replaced the Bytestream class with QDataStream
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
263 stream >> numWads;
10
bc1414343e19 Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 8
diff changeset
264
38
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
265 for (uint8 i = 0; i < numWads; ++i)
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
266 {
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
267 QString wad = readString (stream);
6
67b6ef6917ba Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
268 wads << wad;
67b6ef6917ba Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
269 }
67b6ef6917ba Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
270
38
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
271 // The demo has two checksum strings. We're not interested in them, though.
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
272 (sink = readString (stream)) = readString (stream);
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
273 }
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
274 else
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
275 {
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
276 error (tr ("Unknown header %1!\n").arg (int (header)));
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
277 return 1;
6
67b6ef6917ba Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
278 }
67b6ef6917ba Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
279 }
10
bc1414343e19 Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 8
diff changeset
280
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
281 if (not ready)
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
282 {
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
283 error (tr ("Incomplete demo header in '%s'!").arg (path));
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
284 return 1;
10
bc1414343e19 Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 8
diff changeset
285 }
38
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
286
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
287 ZandronumVersion version = findVersion (zanversion);
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
288
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
289 if (version.name.isNull())
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
290 {
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
291 QDialog* prompt = new UnknownVersionPrompt (path, zanversion, (buildID == ReleaseBuild));
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
292
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
293 if (not prompt->exec())
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
294 return 1;
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
295 }
11
3ddebf76105e made style more consistent
Teemu Piippo <crimsondusk64@gmail.com>
parents: 10
diff changeset
296
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
297 QString iwadpath;
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
298 QStringList pwadpaths;
6
67b6ef6917ba Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
299
67b6ef6917ba Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
300 // Find the WADs
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
301 for (const QString& wad : wads)
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
302 {
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
303 QString path = findWAD (wad);
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
304
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
305 // WAD names are case-sensitive under non-Windows and they can appear in uppercase
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
306 // so we need to test that too.
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
307 if (path.isEmpty())
10
bc1414343e19 Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 8
diff changeset
308 path = findWAD (wad.toUpper());
6
67b6ef6917ba Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
309
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
310 if (path.isEmpty())
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
311 {
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
312 error (tr ("Couldn't find %1!").arg (wad));
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
313 return 1;
6
67b6ef6917ba Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
314 }
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
315
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
316 if (&wad == &wads.first())
6
67b6ef6917ba Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
317 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
318 else
6
67b6ef6917ba Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
319 pwadpaths << path;
8
e8f645d9f28f Added a prompt for demo information
Teemu Piippo <crimsondusk64@gmail.com>
parents: 6
diff changeset
320 }
e8f645d9f28f Added a prompt for demo information
Teemu Piippo <crimsondusk64@gmail.com>
parents: 6
diff changeset
321
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
322 if (not Config::get ("noprompt").toBool())
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
323 {
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
324 QString pwadtext;
10
bc1414343e19 Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 8
diff changeset
325
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
326 for (const QString& wad : wads)
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
327 {
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
328 if (&wad == &wads.first())
10
bc1414343e19 Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 8
diff changeset
329 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
330
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
331 if (not pwadtext.isEmpty())
8
e8f645d9f28f Added a prompt for demo information
Teemu Piippo <crimsondusk64@gmail.com>
parents: 6
diff changeset
332 pwadtext += "<br />";
e8f645d9f28f Added a prompt for demo information
Teemu Piippo <crimsondusk64@gmail.com>
parents: 6
diff changeset
333
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
334 pwadtext += wad;
8
e8f645d9f28f Added a prompt for demo information
Teemu Piippo <crimsondusk64@gmail.com>
parents: 6
diff changeset
335 }
e8f645d9f28f Added a prompt for demo information
Teemu Piippo <crimsondusk64@gmail.com>
parents: 6
diff changeset
336
e8f645d9f28f Added a prompt for demo information
Teemu Piippo <crimsondusk64@gmail.com>
parents: 6
diff changeset
337 QDialog* dlg = new QDialog;
e8f645d9f28f Added a prompt for demo information
Teemu Piippo <crimsondusk64@gmail.com>
parents: 6
diff changeset
338 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
339 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
340 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
341 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
342 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
343 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
344 ui.pwadsLabel->setText (pwadtext);
26
9aab482c9125 When launched with no parameters, prompt the user for a demo
Teemu Piippo <crimsondusk64@gmail.com>
parents: 24
diff changeset
345 dlg->setWindowTitle (versionSignature());
8
e8f645d9f28f Added a prompt for demo information
Teemu Piippo <crimsondusk64@gmail.com>
parents: 6
diff changeset
346
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
347 if (not dlg->exec())
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
348 return 0;
6
67b6ef6917ba Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
349 }
10
bc1414343e19 Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 8
diff changeset
350
36
b8fa9171be6e Converted to CMake
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
351 QStringList cmdlineList;
b8fa9171be6e Converted to CMake
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
352 cmdlineList << "-playdemo" << path << "-iwad" << iwadpath;
37
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
353
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
354 if (pwadpaths.size() > 0)
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
355 cmdlineList << "-file" << pwadpaths;
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
356
c82a86ea87be Major rework, lots of internal maintenance, version editor removed
Teemu Piippo <crimsondusk64@gmail.com>
parents: 36
diff changeset
357 // print ("Executing: %1 %2\n", binarypath, cmdlineList.join (" "));
6
67b6ef6917ba Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
358 QProcess* proc = new QProcess;
38
db677d321cf4 Fix demo launching
Teemu Piippo <crimsondusk64@gmail.com>
parents: 37
diff changeset
359 proc->start (version.binaryPath, cmdlineList);
10
bc1414343e19 Overhauled the way versions are handled, it's all kept dynamically now.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 8
diff changeset
360 proc->waitForFinished (-1);
6
67b6ef6917ba Now capable of actually launching demos
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
361 return 0;
36
b8fa9171be6e Converted to CMake
Teemu Piippo <crimsondusk64@gmail.com>
parents: 30
diff changeset
362 }

mercurial