platform.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _PLATFORM_H_
  23. #define _PLATFORM_H_
  24. #ifndef _TORQUECONFIG_H_
  25. #include "torqueConfig.h"
  26. #endif
  27. #ifndef _TORQUE_TYPES_H_
  28. #include "platform/types.h"
  29. #endif
  30. #ifndef _PLATFORMASSERT_H_
  31. #include "platform/platformAssert.h"
  32. #endif
  33. #ifndef _MSGBOX_H_
  34. #include "platform/nativeDialogs/msgBox.h"
  35. #endif
  36. #ifndef TORQUE_OS_WIN32
  37. #include <algorithm>
  38. #endif
  39. #ifndef _PLATFORM_ENDIAN_H_
  40. #include "platform/platformEndian.h"
  41. #endif
  42. #ifndef _PLATFORM_CPU_H_
  43. #include "platform/platformCPU.h"
  44. #endif
  45. #ifndef _PLATFORM_STRING_H_
  46. #include "platform/platformString.h"
  47. #endif
  48. #ifndef _PLATFORM_NETWORK_H_
  49. #include "platform/platformNetwork.h"
  50. #endif
  51. #ifndef _PLATFORM_MEMORY_H_
  52. #include "platform/platformMemory.h"
  53. #endif
  54. #ifndef _PLATFORMFONT_H_
  55. #include "platform/platformFont.h"
  56. #endif
  57. #ifndef _PLATFORM_MATH_H_
  58. #include "platform/platformMath.h"
  59. #endif
  60. #ifndef _PLATFORM_TIME_MANAGER_H_
  61. #include "platform/platformTimeManager.h"
  62. #endif
  63. //------------------------------------------------------------------------------
  64. template <class T> class Vector;
  65. class Point2I;
  66. //------------------------------------------------------------------------------
  67. struct Platform
  68. {
  69. struct LocalTime
  70. {
  71. U8 sec; // seconds after minute (0-59)
  72. U8 min; // Minutes after hour (0-59)
  73. U8 hour; // Hours after midnight (0-23)
  74. U8 month; // Month (0-11; 0=january)
  75. U8 monthday; // Day of the month (1-31)
  76. U8 weekday; // Day of the week (0-6, 6=sunday)
  77. U16 year; // current year minus 1900
  78. U16 yearday; // Day of year (0-365)
  79. bool isdst; // true if daylight savings time is active
  80. };
  81. struct FileInfo
  82. {
  83. const char* pFullPath;
  84. const char* pFileName;
  85. U32 fileSize;
  86. bool equal( const FileInfo& fileInfo )
  87. {
  88. return
  89. fileInfo.pFullPath == pFullPath &&
  90. fileInfo.pFileName == pFileName &&
  91. fileInfo.fileSize == fileSize;
  92. }
  93. };
  94. struct VolumeInformation
  95. {
  96. StringTableEntry RootPath;
  97. StringTableEntry Name;
  98. StringTableEntry FileSystem;
  99. U32 SerialNumber;
  100. U32 Type;
  101. bool ReadOnly;
  102. };
  103. typedef void* FILE_HANDLE;
  104. enum DFILE_STATUS
  105. {
  106. DFILE_OK = 1
  107. };
  108. /// Application.
  109. static void init();
  110. static void initConsole();
  111. static void process();
  112. static void shutdown();
  113. static void sleep(U32 ms);
  114. static void restartInstance();
  115. static void postQuitMessage(const U32 in_quitVal);
  116. static void forceShutdown(S32 returnValue);
  117. /// User.
  118. static StringTableEntry getUserHomeDirectory();
  119. static StringTableEntry getUserDataDirectory();
  120. /// Window.
  121. static void initWindow(const Point2I &initialSize, const char *name);
  122. static void setWindowTitle( const char* title );
  123. static void setWindowSize( U32 newWidth, U32 newHeight );
  124. static const Point2I &getWindowSize();
  125. static void minimizeWindow();
  126. static void restoreWindow();
  127. static void setMouseLock(bool locked);
  128. /// GUI.
  129. static void AlertOK(const char *windowTitle, const char *message);
  130. static bool AlertOKCancel(const char *windowTitle, const char *message);
  131. static bool AlertRetry(const char *windowTitle, const char *message);
  132. static bool AlertYesNo(const char *windowTitle, const char *message);
  133. static S32 messageBox(const UTF8 *title, const UTF8 *message, MBButtons buttons = MBOkCancel, MBIcons icon = MIInformation);
  134. /// Input.
  135. static void enableKeyboardTranslation(void);
  136. static void disableKeyboardTranslation(void);
  137. /// Date & Time.
  138. static U32 getTime( void );
  139. static U32 getVirtualMilliseconds( void );
  140. static U32 getRealMilliseconds( void );
  141. static void advanceTime(U32 delta);
  142. static S32 getBackgroundSleepTime();
  143. static void getLocalTime(LocalTime &);
  144. static S32 compareFileTimes(const FileTime &a, const FileTime &b);
  145. /// Math.
  146. static float getRandom();
  147. /// Debug.
  148. static void debugBreak();
  149. static void outputDebugString(const char *string);
  150. static void cprintf(const char* str);
  151. /// File IO.
  152. static StringTableEntry getCurrentDirectory();
  153. static bool setCurrentDirectory(StringTableEntry newDir);
  154. static StringTableEntry getTemporaryDirectory();
  155. static StringTableEntry getTemporaryFileName();
  156. static StringTableEntry getExecutableName();
  157. static StringTableEntry getExecutablePath();
  158. static void setMainDotCsDir(const char *dir);
  159. static StringTableEntry getMainDotCsDir();
  160. static StringTableEntry getPrefsPath(const char *file = NULL);
  161. static char *makeFullPathName(const char *path, char *buffer, U32 size, const char *cwd = NULL);
  162. static StringTableEntry stripBasePath(const char *path);
  163. static bool isFullPath(const char *path);
  164. static StringTableEntry makeRelativePathName(const char *path, const char *to);
  165. static bool dumpPath(const char *in_pBasePath, Vector<FileInfo>& out_rFileVector, S32 recurseDepth = -1);
  166. static bool dumpDirectories( const char *path, Vector<StringTableEntry> &directoryVector, S32 depth = 0, bool noBasePath = false );
  167. static bool hasSubDirectory( const char *pPath );
  168. static bool getFileTimes(const char *filePath, FileTime *createTime, FileTime *modifyTime);
  169. static bool isFile(const char *pFilePath);
  170. static S32 getFileSize(const char *pFilePath);
  171. static bool hasExtension(const char* pFilename, const char* pExtension);
  172. static bool isDirectory(const char *pDirPath);
  173. static bool isSubDirectory(const char *pParent, const char *pDir);
  174. static void addExcludedDirectory(const char *pDir);
  175. static void clearExcludedDirectories();
  176. static bool isExcludedDirectory(const char *pDir);
  177. static bool createPath(const char *path);
  178. static bool deleteDirectory( const char* pPath );
  179. static bool fileDelete(const char *name);
  180. static bool fileRename(const char *oldName, const char *newName);
  181. static bool fileTouch(const char *name);
  182. static bool pathCopy(const char *fromName, const char *toName, bool nooverwrite = true);
  183. static StringTableEntry osGetTemporaryDirectory();
  184. /// Misc.
  185. static StringTableEntry createUUID( void );
  186. static bool openWebBrowser( const char* webAddress );
  187. static void openFolder( const char* path );
  188. static const char* getClipboard();
  189. static bool setClipboard(const char *text);
  190. };
  191. #endif // _PLATFORM_H_