diff --git a/BUILDS/net6.0/PluginManager.dll b/BUILDS/net6.0/PluginManager.dll index 7c99f4f..358c730 100644 Binary files a/BUILDS/net6.0/PluginManager.dll and b/BUILDS/net6.0/PluginManager.dll differ diff --git a/DiscordBot/DiscordBot.csproj b/DiscordBot/DiscordBot.csproj index 5aa59c2..a0ad0e1 100644 --- a/DiscordBot/DiscordBot.csproj +++ b/DiscordBot/DiscordBot.csproj @@ -8,7 +8,7 @@ False True - 1.0.0.3 + 1.0.0.10 diff --git a/DiscordBot/Program.cs b/DiscordBot/Program.cs index a94ff80..1ec9773 100644 --- a/DiscordBot/Program.cs +++ b/DiscordBot/Program.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; @@ -30,18 +31,18 @@ public class Program [Obsolete] public static void Main(string[] args) { + Console.WriteLine("Loading resources ..."); Directory.CreateDirectory("./Data/Resources"); Directory.CreateDirectory("./Data/Plugins/Commands"); Directory.CreateDirectory("./Data/Plugins/Events"); PreLoadComponents().Wait(); - - - if (!Config.ContainsKey("ServerID")) + do { - do + if (!Config.ContainsKey("ServerID")) { - Console.Clear(); + + Console.WriteLine("Please enter the server ID: "); Console_Utilities.WriteColorText("You can find it in the Server Settings at &r\"Widget\"&c section"); Console.WriteLine("Example: 1234567890123456789"); @@ -56,49 +57,48 @@ public class Program string SID = key.KeyChar + Console.ReadLine(); if (SID.Length != 18) { - Console.WriteLine("Your server ID is not 18 characters long. Please try again."); + Console.Clear(); + Console_Utilities.WriteColorText("&rYour server ID is not 18 characters long. Please try again. \n"); + continue; } - - Config.AddValueToVariables("ServerID", SID, false); - } - break; - } while (true); + } - } + if (!Config.ContainsKey("token") || Config.GetValue("token") == null || (Config.GetValue("token")?.Length != 70 && Config.GetValue("token")?.Length != 59)) + { + Console.WriteLine("Please insert your token"); + Console.Write("Token = "); + var token = Console.ReadLine(); + if (token?.Length == 59 || token?.Length == 70) + Config.AddValueToVariables("token", token, true); + else + { + Console.Clear(); + Console_Utilities.WriteColorText("&rThe token length is invalid !"); + continue; + } + } - if (!Config.ContainsKey("token") || Config.GetValue("token") == null || Config.GetValue("token")?.Length != 70) - { - Console.WriteLine("Please insert your token"); - Console.Write("Token = "); - var token = Console.ReadLine(); - if (token?.Length == 59 || token?.Length == 70) - Config.AddValueToVariables("token", token, true); - else - Console.WriteLine("Invalid token"); + if (!Config.ContainsKey("prefix") || Config.GetValue("prefix") == null || Config.GetValue("prefix")?.Length != 1) + { + Console.WriteLine("Please insert your prefix (max. 1 character long):"); + Console.WriteLine("For a prefix longer then one character, the first character will be saved and the others will be ignored.\n No spaces, numbers, '/' or '\\' allowed"); + Console.Write("Prefix = "); + var prefix = Console.ReadLine()![0]; - Console.WriteLine("Please insert your prefix (max. 1 character long):"); - Console.WriteLine("For a prefix longer then one character, the first character will be saved and the others will be ignored.\n No spaces or numbers allowed"); - Console.Write("Prefix = "); - var prefix = Console.ReadLine()![0]; - - if (prefix == ' ' || char.IsDigit(prefix)) - return; - Config.AddValueToVariables("prefix", prefix.ToString(), false); - } - - if (!Config.ContainsKey("prefix") || Config.GetValue("prefix") == default) - { - Console.WriteLine("Please insert your prefix (max. 1 character long):"); - Console.WriteLine("For a prefix longer then one character, the first character will be saved and the others will be ignored.\n No spaces or numbers allowed"); - Console.Write("Prefix = "); - var prefix = Console.ReadLine()![0]; - if (prefix == ' ') return; - Config.AddValueToVariables("prefix", prefix.ToString(), false); - } + if (prefix == ' ' || char.IsDigit(prefix) || prefix == '/' || prefix == '\\') + { + Console.Clear(); + Console_Utilities.WriteColorText("&rThe prefix is invalid"); + continue; + } + Config.AddValueToVariables("prefix", prefix.ToString(), false); + } + break; + } while (true); HandleInput(args).Wait(); } @@ -346,6 +346,8 @@ public class Program private static async Task PreLoadComponents() { + Console_Utilities.ProgressBar main = new Console_Utilities.ProgressBar(ProgressBarType.NO_END); + main.Start(); await Config.LoadConfig(); if (Config.ContainsKey("DeleteLogsAtStartup")) if (Config.GetValue("DeleteLogsAtStartup")) @@ -375,7 +377,11 @@ public class Program } } + + + List onlineSettingsList = await ServerCom.ReadTextFromURL("https://raw.githubusercontent.com/Wizzy69/installer/discord-bot-files/OnlineData"); + main.Stop(); foreach (var key in onlineSettingsList) { if (key.Length <= 3 || !key.Contains(' ')) continue; @@ -387,42 +393,45 @@ public class Program string newVersion = s[1]; if (!newVersion.Equals(Config.GetValue("Version"))) { - Console.WriteLine("A new version has been released on github page."); - Console.WriteLine("Download the new version using the following link wrote in yellow"); - Console_Utilities.WriteColorText("&y" + Config.GetValue("GitURL") + "&c"); - - Console.WriteLine(); - Console.WriteLine("Your product will work just fine on this outdated version, but an update is recommended.\n" + - "From now on, this version is no longer supported" - ); - Console_Utilities.WriteColorText("&rUse at your own risk&c"); - - Console_Utilities.WriteColorText("&mCurrent Version: " + Config.GetValue("Version") + "&c"); - Console_Utilities.WriteColorText("&gNew Version: " + newVersion + "&c"); - - Console.WriteLine("\n\n"); - await Task.Delay(1000); - - int waitTime = 10; //wait time to proceed - - Console.Write($"The bot will start in {waitTime} seconds"); - while (waitTime > 0) + if (Functions.GetOperatingSystem() == PluginManager.Others.OperatingSystem.WINDOWS) { - await Task.Delay(1000); - waitTime--; - Console.SetCursorPosition("The bot will start in ".Length, Console.CursorTop); - Console.Write(" "); - Console.SetCursorPosition("The bot will start in ".Length, Console.CursorTop); - Console.Write(waitTime + " seconds"); + + string url = $"https://github.com/Wizzy69/SethDiscordBot/releases/download/v{newVersion}/net6.0.zip"; + //string url2 = $"https://github.com/Wizzy69/SethDiscordBot/releases/download/v{newVersion}-preview/net6.0.zip"; + Process.Start("./Updater/Updater.exe", $"/update {url} ./DiscordBot.exe ./"); } + else + { + string url = $"https://github.com/Wizzy69/SethDiscordBot/releases/download/v{newVersion}/net6.0_linux.zip"; + Process.Start("./Updater/Updater", $"/update {url} ./DiscordBot ./"); + } + Environment.Exit(0); } + break; + case "UpdaterVersion": + string updaternewversion = s[1]; + if (Config.UpdaterVersion != updaternewversion) + { + Console.Clear(); + Console.WriteLine("Installing updater ...\nDo NOT close the bot during update !"); + Console_Utilities.ProgressBar bar = new Console_Utilities.ProgressBar(ProgressBarType.NO_END); + bar.Start(); + await ServerCom.DownloadFileNoProgressAsync("https://github.com/Wizzy69/installer/releases/download/release-1-discordbot/Updater.zip", "./Updater.zip"); + await Functions.ExtractArchive("./Updater.zip", "./", null, UnzipProgressType.PercentageFromTotalSize); + Config.UpdaterVersion = updaternewversion; + File.Delete("Updater.zip"); + await Config.SaveConfig(SaveType.NORMAL); + bar.Stop(); + Console.Clear(); + } break; } } - Console_Utilities.Initialize(); - Config.SaveConfig(SaveType.NORMAL); + Console_Utilities.Initialize(); + await Config.SaveConfig(SaveType.NORMAL); + Console.Clear(); } } diff --git a/PluginManager/Config.cs b/PluginManager/Config.cs index 9bb7140..348602f 100644 --- a/PluginManager/Config.cs +++ b/PluginManager/Config.cs @@ -11,6 +11,7 @@ namespace PluginManager { internal class AppConfig { + public string UpdaterVersion { get; set; } public Dictionary? ApplicationVariables { get; init; } public List? ProtectedKeyWords { get; init; } public Dictionary? PluginVersions { get; init; } @@ -77,6 +78,8 @@ namespace PluginManager private static AppConfig? appConfig { get; set; } + public static string UpdaterVersion { get => appConfig.UpdaterVersion; set => appConfig.UpdaterVersion = value; } + public static string GetPluginVersion(string pluginName) => appConfig!.PluginVersions![pluginName]; public static void SetPluginVersion(string pluginName, string newVersion) { @@ -220,7 +223,7 @@ namespace PluginManager Functions.WriteLogFile($"Loaded {appConfig.ApplicationVariables!.Keys.Count} application variables.\nLoaded {appConfig.ProtectedKeyWords!.Count} readonly variables."); return; } - appConfig = new() { ApplicationVariables = new Dictionary(), ProtectedKeyWords = new List(), PluginVersions = new Dictionary() }; + appConfig = new() { ApplicationVariables = new Dictionary(), ProtectedKeyWords = new List(), PluginVersions = new Dictionary(), UpdaterVersion = "-1" }; } public static bool ContainsValue(T value) => appConfig!.ApplicationVariables!.ContainsValue(value!); diff --git a/PluginManager/Items/ConsoleCommandsHandler.cs b/PluginManager/Items/ConsoleCommandsHandler.cs index 4a31091..3f2d455 100644 --- a/PluginManager/Items/ConsoleCommandsHandler.cs +++ b/PluginManager/Items/ConsoleCommandsHandler.cs @@ -193,29 +193,11 @@ public class ConsoleCommandsHandler if (split[0].EndsWith(".zip") || split[0].EndsWith(".pak") || split[0].EndsWith(".pkg")) { - Console.WriteLine($"Extracting {split[1]}"); - var proc = 0f; - var isExtracting = true; - var bar = new Console_Utilities.ProgressBar(ProgressBarType.NORMAL) { Max = 100f, Color = ConsoleColor.Green }; - - IProgress extractProgress = new Progress(value => { proc = value; }); - new Thread(new Task(() => - { - while (isExtracting) - { - bar.Update(proc); - if (proc >= 99.9f) - isExtracting = false; - Thread.Sleep(500); - } - } - ).Start - ).Start(); - await Functions.ExtractArchive("./" + split[1], "./", extractProgress, UnzipProgressType.PercentageFromTotalSize); - bar.Update(100f); - isExtracting = false; - await Task.Delay(1000); - bar.Update(100); + Console.WriteLine($"Extracting {split[1]} ..."); + var bar = new Console_Utilities.ProgressBar(ProgressBarType.NO_END) { Max = 100f, Color = ConsoleColor.Green }; + bar.Start(); + await Functions.ExtractArchive("./" + split[1], "./", null, UnzipProgressType.PercentageFromTotalSize); + bar.Stop(); Console.WriteLine("\n"); File.Delete("./" + split[1]); } @@ -277,21 +259,13 @@ public class ConsoleCommandsHandler { if (client is null) return; - bool run = true; - var t = new Thread(() => - { - Console_Utilities.ProgressBar bar = new Console_Utilities.ProgressBar(ProgressBarType.NO_END); - while (run) - { - bar.Update(1); - Thread.Sleep(50); - } - }); - t.Start(); + Console_Utilities.ProgressBar bar = new Console_Utilities.ProgressBar(ProgressBarType.NO_END); + + bar.Start(); await Config.SaveConfig(SaveType.NORMAL); await Config.SaveConfig(SaveType.BACKUP); await Task.Delay(4000); - run = false; + bar.Stop(); Console.WriteLine(); await client.StopAsync(); await client.DisposeAsync(); diff --git a/PluginManager/Online/ServerCom.cs b/PluginManager/Online/ServerCom.cs index 925bbf5..6151e61 100644 --- a/PluginManager/Online/ServerCom.cs +++ b/PluginManager/Online/ServerCom.cs @@ -79,5 +79,11 @@ namespace PluginManager.Online pbar.Update(100f); isDownloading = false; } + public static async Task DownloadFileNoProgressAsync(string URL, string location) + { + IProgress progress = new Progress(); + await DownloadFileAsync(URL, location, progress); + } + } } diff --git a/PluginManager/Others/Console Utilities.cs b/PluginManager/Others/Console Utilities.cs index c1277f0..81800ea 100644 --- a/PluginManager/Others/Console Utilities.cs +++ b/PluginManager/Others/Console Utilities.cs @@ -46,6 +46,32 @@ namespace PluginManager.Others private int position = 1; private bool positive = true; + private bool isRunning; + + public async void Start() + { + if (type != ProgressBarType.NO_END) + throw new Exception("Only NO_END progress bar can use this method"); + if (isRunning) + throw new Exception("This progress bar is already running"); + + isRunning = true; + while (isRunning) + { + UpdateNoEnd(); + await System.Threading.Tasks.Task.Delay(100); + } + } + + public void Stop() + { + if (type != ProgressBarType.NO_END) + throw new Exception("Only NO_END progress bar can use this method"); + if (!isRunning) + throw new Exception("Can not stop a progressbar that did not start"); + isRunning = false; + } + public void Update(float progress) { switch (type) diff --git a/PluginManager/Others/Functions.cs b/PluginManager/Others/Functions.cs index 2f26f9e..4decd4b 100644 --- a/PluginManager/Others/Functions.cs +++ b/PluginManager/Others/Functions.cs @@ -168,9 +168,7 @@ namespace PluginManager.Others /// public static async Task ExtractArchive(string zip, string folder, IProgress progress, UnzipProgressType type) { - if (!Directory.Exists(folder)) Directory.CreateDirectory(folder); - - + Directory.CreateDirectory(folder); using (ZipArchive archive = ZipFile.OpenRead(zip)) { if (type == UnzipProgressType.PercentageFromNumberOfFiles) @@ -194,7 +192,8 @@ namespace PluginManager.Others currentZIPFile++; await Task.Delay(10); - progress.Report((float)currentZIPFile / totalZIPFiles * 100); + if (progress != null) + progress.Report((float)currentZIPFile / totalZIPFiles * 100); } } else if (type == UnzipProgressType.PercentageFromTotalSize) @@ -224,7 +223,8 @@ namespace PluginManager.Others } await Task.Delay(10); - progress.Report((float)currentSize / zipSize * 100); + if (progress != null) + progress.Report((float)currentSize / zipSize * 100); } } } diff --git a/SethDiscordBot.sln b/SethDiscordBot.sln index 13ea9af..d19c69a 100644 --- a/SethDiscordBot.sln +++ b/SethDiscordBot.sln @@ -23,6 +23,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CMD_LevelingSystem", "CMD_L EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Roles", "Roles\Roles.csproj", "{954F2AA9-6624-4554-946D-0F17B84487C3}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Others", "Others", "{727BBA0B-9114-4BC8-B9A8-3F461449A564}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Updater", "Updater\Updater.csproj", "{24616F7E-E2E9-45A3-8A44-AB51FCD2D525}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -57,6 +61,10 @@ Global {954F2AA9-6624-4554-946D-0F17B84487C3}.Debug|Any CPU.Build.0 = Debug|Any CPU {954F2AA9-6624-4554-946D-0F17B84487C3}.Release|Any CPU.ActiveCfg = Release|Any CPU {954F2AA9-6624-4554-946D-0F17B84487C3}.Release|Any CPU.Build.0 = Release|Any CPU + {24616F7E-E2E9-45A3-8A44-AB51FCD2D525}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {24616F7E-E2E9-45A3-8A44-AB51FCD2D525}.Debug|Any CPU.Build.0 = Debug|Any CPU + {24616F7E-E2E9-45A3-8A44-AB51FCD2D525}.Release|Any CPU.ActiveCfg = Release|Any CPU + {24616F7E-E2E9-45A3-8A44-AB51FCD2D525}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -69,6 +77,8 @@ Global {EEC445DC-0C4B-43EA-8694-606BA0390B77} = {A290C028-77C4-4D1D-AB43-DDFE6ABD9012} {1A4E49FF-9A0A-4C54-AF35-CFFBA64353D9} = {449FA364-0B72-43FF-B3A3-806E2916200E} {954F2AA9-6624-4554-946D-0F17B84487C3} = {449FA364-0B72-43FF-B3A3-806E2916200E} + {727BBA0B-9114-4BC8-B9A8-3F461449A564} = {1862ABD5-7C30-4F15-A561-45AC8A9CA10E} + {24616F7E-E2E9-45A3-8A44-AB51FCD2D525} = {727BBA0B-9114-4BC8-B9A8-3F461449A564} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {3FB3C5DE-ED21-4D2E-ABDD-3A00EE4A2FFF} diff --git a/Updater/.gitignore b/Updater/.gitignore new file mode 100644 index 0000000..8afdcb6 --- /dev/null +++ b/Updater/.gitignore @@ -0,0 +1,454 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# Tye +.tye/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +## +## Visual studio for Mac +## + + +# globs +Makefile.in +*.userprefs +*.usertasks +config.make +config.status +aclocal.m4 +install-sh +autom4te.cache/ +*.tar.gz +tarballs/ +test-results/ + +# Mac bundle stuff +*.dmg +*.app + +# content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# JetBrains Rider +.idea/ +*.sln.iml + +## +## Visual Studio Code +## +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json diff --git a/Updater/App.axaml b/Updater/App.axaml new file mode 100644 index 0000000..828d949 --- /dev/null +++ b/Updater/App.axaml @@ -0,0 +1,7 @@ + + + + + diff --git a/Updater/App.axaml.cs b/Updater/App.axaml.cs new file mode 100644 index 0000000..a9165e5 --- /dev/null +++ b/Updater/App.axaml.cs @@ -0,0 +1,24 @@ +using Avalonia; +using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Markup.Xaml; + +namespace Updater +{ + public partial class App : Application + { + public override void Initialize() + { + AvaloniaXamlLoader.Load(this); + } + + public override void OnFrameworkInitializationCompleted() + { + if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) + { + desktop.MainWindow = new MainWindow() { Width = 250, Height = 50 }; + } + + base.OnFrameworkInitializationCompleted(); + } + } +} diff --git a/Updater/MainWindow.axaml b/Updater/MainWindow.axaml new file mode 100644 index 0000000..439b8e5 --- /dev/null +++ b/Updater/MainWindow.axaml @@ -0,0 +1,12 @@ + + + + diff --git a/Updater/MainWindow.axaml.cs b/Updater/MainWindow.axaml.cs new file mode 100644 index 0000000..2aa21e1 --- /dev/null +++ b/Updater/MainWindow.axaml.cs @@ -0,0 +1,36 @@ +using Avalonia.Controls; + +using System; +using System.Diagnostics; +using System.IO; +using System.IO.Compression; +using System.Net; + +using System.Threading.Tasks; + +namespace Updater +{ + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + + Activated += (sender, e) => FormActive(); + } + + public async void FormActive() + { + if (Program.Command != "/update") + return; + await Task.Delay(3000); + WebClient c = new WebClient(); + Directory.CreateDirectory("./Updater/Downloads"); + await c.DownloadFileTaskAsync(Program.Link, "./Updater/Downloads/Update.zip"); + await Task.Run(() => ZipFile.ExtractToDirectory("./Updater/Downloads/Update.zip", Program.Location, true)); + Process.Start(Program.AppToOpen); + File.Delete("./Updater/Downloads/Update.zip"); + Environment.Exit(0); + } + } +} diff --git a/Updater/Program.cs b/Updater/Program.cs new file mode 100644 index 0000000..e42859e --- /dev/null +++ b/Updater/Program.cs @@ -0,0 +1,34 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Controls.ApplicationLifetimes; + +using System; + +namespace Updater +{ + internal class Program + { + + public static string Command, Link, AppToOpen, Location; + + // Initialization code. Don't use any Avalonia, third-party APIs or any + // SynchronizationContext-reliant code before AppMain is called: things aren't initialized + // yet and stuff might break. + [STAThread] + public static void Main(string[] args) + { + Command = args[0]; + Link = args[1]; + AppToOpen = args[2]; + Location = string.Join(' ', args, 3, args.Length - 3); + BuildAvaloniaApp() + .StartWithClassicDesktopLifetime(args); + } + + // Avalonia configuration, don't remove; also used by visual designer. + public static AppBuilder BuildAvaloniaApp() + => AppBuilder.Configure() + .UsePlatformDetect() + .LogToTrace(); + } +} diff --git a/Updater/Updater.csproj b/Updater/Updater.csproj new file mode 100644 index 0000000..2524f5b --- /dev/null +++ b/Updater/Updater.csproj @@ -0,0 +1,27 @@ + + + WinExe + net6.0 + enable + + copyused + true + + + + + + + + + + + + + + + + +