AndroidPlatform.cpp 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. #include <unistd.h>
  23. #include "platform/platform.h"
  24. #include "console/console.h"
  25. #include "string/stringTable.h"
  26. #include "platform/platformInput.h"
  27. #include "platform/threads/thread.h"
  28. #pragma mark ---- Various Directories ----
  29. //-----------------------------------------------------------------------------
  30. const char* Platform::getUserDataDirectory()
  31. {
  32. // application support directory is most in line with the current usages of this function.
  33. // this may change with later usage
  34. // perhaps the user data directory should be pref-controlled?
  35. //NSString *nsDataDir = [@"~/Library/Application Support/" stringByStandardizingPath];
  36. //-Mat using Documents directory in same folder as .app
  37. //TODO: replace objc
  38. /*NSString *nsDataDir = [@"~/Documents/" stringByStandardizingPath];
  39. return StringTable->insert([nsDataDir UTF8String]);
  40. */
  41. return StringTable->insert("");
  42. }
  43. //-----------------------------------------------------------------------------
  44. const char* Platform::getUserHomeDirectory()
  45. {
  46. //TODO: replace objc
  47. /*
  48. return StringTable->insert([[@"~/" stringByStandardizingPath] UTF8String]);
  49. */
  50. return StringTable->insert("");
  51. }
  52. //-----------------------------------------------------------------------------
  53. StringTableEntry Platform::osGetTemporaryDirectory()
  54. {
  55. //TODO: replace objc
  56. /*NSString *tdir = NSTemporaryDirectory();
  57. const char *path = [tdir UTF8String];
  58. return StringTable->insert(path);
  59. */
  60. return StringTable->insert("");
  61. }
  62. //-----------------------------------------------------------------------------
  63. S32 Platform::messageBox(const UTF8 *title, const UTF8 *message, MBButtons buttons, MBIcons icon)
  64. {
  65. Platform::AlertOK( title, message );//<Mat> maybe add in a a way to do other buttons
  66. return 1;
  67. }
  68. #pragma mark ---- File IO ----
  69. //-----------------------------------------------------------------------------
  70. bool Platform::pathCopy(const char* source, const char* dest, bool nooverwrite)
  71. {
  72. //TODO: replace objc
  73. /*
  74. NSFileManager *manager = [NSFileManager defaultManager];
  75. @autoreleasepool {
  76. NSString *nsource = [@(source) stringByStandardizingPath];
  77. NSString *ndest = [@(dest) stringByStandardizingPath];
  78. NSString *ndestFolder = [ndest stringByDeletingLastPathComponent];
  79. if(! [manager fileExistsAtPath:nsource])
  80. {
  81. Con::errorf("Platform::pathCopy: no file exists at %s",source);
  82. return false;
  83. }
  84. //Catcher for the errors.
  85. NSError* returnValue = nil;
  86. if( [manager fileExistsAtPath:ndest] )
  87. {
  88. if(nooverwrite)
  89. {
  90. Con::errorf("Platform::pathCopy file already exists at %s",dest);
  91. return false;
  92. }
  93. Con::warnf("Deleting files at path: %s", dest);
  94. bool deleted = [manager removeItemAtPath:ndest error:&returnValue];
  95. if(!deleted)
  96. {
  97. Con::errorf("Copy failed! Could not delete files at path: %s", dest);
  98. return false;
  99. }
  100. }
  101. if([manager fileExistsAtPath:ndestFolder] == NO)
  102. {
  103. ndestFolder = [ndestFolder stringByAppendingString:@"/"]; // createpath requires a trailing slash
  104. Platform::createPath([ndestFolder UTF8String]);
  105. }
  106. bool ret = [manager copyItemAtPath:nsource toPath:ndest error:&returnValue];
  107. return ret;
  108. }
  109. */
  110. return false;
  111. }
  112. //-----------------------------------------------------------------------------
  113. bool Platform::fileRename(const char *source, const char *dest)
  114. {
  115. //TODO: replace objc
  116. /*
  117. if(source == NULL || dest == NULL)
  118. return false;
  119. NSFileManager *manager = [NSFileManager defaultManager];
  120. NSString *nsource = [manager stringWithFileSystemRepresentation:source length:dStrlen(source)];
  121. NSString *ndest = [manager stringWithFileSystemRepresentation:dest length:dStrlen(dest)];
  122. if(! [manager fileExistsAtPath:nsource])
  123. {
  124. Con::errorf("Platform::fileRename: no file exists at %s",source);
  125. return false;
  126. }
  127. if( [manager fileExistsAtPath:ndest] )
  128. {
  129. Con::warnf("Platform::fileRename: Deleting files at path: %s", dest);
  130. }
  131. NSError* returnValue = NULL;
  132. bool ret = [manager moveItemAtPath:nsource toPath:ndest error:&returnValue];
  133. return ret;
  134. */
  135. return false;
  136. }
  137. #pragma mark ---- ShellExecute ----
  138. class ExecuteThread : public Thread
  139. {
  140. const char* zargs;
  141. const char* directory;
  142. const char* executable;
  143. public:
  144. ExecuteThread(const char *_executable, const char *_args /* = NULL */, const char *_directory /* = NULL */) : Thread(0, NULL, false, true)
  145. {
  146. zargs = dStrdup(_args);
  147. directory = dStrdup(_directory);
  148. executable = dStrdup(_executable);
  149. start();
  150. }
  151. virtual void run(void* arg);
  152. };
  153. static char* _unDoubleQuote(char* arg)
  154. {
  155. U32 len = dStrlen(arg);
  156. if(!len)
  157. return arg;
  158. if(arg[0] == '"' && arg[len-1] == '"')
  159. {
  160. arg[len - 1] = '\0';
  161. return arg + 1;
  162. }
  163. return arg;
  164. }
  165. void ExecuteThread::run(void* arg)
  166. {
  167. }
  168. ConsoleFunction(shellExecute, bool, 2, 4, "(executable, [args], [directory])")
  169. {
  170. return true; // Bug: BPNC error: need feedback on whether the command was sucessful
  171. }
  172. void Input::setCursorShape(U32 cursorID)
  173. {
  174. //no cursors on Android except Torque cursors
  175. }
  176. void Input::setCursorState(bool on)
  177. {
  178. }