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