Attempt to find a new filename for the log if we can't open the requested one

This commit is contained in:
parax0 2016-03-20 06:39:07 -06:00
parent 5009c08c87
commit 8dddbd8b92
1 changed files with 18 additions and 1 deletions

View File

@ -21,7 +21,24 @@ bool InitLog(const TString& rkFilename)
{ {
fopen_s(&gpLogFile, *rkFilename, "w"); fopen_s(&gpLogFile, *rkFilename, "w");
gLogFilename = rkFilename; 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 // Print initial message to log
time_t RawTime; time_t RawTime;