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