gamedemo.cpp
1 //------------------------------------------------------------------------------
2 // gamedemo.cpp
3 //------------------------------------------------------------------------------
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301, USA.
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2014 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #include "gamedemo.h"
24 
25 #include "ini/ini.h"
26 #include "ini/settingsproviderqt.h"
27 #include "plugins/engineplugin.h"
28 #include "datapaths.h"
29 #include <cassert>
30 #include <QDateTime>
31 #include <QDir>
32 
33 GameDemo::GameDemo()
34 {
35  d.control = NoDemo;
36 }
37 
38 GameDemo::GameDemo(Control control)
39 {
40  d.control = control;
41 }
42 
43 QString GameDemo::mkDemoFullPath(Control control, const EnginePlugin &plugin)
44 {
45  switch (control)
46  {
47  case Managed:
48  return gDefaultDataPaths->demosDirectoryPath() + QDir::separator() + mkDemoName(plugin);
49  case Unmanaged:
50  return mkDemoName(plugin);
51  case NoDemo:
52  return QString();
53  default:
54  assert(0 && "Unknown demo control type");
55  return QString();
56  }
57 }
58 
59 QString GameDemo::mkDemoName(const EnginePlugin &plugin)
60 {
61  QString demoName = "";
62  demoName += QString("%1_%2").
63  arg(plugin.data()->name).
64  arg(QDateTime::currentDateTime().toString("dd.MM.yyyy_hh.mm.ss"));
65  if (!plugin.data()->demoExtensionAutomatic)
66  {
67  demoName += QString(".%1").arg(plugin.data()->demoExtension);
68  }
69  return demoName;
70 }
71 
72 void GameDemo::saveDemoMetaData(const QString &demoName, const EnginePlugin &plugin,
73  const QString &iwad, const QStringList &pwads)
74 {
75  QString metaFileName;
76  // If the extension is automatic we need to add it here
77  if (plugin.data()->demoExtensionAutomatic)
78  {
79  metaFileName = QString("%1.%2.ini").arg(demoName)
80  .arg(plugin.data()->demoExtension);
81  }
82  else
83  {
84  metaFileName = demoName + ".ini";
85  }
86 
87  QSettings settings(metaFileName, QSettings::IniFormat);
88  SettingsProviderQt settingsProvider(&settings);
89  Ini metaFile(&settingsProvider);
90  IniSection metaSection = metaFile.section("meta");
91 
92  metaSection.createSetting("iwad", iwad.toLower());
93  metaSection.createSetting("pwads", pwads.join(";"));
94 }
95 
96 GameDemo::operator GameDemo::Control() const
97 {
98  return d.control;
99 }
IniVariable createSetting(const QString &name, const QVariant &data)
Inits specified variable with specified data.
Definition: inisection.cpp:57
Configuration handler.
Definition: ini.h:69
INI section representation.
Definition: inisection.h:40