Saving last Release Stream in Registry

This commit is contained in:
HorizonCode 2021-05-27 10:40:02 +02:00
parent d71f0d38fc
commit 0937fa43a3
3 changed files with 62 additions and 6 deletions

View File

@ -94,6 +94,7 @@
<Compile Include="Utils\DownloadUtil.cs" />
<Compile Include="Utils\MD5Util.cs" />
<Compile Include="Utils\ProcessUtil.cs" />
<Compile Include="Utils\RegistryUtil.cs" />
<Compile Include="Utils\ReleaseStreamUtil.cs" />
<Compile Include="Objects\Shortcut.cs" />
<Compile Include="Objects\UpdateState.cs" />

View File

@ -15,6 +15,10 @@ using System.Media;
using System.Runtime.InteropServices.ComTypes;
using Shortcut;
using Path = System.Windows.Shapes.Path;
using EZPPClient_Installer.Utils;
using Microsoft.Win32;
using System.Windows.Controls;
using System.Threading;
#if DEBUG
using MessageBox = System.Windows.MessageBox;
@ -114,9 +118,15 @@ namespace EZPPClient_Installer
List<string> releases = await ReleaseStreamUtil.GetAvailableReleaseStreams();
foreach(string release in releases)
{
ReleaseStreamComboBox.Items.Add(release.UppercaseFirst());
ReleaseStreamComboBox.Items.Add(release.UppercaseFirst().Trim());
}
ReleaseStreamComboBox.SelectedIndex = 0;
string systemRelease = RegistryUtil.GetUsedReleaseStream("Stable");
bool containsRelease = releases.Contains(systemRelease);
ReleaseStreamComboBox.SelectedValue = systemRelease;
}
private async Task<UpdateState> CheckForInstallerUpdates()
@ -127,7 +137,7 @@ namespace EZPPClient_Installer
using (WebClient client = new WebClient())
{
client.Headers.Add("user-agent", "EZPPClientInstaller");
string newVersionString = client.DownloadString("https://new.ez-pp.farm/ezppclient?version");
string newVersionString = await client.DownloadStringTaskAsync("https://new.ez-pp.farm/ezppclient?version");
double ver = 0;
try
{
@ -202,6 +212,10 @@ namespace EZPPClient_Installer
return;
}
var type = InstallButton.Content;
RegistryUtil.SetUsedReleaseStream(RELEASESTREAM);
if (!Directory.Exists(osuFolder + "\\EZPPClient"))
{
Directory.CreateDirectory(osuFolder + "\\EZPPClient");
@ -403,7 +417,7 @@ namespace EZPPClient_Installer
await DownloadUtil.DownloadFiles(filesToDownload, EZPPFolder);
if (InstallButton.Content.Equals("Install"))
if (type.Equals("Install"))
{
IShellLink link = (IShellLink)new ShellLink();
@ -440,7 +454,7 @@ namespace EZPPClient_Installer
linkFoldersCheckbox.IsEnabled = false;
string updateText = "It seems like the installation was faulty, please hit Update to repair the EZPPClient.";
switch (InstallButton.Content)
switch (type)
{
case "Update":
updateText = "It seems like the update was faulty, please hit Update to repair the EZPPClient.";
@ -463,7 +477,7 @@ namespace EZPPClient_Installer
{
string updateText = "The EZPPClient was successfully installed!";
switch (InstallButton.Content)
switch (type)
{
case "Update":
updateText = "The EZPPClient was successfully updated!";

View File

@ -0,0 +1,41 @@
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EZPPClient_Installer.Utils
{
class RegistryUtil
{
public static void SetUsedReleaseStream(string release)
{
RegistryKey key = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\EZPPClientInstaller");
key.SetValue("ReleaseStream", release);
key.Close();
}
public static String GetUsedReleaseStream(string defaultRelease)
{
string release = defaultRelease;
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\EZPPClientInstaller");
//if it does exist, retrieve the stored values
if (key != null)
{
release = (string) key.GetValue("ReleaseStream");
key.Close();
}
return release;
}
public static void DeleteUsedReleaseStream()
{
Registry.CurrentUser.DeleteSubKey(@"SOFTWARE\EZPPClientInstaller");
}
}
}