WorkDir.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // WorkDir.cpp
  2. #include "StdAfx.h"
  3. #include "WorkDir.h"
  4. #include "Common/StringConvert.h"
  5. #include "Common/Wildcard.h"
  6. #include "Windows/FileName.h"
  7. #include "Windows/FileDir.h"
  8. static inline UINT GetCurrentCodePage()
  9. { return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; }
  10. using namespace NWindows;
  11. using namespace NFile;
  12. using namespace NName;
  13. UString GetWorkDir(const NWorkDir::CInfo &workDirInfo, const UString &path)
  14. {
  15. NWorkDir::NMode::EEnum mode = workDirInfo.Mode;
  16. if (workDirInfo.ForRemovableOnly)
  17. {
  18. mode = NWorkDir::NMode::kCurrent;
  19. UString prefix = path.Left(3);
  20. if (prefix[1] == L':' && prefix[2] == L'\\')
  21. {
  22. UINT driveType = GetDriveType(GetSystemString(prefix, GetCurrentCodePage()));
  23. if (driveType == DRIVE_CDROM || driveType == DRIVE_REMOVABLE)
  24. mode = workDirInfo.Mode;
  25. }
  26. /*
  27. CParsedPath parsedPath;
  28. parsedPath.ParsePath(archiveName);
  29. UINT driveType = GetDriveType(parsedPath.Prefix);
  30. if ((driveType != DRIVE_CDROM) && (driveType != DRIVE_REMOVABLE))
  31. mode = NZipSettings::NWorkDir::NMode::kCurrent;
  32. */
  33. }
  34. switch(mode)
  35. {
  36. case NWorkDir::NMode::kCurrent:
  37. {
  38. return ExtractDirPrefixFromPath(path);
  39. }
  40. case NWorkDir::NMode::kSpecified:
  41. {
  42. UString tempDir = workDirInfo.Path;
  43. NormalizeDirPathPrefix(tempDir);
  44. return tempDir;
  45. }
  46. default:
  47. {
  48. UString tempDir;
  49. if(!NFile::NDirectory::MyGetTempPath(tempDir))
  50. throw 141717;
  51. return tempDir;
  52. }
  53. }
  54. }