From 5b302658a3a2ddcd4b5d5000b94d5ca8ff279fe5 Mon Sep 17 00:00:00 2001 From: janwas Date: Tue, 4 Aug 2009 19:57:53 +0000 Subject: [PATCH] # fix permissions of created directories also took the opportunity to move file_system_posix to file_system since a further FS abstraction layer = YAGNI. also namespaced file_system_util. This was SVN commit r7074. --- source/graphics/MapWriter.cpp | 2 +- source/graphics/ObjectManager.cpp | 4 +- source/graphics/TextureManager.cpp | 2 +- source/graphics/tests/test_MeshManager.h | 14 +- source/lib/file/archive/archive_zip.cpp | 7 +- source/lib/file/file_system.cpp | 142 ++++++++++++++++ source/lib/file/file_system.h | 14 ++ source/lib/file/file_system_posix.cpp | 151 ------------------ source/lib/file/file_system_posix.h | 45 ------ source/lib/file/file_system_util.cpp | 15 +- source/lib/file/file_system_util.h | 14 +- source/lib/file/vfs/vfs.cpp | 2 +- source/lib/file/vfs/vfs_populate.cpp | 4 +- source/ps/GameSetup/GameSetup.cpp | 2 +- source/ps/Interact.cpp | 2 +- source/ps/Util.cpp | 4 +- source/ps/i18n.cpp | 6 +- source/ps/scripting/JSInterface_VFS.cpp | 4 +- .../simulation/EntityTemplateCollection.cpp | 2 +- source/simulation/FormationCollection.cpp | 2 +- source/simulation/TechnologyCollection.cpp | 2 +- 21 files changed, 201 insertions(+), 239 deletions(-) delete mode 100644 source/lib/file/file_system_posix.cpp delete mode 100644 source/lib/file/file_system_posix.h diff --git a/source/graphics/MapWriter.cpp b/source/graphics/MapWriter.cpp index b97d1aaf46..c105cdb0c7 100644 --- a/source/graphics/MapWriter.cpp +++ b/source/graphics/MapWriter.cpp @@ -533,7 +533,7 @@ void CMapWriter::RewriteAllMaps(CTerrain* pTerrain, CUnitManager* pUnitMan, CLightEnv* pLightEnv, CCamera* pCamera, CCinemaManager* pCinema) { VfsPaths pathnames; - (void)fs_GetPathnames(g_VFS, "maps/scenarios", "*.pmp", pathnames); + (void)fs_util::GetPathnames(g_VFS, "maps/scenarios", "*.pmp", pathnames); for (size_t i = 0; i < pathnames.size(); i++) { const char* pathname = pathnames[i].string().c_str(); diff --git a/source/graphics/ObjectManager.cpp b/source/graphics/ObjectManager.cpp index d72b1e49af..a27002110f 100644 --- a/source/graphics/ObjectManager.cpp +++ b/source/graphics/ObjectManager.cpp @@ -177,10 +177,10 @@ static LibError GetObjectName_ThunkCb(const VfsPath& pathname, const FileInfo& U void CObjectManager::GetAllObjectNames(std::vector& names) { - (void)fs_ForEachFile(g_VFS, "art/actors/", GetObjectName_ThunkCb, (uintptr_t)&names, "*.xml", DIR_RECURSIVE); + (void)fs_util::ForEachFile(g_VFS, "art/actors/", GetObjectName_ThunkCb, (uintptr_t)&names, "*.xml", fs_util::DIR_RECURSIVE); } void CObjectManager::GetPropObjectNames(std::vector& names) { - (void)fs_ForEachFile(g_VFS, "art/actors/props/", GetObjectName_ThunkCb, (uintptr_t)&names, "*.xml", DIR_RECURSIVE); + (void)fs_util::ForEachFile(g_VFS, "art/actors/props/", GetObjectName_ThunkCb, (uintptr_t)&names, "*.xml", fs_util::DIR_RECURSIVE); } diff --git a/source/graphics/TextureManager.cpp b/source/graphics/TextureManager.cpp index a738684683..1a9ad5395e 100644 --- a/source/graphics/TextureManager.cpp +++ b/source/graphics/TextureManager.cpp @@ -114,7 +114,7 @@ void CTextureManager::DeleteTexture(CTextureEntry* entry) void CTextureManager::LoadTextures(const CTerrainPropertiesPtr& props, const char* dir) { VfsPaths pathnames; - if(fs_GetPathnames(g_VFS, dir, 0, pathnames) < 0) + if(fs_util::GetPathnames(g_VFS, dir, 0, pathnames) < 0) return; for(size_t i = 0; i < pathnames.size(); i++) { diff --git a/source/graphics/tests/test_MeshManager.h b/source/graphics/tests/test_MeshManager.h index 554292f86d..efafe30728 100644 --- a/source/graphics/tests/test_MeshManager.h +++ b/source/graphics/tests/test_MeshManager.h @@ -19,7 +19,6 @@ #include "lib/file/vfs/vfs.h" #include "lib/file/io/io.h" -#include "lib/file/file_system_posix.h" #include "graphics/ColladaManager.h" #include "graphics/MeshManager.h" @@ -53,12 +52,12 @@ class TestMeshManager : public CxxTest::TestSuite // Make sure the required directories doesn't exist when we start, // in case the previous test aborted and left them full of junk if(exists(MOD_PATH)) - fsPosix.DeleteDirectory(MOD_PATH); + DeleteDirectory(MOD_PATH); if(exists(CACHE_PATH)) - fsPosix.DeleteDirectory(CACHE_PATH); + DeleteDirectory(CACHE_PATH); - TS_ASSERT(fs::create_directory(MOD_PATH.external_directory_string())); - TS_ASSERT(fs::create_directory(CACHE_PATH.external_directory_string())); + TS_ASSERT_OK(CreateDirectories(MOD_PATH.external_directory_string(), 0700)); + TS_ASSERT_OK(CreateDirectories(CACHE_PATH.external_directory_string(), 0700)); g_VFS = CreateVfs(20*MiB); @@ -73,8 +72,8 @@ class TestMeshManager : public CxxTest::TestSuite void deinitVfs() { -// fsPosix.DeleteDirectory(MOD_PATH); -// fsPosix.DeleteDirectory(CACHE_PATH); +// DeleteDirectory(MOD_PATH); +// DeleteDirectory(CACHE_PATH); g_VFS.reset(); } @@ -99,7 +98,6 @@ class TestMeshManager : public CxxTest::TestSuite CColladaManager* colladaManager; CMeshManager* meshManager; - FileSystem_Posix fsPosix; public: diff --git a/source/lib/file/archive/archive_zip.cpp b/source/lib/file/archive/archive_zip.cpp index 1f5950f89e..51f7f1b68a 100644 --- a/source/lib/file/archive/archive_zip.cpp +++ b/source/lib/file/archive/archive_zip.cpp @@ -35,13 +35,10 @@ #include "codec_zlib.h" #include "stream.h" #include "lib/file/file.h" -#include "lib/file/file_system_posix.h" #include "lib/file/io/io.h" #include "lib/file/io/io_align.h" // BLOCK_SIZE #include "lib/file/io/write_buffer.h" -static FileSystem_Posix s_fileSystemPosix; - //----------------------------------------------------------------------------- // Zip archive definitions @@ -377,7 +374,7 @@ public: m_file->Open(pathname, 'r'); FileInfo fileInfo; - s_fileSystemPosix.GetFileInfo(pathname, &fileInfo); + GetFileInfo(pathname, &fileInfo); m_fileSize = fileInfo.Size(); const size_t minFileSize = sizeof(LFH)+sizeof(CDFH)+sizeof(ECDR); debug_assert(m_fileSize >= off_t(minFileSize)); @@ -554,7 +551,7 @@ public: LibError AddFile(const fs::path& pathname) { FileInfo fileInfo; - RETURN_ERR(s_fileSystemPosix.GetFileInfo(pathname, &fileInfo)); + RETURN_ERR(GetFileInfo(pathname, &fileInfo)); const off_t usize = fileInfo.Size(); // skip 0-length files. // rationale: zip.cpp needs to determine whether a CDFH entry is diff --git a/source/lib/file/file_system.cpp b/source/lib/file/file_system.cpp index 1ca8ba4ad9..60f1869ede 100644 --- a/source/lib/file/file_system.cpp +++ b/source/lib/file/file_system.cpp @@ -17,3 +17,145 @@ #include "precompiled.h" #include "file_system.h" + +#include +#include +#include + +#include "lib/path_util.h" +#include "lib/posix/posix_filesystem.h" + + +struct DirDeleter +{ + void operator()(DIR* osDir) const + { + const int ret = closedir(osDir); + debug_assert(ret == 0); + } +}; + +// is name "." or ".."? +static bool IsDummyDirectory(const char* name) +{ + if(name[0] != '.') + return false; + return (name[1] == '\0' || (name[1] == '.' && name[2] == '\0')); +} + +LibError GetDirectoryEntries(const fs::path& path, FileInfos* files, DirectoryNames* subdirectoryNames) +{ + // open directory + errno = 0; + DIR* pDir = opendir(path.external_file_string().c_str()); + if(!pDir) + return LibError_from_errno(false); + shared_ptr osDir(pDir, DirDeleter()); + + for(;;) + { + errno = 0; + struct dirent* osEnt = readdir(osDir.get()); + if(!osEnt) + { + // no error, just no more entries to return + if(!errno) + return INFO::OK; + return LibError_from_errno(); + } + + const char* name = osEnt->d_name; + RETURN_ERR(path_component_validate(name)); + + // get file information (mode, size, mtime) + struct stat s; +#if OS_WIN + // .. wposix readdir has enough information to return dirent + // status directly (much faster than calling stat). + RETURN_ERR(readdir_stat_np(osDir.get(), &s)); +#else + // .. call regular stat(). + errno = 0; + const fs::path pathname(path/name); + if(stat(pathname.external_directory_string().c_str(), &s) != 0) + return LibError_from_errno(); +#endif + + if(files && S_ISREG(s.st_mode)) + files->push_back(FileInfo(name, s.st_size, s.st_mtime)); + else if(subdirectoryNames && S_ISDIR(s.st_mode) && !IsDummyDirectory(name)) + subdirectoryNames->push_back(name); + } +} + + +LibError GetFileInfo(const fs::path& pathname, FileInfo* pfileInfo) +{ + char osPathname[PATH_MAX]; + path_copy(osPathname, pathname.external_directory_string().c_str()); + + // if path ends in slash, remove it (required by stat) + char* last_char = osPathname+strlen(osPathname)-1; + if(path_is_dir_sep(*last_char)) + *last_char = '\0'; + + errno = 0; + struct stat s; + memset(&s, 0, sizeof(s)); + if(stat(osPathname, &s) != 0) + return LibError_from_errno(); + + const char* name = path_name_only(osPathname); + *pfileInfo = FileInfo(name, s.st_size, s.st_mtime); + return INFO::OK; +} + + +LibError CreateDirectories(const fs::path& path, mode_t mode) +{ + if(path.empty() || fs::exists(path)) + { + if(!path.empty() && !fs::is_directory(path)) // encountered a file + WARN_RETURN(ERR::FAIL); + return INFO::OK; + } + + RETURN_ERR(CreateDirectories(path.branch_path(), mode)); + + char osPath[PATH_MAX]; + path_copy(osPath, path.external_directory_string().c_str()); + errno = 0; + if(mkdir(osPath, mode) != 0) + return LibError_from_errno(); + + return INFO::OK; +} + + +LibError DeleteDirectory(const fs::path& path) +{ + // note: we have to recursively empty the directory before it can + // be deleted (required by Windows and POSIX rmdir()). + + FileInfos files; DirectoryNames subdirectoryNames; + RETURN_ERR(GetDirectoryEntries(path, &files, &subdirectoryNames)); + + // delete files + for(size_t i = 0; i < files.size(); i++) + { + const fs::path pathname(path/files[i].Name()); + errno = 0; + if(unlink(pathname.external_file_string().c_str()) != 0) + return LibError_from_errno(); + } + + // recurse over subdirectoryNames + for(size_t i = 0; i < subdirectoryNames.size(); i++) + RETURN_ERR(DeleteDirectory(path/subdirectoryNames[i])); + + errno = 0; + if(rmdir(path.external_directory_string().c_str()) != 0) + return LibError_from_errno(); + + return INFO::OK; +} diff --git a/source/lib/file/file_system.h b/source/lib/file/file_system.h index c6dad7a2e5..82cc1d2eec 100644 --- a/source/lib/file/file_system.h +++ b/source/lib/file/file_system.h @@ -51,7 +51,21 @@ private: time_t m_mtime; }; +extern LibError GetFileInfo(const fs::path& pathname, FileInfo* fileInfo); + typedef std::vector FileInfos; typedef std::vector DirectoryNames; +// jw 2007-12-20: we'd love to replace this with boost::filesystem, +// but basic_directory_iterator does not yet cache file_size and +// last_write_time in file_status. (they each entail a stat() call, +// which is unacceptably slow.) +extern LibError GetDirectoryEntries(const fs::path& path, FileInfos* files, DirectoryNames* subdirectoryNames); + +// same as fs::create_directories, except that mkdir is invoked with +// instead of 0755. +extern LibError CreateDirectories(const fs::path& path, mode_t mode); + +extern LibError DeleteDirectory(const fs::path& dirPath); + #endif // #ifndef INCLUDED_FILE_SYSTEM diff --git a/source/lib/file/file_system_posix.cpp b/source/lib/file/file_system_posix.cpp deleted file mode 100644 index 600f8df0e5..0000000000 --- a/source/lib/file/file_system_posix.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/* Copyright (C) 2009 Wildfire Games. - * This file is part of 0 A.D. - * - * 0 A.D. is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * 0 A.D. is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with 0 A.D. If not, see . - */ - -/* - * file layer on top of POSIX. avoids the need for absolute paths and - * provides fast I/O. - */ - -#include "precompiled.h" -#include "file_system_posix.h" - -#include -#include -#include - -#include "lib/path_util.h" -#include "lib/posix/posix_filesystem.h" - - -struct DirDeleter -{ - void operator()(DIR* osDir) const - { - const int ret = closedir(osDir); - debug_assert(ret == 0); - } -}; - -// is name "." or ".."? -static bool IsDummyDirectory(const char* name) -{ - if(name[0] != '.') - return false; - return (name[1] == '\0' || (name[1] == '.' && name[2] == '\0')); -} - -/*virtual*/ LibError FileSystem_Posix::GetDirectoryEntries(const fs::path& path, FileInfos* files, DirectoryNames* subdirectoryNames) const -{ - // open directory - errno = 0; - DIR* pDir = opendir(path.external_file_string().c_str()); - if(!pDir) - return LibError_from_errno(false); - shared_ptr osDir(pDir, DirDeleter()); - - for(;;) - { - errno = 0; - struct dirent* osEnt = readdir(osDir.get()); - if(!osEnt) - { - // no error, just no more entries to return - if(!errno) - return INFO::OK; - return LibError_from_errno(); - } - - const char* name = osEnt->d_name; - RETURN_ERR(path_component_validate(name)); - - // get file information (mode, size, mtime) - struct stat s; -#if OS_WIN - // .. wposix readdir has enough information to return dirent - // status directly (much faster than calling stat). - RETURN_ERR(readdir_stat_np(osDir.get(), &s)); -#else - // .. call regular stat(). - errno = 0; - const fs::path pathname(path/name); - if(stat(pathname.external_directory_string().c_str(), &s) != 0) - return LibError_from_errno(); -#endif - - if(files && S_ISREG(s.st_mode)) - files->push_back(FileInfo(name, s.st_size, s.st_mtime)); - else if(subdirectoryNames && S_ISDIR(s.st_mode) && !IsDummyDirectory(name)) - subdirectoryNames->push_back(name); - } -} - - -LibError FileSystem_Posix::GetFileInfo(const fs::path& pathname, FileInfo* pfileInfo) const -{ - char osPathname[PATH_MAX]; - path_copy(osPathname, pathname.external_directory_string().c_str()); - - // if path ends in slash, remove it (required by stat) - char* last_char = osPathname+strlen(osPathname)-1; - if(path_is_dir_sep(*last_char)) - *last_char = '\0'; - - errno = 0; - struct stat s; - memset(&s, 0, sizeof(s)); - if(stat(osPathname, &s) != 0) - return LibError_from_errno(); - - const char* name = path_name_only(osPathname); - *pfileInfo = FileInfo(name, s.st_size, s.st_mtime); - return INFO::OK; -} - - -LibError FileSystem_Posix::DeleteDirectory(const fs::path& path) -{ - // note: we have to recursively empty the directory before it can - // be deleted (required by Windows and POSIX rmdir()). - - FileInfos files; DirectoryNames subdirectoryNames; - RETURN_ERR(GetDirectoryEntries(path, &files, &subdirectoryNames)); - - // delete files - for(size_t i = 0; i < files.size(); i++) - { - const fs::path pathname(path/files[i].Name()); - errno = 0; - if(unlink(pathname.external_file_string().c_str()) != 0) - return LibError_from_errno(); - } - - // recurse over subdirectoryNames - for(size_t i = 0; i < subdirectoryNames.size(); i++) - RETURN_ERR(DeleteDirectory(path/subdirectoryNames[i])); - - errno = 0; - if(rmdir(path.external_directory_string().c_str()) != 0) - return LibError_from_errno(); - - return INFO::OK; -} - - -PIFileSystem_Posix CreateFileSystem_Posix() -{ - return PIFileSystem_Posix(new FileSystem_Posix); -} diff --git a/source/lib/file/file_system_posix.h b/source/lib/file/file_system_posix.h deleted file mode 100644 index c3a4be1d3f..0000000000 --- a/source/lib/file/file_system_posix.h +++ /dev/null @@ -1,45 +0,0 @@ -/* Copyright (C) 2009 Wildfire Games. - * This file is part of 0 A.D. - * - * 0 A.D. is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * 0 A.D. is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with 0 A.D. If not, see . - */ - -/* - * file layer on top of POSIX. avoids the need for absolute paths and - * provides fast I/O. - */ - -#ifndef INCLUDED_FILE_SYSTEM_POSIX -#define INCLUDED_FILE_SYSTEM_POSIX - -#include "lib/file/file_system.h" - -// jw 2007-12-20: we'd love to replace this with boost::filesystem, -// but basic_directory_iterator does not yet cache file_size and -// last_write_time in file_status. (they each entail a stat() call, -// which is unacceptably slow.) - -struct FileSystem_Posix -{ - virtual LibError GetFileInfo(const fs::path& pathname, FileInfo* fileInfo) const; - virtual LibError GetDirectoryEntries(const fs::path& path, FileInfos* files, DirectoryNames* subdirectoryNames) const; - - LibError DeleteDirectory(const fs::path& dirPath); -}; - -typedef shared_ptr PIFileSystem_Posix; - -LIB_API PIFileSystem_Posix CreateFileSystem_Posix(); - -#endif // #ifndef INCLUDED_FILE_SYSTEM_POSIX diff --git a/source/lib/file/file_system_util.cpp b/source/lib/file/file_system_util.cpp index a761403c15..a3bf40b5ab 100644 --- a/source/lib/file/file_system_util.cpp +++ b/source/lib/file/file_system_util.cpp @@ -28,7 +28,10 @@ #include "lib/path_util.h" #include "lib/regex.h" -LibError fs_GetPathnames(const PIVFS& fs, const VfsPath& path, const char* filter, VfsPaths& pathnames) + +namespace fs_util { + +LibError GetPathnames(const PIVFS& fs, const VfsPath& path, const char* filter, VfsPaths& pathnames) { std::vector files; RETURN_ERR(fs->GetDirectoryEntries(path, &files, 0)); @@ -54,7 +57,7 @@ struct FileInfoNameLess : public std::binary_functionGetFileInfo(nextPathname, 0) == INFO::OK); } + +} // namespace fs_util diff --git a/source/lib/file/file_system_util.h b/source/lib/file/file_system_util.h index 832e018ed2..6fdf73c1b0 100644 --- a/source/lib/file/file_system_util.h +++ b/source/lib/file/file_system_util.h @@ -24,10 +24,12 @@ #include "lib/file/vfs/vfs.h" -extern void fs_SortFiles(FileInfos& files); -extern void fs_SortDirectories(DirectoryNames& directories); +namespace fs_util { -extern LibError fs_GetPathnames(const PIVFS& fs, const VfsPath& path, const char* filter, VfsPaths& pathnames); +extern void SortFiles(FileInfos& files); +extern void SortDirectories(DirectoryNames& directories); + +extern LibError GetPathnames(const PIVFS& fs, const VfsPath& path, const char* filter, VfsPaths& pathnames); /** @@ -58,7 +60,7 @@ enum DirFlags * @param flags see DirFlags * @param LibError **/ -extern LibError fs_ForEachFile(const PIVFS& fs, const VfsPath& path, FileCallback cb, uintptr_t cbData, const char* pattern = 0, size_t flags = 0); +extern LibError ForEachFile(const PIVFS& fs, const VfsPath& path, FileCallback cb, uintptr_t cbData, const char* pattern = 0, size_t flags = 0); /** @@ -73,6 +75,8 @@ extern LibError fs_ForEachFile(const PIVFS& fs, const VfsPath& path, FileCallbac * if 0, numbers corresponding to existing files are skipped. * @param nextPathname receives the output. **/ -extern void fs_NextNumberedFilename(const PIVFS& fs, const VfsPath& pathnameFormat, size_t& nextNumber, VfsPath& nextPathname); +extern void NextNumberedFilename(const PIVFS& fs, const VfsPath& pathnameFormat, size_t& nextNumber, VfsPath& nextPathname); + +} // namespace fs_util #endif // #ifndef INCLUDED_FILE_SYSTEM_UTIL diff --git a/source/lib/file/vfs/vfs.cpp b/source/lib/file/vfs/vfs.cpp index 3730af6157..f9cf729608 100644 --- a/source/lib/file/vfs/vfs.cpp +++ b/source/lib/file/vfs/vfs.cpp @@ -42,7 +42,7 @@ public: virtual LibError Mount(const VfsPath& mountPoint, const fs::path& path, size_t flags /* = 0 */, size_t priority /* = 0 */) { debug_assert(vfs_path_IsDirectory(mountPoint)); - fs::create_directories(path); + CreateDirectories(path, 0700); VfsDirectory* directory; CHECK_ERR(vfs_Lookup(mountPoint, &m_rootDirectory, directory, 0, VFS_LOOKUP_ADD|VFS_LOOKUP_CREATE)); diff --git a/source/lib/file/vfs/vfs_populate.cpp b/source/lib/file/vfs/vfs_populate.cpp index 30ac4d7622..851550213a 100644 --- a/source/lib/file/vfs/vfs_populate.cpp +++ b/source/lib/file/vfs/vfs_populate.cpp @@ -23,14 +23,12 @@ #include "vfs_populate.h" #include "lib/path_util.h" -#include "lib/file/file_system_posix.h" #include "lib/file/archive/archive_zip.h" #include "vfs_tree.h" #include "vfs_lookup.h" #include "vfs.h" // error codes -static FileSystem_Posix s_fileSystemPosix; static std::vector s_looseFiles; static size_t s_numArchivedFiles; @@ -49,7 +47,7 @@ public: { FileInfos files; files.reserve(100); DirectoryNames subdirectoryNames; subdirectoryNames.reserve(20); - RETURN_ERR(s_fileSystemPosix.GetDirectoryEntries(m_realDirectory->Path(), &files, &subdirectoryNames)); + RETURN_ERR(GetDirectoryEntries(m_realDirectory->Path(), &files, &subdirectoryNames)); RETURN_ERR(AddFiles(files)); AddSubdirectories(subdirectoryNames); return INFO::OK; diff --git a/source/ps/GameSetup/GameSetup.cpp b/source/ps/GameSetup/GameSetup.cpp index 16c6ff6475..85c2a8cb2d 100644 --- a/source/ps/GameSetup/GameSetup.cpp +++ b/source/ps/GameSetup/GameSetup.cpp @@ -679,7 +679,7 @@ static void InitVfs(const CmdLineArgs& args) const Paths paths(args.GetArg0(), subdirectory); fs::path logs(paths.Logs()); - fs::create_directories(logs); + CreateDirectories(logs, 0700); psSetLogDir(logs.string().c_str()); const size_t cacheSize = ChooseCacheSize(); diff --git a/source/ps/Interact.cpp b/source/ps/Interact.cpp index 9cae5dce9e..2cdf9fb4f0 100644 --- a/source/ps/Interact.cpp +++ b/source/ps/Interact.cpp @@ -992,7 +992,7 @@ static LibError LoadUnitUIThunk( const VfsPath& pathname, const FileInfo& UNUSED } int CSelectedEntities::LoadUnitUiTextures() { - THROW_ERR( fs_ForEachFile(g_VFS, "art/textures/ui/session/icons/", LoadUnitUIThunk, (uintptr_t)&m_unitUITextures, 0, DIR_RECURSIVE)); + THROW_ERR( fs_util::ForEachFile(g_VFS, "art/textures/ui/session/icons/", LoadUnitUIThunk, (uintptr_t)&m_unitUITextures, 0, fs_util::DIR_RECURSIVE)); return 0; } void CSelectedEntities::DestroyUnitUiTextures() diff --git a/source/ps/Util.cpp b/source/ps/Util.cpp index 5e7820c4c0..1ad9d85d10 100644 --- a/source/ps/Util.cpp +++ b/source/ps/Util.cpp @@ -225,7 +225,7 @@ void WriteScreenshot(const char* extension) const VfsPath basenameFormat("screenshots/screenshot%04d"); const VfsPath filenameFormat = fs::change_extension(basenameFormat, extension); VfsPath filename; - fs_NextNumberedFilename(g_VFS, filenameFormat, s_nextScreenshotNumber, filename); + fs_util::NextNumberedFilename(g_VFS, filenameFormat, s_nextScreenshotNumber, filename); const size_t w = (size_t)g_xres, h = (size_t)g_yres; const size_t bpp = 24; @@ -264,7 +264,7 @@ void WriteBigScreenshot(const char* extension, int tiles) const VfsPath basenameFormat("screenshots/screenshot%04d"); const VfsPath filenameFormat = fs::change_extension(basenameFormat, extension); VfsPath filename; - fs_NextNumberedFilename(g_VFS, filenameFormat, s_nextScreenshotNumber, filename); + fs_util::NextNumberedFilename(g_VFS, filenameFormat, s_nextScreenshotNumber, filename); // Slightly ugly and inflexible: Always draw 640*480 tiles onto the screen, and // hope the screen is actually large enough for that. diff --git a/source/ps/i18n.cpp b/source/ps/i18n.cpp index 37b46051fb..56f0aac0f9 100644 --- a/source/ps/i18n.cpp +++ b/source/ps/i18n.cpp @@ -62,7 +62,7 @@ bool I18n::LoadLanguage(const char* name) // Open *.lng with LoadStrings VfsPaths pathnames; - if(fs_GetPathnames(g_VFS, dirname, "*.lng", pathnames) < 0) + if(fs_util::GetPathnames(g_VFS, dirname, "*.lng", pathnames) < 0) return false; for (size_t i = 0; i < pathnames.size(); i++) { @@ -76,7 +76,7 @@ bool I18n::LoadLanguage(const char* name) } // Open *.wrd with LoadDictionary - if(fs_GetPathnames(g_VFS, dirname, "*.wrd", pathnames) < 0) + if(fs_util::GetPathnames(g_VFS, dirname, "*.wrd", pathnames) < 0) return false; for (size_t i = 0; i < pathnames.size(); i++) { @@ -90,7 +90,7 @@ bool I18n::LoadLanguage(const char* name) } // Open *.js with LoadFunctions - if(fs_GetPathnames(g_VFS, dirname, "*.js", pathnames) < 0) + if(fs_util::GetPathnames(g_VFS, dirname, "*.js", pathnames) < 0) return false; for (size_t i = 0; i < pathnames.size(); i++) { diff --git a/source/ps/scripting/JSInterface_VFS.cpp b/source/ps/scripting/JSInterface_VFS.cpp index f2e71f1531..4d17851191 100644 --- a/source/ps/scripting/JSInterface_VFS.cpp +++ b/source/ps/scripting/JSInterface_VFS.cpp @@ -114,12 +114,12 @@ JSBool JSI_VFS::BuildDirEntList( JSContext* cx, JSObject* UNUSED(obj), uintN arg if( !ToPrimitive( cx, argv[2], recursive ) ) return( JS_FALSE ); } - int flags = recursive? DIR_RECURSIVE : 0; + int flags = recursive? fs_util::DIR_RECURSIVE : 0; // build array in the callback function BuildDirEntListState state(cx); - fs_ForEachFile(g_VFS, path, BuildDirEntListCB, (uintptr_t)&state, filter, flags); + fs_util::ForEachFile(g_VFS, path, BuildDirEntListCB, (uintptr_t)&state, filter, flags); *rval = OBJECT_TO_JSVAL( state.filename_array ); return( JS_TRUE ); diff --git a/source/simulation/EntityTemplateCollection.cpp b/source/simulation/EntityTemplateCollection.cpp index 2e3e84757b..a9cf6b0d80 100644 --- a/source/simulation/EntityTemplateCollection.cpp +++ b/source/simulation/EntityTemplateCollection.cpp @@ -50,7 +50,7 @@ static LibError LoadFileThunk( const VfsPath& path, const FileInfo& UNUSED(fileI int CEntityTemplateCollection::LoadTemplates() { // List all files in entities/ and its subdirectories. - THROW_ERR( fs_ForEachFile(g_VFS, "entities/", LoadFileThunk, (uintptr_t)this, "*.xml", DIR_RECURSIVE)); + THROW_ERR( fs_util::ForEachFile(g_VFS, "entities/", LoadFileThunk, (uintptr_t)this, "*.xml", fs_util::DIR_RECURSIVE)); /*// Load all the templates; this is necessary so that we can apply techs to them // (otherwise a tech can't affect the template of a unit that doesn't yet exist) diff --git a/source/simulation/FormationCollection.cpp b/source/simulation/FormationCollection.cpp index fc9f6b7349..dd42e35d7d 100644 --- a/source/simulation/FormationCollection.cpp +++ b/source/simulation/FormationCollection.cpp @@ -45,7 +45,7 @@ static LibError LoadFormationThunk( const VfsPath& path, const FileInfo& UNUSED( int CFormationCollection::LoadTemplates() { // Load all files in formations and subdirectories. - THROW_ERR( fs_ForEachFile(g_VFS, "formations/", LoadFormationThunk, (uintptr_t)this, "*.xml", DIR_RECURSIVE)); + THROW_ERR( fs_util::ForEachFile(g_VFS, "formations/", LoadFormationThunk, (uintptr_t)this, "*.xml", fs_util::DIR_RECURSIVE)); return 0; } diff --git a/source/simulation/TechnologyCollection.cpp b/source/simulation/TechnologyCollection.cpp index b477b0236d..71b2b44177 100644 --- a/source/simulation/TechnologyCollection.cpp +++ b/source/simulation/TechnologyCollection.cpp @@ -39,7 +39,7 @@ static LibError LoadTechThunk( const VfsPath& pathname, const FileInfo& UNUSED(f int CTechnologyCollection::LoadTechnologies() { // Load all files in techs/ and subdirectories. - THROW_ERR( fs_ForEachFile(g_VFS, "technologies/", LoadTechThunk, (uintptr_t)this, "*.xml", DIR_RECURSIVE)); + THROW_ERR( fs_util::ForEachFile(g_VFS, "technologies/", LoadTechThunk, (uintptr_t)this, "*.xml", fs_util::DIR_RECURSIVE)); return 0; }