WinPhoneUtil.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include <wrl.h>
  2. #include <stdio.h>
  3. static const char *
  4. GetRootPath()
  5. {
  6. static char buf[1024] = "";
  7. if (buf[0] == '\0')
  8. {
  9. Platform::String^ localfolder = Windows::Storage::ApplicationData::Current->LocalFolder->Path;
  10. const char16 *begin = localfolder->Begin();
  11. WideCharToMultiByte(CP_ACP, 0, begin, -1, buf, 1024, NULL, FALSE);
  12. }
  13. return buf;
  14. }
  15. static const char *
  16. GetInstallPath()
  17. {
  18. static char buf[1024] = "";
  19. if (buf[0] == '\0')
  20. {
  21. Platform::String^ installfolder = Windows::ApplicationModel::Package::Current->InstalledLocation->Path;
  22. const char16 *begin = installfolder->Begin();
  23. WideCharToMultiByte(CP_ACP, 0, begin, -1, buf, 1024, NULL, FALSE);
  24. }
  25. return buf;
  26. }
  27. extern "C" FILE *
  28. MY_fopen(const char *path, const char *mode)
  29. {
  30. const char *p = GetRootPath();
  31. char buf[1024];
  32. _snprintf_s(buf, 1024, "%s\\%s", p, path);
  33. FILE *fp = _fsopen(buf, mode, 0x40);
  34. if (fp == NULL)
  35. {
  36. p = GetInstallPath();
  37. _snprintf_s(buf, 1024, "%s\\%s", p, path);
  38. fp = _fsopen(buf, mode, 0x40);
  39. }
  40. if (fp == NULL)
  41. {
  42. p = GetRootPath();
  43. _snprintf_s(buf, 1024, "%s\\Shared\\%s", p, path);
  44. fp = _fsopen(buf, mode, 0x40);
  45. }
  46. return fp;
  47. }