Skip to content

Commit

Permalink
Update Improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
Taiizor committed Oct 6, 2023
1 parent 302050a commit 48c598a
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 13 deletions.
9 changes: 7 additions & 2 deletions src/Library/Sucrose.Manager/Helper/Reader.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using SMHC = Sucrose.Manager.Helper.Cleaner;
using SMR = Sucrose.Memory.Readonly;

namespace Sucrose.Manager.Helper
{
Expand All @@ -17,6 +18,8 @@ public static async Task<string> 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);

Expand All @@ -26,7 +29,7 @@ public static async Task<string> 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);
Expand All @@ -51,13 +54,15 @@ public static async Task<string> 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));
}
Expand Down
13 changes: 10 additions & 3 deletions src/Library/Sucrose.Manager/Helper/Writer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using SMHC = Sucrose.Manager.Helper.Cleaner;
using SMR = Sucrose.Memory.Readonly;

namespace Sucrose.Manager.Helper
{
Expand All @@ -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);

Expand All @@ -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);
Expand All @@ -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));
Expand All @@ -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);

Expand All @@ -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));
}
Expand Down
2 changes: 2 additions & 0 deletions src/Library/Sucrose.Manager/Manage/Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/Library/Sucrose.Memory/Constant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
1 change: 0 additions & 1 deletion src/Live/Sucrose.Live.Nebula/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/Live/Sucrose.Live.Vexana/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 19 additions & 2 deletions src/Update/Sucrose.Update/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -313,6 +315,17 @@ protected async void Configure()
Info(SSDEUT.Download);
}
}
else
{
if (HasFile)
{
Info(SSDEUT.Error);
}
else
{
Info(SSDEUT.Cancelled);
}
}

Close();
}
Expand All @@ -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
Expand All @@ -346,20 +362,21 @@ protected override void OnStartup(StartupEventArgs e)

private void OnDownloadStarted(object sender, DownloadStartedEventArgs e)
{
SMMI.UpdateSettingManager.SetSetting(SMC.UpdateState, true);
HasBundle = true;
}

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;
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/Update/Sucrose.Update/Manage/Internal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 48c598a

Please sign in to comment.