core/systems/LibrarySys.h
author Borja Ferrer <faluco@alliedmods.net>
Thu Jul 05 14:47:36 2007 +0000 (2007-07-05)
changeset 1041 f7b2073013df
parent 978 54782a83a1ef
child 1192 94ee3f012044
permissions -rw-r--r--
added a time stamp argument to FormatTime
     1 /**
     2  * vim: set ts=4 :
     3  * ===============================================================
     4  * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
     5  * ===============================================================
     6  *
     7  * This file is not open source and may not be copied without explicit
     8  * written permission of AlliedModders LLC.  This file may not be redistributed 
     9  * in whole or significant part.
    10  * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
    11  *
    12  * Version: $Id$
    13  */
    14 
    15 #ifndef _INCLUDE_SOURCEMOD_SYSTEM_LIBRARY_H_
    16 #define _INCLUDE_SOURCEMOD_SYSTEM_LIBRARY_H_
    17 
    18 #include <ILibrarySys.h>
    19 #include "sm_platform.h"
    20 
    21 using namespace SourceMod;
    22 
    23 #if defined PLATFORM_WINDOWS
    24 typedef HMODULE		LibraryHandle;
    25 #elif defined PLATFORM_POSIX
    26 typedef void *		LibraryHandle;
    27 #endif
    28 
    29 class CDirectory : public IDirectory
    30 {
    31 public:
    32 	CDirectory(const char *path);
    33 	~CDirectory();
    34 public:
    35 	bool MoreFiles();
    36 	void NextEntry();
    37 	const char *GetEntryName();
    38 	bool IsEntryDirectory();
    39 	bool IsEntryFile();
    40 	bool IsEntryValid();
    41 public:
    42 	bool IsValid();
    43 private:
    44 #if defined PLATFORM_WINDOWS
    45 	HANDLE m_dir;
    46 	WIN32_FIND_DATAA m_fd;
    47 #elif defined PLATFORM_POSIX
    48 	DIR *m_dir;
    49 	struct dirent *ep;
    50 	char m_origpath[PLATFORM_MAX_PATH];
    51 #endif
    52 };
    53 
    54 class CLibrary : public ILibrary
    55 {
    56 public:
    57 	CLibrary(LibraryHandle me);
    58 	~CLibrary();
    59 public:
    60 	void CloseLibrary();
    61 	void *GetSymbolAddress(const char *symname);
    62 private:
    63 	LibraryHandle m_lib;
    64 };
    65 
    66 class LibrarySystem : public ILibrarySys
    67 {
    68 public:
    69 	ILibrary *OpenLibrary(const char *path, char *error, size_t maxlength);
    70 	IDirectory *OpenDirectory(const char *path);
    71 	void CloseDirectory(IDirectory *dir);
    72 	bool PathExists(const char *path);
    73 	bool IsPathFile(const char *path);
    74 	bool IsPathDirectory(const char *path);
    75 	void GetPlatformError(char *error, size_t maxlength);
    76 	size_t PathFormat(char *buffer, size_t len, const char *fmt, ...);
    77 	const char *GetFileExtension(const char *filename);
    78 	bool CreateDirectory(const char *path);
    79 	size_t GetFileFromPath(char *buffer, size_t maxlength, const char *path);
    80 };
    81 
    82 extern LibrarySystem g_LibSys;
    83 
    84 #endif //_INCLUDE_SOURCEMOD_SYSTEM_LIBRARY_H_