Skip to content

Commit 8ea85dd

Browse files
authored
Merge pull request #2439 from ivan-mogilko/361--warningslog-location
Engine: hotfix certain platforms to not save "warnings.log" in current working dir
2 parents 69f6960 + 965d4ec commit 8ea85dd

File tree

5 files changed

+33
-6
lines changed

5 files changed

+33
-6
lines changed

Engine/debug/debug.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,23 +161,32 @@ void SDL_Log_Output(void* /*userdata*/, int category, SDL_LogPriority priority,
161161
// Log configuration
162162
// ----------------------------------------------------------------------------
163163

164-
PDebugOutput create_log_output(const String &name, const String &path = "", LogFile::OpenMode open_mode = LogFile::kLogFile_Overwrite)
164+
// Create a new log output by ID
165+
PDebugOutput create_log_output(const String &name, const String &dir = "", const String &filename = "",
166+
LogFile::OpenMode open_mode = LogFile::kLogFile_Overwrite)
165167
{
166-
// Else create new one, if we know this ID
167168
if (name.CompareNoCase(OutputSystemID) == 0)
168169
{
169170
return DbgMgr.RegisterOutput(OutputSystemID, AGSPlatformDriver::GetDriver(), kDbgMsg_None);
170171
}
171172
else if (name.CompareNoCase(OutputFileID) == 0)
172173
{
173174
DebugLogFile.reset(new LogFile());
174-
String logfile_path = path;
175-
if (logfile_path.IsEmpty())
175+
String logfile_dir = dir;
176+
if (dir.IsEmpty())
176177
{
177178
FSLocation fs = platform->GetAppOutputDirectory();
178179
CreateFSDirs(fs);
179-
logfile_path = Path::ConcatPaths(fs.FullDir, "ags.log");
180+
logfile_dir = fs.FullDir;
180181
}
182+
else if (Path::IsRelativePath(dir) && platform->IsLocalDirRestricted())
183+
{
184+
FSLocation fs = GetGameUserDataDir();
185+
CreateFSDirs(fs);
186+
logfile_dir = fs.FullDir;
187+
}
188+
String logfilename = filename.IsEmpty() ? "ags.log" : filename;
189+
String logfile_path = Path::ConcatPaths(logfile_dir, logfilename);
181190
if (!DebugLogFile->OpenFile(logfile_path, open_mode))
182191
return nullptr;
183192
Debug::Printf(kDbgMsg_Info, "Logging to %s", logfile_path.GetCStr());
@@ -336,7 +345,7 @@ void apply_debug_config(const ConfigTree &cfg)
336345
// then open "warnings.log" for printing script warnings.
337346
if (game.options[OPT_DEBUGMODE] != 0 && !DebugLogFile)
338347
{
339-
auto dbgout = create_log_output(OutputFileID, "warnings.log", LogFile::kLogFile_OverwriteAtFirstMessage);
348+
auto dbgout = create_log_output(OutputFileID, "./", "warnings.log", LogFile::kLogFile_OverwriteAtFirstMessage);
340349
if (dbgout)
341350
{
342351
dbgout->SetGroupFilter(kDbgGroup_Game, kDbgMsg_Warn);

Engine/platform/base/agsplatform_xdg_unix.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ FSLocation AGSPlatformXDGUnix::GetAppOutputDirectory()
8484
return UserDataDirectory;
8585
}
8686

87+
bool AGSPlatformXDGUnix::IsLocalDirRestricted()
88+
{
89+
// Let them to create temp files in the current working dir
90+
return false;
91+
}
92+
8793
uint64_t AGSPlatformXDGUnix::GetDiskFreeSpaceMB(const String &path) {
8894
// placeholder
8995
return 100;

Engine/platform/base/agsplatform_xdg_unix.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ struct AGSPlatformXDGUnix : AGSPlatformDriver {
3131
FSLocation GetUserConfigDirectory() override;
3232
FSLocation GetUserGlobalConfigDirectory() override;
3333
FSLocation GetAppOutputDirectory() override;
34+
bool IsLocalDirRestricted() override;
3435
uint64_t GetDiskFreeSpaceMB(const AGS::Common::String &path) override;
3536
const char* GetBackendFailUserHint() override;
3637
};

Engine/platform/base/agsplatformdriver.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ class AGSPlatformDriver
9595
virtual FSLocation GetUserGlobalConfigDirectory() { return FSLocation("."); }
9696
// Get default directory for program output (logs)
9797
virtual FSLocation GetAppOutputDirectory() { return FSLocation("."); }
98+
// Tells whether it's not permitted to write to the local directory (cwd, or game dir),
99+
// and only specified user/app directories should be used.
100+
// FIXME: this is a part of a hotfix, review uses of this function later.
101+
virtual bool IsLocalDirRestricted() { return true; }
98102
// Returns array of characters illegal to use in file names
99103
virtual const char *GetIllegalFileChars() { return "\\/"; }
100104
virtual const char *GetDiskWriteAccessTroubleshootingText();

Engine/platform/windows/acplwin.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ struct AGSWin32 : AGSPlatformDriver {
6262
FSLocation GetUserConfigDirectory() override;
6363
FSLocation GetUserGlobalConfigDirectory() override;
6464
FSLocation GetAppOutputDirectory() override;
65+
bool IsLocalDirRestricted() override;
6566
const char *GetIllegalFileChars() override;
6667
const char *GetGraphicsTroubleshootingText() override;
6768
uint64_t GetDiskFreeSpaceMB(const String &path) override;
@@ -240,6 +241,12 @@ FSLocation AGSWin32::GetAppOutputDirectory()
240241
return win32OutputDirectory;
241242
}
242243

244+
bool AGSWin32::IsLocalDirRestricted()
245+
{
246+
// Let them to create temp files in the current working dir
247+
return false;
248+
}
249+
243250
const char *AGSWin32::GetIllegalFileChars()
244251
{
245252
return "\\/:?\"<>|*";

0 commit comments

Comments
 (0)