From f25d12a894754cf1951cd198298942a6463b0b32 Mon Sep 17 00:00:00 2001 From: Adison Cavani Date: Sat, 9 Oct 2021 18:45:08 +0200 Subject: [PATCH] Add new auto-update C# program --- src/DistroGrubThemes.csproj | 15 +++++ src/DistroGrubThemes.sln | 25 ++++++++ src/Program.cs | 117 ++++++++++++++++++++++++++++++++++++ src/ProgramOptions.cs | 10 +++ 4 files changed, 167 insertions(+) create mode 100644 src/DistroGrubThemes.csproj create mode 100644 src/DistroGrubThemes.sln create mode 100644 src/Program.cs create mode 100644 src/ProgramOptions.cs diff --git a/src/DistroGrubThemes.csproj b/src/DistroGrubThemes.csproj new file mode 100644 index 0000000..b132f8d --- /dev/null +++ b/src/DistroGrubThemes.csproj @@ -0,0 +1,15 @@ + + + + Exe + netcoreapp3.1 + Adison Cavani + Adison Cavani + + + + + + + + diff --git a/src/DistroGrubThemes.sln b/src/DistroGrubThemes.sln new file mode 100644 index 0000000..ea76239 --- /dev/null +++ b/src/DistroGrubThemes.sln @@ -0,0 +1,25 @@ + +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/Program.cs b/src/Program.cs new file mode 100644 index 0000000..4bc81fb --- /dev/null +++ b/src/Program.cs @@ -0,0 +1,117 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using CommandLine; + +namespace DistroGrubThemes +{ + + internal class Program + { + string repoPath = string.Empty; + string iconsPath = string.Empty; + string customizePath = string.Empty; + string fontsPath = string.Empty; + + static void Main(string[] args) + { + Parser.Default.ParseArguments(args).WithParsed(RunOptions).WithNotParsed(HandleParseError); + } + + static void RunOptions(ProgramOptions opts) + { + Program program = new Program(); + + if (string.IsNullOrWhiteSpace(opts.ArchivedFiles)) + { + program.UpdateAssets(); + } + + else if(opts.ArchivedFiles == "all") + { + Console.WriteLine("Correct"); + } + + else + { + Console.WriteLine("DistroGrubThemes 1.0.0"); + Console.WriteLine("Copyright (C) 2021 Adison Cavani\n"); + Console.WriteLine("ERROR(S): "); + Console.WriteLine($" Argument {opts.ArchivedFiles} is unknown."); + Console.WriteLine("\n -a, --archive\tTest\n"); + } + } + + static void HandleParseError(IEnumerable errs) + { + Environment.Exit(1); + } + + void UpdateAssets() + { + Console.Write("Repository path: "); + CheckRepoPath(Console.ReadLine()); + + iconsPath = repoPath + @"\assets\icons"; + customizePath = repoPath + @"\customize"; + fontsPath = repoPath + @"\font"; + + UpdateIcons(); + UpdateFonts(); + } + + void UpdateIcons() + { + var icons = FilesArray(iconsPath); + + foreach (var directory in CustomDirectories()) + { + foreach (var icon in icons) + { + File.Copy(iconsPath + @"\" + icon, directory + @"\icons\" + icon, true); + } + } + } + + void UpdateFonts() + { + var fonts = FilesArray(fontsPath); + + foreach (var directory in CustomDirectories()) + { + foreach (var font in fonts) + { + File.Copy(fontsPath + @"\" + font, directory + @"\" + font, true); + } + } + } + + List FilesArray(string folderPath) + { + return new List(Directory.GetFiles(folderPath).Select(Path.GetFileName)); + } + + string[] CustomDirectories() + { + return Directory.GetDirectories(customizePath); + } + + void CheckRepoPath(string path) + { + if (Directory.Exists(path) && path.Contains("distro-grub-themes")) + { + int index = path.IndexOf("distro-grub-themes") + 18; + repoPath = path.Substring(0, index); + } + + else + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine("ERROR: Could not find repository in this path!"); + Console.ResetColor(); + Environment.Exit(1); + } + } + } +} diff --git a/src/ProgramOptions.cs b/src/ProgramOptions.cs new file mode 100644 index 0000000..dc52d12 --- /dev/null +++ b/src/ProgramOptions.cs @@ -0,0 +1,10 @@ +using CommandLine; + +namespace DistroGrubThemes +{ + public class ProgramOptions + { + [Option('a', "archive", HelpText = "Create theme archive.")] + public string ArchivedFiles { get; set; } + } +}