mirror of
https://github.com/AdisonCavani/distro-grub-themes.git
synced 2025-06-07 07:32:33 +02:00
Add new auto-update C# program
This commit is contained in:
parent
dcd889da97
commit
f25d12a894
4 changed files with 167 additions and 0 deletions
15
src/DistroGrubThemes.csproj
Normal file
15
src/DistroGrubThemes.csproj
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
|
<Authors>Adison Cavani</Authors>
|
||||||
|
<Company>Adison Cavani</Company>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="CommandLineParser" Version="2.8.0" />
|
||||||
|
<PackageReference Include="SharpZipLib" Version="1.3.3" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
25
src/DistroGrubThemes.sln
Normal file
25
src/DistroGrubThemes.sln
Normal file
|
@ -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
|
117
src/Program.cs
Normal file
117
src/Program.cs
Normal file
|
@ -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<ProgramOptions>(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<Error> 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<string> FilesArray(string folderPath)
|
||||||
|
{
|
||||||
|
return new List<string>(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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
10
src/ProgramOptions.cs
Normal file
10
src/ProgramOptions.cs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
using CommandLine;
|
||||||
|
|
||||||
|
namespace DistroGrubThemes
|
||||||
|
{
|
||||||
|
public class ProgramOptions
|
||||||
|
{
|
||||||
|
[Option('a', "archive", HelpText = "Create theme archive.")]
|
||||||
|
public string ArchivedFiles { get; set; }
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue