-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
284 additions
and
520 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,7 @@ public static void Init() | |
|
||
try | ||
{ | ||
UpdateChecker.Init(); | ||
Media.Init(); | ||
} | ||
catch (Exception e) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
using Avalonia.Threading; | ||
using ColorMC.Core; | ||
using ColorMC.Core.Net; | ||
using ColorMC.Core.Net.Downloader; | ||
using ColorMC.Core.Objs; | ||
using ColorMC.Core.Utils; | ||
using ColorMC.Gui.Objs; | ||
using Newtonsoft.Json.Linq; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Net.Http; | ||
using System.Runtime.InteropServices; | ||
using System.Security.Cryptography; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace ColorMC.Gui; | ||
|
||
public static class UpdateChecker | ||
{ | ||
//private const string url = "http://localhost/colormc/A16/"; | ||
private const string url = "https://colormc.coloryr.com/colormc/A16/"; | ||
|
||
public static readonly string[] WebSha1s = new string[4] { "", "", "", "" }; | ||
private static readonly string[] Sha1s = new string[4] { "", "", "", "" }; | ||
private static readonly string[] Local = new string[4] { "", "", "", "" }; | ||
public static void Init() | ||
{ | ||
Local[0] = Path.GetFullPath($"{ColorMCGui.RunDir}dll/ColorMC.Core.dll"); | ||
Local[1] = Path.GetFullPath($"{ColorMCGui.RunDir}dll/ColorMC.Core.pdb"); | ||
Local[2] = Path.GetFullPath($"{ColorMCGui.RunDir}dll/ColorMC.Gui.dll"); | ||
Local[3] = Path.GetFullPath($"{ColorMCGui.RunDir}dll/ColorMC.Gui.pdb"); | ||
|
||
for (int a = 0; a < 4; a++) | ||
{ | ||
if (File.Exists(Local[a])) | ||
{ | ||
using var file = File.OpenRead(Local[a]); | ||
Sha1s[a] = Funtcions.GenSha1(file); | ||
} | ||
} | ||
} | ||
|
||
public static async void Check() | ||
{ | ||
try | ||
{ | ||
var data = await CheckOne(); | ||
if (data.Item1 == true) | ||
{ | ||
var res = await App.HaveUpdate(data.Item2!); | ||
if (!res) | ||
{ | ||
StartUpdate(); | ||
} | ||
} | ||
} | ||
catch (Exception e) | ||
{ | ||
App.ShowError(App.GetLanguage("Gui.Error21"), e); | ||
} | ||
|
||
} | ||
|
||
public static async void StartUpdate() | ||
{ | ||
var list = new List<DownloadItemObj>() | ||
{ | ||
new DownloadItemObj() | ||
{ | ||
Name = "ColorMC.Core.dll", | ||
SHA1 = WebSha1s[0], | ||
Url = $"{url}ColorMC.Core.dll", | ||
Local = $"{ColorMCGui.RunDir}dll/ColorMC.Core.dll", | ||
Overwrite = true | ||
}, | ||
new DownloadItemObj() | ||
{ | ||
Name = "ColorMC.Core.pdb", | ||
SHA1 = WebSha1s[1], | ||
Url = $"{url}ColorMC.Core.pdb", | ||
Local = $"{ColorMCGui.RunDir}dll/ColorMC.Core.pdb", | ||
Overwrite = true | ||
}, | ||
new DownloadItemObj() | ||
{ | ||
Name = "ColorMC.Gui.dll", | ||
SHA1 = WebSha1s[2], | ||
Url = $"{url}ColorMC.Gui.dll", | ||
Local = $"{ColorMCGui.RunDir}dll/ColorMC.Gui.dll", | ||
Overwrite = true | ||
}, | ||
new DownloadItemObj() | ||
{ | ||
Name = "ColorMC.Gui.pdb", | ||
SHA1 = WebSha1s[3], | ||
Url = $"{url}ColorMC.Gui.pdb", | ||
Local = $"{ColorMCGui.RunDir}dll/ColorMC.Gui.pdb", | ||
Overwrite = true | ||
} | ||
}; | ||
|
||
var res = await DownloadManager.Start(list); | ||
if (res) | ||
{ | ||
Process.Start($"{(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? | ||
"ColorMC.Launcher.exe" : "ColorMC.Launcher")}"); | ||
App.Close(); | ||
} | ||
else | ||
{ | ||
App.ShowError(App.GetLanguage("Gui.Error22"), ""); | ||
} | ||
} | ||
|
||
public static async Task<(bool?, string?)> CheckOne() | ||
{ | ||
try | ||
{ | ||
var data = await BaseClient.DownloadClient.GetStringAsync(url + "sha1.json"); | ||
var obj = JObject.Parse(data); | ||
if (obj == null) | ||
{ | ||
App.ShowError(App.GetLanguage("Gui.Error21"), "Json Error"); | ||
return (false, null); | ||
} | ||
|
||
WebSha1s[0] = obj["core.dll"]!.ToString(); | ||
WebSha1s[1] = obj["core.pdb"]!.ToString(); | ||
WebSha1s[2] = obj["gui.dll"]!.ToString(); | ||
WebSha1s[3] = obj["gui.pdb"]!.ToString(); | ||
|
||
Logs.Info($"ColorMC.Core.dll:{Sha1s[0]} Web:{WebSha1s[0]}"); | ||
Logs.Info($"ColorMC.Core.pdb:{Sha1s[1]} Web:{WebSha1s[1]}"); | ||
Logs.Info($"ColorMC.Gui.dll:{Sha1s[2]} Web:{WebSha1s[2]}"); | ||
Logs.Info($"ColorMC.Gui.pdb:{Sha1s[3]} Web:{WebSha1s[3]}"); | ||
|
||
for (int a = 0; a < 4; a++) | ||
{ | ||
if (WebSha1s[a] != Sha1s[a]) | ||
{ | ||
obj.TryGetValue("text", out var data1); | ||
return (true, data1?.ToString() ?? App.GetLanguage("Gui.Info20")); | ||
} | ||
} | ||
|
||
return (false, null); | ||
} | ||
catch (Exception e) | ||
{ | ||
App.ShowError(App.GetLanguage("Gui.Error21"), e); | ||
} | ||
|
||
return (null, null); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.