diff --git a/src/xrCore/LocatorAPI.cpp b/src/xrCore/LocatorAPI.cpp index 2ced7bdce58..f621229afe2 100644 --- a/src/xrCore/LocatorAPI.cpp +++ b/src/xrCore/LocatorAPI.cpp @@ -9,7 +9,7 @@ #pragma warning(disable : 4995) #include #include -#include +#include #pragma warning(pop) #include "FS_internal.h" @@ -19,17 +19,12 @@ const u32 BIG_FILE_READER_WINDOW_SIZE = 1024 * 1024; -#pragma warning(push) -#pragma warning(disable : 4995) -#include -#pragma warning(pop) - -CLocatorAPI* xr_FS = NULL; +CLocatorAPI* xr_FS = nullptr; #ifdef _EDITOR -#define FSLTX "fs.ltx" +static constexpr pcstr FSLTX = "fs.ltx" #else -#define FSLTX "fsgame.ltx" +static constexpr pcstr FSLTX = "fsgame.ltx"; #endif struct _open_file @@ -51,7 +46,7 @@ struct eq_pointer { IReader* _val; eq_pointer(IReader* p) : _val(p) {} - bool operator()(_open_file& itm) { return (_val == itm._reader); } + bool operator()(_open_file& itm) const { return _val == itm._reader; } }; template <> @@ -59,35 +54,35 @@ struct eq_pointer { CStreamReader* _val; eq_pointer(CStreamReader* p) : _val(p) {} - bool operator()(_open_file& itm) { return (_val == itm._stream_reader); } + bool operator()(_open_file& itm) const { return _val == itm._stream_reader; } }; struct eq_fname_free { shared_str _val; eq_fname_free(shared_str s) { _val = s; } - bool operator()(_open_file& itm) { return (_val == itm._fn && itm._reader == NULL); } + bool operator()(_open_file& itm) const { return _val == itm._fn && itm._reader == nullptr; } }; struct eq_fname_check { shared_str _val; eq_fname_check(shared_str s) { _val = s; } - bool operator()(_open_file& itm) { return (_val == itm._fn && itm._reader != NULL); } + bool operator()(_open_file& itm) const { return _val == itm._fn && itm._reader != nullptr; } }; XRCORE_API xr_vector<_open_file> g_open_files; void _check_open_file(const shared_str& _fname) { - xr_vector<_open_file>::iterator it = std::find_if(g_open_files.begin(), g_open_files.end(), eq_fname_check(_fname)); + auto it = std::find_if(g_open_files.begin(), g_open_files.end(), eq_fname_check(_fname)); if (it != g_open_files.end()) Log("file opened at least twice", _fname.c_str()); } _open_file& find_free_item(const shared_str& _fname) { - xr_vector<_open_file>::iterator it = std::find_if(g_open_files.begin(), g_open_files.end(), eq_fname_free(_fname)); + auto it = std::find_if(g_open_files.begin(), g_open_files.end(), eq_fname_free(_fname)); if (it == g_open_files.end()) { g_open_files.resize(g_open_files.size() + 1); @@ -102,7 +97,7 @@ _open_file& find_free_item(const shared_str& _fname) void setup_reader(CStreamReader* _r, _open_file& _of) { _of._stream_reader = _r; } void setup_reader(IReader* _r, _open_file& _of) { _of._reader = _r; } template -void _register_open_file(T* _r, LPCSTR _fname) +void _register_open_file(T* _r, pcstr _fname) { Lock _lock; _lock.Enter(); @@ -126,43 +121,32 @@ void _unregister_open_file(T* _r) xr_vector<_open_file>::iterator it = std::find_if(g_open_files.begin(), g_open_files.end(), eq_pointer(_r)); VERIFY(it != g_open_files.end()); _open_file& _of = *it; - _of._reader = NULL; + _of._reader = nullptr; _lock.Leave(); } XRCORE_API void _dump_open_files(int mode) { - xr_vector<_open_file>::iterator it = g_open_files.begin(); - xr_vector<_open_file>::iterator it_e = g_open_files.end(); - - bool bShow = false; if (mode == 1) { - for (; it != it_e; ++it) + for (auto file : g_open_files) { - _open_file& _of = *it; - if (_of._reader != NULL) - { - if (!bShow) - Log("----opened files"); - - bShow = true; - Msg("[%d] fname:%s", _of._used, _of._fn.c_str()); - } + Log("----opened files"); + if (file._reader != nullptr) + Msg("[%d] fname:%s", file._used, file._fn.c_str()); } } else { Log("----un-used"); - for (it = g_open_files.begin(); it != it_e; ++it) + for (auto itr : g_open_files) { - _open_file& _of = *it; - if (_of._reader == NULL) - Msg("[%d] fname:%s", _of._used, _of._fn.c_str()); + auto file = itr; + if (file._reader == nullptr) + Msg("[%d] fname:%s", file._used, file._fn.c_str()); } } - if (bShow) - Log("----total count=", g_open_files.size()); + Log("----total count = ", g_open_files.size()); } CLocatorAPI::CLocatorAPI() : @@ -188,7 +172,7 @@ CLocatorAPI::~CLocatorAPI() delete m_auth_lock; } -const CLocatorAPI::file* CLocatorAPI::RegisterExternal(const char* name) +const CLocatorAPI::file* CLocatorAPI::RegisterExternal(pcstr name) { struct stat buffer; if (stat(name, &buffer) == -1) @@ -197,11 +181,11 @@ const CLocatorAPI::file* CLocatorAPI::RegisterExternal(const char* name) } const CLocatorAPI::file* CLocatorAPI::Register( - LPCSTR name, u32 vfs, u32 crc, u32 ptr, u32 size_real, u32 size_compressed, u32 modif) + pcstr name, u32 vfs, u32 crc, u32 ptr, u32 size_real, u32 size_compressed, u32 modif) { // Msg("Register[%d] [%s]",vfs,name); string256 temp_file_name; - xr_strcpy(temp_file_name, sizeof(temp_file_name), name); + xr_strcpy(temp_file_name, sizeof temp_file_name, name); xr_strlwr(temp_file_name); // Register file @@ -213,7 +197,7 @@ const CLocatorAPI::file* CLocatorAPI::Register( desc.ptr = ptr; desc.size_real = size_real; desc.size_compressed = size_compressed; - desc.modif = modif & (~u32(0x3)); + desc.modif = modif & ~u32(0x3); // Msg("registering file %s - %d", name, size_real); // if file already exist - update info files_it I = m_files.find(desc); @@ -237,12 +221,12 @@ const CLocatorAPI::file* CLocatorAPI::Register( // Try to register folder(s) string_path temp; - xr_strcpy(temp, sizeof(temp), desc.name); + xr_strcpy(temp, sizeof temp, desc.name); string_path path; string_path folder; while (temp[0]) { - _splitpath(temp, path, folder, 0, 0); + _splitpath(temp, path, folder, nullptr, nullptr); xr_strcat(path, folder); if (!exist(path)) { @@ -256,7 +240,7 @@ const CLocatorAPI::file* CLocatorAPI::Register( R_ASSERT(I2.second); } - xr_strcpy(temp, sizeof(temp), folder); + xr_strcpy(temp, sizeof temp, folder); if (xr_strlen(temp)) temp[xr_strlen(temp) - 1] = 0; } @@ -265,27 +249,26 @@ const CLocatorAPI::file* CLocatorAPI::Register( IReader* open_chunk(void* ptr, u32 ID) { - BOOL res; u32 dwType, dwSize; DWORD read_byte; - u32 pt = SetFilePointer(ptr, 0, 0, FILE_BEGIN); + u32 pt = SetFilePointer(ptr, 0, nullptr, FILE_BEGIN); VERIFY(pt != INVALID_SET_FILE_POINTER); while (true) { - res = ReadFile(ptr, &dwType, 4, &read_byte, 0); + bool res = ReadFile(ptr, &dwType, 4, &read_byte, nullptr); if (read_byte == 0) - return NULL; + return nullptr; //. VERIFY(res&&(read_byte==4)); - res = ReadFile(ptr, &dwSize, 4, &read_byte, 0); + res = ReadFile(ptr, &dwSize, 4, &read_byte, nullptr); if (read_byte == 0) - return NULL; + return nullptr; //. VERIFY(res&&(read_byte==4)); - if ((dwType & (~CFS_CompressMark)) == ID) + if ((dwType & ~CFS_CompressMark) == ID) { u8* src_data = xr_alloc(dwSize); - res = ReadFile(ptr, src_data, dwSize, &read_byte, 0); + res = ReadFile(ptr, src_data, dwSize, &read_byte, nullptr); VERIFY(res && (read_byte == dwSize)); if (dwType & CFS_CompressMark) { @@ -295,22 +278,16 @@ IReader* open_chunk(void* ptr, u32 ID) xr_free(src_data); return new CTempReader(dest, dest_sz, 0); } - else - { - return new CTempReader(src_data, dwSize, 0); - } - } - else - { - pt = SetFilePointer(ptr, dwSize, 0, FILE_CURRENT); - if (pt == INVALID_SET_FILE_POINTER) - return 0; + return new CTempReader(src_data, dwSize, 0); } + pt = SetFilePointer(ptr, dwSize, nullptr, FILE_CURRENT); + if (pt == INVALID_SET_FILE_POINTER) + return nullptr; } - return 0; + return nullptr; }; -void CLocatorAPI::LoadArchive(archive& A, LPCSTR entrypoint) +void CLocatorAPI::LoadArchive(archive& A, pcstr entrypoint) { // Create base path string_path fs_entry_point; @@ -326,9 +303,9 @@ void CLocatorAPI::LoadArchive(archive& A, LPCSTR entrypoint) { FS_Path* root = P->second; // R_ASSERT3 (root, "path not found ", read_path.c_str()); - xr_strcpy(fs_entry_point, sizeof(fs_entry_point), root->m_Path); + xr_strcpy(fs_entry_point, sizeof fs_entry_point, root->m_Path); } - xr_strcat(fs_entry_point, "gamedata\\"); + xr_strcat(fs_entry_point, "gamedata//"); } else { @@ -345,20 +322,20 @@ void CLocatorAPI::LoadArchive(archive& A, LPCSTR entrypoint) { FS_Path* root = P->second; // R_ASSERT3 (root, "path not found ", alias_name); - xr_strcpy(fs_entry_point, sizeof(fs_entry_point), root->m_Path); + xr_strcpy(fs_entry_point, sizeof fs_entry_point, root->m_Path); } - xr_strcat(fs_entry_point, sizeof(fs_entry_point), read_path.c_str() + xr_strlen(alias_name) + 1); + xr_strcat(fs_entry_point, sizeof fs_entry_point, read_path.c_str() + xr_strlen(alias_name) + 1); } } else { R_ASSERT2(0, "unsupported"); - xr_strcpy(fs_entry_point, sizeof(fs_entry_point), A.path.c_str()); + xr_strcpy(fs_entry_point, sizeof fs_entry_point, A.path.c_str()); if (strext(fs_entry_point)) *strext(fs_entry_point) = 0; } if (entrypoint) - xr_strcpy(fs_entry_point, sizeof(fs_entry_point), entrypoint); + xr_strcpy(fs_entry_point, sizeof fs_entry_point, entrypoint); // Read FileSystem A.open(); IReader* hdr = open_chunk(A.hSrcFile, 1); @@ -375,13 +352,13 @@ void CLocatorAPI::LoadArchive(archive& A, LPCSTR entrypoint) hdr->r(buffer, buffer_size); u32 size_real = *(u32*)buffer; - buffer += sizeof(size_real); + buffer += sizeof size_real; u32 size_compr = *(u32*)buffer; - buffer += sizeof(size_compr); + buffer += sizeof size_compr; u32 crc = *(u32*)buffer; - buffer += sizeof(crc); + buffer += sizeof crc; u32 name_length = buffer_size - 4 * sizeof(u32); memcpy(name, buffer, name_length); @@ -389,9 +366,9 @@ void CLocatorAPI::LoadArchive(archive& A, LPCSTR entrypoint) buffer += buffer_size - 4 * sizeof(u32); u32 ptr = *(u32*)buffer; - buffer += sizeof(ptr); + buffer += sizeof ptr; - strconcat(sizeof(full), full, fs_entry_point, name); + strconcat(sizeof full, full, fs_entry_point, name); Register(full, A.vfs_idx, crc, ptr, size_real, size_compr, 0); } @@ -404,23 +381,23 @@ void CLocatorAPI::archive::open() if (hSrcFile && hSrcMap) return; - hSrcFile = CreateFile(*path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0); + hSrcFile = CreateFile(*path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, 0, nullptr); R_ASSERT(hSrcFile != INVALID_HANDLE_VALUE); - hSrcMap = CreateFileMapping(hSrcFile, 0, PAGE_READONLY, 0, 0, 0); + hSrcMap = CreateFileMapping(hSrcFile, nullptr, PAGE_READONLY, 0, 0, nullptr); R_ASSERT(hSrcMap != INVALID_HANDLE_VALUE); - size = GetFileSize(hSrcFile, 0); + size = GetFileSize(hSrcFile, nullptr); R_ASSERT(size > 0); } void CLocatorAPI::archive::close() { CloseHandle(hSrcMap); - hSrcMap = NULL; + hSrcMap = nullptr; CloseHandle(hSrcFile); - hSrcFile = NULL; + hSrcFile = nullptr; } -void CLocatorAPI::ProcessArchive(LPCSTR _path) +void CLocatorAPI::ProcessArchive(pcstr _path) { // find existing archive shared_str path = _path; @@ -437,7 +414,7 @@ void CLocatorAPI::ProcessArchive(LPCSTR _path) A.open(); // Read header - BOOL bProcessArchiveLoading = TRUE; + bool bProcessArchiveLoading = true; IReader* hdr = open_chunk(A.hSrcFile, CFS_HeaderChunkID); if (hdr) { @@ -462,7 +439,7 @@ void CLocatorAPI::unload_archive(CLocatorAPI::archive& A) #ifndef MASTER_GOLD Msg("unregistering file [%s]", I->name); #endif // #ifndef MASTER_GOLD - char* str = LPSTR(I->name); + auto str = pstr(I->name); xr_free(str); m_files.erase(I); break; @@ -486,10 +463,10 @@ bool CLocatorAPI::load_all_unloaded_archives() return res; } -void CLocatorAPI::ProcessOne(LPCSTR path, const _finddata_t& entry) +void CLocatorAPI::ProcessOne(pcstr path, const _finddata_t& entry) { string_path N; - xr_strcpy(N, sizeof(N), path); + xr_strcpy(N, sizeof N, path); xr_strcat(N, entry.name); xr_strlwr(N); @@ -544,7 +521,7 @@ bool ignore_name(const char* _name) bool ignore_path(const char* _path) { - HANDLE h = CreateFile(_path, 0, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY | FILE_FLAG_NO_BUFFERING, NULL); + HANDLE h = CreateFile(_path, 0, 0, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY | FILE_FLAG_NO_BUFFERING, nullptr); if (h != INVALID_HANDLE_VALUE) { @@ -555,15 +532,15 @@ bool ignore_path(const char* _path) return true; } -bool CLocatorAPI::Recurse(const char* path) +bool CLocatorAPI::Recurse(pcstr path) { string_path scanPath; - xr_strcpy(scanPath, sizeof(scanPath), path); + xr_strcpy(scanPath, sizeof scanPath, path); xr_strcat(scanPath, ".xrignore"); struct stat buffer; if (!stat(scanPath, &buffer)) return true; - xr_strcpy(scanPath, sizeof(scanPath), path); + xr_strcpy(scanPath, sizeof scanPath, path); xr_strcat(scanPath, "*.*"); _finddata_t findData; intptr_t handle = _findfirst(scanPath, &findData); @@ -578,7 +555,7 @@ bool CLocatorAPI::Recurse(const char* path) bool ignore = false; if (m_Flags.test(flNeedCheck)) { - xr_strcpy(fullPath, sizeof(fullPath), path); + xr_strcpy(fullPath, sizeof fullPath, path); xr_strcat(fullPath, findData.name); ignore = ignore_name(findData.name) || ignore_path(fullPath); } @@ -605,13 +582,13 @@ bool CLocatorAPI::Recurse(const char* path) return true; } -bool file_handle_internal(LPCSTR file_name, u32& size, int& file_handle); -void* FileDownload(LPCSTR file_name, const int& file_handle, u32& file_size); +bool file_handle_internal(pcstr file_name, u32& size, int& file_handle); +void* FileDownload(pcstr file_name, const int& file_handle, u32& file_size); -void CLocatorAPI::setup_fs_path(LPCSTR fs_name, string_path& fs_path) +void CLocatorAPI::setup_fs_path(pcstr fs_name, string_path& fs_path) { xr_strcpy(fs_path, fs_name ? fs_name : ""); - LPSTR slash = strrchr(fs_path, '\\'); + pstr slash = strrchr(fs_path, '\\'); if (!slash) slash = strrchr(fs_path, '/'); if (!slash) @@ -623,13 +600,13 @@ void CLocatorAPI::setup_fs_path(LPCSTR fs_name, string_path& fs_path) *(slash + 1) = 0; } -void CLocatorAPI::setup_fs_path(LPCSTR fs_name) +void CLocatorAPI::setup_fs_path(pcstr fs_name) { string_path fs_path; setup_fs_path(fs_name, fs_path); string_path full_current_directory; - _fullpath(full_current_directory, fs_path, sizeof(full_current_directory)); + _fullpath(full_current_directory, fs_path, sizeof full_current_directory); FS_Path* path = new FS_Path(full_current_directory, "", "", "", 0); #ifdef DEBUG @@ -639,7 +616,7 @@ void CLocatorAPI::setup_fs_path(LPCSTR fs_name) pathes.insert(std::make_pair(xr_strdup("$fs_root$"), path)); } -IReader* CLocatorAPI::setup_fs_ltx(LPCSTR fs_name) +IReader* CLocatorAPI::setup_fs_ltx(pcstr fs_name) { setup_fs_path(fs_name); @@ -648,7 +625,7 @@ IReader* CLocatorAPI::setup_fs_ltx(LPCSTR fs_name) // return (0); // } - LPCSTR fs_file_name = FSLTX; + pcstr fs_file_name = FSLTX; if (fs_name && *fs_name) fs_file_name = fs_name; @@ -656,7 +633,7 @@ IReader* CLocatorAPI::setup_fs_ltx(LPCSTR fs_name) int file_handle; u32 file_size; - IReader* result = 0; + IReader* result = nullptr; CHECK_OR_EXIT(file_handle_internal(fs_file_name, file_size, file_handle), make_string("Cannot open file \"%s\".\nCheck your working folder.", fs_file_name)); @@ -671,10 +648,10 @@ IReader* CLocatorAPI::setup_fs_ltx(LPCSTR fs_name) if (m_Flags.test(flDumpFileActivity)) _register_open_file(result, fs_file_name); - return (result); + return result; } -void CLocatorAPI::_initialize(u32 flags, LPCSTR target_folder, LPCSTR fs_name) +void CLocatorAPI::_initialize(u32 flags, pcstr target_folder, pcstr fs_name) { char _delimiter = '|'; //',' if (m_Flags.is(flReady)) @@ -684,28 +661,28 @@ void CLocatorAPI::_initialize(u32 flags, LPCSTR target_folder, LPCSTR fs_name) Log("Initializing File System..."); u32 M1 = Memory.mem_usage(); - m_Flags.set(flags, TRUE); + m_Flags.set(flags, true); // scan root directory - bNoRecurse = TRUE; + bNoRecurse = true; string4096 buf; // append application path if (m_Flags.is(flScanAppRoot)) - append_path("$app_root$", Core.ApplicationPath, 0, FALSE); + append_path("$app_root$", Core.ApplicationPath, nullptr, false); //----------------------------------------------------------- // append application data path // target folder if (m_Flags.is(flTargetFolderOnly)) { - append_path("$target_folder$", target_folder, 0, TRUE); + append_path("$target_folder$", target_folder, nullptr, true); } else { IReader* pFSltx = setup_fs_ltx(fs_name); /* - LPCSTR fs_ltx = (fs_name&&fs_name[0])?fs_name:FSLTX; + pcstr fs_ltx = (fs_name&&fs_name[0])?fs_name:FSLTX; F = r_open(fs_ltx); if (!F&&m_Flags.is(flScanAppRoot)) F = r_open("$app_root$",fs_ltx); @@ -731,19 +708,19 @@ void CLocatorAPI::_initialize(u32 flags, LPCSTR target_folder, LPCSTR fs_name) */ // append all pathes string_path id, root, add, def, capt; - LPCSTR lp_add, lp_def, lp_capt; + pcstr lp_add, lp_def, lp_capt; string16 b_v; string4096 temp; while (!pFSltx->eof()) { - pFSltx->r_string(buf, sizeof(buf)); + pFSltx->r_string(buf, sizeof buf); if (buf[0] == ';') continue; _GetItem(buf, 0, id, '='); - if (!m_Flags.is(flBuildCopy) && (0 == xr_strcmp(id, "$build_copy$"))) + if (!m_Flags.is(flBuildCopy) && 0 == xr_strcmp(id, "$build_copy$")) continue; _GetItem(buf, 1, temp, '='); @@ -766,18 +743,18 @@ void CLocatorAPI::_initialize(u32 flags, LPCSTR target_folder, LPCSTR fs_name) xr_strlwr(id); xr_strlwr(root); - lp_add = (cnt >= 4) ? xr_strlwr(add) : 0; - lp_def = (cnt >= 5) ? def : 0; - lp_capt = (cnt >= 6) ? capt : 0; + lp_add = cnt >= 4 ? xr_strlwr(add) : 0; + lp_def = cnt >= 5 ? def : 0; + lp_capt = cnt >= 6 ? capt : 0; auto p_it = pathes.find(root); - FS_Path* P = new FS_Path((p_it != pathes.end()) ? p_it->second->m_Path : root, lp_add, lp_def, lp_capt, fl); + FS_Path* P = new FS_Path(p_it != pathes.end() ? p_it->second->m_Path : root, lp_add, lp_def, lp_capt, fl); bNoRecurse = !(fl & FS_Path::flRecurse); Recurse(P->m_Path); auto I = pathes.insert(std::make_pair(xr_strdup(id), P)); #ifndef DEBUG - m_Flags.set(flCacheFiles, FALSE); + m_Flags.set(flCacheFiles, false); #endif // DEBUG CHECK_OR_EXIT(I.second, @@ -791,7 +768,7 @@ void CLocatorAPI::_initialize(u32 flags, LPCSTR target_folder, LPCSTR fs_name) u32 M2 = Memory.mem_usage(); Msg("FS: %d files cached %d archives, %dKb memory used.", m_files.size(), m_archives.size(), (M2 - M1) / 1024); - m_Flags.set(flReady, TRUE); + m_Flags.set(flReady, true); Msg("Init FileSystem %f sec", t.GetElapsed_sec()); //----------------------------------------------------------- @@ -814,7 +791,7 @@ void CLocatorAPI::_initialize(u32 flags, LPCSTR target_folder, LPCSTR fs_name) rec_files.clear(); //----------------------------------------------------------- - CreateLog(0 != strstr(Core.Params, "-nolog")); + CreateLog(nullptr != strstr(Core.Params, "-nolog")); } void CLocatorAPI::_destroy() @@ -823,14 +800,14 @@ void CLocatorAPI::_destroy() for (auto it : m_files) { - char* str = LPSTR(it.name); + auto str = pstr(it.name); xr_free(str); } m_files.clear(); for (auto& it : pathes) { - char* str = LPSTR(it.first); + auto str = pstr(it.first); xr_free(str); xr_delete(it.second); } @@ -844,13 +821,13 @@ void CLocatorAPI::_destroy() m_archives.clear(); } -const CLocatorAPI::file* CLocatorAPI::GetFileDesc(const char* path) +const CLocatorAPI::file* CLocatorAPI::GetFileDesc(pcstr path) { auto it = file_find_it(path); return it != m_files.end() ? &*it : nullptr; } -FileStatus CLocatorAPI::exist(const char* fn, FSType fsType /*= FSType::Virtual*/) +FileStatus CLocatorAPI::exist(pcstr fn, FSType fsType /*= FSType::Virtual*/) { if ((fsType | FSType::Virtual) == FSType::Virtual) { @@ -867,29 +844,29 @@ FileStatus CLocatorAPI::exist(const char* fn, FSType fsType /*= FSType::Virtual* return FileStatus(false, false); } -FileStatus CLocatorAPI::exist(const char* path, const char* name, FSType fsType /*= FSType::Virtual*/) +FileStatus CLocatorAPI::exist(pcstr path, pcstr name, FSType fsType /*= FSType::Virtual*/) { string_path temp; update_path(temp, path, name); return exist(temp, fsType); } -FileStatus CLocatorAPI::exist(string_path& fn, LPCSTR path, LPCSTR name, FSType fsType /*= FSType::Virtual*/) +FileStatus CLocatorAPI::exist(string_path& fn, pcstr path, pcstr name, FSType fsType /*= FSType::Virtual*/) { update_path(fn, path, name); return exist(fn, fsType); } FileStatus CLocatorAPI::exist( - string_path& fn, LPCSTR path, LPCSTR name, LPCSTR ext, FSType fsType /*= FSType::Virtual*/) + string_path& fn, pcstr path, pcstr name, pcstr ext, FSType fsType /*= FSType::Virtual*/) { string_path nm; - strconcat(sizeof(nm), nm, name, ext); + strconcat(sizeof nm, nm, name, ext); update_path(fn, path, nm); return exist(fn, fsType); } -xr_vector* CLocatorAPI::file_list_open(const char* initial, const char* folder, u32 flags) +xr_vector* CLocatorAPI::file_list_open(pcstr initial, pcstr folder, u32 flags) { string_path N; R_ASSERT(initial && initial[0]); @@ -897,7 +874,7 @@ xr_vector* CLocatorAPI::file_list_open(const char* initial, const char* f return file_list_open(N, flags); } -xr_vector* CLocatorAPI::file_list_open(const char* _path, u32 flags) +xr_vector* CLocatorAPI::file_list_open(pcstr _path, u32 flags) { R_ASSERT(_path); VERIFY(flags); @@ -908,13 +885,13 @@ xr_vector* CLocatorAPI::file_list_open(const char* _path, u32 flags) if (path_exist(_path)) update_path(N, _path, ""); else - xr_strcpy(N, sizeof(N), _path); + xr_strcpy(N, sizeof N, _path); file desc; desc.name = N; files_it I = m_files.find(desc); if (I == m_files.end()) - return 0; + return nullptr; xr_vector* dest = new xr_vector(); @@ -925,19 +902,19 @@ xr_vector* CLocatorAPI::file_list_open(const char* _path, u32 flags) if (0 != strncmp(entry.name, N, base_len)) break; // end of list const char* end_symbol = entry.name + xr_strlen(entry.name) - 1; - if ((*end_symbol) != '\\') + if (*end_symbol != '\\') { // file if ((flags & FS_ListFiles) == 0) continue; const char* entry_begin = entry.name + base_len; - if ((flags & FS_RootOnly) && strstr(entry_begin, "\\")) + if (flags & FS_RootOnly && strstr(entry_begin, "\\")) continue; // folder in folder dest->push_back(xr_strdup(entry_begin)); - LPSTR fname = dest->back(); + pstr fname = dest->back(); if (flags & FS_ClampExt) - if (0 != strext(fname)) + if (nullptr != strext(fname)) *strext(fname) = 0; } else @@ -947,7 +924,7 @@ xr_vector* CLocatorAPI::file_list_open(const char* _path, u32 flags) continue; const char* entry_begin = entry.name + base_len; - if ((flags & FS_RootOnly) && (strstr(entry_begin, "\\") != end_symbol)) + if (flags & FS_RootOnly && strstr(entry_begin, "\\") != end_symbol) continue; // folder in folder dest->push_back(xr_strdup(entry_begin)); @@ -956,7 +933,7 @@ xr_vector* CLocatorAPI::file_list_open(const char* _path, u32 flags) return dest; } -void CLocatorAPI::file_list_close(xr_vector*& lst) +void CLocatorAPI::file_list_close(xr_vector*& lst) { if (lst) { @@ -966,7 +943,7 @@ void CLocatorAPI::file_list_close(xr_vector*& lst) } } -int CLocatorAPI::file_list(FS_FileSet& dest, LPCSTR path, u32 flags, LPCSTR mask) +int CLocatorAPI::file_list(FS_FileSet& dest, pcstr path, u32 flags, pcstr mask) { R_ASSERT(path); VERIFY(flags); @@ -976,7 +953,7 @@ int CLocatorAPI::file_list(FS_FileSet& dest, LPCSTR path, u32 flags, LPCSTR mask if (path_exist(path)) update_path(N, path, ""); else - xr_strcpy(N, sizeof(N), path); + xr_strcpy(N, sizeof N, path); file desc; desc.name = N; @@ -986,7 +963,7 @@ int CLocatorAPI::file_list(FS_FileSet& dest, LPCSTR path, u32 flags, LPCSTR mask SStringVec masks; _SequenceToList(masks, mask); - BOOL b_mask = !masks.empty(); + bool b_mask = !masks.empty(); size_t base_len = xr_strlen(N); for (++I; I != m_files.end(); ++I) @@ -994,14 +971,14 @@ int CLocatorAPI::file_list(FS_FileSet& dest, LPCSTR path, u32 flags, LPCSTR mask const file& entry = *I; if (0 != strncmp(entry.name, N, base_len)) break; // end of list - LPCSTR end_symbol = entry.name + xr_strlen(entry.name) - 1; - if ((*end_symbol) != '\\') + pcstr end_symbol = entry.name + xr_strlen(entry.name) - 1; + if (*end_symbol != '\\') { // file if ((flags & FS_ListFiles) == 0) continue; LPCSTR entry_begin = entry.name + base_len; - if ((flags & FS_RootOnly) && strstr(entry_begin, "\\")) + if (flags & FS_RootOnly && strstr(entry_begin, "\\")) continue; // folder in folder // check extension if (b_mask) @@ -1023,7 +1000,7 @@ int CLocatorAPI::file_list(FS_FileSet& dest, LPCSTR path, u32 flags, LPCSTR mask file.name = EFS.ChangeFileExt(entry_begin, ""); else file.name = entry_begin; - u32 fl = (entry.vfs != 0xffffffff ? FS_File::flVFS : 0); + u32 fl = entry.vfs != 0xffffffff ? FS_File::flVFS : 0; file.size = entry.size_real; file.time_write = entry.modif; file.attrib = fl; @@ -1036,7 +1013,7 @@ int CLocatorAPI::file_list(FS_FileSet& dest, LPCSTR path, u32 flags, LPCSTR mask continue; LPCSTR entry_begin = entry.name + base_len; - if ((flags & FS_RootOnly) && (strstr(entry_begin, "\\") != end_symbol)) + if (flags & FS_RootOnly && strstr(entry_begin, "\\") != end_symbol) continue; // folder in folder u32 fl = FS_File::flSubDir | (entry.vfs ? FS_File::flVFS : 0); dest.insert(FS_File(entry_begin, entry.size_real, entry.modif, fl)); @@ -1045,7 +1022,7 @@ int CLocatorAPI::file_list(FS_FileSet& dest, LPCSTR path, u32 flags, LPCSTR mask return dest.size(); } -void CLocatorAPI::check_cached_files(LPSTR fname, const u32& fname_size, const file& desc, LPCSTR& source_name) +void CLocatorAPI::check_cached_files(pstr fname, const u32& fname_size, const file& desc, pcstr& source_name) { string_path fname_copy; if (pathes.size() <= 1) @@ -1061,13 +1038,13 @@ void CLocatorAPI::check_cached_files(LPSTR fname, const u32& fname_size, const f if (len_file <= len_base) return; - if ((len_base == 1) && (*path_base == '\\')) + if (len_base == 1 && *path_base == '\\') len_base = 0; if (0 != memcmp(path_base, fname, len_base)) return; - BOOL bCopy = FALSE; + bool bCopy = false; string_path fname_in_cache; update_path(fname_in_cache, "$cache$", path_file + len_base); @@ -1076,7 +1053,7 @@ void CLocatorAPI::check_cached_files(LPSTR fname, const u32& fname_size, const f { // use const file& fc = *fit; - if ((fc.size_real == desc.size_real) && (fc.modif == desc.modif)) + if (fc.size_real == desc.size_real && fc.modif == desc.modif) { // use } @@ -1084,13 +1061,13 @@ void CLocatorAPI::check_cached_files(LPSTR fname, const u32& fname_size, const f { // copy & use Msg("copy: db[%X],cache[%X] - '%s', ", desc.modif, fc.modif, fname); - bCopy = TRUE; + bCopy = true; } } else { // copy & use - bCopy = TRUE; + bCopy = true; } // copy if need @@ -1111,7 +1088,7 @@ void CLocatorAPI::check_cached_files(LPSTR fname, const u32& fname_size, const f // Use source_name = &fname_copy[0]; - xr_strcpy(fname_copy, sizeof(fname_copy), fname); + xr_strcpy(fname_copy, sizeof fname_copy, fname); xr_strcpy(fname, fname_size, fname_in_cache); } @@ -1134,7 +1111,7 @@ void CLocatorAPI::file_from_cache_impl(CStreamReader*& R, LPSTR fname, const fil } template -void CLocatorAPI::file_from_cache(T*& R, LPSTR fname, const u32& fname_size, const file& desc, LPCSTR& source_name) +void CLocatorAPI::file_from_cache(T*& R, pstr fname, const u32& fname_size, const file& desc, pcstr& source_name) { #ifdef DEBUG if (m_Flags.is(flCacheFiles)) @@ -1144,23 +1121,23 @@ void CLocatorAPI::file_from_cache(T*& R, LPSTR fname, const u32& fname_size, con file_from_cache_impl(R, fname, desc); } -void CLocatorAPI::file_from_archive(IReader*& R, LPCSTR fname, const file& desc) +void CLocatorAPI::file_from_archive(IReader*& R, pcstr fname, const file& desc) { // Archived one archive& A = m_archives[desc.vfs]; - u32 start = (desc.ptr / dwAllocGranularity) * dwAllocGranularity; + u32 start = desc.ptr / dwAllocGranularity * dwAllocGranularity; u32 end = (desc.ptr + desc.size_compressed) / dwAllocGranularity; if ((desc.ptr + desc.size_compressed) % dwAllocGranularity) end += 1; end *= dwAllocGranularity; if (end > A.size) end = A.size; - u32 sz = (end - start); + u32 sz = end - start; u8* ptr = (u8*)MapViewOfFile(A.hSrcMap, FILE_MAP_READ, 0, start, sz); VERIFY3(ptr, "cannot create file mapping on file", fname); string512 temp; - xr_sprintf(temp, sizeof(temp), "%s:%s", *A.path, fname); + xr_sprintf(temp, sizeof temp, "%s:%s", *A.path, fname); #ifdef FS_DEBUG register_file_mapping(ptr, sz, temp); @@ -1184,7 +1161,7 @@ void CLocatorAPI::file_from_archive(IReader*& R, LPCSTR fname, const file& desc) #endif // DEBUG } -void CLocatorAPI::file_from_archive(CStreamReader*& R, LPCSTR fname, const file& desc) +void CLocatorAPI::file_from_archive(CStreamReader*& R, pcstr fname, const file& desc) { archive& A = m_archives[desc.vfs]; R_ASSERT2(desc.size_compressed == desc.size_real, @@ -1206,7 +1183,7 @@ void CLocatorAPI::copy_file_to_build(IWriter* W, CStreamReader* r) } template -void CLocatorAPI::copy_file_to_build(T*& r, LPCSTR source_name) +void CLocatorAPI::copy_file_to_build(T*& r, pcstr source_name) { string_path cpy_name; string_path e_cpy_name; @@ -1217,7 +1194,7 @@ void CLocatorAPI::copy_file_to_build(T*& r, LPCSTR source_name) string_path fs_root; update_path(fs_root, "$fs_root$", ""); - LPCSTR const position = strstr(source_name, fs_root); + pcstr const position = strstr(source_name, fs_root); if (position == source_name) update_path(cpy_name, "$build_copy$", source_name + xr_strlen(fs_root)); else @@ -1236,11 +1213,11 @@ void CLocatorAPI::copy_file_to_build(T*& r, LPCSTR source_name) if (!m_Flags.is(flEBuildCopy)) return; - LPCSTR ext = strext(cpy_name); + pcstr ext = strext(cpy_name); if (!ext) return; - IReader* R = 0; + IReader* R = nullptr; if (0 == xr_strcmp(ext, ".dds")) { P = get_path("$game_textures$"); @@ -1273,7 +1250,7 @@ void CLocatorAPI::copy_file_to_build(T*& r, LPCSTR source_name) if (0 == xr_strcmp(ext, ".object")) { - xr_strcpy(e_cpy_name, sizeof(e_cpy_name), source_name); + xr_strcpy(e_cpy_name, sizeof e_cpy_name, source_name); // object thm *strext(e_cpy_name) = 0; xr_strcat(e_cpy_name, ".thm"); @@ -1283,7 +1260,7 @@ void CLocatorAPI::copy_file_to_build(T*& r, LPCSTR source_name) } } -bool CLocatorAPI::check_for_file(LPCSTR path, LPCSTR _fname, string_path& fname, const file*& desc) +bool CLocatorAPI::check_for_file(pcstr path, pcstr _fname, string_path& fname, const file*& desc) { check_pathes(); @@ -1309,23 +1286,23 @@ bool CLocatorAPI::check_for_file(LPCSTR path, LPCSTR _fname, string_path& fname, else desc = &*I; ++dwOpenCounter; - return (true); + return true; } template -T* CLocatorAPI::r_open_impl(LPCSTR path, LPCSTR _fname) +T* CLocatorAPI::r_open_impl(pcstr path, pcstr _fname) { - T* R = 0; + T* R = nullptr; string_path fname; - const file* desc = 0; - LPCSTR source_name = &fname[0]; + const file* desc = nullptr; + pcstr source_name = &fname[0]; if (!check_for_file(path, _fname, fname, desc)) - return (0); + return nullptr; // OK, analyse if (0xffffffff == desc->vfs) - file_from_cache(R, fname, sizeof(fname), *desc, source_name); + file_from_cache(R, fname, sizeof fname, *desc, source_name); else file_from_archive(R, fname, *desc); @@ -1340,8 +1317,8 @@ T* CLocatorAPI::r_open_impl(LPCSTR path, LPCSTR _fname) return (R); } -CStreamReader* CLocatorAPI::rs_open(LPCSTR path, LPCSTR _fname) { return (r_open_impl(path, _fname)); } -IReader* CLocatorAPI::r_open(LPCSTR path, LPCSTR _fname) { return (r_open_impl(path, _fname)); } +CStreamReader* CLocatorAPI::rs_open(pcstr path, pcstr _fname) { return r_open_impl(path, _fname); } +IReader* CLocatorAPI::r_open(pcstr path, pcstr _fname) { return r_open_impl(path, _fname); } void CLocatorAPI::r_close(IReader*& fs) { if (m_Flags.test(flDumpFileActivity)) @@ -1358,7 +1335,7 @@ void CLocatorAPI::r_close(CStreamReader*& fs) fs->close(); } -IWriter* CLocatorAPI::w_open(LPCSTR path, LPCSTR _fname) +IWriter* CLocatorAPI::w_open(pcstr path, pcstr _fname) { string_path fname; xr_strcpy(fname, _fname); @@ -1373,7 +1350,7 @@ IWriter* CLocatorAPI::w_open(LPCSTR path, LPCSTR _fname) return W; } -IWriter* CLocatorAPI::w_open_ex(LPCSTR path, LPCSTR _fname) +IWriter* CLocatorAPI::w_open_ex(pcstr path, pcstr _fname) { string_path fname; xr_strcpy(fname, _fname); @@ -1394,7 +1371,7 @@ void CLocatorAPI::w_close(IWriter*& S) { R_ASSERT(S->fName.size()); string_path fname; - xr_strcpy(fname, sizeof(fname), *S->fName); + xr_strcpy(fname, sizeof fname, *S->fName); bool bReg = S->valid(); xr_delete(S); @@ -1407,28 +1384,28 @@ void CLocatorAPI::w_close(IWriter*& S) } } -CLocatorAPI::files_it CLocatorAPI::file_find_it(LPCSTR fname) +CLocatorAPI::files_it CLocatorAPI::file_find_it(pcstr fname) { check_pathes(); file desc_f; string_path file_name; VERIFY(xr_strlen(fname) * sizeof(char) < sizeof(file_name)); - xr_strcpy(file_name, sizeof(file_name), fname); + xr_strcpy(file_name, sizeof file_name, fname); desc_f.name = file_name; // desc_f.name = xr_strlwr(xr_strdup(fname)); files_it I = m_files.find(desc_f); // xr_free (desc_f.name); - return (I); + return I; } -BOOL CLocatorAPI::dir_delete(LPCSTR initial, LPCSTR nm, BOOL remove_files) +bool CLocatorAPI::dir_delete(pcstr initial, pcstr nm, bool remove_files) { string_path fpath; if (initial && initial[0]) update_path(fpath, initial, nm); else - xr_strcpy(fpath, sizeof(fpath), nm); + xr_strcpy(fpath, sizeof fpath, nm); files_set folders; files_it I; @@ -1446,11 +1423,11 @@ BOOL CLocatorAPI::dir_delete(LPCSTR initial, LPCSTR nm, BOOL remove_files) if (0 != strncmp(entry.name, fpath, base_len)) break; // end of list const char* end_symbol = entry.name + xr_strlen(entry.name) - 1; - if ((*end_symbol) != '\\') + if (*end_symbol != '\\') { // const char* entry_begin = entry.name+base_len; if (!remove_files) - return FALSE; + return false; _unlink(entry.name); m_files.erase(cur_item); } @@ -1465,35 +1442,35 @@ BOOL CLocatorAPI::dir_delete(LPCSTR initial, LPCSTR nm, BOOL remove_files) for (; r_it != folders.rend(); r_it++) { const char* end_symbol = r_it->name + xr_strlen(r_it->name) - 1; - if ((*end_symbol) == '\\') + if (*end_symbol == '\\') { _rmdir(r_it->name); m_files.erase(*r_it); } } - return TRUE; + return true; } -void CLocatorAPI::file_delete(LPCSTR path, LPCSTR nm) +void CLocatorAPI::file_delete(pcstr path, pcstr nm) { string_path fname; if (path && path[0]) update_path(fname, path, nm); else - xr_strcpy(fname, sizeof(fname), nm); + xr_strcpy(fname, sizeof fname, nm); const files_it I = file_find_it(fname); if (I != m_files.end()) { // remove file _unlink(I->name); - char* str = LPSTR(I->name); + auto str = pstr(I->name); xr_free(str); m_files.erase(I); } } -void CLocatorAPI::file_copy(LPCSTR src, LPCSTR dest) +void CLocatorAPI::file_copy(pcstr src, pcstr dest) { if (exist(src)) { @@ -1511,7 +1488,7 @@ void CLocatorAPI::file_copy(LPCSTR src, LPCSTR dest) } } -void CLocatorAPI::file_rename(LPCSTR src, LPCSTR dest, bool bOwerwrite) +void CLocatorAPI::file_rename(pcstr src, pcstr dest, bool overwrite) { files_it S = file_find_it(src); if (S != m_files.end()) @@ -1519,17 +1496,17 @@ void CLocatorAPI::file_rename(LPCSTR src, LPCSTR dest, bool bOwerwrite) files_it D = file_find_it(dest); if (D != m_files.end()) { - if (!bOwerwrite) + if (!overwrite) return; _unlink(D->name); - char* str = LPSTR(D->name); + auto str = pstr(D->name); xr_free(str); m_files.erase(D); } file new_desc = *S; // remove existing item - char* str = LPSTR(S->name); + auto str = pstr(S->name); xr_free(str); m_files.erase(S); // insert updated item @@ -1542,7 +1519,7 @@ void CLocatorAPI::file_rename(LPCSTR src, LPCSTR dest, bool bOwerwrite) } } -int CLocatorAPI::file_length(LPCSTR src) +int CLocatorAPI::file_length(pcstr src) { files_it it = file_find_it(src); if (it != m_files.end()) @@ -1553,48 +1530,49 @@ int CLocatorAPI::file_length(LPCSTR src) return -1; } -bool CLocatorAPI::path_exist(LPCSTR path) +bool CLocatorAPI::path_exist(pcstr path) { return pathes.find(path) != pathes.end(); } -FS_Path* CLocatorAPI::append_path(LPCSTR path_alias, LPCSTR root, LPCSTR add, BOOL recursive) +FS_Path* CLocatorAPI::append_path(pcstr path_alias, pcstr root, pcstr add, bool recursive) { VERIFY(root /**&&root[0]/**/); VERIFY(false == path_exist(path_alias)); - FS_Path* P = new FS_Path(root, add, LPCSTR(0), LPCSTR(0), 0); + FS_Path* P = new FS_Path(root, add, nullptr, nullptr, 0); bNoRecurse = !recursive; Recurse(P->m_Path); pathes.insert(std::make_pair(xr_strdup(path_alias), P)); return P; } -FS_Path* CLocatorAPI::get_path(LPCSTR path) +FS_Path* CLocatorAPI::get_path(pcstr path) { auto P = pathes.find(path); R_ASSERT2(P != pathes.end(), path); return P->second; } -LPCSTR CLocatorAPI::update_path(string_path& dest, LPCSTR initial, LPCSTR src) +pcstr CLocatorAPI::update_path(string_path& dest, pcstr initial, pcstr src) { return get_path(initial)->_update(dest, src); } /* -void CLocatorAPI::update_path(xr_string& dest, LPCSTR initial, LPCSTR src) +void CLocatorAPI::update_path(xr_string& dest, pcstr initial, pcstr src) { -return get_path(initial)->_update(dest,src); + return get_path(initial)->_update(dest,src); +} }*/ -u32 CLocatorAPI::get_file_age(LPCSTR nm) +u32 CLocatorAPI::get_file_age(pcstr nm) { check_pathes(); files_it I = file_find_it(nm); - return (I != m_files.end()) ? I->modif : u32(-1); + return I != m_files.end() ? I->modif : u32(-1); } -void CLocatorAPI::set_file_age(LPCSTR nm, u32 age) +void CLocatorAPI::set_file_age(pcstr nm, u32 age) { check_pathes(); @@ -1619,7 +1597,7 @@ void CLocatorAPI::set_file_age(LPCSTR nm, u32 age) } } -void CLocatorAPI::rescan_path(LPCSTR full_path, BOOL bRecurse) +void CLocatorAPI::rescan_path(pcstr full_path, bool bRecurse) { file desc; desc.name = full_path; @@ -1638,11 +1616,11 @@ void CLocatorAPI::rescan_path(LPCSTR full_path, BOOL bRecurse) break; // end of list if (entry.vfs != 0xFFFFFFFF) continue; - const char* entry_begin = entry.name + base_len; + pcstr entry_begin = entry.name + base_len; if (!bRecurse && strstr(entry_begin, "\\")) continue; // erase item - char* str = LPSTR(cur_item->name); + auto str = pstr(cur_item->name); xr_free(str); m_files.erase(cur_item); } @@ -1652,14 +1630,14 @@ void CLocatorAPI::rescan_path(LPCSTR full_path, BOOL bRecurse) void CLocatorAPI::rescan_pathes() { - m_Flags.set(flNeedRescan, FALSE); + m_Flags.set(flNeedRescan, false); for (const auto& it : pathes) { FS_Path* P = it.second; if (P->m_Flags.is(FS_Path::flNeedRescan)) { rescan_path(P->m_Path, P->m_Flags.is(FS_Path::flRecurse)); - P->m_Flags.set(FS_Path::flNeedRescan, FALSE); + P->m_Flags.set(FS_Path::flNeedRescan, false); } } } @@ -1669,13 +1647,13 @@ void CLocatorAPI::unlock_rescan() { m_iLockRescan--; VERIFY(m_iLockRescan >= 0); - if ((0 == m_iLockRescan) && m_Flags.is(flNeedRescan)) + if (0 == m_iLockRescan && m_Flags.is(flNeedRescan)) rescan_pathes(); } void CLocatorAPI::check_pathes() { - if (m_Flags.is(flNeedRescan) && (0 == m_iLockRescan)) + if (m_Flags.is(flNeedRescan) && 0 == m_iLockRescan) { lock_rescan(); rescan_pathes(); @@ -1683,51 +1661,45 @@ void CLocatorAPI::check_pathes() } } -BOOL CLocatorAPI::can_write_to_folder(LPCSTR path) +bool CLocatorAPI::can_write_to_folder(pcstr path) { if (path && path[0]) { string_path temp; - LPCSTR fn = "$!#%TEMP%#!$.$$$"; - strconcat(sizeof(temp), temp, path, path[xr_strlen(path) - 1] != '\\' ? "\\" : "", fn); + pcstr fn = "$!#%TEMP%#!$.$$$"; + strconcat(sizeof temp, temp, path, path[xr_strlen(path) - 1] != '\\' ? "\\" : "", fn); FILE* hf = fopen(temp, "wb"); - if (hf == 0) - return FALSE; - else - { - fclose(hf); - _unlink(temp); - return TRUE; - } - } - else - { - return FALSE; + if (hf == nullptr) + return false; + fclose(hf); + _unlink(temp); + return true; } + return false; } -BOOL CLocatorAPI::can_write_to_alias(LPCSTR path) +bool CLocatorAPI::can_write_to_alias(pcstr path) { string_path temp; update_path(temp, path, ""); return can_write_to_folder(temp); } -BOOL CLocatorAPI::can_modify_file(LPCSTR fname) +bool CLocatorAPI::can_modify_file(pcstr fname) { FILE* hf = fopen(fname, "r+b"); if (hf) { fclose(hf); - return TRUE; + return true; } else { - return FALSE; + return false; } } -BOOL CLocatorAPI::can_modify_file(LPCSTR path, LPCSTR name) +bool CLocatorAPI::can_modify_file(pcstr path, pcstr name) { string_path temp; update_path(temp, path, name); diff --git a/src/xrCore/LocatorAPI.h b/src/xrCore/LocatorAPI.h index 2395afc8868..3d388df9f01 100644 --- a/src/xrCore/LocatorAPI.h +++ b/src/xrCore/LocatorAPI.h @@ -28,13 +28,13 @@ class FileStatus bool Exists; bool External; // File can be accessed only as external - inline FileStatus(bool exists, bool external) + FileStatus(bool exists, bool external) { Exists = exists; External = external; } - inline operator bool() { return Exists; } + operator bool() const { return Exists; } }; class XRCORE_API CLocatorAPI @@ -52,6 +52,7 @@ class XRCORE_API CLocatorAPI u32 size_compressed; // if (size_real==size_compressed) - uncompressed u32 modif; // for editor }; + struct archive { shared_str path; @@ -59,20 +60,22 @@ class XRCORE_API CLocatorAPI u32 size; CInifile* header; u32 vfs_idx; - archive() : hSrcFile(NULL), hSrcMap(NULL), header(NULL), size(0), vfs_idx(u32(-1)) {} + archive() : hSrcFile(nullptr), hSrcMap(nullptr), header(nullptr), size(0), vfs_idx(u32(-1)) {} void open(); void close(); }; + using archives_vec = xr_vector; archives_vec m_archives; - void LoadArchive(archive& A, LPCSTR entrypoint = NULL); + void LoadArchive(archive& A, pcstr entrypoint = nullptr); private: struct file_pred : public std::binary_function { - IC bool operator()(const file& x, const file& y) const { return xr_strcmp(x.name, y.name) < 0; } + bool operator()(const file& x, const file& y) const { return xr_strcmp(x.name, y.name) < 0; } }; - using PathMap = xr_map; + + using PathMap = xr_map; PathMap pathes; using files_set = xr_set; @@ -85,21 +88,21 @@ class XRCORE_API CLocatorAPI void check_pathes(); files_set m_files; - BOOL bNoRecurse; + bool bNoRecurse; Lock* m_auth_lock; u64 m_auth_code; - const file* RegisterExternal(const char* name); - const file* Register(LPCSTR name, u32 vfs, u32 crc, u32 ptr, u32 size_real, u32 size_compressed, u32 modif); - void ProcessArchive(LPCSTR path); - void ProcessOne(LPCSTR path, const _finddata_t& entry); - bool Recurse(LPCSTR path); + const file* RegisterExternal(pcstr name); + const file* Register(pcstr name, u32 vfs, u32 crc, u32 ptr, u32 size_real, u32 size_compressed, u32 modif); + void ProcessArchive(pcstr path); + void ProcessOne(pcstr path, const _finddata_t& entry); + bool Recurse(pcstr path); - files_it file_find_it(LPCSTR n); + files_it file_find_it(pcstr n); public: - enum + enum : u32 { flNeedRescan = (1 << 0), flBuildCopy = (1 << 1), @@ -117,82 +120,81 @@ class XRCORE_API CLocatorAPI u32 dwOpenCounter; private: - void check_cached_files(LPSTR fname, const u32& fname_size, const file& desc, LPCSTR& source_name); + void check_cached_files(pstr fname, const u32& fname_size, const file& desc, pcstr& source_name); void file_from_cache_impl(IReader*& R, LPSTR fname, const file& desc); void file_from_cache_impl(CStreamReader*& R, LPSTR fname, const file& desc); template - void file_from_cache(T*& R, LPSTR fname, const u32& fname_size, const file& desc, LPCSTR& source_name); + void file_from_cache(T*& R, pstr fname, const u32& fname_size, const file& desc, pcstr& source_name); - void file_from_archive(IReader*& R, LPCSTR fname, const file& desc); - void file_from_archive(CStreamReader*& R, LPCSTR fname, const file& desc); + void file_from_archive(IReader*& R, pcstr fname, const file& desc); + void file_from_archive(CStreamReader*& R, pcstr fname, const file& desc); void copy_file_to_build(IWriter* W, IReader* r); void copy_file_to_build(IWriter* W, CStreamReader* r); template - void copy_file_to_build(T*& R, LPCSTR source_name); + void copy_file_to_build(T*& R, pcstr source_name); - bool check_for_file(LPCSTR path, LPCSTR _fname, string_path& fname, const file*& desc); + bool check_for_file(pcstr path, pcstr _fname, string_path& fname, const file*& desc); template - IC T* r_open_impl(LPCSTR path, LPCSTR _fname); + T* r_open_impl(pcstr path, pcstr _fname); -private: - void setup_fs_path(LPCSTR fs_name, string_path& fs_path); - void setup_fs_path(LPCSTR fs_name); - IReader* setup_fs_ltx(LPCSTR fs_name); + void setup_fs_path(pcstr fs_name, string_path& fs_path); + void setup_fs_path(pcstr fs_name); + IReader* setup_fs_ltx(pcstr fs_name); public: CLocatorAPI(); ~CLocatorAPI(); - void _initialize(u32 flags, LPCSTR target_folder = 0, LPCSTR fs_name = 0); + void _initialize(u32 flags, pcstr target_folder = nullptr, pcstr fs_name = nullptr); void _destroy(); - CStreamReader* rs_open(LPCSTR initial, LPCSTR N); - IReader* r_open(LPCSTR initial, LPCSTR N); - IC IReader* r_open(LPCSTR N) { return r_open(0, N); } + CStreamReader* rs_open(pcstr initial, pcstr N); + IReader* r_open(pcstr initial, pcstr N); + IReader* r_open(pcstr N) { return r_open(nullptr, N); } void r_close(IReader*& S); void r_close(CStreamReader*& fs); - IWriter* w_open(LPCSTR initial, LPCSTR N); - IC IWriter* w_open(LPCSTR N) { return w_open(0, N); } - IWriter* w_open_ex(LPCSTR initial, LPCSTR N); - IC IWriter* w_open_ex(LPCSTR N) { return w_open_ex(0, N); } + IWriter* w_open(pcstr initial, pcstr N); + IWriter* w_open(pcstr N) { return w_open(nullptr, N); } + IWriter* w_open_ex(pcstr initial, pcstr N); + IWriter* w_open_ex(pcstr N) { return w_open_ex(nullptr, N); } void w_close(IWriter*& S); // For registered files only - const file* GetFileDesc(const char* path); + const file* GetFileDesc(pcstr path); - FileStatus exist(LPCSTR N, FSType fsType = FSType::Virtual); - FileStatus exist(LPCSTR path, LPCSTR name, FSType fsType = FSType::Virtual); - FileStatus exist(string_path& fn, LPCSTR path, LPCSTR name, FSType fsType = FSType::Virtual); - FileStatus exist(string_path& fn, LPCSTR path, LPCSTR name, LPCSTR ext, FSType fsType = FSType::Virtual); + FileStatus exist(pcstr N, FSType fsType = FSType::Virtual); + FileStatus exist(pcstr path, pcstr name, FSType fsType = FSType::Virtual); + FileStatus exist(string_path& fn, pcstr path, pcstr name, FSType fsType = FSType::Virtual); + FileStatus exist(string_path& fn, pcstr path, pcstr name, pcstr ext, FSType fsType = FSType::Virtual); - BOOL can_write_to_folder(LPCSTR path); - BOOL can_write_to_alias(LPCSTR path); - BOOL can_modify_file(LPCSTR fname); - BOOL can_modify_file(LPCSTR path, LPCSTR name); + bool can_write_to_folder(pcstr path); + bool can_write_to_alias(pcstr path); + bool can_modify_file(pcstr fname); + bool can_modify_file(pcstr path, pcstr name); - BOOL dir_delete(LPCSTR path, LPCSTR nm, BOOL remove_files); - BOOL dir_delete(LPCSTR full_path, BOOL remove_files) { return dir_delete(0, full_path, remove_files); } - void file_delete(LPCSTR path, LPCSTR nm); - void file_delete(LPCSTR full_path) { file_delete(0, full_path); } - void file_copy(LPCSTR src, LPCSTR dest); - void file_rename(LPCSTR src, LPCSTR dest, bool bOwerwrite = true); - int file_length(LPCSTR src); + bool dir_delete(pcstr path, pcstr nm, bool remove_files); + bool dir_delete(pcstr full_path, bool remove_files) { return dir_delete(nullptr, full_path, remove_files); } + void file_delete(pcstr path, pcstr nm); + void file_delete(pcstr full_path) { file_delete(nullptr, full_path); } + void file_copy(pcstr src, pcstr dest); + void file_rename(pcstr src, pcstr dest, bool overwrite = true); + int file_length(pcstr src); - u32 get_file_age(LPCSTR nm); - void set_file_age(LPCSTR nm, u32 age); + u32 get_file_age(pcstr nm); + void set_file_age(pcstr nm, u32 age); - xr_vector* file_list_open(LPCSTR initial, LPCSTR folder, u32 flags = FS_ListFiles); - xr_vector* file_list_open(LPCSTR path, u32 flags = FS_ListFiles); - void file_list_close(xr_vector*& lst); + xr_vector* file_list_open(pcstr initial, pcstr folder, u32 flags = FS_ListFiles); + xr_vector* file_list_open(pcstr path, u32 flags = FS_ListFiles); + void file_list_close(xr_vector*& lst); - bool path_exist(LPCSTR path); - FS_Path* get_path(LPCSTR path); - FS_Path* append_path(LPCSTR path_alias, LPCSTR root, LPCSTR add, BOOL recursive); - LPCSTR update_path(string_path& dest, LPCSTR initial, LPCSTR src); + bool path_exist(pcstr path); + FS_Path* get_path(pcstr path); + FS_Path* append_path(pcstr path_alias, pcstr root, pcstr add, bool recursive); + pcstr update_path(string_path& dest, pcstr initial, pcstr src); - int file_list(FS_FileSet& dest, LPCSTR path, u32 flags = FS_ListFiles, LPCSTR mask = 0); + int file_list(FS_FileSet& dest, pcstr path, u32 flags = FS_ListFiles, pcstr mask = nullptr); bool load_all_unloaded_archives(); void unload_archive(archive& A); @@ -201,7 +203,7 @@ class XRCORE_API CLocatorAPI u64 auth_get(); void auth_runtime(void*); - void rescan_path(LPCSTR full_path, BOOL bRecurse); + void rescan_path(pcstr full_path, bool bRecurse); // editor functions void rescan_pathes(); void lock_rescan();