diff --git a/core/CoreConfig.cpp b/core/CoreConfig.cpp index 1cce9f4d..36fef52c 100644 --- a/core/CoreConfig.cpp +++ b/core/CoreConfig.cpp @@ -35,11 +35,12 @@ #include "sourcemm_api.h" #include "sm_srvcmds.h" #include "sm_stringutil.h" -#include "LibrarySys.h" #include "Logger.h" #include "frame_hooks.h" #include "logic_bridge.h" #include +#include +#include #ifdef PLATFORM_WINDOWS ConVar sm_corecfgfile("sm_corecfgfile", "addons\\sourcemod\\configs\\core.cfg", 0, "SourceMod core configuration file"); @@ -237,7 +238,7 @@ void CoreConfig::Initialize() */ if (corecfg) { - g_LibSys.PathFormat(filePath, sizeof(filePath), "%s/%s", g_SourceMod.GetGamePath(), corecfg); + ke::path::Format(filePath, sizeof(filePath), "%s/%s", g_SourceMod.GetGamePath(), corecfg); } else { @@ -246,11 +247,11 @@ void CoreConfig::Initialize() /* Format path to config file */ if (basepath) { - g_LibSys.PathFormat(filePath, sizeof(filePath), "%s/%s/%s", g_SourceMod.GetGamePath(), basepath, "configs/core.cfg"); + ke::path::Format(filePath, sizeof(filePath), "%s/%s/%s", g_SourceMod.GetGamePath(), basepath, "configs/core.cfg"); } else { - g_LibSys.PathFormat(filePath, sizeof(filePath), "%s/%s", g_SourceMod.GetGamePath(), sm_corecfgfile.GetDefault()); + ke::path::Format(filePath, sizeof(filePath), "%s/%s", g_SourceMod.GetGamePath(), sm_corecfgfile.GetDefault()); } } @@ -341,12 +342,12 @@ bool SM_ExecuteConfig(IPlugin *pl, AutoConfig *cfg, bool can_create) g_SourceMod.BuildPath(Path_Game, path, sizeof(path), "cfg/%s", folder); - if (!g_LibSys.IsPathDirectory(path)) + if (!ke::file::IsDirectory(path)) { char *cur_ptr = path; size_t len; - g_LibSys.PathFormat(path, sizeof(path), "%s", folder); + ke::path::Format(path, sizeof(path), "%s", folder); len = g_SourceMod.BuildPath(Path_Game, build, sizeof(build), "cfg"); do @@ -367,14 +368,12 @@ bool SM_ExecuteConfig(IPlugin *pl, AutoConfig *cfg, bool can_create) { next_ptr = NULL; } - len += g_LibSys.PathFormat(&build[len], + len += ke::path::Format(&build[len], sizeof(build)-len, "/%s", cur_ptr); - if (!g_LibSys.CreateFolder(build)) - { + if (!ke::file::CreateDirectory(build)) break; - } cur_ptr = next_ptr; } while (cur_ptr); } @@ -386,13 +385,13 @@ bool SM_ExecuteConfig(IPlugin *pl, AutoConfig *cfg, bool can_create) if (cfg->folder.size()) { - g_LibSys.PathFormat(local, - sizeof(local), + ke::path::Format(local, + sizeof(local), "%s/%s.cfg", cfg->folder.c_str(), cfg->autocfg.c_str()); } else { - g_LibSys.PathFormat(local, + ke::path::Format(local, sizeof(local), "%s.cfg", cfg->autocfg.c_str()); @@ -400,7 +399,7 @@ bool SM_ExecuteConfig(IPlugin *pl, AutoConfig *cfg, bool can_create) g_SourceMod.BuildPath(Path_Game, file, sizeof(file), "cfg/%s", local); - bool file_exists = g_LibSys.IsPathFile(file); + bool file_exists = ke::file::IsFile(file); if (!file_exists && will_create) { List *convars = NULL; diff --git a/core/LibrarySys.cpp b/core/LibrarySys.cpp index 6c568f90..3afab21b 100644 --- a/core/LibrarySys.cpp +++ b/core/LibrarySys.cpp @@ -36,6 +36,8 @@ #include #include "sm_stringutil.h" #include "LibrarySys.h" +#include +#include LibrarySystem g_LibSys; @@ -124,7 +126,7 @@ bool CDirectory::IsEntryDirectory() #elif defined PLATFORM_POSIX char temppath[PLATFORM_MAX_PATH]; snprintf(temppath, sizeof(temppath), "%s/%s", m_origpath, GetEntryName()); - return g_LibSys.IsPathDirectory(temppath); + return ke::file::IsDirectory(temppath); #endif } @@ -135,7 +137,7 @@ bool CDirectory::IsEntryFile() #elif defined PLATFORM_POSIX char temppath[PLATFORM_MAX_PATH]; snprintf(temppath, sizeof(temppath), "%s/%s", m_origpath, GetEntryName()); - return g_LibSys.IsPathFile(temppath); + return ke::file::IsFile(temppath); #endif } @@ -170,75 +172,17 @@ bool CDirectory::IsValid() bool LibrarySystem::PathExists(const char *path) { -#if defined PLATFORM_WINDOWS - DWORD attr = GetFileAttributesA(path); - - return (attr != INVALID_FILE_ATTRIBUTES); -#elif defined PLATFORM_POSIX - struct stat s; - - return (stat(path, &s) == 0); -#endif + return ke::file::PathExists(path); } bool LibrarySystem::IsPathFile(const char *path) { -#if defined PLATFORM_WINDOWS - DWORD attr = GetFileAttributes(path); - - if (attr == INVALID_FILE_ATTRIBUTES) - { - return false; - } - - if (attr & (FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_DEVICE)) - { - return false; - } - - return true; -#elif defined PLATFORM_POSIX - struct stat s; - - if (stat(path, &s) != 0) - { - return false; - } - - return S_ISREG(s.st_mode) ? true : false; -#endif + return ke::file::IsFile(path); } bool LibrarySystem::IsPathDirectory(const char *path) { -#if defined PLATFORM_WINDOWS - DWORD attr = GetFileAttributes(path); - - if (attr == INVALID_FILE_ATTRIBUTES) - { - return false; - } - - if (attr & FILE_ATTRIBUTE_DIRECTORY) - { - return true; - } - -#elif defined PLATFORM_POSIX - struct stat s; - - if (stat(path, &s) != 0) - { - return false; - } - - if (S_ISDIR(s.st_mode)) - { - return true; - } -#endif - - return false; + return ke::file::IsDirectory(path); } IDirectory *LibrarySystem::OpenDirectory(const char *path) @@ -307,23 +251,8 @@ size_t LibrarySystem::PathFormat(char *buffer, size_t len, const char *fmt, ...) { va_list ap; va_start(ap, fmt); - size_t mylen = vsnprintf(buffer, len, fmt, ap); + size_t mylen = ke::path::FormatVa(buffer, len, fmt, ap); va_end(ap); - - if (mylen >= len) - { - mylen = len - 1; - buffer[mylen] = '\0'; - } - - for (size_t i=0; i +#include #if defined _WIN32 #define MATCHMAKINGDS_SUFFIX "" @@ -653,7 +654,7 @@ void InitLogicBridge() char path[PLATFORM_MAX_PATH]; - g_LibSys.PathFormat(path, sizeof(path), "%s/bin/matchmaking_ds%s.%s", g_SMAPI->GetBaseDir(), MATCHMAKINGDS_SUFFIX, MATCHMAKINGDS_EXT); + ke::path::Format(path, sizeof(path), "%s/bin/matchmaking_ds%s.%s", g_SMAPI->GetBaseDir(), MATCHMAKINGDS_SUFFIX, MATCHMAKINGDS_EXT); if (ke::Ref mmlib = ke::SharedLib::Open(path, NULL, 0)) { diff --git a/core/sourcemod.cpp b/core/sourcemod.cpp index 640e0fa7..e98ca658 100644 --- a/core/sourcemod.cpp +++ b/core/sourcemod.cpp @@ -43,6 +43,7 @@ #include "frame_hooks.h" #include "logic_bridge.h" #include +#include SH_DECL_HOOK6(IServerGameDLL, LevelInit, SH_NOATTRIB, false, bool, const char *, const char *, const char *, const char *, bool, bool); SH_DECL_HOOK0_void(IServerGameDLL, LevelShutdown, SH_NOATTRIB, false); @@ -106,8 +107,8 @@ ConfigResult SourceModBase::OnSourceModConfigChanged(const char *key, if (!m_GotBasePath) { - g_LibSys.PathFormat(m_SMBaseDir, sizeof(m_SMBaseDir), "%s/%s", g_BaseDir.c_str(), value); - g_LibSys.PathFormat(m_SMRelDir, sizeof(m_SMRelDir), value); + ke::path::Format(m_SMBaseDir, sizeof(m_SMBaseDir), "%s/%s", g_BaseDir.c_str(), value); + ke::path::Format(m_SMRelDir, sizeof(m_SMRelDir), value); m_GotBasePath = true; } @@ -164,8 +165,8 @@ bool SourceModBase::InitializeSourceMod(char *error, size_t maxlength, bool late basepath = sm_basepath.GetDefault(); } - g_LibSys.PathFormat(m_SMBaseDir, sizeof(m_SMBaseDir), "%s/%s", g_BaseDir.c_str(), basepath); - g_LibSys.PathFormat(m_SMRelDir, sizeof(m_SMRelDir), "%s", basepath); + ke::path::Format(m_SMBaseDir, sizeof(m_SMBaseDir), "%s/%s", g_BaseDir.c_str(), basepath); + ke::path::Format(m_SMRelDir, sizeof(m_SMRelDir), "%s", basepath); if (!StartLogicBridge(error, maxlength)) { @@ -443,7 +444,7 @@ size_t SourceModBase::BuildPath(PathType type, char *buffer, size_t maxlength, c */ if (type != Path_SM_Rel && strncmp(_buffer, "file://", 7) == 0) { - return g_LibSys.PathFormat(buffer, maxlength, "%s", &_buffer[7]); + return ke::path::Format(buffer, maxlength, "%s", &_buffer[7]); } const char *base = NULL; @@ -462,11 +463,11 @@ size_t SourceModBase::BuildPath(PathType type, char *buffer, size_t maxlength, c if (base) { - return g_LibSys.PathFormat(buffer, maxlength, "%s/%s", base, _buffer); + return ke::path::Format(buffer, maxlength, "%s/%s", base, _buffer); } else { - return g_LibSys.PathFormat(buffer, maxlength, "%s", _buffer); + return ke::path::Format(buffer, maxlength, "%s", _buffer); } }