Pyrogenesis  trunk
ModInstaller.h
Go to the documentation of this file.
1 /* Copyright (C) 2022 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef INCLUDED_MODINSTALLER
19 #define INCLUDED_MODINSTALLER
20 
21 #include "CStr.h"
22 #include "lib/file/vfs/vfs.h"
23 
24 #include <memory>
25 #include <vector>
26 
27 class ScriptContext;
28 
29 /**
30  * Install a mod into the mods directory.
31  */
33 {
34 public:
36  {
45  };
46 
47  /**
48  * Initialise the mod installer for processing the given mod.
49  *
50  * @param modsdir path to the data directory that contains mods
51  * @param tempdir path to a writable directory for temporary files
52  */
53  CModInstaller(const OsPath& modsdir, const OsPath& tempdir);
54 
56 
57  /**
58  * Process and unpack the mod.
59  * @param mod path of .pyromod/.zip file
60  * @param keepFile if true, copy the file, if false move it
61  */
63  const OsPath& mod,
64  const std::shared_ptr<ScriptContext>& scriptContext,
65  bool keepFile);
66 
67  /**
68  * @return a list of all mods installed so far by this CModInstaller.
69  */
70  const std::vector<CStr>& GetInstalledMods() const;
71 
72  /**
73  * @return whether the path has a mod-like extension.
74  */
75  static bool IsDefaultModExtension(const Path& ext)
76  {
77  return ext == ".pyromod" || ext == ".zip";
78  }
79 
80 private:
85  std::vector<CStr> m_InstalledMods;
86 };
87 
88 #endif // INCLUDED_MODINSTALLER
static bool IsDefaultModExtension(const Path &ext)
Definition: ModInstaller.h:75
PIVFS m_VFS
Definition: ModInstaller.h:81
Definition: ModInstaller.h:44
ModInstallationResult
Definition: ModInstaller.h:35
ModInstallationResult Install(const OsPath &mod, const std::shared_ptr< ScriptContext > &scriptContext, bool keepFile)
Process and unpack the mod.
Definition: ModInstaller.cpp:53
Definition: ModInstaller.h:42
std::vector< CStr > m_InstalledMods
Definition: ModInstaller.h:85
Definition: ModInstaller.h:41
Definition: ModInstaller.h:37
Abstraction around a SpiderMonkey JSContext.
Definition: ScriptContext.h:40
std::shared_ptr< IVFS > PIVFS
Definition: vfs.h:220
Definition: ModInstaller.h:43
OsPath m_TempDir
Definition: ModInstaller.h:83
Definition: ModInstaller.h:39
Definition: path.h:79
const std::vector< CStr > & GetInstalledMods() const
Definition: ModInstaller.cpp:137
~CModInstaller()
Definition: ModInstaller.cpp:47
OsPath m_ModsDir
Definition: ModInstaller.h:82
CModInstaller(const OsPath &modsdir, const OsPath &tempdir)
Initialise the mod installer for processing the given mod.
Definition: ModInstaller.cpp:40
Definition: ModInstaller.h:40
VfsPath m_CacheDir
Definition: ModInstaller.h:84
Definition: ModInstaller.h:38
Install a mod into the mods directory.
Definition: ModInstaller.h:32