Remove PCK-Studio-Updater Project

This commit is contained in:
miku-666
2024-06-27 19:53:33 +02:00
parent 974b4cab96
commit 3840b2940e
8 changed files with 0 additions and 456 deletions

View File

@@ -1,22 +0,0 @@
using System.Text.RegularExpressions;
namespace PCKStudio_Updater
{
public sealed class GithubParams
{
public readonly string RepositoryOwnerName;
public readonly string RepositoryName;
public readonly string TargetExecutableName;
public readonly bool UsePreRelease;
public readonly Regex VersionMatcher;
public GithubParams(string repositoryOwnerName, string repositoryName, string targetExecutableName, bool usePreRelease, Regex versionMatcher)
{
RepositoryOwnerName = repositoryOwnerName;
RepositoryName = repositoryName;
TargetExecutableName = targetExecutableName;
UsePreRelease = usePreRelease;
VersionMatcher = versionMatcher;
}
}
}

View File

@@ -1,146 +0,0 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO.Compression;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Octokit;
namespace PCKStudio_Updater
{
public sealed class GithubUpdateDownloader : IUpdateDownloader
{
private static readonly Assembly updaterAssembly = Assembly.GetAssembly(typeof(GithubUpdateDownloader));
private readonly GithubParams _updateParams;
private readonly GitHubClient githubClient;
private Release latestFetchedRelease;
private Version latestReleaseVersion;
private DirectoryInfo downloadDirectory;
public GithubUpdateDownloader(GithubParams updateParams)
{
_updateParams = updateParams;
var githubClientProductHeader = new ProductHeaderValue(updaterAssembly.GetName().Name);
githubClient = new GitHubClient(githubClientProductHeader);
}
public bool IsUpdateAvailable(FileVersionInfo fileVersionInfo)
{
return IsUpdateAvailable(fileVersionInfo.ProductVersion);
}
public bool IsUpdateAvailable(Assembly currentAssembly)
{
if (!File.Exists(currentAssembly.Location))
return false;
FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(currentAssembly.Location);
return IsUpdateAvailable(fileVersionInfo.ProductVersion);
}
public bool IsUpdateAvailable(Version productVersion)
{
Debug.WriteLine("Release Product ver.: " + latestReleaseVersion);
Debug.WriteLine("Current Product ver.: " + productVersion);
return latestReleaseVersion.CompareTo(productVersion) >= 0;
}
public bool IsUpdateAvailable(string productVersion)
{
GetLatestRelease(_updateParams.UsePreRelease);
if (Version.TryParse(productVersion, out var currentVersion))
{
return IsUpdateAvailable(currentVersion);
}
return false;
}
private void UnpackZip(string zipFilePath)
{
ZipFile.ExtractToDirectory(zipFilePath, Path.GetDirectoryName(zipFilePath));
}
private static void DownloadAsset(ReleaseAsset asset, Stream destination)
{
string downloadUrl = asset.BrowserDownloadUrl;
var client = new WebClient();
using (var serverStream = client.OpenRead(downloadUrl))
{
serverStream.CopyTo(destination);
}
}
private void GetLatestRelease(bool prerelease)
{
Release release;
if (prerelease)
{
var prereleaseTask = githubClient.Repository.Release.GetAll(_updateParams.RepositoryOwnerName, _updateParams.RepositoryName);
prereleaseTask.Wait();
var prereleases = prereleaseTask.Result.OrderByDescending(release => release.PublishedAt ?? release.CreatedAt).Where(release => release.Prerelease).ToArray();
release = latestFetchedRelease = prereleases[0];
}
else
{
var latestReleaseTask = githubClient.Repository.Release.GetLatest(_updateParams.RepositoryOwnerName, _updateParams.RepositoryName);
latestReleaseTask.Wait();
release = latestFetchedRelease = latestReleaseTask.Result;
}
var match = _updateParams.VersionMatcher.Match(release.Name);
if (match.Success)
{
string versionString = match.Value;
Version.TryParse(versionString, out latestReleaseVersion);
}
}
private void EmptyDirectory(DirectoryInfo directory)
{
foreach (FileInfo file in directory.GetFiles())
{
if (Path.GetFileNameWithoutExtension(file.Name) != _updateParams.TargetExecutableName && file.Name != "update.zip")
file.Delete();
}
foreach (DirectoryInfo subDirectory in directory.GetDirectories())
subDirectory.Delete(true);
}
public void DownloadTo(DirectoryInfo directory)
{
if (latestFetchedRelease is null)
GetLatestRelease(_updateParams.UsePreRelease);
if (latestFetchedRelease.Assets?.Count > 0)
{
var asset = latestFetchedRelease.Assets[0];
string zipFilePath = Path.Combine(directory.FullName, asset.Name);
using(var zipFileStream = File.OpenWrite(zipFilePath))
{
DownloadAsset(asset, zipFileStream);
}
Debug.WriteLine("Download Complete", category: nameof(GithubUpdateDownloader));
EmptyDirectory(directory);
UnpackZip(zipFilePath);
downloadDirectory = directory;
}
}
public void Launch()
{
if (downloadDirectory is null)
{
throw new ArgumentNullException("Download directory not set.");
}
var files = downloadDirectory.GetFiles(_updateParams.TargetExecutableName + ".exe", SearchOption.TopDirectoryOnly);
if (files is not null && files.Length > 0)
{
Process.Start(files[0].FullName);
}
}
}
}

View File

@@ -1,19 +0,0 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PCKStudio_Updater
{
public interface IUpdateDownloader
{
public bool IsUpdateAvailable(Version currentVersion);
public bool IsUpdateAvailable(string currentVersionString);
public void DownloadTo(DirectoryInfo directory);
public void Launch();
}
}

View File

@@ -1,105 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{5B223556-15B9-41DA-AA0B-5E7F45E743BF}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>PCKStudio_Updater</RootNamespace>
<AssemblyName>PCK-Studio-Updater</AssemblyName>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<StartupObject>PCKStudio_Updater.Program</StartupObject>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>ProjectLogo.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="API\IUpdateDownloader.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="API\GithubParams.cs" />
<Compile Include="API\GithubUpdateDownloader.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Costura.Fody">
<Version>5.7.0</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Octokit">
<Version>7.1.0</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.8">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.8 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Content Include="ProjectLogo.ico" />
</ItemGroup>
<ItemGroup>
<None Include="Properties\app.manifest" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@@ -1,58 +0,0 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime;
using System.Text;
using System.Text.RegularExpressions;
namespace PCKStudio_Updater
{
internal class Program
{
static void Main(string[] args)
{
Uri projectUrl = new Uri("https://github.com/PhoenixARC/-PCK-Studio");
if (args.Length > 0)
{
projectUrl = new Uri(args[0]);
}
string executableName = "PCK-Studio";
if (args.Length > 1)
{
executableName = args[1];
}
bool prerelease = false;
if (args.Length > 2)
{
prerelease = args[2].ToLower() == "true" || args[2].ToLower() == "1";
}
var versionMatcher = new Regex("(\\*|\\d+(\\.\\d+){0,3}(\\.\\*)?)");
if (args.Length > 3)
{
versionMatcher = new Regex(args[3]);
}
GithubParams updateParams = new GithubParams(
Path.GetDirectoryName(projectUrl.AbsolutePath).Replace("\\", ""),
Path.GetFileName(projectUrl.AbsolutePath),
executableName,
prerelease,
versionMatcher
);
IUpdateDownloader updater = new GithubUpdateDownloader(updateParams);
if (!File.Exists(updateParams.TargetExecutableName + ".exe") || updater.IsUpdateAvailable(FileVersionInfo.GetVersionInfo(updateParams.TargetExecutableName + ".exe").ProductVersion))
{
updater.DownloadTo(new DirectoryInfo("."));
updater.Launch();
return;
}
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 146 KiB

View File

@@ -1,36 +0,0 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("PckStudio-Updater")]
[assembly: AssemblyDescription("Updater for PCK-Studio")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PckStudio-Updater")]
[assembly: AssemblyCopyright("Copyright © 2023 Miku-666")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("5b223556-15b9-41da-aa0b-5e7f45e743bf")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -1,70 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app" />
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<!-- UAC Manifest Options
If you want to change the Windows User Account Control level replace the
requestedExecutionLevel node with one of the following.
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
Specifying requestedExecutionLevel element will disable file and registry virtualization.
Remove this element if your application requires this virtualization for backwards
compatibility.
-->
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
<applicationRequestMinimum>
<defaultAssemblyRequest permissionSetReference="Custom" />
<PermissionSet class="System.Security.PermissionSet" version="1" ID="Custom" SameSite="site" />
</applicationRequestMinimum>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- A list of the Windows versions that this application has been tested on
and is designed to work with. Uncomment the appropriate elements
and Windows will automatically select the most compatible environment. -->
<!-- Windows Vista -->
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->
<!-- Windows 7 -->
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />-->
<!-- Windows 8 -->
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />-->
<!-- Windows 8.1 -->
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />-->
<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
</application>
</compatibility>
<!-- Indicates that the application is DPI-aware and will not be automatically scaled by Windows at higher
DPIs. Windows Presentation Foundation (WPF) applications are automatically DPI-aware and do not need
to opt in. Windows Forms applications targeting .NET Framework 4.6 that opt into this setting, should
also set the 'EnableWindowsFormsHighDpiAutoResizing' setting to 'true' in their app.config. -->
<!--
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
</windowsSettings>
</application>
-->
<!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
<!--
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
-->
</assembly>