Compare commits
No commits in common. "master" and "1.0.7403.37792" have entirely different histories.
master
...
1.0.7403.3
138
.github/workflows/main.yml
vendored
Normal file
138
.github/workflows/main.yml
vendored
Normal file
@ -0,0 +1,138 @@
|
||||
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\*
|
||||
& "C:\Program Files\7-Zip\7z" a .\Release.zip .\UpToolCLI\bin\Release\netcoreapp3.1\*
|
||||
$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\Installer
|
||||
& "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
|
||||
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
|
@ -1,72 +0,0 @@
|
||||
.shared_windows_runners:
|
||||
tags:
|
||||
- windows
|
||||
|
||||
uptool:
|
||||
extends:
|
||||
- .shared_windows_runners
|
||||
stage: deploy
|
||||
script: |
|
||||
Invoke-WebRequest -Uri https://dotnet.microsoft.com/download/dotnet-core/scripts/v1/dotnet-install.ps1 -OutFile dotnet-install.ps1
|
||||
Set-ExecutionPolicy Unrestricted -Scope Process
|
||||
.\dotnet-install.ps1 -Channel 5.0
|
||||
$env:Path = "C:\Users\gitlab_runner\AppData\Local\Microsoft\dotnet;" + $env:Path + ";C:\Users\gitlab_runner\AppData\Local\Microsoft\dotnet"
|
||||
dotnet build --verbosity:m -p:Configuration=Release
|
||||
cp ".\UpTool build tool\bin\Release\net5.0\package.zip" .\Tools.zip
|
||||
& "C:\Program Files\7-Zip\7z" a .\Release.zip .\UpTool2\bin\Release\net5.0-windows\UpTool2.exe
|
||||
& "C:\Program Files\7-Zip\7z" a .\Release.zip .\UpTool2\bin\Release\net5.0-windows\*.dll
|
||||
& "C:\Program Files\7-Zip\7z" a .\Release.zip .\UpTool2\bin\Release\net5.0-windows\UpTool2.runtimeconfig.json
|
||||
& "C:\Program Files\7-Zip\7z" a .\Release.zip .\UpToolCLI\bin\Release\net5.0\uptool.exe
|
||||
& "C:\Program Files\7-Zip\7z" a .\Release.zip .\UpToolCLI\bin\Release\net5.0\*.dll
|
||||
& "C:\Program Files\7-Zip\7z" a .\Release.zip .\UpToolCLI\bin\Release\net5.0\uptool.runtimeconfig.json
|
||||
$asmver = $([Reflection.Assembly]::Loadfile($(pwd).Path + "\\UpTool2\\bin\\Release\\net5.0-windows\\UpTool2.dll").GetName().version.ToString())
|
||||
$pkgtoolver = $([Reflection.Assembly]::Loadfile($(pwd).Path + "\\UpTool build tool\\bin\\Release\\net5.0\\pkgtool.dll").GetName().version.ToString())
|
||||
& "C:\Program Files\7-Zip\7z" a .\Installer-generic.zip .\InstallerCLI\bin\Release\net5.0\Installer.exe
|
||||
& "C:\Program Files\7-Zip\7z" a .\Installer-generic.zip .\InstallerCLI\bin\Release\net5.0\*.dll
|
||||
& "C:\Program Files\7-Zip\7z" a .\Installer-generic.zip .\InstallerCLI\bin\Release\net5.0\Installer.runtimeconfig.json
|
||||
& "C:\Program Files\7-Zip\7z" a .\Installer-generic.zip .\InstallerCLI\Info.txt
|
||||
& "C:\Program Files\7-Zip\7z" a .\Installer-gui.zip .\Installer\bin\Release\net5.0-windows\Installer.exe
|
||||
& "C:\Program Files\7-Zip\7z" a .\Installer-gui.zip .\Installer\bin\Release\net5.0-windows\*.dll
|
||||
& "C:\Program Files\7-Zip\7z" a .\Installer-gui.zip .\Installer\bin\Release\net5.0-windows\Installer.runtimeconfig.json
|
||||
[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 = $pkgtoolver
|
||||
$app.appendChild($xml.CreateElement("ID")).InnerText = "0e35d154-d0d3-45e0-b080-62f521263a44"
|
||||
$app.appendChild($xml.CreateElement("File")).InnerText = $CI_PROJECT_URL + "/-/jobs/" + $CI_JOB_ID + "/artifacts/raw/Tools.zip"
|
||||
$app.appendChild($xml.CreateElement("Hash")).InnerText = $(Get-FileHash .\Tools.zip).Hash
|
||||
$app.appendChild($xml.CreateElement("MainFile")).InnerText = "pkgtool.exe"
|
||||
$app.appendChild($xml.CreateElement("Icon")).InnerText = "https://gitlab.com/JFronny/UpTool2/-/raw/master/UpTool2.ico"
|
||||
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 = $asmver
|
||||
$app.appendChild($xml.CreateElement("File")).InnerText = $CI_PROJECT_URL + "/-/jobs/" + $CI_JOB_ID + "/artifacts/raw/Release.zip"
|
||||
$app.appendChild($xml.CreateElement("Hash")).InnerText = $(Get-FileHash .\Release.zip).Hash
|
||||
$app.appendChild($xml.CreateElement("Installer")).InnerText = $CI_PROJECT_URL + "/-/jobs/" + $CI_JOB_ID + "/artifacts/raw/Installer-generic.zip"
|
||||
$app.appendChild($xml.CreateElement("InstallerHash")).InnerText = $(Get-FileHash .\Installer-generic.zip).Hash
|
||||
$app.appendChild($xml.CreateElement("InstallerGui")).InnerText = $CI_PROJECT_URL + "/-/jobs/" + $CI_JOB_ID + "/artifacts/raw/Installer-gui.zip"
|
||||
$app.appendChild($xml.CreateElement("InstallerGuiHash")).InnerText = $(Get-FileHash .\Installer-gui.zip).Hash
|
||||
echo NULL > meta.xml
|
||||
$xml.save($(gi .\meta.xml).Fullname)
|
||||
#cd 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\net5.0-windows\win-x64\publish\Installer.exe ..\Installer-x64.exe
|
||||
#cp .\bin\Release\net5.0-windows\win-x86\publish\Installer.exe ..\Installer-x86.exe
|
||||
#cd ..
|
||||
#Installer-x64 and Installer-x86 were also originally artifacts but there doesn't seem to be a x86-64 windows runner
|
||||
artifacts:
|
||||
paths:
|
||||
- Release.zip
|
||||
- Tools.zip
|
||||
- Installer-generic.zip
|
||||
- Installer-gui.zip
|
||||
- meta.xml
|
||||
- tools.xml
|
||||
only:
|
||||
- master
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DiscordProjectSettings">
|
||||
<option name="show" value="PROJECT_FILES" />
|
||||
<option name="show" value="true" />
|
||||
</component>
|
||||
<component name="ProjectNotificationSettings">
|
||||
<option name="askShowProject" value="false" />
|
||||
|
@ -2,7 +2,7 @@
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/.idea.UpTool2/.idea/riderModule.iml" filepath="$PROJECT_DIR$/.idea/.idea.UpTool2/.idea/riderModule.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/.idea/.idea.UpTool2/riderModule.iml" filepath="$PROJECT_DIR$/.idea/.idea.UpTool2/riderModule.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RiderProjectSettingsUpdater">
|
||||
<option name="vcsConfiguration" value="2" />
|
||||
<option name="vcsConfiguration" value="1" />
|
||||
</component>
|
||||
</project>
|
@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="RIDER_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$/../.." />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
20
CLI.md
20
CLI.md
@ -1,6 +1,5 @@
|
||||
# CLI
|
||||
|
||||
### Package Management
|
||||
Updating the cache: uptool update
|
||||
|
||||
Installing a package (set \<package> to a file for local): uptool install \<package>
|
||||
|
||||
@ -12,28 +11,17 @@ Removing a package: uptool remove \<package>
|
||||
|
||||
Removing a package and all its configuration and data files: uptool purge \<package>
|
||||
|
||||
Upgrade all packages: uptool dist-upgrade
|
||||
|
||||
### Cache Management
|
||||
|
||||
List installed packages: uptool list
|
||||
|
||||
Upgrade all packages: uptool dist-upgrade
|
||||
|
||||
Search for a package: uptool search \<text>
|
||||
|
||||
Show package info: uptool show \<package>
|
||||
|
||||
Updating the cache: uptool update
|
||||
Start an app: uptool start \<package>
|
||||
|
||||
### Repos Management
|
||||
|
||||
Add a repository: uptool add-repo \<name> \<link>
|
||||
|
||||
Remove a repository: uptool remove-repo \<name>
|
||||
|
||||
List repositories: uptool list-repo
|
||||
|
||||
### Other
|
||||
|
||||
Upgrading UpToolCLI: uptool upgrade-self
|
||||
|
||||
Start an app: uptool start \<package>
|
@ -1,8 +1,8 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net5.0-windows</TargetFramework>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ApplicationIcon>..\UpTool2.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
|
46
Installer/InstallerForm.Designer.cs
generated
46
Installer/InstallerForm.Designer.cs
generated
@ -17,7 +17,6 @@
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
_lib.Dispose();
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
@ -28,7 +27,7 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Installer.InstallerForm));
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(InstallerForm));
|
||||
this.install = new System.Windows.Forms.Button();
|
||||
this.installLabel = new System.Windows.Forms.Label();
|
||||
this.progress = new System.Windows.Forms.ProgressBar();
|
||||
@ -38,7 +37,11 @@
|
||||
this.pathBox = new System.Windows.Forms.CheckBox();
|
||||
this.updateAppsBox = new System.Windows.Forms.CheckBox();
|
||||
this.SuspendLayout();
|
||||
this.install.Anchor = ((System.Windows.Forms.AnchorStyles) (((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right)));
|
||||
//
|
||||
// install
|
||||
//
|
||||
this.install.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.install.Location = new System.Drawing.Point(12, 116);
|
||||
this.install.Name = "install";
|
||||
this.install.Size = new System.Drawing.Size(539, 27);
|
||||
@ -46,26 +49,40 @@
|
||||
this.install.Text = "Install";
|
||||
this.install.UseVisualStyleBackColor = true;
|
||||
this.install.Click += new System.EventHandler(this.install_Click);
|
||||
//
|
||||
// installLabel
|
||||
//
|
||||
this.installLabel.AutoSize = true;
|
||||
this.installLabel.Location = new System.Drawing.Point(12, 9);
|
||||
this.installLabel.Name = "installLabel";
|
||||
this.installLabel.Size = new System.Drawing.Size(550, 75);
|
||||
this.installLabel.TabIndex = 1;
|
||||
this.installLabel.Text = resources.GetString("installLabel.Text");
|
||||
this.progress.Anchor = ((System.Windows.Forms.AnchorStyles) (((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right)));
|
||||
//
|
||||
// progress
|
||||
//
|
||||
this.progress.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.progress.Location = new System.Drawing.Point(12, 116);
|
||||
this.progress.Maximum = 8;
|
||||
this.progress.Name = "progress";
|
||||
this.progress.Size = new System.Drawing.Size(539, 27);
|
||||
this.progress.TabIndex = 2;
|
||||
this.progress.Visible = false;
|
||||
this.processLabel.Anchor = ((System.Windows.Forms.AnchorStyles) (((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right)));
|
||||
//
|
||||
// processLabel
|
||||
//
|
||||
this.processLabel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.processLabel.ForeColor = System.Drawing.SystemColors.ControlText;
|
||||
this.processLabel.Location = new System.Drawing.Point(386, 91);
|
||||
this.processLabel.Name = "processLabel";
|
||||
this.processLabel.Size = new System.Drawing.Size(165, 22);
|
||||
this.processLabel.TabIndex = 3;
|
||||
this.processLabel.TextAlign = System.Drawing.ContentAlignment.TopRight;
|
||||
//
|
||||
// log
|
||||
//
|
||||
this.log.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.log.Location = new System.Drawing.Point(524, 3);
|
||||
this.log.Name = "log";
|
||||
@ -75,6 +92,9 @@
|
||||
this.log.UseVisualStyleBackColor = true;
|
||||
this.log.Visible = false;
|
||||
this.log.Click += new System.EventHandler(this.log_Click);
|
||||
//
|
||||
// startupBox
|
||||
//
|
||||
this.startupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.startupBox.AutoSize = true;
|
||||
this.startupBox.Enabled = false;
|
||||
@ -84,6 +104,9 @@
|
||||
this.startupBox.TabIndex = 5;
|
||||
this.startupBox.Text = "Update on Startup";
|
||||
this.startupBox.CheckedChanged += new System.EventHandler(this.startupBox_CheckedChanged);
|
||||
//
|
||||
// pathBox
|
||||
//
|
||||
this.pathBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.pathBox.AutoSize = true;
|
||||
this.pathBox.Location = new System.Drawing.Point(12, 91);
|
||||
@ -92,6 +115,9 @@
|
||||
this.pathBox.TabIndex = 6;
|
||||
this.pathBox.Text = "Register in PATH";
|
||||
this.pathBox.CheckedChanged += new System.EventHandler(this.pathBox_CheckedChanged);
|
||||
//
|
||||
// updateAppsBox
|
||||
//
|
||||
this.updateAppsBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.updateAppsBox.AutoSize = true;
|
||||
this.updateAppsBox.Enabled = false;
|
||||
@ -100,6 +126,9 @@
|
||||
this.updateAppsBox.Size = new System.Drawing.Size(94, 19);
|
||||
this.updateAppsBox.TabIndex = 5;
|
||||
this.updateAppsBox.Text = "Update Apps";
|
||||
//
|
||||
// InstallerForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(563, 156);
|
||||
@ -118,17 +147,18 @@
|
||||
this.Text = "UpTool2 Installer";
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.Button install;
|
||||
private System.Windows.Forms.Label installLabel;
|
||||
private System.Windows.Forms.ProgressBar progress;
|
||||
private System.Windows.Forms.Label processLabel;
|
||||
private System.Windows.Forms.Button log;
|
||||
private System.Windows.Forms.CheckBox pathBox;
|
||||
private System.Windows.Forms.Label processLabel;
|
||||
private System.Windows.Forms.ProgressBar progress;
|
||||
private System.Windows.Forms.CheckBox startupBox;
|
||||
private System.Windows.Forms.CheckBox updateAppsBox;
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
using Microsoft.Win32;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
@ -9,32 +10,27 @@ using System.Security.Cryptography;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.Win32;
|
||||
using UpToolLib;
|
||||
using UpToolLib.v1.Tool;
|
||||
using UpToolLib.v2;
|
||||
using UpToolLib.Tool;
|
||||
|
||||
namespace Installer
|
||||
{
|
||||
public partial class InstallerForm : Form
|
||||
{
|
||||
private string _log = "";
|
||||
private const string AppName = "UpTool2";
|
||||
private readonly RegistryKey _rkApp;
|
||||
private string _log = "";
|
||||
private UpToolLibMain _lib;
|
||||
|
||||
public InstallerForm()
|
||||
{
|
||||
_lib = new UpToolLibMain(new UtLibFunctionsGui(Log));
|
||||
ExternalFunctionalityManager.Init(new UtLibFunctionsGui(Log));
|
||||
InitializeComponent();
|
||||
Step(0, "Initialized");
|
||||
_log = _log.TrimStart(Environment.NewLine.ToCharArray());
|
||||
_rkApp = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);
|
||||
pathBox.Checked = !File.Exists(_lib.V1.PathTool.InfoXml) ||
|
||||
Path.Content.Contains(Path.GetName(_lib.V1.PathTool.GetRelative("Install")));
|
||||
pathBox.Checked = Path.Content.Contains(Path.GetName(PathTool.GetRelative("Install")));
|
||||
startupBox.Checked = pathBox.Checked && _rkApp.GetValue(AppName) != null;
|
||||
updateAppsBox.Checked = pathBox.Checked && startupBox.Checked &&
|
||||
(string) _rkApp.GetValue(AppName) == "uptool dist-upgrade";
|
||||
updateAppsBox.Checked = pathBox.Checked && startupBox.Checked && (string)_rkApp.GetValue(AppName) == "uptool dist-upgrade";
|
||||
}
|
||||
|
||||
private void install_Click(object sender, EventArgs e)
|
||||
@ -43,15 +39,14 @@ namespace Installer
|
||||
try
|
||||
{
|
||||
progress.Visible = true;
|
||||
WebClient client = new();
|
||||
WebClient client = new WebClient();
|
||||
Step(1, "Downloading metadata");
|
||||
XElement meta = XDocument
|
||||
.Load("https://gitlab.com/JFronny/UpTool2/-/jobs/artifacts/master/raw/meta.xml?job=uptool")
|
||||
XElement meta = XDocument.Load("https://github.com/JFronny/UpTool2/releases/latest/download/meta.xml")
|
||||
.Element("meta");
|
||||
Step(2, "Downloading binary");
|
||||
byte[] dl = client.DownloadData(meta.Element("File").Value);
|
||||
Step(3, "Verifying integrity");
|
||||
using (SHA256CryptoServiceProvider sha256 = new())
|
||||
using (SHA256CryptoServiceProvider sha256 = new SHA256CryptoServiceProvider())
|
||||
{
|
||||
string pkgHash = BitConverter.ToString(sha256.ComputeHash(dl)).Replace("-", string.Empty).ToUpper();
|
||||
if (pkgHash != meta.Element("Hash").Value.ToUpper())
|
||||
@ -61,28 +56,30 @@ Package: {pkgHash}
|
||||
Online: {meta.Element("Hash").Value.ToUpper()}");
|
||||
}
|
||||
Step(4, "Extracting");
|
||||
if (Directory.Exists(_lib.V1.PathTool.GetRelative("Install")))
|
||||
Directory.Delete(_lib.V1.PathTool.GetRelative("Install"), true);
|
||||
Directory.CreateDirectory(_lib.V1.PathTool.GetRelative("Install"));
|
||||
using (MemoryStream ms = new(dl))
|
||||
if (Directory.Exists(PathTool.GetRelative("Install")))
|
||||
Directory.Delete(PathTool.GetRelative("Install"), true);
|
||||
Directory.CreateDirectory(PathTool.GetRelative("Install"));
|
||||
using (MemoryStream ms = new MemoryStream(dl))
|
||||
{
|
||||
using ZipArchive ar = new(ms);
|
||||
ar.ExtractToDirectory(_lib.V1.PathTool.GetRelative("Install"), true);
|
||||
using ZipArchive ar = new ZipArchive(ms);
|
||||
ar.ExtractToDirectory(PathTool.GetRelative("Install"), true);
|
||||
}
|
||||
Step(5, "Creating shortcut");
|
||||
Shortcut.Make(_lib.V1.PathTool.GetRelative("Install", "UpTool2.exe"),
|
||||
Shortcut.Make(PathTool.GetRelative("Install", "UpTool2.exe"),
|
||||
System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Programs),
|
||||
"UpTool2.lnk"));
|
||||
Step(6, "Preparing Repos");
|
||||
_lib.V1.XmlTool.FixXml();
|
||||
_lib.V2.RepoManagement.FetchRepos();
|
||||
XmlTool.FixXml();
|
||||
RepoManagement.FetchRepos();
|
||||
if (pathBox.Checked)
|
||||
{
|
||||
Step(7, startupBox.Checked ? "Creating PATH & Autostart entry" : "Creating PATH entry");
|
||||
if (!Path.Content.Contains(Path.GetName(_lib.V1.PathTool.GetRelative("Install"))))
|
||||
Path.Append(_lib.V1.PathTool.GetRelative("Install"));
|
||||
if (!Path.Content.Contains(Path.GetName(PathTool.GetRelative("Install"))))
|
||||
Path.Append(PathTool.GetRelative("Install"));
|
||||
if (startupBox.Checked)
|
||||
{
|
||||
_rkApp.SetValue(AppName, updateAppsBox.Checked ? "uptool dist-upgrade" : "uptool upgrade-self");
|
||||
}
|
||||
else if (_rkApp.GetValue(AppName) != null)
|
||||
_rkApp.DeleteValue(AppName, false);
|
||||
}
|
||||
|
@ -1,6 +1,13 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Security.Cryptography;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
using UpToolLib;
|
||||
using UpToolLib.Tool;
|
||||
|
||||
namespace Installer
|
||||
{
|
||||
@ -10,12 +17,68 @@ namespace Installer
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
private static void Main()
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!args.Any(s => new[] {"install", "i"}.Contains(s.TrimStart('-', '/').ToLower())))
|
||||
{
|
||||
MutexLock.Lock();
|
||||
Application.SetHighDpiMode(HighDpiMode.SystemAware);
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new InstallerForm());
|
||||
}
|
||||
else
|
||||
{
|
||||
Thread.Sleep(2000);
|
||||
MutexLock.Lock();
|
||||
ExternalFunctionalityManager.Init(new UtLibFunctionsCli());
|
||||
WebClient client = new WebClient();
|
||||
Console.WriteLine("Downloading metadata");
|
||||
UpdateCheck.Reload("https://github.com/JFronny/UpTool2/releases/latest/download/meta.xml");
|
||||
Console.WriteLine("Downloading binary");
|
||||
byte[] dl = client.DownloadData(UpdateCheck.App);
|
||||
Console.WriteLine("Verifying integrity");
|
||||
using (SHA256CryptoServiceProvider sha256 = new SHA256CryptoServiceProvider())
|
||||
{
|
||||
string pkgHash = BitConverter.ToString(sha256.ComputeHash(dl)).Replace("-", string.Empty)
|
||||
.ToUpper();
|
||||
if (pkgHash != UpdateCheck.AppHash)
|
||||
throw new Exception($@"The hash is not equal to the one stored in the repo:
|
||||
Package: {pkgHash}
|
||||
Online: {UpdateCheck.AppHash}");
|
||||
}
|
||||
Console.WriteLine("Extracting");
|
||||
if (Directory.Exists(PathTool.GetRelative("Install")))
|
||||
{
|
||||
foreach (string file in Directory.GetFiles(PathTool.GetRelative("Install"))) File.Delete(file);
|
||||
foreach (string dir in Directory.GetDirectories(PathTool.GetRelative("Install")))
|
||||
if (System.IO.Path.GetFileName(dir) != "tmp")
|
||||
Directory.Delete(dir, true);
|
||||
}
|
||||
Directory.CreateDirectory(PathTool.GetRelative("Install"));
|
||||
using (MemoryStream ms = new MemoryStream(dl))
|
||||
{
|
||||
using ZipArchive ar = new ZipArchive(ms);
|
||||
ar.ExtractToDirectory(PathTool.GetRelative("Install"), true);
|
||||
}
|
||||
Console.WriteLine("Creating shortcut");
|
||||
Shortcut.Make(PathTool.GetRelative("Install", "UpTool2.exe"),
|
||||
System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Programs),
|
||||
"UpTool2.lnk"));
|
||||
Console.WriteLine("Creating PATH entry");
|
||||
if (!Path.Content.Contains(Path.GetName(PathTool.GetRelative("Install"))))
|
||||
Path.Append(PathTool.GetRelative("Install"));
|
||||
Console.WriteLine("Preparing Repos");
|
||||
XmlTool.FixXml();
|
||||
RepoManagement.FetchRepos();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
MutexLock.Unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
116
Installer/UTLibFunctions_CLI.cs
Normal file
116
Installer/UTLibFunctions_CLI.cs
Normal file
@ -0,0 +1,116 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using UpToolLib.DataStructures;
|
||||
|
||||
namespace Installer
|
||||
{
|
||||
public class UtLibFunctionsCli : IExternalFunctionality
|
||||
{
|
||||
public Tuple<bool, byte[]> Download(Uri link)
|
||||
{
|
||||
using WebClient client = new WebClient();
|
||||
byte[] result = new byte[0];
|
||||
bool finished = false;
|
||||
bool success = true;
|
||||
client.DownloadDataCompleted += (sender, e) =>
|
||||
{
|
||||
success = !e.Cancelled;
|
||||
if (success)
|
||||
result = e.Result;
|
||||
finished = true;
|
||||
};
|
||||
client.DownloadProgressChanged += (sender, e) =>
|
||||
{
|
||||
Console.Write(
|
||||
$"{new string('=', e.ProgressPercentage / 10)}[{e.ProgressPercentage}]{new string('-', 10 - e.ProgressPercentage / 10)}");
|
||||
Console.CursorLeft = 0;
|
||||
};
|
||||
client.DownloadDataAsync(link);
|
||||
while (!finished)
|
||||
Thread.Sleep(100);
|
||||
return new Tuple<bool, byte[]>(success, result);
|
||||
}
|
||||
|
||||
public string FetchImageB64(Uri link)
|
||||
{
|
||||
using WebClient client = new WebClient();
|
||||
Image src = Image.FromStream(
|
||||
client.OpenRead(link));
|
||||
Bitmap dest = new Bitmap(70, 70);
|
||||
dest.SetResolution(src.HorizontalResolution, src.VerticalResolution);
|
||||
using (Graphics g = Graphics.FromImage(dest))
|
||||
{
|
||||
g.CompositingMode = CompositingMode.SourceCopy;
|
||||
g.CompositingQuality = CompositingQuality.HighQuality;
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
using ImageAttributes wrapMode = new ImageAttributes();
|
||||
wrapMode.SetWrapMode(WrapMode.TileFlipXY);
|
||||
g.DrawImage(src, new Rectangle(0, 0, 70, 70), 0, 0, src.Width, src.Height,
|
||||
GraphicsUnit.Pixel, wrapMode);
|
||||
}
|
||||
using MemoryStream ms = new MemoryStream();
|
||||
dest.Save(ms, ImageFormat.Png);
|
||||
return Convert.ToBase64String(ms.ToArray());
|
||||
}
|
||||
|
||||
public bool YesNoDialog(string text, bool defaultVal)
|
||||
{
|
||||
bool choosing = true;
|
||||
bool current = defaultVal;
|
||||
Console.WriteLine(text);
|
||||
while (choosing)
|
||||
{
|
||||
Console.CursorLeft = 0;
|
||||
Console.BackgroundColor = current ? ConsoleColor.White : ConsoleColor.Black;
|
||||
Console.ForegroundColor = current ? ConsoleColor.Black : ConsoleColor.White;
|
||||
Console.Write("Yes");
|
||||
Console.ResetColor();
|
||||
Console.Write(" ");
|
||||
Console.BackgroundColor = current ? ConsoleColor.Black : ConsoleColor.White;
|
||||
Console.ForegroundColor = current ? ConsoleColor.White : ConsoleColor.Black;
|
||||
Console.Write("No");
|
||||
Console.ResetColor();
|
||||
switch (Console.ReadKey().Key)
|
||||
{
|
||||
case ConsoleKey.LeftArrow:
|
||||
case ConsoleKey.RightArrow:
|
||||
current = !current;
|
||||
break;
|
||||
case ConsoleKey.Enter:
|
||||
choosing = false;
|
||||
break;
|
||||
case ConsoleKey.Escape:
|
||||
current = defaultVal;
|
||||
choosing = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Console.ResetColor();
|
||||
Console.WriteLine($" Selecting: {current}");
|
||||
return current;
|
||||
}
|
||||
|
||||
public void OkDialog(string text)
|
||||
{
|
||||
Console.WriteLine(text);
|
||||
Console.BackgroundColor = ConsoleColor.White;
|
||||
Console.Write("OK");
|
||||
Console.ResetColor();
|
||||
Console.ReadKey();
|
||||
}
|
||||
|
||||
public object GetDefaultIcon() => 0;
|
||||
|
||||
public object ImageFromB64(string b64) =>
|
||||
(Bitmap) new ImageConverter().ConvertFrom(Convert.FromBase64String(b64));
|
||||
|
||||
public void Log(string text) => Console.WriteLine(text);
|
||||
}
|
||||
}
|
@ -16,7 +16,7 @@ namespace Installer
|
||||
|
||||
public Tuple<bool, byte[]> Download(Uri link)
|
||||
{
|
||||
using WebClient cli = new();
|
||||
using WebClient cli = new WebClient();
|
||||
try
|
||||
{
|
||||
return new Tuple<bool, byte[]>(true, cli.DownloadData(link));
|
||||
@ -29,10 +29,10 @@ namespace Installer
|
||||
|
||||
public string FetchImageB64(Uri link)
|
||||
{
|
||||
using WebClient client = new();
|
||||
using WebClient client = new WebClient();
|
||||
Image src = Image.FromStream(
|
||||
client.OpenRead(link));
|
||||
Bitmap dest = new(70, 70);
|
||||
Bitmap dest = new Bitmap(70, 70);
|
||||
dest.SetResolution(src.HorizontalResolution, src.VerticalResolution);
|
||||
using (Graphics g = Graphics.FromImage(dest))
|
||||
{
|
||||
@ -41,12 +41,12 @@ namespace Installer
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||
using ImageAttributes wrapMode = new();
|
||||
using ImageAttributes wrapMode = new ImageAttributes();
|
||||
wrapMode.SetWrapMode(WrapMode.TileFlipXY);
|
||||
g.DrawImage(src, new Rectangle(0, 0, 70, 70), 0, 0, src.Width, src.Height,
|
||||
GraphicsUnit.Pixel, wrapMode);
|
||||
}
|
||||
using MemoryStream ms = new();
|
||||
using MemoryStream ms = new MemoryStream();
|
||||
dest.Save(ms, ImageFormat.Png);
|
||||
return Convert.ToBase64String(ms.ToArray());
|
||||
}
|
@ -1,2 +0,0 @@
|
||||
Use "Installer --help" for info
|
||||
(on non-windows platforms, use the dotnet CLI to run Installer.dll)
|
@ -1,19 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<AssemblyName>Installer</AssemblyName>
|
||||
<RootNamespace>Installer</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\UpToolLib\UpToolLib.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.2" />
|
||||
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.20574.7" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -1,90 +0,0 @@
|
||||
using System;
|
||||
using System.CommandLine;
|
||||
using System.CommandLine.Invocation;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Net;
|
||||
using System.Security.Cryptography;
|
||||
using System.Threading;
|
||||
using UpToolLib;
|
||||
using UpToolLib.v1.Tool;
|
||||
using UpToolLib.v2;
|
||||
|
||||
namespace Installer
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
public static bool Basic;
|
||||
private static UpToolLibMain _lib;
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
Thread.Sleep(2000);
|
||||
try
|
||||
{
|
||||
Basic = args.Length > 0 && args[0].ToLower() == "--basic";
|
||||
_lib = new UpToolLibMain(new UtLibFunctions());
|
||||
RootCommand rootCommand = new();
|
||||
rootCommand.AddGlobalOption(new Option<bool>("--basic",
|
||||
"Use only basic console functionality. Must be the first parameter in the call"));
|
||||
Command install = new("install", "Install UpTool")
|
||||
{
|
||||
new Option<bool>(new[] {"--noPrep", "-p"}, "Doesn't initialize repos. Use with caution!")
|
||||
};
|
||||
install.AddAlias("-i");
|
||||
install.AddAlias("i");
|
||||
install.Handler = CommandHandler.Create<bool>(Install);
|
||||
rootCommand.AddCommand(install);
|
||||
return rootCommand.InvokeAsync(args).Result;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine($"FAILED: {e}");
|
||||
return 1;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_lib?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
private static void Install(bool noPrep)
|
||||
{
|
||||
WebClient client = new();
|
||||
Console.WriteLine("Downloading metadata");
|
||||
UpdateCheck check =
|
||||
_lib.V2.UpdateChecker.Check(
|
||||
"https://gitlab.com/JFronny/UpTool2/-/jobs/artifacts/master/raw/meta.xml?job=uptool");
|
||||
PathTool pathTool = _lib.V1.PathTool;
|
||||
Console.WriteLine("Downloading binary");
|
||||
byte[] dl = client.DownloadData(check.App);
|
||||
Console.WriteLine("Verifying integrity");
|
||||
using (SHA256CryptoServiceProvider sha256 = new())
|
||||
{
|
||||
string pkgHash = BitConverter.ToString(sha256.ComputeHash(dl)).Replace("-", string.Empty)
|
||||
.ToUpper();
|
||||
if (pkgHash != check.AppHash)
|
||||
throw new Exception($@"The hash is not equal to the one stored in the repo:
|
||||
Package: {pkgHash}
|
||||
Online: {check.AppHash}");
|
||||
}
|
||||
Console.WriteLine("Extracting");
|
||||
if (Directory.Exists(pathTool.GetRelative("Install")))
|
||||
{
|
||||
foreach (string file in Directory.GetFiles(pathTool.GetRelative("Install"))) File.Delete(file);
|
||||
foreach (string dir in Directory.GetDirectories(pathTool.GetRelative("Install")))
|
||||
if (Path.GetFileName(dir) != "tmp")
|
||||
Directory.Delete(dir, true);
|
||||
}
|
||||
Directory.CreateDirectory(pathTool.GetRelative("Install"));
|
||||
using (MemoryStream ms = new(dl))
|
||||
{
|
||||
using ZipArchive ar = new(ms);
|
||||
ar.ExtractToDirectory(pathTool.GetRelative("Install"), true);
|
||||
}
|
||||
if (noPrep) return;
|
||||
Console.WriteLine("Preparing Repos");
|
||||
_lib.V1.XmlTool.FixXml();
|
||||
_lib.V2.RepoManagement.FetchRepos();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,116 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
using UpToolLib.DataStructures;
|
||||
using static Installer.Program;
|
||||
|
||||
namespace Installer
|
||||
{
|
||||
public class UtLibFunctions : IExternalFunctionality
|
||||
{
|
||||
public Tuple<bool, byte[]> Download(Uri link)
|
||||
{
|
||||
using WebClient client = new();
|
||||
byte[] result = new byte[0];
|
||||
bool finished = false;
|
||||
bool success = true;
|
||||
client.DownloadDataCompleted += (sender, e) =>
|
||||
{
|
||||
success = !e.Cancelled;
|
||||
if (success)
|
||||
result = e.Result;
|
||||
finished = true;
|
||||
};
|
||||
client.DownloadProgressChanged += (sender, e) =>
|
||||
{
|
||||
if (!Basic)
|
||||
{
|
||||
Console.Write(
|
||||
$"{new string('=', e.ProgressPercentage / 10)}[{e.ProgressPercentage}]{new string('-', 10 - e.ProgressPercentage / 10)}");
|
||||
Console.CursorLeft = 0;
|
||||
}
|
||||
};
|
||||
client.DownloadDataAsync(link);
|
||||
while (!finished)
|
||||
Thread.Sleep(100);
|
||||
return new Tuple<bool, byte[]>(success, result);
|
||||
}
|
||||
|
||||
public string FetchImageB64(Uri link)
|
||||
{
|
||||
using WebClient client = new();
|
||||
using Image image = Image.Load(client.OpenRead(link));
|
||||
using MemoryStream ms = new();
|
||||
image.SaveAsPng(ms);
|
||||
return Convert.ToBase64String(ms.ToArray());
|
||||
}
|
||||
|
||||
public bool YesNoDialog(string text, bool defaultVal)
|
||||
{
|
||||
if (Basic)
|
||||
{
|
||||
Console.WriteLine(text);
|
||||
Console.WriteLine($"Selecting: {defaultVal}");
|
||||
return defaultVal;
|
||||
}
|
||||
else
|
||||
{
|
||||
bool choosing = true;
|
||||
bool current = defaultVal;
|
||||
Console.WriteLine(text);
|
||||
while (choosing)
|
||||
{
|
||||
Console.CursorLeft = 0;
|
||||
Console.BackgroundColor = current ? ConsoleColor.White : ConsoleColor.Black;
|
||||
Console.ForegroundColor = current ? ConsoleColor.Black : ConsoleColor.White;
|
||||
Console.Write("Yes");
|
||||
Console.ResetColor();
|
||||
Console.Write(" ");
|
||||
Console.BackgroundColor = current ? ConsoleColor.Black : ConsoleColor.White;
|
||||
Console.ForegroundColor = current ? ConsoleColor.White : ConsoleColor.Black;
|
||||
Console.Write("No");
|
||||
Console.ResetColor();
|
||||
switch (Console.ReadKey().Key)
|
||||
{
|
||||
case ConsoleKey.LeftArrow:
|
||||
case ConsoleKey.RightArrow:
|
||||
current = !current;
|
||||
break;
|
||||
case ConsoleKey.Enter:
|
||||
choosing = false;
|
||||
break;
|
||||
case ConsoleKey.Escape:
|
||||
current = defaultVal;
|
||||
choosing = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Console.ResetColor();
|
||||
Console.WriteLine($" Selecting: {current}");
|
||||
return current;
|
||||
}
|
||||
}
|
||||
|
||||
public void OkDialog(string text)
|
||||
{
|
||||
if (Basic)
|
||||
Console.WriteLine(text);
|
||||
else
|
||||
{
|
||||
Console.WriteLine(text);
|
||||
Console.BackgroundColor = ConsoleColor.White;
|
||||
Console.Write("OK");
|
||||
Console.ResetColor();
|
||||
Console.ReadKey();
|
||||
}
|
||||
}
|
||||
|
||||
public object GetDefaultIcon() => 0;
|
||||
|
||||
public object ImageFromB64(string b64) => 0;
|
||||
public void Log(string text) => Console.WriteLine(text);
|
||||
}
|
||||
}
|
21
LICENSE
21
LICENSE
@ -1,21 +0,0 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020 J. Fronny
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
17
README.md
17
README.md
@ -1,8 +1,11 @@
|
||||
# UpTool2
|
||||
Downloading software from online repos since 2019\
|
||||
[![GitLab pipeline](https://img.shields.io/gitlab/pipeline/JFronny/UpTool2)](https://gitlab.com/JFronny/UpTool2/builds)
|
||||
[![CodeFactor](https://www.codefactor.io/repository/github/jfronny/uptool2/badge)](https://www.codefactor.io/repository/github/jfronny/uptool2)
|
||||
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/JFronny/UpTool2)](https://github.com/JFronny/UpTool2/releases/latest)
|
||||
[![GitHub repo size](https://img.shields.io/github/repo-size/JFronny/UpTool2)](https://github.com/JFronny/UpTool2/archive/master.zip)
|
||||
[![GitHub All Releases](https://img.shields.io/github/downloads/JFronny/UpTool2/total)](https://github.com/JFronny/UpTool2/releases)
|
||||
[![Discord](https://img.shields.io/discord/466965965658128384)](https://discordapp.com/invite/UjhHBqt)
|
||||
[![Default Repo](https://img.shields.io/badge/Default-Repo-informational)](https://gitlab.com/JFronny/UpTool2/snippets/1988600)
|
||||
[![Default Repo](https://img.shields.io/badge/Default-Repo-informational)](https://gist.github.com/JFronny/f1ccbba3d8a2f5862592bb29fdb612c4)
|
||||
## How to automate UpTool2 deployments
|
||||
You will want the assembly version to automatically increment.
|
||||
To achieve this you have to add this:\
|
||||
@ -13,14 +16,14 @@ Now you can add this\
|
||||
as a PostBuild event to automatically run pkgtool. Customize this if you need to.\
|
||||
For GitHub actions I wrote [this](https://github.com/JFronny/CC-Clicker/blob/master/.github/workflows/main.yml).\
|
||||
If you copy it, make sure to replace the descriptions and ID under the `Generate XML` step\
|
||||
You can also add something like this to your Readme: [![UpTool2](https://img.shields.io/badge/Get%20it-on%20UpTool2-blue)](https://jfronny.gitlab.io/home/uptool)\
|
||||
You can also add something like this to your Readme: [![UpTool2](https://img.shields.io/github/v/tag/JFronny/CC-Clicker?color=informational&label=UpTool2)](https://jfronny.github.io/home/uptool)\
|
||||
(Look at the source for the MD Code)
|
||||
## Folder layout
|
||||
- %APPDATA%\UpTool2
|
||||
- Apps
|
||||
- __APPGUID
|
||||
- `info.xml` Local copy of some app information, like [this](https://gitlab.com/JFronny/UpTool2#app-layout) but missing ID, File, Hash, Platform and Icon
|
||||
- [`package.zip`](https://gitlab.com/JFronny/UpTool2#package-layout) The package that was downloaded on install
|
||||
- `info.xml` Local copy of some app information, like [this](https://github.com/JFronny/UpTool2#app-layout) but missing ID, File, Hash, Platform and Icon
|
||||
- [`package.zip`](https://github.com/JFronny/UpTool2#package-layout) The package that was downloaded on install
|
||||
- `app` The app install path
|
||||
- `__APPFILES` Copy of the app files from above, may contain user-configs
|
||||
- `info.xml` File used by UpTool2 for saving info
|
||||
@ -30,7 +33,7 @@ You can also add something like this to your Readme: [![UpTool2](https://img.shi
|
||||
- `Name` The display name of the repository
|
||||
- `Link` The source of the repo xml
|
||||
- `Local Repo` A preprocessed copy of the online repos
|
||||
- [`__APP`](https://gitlab.com/JFronny/UpTool2#app-layout) A normal app with the icon processed as Base64
|
||||
- [`__APP`](https://github.com/JFronny/UpTool2#app-layout) A normal app with the icon processed as Base64
|
||||
- `Install` The folder containing the actual tool
|
||||
- `__ZIP CONTENTS` The app files
|
||||
- `tmp` A temporary folder used during updates
|
||||
@ -39,7 +42,7 @@ You can also add something like this to your Readme: [![UpTool2](https://img.shi
|
||||
- `repo` The main repo tag
|
||||
- `__APPLINK` Links to external app XMLs
|
||||
- `__REPOLINK` Links to external repos
|
||||
- [`__APP`](https://gitlab.com/JFronny/UpTool2#app-layout) Apps
|
||||
- [`__APP`](https://github.com/JFronny/UpTool2#app-layout) Apps
|
||||
## App layout
|
||||
- app
|
||||
- `Name` Name of the application
|
||||
|
@ -14,7 +14,7 @@ namespace UpTool_build_tool
|
||||
{
|
||||
installBat += "\r\n";
|
||||
installBat +=
|
||||
$@"powershell ""$s=(New-Object -COM WScript.Shell).CreateShortcut('%appdata%\Microsoft\Windows\Start Menu\Programs\{programName}.lnk');$s.TargetPath='%cd%\{Path.GetFileName(mainBin)}';$s.Save()""";
|
||||
$@"powershell ""$s=(New-Object -COM WScript.Shell).CreateShortcut('%appdata%\Microsoft\Windows\Start Menu\Programs\{programName}.lnk');$s.TargetPath='%cd%\{mainBin}';$s.Save()""";
|
||||
removeBat += "\r\n";
|
||||
removeBat += $@"del ""%appdata%\Microsoft\Windows\Start Menu\Programs\{programName}.lnk""";
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Reflection;
|
||||
using CC_Functions.Core;
|
||||
using CC_Functions.Misc;
|
||||
|
||||
namespace UpTool_build_tool
|
||||
{
|
||||
@ -30,13 +30,13 @@ namespace UpTool_build_tool
|
||||
"This indicates that your program supports multiple platforms natively and doesn't require WINE")
|
||||
};
|
||||
build.Handler =
|
||||
CommandHandler.Create((Action<string?, string, string, string, string, bool, bool, bool>) Build);
|
||||
CommandHandler.Create((Action<string, string, string, string, string, bool, bool, bool>) Build);
|
||||
rootCommand.AddCommand(build);
|
||||
return rootCommand.InvokeAsync(args).Result;
|
||||
}
|
||||
|
||||
private static void Build(string? binDir, string? mainBin, string? packageFile, string? postInstall,
|
||||
string? postRemove, bool noLogo, bool noShortcuts, bool noWine)
|
||||
private static void Build(string binDir, string mainBin, string packageFile, string postInstall,
|
||||
string postRemove, bool noLogo, bool noShortcuts, bool noWine)
|
||||
{
|
||||
Stopwatch watch = Stopwatch.StartNew();
|
||||
if (!noLogo)
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace UpTool_build_tool
|
||||
@ -18,7 +17,7 @@ namespace UpTool_build_tool
|
||||
{
|
||||
installSh += $@"
|
||||
echo ""[Desktop Entry]"" > {lnkName}
|
||||
echo ""Exec={(wine ? "wine " : "")}{Path.GetFileName(mainBin)}"" >> {lnkName}
|
||||
echo ""Exec={(wine ? "wine " : "")}{mainBin}"" >> {lnkName}
|
||||
echo ""Icon=application/x-shellscript"" >> {lnkName}
|
||||
echo ""Name={upRgx.Replace(programName, "")}"" >> {lnkName}
|
||||
echo ""StartupNotify=false"" >> {lnkName}
|
||||
@ -30,7 +29,7 @@ echo ""Type=Application"" >> {lnkName}";
|
||||
if (!string.IsNullOrWhiteSpace(mainBin))
|
||||
{
|
||||
removeSh += "\r\n";
|
||||
removeSh += $@"pkill -f ""{Path.GetFileName(mainBin)}""";
|
||||
removeSh += $@"pkill -f ""{mainBin}""";
|
||||
}
|
||||
installSh += $"\r\n{postInstall}";
|
||||
removeSh += $"\r\n{postRemove}";
|
||||
|
@ -1,6 +1,6 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>UpTool_build_tool</RootNamespace>
|
||||
<AssemblyName>pkgtool</AssemblyName>
|
||||
@ -15,7 +15,7 @@
|
||||
<ApplicationIcon>..\UpTool2.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CC-Functions.Core" Version="1.1.7628.34181" />
|
||||
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.20574.7" />
|
||||
<PackageReference Include="CC-Functions.Misc" Version="1.1.7399.26972" />
|
||||
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.20158.1" />
|
||||
</ItemGroup>
|
||||
</Project>
|
43
UpTool2.sln
43
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}"
|
||||
@ -21,20 +21,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UpToolLib", "UpToolLib\UpTo
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UpToolCLI", "UpToolCLI\UpToolCLI.csproj", "{3EC369B9-D927-4A53-BE1A-7E7006081BCE}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "GUI", "GUI", "{EA919DFD-766B-423C-99DF-C99356592842}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CLI", "CLI", "{3CFAB991-C12A-4B51-BC91-6965133DAF53}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common", "Common", "{0E778462-504C-4183-A27E-44EEE7B8CCDD}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InstallerCLI", "InstallerCLI\InstallerCLI.csproj", "{493B2CC5-29E9-4F10-A2F5-E10B9584D667}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UpToolEto", "UpToolEto\UpToolEto\UpToolEto.csproj", "{213FF69B-426E-475F-8A77-0A20EA4257C2}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UpToolEto.Gtk", "UpToolEto\UpToolEto.Gtk\UpToolEto.Gtk.csproj", "{8A544AEA-3081-45C9-BED2-7E424EB287B1}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UpToolEto.Wpf", "UpToolEto\UpToolEto.Wpf\UpToolEto.Wpf.csproj", "{C89EC79F-CC2B-4B8E-B4CB-D4DFD30A58AB}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -61,22 +47,6 @@ Global
|
||||
{3EC369B9-D927-4A53-BE1A-7E7006081BCE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{3EC369B9-D927-4A53-BE1A-7E7006081BCE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{3EC369B9-D927-4A53-BE1A-7E7006081BCE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{493B2CC5-29E9-4F10-A2F5-E10B9584D667}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{493B2CC5-29E9-4F10-A2F5-E10B9584D667}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{493B2CC5-29E9-4F10-A2F5-E10B9584D667}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{493B2CC5-29E9-4F10-A2F5-E10B9584D667}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{213FF69B-426E-475F-8A77-0A20EA4257C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{213FF69B-426E-475F-8A77-0A20EA4257C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{213FF69B-426E-475F-8A77-0A20EA4257C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{213FF69B-426E-475F-8A77-0A20EA4257C2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{8A544AEA-3081-45C9-BED2-7E424EB287B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{8A544AEA-3081-45C9-BED2-7E424EB287B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8A544AEA-3081-45C9-BED2-7E424EB287B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{8A544AEA-3081-45C9-BED2-7E424EB287B1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C89EC79F-CC2B-4B8E-B4CB-D4DFD30A58AB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C89EC79F-CC2B-4B8E-B4CB-D4DFD30A58AB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C89EC79F-CC2B-4B8E-B4CB-D4DFD30A58AB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C89EC79F-CC2B-4B8E-B4CB-D4DFD30A58AB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@ -84,15 +54,4 @@ Global
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {008127DC-F473-4709-A763-75F5FCED93AB}
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{FACD621F-6C6D-4D4B-B322-4364A0F9B4C2} = {0E778462-504C-4183-A27E-44EEE7B8CCDD}
|
||||
{AAB8D6BA-3A43-4DC4-95EE-6757482B77FD} = {0E778462-504C-4183-A27E-44EEE7B8CCDD}
|
||||
{C0C1E002-9E13-4E8F-A035-DBDC5128E00E} = {EA919DFD-766B-423C-99DF-C99356592842}
|
||||
{3EC369B9-D927-4A53-BE1A-7E7006081BCE} = {3CFAB991-C12A-4B51-BC91-6965133DAF53}
|
||||
{1D273392-3796-4BE9-A67F-BB402315D52D} = {EA919DFD-766B-423C-99DF-C99356592842}
|
||||
{493B2CC5-29E9-4F10-A2F5-E10B9584D667} = {3CFAB991-C12A-4B51-BC91-6965133DAF53}
|
||||
{213FF69B-426E-475F-8A77-0A20EA4257C2} = {EA919DFD-766B-423C-99DF-C99356592842}
|
||||
{8A544AEA-3081-45C9-BED2-7E424EB287B1} = {EA919DFD-766B-423C-99DF-C99356592842}
|
||||
{C89EC79F-CC2B-4B8E-B4CB-D4DFD30A58AB} = {EA919DFD-766B-423C-99DF-C99356592842}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
@ -1,37 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
using UpToolLib;
|
||||
using UpToolLib.DataStructures;
|
||||
using UpToolLib.Tool;
|
||||
using UpTool2.Task;
|
||||
using System.Collections.Generic;
|
||||
|
||||
#if DEBUG
|
||||
using System.Threading;
|
||||
using System.Diagnostics;
|
||||
using UpToolLib.v1.Tool;
|
||||
using UpToolLib.v2;
|
||||
using UpToolLib.v2.TaskQueue;
|
||||
#endif
|
||||
|
||||
namespace UpTool2
|
||||
{
|
||||
public sealed partial class MainForm : Form
|
||||
{
|
||||
private readonly HelpEventHandler _help;
|
||||
private List<AppTask> _tasks;
|
||||
private List<IAppTask> _tasks;
|
||||
|
||||
public MainForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
_tasks = new List<AppTask>();
|
||||
_tasks = new List<IAppTask>();
|
||||
_help = MainForm_HelpRequested;
|
||||
HelpRequested += _help;
|
||||
filterBox.DataSource = Enum.GetValues(typeof(Status));
|
||||
if (Program.Online)
|
||||
{
|
||||
Program.SetSplash(8, "Fetching repositories");
|
||||
Program.Lib.V2.RepoManagement.FetchRepos();
|
||||
}
|
||||
RepoManagement.FetchRepos();
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Starting in offline mode!");
|
||||
@ -39,10 +38,10 @@ namespace UpTool2
|
||||
filterBox.Enabled = false;
|
||||
filterBox.SelectedIndex = 2;
|
||||
}
|
||||
Program.SetSplash(9, "Reloading data");
|
||||
Program.SetSplash(8, "Reloading data");
|
||||
ReloadElements();
|
||||
if (!Directory.Exists(Program.Lib.V1.PathTool.AppsPath))
|
||||
Directory.CreateDirectory(Program.Lib.V1.PathTool.AppsPath);
|
||||
if (!Directory.Exists(PathTool.AppsPath))
|
||||
Directory.CreateDirectory(PathTool.AppsPath);
|
||||
}
|
||||
|
||||
private void Action_install_Click(object sender, EventArgs e)
|
||||
@ -55,7 +54,7 @@ namespace UpTool2
|
||||
}
|
||||
else
|
||||
{
|
||||
_tasks.Add(Program.Lib.V2.TaskFactory.CreateInstall(tmp, ReloadElements));
|
||||
_tasks.Add(new InstallTask(tmp, ReloadElements));
|
||||
action_install.BackColor = Color.Green;
|
||||
}
|
||||
UpdateChangesLabel();
|
||||
@ -71,7 +70,7 @@ namespace UpTool2
|
||||
}
|
||||
else
|
||||
{
|
||||
_tasks.Add(Program.Lib.V2.TaskFactory.CreateRemove(tmp, ReloadElements));
|
||||
_tasks.Add(new RemoveTask(tmp, ReloadElements));
|
||||
action_remove.BackColor = Color.Green;
|
||||
}
|
||||
UpdateChangesLabel();
|
||||
@ -82,7 +81,7 @@ namespace UpTool2
|
||||
if (searchPackageDialog.ShowDialog() != DialogResult.OK)
|
||||
return;
|
||||
if (!_tasks.Any(s => s is UploadTask t && t.ZipFile == searchPackageDialog.FileName))
|
||||
_tasks.Add(Program.Lib.V2.TaskFactory.CreateUpload(searchPackageDialog.FileName, AppNameDialog.Show(), ReloadElements));
|
||||
_tasks.Add(new UploadTask(searchPackageDialog.FileName, AppNameDialog.Show(), ReloadElements));
|
||||
UpdateChangesLabel();
|
||||
}
|
||||
|
||||
@ -96,7 +95,7 @@ namespace UpTool2
|
||||
}
|
||||
else
|
||||
{
|
||||
_tasks.Add(Program.Lib.V2.TaskFactory.CreateUpdate(tmp, ReloadElements));
|
||||
_tasks.Add(new UpdateTask(tmp, ReloadElements));
|
||||
action_update.BackColor = Color.Green;
|
||||
}
|
||||
UpdateChangesLabel();
|
||||
@ -111,7 +110,7 @@ namespace UpTool2
|
||||
infoPanel_Description.Invalidate();
|
||||
int f = sidebarPanel.Controls.Count;
|
||||
for (int i = 0; i < f; i++) sidebarPanel.Controls[0].Dispose();
|
||||
Program.Lib.V1.Apps.Clear();
|
||||
GlobalVariables.Apps.Clear();
|
||||
//add
|
||||
toolTip.SetToolTip(controls_settings, "Settings");
|
||||
toolTip.SetToolTip(controls_reload, "Refresh repositories");
|
||||
@ -121,9 +120,9 @@ namespace UpTool2
|
||||
toolTip.SetToolTip(action_remove, "Remove");
|
||||
toolTip.SetToolTip(action_update, "Update");
|
||||
toolTip.SetToolTip(action_run, "Run");
|
||||
Program.Lib.V2.RepoManagement.GetReposFromDisk();
|
||||
RepoManagement.GetReposFromDisk();
|
||||
int availableUpdates = 0;
|
||||
foreach (App app in Program.Lib.V1.Apps.Values)
|
||||
foreach (App app in GlobalVariables.Apps.Values)
|
||||
{
|
||||
Panel sidebarIcon = new Panel
|
||||
{
|
||||
@ -133,13 +132,7 @@ namespace UpTool2
|
||||
BackgroundImage = (Bitmap) app.Icon,
|
||||
BackgroundImageLayout = ImageLayout.Stretch
|
||||
};
|
||||
sidebarIcon.Paint += (sender, args) =>
|
||||
{
|
||||
args.Graphics.Clear(sidebarIcon.BackColor);
|
||||
args.Graphics.DrawImage(sidebarIcon.BackgroundImage, args.ClipRectangle,
|
||||
new Rectangle(new Point(0, 0), sidebarIcon.BackgroundImage.Size), GraphicsUnit.Pixel);
|
||||
};
|
||||
bool updateable = !app.Local && app.Status.Contains(Status.Updatable);
|
||||
bool updateable = !app.Local && (app.Status & Status.Updatable) == Status.Updatable;
|
||||
sidebarIcon.Click += (sender, e) =>
|
||||
{
|
||||
infoPanel_Title.Text = app.Name;
|
||||
@ -164,7 +157,7 @@ namespace UpTool2
|
||||
else
|
||||
action_update.ResetBackColor();
|
||||
action_run.Tag = app;
|
||||
action_run.Enabled = app.Status.Contains(Status.Installed) && !app.Local &&
|
||||
action_run.Enabled = (app.Status & Status.Installed) == Status.Installed && !app.Local &&
|
||||
app.Runnable && Directory.Exists(app.AppPath);
|
||||
};
|
||||
if (updateable)
|
||||
@ -181,7 +174,7 @@ namespace UpTool2
|
||||
{
|
||||
try
|
||||
{
|
||||
Program.Lib.V1.AppExtras.RunApp((App) action_run.Tag);
|
||||
AppExtras.RunApp((App) action_run.Tag);
|
||||
}
|
||||
catch (Exception e1)
|
||||
{
|
||||
@ -191,19 +184,8 @@ namespace UpTool2
|
||||
|
||||
private void Controls_reload_Click(object sender, EventArgs e)
|
||||
{
|
||||
Enabled = false;
|
||||
if (MessageBox.Show("This may take a few minutes. Are you sure?", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
|
||||
{
|
||||
new Thread(() =>
|
||||
{
|
||||
Program.Lib.V2.RepoManagement.FetchRepos();
|
||||
Invoke((Action) (() =>
|
||||
{
|
||||
RepoManagement.FetchRepos();
|
||||
ReloadElements();
|
||||
Enabled = true;
|
||||
}));
|
||||
}).Start();
|
||||
}
|
||||
}
|
||||
|
||||
private void Controls_settings_Click(object sender, EventArgs e) => new SettingsForms().ShowDialog();
|
||||
@ -211,29 +193,24 @@ namespace UpTool2
|
||||
private void ClearSelection()
|
||||
{
|
||||
action_install.Enabled = false;
|
||||
action_install.ResetBackColor();
|
||||
action_remove.Enabled = false;
|
||||
action_remove.ResetBackColor();
|
||||
action_update.Enabled = false;
|
||||
action_update.ResetBackColor();
|
||||
action_run.Enabled = false;
|
||||
action_run.ResetBackColor();
|
||||
infoPanel_Title.Text = "";
|
||||
infoPanel_Description.Text = "";
|
||||
}
|
||||
|
||||
private void UpdateSidebarV(object sender, EventArgs e)
|
||||
{
|
||||
#if DEBUG
|
||||
if (searchBox.Text == "!DEBUG:PRINT!")
|
||||
{
|
||||
searchBox.Text = "!DEBUG:PRINT";
|
||||
string tmpFile = Path.GetTempFileName();
|
||||
File.WriteAllText(tmpFile,
|
||||
string.Join("\r\n\r\n",
|
||||
Program.Lib.V1.Apps.Values.Select(app => app.ToString()).Concat(new[]
|
||||
{
|
||||
$"Assembly version: {Assembly.GetExecutingAssembly().GetName().Version}"
|
||||
}).ToArray()));
|
||||
GlobalVariables.Apps.Values.Select(app => app.ToString()).Concat(new[]
|
||||
{"Assembly version: " + Assembly.GetExecutingAssembly().GetName().Version}).ToArray()));
|
||||
new Thread(() =>
|
||||
{
|
||||
Process.Start("notepad", tmpFile).WaitForExit();
|
||||
@ -242,16 +219,20 @@ namespace UpTool2
|
||||
}
|
||||
else
|
||||
{
|
||||
App[] apps = Program.Lib.V1.AppExtras.FindApps(searchBox.Text);
|
||||
#endif
|
||||
App[] apps = AppExtras.FindApps(searchBox.Text);
|
||||
Enum.TryParse(filterBox.SelectedValue.ToString(), out Status status);
|
||||
for (int i = 0; i < sidebarPanel.Controls.Count; i++)
|
||||
{
|
||||
Panel sidebarIcon = (Panel) sidebarPanel.Controls[i];
|
||||
App app = (App) sidebarIcon.Tag;
|
||||
sidebarIcon.Visible = apps.Contains(app) && app.Status.Contains(Program.Online ? status : Status.Installed);
|
||||
sidebarIcon.Visible = apps.Contains(app) &&
|
||||
((int) app.Status & (int) (Program.Online ? status : Status.Installed)) != 0;
|
||||
}
|
||||
ClearSelection();
|
||||
#if DEBUG
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private void MainForm_Load(object sender, EventArgs e)
|
||||
@ -311,11 +292,10 @@ Build Date: {buildTime:dd.MM.yyyy}", "UpTool2");
|
||||
|
||||
private void changesButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (TaskPreview.Show(ref _tasks, true))
|
||||
{
|
||||
TaskPreview.Show(ref _tasks);
|
||||
progressBar1.Maximum = _tasks.Count;
|
||||
progressBar1.Value = 0;
|
||||
foreach (AppTask task in _tasks)
|
||||
foreach (IAppTask task in _tasks)
|
||||
{
|
||||
task.Run();
|
||||
progressBar1.PerformStep();
|
||||
@ -323,11 +303,10 @@ Build Date: {buildTime:dd.MM.yyyy}", "UpTool2");
|
||||
_tasks.Clear();
|
||||
UpdateChangesLabel();
|
||||
}
|
||||
}
|
||||
|
||||
private void changesLabel_Click(object sender, EventArgs e)
|
||||
{
|
||||
TaskPreview.Show(ref _tasks, false);
|
||||
TaskPreview.Show(ref _tasks);
|
||||
UpdateChangesLabel();
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
@ -9,29 +9,28 @@ using System.Windows.Forms;
|
||||
using System.Xml;
|
||||
using UpTool2.Tool;
|
||||
using UpToolLib;
|
||||
using UpToolLib.v1.Tool;
|
||||
using UpToolLib.v2;
|
||||
using UpToolLib.Tool;
|
||||
|
||||
namespace UpTool2
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
public static Form? Splash;
|
||||
public static Form Splash;
|
||||
private static int _splashProgress;
|
||||
private static string? _splashMessage;
|
||||
private static string _splashMessage;
|
||||
public static bool Online;
|
||||
public static UpToolLibMain Lib;
|
||||
|
||||
[STAThread]
|
||||
private static void Main(string[] args)
|
||||
private static void Main()
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
BuildSplash();
|
||||
Splash.Show();
|
||||
//new Thread(() => { Splash.ShowDialog(); }).Start();
|
||||
try
|
||||
{
|
||||
Lib = new UpToolLibMain(new UtLibFunctions());
|
||||
MutexLock.Lock();
|
||||
}
|
||||
catch (MutexLockLockedException)
|
||||
{
|
||||
@ -45,22 +44,27 @@ namespace UpTool2
|
||||
try
|
||||
{
|
||||
#endif
|
||||
ExternalFunctionalityManager.Init(new UtLibFunctions());
|
||||
SetSplash(1, "Initializing paths");
|
||||
if (!Directory.Exists(Lib.V1.PathTool.Dir))
|
||||
Directory.CreateDirectory(Lib.V1.PathTool.Dir);
|
||||
if (!Directory.Exists(PathTool.Dir))
|
||||
Directory.CreateDirectory(PathTool.Dir);
|
||||
FixXml();
|
||||
SetSplash(2, "Performing checks");
|
||||
try
|
||||
{
|
||||
Lib.V2.UpdateChecker.Check();
|
||||
UpToolLib.UpdateCheck.Reload();
|
||||
Online = true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
Online = false;
|
||||
}
|
||||
if (!Directory.Exists(Lib.V1.PathTool.GetRelative("Apps")))
|
||||
Directory.CreateDirectory(Lib.V1.PathTool.GetRelative("Apps"));
|
||||
if (Application.ExecutablePath != PathTool.GetRelative("Install", "UpTool2.dll"))
|
||||
Splash.Invoke((Action) (() => MessageBox.Show(Splash,
|
||||
$"WARNING!{Environment.NewLine}Running from outside the install directory is not recommended!")
|
||||
));
|
||||
if (!Directory.Exists(PathTool.GetRelative("Apps")))
|
||||
Directory.CreateDirectory(PathTool.GetRelative("Apps"));
|
||||
if (!Online)
|
||||
SetSplash(7, "Opening");
|
||||
if (!Online || UpdateCheck())
|
||||
@ -81,7 +85,7 @@ namespace UpTool2
|
||||
}
|
||||
finally
|
||||
{
|
||||
Lib.Dispose();
|
||||
MutexLock.Unlock();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -141,15 +145,30 @@ namespace UpTool2
|
||||
g.DrawString(_splashMessage, smallFont, Brushes.White, bar,
|
||||
new StringFormat {Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Center});
|
||||
};
|
||||
int xOff = 0;
|
||||
int yOff = 0;
|
||||
bool moving = false;
|
||||
Splash.MouseDown += (sender, e) =>
|
||||
{
|
||||
moving = true;
|
||||
xOff = e.X;
|
||||
yOff = e.Y;
|
||||
};
|
||||
Splash.MouseUp += (sender, e) => moving = false;
|
||||
Splash.MouseMove += (sender, e) =>
|
||||
{
|
||||
if (!moving) return;
|
||||
Splash.Left = Cursor.Position.X - xOff;
|
||||
Splash.Top = Cursor.Position.Y - yOff;
|
||||
};
|
||||
Splash.Load += (sender, e) => Splash.BringToFront();
|
||||
Splash.FormClosed += (sender, e) => Splash.Dispose();
|
||||
}
|
||||
|
||||
public static void SetSplash(int progress, string status) => Splash.Invoke(new Action(() =>
|
||||
{
|
||||
Console.WriteLine($"{progress} - {status}");
|
||||
Debug.WriteLine($"{progress} - {status}");
|
||||
_splashProgress = progress;
|
||||
Console.WriteLine(status);
|
||||
_splashMessage = status;
|
||||
Splash.Invoke((Action) Splash.Invalidate);
|
||||
}));
|
||||
@ -158,29 +177,25 @@ namespace UpTool2
|
||||
{
|
||||
try
|
||||
{
|
||||
Lib.V1.XmlTool.FixXml();
|
||||
XmlTool.FixXml();
|
||||
}
|
||||
catch (XmlException)
|
||||
{
|
||||
if (throwOnError) throw;
|
||||
MessageBox.Show("Something went wrong while trying to parse XML. Retrying...");
|
||||
File.Delete(Lib.V1.PathTool.InfoXml);
|
||||
File.Delete(PathTool.InfoXml);
|
||||
FixXml();
|
||||
}
|
||||
}
|
||||
|
||||
private static bool UpdateCheck()
|
||||
{
|
||||
UpdateCheck check = Lib.V2.UpdateChecker.Check();
|
||||
SetSplash(3, "Comparing online version");
|
||||
if (Assembly.GetExecutingAssembly().GetName().Version >= check.OnlineVersion)
|
||||
{
|
||||
SetSplash(7, "Opening");
|
||||
if (Assembly.GetExecutingAssembly().GetName().Version >= UpToolLib.UpdateCheck.OnlineVersion)
|
||||
return true;
|
||||
}
|
||||
byte[] dl;
|
||||
SetSplash(4, "Downloading latest");
|
||||
using (DownloadDialog dlg = new DownloadDialog(check.Installer.AbsoluteUri))
|
||||
using (DownloadDialog dlg = new DownloadDialog(UpToolLib.UpdateCheck.Installer.AbsoluteUri))
|
||||
{
|
||||
if (dlg.ShowDialog() != DialogResult.OK)
|
||||
throw new Exception("Failed to update");
|
||||
@ -190,29 +205,28 @@ namespace UpTool2
|
||||
using (SHA256CryptoServiceProvider sha256 = new SHA256CryptoServiceProvider())
|
||||
{
|
||||
string pkgHash = BitConverter.ToString(sha256.ComputeHash(dl)).Replace("-", string.Empty).ToUpper();
|
||||
if (pkgHash != check.InstallerHash)
|
||||
if (pkgHash != UpToolLib.UpdateCheck.InstallerHash)
|
||||
throw new Exception(
|
||||
$"The hash is not equal to the one stored in the repo:\r\nPackage: {pkgHash}\r\nOnline: {check.InstallerHash}");
|
||||
$"The hash is not equal to the one stored in the repo:\r\nPackage: {pkgHash}\r\nOnline: {UpToolLib.UpdateCheck.InstallerHash}");
|
||||
}
|
||||
SetSplash(9, "Installing");
|
||||
if (Directory.Exists(Lib.V1.PathTool.GetRelative("Install", "tmp")))
|
||||
Directory.Delete(Lib.V1.PathTool.GetRelative("Install", "tmp"), true);
|
||||
Directory.CreateDirectory(Lib.V1.PathTool.GetRelative("Install", "tmp"));
|
||||
if (Directory.Exists(PathTool.GetRelative("Install", "tmp")))
|
||||
Directory.Delete(PathTool.GetRelative("Install", "tmp"), true);
|
||||
Directory.CreateDirectory(PathTool.GetRelative("Install", "tmp"));
|
||||
using (MemoryStream ms = new MemoryStream(dl))
|
||||
{
|
||||
using ZipArchive ar = new ZipArchive(ms);
|
||||
ar.ExtractToDirectory(Lib.V1.PathTool.GetRelative("Install", "tmp"), true);
|
||||
ar.ExtractToDirectory(PathTool.GetRelative("Install", "tmp"), true);
|
||||
}
|
||||
Splash.Hide();
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = Lib.V1.PathTool.GetRelative("Install", "tmp", "Installer.exe"),
|
||||
Arguments = "i -p",
|
||||
FileName = PathTool.GetRelative("Install", "tmp", "Installer.exe"),
|
||||
Arguments = "-i",
|
||||
CreateNoWindow = true,
|
||||
WindowStyle = ProcessWindowStyle.Hidden,
|
||||
WorkingDirectory = Lib.V1.PathTool.GetRelative("Install")
|
||||
WorkingDirectory = PathTool.GetRelative("Install")
|
||||
});
|
||||
SetSplash(7, "Installing");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
12
UpTool2/SourcesForm.Designer.cs
generated
12
UpTool2/SourcesForm.Designer.cs
generated
@ -21,16 +21,20 @@
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(UpTool2.SettingsForms));
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SettingsForms));
|
||||
this.sourceGrid = new System.Windows.Forms.DataGridView();
|
||||
((System.ComponentModel.ISupportInitialize)(this.sourceGrid)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// sourceGrid
|
||||
//
|
||||
this.sourceGrid.BackgroundColor = System.Drawing.Color.White;
|
||||
this.sourceGrid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.sourceGrid.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
@ -40,6 +44,9 @@
|
||||
this.sourceGrid.Name = "sourceGrid";
|
||||
this.sourceGrid.Size = new System.Drawing.Size(933, 519);
|
||||
this.sourceGrid.TabIndex = 0;
|
||||
//
|
||||
// SettingsForms
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(933, 519);
|
||||
@ -53,11 +60,12 @@
|
||||
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.SettingsForms_FormClosing);
|
||||
((System.ComponentModel.ISupportInitialize)(this.sourceGrid)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
private System.Windows.Forms.DataGridView sourceGrid;
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.DataGridView sourceGrid;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn sbName;
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn sbLink;
|
||||
}
|
||||
|
@ -1,27 +1,32 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Forms;
|
||||
using UpToolLib.DataStructures;
|
||||
using System.Windows.Forms;
|
||||
using System.Xml.Linq;
|
||||
using UpToolLib.Tool;
|
||||
|
||||
namespace UpTool2
|
||||
{
|
||||
public partial class SettingsForms : Form
|
||||
{
|
||||
private readonly List<Repo> _repos = new List<Repo>();
|
||||
private readonly XDocument _doc;
|
||||
private readonly XElement _repos;
|
||||
|
||||
public SettingsForms()
|
||||
{
|
||||
InitializeComponent();
|
||||
Program.FixXml();
|
||||
_repos.AddRange(Program.Lib.V2.RepoManagement.GetRepos());
|
||||
sourceGrid.Columns.Clear();
|
||||
sourceGrid.Columns.Add("name", "Name");
|
||||
sourceGrid.Columns.Add("link", "Link");
|
||||
foreach (Repo repo in _repos)
|
||||
sourceGrid.Rows.Add(repo.Name, repo.Url);
|
||||
_doc = XDocument.Load(PathTool.InfoXml);
|
||||
_repos = _doc.Element("meta").Element("Repos");
|
||||
foreach (XElement repo in _repos.Elements("Repo"))
|
||||
sourceGrid.Rows.Add(repo.Element("Name").Value, repo.Element("Link").Value);
|
||||
}
|
||||
|
||||
private void SettingsForms_FormClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
Program.Lib.V2.RepoManagement.Save(_repos);
|
||||
_repos.RemoveNodes();
|
||||
for (int y = 0; y < sourceGrid.Rows.Count; y++)
|
||||
if (y + 1 < sourceGrid.Rows.Count)
|
||||
_repos.Add(new XElement("Repo", new XElement("Name", (string) sourceGrid.Rows[y].Cells[0].Value),
|
||||
new XElement("Link", (string) sourceGrid.Rows[y].Cells[1].Value)));
|
||||
_doc.Save(PathTool.InfoXml);
|
||||
}
|
||||
}
|
||||
}
|
11
UpTool2/Task/IAppTask.cs
Normal file
11
UpTool2/Task/IAppTask.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace UpTool2.Task
|
||||
{
|
||||
interface IAppTask
|
||||
{
|
||||
public void Run();
|
||||
}
|
||||
}
|
@ -1,10 +1,14 @@
|
||||
using UpToolLib.DataStructures;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using UpToolLib.DataStructures;
|
||||
|
||||
namespace UpToolLib.v2.TaskQueue
|
||||
namespace UpTool2.Task
|
||||
{
|
||||
public abstract class KnownAppTask : AppTask
|
||||
abstract class IKnownAppTask : IAppTask
|
||||
{
|
||||
public abstract App App { get; }
|
||||
public abstract void Run();
|
||||
|
||||
public override string ToString() => $"{TrimEnd(GetType().Name, "Task")} {App.Name}";
|
||||
|
||||
@ -13,13 +17,12 @@ namespace UpToolLib.v2.TaskQueue
|
||||
if (string.IsNullOrEmpty(trimString)) return target;
|
||||
|
||||
string result = target;
|
||||
while (result.EndsWith(trimString)) result = result.Substring(0, result.Length - trimString.Length);
|
||||
while (result.EndsWith(trimString))
|
||||
{
|
||||
result = result.Substring(0, result.Length - trimString.Length);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected KnownAppTask(IExternalFunctionality platform) : base(platform)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -1,23 +1,20 @@
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
using UpToolLib.DataStructures;
|
||||
using UpToolLib.v1.Tool;
|
||||
using UpToolLib.Tool;
|
||||
|
||||
namespace UpToolLib.v2.TaskQueue
|
||||
namespace UpTool2.Task
|
||||
{
|
||||
public class InstallTask : KnownAppTask
|
||||
class InstallTask : IKnownAppTask
|
||||
{
|
||||
private readonly AppInstall _installer;
|
||||
public override App App { get; }
|
||||
private readonly Action? _postInstall;
|
||||
|
||||
internal InstallTask(IExternalFunctionality platform, AppInstall installer, App app, Action? postInstall) : base(platform)
|
||||
public InstallTask(App app, Action? postInstall = null)
|
||||
{
|
||||
App = app;
|
||||
_installer = installer;
|
||||
_postInstall = postInstall;
|
||||
}
|
||||
|
||||
public override App App { get; }
|
||||
|
||||
public override void Run()
|
||||
{
|
||||
bool trying = true;
|
||||
@ -27,14 +24,15 @@ namespace UpToolLib.v2.TaskQueue
|
||||
try
|
||||
{
|
||||
#endif
|
||||
_installer.Install(App, true);
|
||||
AppInstall.Install(App, true);
|
||||
_postInstall?.Invoke();
|
||||
trying = false;
|
||||
#if !DEBUG
|
||||
}
|
||||
catch (Exception e1)
|
||||
{
|
||||
trying = Platform.YesNoDialog("Install failed. Retry?\r\nException=" + e1, true);
|
||||
trying = MessageBox.Show(e1.ToString(), "Install failed", MessageBoxButtons.RetryCancel) ==
|
||||
DialogResult.Retry;
|
||||
}
|
||||
#endif
|
||||
}
|
@ -1,36 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using UpToolLib.DataStructures;
|
||||
using UpToolLib.v1.Tool;
|
||||
using UpToolLib.Tool;
|
||||
|
||||
namespace UpToolLib.v2.TaskQueue
|
||||
namespace UpTool2.Task
|
||||
{
|
||||
public class RemoveTask : KnownAppTask
|
||||
class RemoveTask : IKnownAppTask
|
||||
{
|
||||
private readonly AppExtras _extras;
|
||||
public override App App { get; }
|
||||
private readonly Action? _postInstall;
|
||||
|
||||
internal RemoveTask(IExternalFunctionality platform, AppExtras extras, App app, Action? postInstall) : base(platform)
|
||||
public RemoveTask(App app, Action? postInstall = null)
|
||||
{
|
||||
App = app;
|
||||
_extras = extras;
|
||||
_postInstall = postInstall;
|
||||
}
|
||||
|
||||
public override App App { get; }
|
||||
|
||||
public override void Run()
|
||||
{
|
||||
#if !DEBUG
|
||||
try
|
||||
{
|
||||
#endif
|
||||
_extras.Remove(App, true);
|
||||
AppExtras.Remove(App, true);
|
||||
_postInstall?.Invoke();
|
||||
#if !DEBUG
|
||||
}
|
||||
catch (Exception e1)
|
||||
{
|
||||
Platform.OkDialog("Removal failed.\r\nException=" + e1);
|
||||
MessageBox.Show(e1.ToString(), "Removal failed");
|
||||
}
|
||||
#endif
|
||||
}
|
@ -1,36 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using UpToolLib.DataStructures;
|
||||
using UpToolLib.v1.Tool;
|
||||
using UpToolLib.Tool;
|
||||
|
||||
namespace UpToolLib.v2.TaskQueue
|
||||
namespace UpTool2.Task
|
||||
{
|
||||
public class UpdateTask : KnownAppTask
|
||||
class UpdateTask : IKnownAppTask
|
||||
{
|
||||
private readonly AppExtras _extras;
|
||||
public override App App { get; }
|
||||
private readonly Action? _postInstall;
|
||||
|
||||
internal UpdateTask(IExternalFunctionality platform, AppExtras extras, App app, Action? postInstall) : base(platform)
|
||||
public UpdateTask(App app, Action? postInstall = null)
|
||||
{
|
||||
App = app;
|
||||
_extras = extras;
|
||||
_postInstall = postInstall;
|
||||
}
|
||||
|
||||
public override App App { get; }
|
||||
|
||||
public override void Run()
|
||||
{
|
||||
#if !DEBUG
|
||||
try
|
||||
{
|
||||
#endif
|
||||
_extras.Update(App, false);
|
||||
AppExtras.Update(App, false);
|
||||
_postInstall?.Invoke();
|
||||
#if !DEBUG
|
||||
}
|
||||
catch (Exception e1)
|
||||
{
|
||||
Platform.OkDialog("Update failed.\r\nException=" + e1);
|
||||
MessageBox.Show(e1.ToString(), "Install failed");
|
||||
}
|
||||
#endif
|
||||
}
|
50
UpTool2/Task/UploadTask.cs
Normal file
50
UpTool2/Task/UploadTask.cs
Normal file
@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using UpTool2.Properties;
|
||||
using UpToolLib;
|
||||
using UpToolLib.DataStructures;
|
||||
using UpToolLib.Tool;
|
||||
|
||||
namespace UpTool2.Task
|
||||
{
|
||||
class UploadTask : IAppTask
|
||||
{
|
||||
public readonly string ZipFile;
|
||||
private readonly string _name;
|
||||
private readonly Action? _postInstall;
|
||||
public UploadTask(string zipFile, string name, Action? postInstall = null)
|
||||
{
|
||||
ZipFile = zipFile;
|
||||
_name = name;
|
||||
_postInstall = postInstall;
|
||||
}
|
||||
|
||||
public void Run()
|
||||
{
|
||||
#if !DEBUG
|
||||
try
|
||||
{
|
||||
#endif
|
||||
Guid id = Guid.NewGuid();
|
||||
while (GlobalVariables.Apps.ContainsKey(id) || Directory.Exists(PathTool.GetAppPath(id)))
|
||||
id = Guid.NewGuid();
|
||||
App appI = new App(_name, "Locally installed package, removal only",
|
||||
GlobalVariables.MinimumVer, "", true, "", id, Color.Red, Resources.C_64.ToBitmap(), false, "");
|
||||
AppInstall.InstallZip(ZipFile, appI, true);
|
||||
_postInstall?.Invoke();
|
||||
#if !DEBUG
|
||||
}
|
||||
catch (Exception e1)
|
||||
{
|
||||
MessageBox.Show(e1.ToString(), "Install failed");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public override string ToString() => $"Install local {Path.GetFileName(ZipFile)}";
|
||||
}
|
||||
}
|
@ -2,31 +2,22 @@
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using UpToolLib.v2.TaskQueue;
|
||||
using UpTool2.Task;
|
||||
|
||||
namespace UpTool2
|
||||
{
|
||||
internal static class TaskPreview
|
||||
{
|
||||
public static bool Show(ref List<AppTask> tasks, bool showOk)
|
||||
public static void Show(ref List<IAppTask> tasks)
|
||||
{
|
||||
bool ok = false;
|
||||
using Form tmp = new Form {Size = new Size(600, 300), MinimumSize = new Size(300, showOk ? 138 : 133)};
|
||||
using Form tmp = new Form {Size = new Size(600, 300)};
|
||||
using CheckedListBox list = new CheckedListBox {Dock = DockStyle.Fill};
|
||||
using Button okButton = new Button {Dock = DockStyle.Bottom, Text = "OK"};
|
||||
list.Items.AddRange(tasks.ToArray());
|
||||
for (int i = 0; i < tasks.Count; i++)
|
||||
list.SetItemChecked(i, true);
|
||||
tmp.Controls.Add(list);
|
||||
okButton.Click += (sender, args) =>
|
||||
{
|
||||
ok = true;
|
||||
tmp.Close();
|
||||
};
|
||||
if (showOk) tmp.Controls.Add(okButton);
|
||||
tmp.ShowDialog();
|
||||
tasks = list.Items.OfType<AppTask>().Where((s, i) => list.GetItemChecked(i)).ToList();
|
||||
return !showOk || ok;
|
||||
tasks = list.Items.OfType<IAppTask>().Where((s, i) => list.GetItemChecked(i)).ToList();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0-windows</TargetFramework>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<LangVersion>8</LangVersion>
|
||||
<Deterministic>false</Deterministic>
|
||||
@ -19,6 +19,9 @@
|
||||
<ItemGroup>
|
||||
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CC-Functions.Misc" Version="1.1.7399.26972" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\UpToolLib\UpToolLib.csproj" />
|
||||
</ItemGroup>
|
||||
|
@ -1,101 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.CommandLine;
|
||||
using System.CommandLine.Invocation;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UpToolLib;
|
||||
using UpToolLib.DataStructures;
|
||||
using UpToolLib.v1.Tool;
|
||||
using UpToolLib.v2;
|
||||
|
||||
namespace UpToolCLI
|
||||
{
|
||||
public static class CacheManagement
|
||||
{
|
||||
public static void RegisterCommands(RootCommand rootCommand)
|
||||
{
|
||||
rootCommand.AddCommand(new Command("list", "Lists installed packages")
|
||||
{
|
||||
Handler = CommandHandler.Create(List)
|
||||
});
|
||||
|
||||
Command search = new("search", "Search for packages")
|
||||
{
|
||||
new Argument<string>("identifier", "Something to identify the app")
|
||||
};
|
||||
search.Handler = CommandHandler.Create<string>(Search);
|
||||
rootCommand.AddCommand(search);
|
||||
|
||||
Command show = new("show", "Shows package info")
|
||||
{
|
||||
new Argument<string>("identifier", "Something to identify the app")
|
||||
};
|
||||
show.Handler = CommandHandler.Create<string>(Show);
|
||||
rootCommand.AddCommand(show);
|
||||
|
||||
rootCommand.AddCommand(new Command("update", "Updates the cache")
|
||||
{
|
||||
Handler = CommandHandler.Create(Update)
|
||||
});
|
||||
}
|
||||
|
||||
private static void List()
|
||||
{
|
||||
Program.Lib.V2.RepoManagement.GetReposFromDisk();
|
||||
Console.WriteLine(Program.Lib.V1.Apps.Where(s => s.Value.Status.Contains(Status.Installed))
|
||||
.ToStringTable(new[]
|
||||
{
|
||||
"Name", "State", "Guid"
|
||||
},
|
||||
u => u.Value.Name,
|
||||
u => u.Value.Local ? "Local" :
|
||||
u.Value.Status.Contains(Status.Updatable) ? "Updatable" : "None",
|
||||
u => u.Key));
|
||||
}
|
||||
|
||||
private static void Search(string identifier)
|
||||
{
|
||||
Program.Lib.V2.RepoManagement.GetReposFromDisk();
|
||||
App[] apps = Program.Lib.V1.AppExtras.FindApps(identifier);
|
||||
Console.WriteLine($"Found {apps.Length} app(s)");
|
||||
if (apps.Length > 0)
|
||||
Console.WriteLine(apps.ToStringTable(new[]
|
||||
{
|
||||
"Name", "Guid"
|
||||
},
|
||||
u => u.Name,
|
||||
u => u.Id));
|
||||
}
|
||||
|
||||
private static void Show(string identifier)
|
||||
{
|
||||
Program.Lib.V2.RepoManagement.GetReposFromDisk();
|
||||
App[] apps = Program.Lib.V1.AppExtras.FindApps(identifier);
|
||||
if (apps.Length == 0)
|
||||
Console.WriteLine("Package not found.");
|
||||
else
|
||||
Console.WriteLine(apps.First());
|
||||
}
|
||||
|
||||
private static void Update()
|
||||
{
|
||||
Console.WriteLine("Fetching Repos...");
|
||||
Program.Lib.V2.RepoManagement.FetchRepos();
|
||||
Program.Lib.V2.RepoManagement.GetReposFromDisk();
|
||||
Console.WriteLine();
|
||||
IEnumerable<App> tmp = Program.Lib.V1.Apps.Where(s =>
|
||||
s.Value.Status.Contains(Status.Updatable)).Select(s => s.Value);
|
||||
IEnumerable<App> apps = tmp as App[] ?? tmp.ToArray();
|
||||
int updatableCount = apps.Count();
|
||||
Console.WriteLine(updatableCount == 0
|
||||
? "All up-to-date"
|
||||
: $@"Found {updatableCount} Updates:
|
||||
{string.Join(Environment.NewLine, apps.Select(s => $"- {s.Name} ({s.Version})"))}");
|
||||
Version vLocal = Assembly.GetExecutingAssembly().GetName().Version;
|
||||
Version vOnline = Program.Lib.V2.UpdateChecker.Check().OnlineVersion;
|
||||
if (vLocal < vOnline)
|
||||
Console.WriteLine($"uptool is outdated ({vLocal} vs {vOnline}), update using \"uptool upgrade-self\"");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,104 +0,0 @@
|
||||
using System;
|
||||
using System.CommandLine;
|
||||
using System.CommandLine.Invocation;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Security.Cryptography;
|
||||
using UpToolLib;
|
||||
using UpToolLib.DataStructures;
|
||||
using UpToolLib.v1.Tool;
|
||||
using UpToolLib.v2;
|
||||
using Process = System.Diagnostics.Process;
|
||||
|
||||
namespace UpToolCLI
|
||||
{
|
||||
public class Other
|
||||
{
|
||||
public static void RegisterCommands(RootCommand rootCommand)
|
||||
{
|
||||
Command command = new("upgrade-self", "Upgrades UpToolCLI")
|
||||
{
|
||||
new Option<bool>(new[] {"--force", "-f"}, "Overwrites older files")
|
||||
};
|
||||
command.Handler = CommandHandler.Create<bool>(UpgradeSelf);
|
||||
rootCommand.AddCommand(command);
|
||||
|
||||
Command start = new("start", "Starts an app")
|
||||
{
|
||||
new Argument<string>("identifier", "Something to identify the app"),
|
||||
new Option<string>(new[] {"--arguments", "--args", "-a"}, () => "", "The arguments to run the file with"),
|
||||
new Option<string>(new[] {"--file", "-f"}, () => null, "The file to run instead of the MainFile"),
|
||||
new Option<bool>(new[] {"--waitForExit", "-wait"}, "Waits until the program quits")
|
||||
};
|
||||
start.Handler = CommandHandler.Create<string, string, string, bool>(Start);
|
||||
rootCommand.AddCommand(start);
|
||||
}
|
||||
|
||||
public static void UpgradeSelf(bool force)
|
||||
{
|
||||
PathTool pathTool = Program.Lib.V1.PathTool;
|
||||
UpdateCheck updateCheck = Program.Lib.V2.UpdateChecker.Check();
|
||||
if (!force && Assembly.GetExecutingAssembly().GetName().Version >= updateCheck.OnlineVersion)
|
||||
Console.WriteLine("Already up-to-date");
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Downloading latest");
|
||||
(bool success, byte[] dl) = Program.Functions.Download(updateCheck.Installer);
|
||||
if (!success)
|
||||
throw new Exception("Failed to update");
|
||||
Console.WriteLine("Verifying");
|
||||
using (SHA256CryptoServiceProvider sha256 = new())
|
||||
{
|
||||
string pkgHash = BitConverter.ToString(sha256.ComputeHash(dl)).Replace("-", string.Empty).ToUpper();
|
||||
if (pkgHash != updateCheck.InstallerHash)
|
||||
throw new Exception($@"The hash is not equal to the one stored in the repo:
|
||||
Package: {pkgHash}
|
||||
Online: {updateCheck.InstallerHash}");
|
||||
}
|
||||
Console.WriteLine("Installing");
|
||||
if (Directory.Exists(pathTool.GetRelative("Install", "tmp")))
|
||||
Directory.Delete(pathTool.GetRelative("Install", "tmp"), true);
|
||||
Directory.CreateDirectory(pathTool.GetRelative("Install", "tmp"));
|
||||
using (MemoryStream ms = new(dl))
|
||||
{
|
||||
using ZipArchive ar = new(ms);
|
||||
ar.ExtractToDirectory(pathTool.GetRelative("Install", "tmp"), true);
|
||||
}
|
||||
string file = pathTool.GetRelative("Install", "tmp", "Installer.exe");
|
||||
Console.WriteLine($"Starting {file}");
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = file,
|
||||
Arguments = "i",
|
||||
WorkingDirectory = pathTool.GetRelative("Install"),
|
||||
UseShellExecute = false
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static void Start(string identifier, string arguments, string file, bool waitForExit)
|
||||
{
|
||||
Program.Lib.V2.RepoManagement.GetReposFromDisk();
|
||||
App[] apps = Program.Lib.V1.AppExtras.FindApps(identifier);
|
||||
if (apps.Length == 0)
|
||||
Console.WriteLine("Package not found.");
|
||||
else
|
||||
{
|
||||
App tmp = apps.First();
|
||||
if (tmp.Runnable)
|
||||
{
|
||||
Console.WriteLine($"Starting {tmp.Name}");
|
||||
Process tmp1 = Program.Lib.V1.AppExtras.RunApp(tmp, file ?? tmp.MainFile, arguments);
|
||||
if (waitForExit)
|
||||
tmp1.WaitForExit();
|
||||
}
|
||||
else
|
||||
Console.WriteLine($"{tmp.Name} is not runnable");
|
||||
}
|
||||
Console.WriteLine("Done!");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,192 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.CommandLine;
|
||||
using System.CommandLine.Invocation;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UpToolLib;
|
||||
using UpToolLib.DataStructures;
|
||||
using UpToolLib.v1;
|
||||
using UpToolLib.v1.Tool;
|
||||
using UpToolLib.v2;
|
||||
|
||||
namespace UpToolCLI
|
||||
{
|
||||
public static class PackageManagement
|
||||
{
|
||||
public static void RegisterCommands(RootCommand rootCommand)
|
||||
{
|
||||
Command install = new("install", "Install a package")
|
||||
{
|
||||
new Argument<string>("identifier", "Something to identify the app or the file name"),
|
||||
new Option<bool>(new[] {"--force", "-f"}, "Overwrites older files")
|
||||
};
|
||||
install.Handler = CommandHandler.Create<string, bool>(Install);
|
||||
rootCommand.AddCommand(install);
|
||||
|
||||
Command upgrade = new("upgrade", "Upgrade a package")
|
||||
{
|
||||
new Argument<string>("identifier", "Something to identify the app"),
|
||||
new Option<bool>(new[] {"--force", "-f"}, "Overwrites older files")
|
||||
};
|
||||
upgrade.Handler = CommandHandler.Create<string, bool>(Upgrade);
|
||||
rootCommand.AddCommand(upgrade);
|
||||
|
||||
Command reinstall = new("reinstall", "Reinstall a package")
|
||||
{
|
||||
new Argument<string>("identifier", "Something to identify the app"),
|
||||
new Option<bool>(new[] {"--force", "-f"}, "Overwrites older files")
|
||||
};
|
||||
reinstall.Handler = CommandHandler.Create<string, bool>(Reinstall);
|
||||
rootCommand.AddCommand(reinstall);
|
||||
|
||||
Command remove = new("remove", "Remove a package")
|
||||
{
|
||||
new Argument<string>("identifier", "Something to identify the app")
|
||||
};
|
||||
remove.Handler = CommandHandler.Create<string>(Remove);
|
||||
rootCommand.AddCommand(remove);
|
||||
|
||||
Command purge = new("purge", "Completely remove a package")
|
||||
{
|
||||
new Argument<string>("identifier", "Something to identify the app")
|
||||
};
|
||||
purge.Handler = CommandHandler.Create<string>(Purge);
|
||||
rootCommand.AddCommand(purge);
|
||||
|
||||
rootCommand.AddCommand(new Command("dist-upgrade", "Upgrades all packages")
|
||||
{
|
||||
Handler = CommandHandler.Create(DistUpgrade)
|
||||
});
|
||||
}
|
||||
|
||||
private static void Install(string identifier, bool force)
|
||||
{
|
||||
Program.Lib.V2.RepoManagement.GetReposFromDisk();
|
||||
App[] apps = Program.Lib.V1.AppExtras.FindApps(identifier);
|
||||
if (apps.Length == 0)
|
||||
{
|
||||
if (File.Exists(identifier))
|
||||
{
|
||||
Console.WriteLine("Name:");
|
||||
string name = Console.ReadLine();
|
||||
Program.Lib.V1.Installer.InstallZip(identifier, Program.Lib.V2.AppFactory.CreateApp(name, "Locally installed package, removal only",
|
||||
UpToolLibV1.MinimumVer, "", true, "",
|
||||
Guid.NewGuid(), Color.Red, "", false, ""), force);
|
||||
Console.WriteLine($"Successfully installed \"{name}\"");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Package not found.");
|
||||
Console.WriteLine(identifier);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
App tmp = apps.First();
|
||||
if (tmp.Status.Contains(Status.Installed))
|
||||
Console.WriteLine("Package is already installed");
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"Installing {tmp.Name}");
|
||||
Program.Lib.V1.Installer.Install(tmp, true);
|
||||
}
|
||||
}
|
||||
Console.WriteLine("Done!");
|
||||
}
|
||||
|
||||
private static void Upgrade(string identifier, bool force)
|
||||
{
|
||||
Program.Lib.V2.RepoManagement.GetReposFromDisk();
|
||||
App[] apps = Program.Lib.V1.AppExtras.FindApps(identifier);
|
||||
if (apps.Length == 0)
|
||||
Console.WriteLine("Package not found.");
|
||||
else
|
||||
{
|
||||
App tmp = apps.First();
|
||||
if (tmp.Status.Contains(Status.Updatable))
|
||||
{
|
||||
Console.WriteLine($"Upgrading {tmp.Name}");
|
||||
Program.Lib.V1.AppExtras.Update(tmp, force);
|
||||
}
|
||||
else
|
||||
Console.WriteLine("Package is up-to-date");
|
||||
}
|
||||
Console.WriteLine("Done!");
|
||||
}
|
||||
|
||||
private static void Reinstall(string identifier, bool force)
|
||||
{
|
||||
Program.Lib.V2.RepoManagement.GetReposFromDisk();
|
||||
App[] apps = Program.Lib.V1.AppExtras.FindApps(identifier);
|
||||
if (apps.Length == 0)
|
||||
Console.WriteLine("Package not found.");
|
||||
else
|
||||
{
|
||||
App tmp = apps.First();
|
||||
Console.WriteLine($"Reinstalling {tmp.Name}");
|
||||
Program.Lib.V1.AppExtras.Update(tmp, force);
|
||||
}
|
||||
Console.WriteLine("Done!");
|
||||
}
|
||||
|
||||
private static void Remove(string identifier)
|
||||
{
|
||||
Program.Lib.V2.RepoManagement.GetReposFromDisk();
|
||||
App[] apps = Program.Lib.V1.AppExtras.FindApps(identifier);
|
||||
if (apps.Length == 0)
|
||||
Console.WriteLine("Package not found.");
|
||||
else
|
||||
{
|
||||
App tmp = apps.First();
|
||||
if (tmp.Status.Contains(Status.Installed))
|
||||
{
|
||||
Console.WriteLine($"Removing {tmp.Name}");
|
||||
Program.Lib.V1.AppExtras.Remove(tmp, false);
|
||||
}
|
||||
else
|
||||
Console.WriteLine("Package is not installed");
|
||||
}
|
||||
Console.WriteLine("Done!");
|
||||
}
|
||||
|
||||
private static void Purge(string identifier)
|
||||
{
|
||||
Program.Lib.V2.RepoManagement.GetReposFromDisk();
|
||||
App[] apps = Program.Lib.V1.AppExtras.FindApps(identifier);
|
||||
if (apps.Length == 0)
|
||||
Console.WriteLine("Package not found.");
|
||||
else
|
||||
{
|
||||
App tmp = apps.First();
|
||||
if (tmp.Status.Contains(Status.Installed))
|
||||
{
|
||||
Console.WriteLine($"Purging {tmp.Name}");
|
||||
Program.Lib.V1.AppExtras.Remove(tmp, true);
|
||||
}
|
||||
else
|
||||
Console.WriteLine("Package is not installed");
|
||||
}
|
||||
Console.WriteLine("Done!");
|
||||
}
|
||||
|
||||
private static void DistUpgrade()
|
||||
{
|
||||
Program.Lib.V2.RepoManagement.GetReposFromDisk();
|
||||
foreach (KeyValuePair<Guid, App> app in Program.Lib.V1.Apps.Where(s =>
|
||||
s.Value.Status.Contains(Status.Updatable)))
|
||||
{
|
||||
Console.WriteLine($"Updating {app.Value.Name}");
|
||||
Program.Lib.V1.AppExtras.Update(app.Value, false);
|
||||
}
|
||||
if (Assembly.GetExecutingAssembly().GetName().Version < Program.Lib.V2.UpdateChecker.Check().OnlineVersion)
|
||||
{
|
||||
Console.WriteLine("Updating self");
|
||||
Other.UpgradeSelf(false);
|
||||
}
|
||||
Console.WriteLine("Done!");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,41 +1,371 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.CommandLine;
|
||||
using System.CommandLine.Invocation;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Security.Cryptography;
|
||||
using UpToolLib;
|
||||
using UpToolLib.DataStructures;
|
||||
using UpToolLib.Tool;
|
||||
using Process = System.Diagnostics.Process;
|
||||
|
||||
namespace UpToolCLI
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
public static readonly UtLibFunctions Functions = new();
|
||||
public static bool Basic;
|
||||
public static UpToolLibMain Lib;
|
||||
private static readonly UtLibFunctions Functions = new UtLibFunctions();
|
||||
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
MutexLock.Lock();
|
||||
try
|
||||
{
|
||||
Basic = args.Length > 0 && args[0].ToLower() == "--basic";
|
||||
Lib = new UpToolLibMain(Functions);
|
||||
Lib.V1.XmlTool.FixXml();
|
||||
RootCommand rootCommand = new();
|
||||
rootCommand.AddGlobalOption(new Option<bool>("--basic", "Use only basic console functionality. Must be the first parameter in the call"));
|
||||
|
||||
PackageManagement.RegisterCommands(rootCommand);
|
||||
CacheManagement.RegisterCommands(rootCommand);
|
||||
ReposManagement.RegisterCommands(rootCommand);
|
||||
Other.RegisterCommands(rootCommand);
|
||||
|
||||
return rootCommand.InvokeAsync(args).Result;
|
||||
}
|
||||
catch (Exception e)
|
||||
XmlTool.FixXml();
|
||||
ExternalFunctionalityManager.Init(Functions);
|
||||
RootCommand rootCommand = new RootCommand();
|
||||
rootCommand.AddCommand(new Command("update", "Updates the cache")
|
||||
{
|
||||
Console.WriteLine($"FAILED: {e}");
|
||||
return 1;
|
||||
Handler = CommandHandler.Create(Update)
|
||||
});
|
||||
|
||||
Command install = new Command("install", "Install a package")
|
||||
{
|
||||
new Option<string>(new[] {"--identifier", "-i"}, "Something to identify the app or the file name"),
|
||||
new Option<bool>(new[] {"--force", "-f"}, "Overwrites older files")
|
||||
};
|
||||
install.Handler = CommandHandler.Create<string, bool>(Install);
|
||||
rootCommand.AddCommand(install);
|
||||
|
||||
Command upgrade = new Command("upgrade", "Upgrade a package")
|
||||
{
|
||||
new Option<string>(new[] {"--identifier", "-i"}, "Something to identify the app"),
|
||||
new Option<bool>(new[] {"--force", "-f"}, "Overwrites older files")
|
||||
};
|
||||
upgrade.Handler = CommandHandler.Create<string, bool>(Upgrade);
|
||||
rootCommand.AddCommand(upgrade);
|
||||
|
||||
Command command = new Command("upgrade-self", "Upgrades UpToolCLI")
|
||||
{
|
||||
new Option<bool>(new[] {"--force", "-f"}, "Overwrites older files")
|
||||
};
|
||||
command.Handler = CommandHandler.Create<bool>(UpgradeSelf);
|
||||
rootCommand.AddCommand(command);
|
||||
|
||||
Command reinstall = new Command("reinstall", "Reinstall a package")
|
||||
{
|
||||
new Option<string>(new[] {"--identifier", "-i"}, "Something to identify the app"),
|
||||
new Option<bool>(new[] {"--force", "-f"}, "Overwrites older files")
|
||||
};
|
||||
reinstall.Handler = CommandHandler.Create<string, bool>(Reinstall);
|
||||
rootCommand.AddCommand(reinstall);
|
||||
|
||||
Command remove = new Command("remove", "Remove a package")
|
||||
{
|
||||
new Option<string>(new[] {"--identifier", "-i"}, "Something to identify the app")
|
||||
};
|
||||
remove.Handler = CommandHandler.Create<string>(Remove);
|
||||
rootCommand.AddCommand(remove);
|
||||
|
||||
Command purge = new Command("purge", "Completely remove a package")
|
||||
{
|
||||
new Option<string>(new[] {"--identifier", "-i"}, "Something to identify the app")
|
||||
};
|
||||
purge.Handler = CommandHandler.Create<string>(Purge);
|
||||
rootCommand.AddCommand(purge);
|
||||
|
||||
rootCommand.AddCommand(new Command("list", "Lists installed packages")
|
||||
{
|
||||
Handler = CommandHandler.Create(List)
|
||||
});
|
||||
|
||||
rootCommand.AddCommand(new Command("dist-upgrade", "Upgrades all packages")
|
||||
{
|
||||
Handler = CommandHandler.Create(DistUpgrade)
|
||||
});
|
||||
|
||||
Command search = new Command("search", "Search for packages")
|
||||
{
|
||||
new Option<string>(new[] {"--identifier", "-i"}, "Something to identify the app")
|
||||
};
|
||||
search.Handler = CommandHandler.Create<string>(Search);
|
||||
rootCommand.AddCommand(search);
|
||||
|
||||
Command show = new Command("show", "Shows package info")
|
||||
{
|
||||
new Option<string>(new[] {"--identifier", "-i"}, "Something to identify the app")
|
||||
};
|
||||
show.Handler = CommandHandler.Create<string>(Show);
|
||||
rootCommand.AddCommand(show);
|
||||
|
||||
Command start = new Command("start", "Starts an app")
|
||||
{
|
||||
new Option<string>(new[] {"--identifier", "-i"}, "Something to identify the app"),
|
||||
new Option<string>(new[] {"--waitForExit", "-wait"}, "Waits until the program quits")
|
||||
};
|
||||
start.Handler = CommandHandler.Create<string, bool>(Start);
|
||||
rootCommand.AddCommand(start);
|
||||
return rootCommand.InvokeAsync(args).Result;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Lib?.Dispose();
|
||||
}
|
||||
MutexLock.Unlock();
|
||||
}
|
||||
}
|
||||
|
||||
private static void UpgradeSelf(bool force)
|
||||
{
|
||||
#if DEBUG
|
||||
Console.WriteLine("Not enabled in debug builds");
|
||||
#else
|
||||
if (!force && Assembly.GetExecutingAssembly().GetName().Version >= UpdateCheck.OnlineVersion)
|
||||
Console.WriteLine("Already up-to-date");
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Downloading latest");
|
||||
(bool success, byte[] dl) = Functions.Download(UpdateCheck.Installer);
|
||||
if (!success)
|
||||
throw new Exception("Failed to update");
|
||||
Console.WriteLine("Verifying");
|
||||
using (SHA256CryptoServiceProvider sha256 = new SHA256CryptoServiceProvider())
|
||||
{
|
||||
string pkgHash = BitConverter.ToString(sha256.ComputeHash(dl)).Replace("-", string.Empty).ToUpper();
|
||||
if (pkgHash != UpdateCheck.InstallerHash)
|
||||
throw new Exception($@"The hash is not equal to the one stored in the repo:
|
||||
Package: {pkgHash}
|
||||
Online: {UpdateCheck.InstallerHash}");
|
||||
}
|
||||
Console.WriteLine("Installing");
|
||||
if (Directory.Exists(PathTool.GetRelative("Install", "tmp")))
|
||||
Directory.Delete(PathTool.GetRelative("Install", "tmp"), true);
|
||||
Directory.CreateDirectory(PathTool.GetRelative("Install", "tmp"));
|
||||
using (MemoryStream ms = new MemoryStream(dl))
|
||||
{
|
||||
using ZipArchive ar = new ZipArchive(ms);
|
||||
ar.ExtractToDirectory(PathTool.GetRelative("Install", "tmp"), true);
|
||||
}
|
||||
string file = PathTool.GetRelative("Install", "tmp", "Installer.exe");
|
||||
Console.WriteLine($"Starting {file}");
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = file,
|
||||
Arguments = "-i",
|
||||
WorkingDirectory = PathTool.GetRelative("Install"),
|
||||
UseShellExecute = false
|
||||
});
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private static void Update()
|
||||
{
|
||||
Console.WriteLine("Fetching Repos...");
|
||||
RepoManagement.FetchRepos();
|
||||
RepoManagement.GetReposFromDisk();
|
||||
Console.WriteLine();
|
||||
IEnumerable<App> tmp = GlobalVariables.Apps.Where(s =>
|
||||
(s.Value.Status & Status.Updatable) == Status.Updatable).Select(s => s.Value);
|
||||
IEnumerable<App> apps = tmp as App[] ?? tmp.ToArray();
|
||||
int updatableCount = apps.Count();
|
||||
Console.WriteLine(updatableCount == 0
|
||||
? "All up-to-date"
|
||||
: $@"Found {updatableCount} Updates:
|
||||
{string.Join(Environment.NewLine, apps.Select(s => $"- {s.Name} ({s.Version})"))}");
|
||||
#if !DEBUG
|
||||
Version vLocal = Assembly.GetExecutingAssembly().GetName().Version;
|
||||
Version vOnline = UpdateCheck.OnlineVersion;
|
||||
if (vLocal < vOnline)
|
||||
Console.WriteLine($"uptool is outdated ({vLocal} vs {vOnline}), update using \"uptool upgrade-self\"");
|
||||
#endif
|
||||
}
|
||||
|
||||
private static void List()
|
||||
{
|
||||
RepoManagement.GetReposFromDisk();
|
||||
foreach (KeyValuePair<Guid, App> app in GlobalVariables.Apps.Where(s =>
|
||||
(s.Value.Status & Status.Installed) == Status.Installed))
|
||||
{
|
||||
Console.BackgroundColor = (app.Value.Status & Status.Local) == Status.Local ? ConsoleColor.DarkRed :
|
||||
(app.Value.Status & Status.Updatable) == Status.Updatable ? ConsoleColor.DarkGreen :
|
||||
ConsoleColor.Black;
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
Console.WriteLine($"{app.Value.Name} ({app.Key})");
|
||||
}
|
||||
Console.ResetColor();
|
||||
}
|
||||
|
||||
private static void DistUpgrade()
|
||||
{
|
||||
RepoManagement.GetReposFromDisk();
|
||||
foreach (KeyValuePair<Guid, App> app in GlobalVariables.Apps.Where(s =>
|
||||
(s.Value.Status & Status.Updatable) == Status.Updatable))
|
||||
{
|
||||
Console.WriteLine($"Updating {app.Value.Name}");
|
||||
AppExtras.Update(app.Value, false);
|
||||
}
|
||||
#if !DEBUG
|
||||
if (Assembly.GetExecutingAssembly().GetName().Version < UpdateCheck.OnlineVersion)
|
||||
{
|
||||
Console.WriteLine("Updating self");
|
||||
UpgradeSelf(false);
|
||||
}
|
||||
#endif
|
||||
Console.WriteLine("Done!");
|
||||
}
|
||||
|
||||
private static void Show(string identifier)
|
||||
{
|
||||
RepoManagement.GetReposFromDisk();
|
||||
App[] apps = AppExtras.FindApps(identifier);
|
||||
if (apps.Length == 0)
|
||||
Console.WriteLine("Package not found.");
|
||||
else
|
||||
Console.WriteLine(apps.First());
|
||||
}
|
||||
|
||||
private static void Search(string identifier)
|
||||
{
|
||||
RepoManagement.GetReposFromDisk();
|
||||
App[] apps = AppExtras.FindApps(identifier);
|
||||
Console.WriteLine($"Found {apps.Length} app(s)");
|
||||
for (int i = 0; i < apps.Length; i++)
|
||||
Console.WriteLine($"{apps[i].Name} ({apps[i].Id})");
|
||||
}
|
||||
|
||||
private static void Upgrade(string identifier, bool force)
|
||||
{
|
||||
RepoManagement.GetReposFromDisk();
|
||||
App[] apps = AppExtras.FindApps(identifier);
|
||||
if (apps.Length == 0)
|
||||
Console.WriteLine("Package not found.");
|
||||
else
|
||||
{
|
||||
App tmp = apps.First();
|
||||
if ((tmp.Status & Status.Updatable) == Status.Updatable)
|
||||
{
|
||||
Console.WriteLine($"Upgrading {tmp.Name}");
|
||||
AppExtras.Update(tmp, force);
|
||||
}
|
||||
else
|
||||
Console.WriteLine("Package is up-to-date");
|
||||
}
|
||||
Console.WriteLine("Done!");
|
||||
}
|
||||
|
||||
private static void Reinstall(string identifier, bool force)
|
||||
{
|
||||
RepoManagement.GetReposFromDisk();
|
||||
App[] apps = AppExtras.FindApps(identifier);
|
||||
if (apps.Length == 0)
|
||||
Console.WriteLine("Package not found.");
|
||||
else
|
||||
{
|
||||
App tmp = apps.First();
|
||||
Console.WriteLine($"Reinstalling {tmp.Name}");
|
||||
AppExtras.Update(tmp, force);
|
||||
}
|
||||
Console.WriteLine("Done!");
|
||||
}
|
||||
|
||||
private static void Remove(string identifier)
|
||||
{
|
||||
RepoManagement.GetReposFromDisk();
|
||||
App[] apps = AppExtras.FindApps(identifier);
|
||||
if (apps.Length == 0)
|
||||
Console.WriteLine("Package not found.");
|
||||
else
|
||||
{
|
||||
App tmp = apps.First();
|
||||
if ((tmp.Status & Status.Installed) == Status.Installed)
|
||||
{
|
||||
Console.WriteLine($"Removing {tmp.Name}");
|
||||
AppExtras.Remove(tmp, false);
|
||||
}
|
||||
else
|
||||
Console.WriteLine("Package is not installed");
|
||||
}
|
||||
Console.WriteLine("Done!");
|
||||
}
|
||||
|
||||
private static void Purge(string identifier)
|
||||
{
|
||||
RepoManagement.GetReposFromDisk();
|
||||
App[] apps = AppExtras.FindApps(identifier);
|
||||
if (apps.Length == 0)
|
||||
Console.WriteLine("Package not found.");
|
||||
else
|
||||
{
|
||||
App tmp = apps.First();
|
||||
if ((tmp.Status & Status.Installed) == Status.Installed)
|
||||
{
|
||||
Console.WriteLine($"Purgeing {tmp.Name}");
|
||||
AppExtras.Remove(tmp, true);
|
||||
}
|
||||
else
|
||||
Console.WriteLine("Package is not installed");
|
||||
}
|
||||
Console.WriteLine("Done!");
|
||||
}
|
||||
|
||||
private static void Install(string identifier, bool force)
|
||||
{
|
||||
RepoManagement.GetReposFromDisk();
|
||||
App[] apps = AppExtras.FindApps(identifier);
|
||||
if (apps.Length == 0)
|
||||
{
|
||||
if (File.Exists(identifier))
|
||||
{
|
||||
Console.WriteLine("Name:");
|
||||
string name = Console.ReadLine();
|
||||
AppInstall.InstallZip(identifier, new App(name, "Locally installed package, removal only",
|
||||
GlobalVariables.MinimumVer, "", true, "",
|
||||
Guid.NewGuid(), Color.Red, "", false, ""), force);
|
||||
Console.WriteLine($"Successfully installed \"{name}\"");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Package not found.");
|
||||
Console.WriteLine(identifier);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
App tmp = apps.First();
|
||||
if ((tmp.Status & Status.Installed) == Status.Installed)
|
||||
Console.WriteLine("Package is already installed");
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"Installing {tmp.Name}");
|
||||
AppInstall.Install(tmp, true);
|
||||
}
|
||||
}
|
||||
Console.WriteLine("Done!");
|
||||
}
|
||||
|
||||
private static void Start(string identifier, bool waitForExit)
|
||||
{
|
||||
RepoManagement.GetReposFromDisk();
|
||||
App[] apps = AppExtras.FindApps(identifier);
|
||||
if (apps.Length == 0)
|
||||
Console.WriteLine("Package not found.");
|
||||
else
|
||||
{
|
||||
App tmp = apps.First();
|
||||
if (tmp.Runnable)
|
||||
{
|
||||
Console.WriteLine($"Starting {tmp.Name}");
|
||||
Process tmp1 = AppExtras.RunApp(tmp);
|
||||
if (waitForExit)
|
||||
tmp1.WaitForExit();
|
||||
}
|
||||
else
|
||||
Console.WriteLine($"{tmp.Name} is not runnable");
|
||||
}
|
||||
Console.WriteLine("Done!");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,93 +0,0 @@
|
||||
using System;
|
||||
using System.CommandLine;
|
||||
using System.CommandLine.Invocation;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using UpToolLib.v1.Tool;
|
||||
|
||||
namespace UpToolCLI
|
||||
{
|
||||
public class ReposManagement
|
||||
{
|
||||
private static string InfoXml => Program.Lib.V1.PathTool.InfoXml;
|
||||
public static void RegisterCommands(RootCommand rootCommand)
|
||||
{
|
||||
rootCommand.AddCommand(new Command("list-repo", "Lists current repositories")
|
||||
{
|
||||
Handler = CommandHandler.Create(ListRepo)
|
||||
});
|
||||
|
||||
Command addRepo = new("add-repo", "Adds a repository")
|
||||
{
|
||||
new Argument<string>("name", "The new repositories name"),
|
||||
new Argument<string>("link", "A link to the repositories XML")
|
||||
};
|
||||
addRepo.Handler = CommandHandler.Create<string, string>(AddRepo);
|
||||
rootCommand.AddCommand(addRepo);
|
||||
|
||||
Command removeRepo = new("remove-repo", "Removes a repository")
|
||||
{
|
||||
new Argument<string>("name", "The repositories name")
|
||||
};
|
||||
removeRepo.Handler = CommandHandler.Create<string>(RemoveRepo);
|
||||
rootCommand.AddCommand(removeRepo);
|
||||
}
|
||||
|
||||
private static void ListRepo()
|
||||
{
|
||||
XDocument doc = XDocument.Load(InfoXml);
|
||||
XElement repos = doc.Element("meta").Element("Repos");
|
||||
Console.WriteLine("Current repos:");
|
||||
Console.WriteLine(repos.Elements("Repo").ToStringTable(new[]
|
||||
{
|
||||
"Name", "Link"
|
||||
},
|
||||
u => u.Element("Name").Value,
|
||||
u => u.Element("Link").Value));
|
||||
}
|
||||
|
||||
private static void AddRepo(string name, string link)
|
||||
{
|
||||
XDocument doc = XDocument.Load(InfoXml);
|
||||
XElement repos = doc.Element("meta").Element("Repos");
|
||||
repos.Add(new XElement("Repo", new XElement("Name", name),
|
||||
new XElement("Link", link)));
|
||||
doc.Save(InfoXml);
|
||||
Console.WriteLine("Added repo. Remember to update the cache using \"uptool update\"");
|
||||
}
|
||||
|
||||
private static void RemoveRepo(string name)
|
||||
{
|
||||
XDocument doc = XDocument.Load(InfoXml);
|
||||
XElement repos = doc.Element("meta").Element("Repos");
|
||||
XElement[] sRepos = repos.Elements("Repo")
|
||||
.Where(s => s.Element("Name").Value.ToLower().StartsWith(name.ToLower())).ToArray();
|
||||
switch (sRepos.Length)
|
||||
{
|
||||
case 0:
|
||||
Console.WriteLine("No repo was found that matches your input!");
|
||||
return;
|
||||
case 1:
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine("Found multiple repos that match your input:");
|
||||
Console.WriteLine(sRepos.ToStringTable(new[]
|
||||
{
|
||||
"Name", "Link"
|
||||
},
|
||||
u => u.Element("Name").Value,
|
||||
u => u.Element("Link").Value));
|
||||
if (!Program.Functions.YesNoDialog("Are you sure you want to delete them all?", false))
|
||||
return;
|
||||
break;
|
||||
}
|
||||
foreach (XElement t in sRepos)
|
||||
{
|
||||
Console.WriteLine($"Removing {t.Element("Name").Value}");
|
||||
t.Remove();
|
||||
}
|
||||
doc.Save(InfoXml);
|
||||
Console.WriteLine("Removed repo. Remember to update the cache using \"uptool update\"");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,104 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
namespace UpToolCLI
|
||||
{
|
||||
public static class TableParser
|
||||
{
|
||||
public static string ToStringTable<T>(this IEnumerable<T> values, string[] columnHeaders,
|
||||
params Func<T, object>[] valueSelectors) => ToStringTable(values.ToArray(), columnHeaders, valueSelectors);
|
||||
|
||||
public static string ToStringTable<T>(this T[] values, string[] columnHeaders,
|
||||
params Func<T, object>[] valueSelectors)
|
||||
{
|
||||
Debug.Assert(columnHeaders.Length == valueSelectors.Length);
|
||||
|
||||
string[,] arrValues = new string[values.Length + 1, valueSelectors.Length];
|
||||
|
||||
// Fill headers
|
||||
for (int colIndex = 0; colIndex < arrValues.GetLength(1); colIndex++)
|
||||
arrValues[0, colIndex] = columnHeaders[colIndex];
|
||||
|
||||
// Fill table rows
|
||||
for (int rowIndex = 1; rowIndex < arrValues.GetLength(0); rowIndex++)
|
||||
for (int colIndex = 0; colIndex < arrValues.GetLength(1); colIndex++)
|
||||
{
|
||||
object value = valueSelectors[colIndex].Invoke(values[rowIndex - 1]);
|
||||
|
||||
arrValues[rowIndex, colIndex] = value != null ? value.ToString() : "null";
|
||||
}
|
||||
|
||||
return ToStringTable(arrValues);
|
||||
}
|
||||
|
||||
public static string ToStringTable(this string[,] arrValues)
|
||||
{
|
||||
int[] maxColumnsWidth = GetMaxColumnsWidth(arrValues);
|
||||
string headerSpliter = new('-', maxColumnsWidth.Sum(i => i + 3) - 1);
|
||||
|
||||
StringBuilder sb = new();
|
||||
for (int rowIndex = 0; rowIndex < arrValues.GetLength(0); rowIndex++)
|
||||
{
|
||||
for (int colIndex = 0; colIndex < arrValues.GetLength(1); colIndex++)
|
||||
{
|
||||
// Print cell
|
||||
string cell = arrValues[rowIndex, colIndex];
|
||||
cell = cell.PadRight(maxColumnsWidth[colIndex]);
|
||||
sb.Append(" | ");
|
||||
sb.Append(cell);
|
||||
}
|
||||
|
||||
// Print end of line
|
||||
sb.Append(" | ");
|
||||
sb.AppendLine();
|
||||
|
||||
// Print splitter
|
||||
if (rowIndex == 0)
|
||||
{
|
||||
sb.AppendFormat(" |{0}| ", headerSpliter);
|
||||
sb.AppendLine();
|
||||
}
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
private static int[] GetMaxColumnsWidth(string[,] arrValues)
|
||||
{
|
||||
int[] maxColumnsWidth = new int[arrValues.GetLength(1)];
|
||||
for (int colIndex = 0; colIndex < arrValues.GetLength(1); colIndex++)
|
||||
for (int rowIndex = 0; rowIndex < arrValues.GetLength(0); rowIndex++)
|
||||
{
|
||||
int newLength = arrValues[rowIndex, colIndex].Length;
|
||||
int oldLength = maxColumnsWidth[colIndex];
|
||||
|
||||
if (newLength > oldLength) maxColumnsWidth[colIndex] = newLength;
|
||||
}
|
||||
|
||||
return maxColumnsWidth;
|
||||
}
|
||||
|
||||
public static string ToStringTable<T>(this IEnumerable<T> values,
|
||||
params Expression<Func<T, object>>[] valueSelectors)
|
||||
{
|
||||
string[] headers = valueSelectors.Select(func => GetProperty(func).Name).ToArray();
|
||||
Func<T, object>[] selectors = valueSelectors.Select(exp => exp.Compile()).ToArray();
|
||||
return ToStringTable(values, headers, selectors);
|
||||
}
|
||||
|
||||
private static PropertyInfo GetProperty<T>(Expression<Func<T, object>> expresstion)
|
||||
{
|
||||
if (expresstion.Body is UnaryExpression expression)
|
||||
if (expression.Operand is MemberExpression memberExpression)
|
||||
return memberExpression.Member as PropertyInfo;
|
||||
|
||||
if (expresstion.Body is MemberExpression body) return body.Member as PropertyInfo;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -5,7 +5,6 @@ using System.Threading;
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
using UpToolLib.DataStructures;
|
||||
using static UpToolCLI.Program;
|
||||
|
||||
namespace UpToolCLI
|
||||
{
|
||||
@ -13,7 +12,7 @@ namespace UpToolCLI
|
||||
{
|
||||
public Tuple<bool, byte[]> Download(Uri link)
|
||||
{
|
||||
using WebClient client = new();
|
||||
using WebClient client = new WebClient();
|
||||
byte[] result = new byte[0];
|
||||
bool finished = false;
|
||||
bool success = true;
|
||||
@ -25,13 +24,10 @@ namespace UpToolCLI
|
||||
finished = true;
|
||||
};
|
||||
client.DownloadProgressChanged += (sender, e) =>
|
||||
{
|
||||
if (!Basic)
|
||||
{
|
||||
Console.Write(
|
||||
$"{new string('=', e.ProgressPercentage / 10)}[{e.ProgressPercentage}]{new string('-', 10 - e.ProgressPercentage / 10)}");
|
||||
Console.CursorLeft = 0;
|
||||
}
|
||||
};
|
||||
client.DownloadDataAsync(link);
|
||||
while (!finished)
|
||||
@ -41,23 +37,15 @@ namespace UpToolCLI
|
||||
|
||||
public string FetchImageB64(Uri link)
|
||||
{
|
||||
using WebClient client = new();
|
||||
using WebClient client = new WebClient();
|
||||
using Image image = Image.Load(client.OpenRead(link));
|
||||
image.Mutate(x => x.Resize(70, 70));
|
||||
using MemoryStream ms = new();
|
||||
using MemoryStream ms = new MemoryStream();
|
||||
image.SaveAsPng(ms);
|
||||
return Convert.ToBase64String(ms.ToArray());
|
||||
}
|
||||
|
||||
public bool YesNoDialog(string text, bool defaultVal)
|
||||
{
|
||||
if (Basic)
|
||||
{
|
||||
Console.WriteLine(text);
|
||||
Console.WriteLine($"Selecting: {defaultVal}");
|
||||
return defaultVal;
|
||||
}
|
||||
else
|
||||
{
|
||||
bool choosing = true;
|
||||
bool current = defaultVal;
|
||||
@ -93,13 +81,8 @@ namespace UpToolCLI
|
||||
Console.WriteLine($" Selecting: {current}");
|
||||
return current;
|
||||
}
|
||||
}
|
||||
|
||||
public void OkDialog(string text)
|
||||
{
|
||||
if (Basic)
|
||||
Console.WriteLine(text);
|
||||
else
|
||||
{
|
||||
Console.WriteLine(text);
|
||||
Console.BackgroundColor = ConsoleColor.White;
|
||||
@ -107,7 +90,6 @@ namespace UpToolCLI
|
||||
Console.ResetColor();
|
||||
Console.ReadKey();
|
||||
}
|
||||
}
|
||||
|
||||
public object GetDefaultIcon() => 0;
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<AssemblyName>uptool</AssemblyName>
|
||||
<Deterministic>false</Deterministic>
|
||||
<AssemblyVersion>1.0.*</AssemblyVersion>
|
||||
@ -13,8 +13,8 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.2" />
|
||||
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.20574.7" />
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-beta0007" />
|
||||
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.20158.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -1,17 +0,0 @@
|
||||
using System;
|
||||
using Eto.Forms;
|
||||
|
||||
namespace UpToolEto.Gtk
|
||||
{
|
||||
class MainClass
|
||||
{
|
||||
[STAThread]
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
new Main(new Application(Eto.Platforms.Gtk), () =>
|
||||
{
|
||||
|
||||
}, args).Entry();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\UpToolEto\UpToolEto.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Eto.Platform.Gtk" Version="2.5.10"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -1,38 +0,0 @@
|
||||
using System;
|
||||
using Eto.Forms;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace UpToolEto.Wpf
|
||||
{
|
||||
class MainClass
|
||||
{
|
||||
[STAThread]
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
new Main(new Application(Eto.Platforms.Wpf), () =>
|
||||
{
|
||||
Process[] processes = Process.GetProcessesByName("UpTool2");
|
||||
if (processes.Length > 0)
|
||||
BringProcessToFront(processes[0]);
|
||||
}, args).Entry();
|
||||
}
|
||||
|
||||
public static void BringProcessToFront(Process process)
|
||||
{
|
||||
IntPtr handle = process.MainWindowHandle;
|
||||
if (IsIconic(handle))
|
||||
ShowWindow(handle, 9);
|
||||
SetForegroundWindow(handle);
|
||||
}
|
||||
|
||||
[DllImport("User32.dll")]
|
||||
private static extern bool SetForegroundWindow(IntPtr handle);
|
||||
|
||||
[DllImport("User32.dll")]
|
||||
private static extern bool ShowWindow(IntPtr handle, int nCmdShow);
|
||||
|
||||
[DllImport("User32.dll")]
|
||||
private static extern bool IsIconic(IntPtr handle);
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net5.0-windows</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\UpToolEto\UpToolEto.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Eto.Platform.Wpf" Version="2.5.10"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -1,65 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Eto.Drawing;
|
||||
using Eto.Forms;
|
||||
using UpToolLib.v2;
|
||||
using UpToolLib.v2.TaskQueue;
|
||||
|
||||
namespace UpToolEto.Controls
|
||||
{
|
||||
public abstract class AppControlButton : Button
|
||||
{
|
||||
public abstract void ReloadState();
|
||||
public abstract void SetApp(App app);
|
||||
public abstract void Clear();
|
||||
}
|
||||
|
||||
public class AppControlButton<T> : AppControlButton where T : KnownAppTask
|
||||
{
|
||||
private readonly IList<AppTask> _tasks;
|
||||
private readonly Func<App, bool> _enabledCheck;
|
||||
private readonly Color _defaultColor;
|
||||
private App _app;
|
||||
|
||||
public AppControlButton(string text, Func<App, Action?, AppTask> factory, IList<AppTask> tasks, Action reloadState, Func<App, bool> enabledCheck)
|
||||
{
|
||||
_tasks = tasks;
|
||||
_enabledCheck = enabledCheck;
|
||||
_defaultColor = BackgroundColor;
|
||||
Text = text;
|
||||
Click += (_, _) =>
|
||||
{
|
||||
bool found = false;
|
||||
for (var i = tasks.ToArray().Length - 1; i >= 0; i--)
|
||||
{
|
||||
if (tasks[i] is T t && t.App == _app)
|
||||
{
|
||||
found = true;
|
||||
tasks.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
tasks.Add(factory(_app, ReloadState));
|
||||
reloadState();
|
||||
};
|
||||
}
|
||||
|
||||
public override void ReloadState()
|
||||
{
|
||||
Enabled = _enabledCheck(_app);
|
||||
BackgroundColor = _tasks.Any(s => s is T t && t.App == _app) ? Colors.Green : _defaultColor;
|
||||
}
|
||||
|
||||
public override void SetApp(App app)
|
||||
{
|
||||
_app = app;
|
||||
ReloadState();
|
||||
}
|
||||
|
||||
public override void Clear()
|
||||
{
|
||||
Enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,83 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Eto.Drawing;
|
||||
using Eto.Forms;
|
||||
using UpToolEto.Forms;
|
||||
using UpToolLib.DataStructures;
|
||||
using UpToolLib.v2;
|
||||
using UpToolLib.v2.TaskQueue;
|
||||
|
||||
namespace UpToolEto.Controls
|
||||
{
|
||||
public class AppControls : StackLayout
|
||||
{
|
||||
private readonly IList<AppTask> _tasks;
|
||||
private readonly List<AppControlButton> _buttons;
|
||||
private readonly Button _applyButton;
|
||||
public AppControls(TaskFactory factory, IList<AppTask> tasks, IExternalFunctionality platform, Action update)
|
||||
{
|
||||
_tasks = tasks;
|
||||
_buttons = new List<AppControlButton>
|
||||
{
|
||||
new AppControlButton<InstallTask>("Install", factory.CreateInstall, tasks, ReloadState,
|
||||
app => !app.Status.Contains(Status.Installed)),
|
||||
new AppControlButton<UpdateTask>("Update", factory.CreateUpdate, tasks, ReloadState,
|
||||
app => app.Status.Contains(Status.Updatable)),
|
||||
new AppControlButton<RemoveTask>("Remove", factory.CreateRemove, tasks, ReloadState,
|
||||
app => app.Status.Contains(Status.Installed))
|
||||
};
|
||||
_applyButton = new Button((_, _) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
QueueOverview overview = new(tasks);
|
||||
overview.ShowModal();
|
||||
if (!overview.Cancelled)
|
||||
{
|
||||
foreach (AppTask task in overview.TasksResulting)
|
||||
{
|
||||
task.Run();
|
||||
_tasks.RemoveAt(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
platform.OkDialog("Failed to complete queue:\r\n" + e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
ReloadState();
|
||||
update();
|
||||
}
|
||||
})
|
||||
{
|
||||
Text = "Apply",
|
||||
Enabled = false
|
||||
};
|
||||
foreach (AppControlButton button in _buttons) Items.Add(button);
|
||||
Items.Add(new StackLayoutItem(_applyButton, HorizontalAlignment.Right));
|
||||
if (Main.DebugColors)
|
||||
BackgroundColor = Colors.Yellow;
|
||||
Orientation = Orientation.Horizontal;
|
||||
}
|
||||
|
||||
public void SetApp(App app)
|
||||
{
|
||||
foreach (AppControlButton button in _buttons) button.SetApp(app);
|
||||
ReloadState();
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
foreach (AppControlButton button in _buttons) button.Clear();
|
||||
}
|
||||
|
||||
private void ReloadState()
|
||||
{
|
||||
foreach (AppControlButton button in _buttons) button.ReloadState();
|
||||
_applyButton.Enabled = _tasks.Any();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Eto.Drawing;
|
||||
using Eto.Forms;
|
||||
using UpToolEto.Forms;
|
||||
using UpToolLib.v1.Tool;
|
||||
using UpToolLib.v2;
|
||||
using UpToolLib.v2.TaskQueue;
|
||||
|
||||
namespace UpToolEto.Controls
|
||||
{
|
||||
public class AppList : StackLayout
|
||||
{
|
||||
private readonly AppExtras _extras;
|
||||
private readonly Action<Guid, App> _itemClickEvent;
|
||||
private readonly StackLayout _layout;
|
||||
private readonly AppListSearchProvider _searchProvider;
|
||||
|
||||
public AppList(AppExtras extras, Action<Guid, App> itemClickEvent, bool online, TaskFactory factory, IList<AppTask> tasks)
|
||||
{
|
||||
_extras = extras;
|
||||
_itemClickEvent = itemClickEvent;
|
||||
_searchProvider = new AppListSearchProvider(online, Update);
|
||||
Items.Add(_searchProvider);
|
||||
_layout = new StackLayout
|
||||
{
|
||||
Padding = 10,
|
||||
Orientation = Orientation.Vertical,
|
||||
Width = 200
|
||||
};
|
||||
Scrollable scrollable = new()
|
||||
{
|
||||
Content = _layout
|
||||
};
|
||||
if (Main.DebugColors)
|
||||
scrollable.BackgroundColor = Colors.YellowGreen;
|
||||
Items.Add(new StackLayoutItem(scrollable, VerticalAlignment.Stretch, true));
|
||||
Orientation = Orientation.Vertical;
|
||||
if (Main.DebugColors)
|
||||
BackgroundColor = Colors.Green;
|
||||
Update();
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
_layout.Items.Clear();
|
||||
foreach (App app in _extras.FindApps(_searchProvider.GetSearchTerms()))
|
||||
if (_searchProvider.Matches(app))
|
||||
_layout.Items.Add(new Button((_, _) => _itemClickEvent(app.Id, app))
|
||||
{
|
||||
Text = app.Name,
|
||||
Image = (Icon)app.Icon,
|
||||
ImagePosition = ButtonImagePosition.Left,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
using System;
|
||||
using Eto.Forms;
|
||||
using UpToolLib.DataStructures;
|
||||
using UpToolLib.v2;
|
||||
|
||||
namespace UpToolEto.Controls
|
||||
{
|
||||
public class AppListSearchProvider : StackLayout
|
||||
{
|
||||
private readonly bool _online;
|
||||
private readonly TextBox _search;
|
||||
private readonly EnumDropDown<Status> _state;
|
||||
|
||||
public AppListSearchProvider(bool online, Action refresh)
|
||||
{
|
||||
_online = online;
|
||||
_search = new SearchBox();
|
||||
_state = new EnumDropDown<Status>();
|
||||
_state.SelectedValue = online ? Status.NotInstalled : Status.Installed;
|
||||
_state.Enabled = online;
|
||||
_search.TextChanged += (_, _) => refresh();
|
||||
_state.SelectedIndexChanged += (_, _) => refresh();
|
||||
Orientation = Orientation.Vertical;
|
||||
Items.Add(new StackLayoutItem(_search, HorizontalAlignment.Stretch));
|
||||
Items.Add(_state);
|
||||
}
|
||||
|
||||
public bool Matches(App app) => app.Status.Contains(_online ? _state.SelectedValue : Status.Installed);
|
||||
|
||||
public string GetSearchTerms() => _search.Text;
|
||||
}
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Eto.Drawing;
|
||||
using Eto.Forms;
|
||||
using UpToolLib.DataStructures;
|
||||
using UpToolLib.v1.Tool;
|
||||
using UpToolLib.v2;
|
||||
using UpToolLib.v2.TaskQueue;
|
||||
|
||||
namespace UpToolEto.Controls
|
||||
{
|
||||
public class AppPanel : Panel
|
||||
{
|
||||
private readonly Button _appNameLabel;
|
||||
private readonly Label _appDescriptionLabel;
|
||||
private readonly AppControls _appControls;
|
||||
private App _app;
|
||||
public AppPanel(TaskFactory factory, AppExtras extras, IList<AppTask> tasks, IExternalFunctionality platform, Action updateAppList)
|
||||
{
|
||||
_appDescriptionLabel = new Label();
|
||||
_appNameLabel = new Button((_, _) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
extras.RunApp(_app);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
platform.OkDialog("Failed to start\r\n" + e);
|
||||
}
|
||||
});
|
||||
_appNameLabel.Font = new Font(_appNameLabel.Font.Family, _appNameLabel.Font.Size * 2);
|
||||
_appControls = new AppControls(factory, tasks, platform, () =>
|
||||
{
|
||||
updateAppList();
|
||||
SetApp(_app);
|
||||
});
|
||||
Content = new StackLayout
|
||||
{
|
||||
Items =
|
||||
{
|
||||
new StackLayoutItem(_appNameLabel, HorizontalAlignment.Center),
|
||||
new StackLayoutItem(_appDescriptionLabel, HorizontalAlignment.Center, true),
|
||||
new StackLayoutItem(_appControls, HorizontalAlignment.Stretch)
|
||||
},
|
||||
Orientation = Orientation.Vertical
|
||||
};
|
||||
if (Main.DebugColors)
|
||||
BackgroundColor = Colors.Red;
|
||||
Clear();
|
||||
}
|
||||
|
||||
public void SetApp(App app)
|
||||
{
|
||||
_app = app;
|
||||
_appNameLabel.Text = app.Name;
|
||||
_appNameLabel.Enabled = app.Status.Contains(Status.Installed) && app.Runnable;
|
||||
_appDescriptionLabel.Text = app.Description;
|
||||
_appControls.SetApp(app);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_appNameLabel.Text = "Welcome to UpTool2";
|
||||
_appNameLabel.Enabled = false;
|
||||
_appDescriptionLabel.Text = "Select an app to get started";
|
||||
_appControls.Clear();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Eto.Forms;
|
||||
using UpToolLib.DataStructures;
|
||||
|
||||
namespace UpToolEto.Controls
|
||||
{
|
||||
public class RepoItem : StackLayout
|
||||
{
|
||||
public RepoItem(Repo repo, int index, Action update, IList<Repo> repos)
|
||||
{
|
||||
TextBox name = new()
|
||||
{
|
||||
Text = repo.Name
|
||||
};
|
||||
name.TextChanged += (_, _) => repo.Name = name.Text;
|
||||
TextBox link = new()
|
||||
{
|
||||
Text = repo.Url
|
||||
};
|
||||
link.TextChanged += (_, _) => repo.Url = link.Text;
|
||||
Orientation = Orientation.Horizontal;
|
||||
Items.Add(name);
|
||||
Items.Add(new StackLayoutItem(link, HorizontalAlignment.Stretch, true));
|
||||
Items.Add(new Button((_, _) =>
|
||||
{
|
||||
repos.RemoveAt(index);
|
||||
update();
|
||||
})
|
||||
{
|
||||
Text = "-"
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -1,71 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Eto.Forms;
|
||||
using UpToolEto.Forms;
|
||||
using UpToolLib.DataStructures;
|
||||
using UpToolLib.v2;
|
||||
using UpToolLib.v2.TaskQueue;
|
||||
|
||||
namespace UpToolEto.Controls
|
||||
{
|
||||
public class UTMenuBar : MenuBar
|
||||
{
|
||||
public UTMenuBar(MainForm mainForm, RepoManagement repoManagement, TaskFactory factory, IList<AppTask> tasks, AppList appList, IExternalFunctionality platform)
|
||||
{
|
||||
Command reloadRepos = new() {MenuText = "Reload", ToolBarText = "Reload"};
|
||||
reloadRepos.Executed += (_, _) =>
|
||||
{
|
||||
if (platform.YesNoDialog("This may take some time. Are you sure?", true))
|
||||
{
|
||||
repoManagement.FetchRepos();
|
||||
repoManagement.GetReposFromDisk();
|
||||
appList.Update();
|
||||
}
|
||||
};
|
||||
|
||||
Command editSources = new() {MenuText = "Sources", ToolBarText = "Sources"};
|
||||
editSources.Executed += (_, _) => new RepoForm(repoManagement).ShowModal();
|
||||
|
||||
Command addPackage = new() {MenuText = "Add Package", ToolBarText = "Add Package"};
|
||||
addPackage.Executed += (_, _) =>
|
||||
{
|
||||
OpenFileDialog dialog = new() {MultiSelect = false, CheckFileExists = true, Filters = { new FileFilter("App package", ".zip")}};
|
||||
if (dialog.ShowDialog(mainForm) == DialogResult.Ok)
|
||||
{
|
||||
if (!tasks.Any(s => s is UploadTask t && t.ZipFile == dialog.FileName))
|
||||
{
|
||||
StringDialog sd = new("Package name") {Text = "New package"};
|
||||
sd.ShowModal();
|
||||
tasks.Add(factory.CreateUpload(dialog.FileName, sd.Text));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Command quitCommand = new() {MenuText = "Quit", Shortcut = Application.Instance.CommonModifier | Keys.Q};
|
||||
quitCommand.Executed += (_, _) => Application.Instance.Quit();
|
||||
|
||||
Command aboutCommand = new() {MenuText = "About Eto..."};
|
||||
aboutCommand.Executed += (_, _) => new AboutDialog().ShowDialog(mainForm);
|
||||
|
||||
Items.Add(new ButtonMenuItem
|
||||
{
|
||||
Text = "&File", Items =
|
||||
{
|
||||
reloadRepos,
|
||||
editSources,
|
||||
addPackage
|
||||
}
|
||||
});
|
||||
// File submenu
|
||||
// new ButtonMenuItem { Text = "&Edit", Items = { /* commands/items */ } },
|
||||
// new ButtonMenuItem { Text = "&View", Items = { /* commands/items */ } },
|
||||
/*ApplicationItems =
|
||||
{
|
||||
// application (OS X) or file menu (others)
|
||||
new ButtonMenuItem {Text = "&Preferences..."},
|
||||
},*/
|
||||
QuitItem = quitCommand;
|
||||
AboutItem = aboutCommand;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,79 +0,0 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using Eto.Drawing;
|
||||
using Eto.Forms;
|
||||
using UpToolLib.DataStructures;
|
||||
|
||||
namespace UpToolEto.Forms
|
||||
{
|
||||
public class DownloadDialog : Dialog
|
||||
{
|
||||
private readonly Uri _url;
|
||||
private readonly Application _application;
|
||||
private readonly IExternalFunctionality _platform;
|
||||
public State CurrentState = State.NotStarted;
|
||||
public byte[] Download = new byte[0];
|
||||
private readonly ProgressBar _bar;
|
||||
public DownloadDialog(Uri url, Application application, IExternalFunctionality platform)
|
||||
{
|
||||
_url = url;
|
||||
_application = application;
|
||||
_platform = platform;
|
||||
Title = "Downloader";
|
||||
Resizable = false;
|
||||
Maximizable = false;
|
||||
Minimizable = false;
|
||||
WindowStyle = WindowStyle.Utility;
|
||||
_bar = new();
|
||||
_bar.MaxValue = 100;
|
||||
Content = new StackLayout
|
||||
{
|
||||
Padding = 10,
|
||||
Items =
|
||||
{
|
||||
"Downloading " + url,
|
||||
new StackLayoutItem(_bar, HorizontalAlignment.Stretch, true)
|
||||
}
|
||||
};
|
||||
Size = new Size(700, 400);
|
||||
}
|
||||
|
||||
public void StartDownload()
|
||||
{
|
||||
CurrentState = State.Downloading;
|
||||
new Thread(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
WebClient client = new();
|
||||
client.DownloadProgressChanged += (_, args) => _application.Invoke(() =>
|
||||
{
|
||||
_bar.Value = args.ProgressPercentage;
|
||||
_application.RunIteration();
|
||||
});
|
||||
client.DownloadDataCompleted += (_, args) =>
|
||||
{
|
||||
CurrentState = State.Success;
|
||||
Download = args.Result;
|
||||
_application.Invoke(Close);
|
||||
};
|
||||
client.DownloadDataAsync(_url, client);
|
||||
}
|
||||
catch
|
||||
{
|
||||
CurrentState = State.Failed;
|
||||
_application.Invoke(Close);
|
||||
}
|
||||
}).Start();
|
||||
}
|
||||
|
||||
public enum State
|
||||
{
|
||||
NotStarted,
|
||||
Downloading,
|
||||
Failed,
|
||||
Success
|
||||
}
|
||||
}
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
using System;
|
||||
using Eto.Drawing;
|
||||
using Eto.Forms;
|
||||
using UpToolLib.DataStructures;
|
||||
|
||||
namespace UpToolEto.Forms
|
||||
{
|
||||
public class InitScreen : Form
|
||||
{
|
||||
private readonly Application _application;
|
||||
private readonly IExternalFunctionality _platform;
|
||||
private readonly Label _lab;
|
||||
public InitScreen(Application application, IExternalFunctionality platform)
|
||||
{
|
||||
_application = application;
|
||||
_platform = platform;
|
||||
Title = "UpTool2 Init";
|
||||
Resizable = false;
|
||||
Maximizable = false;
|
||||
Minimizable = false;
|
||||
WindowStyle = WindowStyle.None;
|
||||
_lab = new Label();
|
||||
Label header = new();
|
||||
header.Font = new Font(header.Font.Family, header.Font.Size * 2);
|
||||
header.Text = "UpTool2";
|
||||
Content = new StackLayout
|
||||
{
|
||||
Padding = 10,
|
||||
Items =
|
||||
{
|
||||
new StackLayoutItem(header, HorizontalAlignment.Center),
|
||||
new StackLayoutItem(_lab, HorizontalAlignment.Center)
|
||||
},
|
||||
VerticalContentAlignment = VerticalAlignment.Center
|
||||
};
|
||||
Shown += (_, _) => Size = new Size(700, 400);
|
||||
}
|
||||
|
||||
public void SetText(string text)
|
||||
{
|
||||
_application.Invoke(() =>
|
||||
{
|
||||
_platform.Log(text);
|
||||
_lab.Text = text;
|
||||
_application.RunIteration();
|
||||
});
|
||||
}
|
||||
|
||||
public override void Close() => _application.Invoke(() => base.Close());
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using Eto.Drawing;
|
||||
using Eto.Forms;
|
||||
using UpToolEto.Controls;
|
||||
using UpToolLib;
|
||||
using UpToolLib.DataStructures;
|
||||
using UpToolLib.v2.TaskQueue;
|
||||
|
||||
namespace UpToolEto.Forms
|
||||
{
|
||||
public partial class MainForm : Form
|
||||
{
|
||||
private readonly AppPanel _appPanel;
|
||||
private readonly IList<AppTask> _tasks;
|
||||
public MainForm(InitScreen init, UpToolLibMain lib, IExternalFunctionality platform, bool online)
|
||||
{
|
||||
_tasks = new List<AppTask>();
|
||||
Title = "UpTool2";
|
||||
MinimumSize = new Size(600, 100);
|
||||
AppList appList = new(lib.V1.AppExtras, (_, app) => _appPanel.SetApp(app), online, lib.V2.TaskFactory, _tasks);
|
||||
_appPanel = new AppPanel(lib.V2.TaskFactory, lib.V1.AppExtras, _tasks, platform, appList.Update);
|
||||
|
||||
Content = new StackLayout
|
||||
{
|
||||
Padding = 10,
|
||||
Items =
|
||||
{
|
||||
new StackLayoutItem(appList, VerticalAlignment.Stretch),
|
||||
new StackLayoutItem(_appPanel, VerticalAlignment.Stretch, true)
|
||||
},
|
||||
Orientation = Orientation.Horizontal
|
||||
};
|
||||
Menu = new UTMenuBar(this, lib.V2.RepoManagement, lib.V2.TaskFactory, _tasks, appList, platform);
|
||||
Shown += (_, _) => init.Close();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Eto.Forms;
|
||||
using UpToolLib.v2.TaskQueue;
|
||||
|
||||
namespace UpToolEto.Forms
|
||||
{
|
||||
public class QueueOverview : Dialog
|
||||
{
|
||||
private readonly IList<AppTask> _tasks;
|
||||
public bool Cancelled;
|
||||
CheckBoxList cbl;
|
||||
public List<AppTask> TasksResulting => cbl.SelectedValues.Select(s => (AppTask) s).ToList();
|
||||
|
||||
public QueueOverview(IList<AppTask> tasks)
|
||||
{
|
||||
_tasks = tasks;
|
||||
StackLayout layout = new();
|
||||
layout.Items.Add(new StackLayoutItem(new StackLayout()
|
||||
{
|
||||
Items =
|
||||
{
|
||||
new StackLayoutItem(new Button((_, _) =>
|
||||
{
|
||||
Cancelled = true;
|
||||
Close();
|
||||
})
|
||||
{
|
||||
Text = "Cancel"
|
||||
}, HorizontalAlignment.Stretch),
|
||||
new StackLayoutItem(new Button((_, _) =>
|
||||
{
|
||||
Close();
|
||||
})
|
||||
{
|
||||
Text = "OK"
|
||||
}, HorizontalAlignment.Stretch)
|
||||
},
|
||||
Orientation = Orientation.Horizontal
|
||||
}, HorizontalAlignment.Stretch));
|
||||
cbl = new CheckBoxList {DataStore = tasks, SelectedValues = tasks};
|
||||
layout.Items.Add(cbl);
|
||||
Content = layout;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Eto.Forms;
|
||||
using UpToolEto.Controls;
|
||||
using UpToolLib.DataStructures;
|
||||
using UpToolLib.v2;
|
||||
|
||||
namespace UpToolEto.Forms
|
||||
{
|
||||
public class RepoForm : Dialog
|
||||
{
|
||||
private readonly RepoManagement _management;
|
||||
private List<Repo> _repos = new();
|
||||
private StackLayout _layout;
|
||||
public RepoForm(RepoManagement management)
|
||||
{
|
||||
_management = management;
|
||||
_repos.AddRange(management.GetRepos());
|
||||
Title = "Sources";
|
||||
_layout = new StackLayout();
|
||||
Content = _layout;
|
||||
Update();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
_layout.Items.Clear();
|
||||
_layout.Items.Add(new StackLayoutItem(new Button((_, _) =>
|
||||
{
|
||||
_repos.Add(new Repo
|
||||
{
|
||||
Name = "New repo",
|
||||
Url = "https://example.com/repo.xml"
|
||||
});
|
||||
Update();
|
||||
})
|
||||
{
|
||||
Text = "Add",
|
||||
}, HorizontalAlignment.Stretch));
|
||||
StackLayout reposLayout = new();
|
||||
for (int i = 0; i < _repos.Count; i++)
|
||||
reposLayout.Items.Add(new StackLayoutItem(new RepoItem(_repos[i], i, Update, _repos), HorizontalAlignment.Stretch));
|
||||
_layout.Items.Add(new StackLayoutItem(new Scrollable{Content = reposLayout}, HorizontalAlignment.Stretch, true));
|
||||
_layout.Items.Add(new StackLayoutItem(new Button((_, _) =>
|
||||
{
|
||||
_management.Save(_repos);
|
||||
Close();
|
||||
})
|
||||
{
|
||||
Text = "Save"
|
||||
}, HorizontalAlignment.Stretch));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
using Eto.Forms;
|
||||
|
||||
namespace UpToolEto.Forms
|
||||
{
|
||||
public class StringDialog : Dialog
|
||||
{
|
||||
private readonly TextBox _tb;
|
||||
public string Text
|
||||
{
|
||||
get => _tb.Text;
|
||||
set => _tb.Text = value;
|
||||
}
|
||||
public StringDialog(string title)
|
||||
{
|
||||
_tb = new TextBox();
|
||||
Content = _tb;
|
||||
Title = title;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,164 +0,0 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Security.Cryptography;
|
||||
using System.Threading;
|
||||
using System.Xml;
|
||||
using Eto.Forms;
|
||||
using UpToolEto.Forms;
|
||||
using UpToolLib;
|
||||
using UpToolLib.DataStructures;
|
||||
using UpToolLib.v1;
|
||||
using UpToolLib.v1.Tool;
|
||||
using UpToolLib.v2;
|
||||
|
||||
namespace UpToolEto
|
||||
{
|
||||
public class Main
|
||||
{
|
||||
private readonly IExternalFunctionality _platform;
|
||||
private readonly Application _application;
|
||||
private readonly Action _activityExistsException;
|
||||
private readonly InitScreen _init;
|
||||
private readonly bool _skipFetch;
|
||||
public static bool DebugColors { get; private set; }
|
||||
|
||||
public Main(Application application, Action activityExistsException, string[] args)
|
||||
{
|
||||
_skipFetch = args.Contains("--skip-fetch");
|
||||
DebugColors = args.Contains("--debug-colors");
|
||||
_platform = new UTLibFunctions(application);
|
||||
_application = application;
|
||||
_activityExistsException = activityExistsException;
|
||||
_init = new(application, _platform);
|
||||
}
|
||||
|
||||
public void Entry()
|
||||
{
|
||||
new Thread(InitThread).Start();
|
||||
_application.Run(_init);
|
||||
}
|
||||
|
||||
private void InitThread()
|
||||
{
|
||||
UpToolLibMain lib = null;
|
||||
try
|
||||
{
|
||||
lib = new UpToolLibMain(_platform);
|
||||
_init.SetText("Initializing paths");
|
||||
if (!Directory.Exists(lib.V1.PathTool.Dir))
|
||||
Directory.CreateDirectory(lib.V1.PathTool.Dir);
|
||||
FixXml(lib.V1.XmlTool, lib.V1.PathTool);
|
||||
_init.SetText("Performing checks");
|
||||
bool online = false;
|
||||
UpdateCheck updateCheck = null;
|
||||
try
|
||||
{
|
||||
updateCheck = lib.V2.UpdateChecker.Check();
|
||||
online = true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
_platform.Log("Could not perform update check, starting offline");
|
||||
}
|
||||
if (online && UpdateCheck(updateCheck, lib.V1.PathTool, _init))
|
||||
_platform.Log("Quitting");
|
||||
else
|
||||
{
|
||||
if (!Directory.Exists(lib.V1.PathTool.GetRelative("Apps")))
|
||||
Directory.CreateDirectory(lib.V1.PathTool.GetRelative("Apps"));
|
||||
if (!_skipFetch && online)
|
||||
{
|
||||
_init.SetText("Fetching repos");
|
||||
lib.V2.RepoManagement.FetchRepos();
|
||||
}
|
||||
lib.V2.RepoManagement.GetReposFromDisk();
|
||||
_init.SetText("Opening");
|
||||
_application.Invoke(() => _application.Run(new MainForm(_init, lib, _platform, online)));
|
||||
}
|
||||
}
|
||||
catch (MutexLockLockedException)
|
||||
{
|
||||
_application.Invoke(() =>
|
||||
{
|
||||
_init.Close();
|
||||
_platform.OkDialog("Mutex property of other process, quitting");
|
||||
_activityExistsException();
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
lib?.Dispose();
|
||||
_platform.Log(e.ToString());
|
||||
}
|
||||
finally
|
||||
{
|
||||
lib?.Dispose();
|
||||
_application.Invoke(() => _application.Quit());
|
||||
}
|
||||
}
|
||||
|
||||
public void FixXml(XmlTool xmlTool, PathTool pathTool, bool throwOnError = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
xmlTool.FixXml();
|
||||
}
|
||||
catch (XmlException)
|
||||
{
|
||||
if (throwOnError) throw;
|
||||
_platform.OkDialog("Something went wrong while trying to parse XML. Retrying...");
|
||||
File.Delete(pathTool.InfoXml);
|
||||
FixXml(xmlTool, pathTool);
|
||||
}
|
||||
}
|
||||
|
||||
private bool UpdateCheck(UpdateCheck updateCheck, PathTool pathTool, InitScreen init)
|
||||
{
|
||||
init.SetText("Comparing online version");
|
||||
if (Assembly.GetExecutingAssembly().GetName().Version >= updateCheck.OnlineVersion) return false;
|
||||
if (PlatformCheck.IsWindows)
|
||||
{
|
||||
init.SetText("Downloading latest");
|
||||
(bool success, byte[] dl) = _platform.Download(updateCheck.Installer);
|
||||
if (!success)
|
||||
throw new Exception("Failed to update");
|
||||
init.SetText("Verifying");
|
||||
using (SHA256CryptoServiceProvider sha256 = new())
|
||||
{
|
||||
string pkgHash = BitConverter.ToString(sha256.ComputeHash(dl)).Replace("-", string.Empty).ToUpper();
|
||||
if (pkgHash != updateCheck.InstallerHash)
|
||||
throw new Exception(
|
||||
$"The hash is not equal to the one stored in the repo:\r\nPackage: {pkgHash}\r\nOnline: {updateCheck.InstallerHash}");
|
||||
}
|
||||
init.SetText("Installing");
|
||||
if (Directory.Exists(pathTool.GetRelative("Install", "tmp")))
|
||||
Directory.Delete(pathTool.GetRelative("Install", "tmp"), true);
|
||||
Directory.CreateDirectory(pathTool.GetRelative("Install", "tmp"));
|
||||
using (MemoryStream ms = new(dl))
|
||||
{
|
||||
using ZipArchive ar = new(ms);
|
||||
ar.ExtractToDirectory(pathTool.GetRelative("Install", "tmp"), true);
|
||||
}
|
||||
init.Close();
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = pathTool.GetRelative("Install", "tmp", "Installer.exe"),
|
||||
Arguments = "i -p",
|
||||
CreateNoWindow = true,
|
||||
WindowStyle = ProcessWindowStyle.Hidden,
|
||||
WorkingDirectory = pathTool.GetRelative("Install")
|
||||
});
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
_platform.OkDialog("A new version is available. Please install it");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using Eto.Drawing;
|
||||
using Eto.Forms;
|
||||
using UpToolEto.Forms;
|
||||
using UpToolLib;
|
||||
using UpToolLib.DataStructures;
|
||||
|
||||
namespace UpToolEto
|
||||
{
|
||||
public class UTLibFunctions : IExternalFunctionality
|
||||
{
|
||||
private readonly Application _application;
|
||||
private const int ImgSize = 32;
|
||||
public Tuple<bool, byte[]> Download(Uri link)
|
||||
{
|
||||
DownloadDialog dlg = new(link, _application, this);
|
||||
_application.AsyncInvoke(() => dlg.ShowModal());
|
||||
dlg.StartDownload();
|
||||
Log("Downloading " + link);
|
||||
while (dlg.CurrentState == DownloadDialog.State.Downloading) Thread.Sleep(20);
|
||||
Log("Download complete");
|
||||
return new Tuple<bool, byte[]>(dlg.CurrentState == DownloadDialog.State.Success, dlg.Download);
|
||||
}
|
||||
|
||||
public string FetchImageB64(Uri link)
|
||||
{
|
||||
using WebClient client = new();
|
||||
using Stream s = client.OpenRead(link);
|
||||
using Bitmap source = new(s);
|
||||
using Icon bmp = source.WithSize(ImgSize, ImgSize);
|
||||
using Bitmap bitmapResized = new(bmp);
|
||||
using MemoryStream ms = new();
|
||||
bitmapResized.Save(ms, ImageFormat.Png);
|
||||
return Convert.ToBase64String(ms.ToArray());
|
||||
}
|
||||
|
||||
public bool YesNoDialog(string text, bool defaultVal) =>
|
||||
_application.Invoke(() => MessageBox.Show(text, MessageBoxButtons.YesNo,
|
||||
defaultButton: defaultVal ? MessageBoxDefaultButton.Yes : MessageBoxDefaultButton.No)) ==
|
||||
DialogResult.Yes;
|
||||
|
||||
public void OkDialog(string text) => _application.Invoke(() => MessageBox.Show(text));
|
||||
|
||||
public object GetDefaultIcon() => Bitmap.FromResource("UpToolLib.C_64.ico", typeof(UpToolLibMain)).WithSize(ImgSize, ImgSize);
|
||||
|
||||
public object ImageFromB64(string b64) => new Bitmap(Convert.FromBase64String(b64)).WithSize(ImgSize, ImgSize);
|
||||
|
||||
public void Log(string text)
|
||||
{
|
||||
Console.WriteLine(text);
|
||||
//TODO implement visual logging
|
||||
}
|
||||
|
||||
public UTLibFunctions(Application application) => _application = application;
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Eto.Forms" Version="2.5.10" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\UpToolLib\UpToolLib.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -3,11 +3,10 @@ using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using UpToolLib.DataStructures;
|
||||
using UpToolLib.v1.Tool;
|
||||
using UpToolLib.Tool;
|
||||
using static System.Environment;
|
||||
|
||||
namespace UpToolLib.v2
|
||||
namespace UpToolLib.DataStructures
|
||||
{
|
||||
public struct App : IEquatable<App>
|
||||
{
|
||||
@ -22,10 +21,9 @@ namespace UpToolLib.v2
|
||||
public readonly object Icon;
|
||||
public readonly bool Runnable;
|
||||
public readonly string MainFile;
|
||||
private readonly PathTool _pathTool;
|
||||
|
||||
internal App(string name, string description, Version version, string file, bool local, string hash, Guid iD,
|
||||
Color color, object icon, bool runnable, string mainFile, PathTool pathTool)
|
||||
public App(string name, string description, Version version, string file, bool local, string hash, Guid iD,
|
||||
Color color, object icon, bool runnable, string mainFile)
|
||||
{
|
||||
Name = name ?? throw new ArgumentNullException(nameof(name));
|
||||
Description = description ?? throw new ArgumentNullException(nameof(description));
|
||||
@ -38,7 +36,6 @@ namespace UpToolLib.v2
|
||||
Icon = icon ?? throw new ArgumentNullException(nameof(icon));
|
||||
Runnable = runnable;
|
||||
MainFile = mainFile ?? throw new ArgumentNullException(nameof(mainFile));
|
||||
_pathTool = pathTool;
|
||||
}
|
||||
|
||||
public Status Status
|
||||
@ -78,8 +75,8 @@ Object Hash Code: {GetHashCode()}";
|
||||
|
||||
public static bool operator !=(App left, App right) => !(left == right);
|
||||
|
||||
public string AppPath => _pathTool.GetAppPath(Id);
|
||||
public string DataPath => _pathTool.GetDataPath(Id);
|
||||
public string InfoPath => _pathTool.GetInfoPath(Id);
|
||||
public string AppPath => PathTool.GetAppPath(Id);
|
||||
public string DataPath => PathTool.GetDataPath(Id);
|
||||
public string InfoPath => PathTool.GetInfoPath(Id);
|
||||
}
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
namespace UpToolLib.DataStructures
|
||||
{
|
||||
public class Repo
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Url { get; set; }
|
||||
}
|
||||
}
|
@ -9,11 +9,6 @@ namespace UpToolLib.DataStructures
|
||||
Updatable = 2,
|
||||
Installed = 4,
|
||||
Local = 8,
|
||||
All = 0
|
||||
}
|
||||
|
||||
public static class StatusExtensions
|
||||
{
|
||||
public static bool Contains(this Status status, Status other) => (status & other) == other;
|
||||
All = 15
|
||||
}
|
||||
}
|
14
UpToolLib/ExternalFunctionalityManager.cs
Normal file
14
UpToolLib/ExternalFunctionalityManager.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using UpToolLib.DataStructures;
|
||||
|
||||
namespace UpToolLib
|
||||
{
|
||||
public static class ExternalFunctionalityManager
|
||||
{
|
||||
internal static IExternalFunctionality Instance;
|
||||
|
||||
public static void Init(IExternalFunctionality externalFunctionality)
|
||||
{
|
||||
Instance = externalFunctionality;
|
||||
}
|
||||
}
|
||||
}
|
18
UpToolLib/GlobalVariables.cs
Normal file
18
UpToolLib/GlobalVariables.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UpToolLib.DataStructures;
|
||||
|
||||
namespace UpToolLib
|
||||
{
|
||||
public static class GlobalVariables
|
||||
{
|
||||
public const string Windows = "WINDOWS";
|
||||
public const string Posix = "POSIX";
|
||||
public static readonly Dictionary<Guid, App> Apps = new Dictionary<Guid, App>();
|
||||
public static Version MinimumVer => Version.Parse("0.0.0.0");
|
||||
|
||||
public static string CurrentPlatform =>
|
||||
PlatformCheck.IsWindows ? Windows :
|
||||
PlatformCheck.IsPosix ? Posix : throw new Exception("Unexpeccted PlatformCheck");
|
||||
}
|
||||
}
|
44
UpToolLib/Lock.cs
Normal file
44
UpToolLib/Lock.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
|
||||
namespace UpToolLib
|
||||
{
|
||||
public static class MutexLock
|
||||
{
|
||||
private static Mutex _mutex;
|
||||
private static bool _hasHandle;
|
||||
|
||||
public static void Lock()
|
||||
{
|
||||
_mutex = new Mutex(false,
|
||||
"Global\\{c0c1e002-9e13-4e8f-a035-dbdc5128e00e}",
|
||||
out bool _);
|
||||
_hasHandle = false;
|
||||
try
|
||||
{
|
||||
_hasHandle = _mutex.WaitOne(5000, false);
|
||||
if (_hasHandle)
|
||||
return;
|
||||
throw new MutexLockLockedException();
|
||||
}
|
||||
catch (AbandonedMutexException)
|
||||
{
|
||||
#if DEBUG
|
||||
Debug.WriteLine("Mutex abandoned");
|
||||
#endif
|
||||
_hasHandle = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Unlock()
|
||||
{
|
||||
if (_hasHandle)
|
||||
_mutex.ReleaseMutex();
|
||||
}
|
||||
}
|
||||
|
||||
public class MutexLockLockedException : Exception
|
||||
{
|
||||
}
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace UpToolLib
|
||||
{
|
||||
public class MutexLockLockedException : Exception
|
||||
{
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace UpToolLib.v1
|
||||
namespace UpToolLib
|
||||
{
|
||||
public static class PlatformCheck
|
||||
{
|
||||
@ -13,11 +13,5 @@ namespace UpToolLib.v1
|
||||
.Contains(Environment.OSVersion.Platform);
|
||||
|
||||
public static bool IsPosix => !IsWindows;
|
||||
|
||||
public const string Windows = "WINDOWS";
|
||||
public const string Posix = "POSIX";
|
||||
public static string CurrentPlatform =>
|
||||
IsWindows ? Windows :
|
||||
IsPosix ? Posix : throw new Exception("Unexpected PlatformCheck");
|
||||
}
|
||||
}
|
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
@ -4,43 +4,29 @@ using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using UpToolLib.v2;
|
||||
using UpToolLib.DataStructures;
|
||||
|
||||
namespace UpToolLib.v1.Tool
|
||||
namespace UpToolLib.Tool
|
||||
{
|
||||
public class AppExtras
|
||||
public static class AppExtras
|
||||
{
|
||||
private readonly AppInstall _appInstall;
|
||||
private readonly PathTool _pathTool;
|
||||
private readonly IDictionary<Guid, App> _apps;
|
||||
|
||||
internal AppExtras(AppInstall appInstall, PathTool pathTool, IDictionary<Guid, App> apps)
|
||||
{
|
||||
_appInstall = appInstall;
|
||||
_pathTool = pathTool;
|
||||
_apps = apps;
|
||||
}
|
||||
|
||||
public Process RunApp(App app) => RunApp(app, app.MainFile, "");
|
||||
public Process RunApp(App app, string arguments) => RunApp(app, app.MainFile, arguments);
|
||||
public Process RunApp(App app, string file, string arguments) =>
|
||||
public static Process RunApp(App app) =>
|
||||
Process.Start(
|
||||
new ProcessStartInfo
|
||||
{
|
||||
FileName = Path.Combine(app.DataPath, file),
|
||||
Arguments = arguments,
|
||||
FileName = Path.Combine(app.DataPath, app.MainFile),
|
||||
WorkingDirectory = app.DataPath
|
||||
});
|
||||
|
||||
public void Update(App app, bool overwrite)
|
||||
public static void Update(App app, bool overwrite)
|
||||
{
|
||||
Remove(app, overwrite);
|
||||
_appInstall.Install(app, overwrite);
|
||||
AppInstall.Install(app, overwrite);
|
||||
}
|
||||
|
||||
public void Remove(App app, bool deleteAll)
|
||||
public static void Remove(App app, bool deleteAll)
|
||||
{
|
||||
string tmp = _pathTool.TempPath;
|
||||
string tmp = PathTool.TempPath;
|
||||
if (Directory.Exists(tmp))
|
||||
Directory.Delete(tmp, true);
|
||||
Directory.CreateDirectory(tmp);
|
||||
@ -57,7 +43,7 @@ namespace UpToolLib.v1.Tool
|
||||
}).WaitForExit();*/
|
||||
int key = PlatformCheck.IsWindows ? 0 :
|
||||
File.Exists(Path.Combine(tmp, "Remove.sh")) ? 1 : 2;
|
||||
ProcessStartInfo prc = new()
|
||||
ProcessStartInfo prc = new ProcessStartInfo
|
||||
{
|
||||
FileName = key switch
|
||||
{
|
||||
@ -92,7 +78,7 @@ namespace UpToolLib.v1.Tool
|
||||
Directory.Delete(app.AppPath, true);
|
||||
}
|
||||
|
||||
private void CheckDirecory(string tmp, string app)
|
||||
private static void CheckDirecory(string tmp, string app)
|
||||
{
|
||||
foreach (string file in Directory.GetFiles(tmp))
|
||||
{
|
||||
@ -106,13 +92,12 @@ namespace UpToolLib.v1.Tool
|
||||
Directory.Delete(app);
|
||||
}
|
||||
|
||||
public App[] FindApps(string identifier)
|
||||
public static App[] FindApps(string identifier)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(identifier))
|
||||
return _apps.Values.ToArray();
|
||||
IEnumerable<KeyValuePair<Guid, App>> tmp1 = _apps.Where(s => s.Key.ToString().StartsWith(identifier));
|
||||
tmp1 = tmp1.Concat(_apps.Where(s => s.Value.Name.Contains(identifier)));
|
||||
tmp1 = tmp1.Concat(_apps.Where(s => s.Value.Description.Contains(identifier)));
|
||||
Dictionary<Guid, App> tmp = GlobalVariables.Apps;
|
||||
IEnumerable<KeyValuePair<Guid, App>> tmp1 = tmp.Where(s => s.Key.ToString().StartsWith(identifier));
|
||||
tmp1 = tmp1.Concat(tmp.Where(s => s.Value.Name.Contains(identifier)));
|
||||
tmp1 = tmp1.Concat(tmp.Where(s => s.Value.Description.Contains(identifier)));
|
||||
return tmp1.Select(s => s.Value).ToArray();
|
||||
}
|
||||
}
|
@ -5,27 +5,17 @@ using System.IO.Compression;
|
||||
using System.Security.Cryptography;
|
||||
using System.Xml.Linq;
|
||||
using UpToolLib.DataStructures;
|
||||
using UpToolLib.v2;
|
||||
|
||||
namespace UpToolLib.v1.Tool
|
||||
namespace UpToolLib.Tool
|
||||
{
|
||||
public class AppInstall
|
||||
public static class AppInstall
|
||||
{
|
||||
private readonly IExternalFunctionality _platform;
|
||||
private readonly PathTool _pathTool;
|
||||
|
||||
internal AppInstall(IExternalFunctionality platform, PathTool pathTool)
|
||||
{
|
||||
_platform = platform;
|
||||
_pathTool = pathTool;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Install an application
|
||||
/// </summary>
|
||||
/// <param name="appI">The app to install</param>
|
||||
/// <param name="force">Set to true to overwrite all old data</param>
|
||||
public void Install(App appI, bool force)
|
||||
public static void Install(App appI, bool force)
|
||||
{
|
||||
string app = "";
|
||||
string tmp = "";
|
||||
@ -34,7 +24,7 @@ namespace UpToolLib.v1.Tool
|
||||
{
|
||||
#endif
|
||||
app = appI.AppPath;
|
||||
tmp = _pathTool.TempPath;
|
||||
tmp = PathTool.TempPath;
|
||||
if (Directory.Exists(tmp))
|
||||
Directory.Delete(tmp, true);
|
||||
Directory.CreateDirectory(tmp);
|
||||
@ -49,10 +39,10 @@ namespace UpToolLib.v1.Tool
|
||||
if (!Directory.Exists(app))
|
||||
Directory.CreateDirectory(app);
|
||||
}
|
||||
(bool dlSuccess, byte[] dlData) = _platform.Download(new Uri(appI.File));
|
||||
(bool dlSuccess, byte[] dlData) = ExternalFunctionalityManager.Instance.Download(new Uri(appI.File));
|
||||
if (!dlSuccess)
|
||||
throw new Exception("Download failed");
|
||||
using (SHA256CryptoServiceProvider sha256 = new())
|
||||
using (SHA256CryptoServiceProvider sha256 = new SHA256CryptoServiceProvider())
|
||||
{
|
||||
string pkgHash = BitConverter.ToString(sha256.ComputeHash(dlData)).Replace("-", string.Empty)
|
||||
.ToUpper();
|
||||
@ -81,7 +71,7 @@ Online: {appI.Hash.ToUpper()}");
|
||||
#endif
|
||||
}
|
||||
|
||||
public void InstallZip(string zipPath, App meta, bool force)
|
||||
public static void InstallZip(string zipPath, App meta, bool force)
|
||||
{
|
||||
string app = "";
|
||||
string tmp = "";
|
||||
@ -89,7 +79,7 @@ Online: {appI.Hash.ToUpper()}");
|
||||
{
|
||||
app = meta.AppPath;
|
||||
Directory.CreateDirectory(app);
|
||||
tmp = _pathTool.TempPath;
|
||||
tmp = PathTool.TempPath;
|
||||
if (Directory.Exists(tmp))
|
||||
Directory.Delete(tmp, true);
|
||||
Directory.CreateDirectory(tmp);
|
||||
@ -112,13 +102,13 @@ Online: {appI.Hash.ToUpper()}");
|
||||
//Use
|
||||
//PowerShell -Command "Add-Type -AssemblyName PresentationFramework;[System.Windows.MessageBox]::Show('Hello World')"
|
||||
//for message boxes
|
||||
private void CompleteInstall(App app, bool force) => CompleteInstall(app.AppPath, app.Name,
|
||||
private static void CompleteInstall(App app, bool force) => CompleteInstall(app.AppPath, app.Name,
|
||||
app.Description, app.Version, app.MainFile, force);
|
||||
|
||||
private void CompleteInstall(string appPath, string name, string description, Version version,
|
||||
private static void CompleteInstall(string appPath, string name, string description, Version version,
|
||||
string mainFile, bool force)
|
||||
{
|
||||
string tmp = _pathTool.TempPath;
|
||||
string tmp = PathTool.TempPath;
|
||||
ZipFile.ExtractToDirectory(Path.Combine(appPath, "package.zip"), tmp);
|
||||
if (force)
|
||||
Directory.Move(Path.Combine(tmp, "Data"), Path.Combine(appPath, "app"));
|
||||
@ -127,7 +117,7 @@ Online: {appI.Hash.ToUpper()}");
|
||||
CopyAll(Path.Combine(tmp, "Data"), Path.Combine(appPath, "app"));
|
||||
Directory.Delete(Path.Combine(tmp, "Data"), true);
|
||||
}
|
||||
XElement el = new("app", new XElement("Name", name), new XElement("Description", description),
|
||||
XElement el = new XElement("app", new XElement("Name", name), new XElement("Description", description),
|
||||
new XElement("Version", version));
|
||||
if (mainFile != null)
|
||||
el.Add(new XElement(new XElement("MainFile", mainFile)));
|
||||
@ -161,7 +151,7 @@ Online: {appI.Hash.ToUpper()}");
|
||||
}).WaitForExit();*/
|
||||
int key = PlatformCheck.IsWindows ? 0 :
|
||||
File.Exists(Path.Combine(tmp, "Install.sh")) ? 1 : 2;
|
||||
ProcessStartInfo prc = new()
|
||||
ProcessStartInfo prc = new ProcessStartInfo
|
||||
{
|
||||
FileName = key switch
|
||||
{
|
||||
@ -185,7 +175,7 @@ Online: {appI.Hash.ToUpper()}");
|
||||
Process.Start(prc)?.WaitForExit();
|
||||
}
|
||||
|
||||
private void CopyAll(string source, string target)
|
||||
private static void CopyAll(string source, string target)
|
||||
{
|
||||
if (string.Equals(Path.GetFullPath(source), Path.GetFullPath(target),
|
||||
StringComparison.CurrentCultureIgnoreCase))
|
25
UpToolLib/Tool/PathTool.cs
Normal file
25
UpToolLib/Tool/PathTool.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace UpToolLib.Tool
|
||||
{
|
||||
public static class PathTool
|
||||
{
|
||||
public static string Dir =>
|
||||
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "UpTool2");
|
||||
|
||||
public static string TempPath => GetRelative("tmp");
|
||||
public static string AppsPath => GetRelative("Apps");
|
||||
public static string InfoXml => GetRelative("info.xml");
|
||||
|
||||
public static string GetRelative(params string[] segments) =>
|
||||
Path.Combine(new[] {Dir}.Concat(segments).ToArray());
|
||||
|
||||
public static string GetAppPath(Guid app) => Path.Combine(AppsPath, app.ToString());
|
||||
|
||||
public static string GetDataPath(Guid app) => Path.Combine(GetAppPath(app), "app");
|
||||
|
||||
public static string GetInfoPath(Guid app) => Path.Combine(GetAppPath(app), "info.xml");
|
||||
}
|
||||
}
|
@ -5,93 +5,41 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using UpToolLib.DataStructures;
|
||||
using UpToolLib.v1;
|
||||
using UpToolLib.v1.Tool;
|
||||
|
||||
namespace UpToolLib.v2
|
||||
namespace UpToolLib.Tool
|
||||
{
|
||||
public class RepoManagement
|
||||
public static class RepoManagement
|
||||
{
|
||||
private readonly IExternalFunctionality _platform;
|
||||
private readonly XmlTool _xmlTool;
|
||||
private readonly PathTool _pathTool;
|
||||
private readonly AppFactory _appFactory;
|
||||
private readonly IDictionary<Guid, App> _apps;
|
||||
|
||||
public RepoManagement(IExternalFunctionality platform, XmlTool xmlTool, PathTool pathTool, AppFactory appFactory, IDictionary<Guid, App> apps)
|
||||
public static void FetchRepos()
|
||||
{
|
||||
_platform = platform;
|
||||
_xmlTool = xmlTool;
|
||||
_pathTool = pathTool;
|
||||
_appFactory = appFactory;
|
||||
_apps = apps;
|
||||
}
|
||||
|
||||
public void Save(IEnumerable<Repo> repos)
|
||||
{
|
||||
XDocument doc = XDocument.Load(_pathTool.InfoXml);
|
||||
XElement reposEl = doc.Element("meta").Element("Repos");
|
||||
reposEl.RemoveNodes();
|
||||
foreach (Repo repo in repos)
|
||||
reposEl.Add(new XElement("Repo", new XElement("Name", repo.Name), new XElement("Link", repo.Url)));
|
||||
doc.Save(_pathTool.InfoXml);
|
||||
}
|
||||
|
||||
public IEnumerable<Repo> GetRepos()
|
||||
{
|
||||
_xmlTool.FixXml();
|
||||
XDocument doc = XDocument.Load(_pathTool.InfoXml);
|
||||
XElement reposEl = doc.Element("meta").Element("Repos");
|
||||
List<Repo> repos = new();
|
||||
foreach (XElement repo in reposEl.Elements("Repo"))
|
||||
{
|
||||
repos.Add(new Repo
|
||||
{
|
||||
Name = repo.Element("Name").Value,
|
||||
Url = repo.Element("Link").Value
|
||||
});
|
||||
}
|
||||
return repos.ToArray();
|
||||
}
|
||||
|
||||
public void FetchRepos()
|
||||
{
|
||||
_xmlTool.FixXml();
|
||||
XElement meta = XDocument.Load(_pathTool.InfoXml).Element("meta");
|
||||
List<XElement> tmpAppsList = new();
|
||||
XmlTool.FixXml();
|
||||
XElement meta = XDocument.Load(PathTool.InfoXml).Element("meta");
|
||||
List<XElement> tmpAppsList = new List<XElement>();
|
||||
List<string> repArr = meta.Element("Repos").Elements("Repo").Select(s => s.Element("Link").Value).Distinct()
|
||||
.ToList();
|
||||
int i = 0;
|
||||
while (i < repArr.Count)
|
||||
{
|
||||
string status = "Initializing";
|
||||
#if !DEBUG
|
||||
try
|
||||
{
|
||||
#endif
|
||||
_platform.Log($"[{i + 1}] Loading {repArr[i]}");
|
||||
status = $"Loading {repArr[i]}";
|
||||
XDocument repo = XDocument.Load(new Uri(repArr[i]).AbsoluteUri);
|
||||
status = $"Extracting repolinks";
|
||||
ExternalFunctionalityManager.Instance.Log($"[{i + 1}] Loading {repArr[i]}");
|
||||
XDocument repo = XDocument.Load(new Uri(repArr[i]).TryUnshorten().AbsoluteUri);
|
||||
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
|
||||
.Where(a => a.Element("ID").Value == app.Element("ID").Value).Any(a =>
|
||||
GetVer(a.Element("Version")) >= GetVer(app.Element("Version")))).ToArray()
|
||||
GetVer(a.Element("Version")) >= app.Element("Version").GetVer())).ToArray()
|
||||
.Concat(repo.Element("repo").Elements("applink")
|
||||
.Select(s =>
|
||||
{
|
||||
_platform.Log($"- Loading {s.Value}");
|
||||
status = $"Fetching app data tag: {s.Value}";
|
||||
XElement ret = XDocument.Load(new Uri(s.Value).AbsoluteUri)
|
||||
.Element("app");
|
||||
return ret;
|
||||
ExternalFunctionalityManager.Instance.Log($"- Loading {s.Value}");
|
||||
return XDocument.Load(new Uri(s.Value).TryUnshorten().AbsoluteUri).Element("app");
|
||||
}))
|
||||
.ToArray();
|
||||
status = $"Creating app cache";
|
||||
foreach (XElement app in tmpApparray)
|
||||
{
|
||||
//"Sanity check"
|
||||
@ -103,7 +51,7 @@ namespace UpToolLib.v2
|
||||
new XElement("Description", app.Element("Description").Value),
|
||||
new XElement("Version", app.Element("Version").Value),
|
||||
new XElement("ID", app.Element("ID").Value),
|
||||
new XElement("File", new Uri(app.Element("File").Value).ToString()),
|
||||
new XElement("File", app.Element("File").Value),
|
||||
new XElement("Hash", app.Element("Hash").Value)
|
||||
));
|
||||
if (app.Element("MainFile") != null)
|
||||
@ -113,7 +61,8 @@ namespace UpToolLib.v2
|
||||
{
|
||||
tmpAppsList.Last()
|
||||
.Add(new XElement("Icon",
|
||||
_platform.FetchImageB64(new Uri(app.Element("Icon").Value))));
|
||||
ExternalFunctionalityManager.Instance.FetchImageB64(
|
||||
new Uri(app.Element("Icon").Value).TryUnshorten())));
|
||||
}
|
||||
catch
|
||||
{
|
||||
@ -121,9 +70,9 @@ namespace UpToolLib.v2
|
||||
}
|
||||
tmpAppsList.Last().Add(new XElement("Platform",
|
||||
app.Element("Platform") == null ||
|
||||
!new[] {PlatformCheck.Posix, PlatformCheck.Windows}.Contains(app.Element("Platform")
|
||||
!new[] {GlobalVariables.Posix, GlobalVariables.Windows}.Contains(app.Element("Platform")
|
||||
.Value)
|
||||
? PlatformCheck.CurrentPlatform
|
||||
? GlobalVariables.CurrentPlatform
|
||||
: app.Element("Platform").Value));
|
||||
XElement app1 = app;
|
||||
if (tmpAppsList.Count(a => a.Element("ID").Value == app1.Element("ID").Value) > 1)
|
||||
@ -135,8 +84,8 @@ namespace UpToolLib.v2
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_platform.OkDialog(
|
||||
$"Failed to load repo: {repArr[i]}{Environment.NewLine}Last status was: {status}{Environment.NewLine}{e}");
|
||||
ExternalFunctionalityManager.Instance.OkDialog(
|
||||
$"Failed to load repo: {repArr[i]}{Environment.NewLine}{e}");
|
||||
}
|
||||
#endif
|
||||
i++;
|
||||
@ -148,29 +97,29 @@ namespace UpToolLib.v2
|
||||
XElement repos = meta.Element("LocalRepo");
|
||||
repos.RemoveNodes();
|
||||
tmpAppsList.ForEach(app => repos.Add(app));
|
||||
meta.Save(_pathTool.InfoXml);
|
||||
meta.Save(PathTool.InfoXml);
|
||||
}
|
||||
|
||||
private Version GetVer(XElement el) =>
|
||||
private static Version GetVer(this XElement el) =>
|
||||
int.TryParse(el.Value, out int i) ? new Version(0, 0, 0, i) : Version.Parse(el.Value);
|
||||
|
||||
/// <summary>
|
||||
/// Load the repository cache
|
||||
/// </summary>
|
||||
/// <param name="errorHandler">Function to call on an exception, will ask the user whether he wants to quit</param>
|
||||
public void GetReposFromDisk()
|
||||
public static void GetReposFromDisk()
|
||||
{
|
||||
_apps.Clear();
|
||||
string xml = _pathTool.InfoXml;
|
||||
GlobalVariables.Apps.Clear();
|
||||
string xml = PathTool.InfoXml;
|
||||
XDocument.Load(xml).Element("meta").Element("LocalRepo").Elements().ToList().ForEach(app =>
|
||||
{
|
||||
if (app.Element("Platform").Value != PlatformCheck.CurrentPlatform) return;
|
||||
if (app.Element("Platform").Value != GlobalVariables.CurrentPlatform) return;
|
||||
Guid id = Guid.Parse(app.Element("ID").Value);
|
||||
string locInPath = _pathTool.GetInfoPath(id);
|
||||
string locInPath = PathTool.GetInfoPath(id);
|
||||
XElement locIn = File.Exists(locInPath) ? XDocument.Load(locInPath).Element("app") : app;
|
||||
if (int.TryParse(app.Element("Version").Value, out _))
|
||||
app.Element("Version").Value = UpToolLibV1.MinimumVer.ToString();
|
||||
_apps.Add(id, _appFactory.CreateApp(
|
||||
app.Element("Version").Value = GlobalVariables.MinimumVer.ToString();
|
||||
GlobalVariables.Apps.Add(id, new App(
|
||||
locIn.Element("Name").Value,
|
||||
locIn.Element("Description").Value,
|
||||
Version.Parse(app.Element("Version").Value),
|
||||
@ -180,38 +129,38 @@ namespace UpToolLib.v2
|
||||
id,
|
||||
Color.White,
|
||||
app.Element("Icon") == null
|
||||
? _platform.GetDefaultIcon()
|
||||
: _platform.ImageFromB64(app.Element("Icon").Value),
|
||||
? ExternalFunctionalityManager.Instance.GetDefaultIcon()
|
||||
: ExternalFunctionalityManager.Instance.ImageFromB64(app.Element("Icon").Value),
|
||||
locIn.Element("MainFile") != null || app.Element("MainFile") != null,
|
||||
locIn.Element("MainFile") == null
|
||||
? app.Element("MainFile") == null ? "" : app.Element("MainFile").Value
|
||||
: locIn.Element("MainFile").Value
|
||||
));
|
||||
});
|
||||
Directory.GetDirectories(_pathTool.AppsPath)
|
||||
Directory.GetDirectories(PathTool.AppsPath)
|
||||
.Where(s => Guid.TryParse(Path.GetFileName(s), out Guid guid) &&
|
||||
!_apps.ContainsKey(guid)).ToList().ForEach(s =>
|
||||
!GlobalVariables.Apps.ContainsKey(guid)).ToList().ForEach(s =>
|
||||
{
|
||||
Guid tmp = Guid.Parse(Path.GetFileName(s));
|
||||
try
|
||||
{
|
||||
XElement data = XDocument.Load(_pathTool.GetInfoPath(tmp)).Element("app");
|
||||
_apps.Add(tmp,
|
||||
_appFactory.CreateApp($"(local) {data.Element("Name").Value}", data.Element("Description").Value,
|
||||
UpToolLibV1.MinimumVer, "", true, "", tmp, Color.Red,
|
||||
_platform.GetDefaultIcon(),
|
||||
XElement data = XDocument.Load(PathTool.GetInfoPath(tmp)).Element("app");
|
||||
GlobalVariables.Apps.Add(tmp,
|
||||
new App($"(local) {data.Element("Name").Value}", data.Element("Description").Value,
|
||||
GlobalVariables.MinimumVer, "", true, "", tmp, Color.Red,
|
||||
ExternalFunctionalityManager.Instance.GetDefaultIcon(),
|
||||
data.Element("MainFile") != null,
|
||||
data.Element("MainFile") == null ? "" : data.Element("MainFile").Value));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (_platform.YesNoDialog(
|
||||
if (ExternalFunctionalityManager.Instance.YesNoDialog(
|
||||
$@"An error occured while loading this local repo:
|
||||
{e.Message}
|
||||
Do you want to exit? Otherwise the folder will be deleted, possibly causeing problems later.", false))
|
||||
Environment.Exit(0);
|
||||
else
|
||||
Directory.Delete(_pathTool.GetAppPath(tmp), true);
|
||||
Directory.Delete(PathTool.GetAppPath(tmp), true);
|
||||
}
|
||||
});
|
||||
}
|
20
UpToolLib/Tool/TryUnshorten.cs
Normal file
20
UpToolLib/Tool/TryUnshorten.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using CC_Functions.Misc;
|
||||
|
||||
namespace UpToolLib.Tool
|
||||
{
|
||||
public static class TryUnshortenExt
|
||||
{
|
||||
public static Uri TryUnshorten(this Uri self)
|
||||
{
|
||||
try
|
||||
{
|
||||
return self.Unshorten();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return self;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
49
UpToolLib/Tool/XmlTool.cs
Normal file
49
UpToolLib/Tool/XmlTool.cs
Normal file
@ -0,0 +1,49 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace UpToolLib.Tool
|
||||
{
|
||||
public static class XmlTool
|
||||
{
|
||||
public static void FixXml()
|
||||
{
|
||||
if (!Directory.Exists(PathTool.AppsPath))
|
||||
Directory.CreateDirectory(PathTool.AppsPath);
|
||||
if (!File.Exists(PathTool.InfoXml) || XDocument.Load(PathTool.InfoXml).Element("meta") == null)
|
||||
new XElement("meta").Save(PathTool.InfoXml);
|
||||
XDocument x = XDocument.Load(PathTool.InfoXml);
|
||||
XElement meta = x.Element("meta");
|
||||
if (meta.Element("UpdateSource") == null)
|
||||
meta.Add(new XElement("UpdateSource"));
|
||||
if (new[]
|
||||
{
|
||||
"",
|
||||
"https://raw.githubusercontent.com/CreepyCrafter24/UpTool2/master/Meta.xml",
|
||||
"https://raw.githubusercontent.com/JFronny/UpTool2/master/Meta.xml",
|
||||
"https://gist.githubusercontent.com/JFronny/f1ccbba3d8a2f5862592bb29fdb612c4/raw/Meta.xml"
|
||||
}
|
||||
.Contains(meta.Element("UpdateSource").Value))
|
||||
meta.Element("UpdateSource").Value =
|
||||
"https://github.com/JFronny/UpTool2/releases/latest/download/meta.xml";
|
||||
if (meta.Element("Repos") == null)
|
||||
meta.Add(new XElement("Repos"));
|
||||
if (meta.Element("Repos").Elements("Repo").Count() == 0)
|
||||
meta.Element("Repos").Add(new XElement("Repo", new XElement("Name", "UpTool2 official Repo"),
|
||||
new XElement("Link",
|
||||
"https://gist.githubusercontent.com/JFronny/f1ccbba3d8a2f5862592bb29fdb612c4/raw/Repo.xml")));
|
||||
meta.Element("Repos").Elements("Repo").Select(s => s.Element("Link"))
|
||||
.Where(s => new[]
|
||||
{
|
||||
null, "https://github.com/JFronny/UpTool2/releases/download/Repo/Repo.xml",
|
||||
"https://raw.githubusercontent.com/JFronny/UpTool2/master/Repo.xml"
|
||||
}.Contains(s.Value))
|
||||
.ToList().ForEach(s =>
|
||||
s.Value =
|
||||
"https://gist.githubusercontent.com/JFronny/f1ccbba3d8a2f5862592bb29fdb612c4/raw/Repo.xml");
|
||||
if (meta.Element("LocalRepo") == null)
|
||||
meta.Add(new XElement("LocalRepo"));
|
||||
x.Save(PathTool.InfoXml);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,16 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<Deterministic>false</Deterministic>
|
||||
<AssemblyVersion>1.0.*</AssemblyVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Remove="C_64.ico" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="C_64.ico" />
|
||||
<PackageReference Include="CC-Functions.Misc" Version="1.1.7399.26972" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,38 +0,0 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using UpToolLib.DataStructures;
|
||||
using UpToolLib.v1;
|
||||
using UpToolLib.v2;
|
||||
|
||||
namespace UpToolLib
|
||||
{
|
||||
public class UpToolLibMain : IDisposable
|
||||
{
|
||||
private static Mutex _mutex;
|
||||
public UpToolLibMain(IExternalFunctionality platform)
|
||||
{
|
||||
V1 = new UpToolLibV1(platform);
|
||||
V2 = new UpToolLibV2(platform, V1.Installer, V1.AppExtras, V1.PathTool, V1.XmlTool, V1.Apps);
|
||||
_mutex = new Mutex(false,
|
||||
"Global\\{c0c1e002-9e13-4e8f-a035-dbdc5128e00e}",
|
||||
out bool _);
|
||||
try
|
||||
{
|
||||
if (_mutex.WaitOne(5000, false))
|
||||
return;
|
||||
throw new MutexLockLockedException();
|
||||
}
|
||||
catch (AbandonedMutexException)
|
||||
{
|
||||
#if DEBUG
|
||||
_platform.Log("Mutex abandoned");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
public readonly UpToolLibV1 V1;
|
||||
public readonly UpToolLibV2 V2;
|
||||
public void Dispose() => _mutex.ReleaseMutex();
|
||||
~UpToolLibMain() => Dispose();
|
||||
}
|
||||
}
|
32
UpToolLib/UpdateCheck.cs
Normal file
32
UpToolLib/UpdateCheck.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Xml.Linq;
|
||||
using UpToolLib.Tool;
|
||||
|
||||
namespace UpToolLib
|
||||
{
|
||||
public static class UpdateCheck
|
||||
{
|
||||
private static XElement _meta;
|
||||
|
||||
private static XElement Meta
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_meta is null) Reload();
|
||||
return _meta;
|
||||
}
|
||||
set => _meta = value;
|
||||
}
|
||||
|
||||
public static Version OnlineVersion => Version.Parse(Meta.Element("Version").Value);
|
||||
public static Uri Installer => new Uri(Meta.Element("Installer").Value).TryUnshorten();
|
||||
public static string InstallerHash => Meta.Element("InstallerHash").Value.ToUpper();
|
||||
public static Uri App => new Uri(Meta.Element("File").Value).TryUnshorten();
|
||||
public static string AppHash => Meta.Element("Hash").Value.ToUpper();
|
||||
|
||||
public static void Reload() =>
|
||||
Reload(XDocument.Load(PathTool.InfoXml).Element("meta").Element("UpdateSource").Value);
|
||||
|
||||
public static void Reload(string source) => Meta = XDocument.Load(source).Element("meta");
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace UpToolLib.v1.Tool
|
||||
{
|
||||
public class PathTool
|
||||
{
|
||||
public string Dir =>
|
||||
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "UpTool2");
|
||||
|
||||
public string TempPath => GetRelative("tmp");
|
||||
public string AppsPath => GetRelative("Apps");
|
||||
public string InfoXml => GetRelative("info.xml");
|
||||
|
||||
public string GetRelative(params string[] segments) =>
|
||||
Path.Combine(new[] {Dir}.Concat(segments).ToArray());
|
||||
|
||||
public string GetAppPath(Guid app) => Path.Combine(AppsPath, app.ToString());
|
||||
|
||||
public string GetDataPath(Guid app) => Path.Combine(GetAppPath(app), "app");
|
||||
|
||||
public string GetInfoPath(Guid app) => Path.Combine(GetAppPath(app), "info.xml");
|
||||
}
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using UpToolLib.DataStructures;
|
||||
|
||||
namespace UpToolLib.v1.Tool
|
||||
{
|
||||
public class XmlTool
|
||||
{
|
||||
private readonly IExternalFunctionality _platform;
|
||||
private readonly PathTool _pathTool;
|
||||
|
||||
internal XmlTool(IExternalFunctionality platform, PathTool pathTool)
|
||||
{
|
||||
_platform = platform;
|
||||
_pathTool = pathTool;
|
||||
}
|
||||
|
||||
public void FixXml()
|
||||
{
|
||||
if (!Directory.Exists(_pathTool.AppsPath))
|
||||
Directory.CreateDirectory(_pathTool.AppsPath);
|
||||
if (!File.Exists(_pathTool.InfoXml) || XDocument.Load(_pathTool.InfoXml).Element("meta") == null)
|
||||
new XElement("meta").Save(_pathTool.InfoXml);
|
||||
XDocument x = XDocument.Load(_pathTool.InfoXml);
|
||||
XElement meta = x.Element("meta");
|
||||
if (meta.Element("UpdateSource") == null)
|
||||
meta.Add(new XElement("UpdateSource"));
|
||||
if (new[]
|
||||
{
|
||||
"",
|
||||
"https://raw.githubusercontent.com/CreepyCrafter24/UpTool2/master/Meta.xml",
|
||||
"https://raw.githubusercontent.com/JFronny/UpTool2/master/Meta.xml",
|
||||
"https://gist.githubusercontent.com/JFronny/f1ccbba3d8a2f5862592bb29fdb612c4/raw/Meta.xml",
|
||||
"https://github.com/JFronny/UpTool2/releases/latest/download/meta.xml",
|
||||
"https://gitlab.com/JFronny/UpTool2/-/jobs/artifacts/master/raw/meta.xml?job=uptool"
|
||||
}
|
||||
.Contains(meta.Element("UpdateSource").Value))
|
||||
meta.Element("UpdateSource").Value =
|
||||
"https://gitlab.com/uptool/UpTool2/-/jobs/artifacts/master/raw/meta.xml?job=uptool";
|
||||
if (meta.Element("Repos") == null)
|
||||
meta.Add(new XElement("Repos"));
|
||||
if (meta.Element("Repos").Elements("Repo").Count() == 0)
|
||||
{
|
||||
if (_platform.YesNoDialog(
|
||||
"No active repository was detected. Add the default repo?", false))
|
||||
{
|
||||
meta.Element("Repos").Add(new XElement("Repo", new XElement("Name", "UpTool2 official Repo"),
|
||||
new XElement("Link",
|
||||
"https://gitlab.com/uptool/UpTool2/-/snippets/1988600/raw/master/Repo.xml")));
|
||||
}
|
||||
}
|
||||
meta.Element("Repos").Elements("Repo").Select(s => s.Element("Link"))
|
||||
.Where(s => new[]
|
||||
{
|
||||
null, "https://github.com/JFronny/UpTool2/releases/download/Repo/Repo.xml",
|
||||
"https://raw.githubusercontent.com/JFronny/UpTool2/master/Repo.xml",
|
||||
"https://gist.githubusercontent.com/JFronny/f1ccbba3d8a2f5862592bb29fdb612c4/raw/Repo.xml",
|
||||
"https://gitlab.com/JFronny/UpTool2/snippets/1988600/raw"
|
||||
}.Contains(s.Value))
|
||||
.ToList().ForEach(s =>
|
||||
s.Value =
|
||||
"https://gitlab.com/uptool/UpTool2/-/snippets/1988600/raw/master/Repo.xml");
|
||||
if (meta.Element("LocalRepo") == null)
|
||||
meta.Add(new XElement("LocalRepo"));
|
||||
x.Save(_pathTool.InfoXml);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UpToolLib.DataStructures;
|
||||
using UpToolLib.v1.Tool;
|
||||
using UpToolLib.v2;
|
||||
|
||||
namespace UpToolLib.v1
|
||||
{
|
||||
public class UpToolLibV1
|
||||
{
|
||||
internal UpToolLibV1(IExternalFunctionality platform)
|
||||
{
|
||||
PathTool = new PathTool();
|
||||
XmlTool = new XmlTool(platform, PathTool);
|
||||
Installer = new AppInstall(platform, PathTool);
|
||||
AppExtras = new AppExtras(Installer, PathTool, Apps);
|
||||
}
|
||||
public readonly AppExtras AppExtras;
|
||||
public readonly AppInstall Installer;
|
||||
public readonly PathTool PathTool;
|
||||
public readonly XmlTool XmlTool;
|
||||
|
||||
public readonly IDictionary<Guid, App> Apps = new Dictionary<Guid, App>();
|
||||
public static Version MinimumVer => Version.Parse("0.0.0.0");
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using UpToolLib.DataStructures;
|
||||
using UpToolLib.v1.Tool;
|
||||
|
||||
namespace UpToolLib.v2
|
||||
{
|
||||
public class AppFactory
|
||||
{
|
||||
private readonly PathTool _pathTool;
|
||||
|
||||
internal AppFactory(PathTool pathTool) => _pathTool = pathTool;
|
||||
|
||||
public App CreateApp(string name, string description, Version version, string file, bool local, string hash,
|
||||
Guid iD, Color color, object icon, bool runnable, string mainFile) =>
|
||||
new(name, description, version, file, local, hash, iD, color, icon, runnable, mainFile, _pathTool);
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
using UpToolLib.DataStructures;
|
||||
|
||||
namespace UpToolLib.v2.TaskQueue
|
||||
{
|
||||
public abstract class AppTask
|
||||
{
|
||||
public abstract void Run();
|
||||
|
||||
public AppTask(IExternalFunctionality platform) => Platform = platform;
|
||||
|
||||
protected IExternalFunctionality Platform { get; }
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UpToolLib.DataStructures;
|
||||
using UpToolLib.v1.Tool;
|
||||
|
||||
namespace UpToolLib.v2.TaskQueue
|
||||
{
|
||||
public class TaskFactory
|
||||
{
|
||||
private IExternalFunctionality _platform;
|
||||
private readonly AppInstall _installer;
|
||||
private readonly AppExtras _extras;
|
||||
private readonly PathTool _pathTool;
|
||||
private readonly AppFactory _appFactory;
|
||||
private readonly IDictionary<Guid, App> _apps;
|
||||
|
||||
internal TaskFactory(IExternalFunctionality platform, AppInstall installer, AppExtras extras, PathTool pathTool, AppFactory appFactory, IDictionary<Guid, App> apps)
|
||||
{
|
||||
_platform = platform;
|
||||
_installer = installer;
|
||||
_extras = extras;
|
||||
_pathTool = pathTool;
|
||||
_appFactory = appFactory;
|
||||
_apps = apps;
|
||||
}
|
||||
|
||||
public KnownAppTask CreateInstall(App app, Action? postInstall = null) => new InstallTask(_platform, _installer, app, postInstall);
|
||||
|
||||
public KnownAppTask CreateRemove(App app, Action? postInstall = null) => new RemoveTask(_platform, _extras, app, postInstall);
|
||||
|
||||
public KnownAppTask CreateUpdate(App app, Action? postInstall = null) => new UpdateTask(_platform, _extras, app, postInstall);
|
||||
|
||||
public AppTask CreateUpload(string zipFile, string name, Action? postInstall = null) => new UploadTask(_platform, _installer, _appFactory, _pathTool, _apps, zipFile, name, postInstall);
|
||||
}
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using UpToolLib.DataStructures;
|
||||
using UpToolLib.v1;
|
||||
using UpToolLib.v1.Tool;
|
||||
|
||||
namespace UpToolLib.v2.TaskQueue
|
||||
{
|
||||
public class UploadTask : AppTask
|
||||
{
|
||||
private readonly string _name;
|
||||
private readonly Action? _postInstall;
|
||||
private readonly AppInstall _installer;
|
||||
private readonly AppFactory _appFactory;
|
||||
private readonly PathTool _pathTool;
|
||||
private readonly IDictionary<Guid, App> _apps;
|
||||
public readonly string ZipFile;
|
||||
|
||||
internal UploadTask(IExternalFunctionality platform, AppInstall installer, AppFactory appFactory, PathTool pathTool, IDictionary<Guid, App> apps, string zipFile, string name, Action? postInstall) : base(platform)
|
||||
{
|
||||
_installer = installer;
|
||||
_appFactory = appFactory;
|
||||
_pathTool = pathTool;
|
||||
_apps = apps;
|
||||
ZipFile = zipFile;
|
||||
_name = name;
|
||||
_postInstall = postInstall;
|
||||
}
|
||||
|
||||
public override void Run()
|
||||
{
|
||||
#if !DEBUG
|
||||
try
|
||||
{
|
||||
#endif
|
||||
Guid id = Guid.NewGuid();
|
||||
while (_apps.ContainsKey(id) || Directory.Exists(_pathTool.GetAppPath(id)))
|
||||
id = Guid.NewGuid();
|
||||
App appI = _appFactory.CreateApp(_name, "Locally installed package, removal only",
|
||||
UpToolLibV1.MinimumVer, "", true, "", id, Color.Red, Platform.GetDefaultIcon(), false, "");
|
||||
_installer.InstallZip(ZipFile, appI, true);
|
||||
_postInstall?.Invoke();
|
||||
#if !DEBUG
|
||||
}
|
||||
catch (Exception e1)
|
||||
{
|
||||
Platform.OkDialog("Upload failed.\r\nException=" + e1);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public override string ToString() => $"Install local {Path.GetFileName(ZipFile)}";
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UpToolLib.DataStructures;
|
||||
using UpToolLib.v1.Tool;
|
||||
using UpToolLib.v2.TaskQueue;
|
||||
|
||||
namespace UpToolLib.v2
|
||||
{
|
||||
public class UpToolLibV2
|
||||
{
|
||||
internal UpToolLibV2(IExternalFunctionality platform, AppInstall install, AppExtras extras, PathTool pathTool, XmlTool xmlTool, IDictionary<Guid, App> apps)
|
||||
{
|
||||
AppFactory = new AppFactory(pathTool);
|
||||
UpdateChecker = new UpdateChecker(pathTool);
|
||||
TaskFactory = new TaskFactory(platform, install, extras, pathTool, AppFactory, apps);
|
||||
RepoManagement = new RepoManagement(platform, xmlTool, pathTool, AppFactory, apps);
|
||||
}
|
||||
|
||||
public readonly UpdateChecker UpdateChecker;
|
||||
public readonly TaskFactory TaskFactory;
|
||||
public readonly AppFactory AppFactory;
|
||||
public readonly RepoManagement RepoManagement;
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
using System;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace UpToolLib.v2
|
||||
{
|
||||
public class UpdateCheck
|
||||
{
|
||||
public readonly Version OnlineVersion;
|
||||
public readonly Uri Installer;
|
||||
public readonly string InstallerHash;
|
||||
public readonly Uri App;
|
||||
public readonly string AppHash;
|
||||
|
||||
public UpdateCheck(XElement meta)
|
||||
{
|
||||
OnlineVersion = Version.Parse(meta.Element("Version").Value);
|
||||
Installer = new Uri(meta.Element("Installer").Value);
|
||||
InstallerHash = meta.Element("InstallerHash").Value.ToUpper();
|
||||
App = new Uri(meta.Element("File").Value);
|
||||
AppHash = meta.Element("Hash").Value.ToUpper();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
using System.Xml.Linq;
|
||||
using UpToolLib.v1.Tool;
|
||||
|
||||
namespace UpToolLib.v2
|
||||
{
|
||||
public class UpdateChecker
|
||||
{
|
||||
private readonly PathTool _pathTool;
|
||||
public UpdateCheck Check() => Check(XDocument.Load(_pathTool.InfoXml).Element("meta").Element("UpdateSource").Value);
|
||||
public UpdateCheck Check(string source) => new(XDocument.Load(source).Element("meta"));
|
||||
internal UpdateChecker(PathTool pathTool) => _pathTool = pathTool;
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
{
|
||||
"extends": [
|
||||
"config:base"
|
||||
],
|
||||
"hostRules": [
|
||||
{
|
||||
"domainName": "github.com",
|
||||
"encrypted": {
|
||||
"token": "o53wjvsApqgx2krTKwD5LBnbmtK7gZ4zgAYsFIxLxf3blIMY2y9tUpsVNo4thY/kTA1tDOvIiP9PNdJV/DRYqvMDQMxvKiGHE1eSrpmrICRaq4Bhdc9/QZotkliqcziynLV0vD+xXZ7tyXKhR+nZijp4K1H2euCAv8vCVAUrpXIlBf/gmHvfEjmTDKUqJTEAvzre7H7l3C7SmQ2VwyE6gEFD91K9jGbgfI6MIgjx3i3O4fxM/JLXmUR19mGVK//Hpc1GXyVePB1sdzYhsyMU/3hzR3d/lJLOrHhr40WO1vNf3aB0WVDqqsl+XwoFxBxFqhSPTVHkEsylD+l+d8fsXA=="
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
Reference in New Issue
Block a user