From c5de2e6886cfc45228ebea4d92409c112f25839a Mon Sep 17 00:00:00 2001 From: JFronny <33260128+JFronny@users.noreply.github.com> Date: Mon, 31 Aug 2020 18:58:15 +0200 Subject: [PATCH] Better logging for debugging, partially reworked interface for UpToolCLI --- .github/workflows/main.yml | 145 ------------------------------- .gitlab-ci.yml | 3 - UpTool2.sln | 2 +- UpTool2/MainForm.cs | 21 ++++- UpToolCLI/CacheManagement.cs | 10 +-- UpToolCLI/Other.cs | 5 +- UpToolCLI/PackageManagement.cs | 25 ++---- UpToolCLI/ReposManagement.cs | 15 +--- UpToolLib/Tool/RepoManagement.cs | 15 +++- 9 files changed, 42 insertions(+), 199 deletions(-) delete mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 39396e0..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,145 +0,0 @@ -name: CD - -on: - push: - branches: - - master - -jobs: - build: - - runs-on: windows-latest - - steps: - - uses: actions/checkout@v2.0.0 - - name: Build - id: base_init - run: | - cd $Env:GITHUB_WORKSPACE - dotnet build --verbosity:m -p:Configuration=Release - cp ".\UpTool build tool\bin\Release\netcoreapp3.1\package.zip" $Env:GITHUB_WORKSPACE\Tools.zip - & "C:\Program Files\7-Zip\7z" a .\Release.zip .\UpTool2\bin\Release\netcoreapp3.1\UpTool2.exe - & "C:\Program Files\7-Zip\7z" a .\Release.zip .\UpTool2\bin\Release\netcoreapp3.1\*.dll - & "C:\Program Files\7-Zip\7z" a .\Release.zip .\UpTool2\bin\Release\netcoreapp3.1\UpTool2.runtimeconfig.json - & "C:\Program Files\7-Zip\7z" a .\Release.zip .\UpTool2\bin\Release\netcoreapp3.1\runtimes - & "C:\Program Files\7-Zip\7z" a .\Release.zip .\UpToolCLI\bin\Release\netcoreapp3.1\uptool.exe - & "C:\Program Files\7-Zip\7z" a .\Release.zip .\UpToolCLI\bin\Release\netcoreapp3.1\*.dll - & "C:\Program Files\7-Zip\7z" a .\Release.zip .\UpToolCLI\bin\Release\netcoreapp3.1\uptool.runtimeconfig.json - & "C:\Program Files\7-Zip\7z" a .\Release.zip .\UpToolCLI\bin\Release\netcoreapp3.1\runtimes - $asmver = $([Reflection.Assembly]::Loadfile($(pwd).Path + "\\UpTool2\\bin\\Release\\netcoreapp3.1\\UpTool2.dll").GetName().version.ToString()) - $pkgtoolver = $([Reflection.Assembly]::Loadfile($(pwd).Path + "\\UpTool build tool\\bin\\Release\\netcoreapp3.1\\pkgtool.dll").GetName().version.ToString()) - echo "::set-output name=vers::$asmver" - echo "::set-output name=pkgvers::$pkgtoolver" - cd $Env:GITHUB_WORKSPACE\InstallerCLI - & "C:\Program Files\7-Zip\7z" a ..\Installer-generic.zip .\bin\Release\netcoreapp3.1\Installer.exe - & "C:\Program Files\7-Zip\7z" a ..\Installer-generic.zip .\bin\Release\netcoreapp3.1\*.dll - & "C:\Program Files\7-Zip\7z" a ..\Installer-generic.zip .\bin\Release\netcoreapp3.1\Installer.runtimeconfig.json - & "C:\Program Files\7-Zip\7z" a ..\Installer-generic.zip .\Info.txt - cd $Env:GITHUB_WORKSPACE - - name: Create Release - id: create_release - uses: actions/create-release@v1.0.1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: ${{ steps.base_init.outputs.vers }} - release_name: Release ${{ steps.base_init.outputs.vers }} - draft: false - prerelease: false - - name: Upload Release Asset - id: upload_release_asset - uses: actions/upload-release-asset@v1.0.2 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./Release.zip - asset_name: Release.zip - asset_content_type: application/zip - - name: Upload Tool Asset - id: upload_tool_asset - uses: actions/upload-release-asset@v1.0.2 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./Tools.zip - asset_name: Tools.zip - asset_content_type: application/zip - - name: Upload generic Installer - id: upload_generic_installer - uses: actions/upload-release-asset@v1.0.2 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./Installer-generic.zip - asset_name: Installer-generic.zip - asset_content_type: application/zip - - name: Create XML - run: | - [System.XML.XMLDocument]$xml=New-Object System.XML.XMLDocument - [System.XML.XMLElement]$app=$xml.CreateElement("app") - $xml.appendChild($app) - $app.appendChild($xml.CreateElement("Name")).InnerText = "UpTool2 package tools" - $app.appendChild($xml.CreateElement("Description")).InnerText = "Tools for automating package creation" - $app.appendChild($xml.CreateElement("Version")).InnerText = "${{ steps.base_init.outputs.pkgvers }}" - $app.appendChild($xml.CreateElement("ID")).InnerText = "0e35d154-d0d3-45e0-b080-62f521263a44" - $app.appendChild($xml.CreateElement("File")).InnerText = "${{ steps.upload_tool_asset.outputs.browser_download_url }}" - $app.appendChild($xml.CreateElement("Hash")).InnerText = $(Get-FileHash $Env:GITHUB_WORKSPACE\Tools.zip).Hash - echo NULL > tools.xml - $xml.save($(gi .\tools.xml).Fullname) - [System.XML.XMLDocument]$xml=New-Object System.XML.XMLDocument - [System.XML.XMLElement]$app=$xml.CreateElement("meta") - $xml.appendChild($app) - $app.appendChild($xml.CreateElement("Version")).InnerText = "${{ steps.base_init.outputs.vers }}" - $app.appendChild($xml.CreateElement("File")).InnerText = "${{ steps.upload_release_asset.outputs.browser_download_url }}" - $app.appendChild($xml.CreateElement("Hash")).InnerText = $(Get-FileHash $Env:GITHUB_WORKSPACE\Release.zip).Hash - $app.appendChild($xml.CreateElement("Installer")).InnerText = "${{ steps.upload_generic_installer.outputs.browser_download_url }}" - $app.appendChild($xml.CreateElement("InstallerHash")).InnerText = $(Get-FileHash $Env:GITHUB_WORKSPACE\Installer-generic.zip).Hash - echo NULL > meta.xml - $xml.save($(gi .\meta.xml).Fullname) - - name: Upload Meta XML - uses: actions/upload-release-asset@v1.0.2 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./meta.xml - asset_name: meta.xml - asset_content_type: text/xml - - name: Upload Tool XML - uses: actions/upload-release-asset@v1.0.2 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./tools.xml - asset_name: tools.xml - asset_content_type: text/xml - - name: Build non-generic installers - run: | - cd $Env:GITHUB_WORKSPACE\Installer - dotnet publish -r win-x64 -c Release /p:PublishSingleFile=true /p:PublishTrimmed=true - dotnet publish -r win-x86 -c Release /p:PublishSingleFile=true /p:PublishTrimmed=true - cp .\bin\Release\netcoreapp3.1\win-x64\publish\Installer.exe ..\Installer-x64.exe - cp .\bin\Release\netcoreapp3.1\win-x86\publish\Installer.exe ..\Installer-x86.exe - cd $Env:GITHUB_WORKSPACE - - name: Upload x86 Installer - uses: actions/upload-release-asset@v1.0.2 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./Installer-x86.exe - asset_name: Installer-x86.exe - asset_content_type: application/vnd.microsoft.portable-executable - - name: Upload x64 Installer - uses: actions/upload-release-asset@v1.0.2 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./Installer-x64.exe - asset_name: Installer-x64.exe - asset_content_type: application/vnd.microsoft.portable-executable diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9e60e45..4d4f3df 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,9 +2,6 @@ tags: - windows -before_script: - - dotnet restore - uptool: extends: - .shared_windows_runners diff --git a/UpTool2.sln b/UpTool2.sln index af5da86..b2991d7 100644 --- a/UpTool2.sln +++ b/UpTool2.sln @@ -8,9 +8,9 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{9841227C-3F1B-4C32-8123-3DB2CF4E15EE}" ProjectSection(SolutionItems) = preProject .gitignore = .gitignore - .github\workflows\main.yml = .github\workflows\main.yml README.md = README.md CLI.md = CLI.md + .gitlab-ci.yml = .gitlab-ci.yml EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UpTool build tool", "UpTool build tool\UpTool build tool.csproj", "{AAB8D6BA-3A43-4DC4-95EE-6757482B77FD}" diff --git a/UpTool2/MainForm.cs b/UpTool2/MainForm.cs index 75660ca..cef93fe 100644 --- a/UpTool2/MainForm.cs +++ b/UpTool2/MainForm.cs @@ -4,6 +4,7 @@ using System.Drawing; using System.IO; using System.Linq; using System.Reflection; +using System.Threading; using System.Windows.Forms; using UpTool2.Task; using UpToolLib; @@ -30,7 +31,10 @@ namespace UpTool2 HelpRequested += _help; filterBox.DataSource = Enum.GetValues(typeof(Status)); if (Program.Online) + { + Program.SetSplash(8, "Fetching repositories"); RepoManagement.FetchRepos(); + } else { MessageBox.Show("Starting in offline mode!"); @@ -38,7 +42,7 @@ namespace UpTool2 filterBox.Enabled = false; filterBox.SelectedIndex = 2; } - Program.SetSplash(8, "Reloading data"); + Program.SetSplash(9, "Reloading data"); ReloadElements(); if (!Directory.Exists(PathTool.AppsPath)) Directory.CreateDirectory(PathTool.AppsPath); @@ -190,8 +194,19 @@ namespace UpTool2 private void Controls_reload_Click(object sender, EventArgs e) { - RepoManagement.FetchRepos(); - ReloadElements(); + Enabled = false; + if (MessageBox.Show("This may take a few minutes. Are you sure?", "", MessageBoxButtons.YesNo) == DialogResult.Yes) + { + new Thread(() => + { + RepoManagement.FetchRepos(); + Invoke((Action) (() => + { + ReloadElements(); + Enabled = true; + })); + }).Start(); + } } private void Controls_settings_Click(object sender, EventArgs e) => new SettingsForms().ShowDialog(); diff --git a/UpToolCLI/CacheManagement.cs b/UpToolCLI/CacheManagement.cs index 415281b..f6c333a 100644 --- a/UpToolCLI/CacheManagement.cs +++ b/UpToolCLI/CacheManagement.cs @@ -21,20 +21,14 @@ namespace UpToolCLI Command search = new Command("search", "Search for packages") { - new Option(new[] {"--identifier", "-i"}, "Something to identify the app") - { - Required = true - } + new Argument("identifier", "Something to identify the app") }; search.Handler = CommandHandler.Create(Search); rootCommand.AddCommand(search); Command show = new Command("show", "Shows package info") { - new Option(new[] {"--identifier", "-i"}, "Something to identify the app") - { - Required = true - } + new Argument("identifier", "Something to identify the app") }; show.Handler = CommandHandler.Create(Show); rootCommand.AddCommand(show); diff --git a/UpToolCLI/Other.cs b/UpToolCLI/Other.cs index 388edda..f45193c 100644 --- a/UpToolCLI/Other.cs +++ b/UpToolCLI/Other.cs @@ -27,10 +27,7 @@ namespace UpToolCLI Command start = new Command("start", "Starts an app") { - new Option(new[] {"--identifier", "-i"}, "Something to identify the app") - { - Required = true - }, + new Argument("identifier", "Something to identify the app"), new Option(new[] {"--waitForExit", "-wait"}, "Waits until the program quits") }; start.Handler = CommandHandler.Create(Start); diff --git a/UpToolCLI/PackageManagement.cs b/UpToolCLI/PackageManagement.cs index 98dcd10..63a6e83 100644 --- a/UpToolCLI/PackageManagement.cs +++ b/UpToolCLI/PackageManagement.cs @@ -18,10 +18,7 @@ namespace UpToolCLI { Command install = new Command("install", "Install a package") { - new Option(new[] {"--identifier", "-i"}, "Something to identify the app or the file name") - { - Required = true - }, + new Argument("identifier", "Something to identify the app or the file name"), new Option(new[] {"--force", "-f"}, "Overwrites older files") }; install.Handler = CommandHandler.Create(Install); @@ -29,10 +26,7 @@ namespace UpToolCLI Command upgrade = new Command("upgrade", "Upgrade a package") { - new Option(new[] {"--identifier", "-i"}, "Something to identify the app") - { - Required = true - }, + new Argument("identifier", "Something to identify the app"), new Option(new[] {"--force", "-f"}, "Overwrites older files") }; upgrade.Handler = CommandHandler.Create(Upgrade); @@ -40,10 +34,7 @@ namespace UpToolCLI Command reinstall = new Command("reinstall", "Reinstall a package") { - new Option(new[] {"--identifier", "-i"}, "Something to identify the app") - { - Required = true - }, + new Argument("identifier", "Something to identify the app"), new Option(new[] {"--force", "-f"}, "Overwrites older files") }; reinstall.Handler = CommandHandler.Create(Reinstall); @@ -51,20 +42,14 @@ namespace UpToolCLI Command remove = new Command("remove", "Remove a package") { - new Option(new[] {"--identifier", "-i"}, "Something to identify the app") - { - Required = true - } + new Argument("identifier", "Something to identify the app") }; remove.Handler = CommandHandler.Create(Remove); rootCommand.AddCommand(remove); Command purge = new Command("purge", "Completely remove a package") { - new Option(new[] {"--identifier", "-i"}, "Something to identify the app") - { - Required = true - } + new Argument("identifier", "Something to identify the app") }; purge.Handler = CommandHandler.Create(Purge); rootCommand.AddCommand(purge); diff --git a/UpToolCLI/ReposManagement.cs b/UpToolCLI/ReposManagement.cs index 202a0a7..029d92b 100644 --- a/UpToolCLI/ReposManagement.cs +++ b/UpToolCLI/ReposManagement.cs @@ -18,24 +18,15 @@ namespace UpToolCLI Command addRepo = new Command("add-repo", "Adds a repository") { - new Option(new[] {"--name", "-n"}, "The new repositories name") - { - Required = true - }, - new Option(new[] {"--link", "-l"}, "A link to the repositories XML") - { - Required = true - } + new Argument("name", "The new repositories name"), + new Argument("link", "A link to the repositories XML") }; addRepo.Handler = CommandHandler.Create(AddRepo); rootCommand.AddCommand(addRepo); Command removeRepo = new Command("remove-repo", "Removes a repository") { - new Option(new[] {"--name", "-n"}, "The repositories name") - { - Required = true - } + new Argument("name", "The repositories name") }; removeRepo.Handler = CommandHandler.Create(RemoveRepo); rootCommand.AddCommand(removeRepo); diff --git a/UpToolLib/Tool/RepoManagement.cs b/UpToolLib/Tool/RepoManagement.cs index 31c0791..6ec581e 100644 --- a/UpToolLib/Tool/RepoManagement.cs +++ b/UpToolLib/Tool/RepoManagement.cs @@ -4,6 +4,7 @@ using System.Drawing; using System.IO; using System.Linq; using System.Xml.Linq; +using CC_Functions.Misc; using UpToolLib.DataStructures; namespace UpToolLib.Tool @@ -20,14 +21,18 @@ namespace UpToolLib.Tool int i = 0; while (i < repArr.Count) { + string status = "Initializing"; #if !DEBUG try { #endif ExternalFunctionalityManager.Instance.Log($"[{i + 1}] Loading {repArr[i]}"); + status = $"Loading {repArr[i]}"; XDocument repo = XDocument.Load(new Uri(repArr[i]).TryUnshorten().AbsoluteUri); + status = $"Extracting repolinks"; repArr.AddRange(repo.Element("repo").Elements("repolink").Select(s => s.Value) .Where(s => !repArr.Contains(s))); + status = $"Extracting apps"; XElement[] tmpApparray = repo.Element("repo").Elements("app").Where(app => !tmpAppsList.Any(a => a.Element("ID").Value == app.Element("ID").Value) || !tmpAppsList @@ -37,9 +42,13 @@ namespace UpToolLib.Tool .Select(s => { ExternalFunctionalityManager.Instance.Log($"- Loading {s.Value}"); - return XDocument.Load(new Uri(s.Value).TryUnshorten().AbsoluteUri).Element("app"); + status = $"Fetching app data tag: {s.Value}"; + XElement ret = XDocument.Load(new Uri(s.Value).TryUnshorten().AbsoluteUri) + .Element("app"); + return ret; })) .ToArray(); + status = $"Creating app cache"; foreach (XElement app in tmpApparray) { //"Sanity check" @@ -51,7 +60,7 @@ namespace UpToolLib.Tool new XElement("Description", app.Element("Description").Value), new XElement("Version", app.Element("Version").Value), new XElement("ID", app.Element("ID").Value), - new XElement("File", app.Element("File").Value), + new XElement("File", new Uri(app.Element("File").Value).Unshorten().ToString()), new XElement("Hash", app.Element("Hash").Value) )); if (app.Element("MainFile") != null) @@ -85,7 +94,7 @@ namespace UpToolLib.Tool catch (Exception e) { ExternalFunctionalityManager.Instance.OkDialog( - $"Failed to load repo: {repArr[i]}{Environment.NewLine}{e}"); + $"Failed to load repo: {repArr[i]}{Environment.NewLine}Last status was: {status}{Environment.NewLine}{e}"); } #endif i++;