aboutsummaryrefslogtreecommitdiff
path: root/primedev/mods
diff options
context:
space:
mode:
Diffstat (limited to 'primedev/mods')
-rw-r--r--primedev/mods/autodownload/moddownloader.cpp35
-rw-r--r--primedev/mods/autodownload/moddownloader.h1
-rw-r--r--primedev/mods/compiled/modkeyvalues.cpp2
-rw-r--r--primedev/mods/modmanager.cpp2
-rw-r--r--primedev/mods/modsavefiles.cpp20
5 files changed, 54 insertions, 6 deletions
diff --git a/primedev/mods/autodownload/moddownloader.cpp b/primedev/mods/autodownload/moddownloader.cpp
index c20a3adb..21b98942 100644
--- a/primedev/mods/autodownload/moddownloader.cpp
+++ b/primedev/mods/autodownload/moddownloader.cpp
@@ -156,6 +156,14 @@ int ModDownloader::ModFetchingProgressCallback(
{
NOTE_UNUSED(totalToUpload);
NOTE_UNUSED(nowUploaded);
+
+ // Abort download
+ ModDownloader* instance = static_cast<ModDownloader*>(ptr);
+ if (instance->modState.state == ABORTED)
+ {
+ return 1;
+ }
+
if (totalDownloadSize != 0 && finishedDownloadSize != 0)
{
ModDownloader* instance = static_cast<ModDownloader*>(ptr);
@@ -563,6 +571,13 @@ void ModDownloader::ExtractMod(fs::path modPath, VerifiedModPlatform platform)
}
}
+ // Abort mod extraction if needed
+ if (modState.state == ABORTED)
+ {
+ spdlog::info("User cancelled mod installation, aborting mod extraction.");
+ return;
+ }
+
// Go to next file
if ((i + 1) < gi.number_entry)
{
@@ -602,8 +617,7 @@ void ModDownloader::DownloadMod(std::string modName, std::string modVersion)
spdlog::error("Error while removing downloaded archive: {}", a.what());
}
- modState.state = DONE;
- spdlog::info("Done downloading {}.", modName);
+ spdlog::info("Done cleaning after downloading {}.", modName);
});
// Download mod archive
@@ -613,7 +627,10 @@ void ModDownloader::DownloadMod(std::string modName, std::string modVersion)
if (!fetchingResult.has_value())
{
spdlog::error("Something went wrong while fetching archive, aborting.");
- modState.state = MOD_FETCHING_FAILED;
+ if (modState.state != ABORTED)
+ {
+ modState.state = MOD_FETCHING_FAILED;
+ }
return;
}
archiveLocation = fetchingResult.value();
@@ -626,11 +643,17 @@ void ModDownloader::DownloadMod(std::string modName, std::string modVersion)
// Extract downloaded mod archive
ExtractMod(archiveLocation, fullVersion.platform);
+ modState.state = DONE;
});
requestThread.detach();
}
+void ModDownloader::CancelDownload()
+{
+ modState.state = ABORTED;
+}
+
ON_DLL_LOAD_RELIESON("engine.dll", ModDownloader, (ConCommand), (CModule module))
{
g_pModDownloader = new ModDownloader();
@@ -687,3 +710,9 @@ ADD_SQFUNC("ModInstallState", NSGetModInstallState, "", "", ScriptContext::SERVE
return SQRESULT_NOTNULL;
}
+
+ADD_SQFUNC("void", NSCancelModDownload, "", "", ScriptContext::SERVER | ScriptContext::CLIENT | ScriptContext::UI)
+{
+ g_pModDownloader->CancelDownload();
+ return SQRESULT_NULL;
+}
diff --git a/primedev/mods/autodownload/moddownloader.h b/primedev/mods/autodownload/moddownloader.h
index c7a88c19..2ac72a48 100644
--- a/primedev/mods/autodownload/moddownloader.h
+++ b/primedev/mods/autodownload/moddownloader.h
@@ -129,6 +129,7 @@ public:
CHECKSUMING,
EXTRACTING,
DONE, // Everything went great, mod can be used in-game
+ ABORTED, // User cancelled mod install process
// Errors
FAILED, // Generic error message, should be avoided as much as possible
diff --git a/primedev/mods/compiled/modkeyvalues.cpp b/primedev/mods/compiled/modkeyvalues.cpp
index e44a81d3..dfff706d 100644
--- a/primedev/mods/compiled/modkeyvalues.cpp
+++ b/primedev/mods/compiled/modkeyvalues.cpp
@@ -3,8 +3,6 @@
#include <fstream>
-AUTOHOOK_INIT()
-
void ModManager::TryBuildKeyValues(const char* filename)
{
spdlog::info("Building KeyValues for file {}", filename);
diff --git a/primedev/mods/modmanager.cpp b/primedev/mods/modmanager.cpp
index 056ea136..0c42ba21 100644
--- a/primedev/mods/modmanager.cpp
+++ b/primedev/mods/modmanager.cpp
@@ -1077,7 +1077,7 @@ void ModManager::LoadMods()
int currentModIndex = 0;
for (Mod& mod : m_LoadedMods)
{
- if (!mod.m_bEnabled || (!mod.RequiredOnClient && !mod.Pdiff.size()))
+ if (!mod.m_bEnabled)
continue;
modinfoDoc["Mods"].PushBack(rapidjson::kObjectType, modinfoDoc.GetAllocator());
diff --git a/primedev/mods/modsavefiles.cpp b/primedev/mods/modsavefiles.cpp
index 13239c99..d73b867c 100644
--- a/primedev/mods/modsavefiles.cpp
+++ b/primedev/mods/modsavefiles.cpp
@@ -74,6 +74,26 @@ template <ScriptContext context> void SaveFileManager::SaveFileAsync(fs::path fi
std::thread writeThread(
[mutex, file, contents]()
{
+ // Check if has extension and return early if not
+ if (!file.has_extension())
+ {
+ spdlog::error("A mod failed to save a file via Safe I/O due to the following error:");
+ spdlog::error("No file extension specified");
+ return;
+ }
+
+ // If there's a file extension missing here that you need, feel free to make a PR adding it
+ static const std::set<std::string> whitelist = {".txt", ".json"};
+
+ // Check if file extension is whitelisted
+ std::string extension = file.extension().string();
+ if (whitelist.find(extension) == whitelist.end())
+ {
+ spdlog::error("A mod failed to save a file via Safe I/O due to the following error:");
+ spdlog::error("Disallowed file extension: {}", extension);
+ return;
+ }
+
try
{
mutex.get().lock();