From 8fecea3e02ebf4df974a699e6b7cdd2d517ebb5b Mon Sep 17 00:00:00 2001 From: Adison Cavani Date: Wed, 16 Mar 2022 22:33:28 +0100 Subject: [PATCH] Move old C# program to legacy branch --- src/ArchiveManager.cs | 53 ------------ src/DistroGrubThemes.csproj | 16 ---- src/DistroGrubThemes.sln | 25 ------ src/Help.cs | 28 ------- src/Program.cs | 161 ------------------------------------ src/ProgramOptions.cs | 22 ----- src/README.md | 5 -- 7 files changed, 310 deletions(-) delete mode 100644 src/ArchiveManager.cs delete mode 100644 src/DistroGrubThemes.csproj delete mode 100644 src/DistroGrubThemes.sln delete mode 100644 src/Help.cs delete mode 100644 src/Program.cs delete mode 100644 src/ProgramOptions.cs delete mode 100644 src/README.md diff --git a/src/ArchiveManager.cs b/src/ArchiveManager.cs deleted file mode 100644 index 2cd62fc..0000000 --- a/src/ArchiveManager.cs +++ /dev/null @@ -1,53 +0,0 @@ -using ICSharpCode.SharpZipLib.Tar; -using System; -using System.IO; - -namespace DistroGrubThemes; - -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 deleted file mode 100644 index 74a441a..0000000 --- a/src/DistroGrubThemes.csproj +++ /dev/null @@ -1,16 +0,0 @@ - - - - Exe - netcoreapp3.1 - Adison Cavani - Adison Cavani - 10 - - - - - - - - diff --git a/src/DistroGrubThemes.sln b/src/DistroGrubThemes.sln deleted file mode 100644 index ea76239..0000000 --- a/src/DistroGrubThemes.sln +++ /dev/null @@ -1,25 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.0.31717.71 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DistroGrubThemes", "DistroGrubThemes.csproj", "{0CCFA519-E529-4AF9-B800-92FC96351EE9}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {0CCFA519-E529-4AF9-B800-92FC96351EE9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0CCFA519-E529-4AF9-B800-92FC96351EE9}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0CCFA519-E529-4AF9-B800-92FC96351EE9}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0CCFA519-E529-4AF9-B800-92FC96351EE9}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {C18C7214-AE56-46A5-8C62-8A5A2B8886D7} - EndGlobalSection -EndGlobal diff --git a/src/Help.cs b/src/Help.cs deleted file mode 100644 index ca06887..0000000 --- a/src/Help.cs +++ /dev/null @@ -1,28 +0,0 @@ -using CommandLine; -using CommandLine.Text; -using System; -using System.Collections.Generic; - -namespace DistroGrubThemes -{ - public class Help - { - public static void DisplayHelp(ParserResult result, IEnumerable errs) - { - HelpText helpText = null; - if (errs.IsVersion()) - helpText = HelpText.AutoBuild(result); - else - { - helpText = HelpText.AutoBuild(result, h => - { - h.AdditionalNewLineAfterOption = false; - h.Heading = string.Empty; - h.Copyright = string.Empty; - return HelpText.DefaultParsingErrorsHandler(result, h); - }, e => e); - } - Console.WriteLine(helpText); - } - } -} diff --git a/src/Program.cs b/src/Program.cs deleted file mode 100644 index e16fc07..0000000 --- a/src/Program.cs +++ /dev/null @@ -1,161 +0,0 @@ -using CommandLine; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; - -namespace DistroGrubThemes; - -internal class Program -{ - 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) - { - if (opts.VerboseMode) - Console.WriteLine(); - - program.UpdateIcons($"{path}\\assets\\icons", $"{path}\\customize", opts.VerboseMode); - } - - if (opts.UpdateArchives) - { - if (opts.VerboseMode) - Console.WriteLine(); - - program.UpdateArchive(path, opts.VerboseMode); - } - } - - void UpdateArchive(string path, bool verbose) - { - if (!verbose) - Console.Write("Creating .tar archives ... "); - - foreach (var directory in DirectoriesDictionary($"{path}\\customize", path)) - { - if (verbose) - Console.Write($"Creating {directory.Value}.tar archive ... "); - - ArchiveManager.CreateTarArchive(directory.Key, $"{path}\\themes\\{directory.Value}.tar", verbose); - } - - 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) - Console.Write($"Copying {icon} ... "); - - File.Copy($"{iconsPath}\\{icon}", $"{directory}\\icons\\{icon}", true); - - if (verbose) - { - 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) - Console.Write("Copying fonts ... "); - - foreach (var directory in DirectoriesArray(customizePath)) - { - foreach (var font in FilesArray(fontsPath)) - { - 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(); - } - } - } - - if (!verbose) - { - 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]; - } - - else - { - 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/src/ProgramOptions.cs b/src/ProgramOptions.cs deleted file mode 100644 index 0d13a8f..0000000 --- a/src/ProgramOptions.cs +++ /dev/null @@ -1,22 +0,0 @@ -using CommandLine; - -namespace DistroGrubThemes -{ - public class ProgramOptions - { - [Option('r', "repository", Required = true, HelpText = "Path to repository.")] - public string RepositoryPath { get; set; } - - [Option('a', "archive", HelpText = "Update archives.")] - public bool UpdateArchives { get; set; } - - [Option('f', "fonts", HelpText = "Update fonts.")] - public bool UpdateFonts { get; set; } - - [Option('i', "icons", HelpText = "Update icons.")] - public bool UpdateIcons { get; set; } - - [Option('v', "verbose" , HelpText = "Enable debug messages.")] - public bool VerboseMode { get; set; } - } -} diff --git a/src/README.md b/src/README.md deleted file mode 100644 index 8246f0d..0000000 --- a/src/README.md +++ /dev/null @@ -1,5 +0,0 @@ -## Readme -This is obsolete program to update all icons, fonts and pack each theme files from ``customize/*`` to ``themes/`` folder in ``.tar`` format (non-compressed). - -Now, every time you create new commit on ``master`` branch and change something in ``assets/icons``, ``customize`` or ``font`` folder, [github action](https://github.com/features/actions) bot will update all files (as defined in [this file](https://github.com/AdisonCavani/distro-grub-themes/blob/master/.github/workflows/update-content.yml)). -
To check all workflows, go [here](https://github.com/AdisonCavani/distro-grub-themes/actions).