AndroidPlatform.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. #include "platformAndroid/T2DActivity.h"
  29. #pragma mark ---- Various Directories ----
  30. //-----------------------------------------------------------------------------
  31. const char* Platform::getUserDataDirectory()
  32. {
  33. //on android we will be using the cache dir to store user data
  34. return StringTable->insert(activity.getCacheDir());
  35. }
  36. //-----------------------------------------------------------------------------
  37. const char* Platform::getUserHomeDirectory()
  38. {
  39. return StringTable->insert("~/");
  40. }
  41. //-----------------------------------------------------------------------------
  42. StringTableEntry Platform::osGetTemporaryDirectory()
  43. {
  44. //Android has no global temp folder, each application is expected to use cache dir
  45. return StringTable->insert(activity.getCacheDir());
  46. }
  47. //-----------------------------------------------------------------------------
  48. S32 Platform::messageBox(const UTF8 *title, const UTF8 *message, MBButtons buttons, MBIcons icon)
  49. {
  50. Platform::AlertOK( title, message );//<Mat> maybe add in a a way to do other buttons
  51. return 1;
  52. }
  53. #pragma mark ---- File IO ----
  54. //-----------------------------------------------------------------------------
  55. bool Platform::pathCopy(const char* source, const char* dest, bool nooverwrite)
  56. {
  57. Con::errorf("pathCopy is not supported on Android due to assets being in a zip file");
  58. return false;
  59. }
  60. //-----------------------------------------------------------------------------
  61. bool Platform::fileRename(const char *source, const char *dest)
  62. {
  63. Con::errorf("fileRename is not supported on Android due to assets being in a zip file");
  64. return false;
  65. }
  66. #pragma mark ---- ShellExecute ----
  67. class ExecuteThread : public Thread
  68. {
  69. const char* zargs;
  70. const char* directory;
  71. const char* executable;
  72. public:
  73. ExecuteThread(const char *_executable, const char *_args /* = NULL */, const char *_directory /* = NULL */) : Thread(0, NULL, false, true)
  74. {
  75. zargs = dStrdup(_args);
  76. directory = dStrdup(_directory);
  77. executable = dStrdup(_executable);
  78. start();
  79. }
  80. virtual void run(void* arg);
  81. };
  82. static char* _unDoubleQuote(char* arg)
  83. {
  84. U32 len = dStrlen(arg);
  85. if(!len)
  86. return arg;
  87. if(arg[0] == '"' && arg[len-1] == '"')
  88. {
  89. arg[len - 1] = '\0';
  90. return arg + 1;
  91. }
  92. return arg;
  93. }
  94. void ExecuteThread::run(void* arg)
  95. {
  96. }
  97. ConsoleFunction(shellExecute, bool, 2, 4, "(executable, [args], [directory])")
  98. {
  99. return true; // Bug: BPNC error: need feedback on whether the command was sucessful
  100. }
  101. void Input::setCursorShape(U32 cursorID)
  102. {
  103. //no cursors on Android except Torque cursors
  104. }
  105. void Input::setCursorState(bool on)
  106. {
  107. }