diff --git a/source/lib/file/file_system.cpp b/source/lib/file/file_system.cpp index 6d3eef4d78..d7da0d1c3b 100644 --- a/source/lib/file/file_system.cpp +++ b/source/lib/file/file_system.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2015 Wildfire Games +/* Copyright (c) 2016 Wildfire Games * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the diff --git a/source/lib/file/file_system.h b/source/lib/file/file_system.h index 95589b01f6..867adadf35 100644 --- a/source/lib/file/file_system.h +++ b/source/lib/file/file_system.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2010 Wildfire Games +/* Copyright (c) 2016 Wildfire Games * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -80,6 +80,7 @@ LIB_API Status GetDirectoryEntries(const OsPath& path, CFileInfos* files, Direct // same as boost::filesystem::create_directories, except that mkdir is invoked with // instead of 0755. +// If the breakpoint is enabled, debug_break will be called if the directory didn't exist and couldn't be created. LIB_API Status CreateDirectories(const OsPath& path, mode_t mode, bool breakpoint = true); LIB_API Status DeleteDirectory(const OsPath& dirPath); diff --git a/source/ps/Replay.cpp b/source/ps/Replay.cpp index cf2e458c0e..1896a80fd1 100644 --- a/source/ps/Replay.cpp +++ b/source/ps/Replay.cpp @@ -70,7 +70,7 @@ void CReplayLogger::StartGame(JS::MutableHandleValue attribs) m_ScriptInterface.SetProperty(attribs, "engine_version", CStr(engine_version)); m_ScriptInterface.SetProperty(attribs, "mods", g_modsLoaded); - m_Directory = getDateIndexSubdirectory(VisualReplay::GetDirectoryName()); + m_Directory = createDateIndexSubdirectory(VisualReplay::GetDirectoryName()); debug_printf("Writing replay to %s\n", m_Directory.string8().c_str()); m_Stream = new std::ofstream(OsString(m_Directory / L"commands.txt").c_str(), std::ofstream::out | std::ofstream::trunc); diff --git a/source/ps/Util.cpp b/source/ps/Util.cpp index e0070e628b..5e493d47d8 100644 --- a/source/ps/Util.cpp +++ b/source/ps/Util.cpp @@ -196,7 +196,7 @@ Status tex_write(Tex* t, const VfsPath& filename) /** * Return an unused directory, based on date and index (for example 2016-02-09_0001) */ -OsPath getDateIndexSubdirectory(const OsPath& parentDir) +OsPath createDateIndexSubdirectory(const OsPath& parentDir) { const std::time_t timestamp = std::time(nullptr); const struct std::tm* now = std::localtime(×tamp); diff --git a/source/ps/Util.h b/source/ps/Util.h index 890d0d783b..accda37b61 100644 --- a/source/ps/Util.h +++ b/source/ps/Util.h @@ -26,7 +26,7 @@ extern void WriteSystemInfo(); extern const wchar_t* ErrorString(int err); -extern OsPath getDateIndexSubdirectory(const OsPath& parentDir); +extern OsPath createDateIndexSubdirectory(const OsPath& parentDir); extern void WriteScreenshot(const VfsPath& extension); extern void WriteBigScreenshot(const VfsPath& extension, int tiles); diff --git a/source/simulation2/Simulation2.cpp b/source/simulation2/Simulation2.cpp index 1bde736906..7b978e1deb 100644 --- a/source/simulation2/Simulation2.cpp +++ b/source/simulation2/Simulation2.cpp @@ -76,10 +76,11 @@ public: CFG_GET_VAL("serializationtest", m_EnableSerializationTest); } - m_OOSLogPath = getDateIndexSubdirectory(psLogDir() / "oos_logs"); - if (m_EnableOOSLog) + { + m_OOSLogPath = createDateIndexSubdirectory(psLogDir() / "oos_logs"); debug_printf("Writing ooslogs to %s\n", m_OOSLogPath.string8().c_str()); + } } ~CSimulation2Impl() @@ -296,7 +297,7 @@ void CSimulation2Impl::ReportSerializationFailure( SerializationTestState* primaryStateBefore, SerializationTestState* primaryStateAfter, SerializationTestState* secondaryStateBefore, SerializationTestState* secondaryStateAfter) { - const OsPath path = getDateIndexSubdirectory(psLogDir() / "serializationtest"); + const OsPath path = createDateIndexSubdirectory(psLogDir() / "serializationtest"); debug_printf("Writing serializationtest-data to %s\n", path.string8().c_str()); // Clean up obsolete files from previous runs @@ -555,6 +556,12 @@ void CSimulation2Impl::DumpState() const OsPath path = m_OOSLogPath / name.str(); std::ofstream file (OsString(path).c_str(), std::ofstream::out | std::ofstream::trunc); + if (!DirectoryExists(m_OOSLogPath)) + { + LOGWARNING("OOS-log directory %s was deleted, creating it again.", m_OOSLogPath.string8().c_str()); + CreateDirectories(m_OOSLogPath, 0700); + } + file << "State hash: " << std::hex; std::string hashRaw; m_ComponentManager.ComputeStateHash(hashRaw, false); @@ -590,6 +597,8 @@ void CSimulation2::EnableOOSLog() return; m->m_EnableOOSLog = true; + m->m_OOSLogPath = createDateIndexSubdirectory(psLogDir() / "oos_logs"); + debug_printf("Writing ooslogs to %s\n", m->m_OOSLogPath.string8().c_str()); }