diff --git a/source/lib/file/file_system.cpp b/source/lib/file/file_system.cpp index b802e79095..7545b66050 100644 --- a/source/lib/file/file_system.cpp +++ b/source/lib/file/file_system.cpp @@ -48,20 +48,6 @@ bool DirectoryExists(const OsPath& path) } -bool FileExists(const OsPath& pathname) -{ - try - { - return std::filesystem::is_regular_file(pathname.string()); - } - catch (std::filesystem::filesystem_error& err) - { - debug_printf("FileExists: failed to check if file '%s' exists, reason: %s\n", pathname.string8().c_str(), err.what()); - } - return false; -} - - Status GetFileInfo(const OsPath& pathname, CFileInfo* pPtrInfo) { try diff --git a/source/lib/file/file_system.h b/source/lib/file/file_system.h index a8e97e8a74..46fca70670 100644 --- a/source/lib/file/file_system.h +++ b/source/lib/file/file_system.h @@ -36,7 +36,6 @@ #include bool DirectoryExists(const OsPath& path); -bool FileExists(const OsPath& pathname); // (bundling size and mtime avoids a second expensive call to stat()) class CFileInfo diff --git a/source/main.cpp b/source/main.cpp index 4fd9474fb2..54a715b37a 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -98,6 +98,7 @@ that of Atlas depending on commandline parameters. #include #include #include +#include #include #include #include @@ -549,7 +550,7 @@ static void RunGameOrAtlas(const std::span argv) if (isVisualReplay || isNonVisualReplay) { - if (!FileExists(replayFile)) + if (!std::filesystem::is_regular_file(replayFile.string())) { debug_printf("ERROR: The requested replay file '%s' does not exist!\n", replayFile.string8().c_str()); return; @@ -570,7 +571,7 @@ static void RunGameOrAtlas(const std::span argv) debug_printf("Skipping file '%s' which does not have a mod file extension.\n", modPath.string8().c_str()); continue; } - if (!FileExists(modPath)) + if (!std::filesystem::is_regular_file(modPath.string())) { debug_printf("ERROR: The mod file '%s' does not exist!\n", modPath.string8().c_str()); continue; diff --git a/source/ps/GameSetup/GameSetup.cpp b/source/ps/GameSetup/GameSetup.cpp index 8f97edea79..532a7c15d6 100644 --- a/source/ps/GameSetup/GameSetup.cpp +++ b/source/ps/GameSetup/GameSetup.cpp @@ -105,6 +105,7 @@ #include #include #include +#include #include #include #include @@ -877,7 +878,7 @@ bool Autostart(const CmdLineArgs& args) bool AutostartVisualReplay(const std::string& replayFile) { - if (!FileExists(OsPath(replayFile))) + if (!std::filesystem::is_regular_file(replayFile)) return false; g_Game = new CGame(false); diff --git a/source/ps/GameSetup/Paths.cpp b/source/ps/GameSetup/Paths.cpp index 8fd8d331e5..552e514af8 100644 --- a/source/ps/GameSetup/Paths.cpp +++ b/source/ps/GameSetup/Paths.cpp @@ -187,7 +187,7 @@ Paths::Paths(const CmdLineArgs& args) } // make sure it's valid - if(!FileExists(pathname)) + if(!std::filesystem::is_regular_file(pathname.string())) { LOGERROR("Cannot find executable (expected at '%s')", pathname.string8()); WARN_IF_ERR(StatusFromErrno()); diff --git a/source/ps/Util.cpp b/source/ps/Util.cpp index ada1d6a70b..1ac56c268b 100644 --- a/source/ps/Util.cpp +++ b/source/ps/Util.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -34,6 +34,7 @@ #include "ps/Pyrogenesis.h" #include +#include #include #include #include @@ -107,7 +108,7 @@ OsPath createDateIndexSubdirectory(const OsPath& parentDir) sprintf_s(directory, ARRAY_SIZE(directory), "%04d-%02d-%02d_%04d", now->tm_year+1900, now->tm_mon+1, now->tm_mday, ++i); path = parentDir / CStr(directory); - if (DirectoryExists(path) || FileExists(path)) + if (DirectoryExists(path) || std::filesystem::is_regular_file(path.string())) continue; if (CreateDirectories(path, 0700, ++tries > maxTries) == INFO::OK) diff --git a/source/ps/VisualReplay.cpp b/source/ps/VisualReplay.cpp index b5c5dc05cc..7b3bbcf59e 100644 --- a/source/ps/VisualReplay.cpp +++ b/source/ps/VisualReplay.cpp @@ -84,7 +84,7 @@ bool VisualReplay::StartVisualReplay(const OsPath& directory) const OsPath replayFile = VisualReplay::GetDirectoryPath() / directory / L"commands.txt"; - if (!FileExists(replayFile)) + if (!std::filesystem::is_regular_file(replayFile.string())) return false; g_Game = new CGame(false); @@ -93,7 +93,7 @@ bool VisualReplay::StartVisualReplay(const OsPath& directory) bool VisualReplay::ReadCacheFile(const ScriptInterface& scriptInterface, JS::MutableHandleObject cachedReplaysObject) { - if (!FileExists(GetCacheFilePath())) + if (!std::filesystem::is_regular_file(GetCacheFilePath().string())) return false; std::ifstream cacheStream(OsString(GetCacheFilePath())); @@ -192,7 +192,7 @@ JS::HandleObject VisualReplay::ReloadReplayCache(const ScriptInterface& scriptIn { if (compareFiles) { - if (!FileExists(replayFile)) + if (!std::filesystem::is_regular_file(replayFile.string())) continue; CFileInfo fileInfo; GetFileInfo(replayFile, &fileInfo); @@ -208,7 +208,7 @@ JS::HandleObject VisualReplay::ReloadReplayCache(const ScriptInterface& scriptIn JS::RootedValue replayData(rq.cx, LoadReplayData(scriptInterface, directory)); if (replayData.isNull()) { - if (!FileExists(replayFile)) + if (!std::filesystem::is_regular_file(replayFile.string())) continue; CFileInfo fileInfo; GetFileInfo(replayFile, &fileInfo); @@ -363,7 +363,7 @@ JS::Value VisualReplay::LoadReplayData(const ScriptInterface& scriptInterface, c // The directory argument must not be constant, otherwise concatenating will fail const OsPath replayFile = GetDirectoryPath() / directory / L"commands.txt"; - if (!FileExists(replayFile)) + if (!std::filesystem::is_regular_file(replayFile.string())) return JS::NullValue(); // Get file size and modification date @@ -461,7 +461,7 @@ JS::Value VisualReplay::GetReplayAttributes(const ScriptInterface& scriptInterfa // Return empty object if file doesn't exist const OsPath replayFile = GetDirectoryPath() / directoryName / L"commands.txt"; - if (!FileExists(replayFile)) + if (!std::filesystem::is_regular_file(replayFile.string())) return attribs; // Open file @@ -500,7 +500,7 @@ bool VisualReplay::HasReplayMetadata(const OsPath& directoryName) { const OsPath filePath(GetDirectoryPath() / directoryName / L"metadata.json"); - if (!FileExists(filePath)) + if (!std::filesystem::is_regular_file(filePath.string())) return false; CFileInfo fileInfo;