# 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.
This commit is contained in:
parent
4a4269824b
commit
5b302658a3
@ -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();
|
||||
|
@ -177,10 +177,10 @@ static LibError GetObjectName_ThunkCb(const VfsPath& pathname, const FileInfo& U
|
||||
|
||||
void CObjectManager::GetAllObjectNames(std::vector<CStr>& 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<CStr>& 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);
|
||||
}
|
||||
|
@ -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++)
|
||||
{
|
||||
|
@ -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:
|
||||
|
||||
|
@ -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
|
||||
|
@ -17,3 +17,145 @@
|
||||
|
||||
#include "precompiled.h"
|
||||
#include "file_system.h"
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
#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<DIR> 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;
|
||||
}
|
||||
|
@ -51,7 +51,21 @@ private:
|
||||
time_t m_mtime;
|
||||
};
|
||||
|
||||
extern LibError GetFileInfo(const fs::path& pathname, FileInfo* fileInfo);
|
||||
|
||||
typedef std::vector<FileInfo> FileInfos;
|
||||
typedef std::vector<std::string> 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
|
||||
// <mode> 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
|
||||
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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 <vector>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
#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<DIR> 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);
|
||||
}
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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<FileSystem_Posix> PIFileSystem_Posix;
|
||||
|
||||
LIB_API PIFileSystem_Posix CreateFileSystem_Posix();
|
||||
|
||||
#endif // #ifndef INCLUDED_FILE_SYSTEM_POSIX
|
@ -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<FileInfo> files;
|
||||
RETURN_ERR(fs->GetDirectoryEntries(path, &files, 0));
|
||||
@ -54,7 +57,7 @@ struct FileInfoNameLess : public std::binary_function<const FileInfo, const File
|
||||
}
|
||||
};
|
||||
|
||||
void fs_SortFiles(FileInfos& files)
|
||||
void SortFiles(FileInfos& files)
|
||||
{
|
||||
std::sort(files.begin(), files.end(), FileInfoNameLess());
|
||||
}
|
||||
@ -68,13 +71,13 @@ struct NameLess : public std::binary_function<const std::string, const std::stri
|
||||
}
|
||||
};
|
||||
|
||||
void fs_SortDirectories(DirectoryNames& directories)
|
||||
void SortDirectories(DirectoryNames& directories)
|
||||
{
|
||||
std::sort(directories.begin(), directories.end(), NameLess());
|
||||
}
|
||||
|
||||
|
||||
LibError fs_ForEachFile(const PIVFS& fs, const VfsPath& startPath, FileCallback cb, uintptr_t cbData, const char* pattern, size_t flags)
|
||||
LibError ForEachFile(const PIVFS& fs, const VfsPath& startPath, FileCallback cb, uintptr_t cbData, const char* pattern, size_t flags)
|
||||
{
|
||||
debug_assert(vfs_path_IsDirectory(startPath));
|
||||
|
||||
@ -113,7 +116,7 @@ LibError fs_ForEachFile(const PIVFS& fs, const VfsPath& startPath, FileCallback
|
||||
}
|
||||
|
||||
|
||||
void fs_NextNumberedFilename(const PIVFS& fs, const VfsPath& pathnameFormat, size_t& nextNumber, VfsPath& nextPathname)
|
||||
void NextNumberedFilename(const PIVFS& fs, const VfsPath& pathnameFormat, size_t& nextNumber, VfsPath& nextPathname)
|
||||
{
|
||||
// (first call only:) scan directory and set nextNumber according to
|
||||
// highest matching filename found. this avoids filling "holes" in
|
||||
@ -151,3 +154,5 @@ void fs_NextNumberedFilename(const PIVFS& fs, const VfsPath& pathnameFormat, siz
|
||||
}
|
||||
while(fs->GetFileInfo(nextPathname, 0) == INFO::OK);
|
||||
}
|
||||
|
||||
} // namespace fs_util
|
||||
|
@ -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
|
||||
|
@ -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));
|
||||
|
@ -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<const VfsFile*> 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;
|
||||
|
@ -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();
|
||||
|
@ -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()
|
||||
|
@ -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.
|
||||
|
@ -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++)
|
||||
{
|
||||
|
@ -114,12 +114,12 @@ JSBool JSI_VFS::BuildDirEntList( JSContext* cx, JSObject* UNUSED(obj), uintN arg
|
||||
if( !ToPrimitive<bool>( 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 );
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user