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