diff --git a/src/ArchiveManager.cs b/src/ArchiveManager.cs index 19a56b7..2cd62fc 100644 --- a/src/ArchiveManager.cs +++ b/src/ArchiveManager.cs @@ -2,21 +2,52 @@ using System; using System.IO; -namespace DistroGrubThemes -{ - public static class ArchiveManager - { - public static void CreateTarArchive(string outputFile, bool verbose) - { - Stream outStream = File.Create(outputFile); - TarArchive.CreateOutputTarArchive(outStream); +namespace DistroGrubThemes; - if (verbose) - { - Console.ForegroundColor = ConsoleColor.Green; - Console.Write("OK\n"); - Console.ResetColor(); - } +public static class ArchiveManager +{ + public static void CreateTarArchive(string sourceDirectory, string outputFile, bool verbose) + { + Stream outStream = File.Create(outputFile); + TarArchive tarArchive = TarArchive.CreateOutputTarArchive(outStream); + + // Case sensitive + tarArchive.RootPath = sourceDirectory.Replace('\\', '/'); + if (tarArchive.RootPath.EndsWith("/")) + tarArchive.RootPath = tarArchive.RootPath.Remove(tarArchive.RootPath.Length - 1); + + AddDirectoryFilesToTar(tarArchive, sourceDirectory, true); + tarArchive.Close(); + + if (verbose) + { + Console.ForegroundColor = ConsoleColor.Green; + Console.Write("OK\n"); + Console.ResetColor(); + } + } + + // Example: https://github.com/icsharpcode/SharpZipLib/wiki/GZip-and-Tar-Samples + private static void AddDirectoryFilesToTar(TarArchive tarArchive, string sourceDirectory, bool recurse) + { + // Optionally, write an entry for the directory itself. + // Specify false for recursion here if we will add the directory's files individually. + TarEntry tarEntry = TarEntry.CreateEntryFromFile(sourceDirectory); + tarArchive.WriteEntry(tarEntry, false); + + // Write each file to the tar. + string[] filenames = Directory.GetFiles(sourceDirectory); + foreach (string filename in filenames) + { + tarEntry = TarEntry.CreateEntryFromFile(filename); + tarArchive.WriteEntry(tarEntry, true); + } + + if (recurse) + { + string[] directories = Directory.GetDirectories(sourceDirectory); + foreach (string directory in directories) + AddDirectoryFilesToTar(tarArchive, directory, recurse); } } } diff --git a/src/DistroGrubThemes.csproj b/src/DistroGrubThemes.csproj index b132f8d..74a441a 100644 --- a/src/DistroGrubThemes.csproj +++ b/src/DistroGrubThemes.csproj @@ -5,6 +5,7 @@ netcoreapp3.1 Adison Cavani Adison Cavani + 10 diff --git a/src/Program.cs b/src/Program.cs index 23dcca8..e16fc07 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -4,159 +4,158 @@ using System.Collections.Generic; using System.IO; using System.Linq; -namespace DistroGrubThemes +namespace DistroGrubThemes; + +internal class Program { - internal class Program + static void Main(string[] args) { - static void Main(string[] args) + var parser = new Parser(with => with.HelpWriter = null); + var parserResult = parser.ParseArguments(args); + parserResult.WithParsed(options => RunOptions(options)).WithNotParsed(errs => Help.DisplayHelp(parserResult, errs)); + } + + static void RunOptions(ProgramOptions opts) + { + Program program = new(); + string path = program.CheckRepoPath(opts.RepositoryPath); + + if (opts.UpdateFonts) + program.UpdateFonts($"{path}\\font", $"{path}\\customize", opts.VerboseMode); + + if (opts.UpdateIcons) { - var parser = new Parser(with => with.HelpWriter = null); - var parserResult = parser.ParseArguments(args); - parserResult.WithParsed(options => RunOptions(options)).WithNotParsed(errs => Help.DisplayHelp(parserResult, errs)); + if (opts.VerboseMode) + Console.WriteLine(); + + program.UpdateIcons($"{path}\\assets\\icons", $"{path}\\customize", opts.VerboseMode); } - static void RunOptions(ProgramOptions opts) + if (opts.UpdateArchives) { - Program program = new Program(); - string path = program.CheckRepoPath(opts.RepositoryPath); + if (opts.VerboseMode) + Console.WriteLine(); - if (opts.UpdateFonts) - program.UpdateFonts($"{path}\\font", $"{path}\\customize", opts.VerboseMode); + program.UpdateArchive(path, opts.VerboseMode); + } + } - if (opts.UpdateIcons) - { - if (opts.VerboseMode) - Console.WriteLine(); + void UpdateArchive(string path, bool verbose) + { + if (!verbose) + Console.Write("Creating .tar archives ... "); - program.UpdateIcons($"{path}\\assets\\icons", $"{path}\\customize", opts.VerboseMode); - } + foreach (var directory in DirectoriesDictionary($"{path}\\customize", path)) + { + if (verbose) + Console.Write($"Creating {directory.Value}.tar archive ... "); - if (opts.UpdateArchives) - { - if (opts.VerboseMode) - Console.WriteLine(); - - program.UpdateArchive(path, opts.VerboseMode); - } + ArchiveManager.CreateTarArchive(directory.Key, $"{path}\\themes\\{directory.Value}.tar", verbose); } - void UpdateArchive(string path, bool verbose) + if (!verbose) { - if (!verbose) - Console.Write("Creating .tar archives ... "); + Console.ForegroundColor = ConsoleColor.Green; + Console.Write("OK\n"); + Console.ResetColor(); + } + } - foreach (var directory in DirectoriesDictionary($"{path}\\customize", path)) + void UpdateIcons(string iconsPath, string customizePath, bool verbose) + { + if (!verbose) + Console.Write("Copying icons ... "); + + foreach (var directory in DirectoriesArray(customizePath)) + { + foreach (var icon in FilesArray(iconsPath)) { if (verbose) - Console.Write($"Creating {directory.Value}.tar archive ... "); + Console.Write($"Copying {icon} ... "); - ArchiveManager.CreateTarArchive($"{path}\\themes\\{directory.Value}.tar", verbose); - } + File.Copy($"{iconsPath}\\{icon}", $"{directory}\\icons\\{icon}", true); - if (!verbose) - { - Console.ForegroundColor = ConsoleColor.Green; - Console.Write("OK\n"); - Console.ResetColor(); - } - } - - void UpdateIcons(string iconsPath, string customizePath, bool verbose) - { - if (!verbose) - Console.Write("Copying icons ... "); - - foreach (var directory in DirectoriesArray(customizePath)) - { - foreach (var icon in FilesArray(iconsPath)) + if (verbose) { - if (verbose) - Console.Write($"Copying {icon} ... "); - - File.Copy($"{iconsPath}\\{icon}", $"{directory}\\icons\\{icon}", true); - - if (verbose) - { - Console.ForegroundColor = ConsoleColor.Green; - Console.Write("OK\n"); - Console.ResetColor(); - } + Console.ForegroundColor = ConsoleColor.Green; + Console.Write("OK\n"); + Console.ResetColor(); } } - - if (!verbose) - { - Console.ForegroundColor = ConsoleColor.Green; - Console.Write("OK\n"); - Console.ResetColor(); - } } - void UpdateFonts(string fontsPath, string customizePath, bool verbose) + if (!verbose) { - if (!verbose) - Console.Write("Copying fonts ... "); + Console.ForegroundColor = ConsoleColor.Green; + Console.Write("OK\n"); + Console.ResetColor(); + } + } - foreach (var directory in DirectoriesArray(customizePath)) + void UpdateFonts(string fontsPath, string customizePath, bool verbose) + { + if (!verbose) + Console.Write("Copying fonts ... "); + + foreach (var directory in DirectoriesArray(customizePath)) + { + foreach (var font in FilesArray(fontsPath)) { - foreach (var font in FilesArray(fontsPath)) + if (verbose) + Console.Write($"Copying {font} ... "); + + File.Copy($"{fontsPath}\\{font}", $"{directory}\\{font}", true); + + if (verbose) { - if (verbose) - Console.Write($"Copying {font} ... "); - - File.Copy($"{fontsPath}\\{font}", $"{directory}\\{font}", true); - - if (verbose) - { - Console.ForegroundColor = ConsoleColor.Green; - Console.Write("OK\n"); - Console.ResetColor(); - } + Console.ForegroundColor = ConsoleColor.Green; + Console.Write("OK\n"); + Console.ResetColor(); } } - - if (!verbose) - { - Console.ForegroundColor = ConsoleColor.Green; - Console.Write("OK\n"); - Console.ResetColor(); - } } - List FilesArray(string folderPath) + if (!verbose) { - return new List(Directory.GetFiles(folderPath).Select(Path.GetFileName)); + Console.ForegroundColor = ConsoleColor.Green; + Console.Write("OK\n"); + Console.ResetColor(); + } + } + + List FilesArray(string folderPath) + { + return new List(Directory.GetFiles(folderPath).Select(Path.GetFileName)); + } + + string[] DirectoriesArray(string directoryPath) + { + return Directory.GetDirectories(directoryPath); + } + + Dictionary DirectoriesDictionary(string directoryPath, string repoPath) + { + var dirsArray = Directory.GetDirectories(directoryPath); + + return dirsArray.ToDictionary(key => key, value => value[(value.IndexOf(@"customize\") + 10)..]); + } + + string CheckRepoPath(string path) + { + if (Directory.Exists(path) && path.Contains("distro-grub-themes")) + { + int index = path.IndexOf("distro-grub-themes") + 18; + return path[..index]; } - string[] DirectoriesArray(string directoryPath) + else { - return Directory.GetDirectories(directoryPath); - } - - Dictionary DirectoriesDictionary(string directoryPath, string repoPath) - { - var dirsArray = Directory.GetDirectories(directoryPath); - - return dirsArray.ToDictionary(key => key, value => value[(value.IndexOf(@"customize\") + 10)..]); - } - - string CheckRepoPath(string path) - { - if (Directory.Exists(path) && path.Contains("distro-grub-themes")) - { - int index = path.IndexOf("distro-grub-themes") + 18; - return path[..index]; - } - - else - { - Console.ForegroundColor = ConsoleColor.Red; - Console.Write("error: "); - Console.ResetColor(); - Console.Write("could not find repository in this path"); - Environment.Exit(1); - return null; - } + Console.ForegroundColor = ConsoleColor.Red; + Console.Write("error: "); + Console.ResetColor(); + Console.Write("could not find repository in this path"); + Environment.Exit(1); + return null; } } } diff --git a/themes/CentOS.tar b/themes/CentOS.tar index e69de29..3e8e861 100644 Binary files a/themes/CentOS.tar and b/themes/CentOS.tar differ diff --git a/themes/Debian.tar b/themes/Debian.tar index e69de29..c616438 100644 Binary files a/themes/Debian.tar and b/themes/Debian.tar differ diff --git a/themes/Deepin.tar b/themes/Deepin.tar index e69de29..37671ab 100644 Binary files a/themes/Deepin.tar and b/themes/Deepin.tar differ diff --git a/themes/EndeavourOS.tar b/themes/EndeavourOS.tar index e69de29..6645cde 100644 Binary files a/themes/EndeavourOS.tar and b/themes/EndeavourOS.tar differ diff --git a/themes/Fedora.tar b/themes/Fedora.tar index e69de29..fcbebbf 100644 Binary files a/themes/Fedora.tar and b/themes/Fedora.tar differ diff --git a/themes/FreeBSD.tar b/themes/FreeBSD.tar index e69de29..4a23ddf 100644 Binary files a/themes/FreeBSD.tar and b/themes/FreeBSD.tar differ diff --git a/themes/Garuda.tar b/themes/Garuda.tar index e69de29..e797484 100644 Binary files a/themes/Garuda.tar and b/themes/Garuda.tar differ diff --git a/themes/Gentoo.tar b/themes/Gentoo.tar index e69de29..7fb178c 100644 Binary files a/themes/Gentoo.tar and b/themes/Gentoo.tar differ diff --git a/themes/KDEneon.tar b/themes/KDEneon.tar index e69de29..192218c 100644 Binary files a/themes/KDEneon.tar and b/themes/KDEneon.tar differ diff --git a/themes/Manjaro.tar b/themes/Manjaro.tar index e69de29..b0054ba 100644 Binary files a/themes/Manjaro.tar and b/themes/Manjaro.tar differ diff --git a/themes/Solus.tar b/themes/Solus.tar index e69de29..928d765 100644 Binary files a/themes/Solus.tar and b/themes/Solus.tar differ diff --git a/themes/Ubuntu.tar b/themes/Ubuntu.tar index e69de29..7621d66 100644 Binary files a/themes/Ubuntu.tar and b/themes/Ubuntu.tar differ diff --git a/themes/Ventoy.tar b/themes/Ventoy.tar index e69de29..c16d781 100644 Binary files a/themes/Ventoy.tar and b/themes/Ventoy.tar differ diff --git a/themes/Windows10.tar b/themes/Windows10.tar index e69de29..ad4291d 100644 Binary files a/themes/Windows10.tar and b/themes/Windows10.tar differ diff --git a/themes/ZorinOS.tar b/themes/ZorinOS.tar index e69de29..76f157b 100644 Binary files a/themes/ZorinOS.tar and b/themes/ZorinOS.tar differ diff --git a/themes/aorus.tar b/themes/aorus.tar index e69de29..fe3cb12 100644 Binary files a/themes/aorus.tar and b/themes/aorus.tar differ diff --git a/themes/arch.tar b/themes/arch.tar index e69de29..278b705 100644 Binary files a/themes/arch.tar and b/themes/arch.tar differ diff --git a/themes/arco.tar b/themes/arco.tar index e69de29..6f6cb37 100644 Binary files a/themes/arco.tar and b/themes/arco.tar differ diff --git a/themes/artix.tar b/themes/artix.tar index e69de29..2c34b3c 100644 Binary files a/themes/artix.tar and b/themes/artix.tar differ diff --git a/themes/asus.tar b/themes/asus.tar index e69de29..f4c0a27 100644 Binary files a/themes/asus.tar and b/themes/asus.tar differ diff --git a/themes/elementary.tar b/themes/elementary.tar index e69de29..0409d25 100644 Binary files a/themes/elementary.tar and b/themes/elementary.tar differ diff --git a/themes/gigabyte-with-hue.tar b/themes/gigabyte-with-hue.tar index e69de29..de55e23 100644 Binary files a/themes/gigabyte-with-hue.tar and b/themes/gigabyte-with-hue.tar differ diff --git a/themes/gigabyte.tar b/themes/gigabyte.tar index e69de29..9a93e29 100644 Binary files a/themes/gigabyte.tar and b/themes/gigabyte.tar differ diff --git a/themes/hp.tar b/themes/hp.tar index e69de29..39df7cf 100644 Binary files a/themes/hp.tar and b/themes/hp.tar differ diff --git a/themes/lenovo.tar b/themes/lenovo.tar index e69de29..3ebc16d 100644 Binary files a/themes/lenovo.tar and b/themes/lenovo.tar differ diff --git a/themes/mate.tar b/themes/mate.tar index e69de29..9e0db99 100644 Binary files a/themes/mate.tar and b/themes/mate.tar differ diff --git a/themes/mint.tar b/themes/mint.tar index e69de29..085de96 100644 Binary files a/themes/mint.tar and b/themes/mint.tar differ diff --git a/themes/mx.tar b/themes/mx.tar index e69de29..9907791 100644 Binary files a/themes/mx.tar and b/themes/mx.tar differ diff --git a/themes/openSUSE.tar b/themes/openSUSE.tar index e69de29..cd2be74 100644 Binary files a/themes/openSUSE.tar and b/themes/openSUSE.tar differ diff --git a/themes/pop.tar b/themes/pop.tar index e69de29..1f02e39 100644 Binary files a/themes/pop.tar and b/themes/pop.tar differ diff --git a/themes/rocky.tar b/themes/rocky.tar index e69de29..3987c34 100644 Binary files a/themes/rocky.tar and b/themes/rocky.tar differ diff --git a/themes/toshiba.tar b/themes/toshiba.tar index e69de29..d9c4928 100644 Binary files a/themes/toshiba.tar and b/themes/toshiba.tar differ diff --git a/themes/void.tar b/themes/void.tar index e69de29..3cc7e19 100644 Binary files a/themes/void.tar and b/themes/void.tar differ