Upgrade to NET 7

This commit is contained in:
Manu
2023-01-23 20:07:13 +01:00
parent fcb162e8d2
commit f7e4198433
17 changed files with 118 additions and 43 deletions

View File

@@ -1,6 +1,7 @@
using System.Text.RegularExpressions;
using SwitchGiftDataManager.Core;
using Enums;
using System.Diagnostics;
namespace SwitchGiftDataManager.WinForm
{
@@ -16,11 +17,21 @@ namespace SwitchGiftDataManager.WinForm
public MainWindow()
{
Task.Run(async () => { await GitHubUtil.TryUpdate(); });
Task.Run(TryUpdate).Wait();
InitializeComponent();
Text += BCATManager.Version;
}
private static async Task TryUpdate()
{
if (await GitHubUtil.IsUpdateAvailable())
{
var result = MessageBox.Show("A program update is available. Do you want to download the latest release?", "Update available", MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
Process.Start(new ProcessStartInfo { FileName = @"https://github.com/Manu098vm/Switch-Gift-Data-Manager/releases", UseShellExecute = true });
}
}
private void ChangeGame(Games game)
{
GrpBCAT.Enabled = true;
@@ -259,7 +270,7 @@ namespace SwitchGiftDataManager.WinForm
{
if (e.Data is not null && CurrentGame is not Games.None)
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop)!;
LoadLocalFiles(files);
}
}

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>bin\Release\net7.0-windows\win-x64\publish\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<_TargetId>Folder</_TargetId>
<TargetFramework>net7.0-windows</TargetFramework>
<SelfContained>false</SelfContained>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<History>True|2023-01-23T19:01:57.3824432Z;False|2023-01-23T20:00:42.5423966+01:00;True|2023-01-23T19:57:25.6949583+01:00;</History>
<LastFailureDetails />
</PropertyGroup>
</Project>

View File

@@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<TargetFramework>net7.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
@@ -26,15 +26,20 @@
<Optimize>True</Optimize>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='WSL|AnyCPU'">
<DebugType>embedded</DebugType>
<Optimize>True</Optimize>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugType>embedded</DebugType>
</PropertyGroup>
<PropertyGroup>
<DebugType>embedded</DebugType>
<EmbedAllSources>true</EmbedAllSources>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
<PublishReadyToRun>true</PublishReadyToRun>
<PublishSingleFile>true</PublishSingleFile>
<PublishTrimmed>false</PublishTrimmed>
<SelfContained>false</SelfContained>
</PropertyGroup>
<ItemGroup>
<None Include="..\README.md">
<Pack>True</Pack>
@@ -49,10 +54,6 @@
</None>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Octokit" Version="4.0.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SwitchGiftDataManager.Core\SwitchGiftDataManager.Core.csproj">
<Private>True</Private>
@@ -95,6 +96,10 @@
<Move SourceFiles="$(OUTDIR)\SwitchGiftDataManager.WinForm.exe" DestinationFiles="$(OUTDIR)\Switch Gift Data Manager.exe" />
</Target>
<Target Name="PostPublish" AfterTargets="Publish" Condition="$(ConfigurationName) == Release and '$(OS)' == 'Windows_NT'">
<Move SourceFiles="$(OUTDIR)\publish\SwitchGiftDataManager.WinForm.exe" DestinationFiles="$(OUTDIR)\publish\Switch Gift Data Manager.exe" />
</Target>
<Target Name="PostClean" AfterTargets="Clean" Condition="$(ConfigurationName) == Release">
<RemoveDir Directories="$(TargetDir)" />
<RemoveDir Directories="$(ProjectDir)$(BaseIntermediateOutputPath)" />

View File

@@ -1,11 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Compile Update="MainWindow.cs">
<SubType>Form</SubType>
</Compile>
<Compile Update="SaveWindow.cs">
<SubType>Form</SubType>
</Compile>
</ItemGroup>
<PropertyGroup>
<_LastSelectedProfileId>D:\Projects\SwitchGiftDataManager\SwitchGiftDataManager.WinForm\Properties\PublishProfiles\FolderProfile.pubxml</_LastSelectedProfileId>
</PropertyGroup>
</Project>

View File

@@ -1,69 +0,0 @@
using System.Diagnostics;
using SwitchGiftDataManager.Core;
using Octokit;
namespace SwitchGiftDataManager.WinForm
{
public static class GitHubUtil
{
public static async Task TryUpdate()
{
if (await IsUpdateAvailable())
{
var result = MessageBox.Show("A program update is available. Do you want to download the latest release?", "Update available", MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
Process.Start(new ProcessStartInfo { FileName = @"https://github.com/Manu098vm/Switch-Gift-Data-Manager/releases", UseShellExecute = true } );
}
}
private static async Task<bool> IsUpdateAvailable()
{
var currentVersion = ParseVersion(GetPluginVersion());
var latestVersion = ParseVersion(await GetLatestVersion());
if (latestVersion[0] > currentVersion[0])
return true;
else if (latestVersion[0] == currentVersion[0])
{
if (latestVersion[1] > currentVersion[1])
return true;
else if (latestVersion[1] == currentVersion[1])
{
if (latestVersion[2] > currentVersion[2])
return true;
}
}
return false;
}
private static string GetPluginVersion() => BCATManager.Version;
private static async Task<string> GetLatestVersion()
{
try
{
return await GetLatest();
}
catch (Exception)
{
return "0.0.0";
}
}
private static async Task<string> GetLatest()
{
var client = new GitHubClient(new ProductHeaderValue("Switch-Gift-Data-Manager"));
var release = await client.Repository.Release.GetLatest("Manu098vm", "Switch-Gift-Data-Manager");
return release.Name;
}
private static int[] ParseVersion(string version)
{
var v = new int[3];
v[0] = int.Parse($"{version[0]}");
v[1] = int.Parse($"{version[2]}");
v[2] = int.Parse($"{version[4]}");
return v;
}
}
}