From 8dddbd8b9295d842319d6c4493e42817b485e143 Mon Sep 17 00:00:00 2001 From: parax0 Date: Sun, 20 Mar 2016 06:39:07 -0600 Subject: [PATCH] Attempt to find a new filename for the log if we can't open the requested one --- src/Common/Log.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Common/Log.cpp b/src/Common/Log.cpp index cbeeacd9..dbc26584 100644 --- a/src/Common/Log.cpp +++ b/src/Common/Log.cpp @@ -21,7 +21,24 @@ bool InitLog(const TString& rkFilename) { fopen_s(&gpLogFile, *rkFilename, "w"); gLogFilename = rkFilename; - if (!gpLogFile) return false; + + if (!gpLogFile) + { + TString FileName = rkFilename.GetFileName(false); + TString Extension = rkFilename.GetFileExtension(); + int Num = 0; + + while (!gpLogFile) + { + if (Num > 999) break; + TString NewFilename = FileName + "_" + TString::FromInt32(Num, 0, 10) + "." + Extension; + fopen_s(&gpLogFile, *NewFilename, "w"); + Num++; + } + + if (!gpLogFile) + return false; + } // Print initial message to log time_t RawTime;