src/demo.cpp

changeset 20
a5457405cc9b
parent 18
6bf57b4f42cd
child 21
99225eac33ba
equal deleted inserted replaced
19:c9b6dd9dd4cd 20:a5457405cc9b
23 #include "demo.h" 23 #include "demo.h"
24 #include "misc.h" 24 #include "misc.h"
25 #include "ui_demoprompt.h" 25 #include "ui_demoprompt.h"
26 #include "prompts.h" 26 #include "prompts.h"
27 27
28 EXTERN_CONFIG (Map, binaryPaths)
29 EXTERN_CONFIG (List, wadpaths)
30 EXTERN_CONFIG (Bool, noprompt)
31
28 static const uint32 g_demoSignature = makeByteID ('Z', 'C', 'L', 'D'); 32 static const uint32 g_demoSignature = makeByteID ('Z', 'C', 'L', 'D');
29 33
30 // ============================================================================= 34 // =============================================================================
31 // ----------------------------------------------------------------------------- 35 // -----------------------------------------------------------------------------
32 str uncolorize (const str& in) { 36 str uncolorize (const str& in) {
35 39
36 for (const qchar& c : in) { 40 for (const qchar& c : in) {
37 if (skip-- > 0) 41 if (skip-- > 0)
38 continue; 42 continue;
39 43
40 if (c.toLatin1() == '\034') { 44 if (c == QChar ('\034')) {
41 skip = 1; 45 skip = 1;
42 continue; 46 continue;
43 } 47 }
44 48
45 out += c; 49 out += c;
61 } 65 }
62 66
63 // ============================================================================= 67 // =============================================================================
64 // ----------------------------------------------------------------------------- 68 // -----------------------------------------------------------------------------
65 static bool isKnownVersion (str ver) { 69 static bool isKnownVersion (str ver) {
66 QSettings cfg; 70 for (const var& it : getVersions())
67 list<var> versions = getVersionsList();
68
69 for (const var& it : versions)
70 if (it.toString() == ver || it.toString() + 'M' == ver) 71 if (it.toString() == ver || it.toString() + 'M' == ver)
71 return true; 72 return true;
72 73
73 return false; 74 return false;
74 } 75 }
75 76
76 // ============================================================================= 77 // =============================================================================
77 // ----------------------------------------------------------------------------- 78 // -----------------------------------------------------------------------------
78 static str findWAD (str name) { 79 static str findWAD (str name) {
79 QSettings cfg; 80 if (cfg::wadpaths.size() == 0) {
80 list<var> paths = cfg.value ("wads/paths", list<var>()).toList();
81
82 if (paths.size() == 0) {
83 error (tr ("No WAD paths configured!")); 81 error (tr ("No WAD paths configured!"));
84 82
85 // Cannot just return an empty string here since that'd trigger 83 // Cannot just return an empty string here since that'd trigger
86 // another error prompt - skip ahead and exit. 84 // another error prompt - skip ahead and exit.
87 exit (9); 85 exit (9);
88 } 86 }
89 87
90 for (const var& it : paths) { 88 for (const var& it : cfg::wadpaths) {
91 str fullpath = fmt ("%1/%2", it.toString(), name); 89 str fullpath = fmt ("%1/%2", it.toString(), name);
92 QFile f (fullpath); 90 QFile f (fullpath);
93 91
94 if (f.exists()) 92 if (f.exists())
95 return fullpath; 93 return fullpath;
229 error (tr ("Failure in configuration! This shouldn't happen.")); 227 error (tr ("Failure in configuration! This shouldn't happen."));
230 return 6; 228 return 6;
231 } 229 }
232 } 230 }
233 231
234 QSettings cfg; 232 str binarypath = cfg::binaryPaths [zanversion].toString();
235 str binarypath = cfg.value (binaryConfigName (zanversion)).toString();
236 233
237 if (binarypath.isEmpty()) { 234 if (binarypath.isEmpty()) {
238 error (fmt (tr ("No binary path specified for Zandronum version %1!"), zanversion)); 235 error (fmt (tr ("No binary path specified for Zandronum version %1!"), zanversion));
239 return 7; 236 return 7;
240 } 237 }
259 iwadpath = path; 256 iwadpath = path;
260 else 257 else
261 pwadpaths << path; 258 pwadpaths << path;
262 } 259 }
263 260
264 if (!cfg.value ("nodemoprompt", false).toBool()) { 261 if (!cfg::noprompt) {
265 str pwadtext; 262 str pwadtext;
266 263
267 for (const str& pwad : wads) { 264 for (const str& pwad : wads) {
268 if (&pwad == &wads[0]) 265 if (&pwad == &wads[0])
269 continue; // skip the IWAD 266 continue; // skip the IWAD
286 283
287 if (!dlg->exec()) 284 if (!dlg->exec())
288 return 1; 285 return 1;
289 } 286 }
290 287
291 QStringList cmdlineList ( { 288 QStringList cmdlineList ({
292 "-playdemo", path, 289 "-playdemo", path,
293 "-iwad", iwadpath, 290 "-iwad", iwadpath,
294 }); 291 });
295 292
296 if (pwadpaths.size() > 0) { 293 if (pwadpaths.size() > 0) {

mercurial