Skip to content

Commit

Permalink
SporeModManager: add commandline options
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosalie241 committed Nov 2, 2023
1 parent c000cdf commit b8aaa11
Show file tree
Hide file tree
Showing 6 changed files with 238 additions and 40 deletions.
20 changes: 15 additions & 5 deletions SporeModManager/SporeModManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ bool SporeModManager::InstallMod(std::filesystem::path path)
return true;
}

bool SporeModManager::UpdateMod(std::filesystem::path path)
bool SporeModManager::UpdateMod(std::filesystem::path path, bool requiresInstalled)
{
Zip::ZipFile zipFile;
std::vector<char> modInfoFileBuffer;
Expand Down Expand Up @@ -126,12 +126,22 @@ bool SporeModManager::UpdateMod(std::filesystem::path path)

if (!SporeMod::FindInstalledMod(installedSporeModUniqueName, installedSporeModId))
{
std::cerr << "No mod found with the same unique name" << std::endl
<< "Did you mean install?" << std::endl;
return false;
if (requiresInstalled)
{
std::cerr << "No mod found with the same unique name" << std::endl
<< "Did you mean install?" << std::endl;
return false;
}
}
else
{
if (!UninstallMods({ installedSporeModId }))
{
return false;
}
}

return UninstallMods({ installedSporeModId }) && InstallMod(path);
return InstallMod(path);
}

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 @@ -28,7 +28,7 @@ namespace SporeModManager
/// <summary>
/// Updates mod
/// </summary>
bool UpdateMod(std::filesystem::path path);
bool UpdateMod(std::filesystem::path path, bool requiresInstalled = true);

/// <summary>
/// Uninstalls mods with ids
Expand Down
10 changes: 10 additions & 0 deletions SporeModManager/SporeModManagerHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ namespace SporeModManagerHelpers

namespace Path
{
/// <summary>
/// Sets directories for current session
/// </summary>>
void SetDirectories(std::filesystem::path coreLibsPath, std::filesystem::path modLibsPath, std::filesystem::path galacticAdventuresDataPath, std::filesystem::path coreSporeDataPath);

/// <summary>
/// Returns wether all required paths exist
/// </summary>
Expand Down Expand Up @@ -231,6 +236,11 @@ namespace SporeModManagerHelpers

namespace UI
{
/// <summary>
/// Sets no input mode
/// </summary>
void SetNoInputMode(bool value);

/// <summary>
/// Asks user for an integer
/// </summary>
Expand Down
17 changes: 17 additions & 0 deletions SporeModManager/SporeModManagerHelpers/Path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,25 @@ std::filesystem::path MakeAbsolutePath(std::filesystem::path path)
// Exported Functions
//

void Path::SetDirectories(std::filesystem::path coreLibsPath, std::filesystem::path modLibsPath, std::filesystem::path galacticAdventuresDataPath, std::filesystem::path coreSporeDataPath)
{
l_CoreLibsPath = coreLibsPath;
l_ModLibsPath = modLibsPath;
l_GalacticAdventuresDataPath = galacticAdventuresDataPath;
l_CoreSporeDataPath = coreSporeDataPath;
}

bool Path::CheckIfPathsExist(void)
{
// when the paths have been set for the current session,
// we know that those directories already exist, so
// we can safely return true here
if (!l_CoreLibsPath.empty() && !l_ModLibsPath.empty() &&
!l_GalacticAdventuresDataPath.empty() && !l_CoreSporeDataPath.empty())
{
return true;
}

if (!SporeMod::Xml::GetDirectories(l_CoreLibsPath, l_ModLibsPath, l_GalacticAdventuresDataPath, l_CoreSporeDataPath))
{
std::cerr << "SporeMod::Xml::GetDirectories() Failed!" << std::endl;
Expand Down
36 changes: 36 additions & 0 deletions SporeModManager/SporeModManagerHelpers/UI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@

using namespace SporeModManagerHelpers;

//
// Local Variables
//

static bool l_NoInputMode = false;

//
// Exported Functions
//

void UI::SetNoInputMode(bool value)
{
l_NoInputMode = value;
}

void UI::AskUserInput(std::string text, int& number, std::optional<int> defaultNumber, int min, int max)
{
std::string inputLine;
Expand All @@ -22,6 +37,13 @@ void UI::AskUserInput(std::string text, int& number, std::optional<int> defaultN
{
std::cout << text;

if (l_NoInputMode)
{
std::cout << std::endl;
number = defaultNumber.has_value() ? defaultNumber.value() : 0;
return;
}

std::getline(std::cin, inputLine);
if (inputLine.empty() && defaultNumber.has_value())
{
Expand Down Expand Up @@ -58,6 +80,13 @@ void UI::AskUserInput(std::string text, char delimiter, std::vector<int>& number

std::cout << text;

if (l_NoInputMode)
{
std::cout << std::endl;
numbers = defaultNumbers;
return;
}

std::getline(std::cin, inputLine);
if (inputLine.empty())
{
Expand Down Expand Up @@ -103,6 +132,13 @@ void UI::AskUserInput(std::string text, bool& boolValue, bool defaultValue)
{
std::cout << text;

if (l_NoInputMode)
{
std::cout << std::endl;
boolValue = true;
return;
}

std::getline(std::cin, inputLine);
inputLine = String::Lowercase(inputLine);
if (inputLine.empty())
Expand Down
Loading

0 comments on commit b8aaa11

Please sign in to comment.