Class ArchiveNaming
- Namespace
- Archiver.Core.Services
- Assembly
- Archiver.Core.dll
Derives a base name (for a destination folder, or an auto-named archive) from an archive's file name. Path.GetFileNameWithoutExtension only strips the last extension, which is wrong for the compound extensions tar.exe itself produces (T-F103: "archive.tar.gz" must strip to "archive", not "archive.tar"). Kept in sync with ShellExtUtils.cpp's native equivalent.
public static class ArchiveNaming
- Inheritance
-
ArchiveNaming
- Inherited Members
Methods
GetBaseName(string)
Strips an archive's extension, compound tar extensions included (see class remarks).
public static string GetBaseName(string archivePath)
Parameters
archivePathstring
Returns
GetDefaultArchiveName(IReadOnlyList<string>)
T-F264: the one default name for a new archive, used by the App (blank name box), Explorer's "Add to" commands and — mirrored in ShellExtUtils.cpp's BuildAddToArchiveTitle — the menu title. One source: its name without extension (compound tar extensions stripped as a unit, a dotfile keeps its full name). Several sources: the folder that holds the first one. A drive root is named after its letter ("C", T-F281). Falls back to "archive" where that gives no usable name (no sources, a name of only an extension).
public static string GetDefaultArchiveName(IReadOnlyList<string> sourcePaths)
Parameters
sourcePathsIReadOnlyList<string>
Returns
GetExtension(ArchiveContainerFormat)
Maps a creation-time container format to its on-disk file extension.
public static string GetExtension(ArchiveContainerFormat format)
Parameters
formatArchiveContainerFormat
Returns
GetUniqueFolderName(string, string)
T-F264: a folder under parentDir that does not exist yet — "name", else
"name (1)", ... with the number after the whole name (a folder has no extension).
public static string GetUniqueFolderName(string parentDir, string name)
Parameters
Returns
GetUniqueName(string, Func<string, bool>)
T-F264: the "name (1)", "name (2)", ... rule every rename-on-conflict path uses — the number
goes before the extension. isTaken decides what counts as taken (a file
on disk, a name already claimed in memory). A compound tar extension counts as one (T-F362:
"src (1).tar.gz", not "src.tar (1).gz").
public static string GetUniqueName(string fileName, Func<string, bool> isTaken)
Parameters
Returns
ResolveSingleArchiveName(string?, IReadOnlyList<string>)
T-F99: shared by ZipArchiveService.ArchiveAsync and TarSandboxedService.CompressAsync — an explicit user-provided name always wins; otherwise GetDefaultArchiveName(IReadOnlyList<string>) (T-F264).
public static string ResolveSingleArchiveName(string? explicitName, IReadOnlyList<string> sourcePaths)
Parameters
explicitNamestringsourcePathsIReadOnlyList<string>
Returns
Remarks
T-F185: an explicit name is a bare file-name component, never a path — both callers combine the return value directly with a separate DestinationFolder via Path.Combine, which does not sanitize ".." segments. Path.GetFileName strips any directory component (including a leading "....") down to the final segment, closing a real path-traversal write confirmed via CompressAsync_DestinationNameWithParentTraversalSegments_NeverWritesOutsideIntendedTree (a "....\evil" ArchiveName landed the created archive outside DestinationFolder entirely before this fix). Falls back to "archive" if that strips the name down to nothing (e.g. an explicit name of just ".." or "").
SingleArchiveFileName(ArchiveOptions)
The file name of a single archive: ExactFileName as given, else the resolved base name plus the format's extension.
public static string SingleArchiveFileName(ArchiveOptions options)
Parameters
optionsArchiveOptions