From 48c598a5804fe1f079e1d4f64a9e37621184eb29 Mon Sep 17 00:00:00 2001 From: Taiizor <41683699+Taiizor@users.noreply.github.com> Date: Fri, 6 Oct 2023 18:13:22 +0300 Subject: [PATCH] Update Improvement --- src/Library/Sucrose.Manager/Helper/Reader.cs | 9 ++++++-- src/Library/Sucrose.Manager/Helper/Writer.cs | 13 +++++++++--- src/Library/Sucrose.Manager/Manage/Manager.cs | 2 ++ src/Library/Sucrose.Memory/Constant.cs | 2 ++ src/Live/Sucrose.Live.Nebula/App.xaml.cs | 1 - src/Live/Sucrose.Live.Vexana/App.xaml.cs | 1 - src/Update/Sucrose.Update/App.xaml.cs | 21 +++++++++++++++++-- src/Update/Sucrose.Update/Manage/Internal.cs | 8 +++---- 8 files changed, 44 insertions(+), 13 deletions(-) diff --git a/src/Library/Sucrose.Manager/Helper/Reader.cs b/src/Library/Sucrose.Manager/Helper/Reader.cs index 564e2e441..c3a0a5142 100644 --- a/src/Library/Sucrose.Manager/Helper/Reader.cs +++ b/src/Library/Sucrose.Manager/Helper/Reader.cs @@ -1,4 +1,5 @@ using SMHC = Sucrose.Manager.Helper.Cleaner; +using SMR = Sucrose.Memory.Readonly; namespace Sucrose.Manager.Helper { @@ -17,6 +18,8 @@ public static async Task Read(string filePath) { try { + await Task.Delay(SMR.Randomise.Next(10, 100)); + using FileStream fileStream = new(filePath, FileMode.Open, FileAccess.Read, FileShare.None); using StreamReader reader = new(fileStream); @@ -26,7 +29,7 @@ public static async Task Read(string filePath) { try { - await Task.Delay(5); + await Task.Delay(SMR.Randomise.Next(10, 100)); using FileStream fileStream = new(filePath, FileMode.Open, FileAccess.Read, FileShare.None); using StreamReader reader = new(fileStream); @@ -51,13 +54,15 @@ public static async Task ReadBasic(string filePath) { try { + await Task.Delay(SMR.Randomise.Next(10, 100)); + return SMHC.Clean(File.ReadAllText(filePath)); } catch { try { - await Task.Delay(5); + await Task.Delay(SMR.Randomise.Next(10, 100)); return SMHC.Clean(File.ReadAllText(filePath)); } diff --git a/src/Library/Sucrose.Manager/Helper/Writer.cs b/src/Library/Sucrose.Manager/Helper/Writer.cs index 2c7525add..aa0a563bf 100644 --- a/src/Library/Sucrose.Manager/Helper/Writer.cs +++ b/src/Library/Sucrose.Manager/Helper/Writer.cs @@ -1,4 +1,5 @@ using SMHC = Sucrose.Manager.Helper.Cleaner; +using SMR = Sucrose.Memory.Readonly; namespace Sucrose.Manager.Helper { @@ -19,6 +20,8 @@ public static async void Write(string filePath, string fileContent) { try { + await Task.Delay(SMR.Randomise.Next(10, 100)); + using FileStream fileStream = new(filePath, fileMode, FileAccess.Write, FileShare.None); using StreamWriter writer = new(fileStream); @@ -28,7 +31,7 @@ public static async void Write(string filePath, string fileContent) { try { - await Task.Delay(5); + await Task.Delay(SMR.Randomise.Next(10, 100)); using FileStream fileStream = new(filePath, fileMode, FileAccess.Write, FileShare.None); using StreamWriter writer = new(fileStream); @@ -55,6 +58,8 @@ public static async void WriteBasic(string filePath, string fileContent) { try { + await Task.Delay(SMR.Randomise.Next(10, 100)); + using StreamWriter writer = File.AppendText(filePath); writer.WriteLine(SMHC.Clean(fileContent)); @@ -63,7 +68,7 @@ public static async void WriteBasic(string filePath, string fileContent) { try { - await Task.Delay(5); + await Task.Delay(SMR.Randomise.Next(10, 100)); using StreamWriter writer = File.AppendText(filePath); @@ -87,13 +92,15 @@ public static async void WriteStable(string filePath, string fileContent) { try { + await Task.Delay(SMR.Randomise.Next(10, 100)); + File.WriteAllText(filePath, SMHC.Clean(fileContent)); } catch { try { - await Task.Delay(5); + await Task.Delay(SMR.Randomise.Next(10, 100)); File.WriteAllText(filePath, SMHC.Clean(fileContent)); } diff --git a/src/Library/Sucrose.Manager/Manage/Manager.cs b/src/Library/Sucrose.Manager/Manage/Manager.cs index 480a29718..8c0571ddc 100644 --- a/src/Library/Sucrose.Manager/Manage/Manager.cs +++ b/src/Library/Sucrose.Manager/Manage/Manager.cs @@ -105,6 +105,8 @@ public static class Manager public static bool LibraryMove => SMMI.LibrarySettingManager.GetSetting(SMC.LibraryMove, true); + public static bool UpdateState => SMMI.UpdateSettingManager.GetSetting(SMC.UpdateState, false); + public static bool DiscordState => SMMI.HookSettingManager.GetSetting(SMC.DiscordState, true); public static bool DonateVisible => SMMI.DonateManager.GetSetting(SMC.DonateVisible, true); diff --git a/src/Library/Sucrose.Memory/Constant.cs b/src/Library/Sucrose.Memory/Constant.cs index 4030ddbed..5c5c7e8cf 100644 --- a/src/Library/Sucrose.Memory/Constant.cs +++ b/src/Library/Sucrose.Memory/Constant.cs @@ -78,6 +78,8 @@ public static class Constant public const string UploadValue = "UploadValue"; + public const string UpdateState = "UpdateState"; + public const string BatteryUsage = "BatteryUsage"; public const string BackdropType = "BackdropType"; diff --git a/src/Live/Sucrose.Live.Nebula/App.xaml.cs b/src/Live/Sucrose.Live.Nebula/App.xaml.cs index 3d2d933e3..8eba2c9bd 100644 --- a/src/Live/Sucrose.Live.Nebula/App.xaml.cs +++ b/src/Live/Sucrose.Live.Nebula/App.xaml.cs @@ -9,7 +9,6 @@ using SMR = Sucrose.Memory.Readonly; using SSDEWT = Sucrose.Shared.Dependency.Enum.WallpaperType; using SSEHR = Sucrose.Shared.Engine.Helper.Run; -using SSEMI = Sucrose.Shared.Engine.Manage.Internal; using SSEMM = Sucrose.Shared.Engine.Manage.Manager; using SSENVV = Sucrose.Shared.Engine.Nebula.View.Video; using SSRHR = Sucrose.Shared.Resources.Helper.Resources; diff --git a/src/Live/Sucrose.Live.Vexana/App.xaml.cs b/src/Live/Sucrose.Live.Vexana/App.xaml.cs index 97b517538..abb09ebd9 100644 --- a/src/Live/Sucrose.Live.Vexana/App.xaml.cs +++ b/src/Live/Sucrose.Live.Vexana/App.xaml.cs @@ -9,7 +9,6 @@ using SMR = Sucrose.Memory.Readonly; using SSDEWT = Sucrose.Shared.Dependency.Enum.WallpaperType; using SSEHR = Sucrose.Shared.Engine.Helper.Run; -using SSEMI = Sucrose.Shared.Engine.Manage.Internal; using SSEMM = Sucrose.Shared.Engine.Manage.Manager; using SSEVVG = Sucrose.Shared.Engine.Vexana.View.Gif; using SSRHR = Sucrose.Shared.Resources.Helper.Resources; diff --git a/src/Update/Sucrose.Update/App.xaml.cs b/src/Update/Sucrose.Update/App.xaml.cs index f8da061d6..5f4b09d31 100644 --- a/src/Update/Sucrose.Update/App.xaml.cs +++ b/src/Update/Sucrose.Update/App.xaml.cs @@ -56,6 +56,8 @@ public partial class App : Application private static bool HasError { get; set; } = true; + private static bool HasFile { get; set; } = false; + private static int MinDelay => 1000; public App() @@ -313,6 +315,17 @@ protected async void Configure() Info(SSDEUT.Download); } } + else + { + if (HasFile) + { + Info(SSDEUT.Error); + } + else + { + Info(SSDEUT.Cancelled); + } + } Close(); } @@ -336,6 +349,9 @@ protected override void OnStartup(StartupEventArgs e) if (SSSHI.Basic(SMR.UpdateMutex, SMR.Update)) { + SMMI.UpdateSettingManager.SetSetting(SMC.UpdatePercentage, "0%"); + SMMI.UpdateSettingManager.SetSetting(SMC.UpdateState, false); + Configure(); } else @@ -346,6 +362,7 @@ protected override void OnStartup(StartupEventArgs e) private void OnDownloadStarted(object sender, DownloadStartedEventArgs e) { + SMMI.UpdateSettingManager.SetSetting(SMC.UpdateState, true); HasBundle = true; } @@ -353,13 +370,13 @@ private void OnDownloadFileCompleted(object sender, AsyncCompletedEventArgs e) { if (e.Error != null) { - Info(SSDEUT.Error); HasBundle = false; + HasFile = true; } else if (e.Cancelled) { - Info(SSDEUT.Cancelled); HasBundle = false; + HasFile = false; } } diff --git a/src/Update/Sucrose.Update/Manage/Internal.cs b/src/Update/Sucrose.Update/Manage/Internal.cs index bd78bc5ed..64cdcbddb 100644 --- a/src/Update/Sucrose.Update/Manage/Internal.cs +++ b/src/Update/Sucrose.Update/Manage/Internal.cs @@ -19,12 +19,12 @@ internal static class Internal { RangeLow = 0, RangeHigh = 0, - ChunkCount = 8, + ChunkCount = 4, Timeout = 1000, - ParallelCount = 8, + ParallelCount = 4, RangeDownload = false, - BufferBlockSize = 8000, - ParallelDownload = true, + BufferBlockSize = 4096, + ParallelDownload = false, MaximumBytesPerSecond = 0, MaxTryAgainOnFailover = 5, MinimumSizeOfChunking = 1024,