Skip to content

Commit

Permalink
General: Add Log fallback to Temp directories
Browse files Browse the repository at this point in the history
  • Loading branch information
Parik27 committed Nov 6, 2021
1 parent 6c472d5 commit 15e8850
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion build-count.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
510
511
18 changes: 14 additions & 4 deletions src/common/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,15 @@ GetGameDirRelativePathA (const char *subpath)
/*******************************************************/
std::string
Common::GetRainbomizerFileName (const std::string &name,
const std::string &subdirs)
const std::string &subdirs, bool temp)
{
std::string baseDir
= GetGameDirRelativePathA (("rainbomizer/" + subdirs).c_str ());

if (temp)
baseDir = std::filesystem::temp_directory_path ().string ()
+ "/rainbomizer/" + subdirs;

std::error_code ec;
std::filesystem::create_directories (baseDir, ec);

Expand All @@ -106,10 +110,16 @@ Common::GetRainbomizerFileName (const std::string &name,
/*******************************************************/
FILE *
Common::GetRainbomizerFile (const std::string &name, const std::string &mode,
const std::string &subdirs)
const std::string &subdirs, bool tempFallback)
{
return fopen (GetRainbomizerFileName (name, subdirs).c_str (),
mode.c_str ());
FILE *file = fopen (GetRainbomizerFileName (name, subdirs).c_str (),
mode.c_str ());

if (!file && tempFallback)
return fopen (GetRainbomizerFileName (name, subdirs, true).c_str (),
mode.c_str ());

return file;
}

/*******************************************************/
Expand Down
6 changes: 4 additions & 2 deletions src/common/common.hh
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ public:
static const std::vector<uint32_t> &GetPedHashes ();

static std::string GetRainbomizerFileName (const std::string &name,
const std::string &subdirs = "");
const std::string &subdirs = "",
bool temp = false);

static FILE *GetRainbomizerFile (const std::string &name,
const std::string &mode,
const std::string &subdirs = "");
const std::string &subdirs = "",
bool tempFallback = false);

static FILE *GetRainbomizerDataFile (const std::string &name,
const std::string &mode = "r");
Expand Down
9 changes: 2 additions & 7 deletions src/common/logger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,10 @@ Logger::GetLogFile ()
if (!mFile)
{
mFile = Common::GetRainbomizerFile (GetTimeNow () + ".txt", "a+",
"logs/");
"logs/", true);
if (!mFile)
{
MessageBox (NULL,
"Failed to open log file for writing.\n\nAllow "
"write permissions for the GTA V Directory to "
"allow Rainbomizer to work properly.\n\nRight "
"click on the Game Folder > Properties > "
"General > Uncheck Read Only.",
MessageBox (NULL, "Failed to open log file for writing.",
"Error", MB_ICONHAND);
mFile = stdout;
}
Expand Down
5 changes: 0 additions & 5 deletions src/mission/missions_Flow.hh
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@

class MissionRandomizer_Flow
{
FILE *mStartCoordsFile
= Rainbomizer::Common::GetRainbomizerFile ("startCoords.txt", "a");
FILE *mEndCoordsFile
= Rainbomizer::Common::GetRainbomizerFile ("endCoords.txt", "a");

const MissionInfo *OriginalMission = nullptr;
const MissionInfo *RandomizedMission = nullptr;

Expand Down

0 comments on commit 15e8850

Please sign in to comment.