Skip to content

Commit

Permalink
SporeModManager: add skipValidation argument to InstallMods()
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosalie241 committed Nov 9, 2023
1 parent a3ab17e commit 9c1c1a6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 28 deletions.
57 changes: 30 additions & 27 deletions SporeModManager/SporeModManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,46 +95,49 @@ bool SporeModManager::ListInstalledMods(void)
return true;
}

bool SporeModManager::InstallMods(std::vector<std::filesystem::path> paths)
bool SporeModManager::InstallMods(std::vector<std::filesystem::path> paths, bool skipValidation)
{
std::string uniqueName;
std::vector<std::string> uniqueNames;

// do some basic validation before attempting
// to install the given mods
for (size_t i = 0; i < paths.size(); i++)
if (!skipValidation)
{
const std::filesystem::path& path = paths.at(i);

if (!std::filesystem::is_regular_file(path))
for (size_t i = 0; i < paths.size(); i++)
{
std::cerr << "\"" << path.string() << "\" is not a regular file or doesn't exist!" << std::endl;
return false;
}
const std::filesystem::path& path = paths.at(i);

std::string extension = String::Lowercase(path.extension().string());
if (extension == ".sporemod" || extension == ".package")
{
if (!GetUniqueName(path, extension, uniqueName))
if (!std::filesystem::is_regular_file(path))
{
std::cerr << "\"" << path.string() << "\" is not a regular file or doesn't exist!" << std::endl;
return false;
}
}
else
{
std::cerr << "\"" << extension << "\" is an invalid extension!" << std::endl;
return false;
}

// ensure we only have unique mod names
if (std::find(uniqueNames.begin(), uniqueNames.end(), uniqueName) != uniqueNames.end())
{
std::cerr << "Removing \"" << path.string() << "\" from the installation list due to another mod having the same unique name!" << std::endl;
paths.erase(paths.begin() + i);
i -= 1;
continue;
std::string extension = String::Lowercase(path.extension().string());
if (extension == ".sporemod" || extension == ".package")
{
if (!GetUniqueName(path, extension, uniqueName))
{
return false;
}
}
else
{
std::cerr << "\"" << extension << "\" is an invalid extension!" << std::endl;
return false;
}

// ensure we only have unique mod names
if (std::find(uniqueNames.begin(), uniqueNames.end(), uniqueName) != uniqueNames.end())
{
std::cerr << "Removing \"" << path.string() << "\" from the installation list due to another mod having the same unique name!" << std::endl;
paths.erase(paths.begin() + i);
i -= 1;
continue;
}
uniqueNames.push_back(uniqueName);
}
uniqueNames.push_back(uniqueName);
}

// install given mods
Expand Down Expand Up @@ -225,7 +228,7 @@ bool SporeModManager::UpdateMods(std::vector<std::filesystem::path> paths, bool
return false;
}

return InstallMods(paths);
return InstallMods(paths, true);
}

bool SporeModManager::UninstallMods(std::vector<int> ids)
Expand Down
2 changes: 1 addition & 1 deletion SporeModManager/SporeModManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace SporeModManager
/// <summary>
/// Installs mod
/// </summary>
bool InstallMods(std::vector<std::filesystem::path> paths);
bool InstallMods(std::vector<std::filesystem::path> paths, bool skipValidation = false);

/// <summary>
/// Updates mod
Expand Down

0 comments on commit 9c1c1a6

Please sign in to comment.