Path_WINCE.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. //
  2. // Path_WIN32U.cpp
  3. //
  4. // $Id: //poco/1.4/Foundation/src/Path_WINCE.cpp#1 $
  5. //
  6. // Library: Foundation
  7. // Package: Filesystem
  8. // Module: Path
  9. //
  10. // Copyright (c) 2006-2010, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #include "Poco/Path_WINCE.h"
  16. #include "Poco/Environment_WINCE.h"
  17. #include "Poco/UnicodeConverter.h"
  18. #include "Poco/Buffer.h"
  19. #include "Poco/Environment.h"
  20. #include "Poco/Exception.h"
  21. #include "Poco/UnWindows.h"
  22. namespace Poco {
  23. std::string PathImpl::currentImpl()
  24. {
  25. return("\\");
  26. }
  27. std::string PathImpl::homeImpl()
  28. {
  29. return("\\");
  30. }
  31. std::string PathImpl::systemImpl()
  32. {
  33. return("\\");
  34. }
  35. std::string PathImpl::nullImpl()
  36. {
  37. return "NUL:";
  38. }
  39. std::string PathImpl::tempImpl()
  40. {
  41. return "\\Temp\\";
  42. }
  43. std::string PathImpl::expandImpl(const std::string& path)
  44. {
  45. std::string result;
  46. std::string::const_iterator it = path.begin();
  47. std::string::const_iterator end = path.end();
  48. while (it != end)
  49. {
  50. if (*it == '%')
  51. {
  52. ++it;
  53. if (it != end && *it == '%')
  54. {
  55. result += '%';
  56. }
  57. else
  58. {
  59. std::string var;
  60. while (it != end && *it != '%') var += *it++;
  61. if (it != end) ++it;
  62. result += Environment::get(var, "");
  63. }
  64. }
  65. else result += *it++;
  66. }
  67. return result;
  68. }
  69. void PathImpl::listRootsImpl(std::vector<std::string>& roots)
  70. {
  71. roots.clear();
  72. roots.push_back("\\");
  73. WIN32_FIND_DATAW fd;
  74. HANDLE hFind = FindFirstFileW(L"\\*.*", &fd);
  75. if (hFind != INVALID_HANDLE_VALUE)
  76. {
  77. do
  78. {
  79. if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
  80. (fd.dwFileAttributes & FILE_ATTRIBUTE_TEMPORARY))
  81. {
  82. std::wstring name(fd.cFileName);
  83. name += L"\\Vol:";
  84. HANDLE h = CreateFileW(name.c_str(), GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
  85. if (h != INVALID_HANDLE_VALUE)
  86. {
  87. // its a device volume
  88. CloseHandle(h);
  89. std::string name;
  90. UnicodeConverter::toUTF8(fd.cFileName, name);
  91. std::string root = "\\" + name;
  92. roots.push_back(root);
  93. }
  94. }
  95. }
  96. while (FindNextFileW(hFind, &fd));
  97. FindClose(hFind);
  98. }
  99. }
  100. } // namespace Poco