FileSystem.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  1. //
  2. // Copyright (c) 2008-2013 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #include "Precompiled.h"
  23. #include "ArrayPtr.h"
  24. #include "Context.h"
  25. #include "File.h"
  26. #include "FileSystem.h"
  27. #include "Log.h"
  28. #include <cstdio>
  29. #include <cstring>
  30. #ifdef WIN32
  31. #ifndef _MSC_VER
  32. #define _WIN32_IE 0x400
  33. #endif
  34. #include <windows.h>
  35. #include <shellapi.h>
  36. #include <direct.h>
  37. #include <shlobj.h>
  38. #else
  39. #include <dirent.h>
  40. #include <errno.h>
  41. #include <unistd.h>
  42. #include <sys/stat.h>
  43. #include <sys/wait.h>
  44. #define MAX_PATH 256
  45. #endif
  46. #if defined(__APPLE__)
  47. #include <mach-o/dyld.h>
  48. #endif
  49. #ifdef ANDROID
  50. extern "C" const char* SDL_Android_GetFilesDir();
  51. #endif
  52. #ifdef IOS
  53. extern "C" const char* SDL_IOS_GetResourceDir();
  54. #endif
  55. #include "DebugNew.h"
  56. namespace Urho3D
  57. {
  58. FileSystem::FileSystem(Context* context) :
  59. Object(context)
  60. {
  61. }
  62. FileSystem::~FileSystem()
  63. {
  64. }
  65. bool FileSystem::SetCurrentDir(const String& pathName)
  66. {
  67. if (!CheckAccess(pathName))
  68. {
  69. LOGERROR("Access denied to " + pathName);
  70. return false;
  71. }
  72. #ifdef WIN32
  73. if (SetCurrentDirectoryW(GetWideNativePath(pathName).CString()) == FALSE)
  74. {
  75. LOGERROR("Failed to change directory to " + pathName);
  76. return false;
  77. }
  78. #else
  79. if (chdir(GetNativePath(pathName).CString()) != 0)
  80. {
  81. LOGERROR("Failed to change directory to " + pathName);
  82. return false;
  83. }
  84. #endif
  85. return true;
  86. }
  87. bool FileSystem::CreateDir(const String& pathName)
  88. {
  89. if (!CheckAccess(pathName))
  90. {
  91. LOGERROR("Access denied to " + pathName);
  92. return false;
  93. }
  94. #ifdef WIN32
  95. bool success = (CreateDirectoryW(GetWideNativePath(RemoveTrailingSlash(pathName)).CString(), 0) == TRUE) ||
  96. (GetLastError() == ERROR_ALREADY_EXISTS);
  97. #else
  98. bool success = mkdir(GetNativePath(RemoveTrailingSlash(pathName)).CString(), S_IRWXU) == 0 || errno == EEXIST;
  99. #endif
  100. if (success)
  101. LOGDEBUG("Created directory " + pathName);
  102. else
  103. LOGERROR("Failed to create directory " + pathName);
  104. return success;
  105. }
  106. int FileSystem::SystemCommand(const String& commandLine)
  107. {
  108. if (allowedPaths_.Empty())
  109. return system(commandLine.CString());
  110. else
  111. {
  112. LOGERROR("Executing an external command is not allowed");
  113. return -1;
  114. }
  115. }
  116. int FileSystem::SystemRun(const String& fileName, const Vector<String>& arguments)
  117. {
  118. if (allowedPaths_.Empty())
  119. {
  120. String fixedFileName = GetNativePath(fileName);
  121. #ifdef WIN32
  122. // Add .exe extension if no extension defined
  123. if (GetExtension(fixedFileName).Empty())
  124. fixedFileName += ".exe";
  125. // If executable is not found, try cwd-relative path as a fallback
  126. if (!FileExists(fixedFileName))
  127. fixedFileName = GetNativePath(GetCurrentDir() + GetFileNameAndExtension(fixedFileName));
  128. String commandLine = "\"" + fixedFileName + "\"";
  129. for (unsigned i = 0; i < arguments.Size(); ++i)
  130. commandLine += " " + arguments[i];
  131. STARTUPINFOW startupInfo;
  132. PROCESS_INFORMATION processInfo;
  133. memset(&startupInfo, 0, sizeof startupInfo);
  134. memset(&processInfo, 0, sizeof processInfo);
  135. WString commandLineW(commandLine);
  136. if (!CreateProcessW(NULL, (wchar_t*)commandLineW.CString(), 0, 0, 0, CREATE_NO_WINDOW, 0, 0, &startupInfo, &processInfo))
  137. {
  138. LOGERROR("Failed to execute command " + commandLine);
  139. return -1;
  140. }
  141. WaitForSingleObject(processInfo.hProcess, INFINITE);
  142. DWORD exitCode;
  143. GetExitCodeProcess(processInfo.hProcess, &exitCode);
  144. CloseHandle(processInfo.hProcess);
  145. CloseHandle(processInfo.hThread);
  146. return exitCode;
  147. #else
  148. // If executable is not found, try cwd-relative path as a fallback
  149. if (!FileExists(fixedFileName))
  150. fixedFileName = GetNativePath(GetCurrentDir() + GetFileNameAndExtension(fixedFileName));
  151. pid_t pid = fork();
  152. if (!pid)
  153. {
  154. PODVector<const char*> argPtrs;
  155. argPtrs.Push(fixedFileName.CString());
  156. for (unsigned i = 0; i < arguments.Size(); ++i)
  157. argPtrs.Push(arguments[i].CString());
  158. argPtrs.Push(0);
  159. execvp(argPtrs[0], (char**)&argPtrs[0]);
  160. return -1; // Return -1 if we could not spawn the process
  161. }
  162. else if (pid > 0)
  163. {
  164. int exitCode;
  165. wait(&exitCode);
  166. return exitCode;
  167. }
  168. else
  169. {
  170. LOGERROR("Failed to fork");
  171. return -1;
  172. }
  173. #endif
  174. }
  175. else
  176. {
  177. LOGERROR("Executing an external command is not allowed");
  178. return -1;
  179. }
  180. }
  181. bool FileSystem::SystemOpen(const String& fileName, const String& mode)
  182. {
  183. if (allowedPaths_.Empty())
  184. {
  185. if (!FileExists(fileName) && !DirExists(fileName))
  186. {
  187. LOGERROR("File or directory " + fileName + " not found");
  188. return false;
  189. }
  190. #ifdef WIN32
  191. bool success = (int)ShellExecuteW(0, !mode.Empty() ? WString(mode).CString() : 0,
  192. GetWideNativePath(fileName).CString(), 0, 0, SW_SHOW) > 32;
  193. #else
  194. Vector<String> arguments;
  195. arguments.Push(fileName);
  196. bool success = SystemRun(
  197. #if defined(__APPLE__)
  198. "open",
  199. #else
  200. "xdg-open",
  201. #endif
  202. arguments) == 0;
  203. #endif
  204. if (!success)
  205. LOGERROR("Failed to open " + fileName + " externally");
  206. return success;
  207. }
  208. else
  209. {
  210. LOGERROR("Opening a file externally is not allowed");
  211. return false;
  212. }
  213. }
  214. bool FileSystem::Copy(const String& srcFileName, const String& destFileName)
  215. {
  216. if (!CheckAccess(GetPath(srcFileName)))
  217. {
  218. LOGERROR("Access denied to " + srcFileName);
  219. return false;
  220. }
  221. if (!CheckAccess(GetPath(destFileName)))
  222. {
  223. LOGERROR("Access denied to " + destFileName);
  224. return false;
  225. }
  226. SharedPtr<File> srcFile(new File(context_, srcFileName, FILE_READ));
  227. SharedPtr<File> destFile(new File(context_, destFileName, FILE_WRITE));
  228. if (!srcFile->IsOpen() || !destFile->IsOpen())
  229. return false;
  230. unsigned fileSize = srcFile->GetSize();
  231. SharedArrayPtr<unsigned char> buffer(new unsigned char[fileSize]);
  232. unsigned bytesRead = srcFile->Read(buffer.Get(), fileSize);
  233. unsigned bytesWritten = destFile->Write(buffer.Get(), fileSize);
  234. return bytesRead == fileSize && bytesWritten == fileSize;
  235. }
  236. bool FileSystem::Rename(const String& srcFileName, const String& destFileName)
  237. {
  238. if (!CheckAccess(GetPath(srcFileName)))
  239. {
  240. LOGERROR("Access denied to " + srcFileName);
  241. return false;
  242. }
  243. if (!CheckAccess(GetPath(destFileName)))
  244. {
  245. LOGERROR("Access denied to " + destFileName);
  246. return false;
  247. }
  248. #ifdef WIN32
  249. return MoveFileW(GetWideNativePath(srcFileName).CString(), GetWideNativePath(destFileName).CString()) != 0;
  250. #else
  251. return rename(GetNativePath(srcFileName).CString(), GetNativePath(destFileName).CString()) == 0;
  252. #endif
  253. }
  254. bool FileSystem::Delete(const String& fileName)
  255. {
  256. if (!CheckAccess(GetPath(fileName)))
  257. {
  258. LOGERROR("Access denied to " + fileName);
  259. return false;
  260. }
  261. #ifdef WIN32
  262. return DeleteFileW(GetWideNativePath(fileName).CString()) != 0;
  263. #else
  264. return remove(GetNativePath(fileName).CString()) == 0;
  265. #endif
  266. }
  267. String FileSystem::GetCurrentDir() const
  268. {
  269. #ifdef WIN32
  270. wchar_t path[MAX_PATH];
  271. path[0] = 0;
  272. GetCurrentDirectoryW(MAX_PATH, path);
  273. return AddTrailingSlash(String(path));
  274. #else
  275. char path[MAX_PATH];
  276. path[0] = 0;
  277. getcwd(path, MAX_PATH);
  278. return AddTrailingSlash(String(path));
  279. #endif
  280. }
  281. bool FileSystem::CheckAccess(const String& pathName) const
  282. {
  283. String fixedPath = AddTrailingSlash(pathName);
  284. // If no allowed directories defined, succeed always
  285. if (allowedPaths_.Empty())
  286. return true;
  287. // If there is any attempt to go to a parent directory, disallow
  288. if (fixedPath.Contains(".."))
  289. return false;
  290. // Check if the path is a partial match of any of the allowed directories
  291. for (HashSet<String>::ConstIterator i = allowedPaths_.Begin(); i != allowedPaths_.End(); ++i)
  292. {
  293. if (fixedPath.Find(*i) == 0)
  294. return true;
  295. }
  296. // Not found, so disallow
  297. return false;
  298. }
  299. unsigned FileSystem::GetLastModifiedTime(const String& fileName) const
  300. {
  301. if (fileName.Empty() || !CheckAccess(fileName))
  302. return 0;
  303. #ifdef WIN32
  304. WIN32_FILE_ATTRIBUTE_DATA fileAttrData;
  305. memset(&fileAttrData, 0, sizeof fileAttrData);
  306. if (GetFileAttributesExW(WString(fileName).CString(), GetFileExInfoStandard, &fileAttrData))
  307. {
  308. ULARGE_INTEGER ull;
  309. ull.LowPart = fileAttrData.ftLastWriteTime.dwLowDateTime;
  310. ull.HighPart = fileAttrData.ftLastWriteTime.dwHighDateTime;
  311. return (unsigned)(ull.QuadPart / 10000000ULL - 11644473600ULL);
  312. }
  313. else
  314. return 0;
  315. #else
  316. struct stat st;
  317. if (!stat(fileName.CString(), &st))
  318. return (unsigned)st.st_mtime;
  319. else
  320. return 0;
  321. #endif
  322. }
  323. bool FileSystem::FileExists(const String& fileName) const
  324. {
  325. if (!CheckAccess(GetPath(fileName)))
  326. return false;
  327. String fixedName = GetNativePath(RemoveTrailingSlash(fileName));
  328. #ifdef ANDROID
  329. if (fixedName.StartsWith("/apk/"))
  330. {
  331. SDL_RWops* rwOps = SDL_RWFromFile(fileName.Substring(5).CString(), "rb");
  332. if (rwOps)
  333. {
  334. SDL_RWclose(rwOps);
  335. return true;
  336. }
  337. else
  338. return false;
  339. }
  340. #endif
  341. #ifdef WIN32
  342. DWORD attributes = GetFileAttributesW(WString(fixedName).CString());
  343. if (attributes == INVALID_FILE_ATTRIBUTES || attributes & FILE_ATTRIBUTE_DIRECTORY)
  344. return false;
  345. #else
  346. struct stat st;
  347. if (stat(fixedName.CString(), &st) || st.st_mode & S_IFDIR)
  348. return false;
  349. #endif
  350. return true;
  351. }
  352. bool FileSystem::DirExists(const String& pathName) const
  353. {
  354. if (!CheckAccess(pathName))
  355. return false;
  356. #ifndef WIN32
  357. // Always return true for the root directory
  358. if (pathName == "/")
  359. return true;
  360. #endif
  361. String fixedName = GetNativePath(RemoveTrailingSlash(pathName));
  362. #ifdef ANDROID
  363. /// \todo Actually check for existence, now true is always returned for directories within the APK
  364. if (fixedName.StartsWith("/apk/"))
  365. return true;
  366. #endif
  367. #ifdef WIN32
  368. DWORD attributes = GetFileAttributesW(WString(fixedName).CString());
  369. if (attributes == INVALID_FILE_ATTRIBUTES || !(attributes & FILE_ATTRIBUTE_DIRECTORY))
  370. return false;
  371. #else
  372. struct stat st;
  373. if (stat(fixedName.CString(), &st) || !(st.st_mode & S_IFDIR))
  374. return false;
  375. #endif
  376. return true;
  377. }
  378. void FileSystem::ScanDir(Vector<String>& result, const String& pathName, const String& filter, unsigned flags, bool recursive) const
  379. {
  380. result.Clear();
  381. if (CheckAccess(pathName))
  382. {
  383. String initialPath = AddTrailingSlash(pathName);
  384. ScanDirInternal(result, initialPath, initialPath, filter, flags, recursive);
  385. }
  386. }
  387. String FileSystem::GetProgramDir() const
  388. {
  389. #if defined(ANDROID)
  390. // This is an internal directory specifier pointing to the assets in the .apk
  391. // Files from this directory will be opened using special handling
  392. return "/apk/";
  393. #elif defined(IOS)
  394. return AddTrailingSlash(SDL_IOS_GetResourceDir());
  395. #elif defined(WIN32)
  396. wchar_t exeName[MAX_PATH];
  397. exeName[0] = 0;
  398. GetModuleFileNameW(0, exeName, MAX_PATH);
  399. return GetPath(String(exeName));
  400. #elif defined(__APPLE__)
  401. char exeName[MAX_PATH];
  402. memset(exeName, 0, MAX_PATH);
  403. unsigned size = MAX_PATH;
  404. _NSGetExecutablePath(exeName, &size);
  405. return GetPath(String(exeName));
  406. #elif defined(__linux__)
  407. char exeName[MAX_PATH];
  408. memset(exeName, 0, MAX_PATH);
  409. pid_t pid = getpid();
  410. String link = "/proc/" + String(pid) + "/exe";
  411. readlink(link.CString(), exeName, MAX_PATH);
  412. return GetPath(String(exeName));
  413. #else
  414. return String();
  415. #endif
  416. }
  417. String FileSystem::GetUserDocumentsDir() const
  418. {
  419. #if defined(ANDROID)
  420. return AddTrailingSlash(SDL_Android_GetFilesDir());
  421. #elif defined(IOS)
  422. return AddTrailingSlash(SDL_IOS_GetResourceDir());
  423. #elif defined(WIN32)
  424. wchar_t pathName[MAX_PATH];
  425. pathName[0] = 0;
  426. SHGetSpecialFolderPathW(0, pathName, CSIDL_PERSONAL, 0);
  427. return AddTrailingSlash(String(pathName));
  428. #else
  429. char pathName[MAX_PATH];
  430. pathName[0] = 0;
  431. strcpy(pathName, getenv("HOME"));
  432. return AddTrailingSlash(String(pathName));
  433. #endif
  434. }
  435. void FileSystem::RegisterPath(const String& pathName)
  436. {
  437. if (pathName.Empty())
  438. return;
  439. allowedPaths_.Insert(AddTrailingSlash(pathName));
  440. }
  441. void FileSystem::ScanDirInternal(Vector<String>& result, String path, const String& startPath,
  442. const String& filter, unsigned flags, bool recursive) const
  443. {
  444. path = AddTrailingSlash(path);
  445. String deltaPath;
  446. if (path.Length() > startPath.Length())
  447. deltaPath = path.Substring(startPath.Length());
  448. String filterExtension = filter.Substring(filter.Find('.'));
  449. if (filterExtension.Contains('*'))
  450. filterExtension.Clear();
  451. #ifdef WIN32
  452. WIN32_FIND_DATAW info;
  453. HANDLE handle = FindFirstFileW(WString(path + "*").CString(), &info);
  454. if (handle != INVALID_HANDLE_VALUE)
  455. {
  456. do
  457. {
  458. String fileName(info.cFileName);
  459. if (!fileName.Empty())
  460. {
  461. if (info.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN && !(flags & SCAN_HIDDEN))
  462. continue;
  463. if (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
  464. {
  465. if (flags & SCAN_DIRS)
  466. result.Push(deltaPath + fileName);
  467. if (recursive && fileName != "." && fileName != "..")
  468. ScanDirInternal(result, path + fileName, startPath, filter, flags, recursive);
  469. }
  470. else if (flags & SCAN_FILES)
  471. {
  472. if (filterExtension.Empty() || fileName.EndsWith(filterExtension))
  473. result.Push(deltaPath + fileName);
  474. }
  475. }
  476. }
  477. while (FindNextFileW(handle, &info));
  478. FindClose(handle);
  479. }
  480. #else
  481. DIR *dir;
  482. struct dirent *de;
  483. struct stat st;
  484. dir = opendir(GetNativePath(path).CString());
  485. if (dir)
  486. {
  487. while ((de = readdir(dir)))
  488. {
  489. /// \todo Filename may be unnormalized Unicode on Mac OS X. Re-normalize as necessary
  490. String fileName(de->d_name);
  491. bool normalEntry = fileName != "." && fileName != "..";
  492. if (normalEntry && !(flags & SCAN_HIDDEN) && fileName.StartsWith("."))
  493. continue;
  494. String pathAndName = path + fileName;
  495. if (!stat(pathAndName.CString(), &st))
  496. {
  497. if (st.st_mode & S_IFDIR)
  498. {
  499. if (flags & SCAN_DIRS)
  500. result.Push(deltaPath + fileName);
  501. if (recursive && normalEntry)
  502. ScanDirInternal(result, path + fileName, startPath, filter, flags, recursive);
  503. }
  504. else if (flags & SCAN_FILES)
  505. {
  506. if (filterExtension.Empty() || fileName.EndsWith(filterExtension))
  507. result.Push(deltaPath + fileName);
  508. }
  509. }
  510. }
  511. closedir(dir);
  512. }
  513. #endif
  514. }
  515. void SplitPath(const String& fullPath, String& pathName, String& fileName, String& extension)
  516. {
  517. String fullPathCopy = GetInternalPath(fullPath);
  518. unsigned extPos = fullPathCopy.FindLast('.');
  519. unsigned pathPos = fullPathCopy.FindLast('/');
  520. if (extPos != String::NPOS && (pathPos == String::NPOS || extPos > pathPos))
  521. {
  522. extension = fullPathCopy.Substring(extPos).ToLower();
  523. fullPathCopy = fullPathCopy.Substring(0, extPos);
  524. }
  525. else
  526. extension.Clear();
  527. pathPos = fullPathCopy.FindLast('/');
  528. if (pathPos != String::NPOS)
  529. {
  530. fileName = fullPathCopy.Substring(pathPos + 1);
  531. pathName = fullPathCopy.Substring(0, pathPos + 1);
  532. }
  533. else
  534. {
  535. fileName = fullPathCopy;
  536. pathName.Clear();
  537. }
  538. }
  539. String GetPath(const String& fullPath)
  540. {
  541. String path, file, extension;
  542. SplitPath(fullPath, path, file, extension);
  543. return path;
  544. }
  545. String GetFileName(const String& fullPath)
  546. {
  547. String path, file, extension;
  548. SplitPath(fullPath, path, file, extension);
  549. return file;
  550. }
  551. String GetExtension(const String& fullPath)
  552. {
  553. String path, file, extension;
  554. SplitPath(fullPath, path, file, extension);
  555. return extension;
  556. }
  557. String GetFileNameAndExtension(const String& fileName)
  558. {
  559. String path, file, extension;
  560. SplitPath(fileName, path, file, extension);
  561. return file + extension;
  562. }
  563. String ReplaceExtension(const String& fullPath, const String& newExtension)
  564. {
  565. String path, file, extension;
  566. SplitPath(fullPath, path, file, extension);
  567. return path + file + newExtension;
  568. }
  569. String AddTrailingSlash(const String& pathName)
  570. {
  571. String ret = pathName;
  572. ret.Replace('\\', '/');
  573. if (!ret.Empty() && ret.Back() != '/')
  574. ret += '/';
  575. return ret;
  576. }
  577. String RemoveTrailingSlash(const String& pathName)
  578. {
  579. String ret = pathName;
  580. ret.Replace('\\', '/');
  581. if (!ret.Empty() && ret.Back() == '/')
  582. ret.Resize(ret.Length() - 1);
  583. return ret;
  584. }
  585. String GetParentPath(const String& path)
  586. {
  587. unsigned pos = RemoveTrailingSlash(path).FindLast('/');
  588. if (pos != String::NPOS)
  589. return path.Substring(0, pos + 1);
  590. else
  591. return String();
  592. }
  593. String GetInternalPath(const String& pathName)
  594. {
  595. return pathName.Replaced('\\', '/');
  596. }
  597. String GetNativePath(const String& pathName)
  598. {
  599. #ifdef WIN32
  600. return pathName.Replaced('/', '\\');
  601. #else
  602. return pathName;
  603. #endif
  604. }
  605. WString GetWideNativePath(const String& pathName)
  606. {
  607. #ifdef WIN32
  608. return WString(pathName.Replaced('/', '\\'));
  609. #else
  610. return WString(pathName);
  611. #endif
  612. }
  613. }