00001 /** 00002 * vim: set ts=4 : 00003 * ============================================================================= 00004 * SourceMod 00005 * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. 00006 * ============================================================================= 00007 * 00008 * This program is free software; you can redistribute it and/or modify it under 00009 * the terms of the GNU General Public License, version 3.0, as published by the 00010 * Free Software Foundation. 00011 * 00012 * This program is distributed in the hope that it will be useful, but WITHOUT 00013 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00014 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 00015 * details. 00016 * 00017 * You should have received a copy of the GNU General Public License along with 00018 * this program. If not, see <http://www.gnu.org/licenses/>. 00019 * 00020 * As a special exception, AlliedModders LLC gives you permission to link the 00021 * code of this program (as well as its derivative works) to "Half-Life 2," the 00022 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software 00023 * by the Valve Corporation. You must obey the GNU General Public License in 00024 * all respects for all other code used. Additionally, AlliedModders LLC grants 00025 * this exception to all derivative works. AlliedModders LLC defines further 00026 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), 00027 * or <http://www.sourcemod.net/license.php>. 00028 * 00029 * Version: $Id: ILibrarySys.h 1964 2008-03-27 04:54:56Z damagedsoul $ 00030 */ 00031 00032 #ifndef _INCLUDE_SOURCEMOD_LIBRARY_INTERFACE_SYS_H_ 00033 #define _INCLUDE_SOURCEMOD_LIBRARY_INTERFACE_SYS_H_ 00034 00035 /** 00036 * @file ILibrarySys.h 00037 * @brief Defines platform-dependent operations, such as opening libraries and files. 00038 */ 00039 00040 #include <IShareSys.h> 00041 #include <time.h> 00042 00043 namespace SourceMod 00044 { 00045 #define SMINTERFACE_LIBRARYSYS_NAME "ILibrarySys" 00046 #define SMINTERFACE_LIBRARYSYS_VERSION 4 00047 00048 enum FileTimeType 00049 { 00050 FileTime_LastAccess = 0, /* Last access (not available on FAT) */ 00051 FileTime_Created = 1, /* Creation (not available on FAT) */ 00052 FileTime_LastChange = 2, /* Last modification */ 00053 }; 00054 00055 class ILibrary 00056 { 00057 public: 00058 /** Virtual destructor (calls CloseLibrary) */ 00059 virtual ~ILibrary() 00060 { 00061 }; 00062 public: 00063 /** 00064 * @brief Closes dynamic library and invalidates pointer. 00065 */ 00066 virtual void CloseLibrary() =0; 00067 00068 /** 00069 * @brief Retrieves a symbol pointer from the dynamic library. 00070 * 00071 * @param symname Symbol name. 00072 * @return Symbol pointer, NULL if not found. 00073 */ 00074 virtual void *GetSymbolAddress(const char *symname) =0; 00075 }; 00076 00077 /** 00078 * @brief Directory browsing abstraction. 00079 */ 00080 class IDirectory 00081 { 00082 public: 00083 /** Virtual destructor */ 00084 virtual ~IDirectory() 00085 { 00086 } 00087 public: 00088 /** 00089 * @brief Returns true if there are more files to read, false otherwise. 00090 */ 00091 virtual bool MoreFiles() =0; 00092 00093 /** 00094 * @brief Advances to the next entry in the stream. 00095 */ 00096 virtual void NextEntry() =0; 00097 00098 /** 00099 * @brief Returns the name of the current entry. 00100 */ 00101 virtual const char *GetEntryName() =0; 00102 00103 /** 00104 * @brief Returns whether the current entry is a directory. 00105 */ 00106 virtual bool IsEntryDirectory() =0; 00107 00108 /** 00109 * @brief Returns whether the current entry is a file. 00110 */ 00111 virtual bool IsEntryFile() =0; 00112 00113 /** 00114 * @brief Returns true if the current entry is valid 00115 * (Used similarly to MoreFiles). 00116 */ 00117 virtual bool IsEntryValid() =0; 00118 }; 00119 00120 /** 00121 * @brief Contains various operating system specific code. 00122 */ 00123 class ILibrarySys : public SMInterface 00124 { 00125 public: 00126 virtual const char *GetInterfaceName() 00127 { 00128 return SMINTERFACE_LIBRARYSYS_NAME; 00129 } 00130 virtual unsigned int GetInterfaceVersion() 00131 { 00132 return SMINTERFACE_LIBRARYSYS_VERSION; 00133 } 00134 public: 00135 /** 00136 * @brief Opens a dynamic library file. 00137 * 00138 * @param path Path to library file (.dll/.so). 00139 * @param error Buffer for any error message (may be NULL). 00140 * @param maxlength Maximum length of error buffer. 00141 * @return Pointer to an ILibrary, NULL if failed. 00142 */ 00143 virtual ILibrary *OpenLibrary(const char *path, char *error, size_t maxlength) =0; 00144 00145 /** 00146 * @brief Opens a directory for reading. 00147 * 00148 * @param path Path to directory. 00149 * @return Pointer to an IDirectory, NULL if failed. 00150 */ 00151 virtual IDirectory *OpenDirectory(const char *path) =0; 00152 00153 /** 00154 * @brief Closes a directory and frees its handle. 00155 * 00156 * @param dir Pointer to IDirectory. 00157 */ 00158 virtual void CloseDirectory(IDirectory *dir) =0; 00159 00160 /** 00161 * @brief Returns true if a path exists. 00162 */ 00163 virtual bool PathExists(const char *path) =0; 00164 00165 /** 00166 * @brief Returns true if the path is a normal file. 00167 */ 00168 virtual bool IsPathFile(const char *path) =0; 00169 00170 /** 00171 * @brief Returns true if the path is a normal directory. 00172 */ 00173 virtual bool IsPathDirectory(const char *path) =0; 00174 00175 /** 00176 * @brief Gets a platform-specific error message. 00177 * This should only be called when an ILibrary function fails. 00178 * Win32 equivalent: GetLastError() + FormatMessage() 00179 * POSIX equivalent: errno + strerror() 00180 * 00181 * @param error Error message buffer. 00182 * @param maxlength Maximum length of error buffer. 00183 */ 00184 virtual void GetPlatformError(char *error, size_t maxlength) =0; 00185 00186 /** 00187 * @brief Formats a string similar to snprintf(), except 00188 * corrects all non-platform compatible path separators to be 00189 * the correct platform character. 00190 * 00191 * @param buffer Output buffer pointer. 00192 * @param maxlength Output buffer size. 00193 * @param pathfmt Format string of path. 00194 * @param ... Format string arguments. 00195 */ 00196 virtual size_t PathFormat(char *buffer, size_t maxlength, const char *pathfmt, ...) =0; 00197 00198 /** 00199 * @brief Returns a pointer to the extension in a filename. 00200 * 00201 * @param filename Name of file from which the extension should be extracted. 00202 * @return Pointer to file extension. 00203 */ 00204 virtual const char *GetFileExtension(const char *filename) =0; 00205 00206 /** 00207 * @brief Creates a directory. 00208 * 00209 * @param path Full, absolute path of the directory to create. 00210 * @return True on success, false otherwise. 00211 */ 00212 virtual bool CreateFolder(const char *path) =0; 00213 00214 /** 00215 * @brief Returns the requested timestamp of a file. 00216 * 00217 * NOTE: On FAT file systems, the access and creation times 00218 * may not be valid. 00219 * 00220 * @param path Path to file. 00221 * @param type FileTimeType of time value to request. 00222 * @param pTime Pointer to store time. 00223 * @return True on success, false on failure. 00224 */ 00225 virtual bool FileTime(const char *path, FileTimeType type, time_t *pTime) =0; 00226 }; 00227 } 00228 00229 #endif //_INCLUDE_SOURCEMOD_LIBRARY_INTERFACE_SYS_H_
1.5.1