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