Skip to content

Commit

Permalink
Fix: Fixed an issue where empty folders could not be compressed (file…
Browse files Browse the repository at this point in the history
  • Loading branch information
hishitetsu authored Jun 4, 2024
1 parent 212856e commit 2ad172c
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/Files.App/Data/Models/CompressArchiveModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,35 @@ public async Task<bool> RunCreationAsync()

foreach (string directory in directories)
{
await compressor.CompressDirectoryAsync(directory, ArchivePath, Password);
try
{
await compressor.CompressDirectoryAsync(directory, ArchivePath, Password);
}
catch (SevenZipInvalidFileNamesException)
{
// The directory has no files, so we need to create entries manually
var fileDictionary = new Dictionary<string, string>();
AddEntry(fileDictionary, directory, "");

compressor.CompressFileDictionary(fileDictionary, ArchivePath, Password);

static void AddEntry(IDictionary<string, string> fileDictionary, string directory, string entryPrefix)
{
DirectoryInfo directoryInfo = new DirectoryInfo(directory);

DirectoryInfo[] directories = directoryInfo.GetDirectories();
if (directories.Length == 0)
{
fileDictionary.Add(entryPrefix + directoryInfo.Name, null);
}
else
{
entryPrefix += directoryInfo.Name + Path.DirectorySeparatorChar;
foreach (DirectoryInfo directoryInfo2 in directories)
AddEntry(fileDictionary, directoryInfo2.FullName, entryPrefix);
}
}
}

compressor.CompressionMode = CompressionMode.Append;
}
Expand Down

0 comments on commit 2ad172c

Please sign in to comment.