1 /* 2 * Holotz's Castle 3 * Copyright (C) 2004 Juan Carlos Seijo P�rez 4 * 5 * This program is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License as published by the Free 7 * Software Foundation; either version 2 of the License, or (at your option) 8 * any later version. 9 * 10 * This program is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 * more details. 14 * 15 * You should have received a copy of the GNU General Public License along 16 * with this program; if not, write to the Free Software Foundation, Inc., 59 17 * Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 * 19 * Juan Carlos Seijo P�rez 20 * jacob@mainreactor.net 21 */ 22 23 /** Utility functions for Holotz's Castle. 24 * @file HCUtil.h 25 * @author Juan Carlos Seijo P�rez 26 * @date 05/02/2005 27 * @version 0.0.1 - 05/02/2005 - First version. 28 */ 29 30 #ifndef _HCUTIL_INCLUDED 31 #define _HCUTIL_INCLUDED 32 33 #ifndef HC_DATA_DIR 34 #define HC_DATA_DIR "res/" 35 #endif 36 37 #ifndef FILESYS_BAR 38 #ifdef _WIN32 39 #define FILESYS_BAR '\\' 40 #else 41 #define FILESYS_BAR '/' 42 #endif // _WIN32 43 #endif // FILESYS_BAR 44 45 #include <sys/types.h> 46 #include <dirent.h> 47 #include <stdlib.h> 48 #include <vector> 49 #include <JLib/Util/JFile.h> 50 #include <JLib/Util/JString.h> 51 52 class HCUtil 53 { 54 static const char *curDir; 55 static const char *installHCDir; 56 static const char *installHCedDir; 57 static char homeDir[4096]; 58 static char lastFile[4096]; 59 static const char *lastPath; 60 static std::vector<JString> themes; 61 static std::vector<JString> stories; 62 63 public: 64 /** Searchs the given file or directory within the standard dirs: 65 * - Current dir 66 * - Installation dir 67 * - Home dir 68 * @return <b>true</b> if found, <b>false<b> otherwise. 69 */ 70 static bool FindFile(const char *filename); 71 72 /** Returns the last queried file. If none, returns an empty string. 73 * @return Last queried file, with its full resolved path preceding it. 74 */ File()75 static const char* File() {return lastFile;} 76 77 /** Returns the last queried file's path, 0 if it wasn't found. 78 * @return Last queried file, with its full resolved path preceding it. 79 */ Path()80 static const char* Path() {return lastPath;} 81 82 /** Searchs for themes within the standard dirs: 83 * - Current dir 84 * - Installation dir (si onlyEdit es false, por defecto) 85 * - Home dir 86 * @param onlyEdit Indica si se debe buscar en el directorio de instalaci�n (protegido) o no. 87 * @return <b>true</b> if any found, <b>false<b> otherwise. 88 */ 89 static bool FindThemes(bool onlyEdit = false); 90 91 /** Searchs for stories within the standard dirs: 92 * - Current dir 93 * - Installation dir (si onlyEdit es false, por defecto) 94 * - Home dir 95 * @param onlyEdit Indica si se debe buscar en el directorio de instalaci�n (protegido) o no. 96 * @return <b>true</b> if any found, <b>false<b> otherwise. 97 */ 98 static bool FindStories(bool onlyEdit = false); 99 100 /** Returns the found themes. 101 */ Themes()102 static std::vector<JString> & Themes() {return themes;} 103 104 /** Returns the found stories. 105 */ Stories()106 static std::vector<JString> & Stories() {return stories;} 107 108 /** Creates a new story in the first stories directory found in the standard path: 109 * - Current dir 110 * - Installation dir 111 * - Home dir 112 * @return 0 if stories dir found and there was no other story with the same name, 1 if a story with the same name existed, 113 * 2 if the stories directory couldn't be found and 3 if there was an error creating the story's directory. 114 */ 115 static s32 CreateStory(const char *story); 116 117 /** Frees allocated resources and invalidates the themes and stories. 118 */ 119 static void Destroy(); 120 }; 121 122 #endif // _HCUTIL_INCLUDED 123