1
0

api_applicationi.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. #include <precomp.h>
  2. //<?#include "<class data="implementationheader"/>"
  3. #include "api_applicationi.h"
  4. //?>
  5. #include <wasabicfg.h>
  6. #include <api/application/pathmgr.h>
  7. #include <api/application/version.h>
  8. #include <api/apiinit.h>
  9. #ifdef WA3COMPATIBILITY
  10. #include <runtime/main.h> // CUT!
  11. #include <wndmgr/layout.h> // CUT!
  12. #include <skin/skinparse.h>
  13. #endif
  14. StringW g_resourcepath;
  15. // {3CBD4483-DC44-11d3-B608-000086340885}
  16. static const GUID _baseGUID =
  17. { 0x3cbd4483, 0xdc44, 0x11d3, { 0xb6, 0x8, 0x0, 0x0, 0x86, 0x34, 0x8, 0x85 } };
  18. api_application *applicationApi = NULL;
  19. api_applicationI::api_applicationI(HINSTANCE instance, const wchar_t *_userPath)
  20. : appInstance(instance), mainthread(0), shuttingdown(0)
  21. {
  22. userPath = _userPath;
  23. #ifndef _WASABIRUNTIME
  24. #ifdef WASABI_DIRS_FROMEXEPATH
  25. HINSTANCE hInst = GetModuleHandle(0);
  26. #else
  27. HINSTANCE hInst = appInstance;
  28. #endif
  29. StringW path;
  30. {
  31. wchar_t g[WA_MAX_PATH];
  32. GetModuleFileNameW(hInst, g, WA_MAX_PATH - 1);
  33. wchar_t *p = wcsrchr(g, '\\');
  34. if (p) *p = 0;
  35. path = g;
  36. }
  37. #ifdef WIN32
  38. g_resourcepath = path;
  39. #elif defined(LINUX)
  40. g_resourcepath = "/usr/local/share/";
  41. g_resourcepath += WasabiVersion::getAppName();
  42. #endif
  43. #ifdef LINUX
  44. //char *file = getenv( "WASABI_LOG_FILE" );
  45. //if (!ACCESS(file, 0)) UNLINK(file);
  46. #endif
  47. apppath = path;
  48. g_resourcepath.AddBackslash();
  49. #if defined(WASABI_COMPILE_SKIN) || defined(WASABI_COMPILE_IMGLDR)
  50. g_resourcepath.AppendPath(WASABI_RESOURCES_SUBDIRECTORY);
  51. #endif
  52. #endif
  53. #ifdef WIN32
  54. HANDLE h = NULL;
  55. DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), &h, 0, FALSE, DUPLICATE_SAME_ACCESS);
  56. mainthread = h; // 32-bit writes assumed atomic
  57. #endif
  58. #ifdef LINUX
  59. DebugString("portme: api main thread handle dup\n");
  60. #endif
  61. }
  62. api_applicationI::~api_applicationI()
  63. {
  64. g_resourcepath.purge();
  65. }
  66. const wchar_t *api_applicationI::main_getAppName()
  67. {
  68. return WasabiVersion::getAppName();
  69. }
  70. const wchar_t *api_applicationI::main_getVersionString()
  71. {
  72. return WasabiVersion::getVersionString();
  73. }
  74. unsigned int api_applicationI::main_getBuildNumber()
  75. {
  76. return WasabiVersion::getBuildNumber();
  77. }
  78. GUID api_applicationI::main_getGUID()
  79. {
  80. return guid;
  81. }
  82. HANDLE api_applicationI::main_getMainThreadHandle()
  83. {
  84. if (mainthread == 0) return (HANDLE)0;
  85. HANDLE h = (HANDLE)0;
  86. #ifdef WIN32
  87. DuplicateHandle(GetCurrentProcess(), mainthread, GetCurrentProcess(), &h, 0, FALSE, DUPLICATE_SAME_ACCESS);
  88. #endif
  89. #ifdef LINUX
  90. DebugString("portme: dup handle\n");
  91. #endif
  92. return h;
  93. }
  94. HINSTANCE api_applicationI::main_gethInstance()
  95. {
  96. return appInstance;
  97. }
  98. const wchar_t *api_applicationI::main_getCommandLine()
  99. {
  100. return cmdLine;
  101. }
  102. void api_applicationI::main_shutdown(int deferred)
  103. {
  104. int x = 1;
  105. #ifdef WASABI_CHECK_CAN_EXIT
  106. WASABI_CHECK_CAN_EXIT(x)
  107. #endif
  108. if (!x) return ;
  109. shuttingdown = 1;
  110. #ifdef _WASABIRUNTIME
  111. Main::doAction(ACTION_CLOSE, deferred);
  112. #endif
  113. #ifdef WASABI_CUSTOM_QUIT
  114. WASABI_CUSTOM_QUITFN
  115. #endif
  116. }
  117. void api_applicationI::main_cancelShutdown()
  118. {
  119. #ifdef _WASABIRUNTIME
  120. Main::cancelShutdown();
  121. #endif
  122. shuttingdown = 0;
  123. }
  124. int api_applicationI::main_isShuttingDown()
  125. {
  126. return shuttingdown;
  127. }
  128. const wchar_t *api_applicationI::path_getAppPath()
  129. {
  130. #ifdef _WASABIRUNTIME
  131. return Main::getMainAppPath();
  132. #endif
  133. return apppath;
  134. }
  135. const wchar_t *api_applicationI::path_getUserSettingsPath()
  136. {
  137. return userPath;
  138. //return PathMgr::getUserSettingsPath();
  139. }
  140. void api_applicationI::setHInstance(HINSTANCE instance)
  141. {
  142. appInstance = instance;
  143. };
  144. void api_applicationI::setCommandLine(const wchar_t *cmdline)
  145. {
  146. cmdLine = cmdline;
  147. }
  148. void api_applicationI::setGUID(GUID g)
  149. {
  150. guid = g;
  151. }
  152. int api_applicationI::app_getInitCount()
  153. {
  154. return ApiInit::getInitCount();
  155. }
  156. int api_applicationI::app_messageLoopStep()
  157. {
  158. #if defined(WASABI_COMPILE_TIMERS) || defined(WASABI_COMPILE_WND)
  159. MSG msg;
  160. if (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
  161. {
  162. if (!GetMessage( &msg, NULL, 0, 0 )) return 0;
  163. #ifdef WASABI_COMPILE_WND
  164. TranslateMessage( &msg );
  165. #endif
  166. DispatchMessage( &msg );
  167. }
  168. #endif
  169. return 1;
  170. }