Skip to content

Commit

Permalink
move removing log file to Logger::Clear()
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosalie241 committed Jul 11, 2022
1 parent fc92626 commit 39cc9c6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 23 deletions.
25 changes: 3 additions & 22 deletions SporeModLoader/SporeModLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,13 @@ bool SporeModLoader::Initialize()
{
try
{
std::wstring errorMessage;
std::filesystem::path logFilePath;

logFilePath = Path::GetLogFilePath();

// remove log file if it exists
if (std::filesystem::exists(logFilePath))
{
try
{
std::filesystem::remove(logFilePath);
}
catch (...)
{
errorMessage = L"std::filesystem::remove(\"";
errorMessage += logFilePath.wstring();
errorMessage += L"\") Failed!";
UI::ShowErrorMessage(errorMessage);
throw std::exception();
}
}

Logger::Clear();

for (const auto& path : { Path::GetCoreLibsPath(), Path::GetModLibsPath() })
{
if (!std::filesystem::is_directory(path))
{
std::wstring errorMessage;
errorMessage = L"\"";
errorMessage += path.wstring();
errorMessage += L"\" doesn't exist!";
Expand Down
25 changes: 24 additions & 1 deletion SporeModLoader/SporeModLoaderHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,29 @@ std::filesystem::path Path::GetModLibsPath(void)
return modLibsPath;
}

void Logger::Clear(void)
{
std::filesystem::path logFilePath;

logFilePath = Path::GetLogFilePath();

if (std::filesystem::exists(logFilePath))
{
try
{
std::filesystem::remove(logFilePath);
}
catch (...)
{
std::wstring errorMessage;
errorMessage = L"std::filesystem::remove(\"";
errorMessage += logFilePath.wstring();
errorMessage += L"\") Failed!";
UI::ShowErrorMessage(errorMessage);
throw std::exception();
}
}
}

void Logger::AddMessage(std::wstring message)
{
Expand Down Expand Up @@ -150,7 +173,7 @@ bool Library::LoadAllInPath(std::filesystem::path path)
return true;
}

Game::GameVersion SporeModLoaderHelpers::Game::GetCurrentVersion(void)
Game::GameVersion Game::GetCurrentVersion(void)
{
std::filesystem::path currentExecutablePath;
uintmax_t currentFileSize;
Expand Down
5 changes: 5 additions & 0 deletions SporeModLoader/SporeModLoaderHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ namespace SporeModLoaderHelpers

namespace Logger
{
/// <summary>
/// Clears log file
/// </summary>
void Clear(void);

/// <summary>
/// Adds message to the log file
/// </summary>
Expand Down

0 comments on commit 39cc9c6

Please sign in to comment.