1 // ArchiveName.cpp
2
3 #include "StdAfx.h"
4
5 #include "../../../Windows/FileDir.h"
6 #include "../../../Windows/FileName.h"
7
8 #include "ExtractingFilePath.h"
9 #include "ArchiveName.h"
10
11 using namespace NWindows;
12 using namespace NFile;
13
CreateArchiveName(const NFind::CFileInfo & fi,bool keepName)14 UString CreateArchiveName(const NFind::CFileInfo &fi, bool keepName)
15 {
16 FString resultName = fi.Name;
17 if (!fi.IsDir() && !keepName)
18 {
19 int dotPos = resultName.ReverseFind_Dot();
20 if (dotPos > 0)
21 {
22 FString archiveName2 = resultName.Left(dotPos);
23 if (archiveName2.ReverseFind_Dot() < 0)
24 resultName = archiveName2;
25 }
26 }
27 return Get_Correct_FsFile_Name(fs2us(resultName));
28 }
29
CreateArchiveName2(const FString & path,bool fromPrev,bool keepName)30 static FString CreateArchiveName2(const FString &path, bool fromPrev, bool keepName)
31 {
32 FString resultName ("Archive");
33 if (fromPrev)
34 {
35 FString dirPrefix;
36 if (NDir::GetOnlyDirPrefix(path, dirPrefix))
37 {
38 if (!dirPrefix.IsEmpty() && IsPathSepar(dirPrefix.Back()))
39 {
40 #if defined(_WIN32) && !defined(UNDER_CE)
41 if (NName::IsDriveRootPath_SuperAllowed(dirPrefix))
42 resultName = dirPrefix[dirPrefix.Len() - 3]; // only letter
43 else
44 #endif
45 {
46 dirPrefix.DeleteBack();
47 NFind::CFileInfo fi;
48 if (fi.Find(dirPrefix))
49 resultName = fi.Name;
50 }
51 }
52 }
53 }
54 else
55 {
56 NFind::CFileInfo fi;
57 if (fi.Find(path))
58 {
59 resultName = fi.Name;
60 if (!fi.IsDir() && !keepName)
61 {
62 int dotPos = resultName.ReverseFind_Dot();
63 if (dotPos > 0)
64 {
65 FString name2 = resultName.Left(dotPos);
66 if (name2.ReverseFind_Dot() < 0)
67 resultName = name2;
68 }
69 }
70 }
71 }
72 return resultName;
73 }
74
CreateArchiveName(const UString & path,bool fromPrev,bool keepName)75 UString CreateArchiveName(const UString &path, bool fromPrev, bool keepName)
76 {
77 return Get_Correct_FsFile_Name(fs2us(CreateArchiveName2(us2fs(path), fromPrev, keepName)));
78 }
79