Skip to content

Commit

Permalink
SporeModManager: add -v/--verbose commandline option
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosalie241 committed Dec 5, 2023
1 parent 49c01ff commit 8c0db82
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 12 deletions.
7 changes: 6 additions & 1 deletion SporeModManager/SporeModManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,13 +336,18 @@ bool SporeModManager::UninstallMods(std::vector<int> ids)
{
installedSporeMod = l_InstalledSporeMods.at(id);

std::cout << "-> Removing " << installedSporeMod.Name << std::endl;

for (const auto& installedFile : installedSporeMod.InstalledFiles)
{
try
{
fullInstallPath = Path::GetFullInstallPath(installedFile.InstallLocation, installedFile.FileName);

std::cout << "-> Removing " << installedFile.FileName.string() << std::endl;
if (UI::GetVerboseMode())
{
std::cout << "--> Removing " << installedFile.FileName.string() << std::endl;
}

std::filesystem::remove(fullInstallPath);
}
Expand Down
10 changes: 10 additions & 0 deletions SporeModManager/SporeModManagerHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,16 @@ namespace SporeModManagerHelpers

namespace UI
{
/// <summary>
/// Sets verbose mode
/// </summary>
void SetVerboseMode(bool value);

/// <summary>
/// Gets verbose mode
/// </summary>
bool GetVerboseMode(void);

/// <summary>
/// Sets no input mode
/// </summary>
Expand Down
55 changes: 44 additions & 11 deletions SporeModManager/SporeModManagerHelpers/SporeMod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ bool SporeMod::InstallSporeMod(void* zipFile, const Xml::SporeModInfo& sporeModI
std::vector<int> defaultComponentIds;
std::vector<int> componentIds;
std::string uiText;
bool configurationRequired = false;

installedSporeMod.Name = sporeModInfo.Name;
installedSporeMod.UniqueName = sporeModInfo.UniqueName;
Expand All @@ -96,15 +97,30 @@ bool SporeMod::InstallSporeMod(void* zipFile, const Xml::SporeModInfo& sporeModI
return false;
}

configurationRequired = sporeModInfo.IsExperimental ||
sporeModInfo.RequiresGalaxyReset ||
sporeModInfo.CausesSaveDataDependency ||
!sporeModInfo.ComponentGroups.empty() ||
!sporeModInfo.Components.empty();

if (configurationRequired)
{
std::cout << "-> Configuring " << sporeModInfo.Name << std::endl;
}
else
{
std::cout << "-> Installing " << sporeModInfo.Name << std::endl;
}

struct
{
bool NeedsWarn;
std::string Text;
} warningOptions[] =
{
{ sporeModInfo.IsExperimental, "This mod is experimental" },
{ sporeModInfo.RequiresGalaxyReset, "This mod requires a galaxy reset" },
{ sporeModInfo.CausesSaveDataDependency, "This mod causes save data dependency" }
{ sporeModInfo.IsExperimental, "--> This mod is experimental" },
{ sporeModInfo.RequiresGalaxyReset, "--> This mod requires a galaxy reset" },
{ sporeModInfo.CausesSaveDataDependency, "--> This mod causes save data dependency" }
};

for (const auto& warnOption : warningOptions)
Expand All @@ -113,7 +129,7 @@ bool SporeMod::InstallSporeMod(void* zipFile, const Xml::SporeModInfo& sporeModI
{
std::string inputText = warnOption.Text;
bool userAnswer = false;
inputText += "\n-> Are you sure you want to continue? [y/N]: ";
inputText += "\n--> Are you sure you want to continue? [y/N]: ";
UI::AskUserInput(inputText, userAnswer, false);
if (!userAnswer)
{
Expand All @@ -124,7 +140,7 @@ bool SporeMod::InstallSporeMod(void* zipFile, const Xml::SporeModInfo& sporeModI

for (const auto& componentGroup : sporeModInfo.ComponentGroups)
{
std::cout << "-> " << componentGroup.Name << std::endl;
std::cout << "--> " << componentGroup.Name << std::endl;

componentsSize = componentGroup.Components.size();
componentId = 0;
Expand All @@ -143,7 +159,7 @@ bool SporeMod::InstallSporeMod(void* zipFile, const Xml::SporeModInfo& sporeModI
}
}

uiText = "-> select which component you want";
uiText = "--> select which component you want";
if (defaultComponentId.has_value())
{
uiText += " [";
Expand Down Expand Up @@ -184,7 +200,7 @@ bool SporeMod::InstallSporeMod(void* zipFile, const Xml::SporeModInfo& sporeModI
}
}

uiText = "-> select which components you want to install (comma seperated";
uiText = "--> select which components you want to install (comma seperated";
if (!defaultComponentIds.empty())
{
uiText += " or N for none) [";
Expand Down Expand Up @@ -240,6 +256,11 @@ bool SporeMod::InstallSporeMod(void* zipFile, const Xml::SporeModInfo& sporeModI
}
}

if (configurationRequired)
{
std::cout << "-> Installing " << sporeModInfo.Name << std::endl;
}

// file collision detection
if (CheckIfOtherModContainsFiles(installedSporeMod.InstalledFiles, installedSporeMods))
{
Expand All @@ -248,7 +269,10 @@ bool SporeMod::InstallSporeMod(void* zipFile, const Xml::SporeModInfo& sporeModI

for (const auto& installedFile : installedSporeMod.InstalledFiles)
{
std::cout << "-> Installing " << installedFile.FileName.string() << std::endl;
if (UI::GetVerboseMode())
{
std::cout << "--> Installing " << installedFile.FileName.string() << std::endl;
}

std::filesystem::path sourcePath = installedFile.FileName;
std::filesystem::path installPath = Path::GetFullInstallPath(installedFile.InstallLocation, installedFile.FileName);
Expand All @@ -264,7 +288,10 @@ bool SporeMod::InstallSporeMod(void* zipFile, const Xml::SporeModInfo& sporeModI
{
try
{
std::cout << "-> Removing " << installPath.filename().string() << std::endl;
if (UI::GetVerboseMode())
{
std::cout << "--> Removing " << installPath.filename().string() << std::endl;
}
std::filesystem::remove(installPath);
}
catch(...)
Expand Down Expand Up @@ -300,19 +327,25 @@ bool SporeMod::InstallPackage(std::filesystem::path path, Xml::InstalledSporeMod
return false;
}

std::cout << "-> Installing " << installedSporeMod.Name << std::endl;

// file collision detection
if (CheckIfOtherModContainsFiles(installedSporeMod.InstalledFiles, installedSporeMods))
{
return false;
}

for (const auto& installedFile : installedSporeMod.InstalledFiles)
{
std::cout << "-> Installing " << installedFile.FileName.string() << std::endl;

std::filesystem::path sourcePath = path;
std::filesystem::path installPath = Path::GetFullInstallPath(installedFile.InstallLocation, installedFile.FileName);

if (UI::GetVerboseMode())
{
std::cout << "--> Installing " << installedFile.FileName.string() << std::endl;
}

try
{
std::filesystem::copy_file(sourcePath, installPath, std::filesystem::copy_options::overwrite_existing);
Expand Down
11 changes: 11 additions & 0 deletions SporeModManager/SporeModManagerHelpers/UI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,23 @@ using namespace SporeModManagerHelpers;
// Local Variables
//

static bool l_VerboseMode = false;
static bool l_NoInputMode = false;

//
// Exported Functions
//

void UI::SetVerboseMode(bool value)
{
l_VerboseMode = value;
}

bool UI::GetVerboseMode(void)
{
return l_VerboseMode;
}

void UI::SetNoInputMode(bool value)
{
l_NoInputMode = value;
Expand Down
4 changes: 4 additions & 0 deletions SporeModManager/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ static void ShowUsage()
<< " help display this help and exit" << std::endl
<< std::endl
<< "Options: " << std::endl
<< " -v, --verbose shows verbose output" << std::endl
<< " -n, --no-input disables user input during installation of mods" << std::endl
<< " -u, --update-needed updates mod when mod is already installed" << std::endl
<< " -s, --save-paths saves paths to the configuration file" << std::endl
Expand All @@ -88,6 +89,7 @@ int main(int argc, char** argv)
std::vector<arg_str_type> args(argv, argv + argc);

// parse options
bool hasVerboseOption = false;
bool hasNoInputOption = false;
bool hasUpdateOption = false;
bool hasSavePathsOption = false;
Expand All @@ -98,6 +100,7 @@ int main(int argc, char** argv)

struct option_argument optionArgs[] =
{
{ arg_str("v"), arg_str("verbose"), hasVerboseOption },
{ arg_str("n"), arg_str("no-input"), hasNoInputOption },
{ arg_str("u"), arg_str("update-needed"), hasUpdateOption },
{ arg_str("s"), arg_str("save-paths"), hasSavePathsOption },
Expand Down Expand Up @@ -190,6 +193,7 @@ int main(int argc, char** argv)
}

// apply options
UI::SetVerboseMode(hasVerboseOption);
UI::SetNoInputMode(hasNoInputOption);
Path::SetDirectories(coreLibsPath, modLibsPath, ep1Path, dataPath);
if (hasSavePathsOption)
Expand Down

0 comments on commit 8c0db82

Please sign in to comment.