Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
ModInstaller.h
Go to the documentation of this file.
1/* Copyright (C) 2026 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 "lib/file/vfs/vfs.h"
23#include "lib/os_path.h"
24#include "lib/path.h"
25#include "ps/CStr.h"
26#include <memory>
27#include <vector>
28
29namespace Script { class Context; }
30
31/**
32 * Install a mod into the mods directory.
33 */
35{
36public:
38 {
47 };
48
49 /**
50 * Initialise the mod installer for processing the given mod.
51 *
52 * @param modsdir path to the data directory that contains mods
53 * @param tempdir path to a writable directory for temporary files
54 */
55 CModInstaller(const OsPath& modsdir, const OsPath& tempdir);
56
58
59 /**
60 * Process and unpack the mod.
61 * @param mod path of .pyromod/.zip file
62 * @param keepFile if true, copy the file, if false move it
63 */
65 const OsPath& mod,
66 const std::shared_ptr<Script::Context>& scriptContext,
67 bool keepFile);
68
69 /**
70 * @return a list of all mods installed so far by this CModInstaller.
71 */
72 const std::vector<CStr>& GetInstalledMods() const;
73
74 /**
75 * @return whether the path has a mod-like extension.
76 */
77 static bool IsDefaultModExtension(const Path& ext)
78 {
79 return ext == ".pyromod" || ext == ".zip";
80 }
81
82private:
87 std::vector<CStr> m_InstalledMods;
88};
89
90#endif // INCLUDED_MODINSTALLER
Install a mod into the mods directory.
Definition: ModInstaller.h:35
VfsPath m_CacheDir
Definition: ModInstaller.h:86
const std::vector< CStr > & GetInstalledMods() const
Definition: ModInstaller.cpp:145
PIVFS m_VFS
Definition: ModInstaller.h:83
~CModInstaller()
Definition: ModInstaller.cpp:55
OsPath m_TempDir
Definition: ModInstaller.h:85
std::vector< CStr > m_InstalledMods
Definition: ModInstaller.h:87
static bool IsDefaultModExtension(const Path &ext)
Definition: ModInstaller.h:77
ModInstallationResult Install(const OsPath &mod, const std::shared_ptr< Script::Context > &scriptContext, bool keepFile)
Process and unpack the mod.
Definition: ModInstaller.cpp:61
OsPath m_ModsDir
Definition: ModInstaller.h:84
CModInstaller(const OsPath &modsdir, const OsPath &tempdir)
Initialise the mod installer for processing the given mod.
Definition: ModInstaller.cpp:48
ModInstallationResult
Definition: ModInstaller.h:38
@ FAIL_ON_VFS_MOUNT
Definition: ModInstaller.h:40
@ FAIL_ON_MOD_LOAD
Definition: ModInstaller.h:41
@ FAIL_ON_PARSE_JSON
Definition: ModInstaller.h:42
@ FAIL_ON_MOD_COPY
Definition: ModInstaller.h:46
@ FAIL_ON_MOD_MOVE
Definition: ModInstaller.h:44
@ FAIL_ON_JSON_WRITE
Definition: ModInstaller.h:45
@ FAIL_ON_EXTRACT_NAME
Definition: ModInstaller.h:43
@ SUCCESS
Definition: ModInstaller.h:39
Definition: path.h:84
Abstraction around a SpiderMonkey JSContext.
Definition: DapInterface.h:32
std::shared_ptr< IVFS > PIVFS
Definition: vfs.h:240