Skip to content

Commit

Permalink
Correct update process
Browse files Browse the repository at this point in the history
  • Loading branch information
xmegz committed Apr 2, 2024
1 parent 4e421df commit d9b7cfa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
11 changes: 5 additions & 6 deletions MndpTray/MndpTray.Core/Update/Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,10 @@ public static void UpdateProgram(string fileName, byte[] data)
private static T DeserializeResponse<T>(string data)
{
var instance = Activator.CreateInstance<T>();
using (var ms = new MemoryStream(Encoding.Unicode.GetBytes(data)))
{
var serializer = new DataContractJsonSerializer(instance.GetType());
return (T)serializer.ReadObject(ms);
}
using var ms = new MemoryStream(Encoding.Unicode.GetBytes(data));

var serializer = new DataContractJsonSerializer(instance.GetType());
return (T)serializer.ReadObject(ms);
}

private static release GetMaxRelease(List<release> list)
Expand Down Expand Up @@ -194,7 +193,7 @@ private static string GetReleasesFromApi(string author, string repositoryName)

private static List<int> GetReleaseVersion(release data)
{
List<int> ret = new List<int>();
List<int> ret = [];

if (data == null)
{
Expand Down
5 changes: 4 additions & 1 deletion MndpTray/MndpTray.Core/Visual/NotifyContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace MndpTray.Core
{
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Threading;
Expand Down Expand Up @@ -80,6 +81,7 @@ private void Send_Click(object sender, System.EventArgs e)
MndpSender.Instance.SendHostInfoNow();
}

[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1839:Use 'Environment.ProcessPath'", Justification = "<Pending>")]
private void Update_Click(object sender, System.EventArgs e)
{
string repositoryName = "MndpTray";
Expand All @@ -95,7 +97,8 @@ private void Update_Click(object sender, System.EventArgs e)
if (res == DialogResult.Yes)
{
byte[] data = Update.Methods.DownloadBinary(url);
Update.Methods.UpdateProgram(Path.GetFullPath(Environment.ProcessPath), data);
string processFileName = Process.GetCurrentProcess().MainModule.FileName;
Update.Methods.UpdateProgram(Path.GetFullPath(processFileName), data);

MessageBox.Show("Update successful, please restart application!", "Update", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
Expand Down

0 comments on commit d9b7cfa

Please sign in to comment.