WinPhoneUtil.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include <wrl.h>
  2. #include <string>
  3. //#include <stdio.h>
  4. //#include <share.h>
  5. //static const char *
  6. //GetRootPath()
  7. //{
  8. // static char buf[1024] = "";
  9. // if (buf[0] == '\0')
  10. // {
  11. // Platform::String^ localfolder = Windows::Storage::ApplicationData::Current->LocalFolder->Path;
  12. // const char16 *begin = localfolder->Begin();
  13. // WideCharToMultiByte(CP_ACP, 0, begin, -1, buf, 1024, NULL, FALSE);
  14. // }
  15. // return buf;
  16. //}
  17. //
  18. //static const char *
  19. //GetInstallPath()
  20. //{
  21. // static char buf[1024] = "";
  22. // if (buf[0] == '\0')
  23. // {
  24. // Platform::String^ installfolder = Windows::ApplicationModel::Package::Current->InstalledLocation->Path;
  25. // const char16 *begin = installfolder->Begin();
  26. // WideCharToMultiByte(CP_ACP, 0, begin, -1, buf, 1024, NULL, FALSE);
  27. // }
  28. // return buf;
  29. //}
  30. //
  31. //extern "C" FILE *
  32. //MY_fopen(const char *path, const char *mode)
  33. //{
  34. // return fopen(path, mode);
  35. //
  36. // const char *p = GetRootPath();
  37. // char buf[1024];
  38. // _snprintf_s(buf, 1024, "%s\\%s", p, path);
  39. // FILE *fp = _fsopen(buf, mode, _SH_DENYNO);
  40. // if (fp == NULL)
  41. // {
  42. // p = GetInstallPath();
  43. // _snprintf_s(buf, 1024, "%s\\%s", p, path);
  44. // fp = _fsopen(buf, mode, _SH_DENYNO);
  45. // }
  46. // if (fp == NULL)
  47. // {
  48. // p = GetRootPath();
  49. // _snprintf_s(buf, 1024, "%s\\Shared\\%s", p, path);
  50. // fp = _fsopen(buf, mode, _SH_DENYNO);
  51. // }
  52. // return fp;
  53. //}
  54. static std::string g_savepath;
  55. extern "C"
  56. LPCSTR UTIL_WP_SavePath(VOID)
  57. {
  58. Platform::String^ localfolder = Windows::Storage::ApplicationData::Current->LocalFolder->Path;
  59. int len = WideCharToMultiByte(CP_ACP, 0, localfolder->Begin(), -1, nullptr, 0, nullptr, nullptr);
  60. g_savepath.resize(len);
  61. WideCharToMultiByte(CP_ACP, 0, localfolder->Begin(), -1, (char*)g_savepath.data(), len, nullptr, nullptr);
  62. const_cast<char*>(g_savepath.data())[len - 1] = '\\';
  63. return g_savepath.c_str();
  64. }