1
0

application.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #include <stdio.h>
  2. #include "main.h"
  3. #include "api__wasabi2.h"
  4. #include "application.h"
  5. #include <nx/nxstring.h>
  6. #include <foundation/error.h>
  7. #include <shlobj.h>
  8. #include <nswasabi/ReferenceCounted.h>
  9. #include <strsafe.h>
  10. #include <Replicant/version.h>
  11. Application::Application()
  12. {
  13. // string_heap = 0;
  14. user_agent[0]=0;
  15. version_string=0;
  16. build_number=0;
  17. }
  18. Application::~Application()
  19. {
  20. NXStringRelease(version_string);
  21. }
  22. int Application::Init()
  23. {
  24. int ret = ApplicationBase::Initialize();
  25. if (ret != NErr_Success)
  26. return ret;
  27. #if 0
  28. string_heap = HeapCreate(0, 0, 0);
  29. if (!string_heap)
  30. return INIT_ERROR_STRING_HEAP;
  31. ULONG argh = 2;
  32. HeapSetInformation(string_heap, HeapCompatibilityInformation, &argh, sizeof(ULONG));
  33. NXStringSetHeap(string_heap);
  34. #endif
  35. /* set the device id */
  36. GUID winamp_id;
  37. WASABI_API_APP->GetUserID(&winamp_id);
  38. ReferenceCountedNXString device_id;
  39. NXStringCreateWithFormatting(&device_id, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
  40. (int)winamp_id.Data1, (int)winamp_id.Data2, (int)winamp_id.Data3, (int)winamp_id.Data4[0],
  41. (int)winamp_id.Data4[1], (int)winamp_id.Data4[2], (int)winamp_id.Data4[3],
  42. (int)winamp_id.Data4[4], (int)winamp_id.Data4[5], (int)winamp_id.Data4[6], (int)winamp_id.Data4[7]);
  43. ApplicationBase::SetDeviceID(device_id);
  44. /* set the data path */
  45. const wchar_t *settings = WASABI_API_APP->path_getUserSettingsPath();
  46. ReferenceCountedNXURI settings_uri;
  47. NXURICreateWithUTF16(&settings_uri, settings);
  48. ApplicationBase::SetDataPath(settings_uri);
  49. build_number = WASABI_API_APP->main_getBuildNumber();
  50. const wchar_t *version_number_string = WASABI_API_APP->main_getVersionNumString();
  51. NXStringCreateWithUTF16(&version_string, version_number_string);
  52. OSVERSIONINFO info;
  53. info.dwOSVersionInfoSize=sizeof(info);
  54. GetVersionExW(&info);
  55. StringCbPrintfA(user_agent, sizeof(user_agent), "Winamp/%S (Windows NT %u.%u) Replicant/%s", WASABI_API_APP->main_getVersionNumString(), info.dwMajorVersion, info.dwMinorVersion, replicant_version);
  56. ApplicationBase::EnableAllPermissions();
  57. return NErr_Success;
  58. }
  59. const char *Application::Application_GetUserAgent()
  60. {
  61. return user_agent;
  62. }
  63. unsigned int Application::Application_GetBuildNumber()
  64. {
  65. return build_number;
  66. }
  67. int Application::Application_GetVersionString(nx_string_t *version)
  68. {
  69. *version = NXStringRetain(version_string);
  70. return NErr_Success;
  71. }
  72. int Application::Application_GetProductShortName(nx_string_t *name)
  73. {
  74. return NXStringCreateWithUTF8(name, "Winamp");
  75. }