Skip to content

Commit

Permalink
Added support for wildcard for KeepFiles in a script Package.ini
Browse files Browse the repository at this point in the history
  • Loading branch information
maforget committed Jun 2, 2024
1 parent f7226df commit 2ff74b6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
26 changes: 18 additions & 8 deletions ComicRack.Engine/PackageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using cYo.Common.Collections;
using cYo.Common.Drawing;
using cYo.Common.IO;
Expand Down Expand Up @@ -404,17 +405,26 @@ private bool CommitInstallPackage(Package package)
Directory.CreateDirectory(text);
if (!package.KeepFiles.IsEmpty())
{
string[] keep = package.KeepFiles;
foreach (string item in from f in Directory.GetFiles(text)
where !keep.Contains(Path.GetFileName(f), StringComparer.OrdinalIgnoreCase)
select f)
string[] keep = package.KeepFiles;

// Convert wildcard patterns to regular expressions
List<Regex> keepPatterns = keep.Select(pattern =>
{
string regexPattern = $"^{Regex.Escape(pattern).Replace("\\*", ".*").Replace("\\?", ".")}$";
return new Regex(regexPattern, RegexOptions.IgnoreCase);
}).ToList();

foreach (string item in from f in Directory.EnumerateFiles(text)
where !keepPatterns.Any(regex => regex.IsMatch(f))
select f)
{
FileUtility.SafeDelete(item);
}
foreach (string item2 in from f in Directory.GetDirectories(text)
where !keep.Contains(Path.GetFileName(f), StringComparer.OrdinalIgnoreCase)
select f)
{

foreach (string item2 in from f in Directory.EnumerateDirectories(text)
where !keepPatterns.Any(regex => regex.IsMatch(f))
select f)
{
FileUtility.SafeDirectoryDelete(item2);
}
}
Expand Down
1 change: 1 addition & 0 deletions ComicRack/Changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Community Edition Build 0.9.180:
* NEW: "__MACOSX" & ".DS_Store" folders will be ignored inside archives.
* NEW: Images smaller than 512 bytes will be ignored inside archives.
* NEW: Added a "Published (Regional)" column that will use the OS regional setting for the Published date (like the other dates).
* NEW: Added support for wildcard for "KeepFiles" in a script "Package.ini" (used for Data Manager multiple profiles).

* CHANGE: Updated to .NET Framework v4.8.
* CHANGE: Updated the Splash Screen and Renamed the Program to Community Edition, this means that a new config folder will be used %appdata%\cYo\ComicRack Community Edition.
Expand Down

0 comments on commit 2ff74b6

Please sign in to comment.