Home | History | Annotate | Download | only in Common
      1 // ArchiveName.cpp
      2 
      3 #include "StdAfx.h"
      4 
      5 #include "Windows/FileDir.h"
      6 #include "Windows/FileFind.h"
      7 
      8 #include "ExtractingFilePath.h"
      9 
     10 using namespace NWindows;
     11 
     12 static UString CreateArchiveName2(const UString &srcName, bool fromPrev, bool keepName)
     13 {
     14   UString resultName = L"Archive";
     15   if (fromPrev)
     16   {
     17     UString dirPrefix;
     18     if (NFile::NDirectory::GetOnlyDirPrefix(srcName, dirPrefix))
     19     {
     20       if (dirPrefix.Length() > 0)
     21         if (dirPrefix[dirPrefix.Length() - 1] == WCHAR_PATH_SEPARATOR)
     22         {
     23           dirPrefix.Delete(dirPrefix.Length() - 1);
     24           NFile::NFind::CFileInfoW fileInfo;
     25           if (fileInfo.Find(dirPrefix))
     26             resultName = fileInfo.Name;
     27         }
     28     }
     29   }
     30   else
     31   {
     32     NFile::NFind::CFileInfoW fileInfo;
     33     if (!fileInfo.Find(srcName))
     34       // return resultName;
     35       return srcName;
     36     resultName = fileInfo.Name;
     37     if (!fileInfo.IsDir() && !keepName)
     38     {
     39       int dotPos = resultName.ReverseFind('.');
     40       if (dotPos > 0)
     41       {
     42         UString archiveName2 = resultName.Left(dotPos);
     43         if (archiveName2.ReverseFind('.') < 0)
     44           resultName = archiveName2;
     45       }
     46     }
     47   }
     48   return resultName;
     49 }
     50 
     51 UString CreateArchiveName(const UString &srcName, bool fromPrev, bool keepName)
     52 {
     53   return GetCorrectFsPath(CreateArchiveName2(srcName, fromPrev, keepName));
     54 }
     55