• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // ArchiveName.cpp
2 
3 #include "StdAfx.h"
4 
5 #include "../../../Windows/FileDir.h"
6 
7 #include "ExtractingFilePath.h"
8 #include "ArchiveName.h"
9 
10 using namespace NWindows;
11 
CreateArchiveName(const NFile::NFind::CFileInfo fileInfo,bool keepName)12 UString CreateArchiveName(const NFile::NFind::CFileInfo fileInfo, bool keepName)
13 {
14   FString resultName = fileInfo.Name;
15   if (!fileInfo.IsDir() && !keepName)
16   {
17     int dotPos = resultName.ReverseFind(FTEXT('.'));
18     if (dotPos > 0)
19     {
20       FString archiveName2 = resultName.Left(dotPos);
21       if (archiveName2.ReverseFind(FTEXT('.')) < 0)
22         resultName = archiveName2;
23     }
24   }
25   return GetCorrectFsPath(fs2us(resultName));
26 }
27 
CreateArchiveName2(const FString & srcName,bool fromPrev,bool keepName)28 static FString CreateArchiveName2(const FString &srcName, bool fromPrev, bool keepName)
29 {
30   FString resultName = FTEXT("Archive");
31   if (fromPrev)
32   {
33     FString dirPrefix;
34     if (NFile::NDir::GetOnlyDirPrefix(srcName, dirPrefix))
35     {
36       if (dirPrefix.Len() > 0)
37         if (dirPrefix.Back() == FCHAR_PATH_SEPARATOR)
38         {
39           dirPrefix.DeleteBack();
40           NFile::NFind::CFileInfo fileInfo;
41           if (fileInfo.Find(dirPrefix))
42             resultName = fileInfo.Name;
43         }
44     }
45   }
46   else
47   {
48     NFile::NFind::CFileInfo fileInfo;
49     if (!fileInfo.Find(srcName))
50       // return resultName;
51       return srcName;
52     resultName = fileInfo.Name;
53     if (!fileInfo.IsDir() && !keepName)
54     {
55       int dotPos = resultName.ReverseFind('.');
56       if (dotPos > 0)
57       {
58         FString archiveName2 = resultName.Left(dotPos);
59         if (archiveName2.ReverseFind(FTEXT('.')) < 0)
60           resultName = archiveName2;
61       }
62     }
63   }
64   return resultName;
65 }
66 
CreateArchiveName(const UString & srcName,bool fromPrev,bool keepName)67 UString CreateArchiveName(const UString &srcName, bool fromPrev, bool keepName)
68 {
69   return GetCorrectFsPath(fs2us(CreateArchiveName2(us2fs(srcName), fromPrev, keepName)));
70 }
71