Skip to content

Commit

Permalink
Minor Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Taiizor committed Sep 27, 2023
1 parent c073734 commit 025307b
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 19 deletions.
41 changes: 40 additions & 1 deletion src/Library/Sucrose.Manager/SettingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,41 @@ public void SetSetting<T>(string key, T value)
}
}

public string ReadSetting()
{
_lock.EnterReadLock();

try
{
lock (lockObject)
{
using Mutex Mutex = new(false, Path.GetFileName(_settingsFilePath));

try
{
try
{
Mutex.WaitOne();
}
catch
{
//
}

return SMHR.Read(_settingsFilePath);
}
finally
{
Mutex.ReleaseMutex();
}
}
}
finally
{
_lock.ExitReadLock();
}
}

public void ApplySetting()
{
_lock.EnterWriteLock();
Expand Down Expand Up @@ -279,7 +314,7 @@ private void ControlFile()
{
if (CheckFile())
{
string json = SMHR.Read(_settingsFilePath);
string json = ReadSetting();

if (string.IsNullOrEmpty(json))
{
Expand All @@ -295,6 +330,10 @@ private void ControlFile()
{
return;
}
else
{
ApplySetting();
}
}
catch
{
Expand Down
2 changes: 1 addition & 1 deletion src/Portal/Sucrose.Portal/Views/Pages/StorePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private async Task Start()

FrameStore.Content = FullStorePage;
}
else if (StoreStage == SSDESST.Broken)
else if (StoreStage == SSDESST.Unknown)
{
UnknownStorePage = new();

Expand Down
41 changes: 24 additions & 17 deletions src/Shared/Sucrose.Shared.Store/Helper/Download.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,34 +42,41 @@ public static bool Store(string Store, string Agent, string Key)

InitializeClient(Agent, Key);

List<SSIIC> Contents = SSHG.ContentsList(SMR.Owner, SMR.StoreRepository, SMR.StoreSource, SMR.Branch, Agent, Key);

foreach (SSIIC Content in Contents)
try
{
if (Content.Name == SMR.StoreFile)
List<SSIIC> Contents = SSHG.ContentsList(SMR.Owner, SMR.StoreRepository, SMR.StoreSource, SMR.Branch, Agent, Key);

foreach (SSIIC Content in Contents)
{
using HttpResponseMessage Response = SSSMI.Client.GetAsync(Content.DownloadUrl).Result;
if (Content.Name == SMR.StoreFile)
{
using HttpResponseMessage Response = SSSMI.Client.GetAsync(Content.DownloadUrl).Result;

Response.EnsureSuccessStatusCode();
Response.EnsureSuccessStatusCode();

if (Response.IsSuccessStatusCode)
{
using HttpContent HContent = Response.Content;
if (Response.IsSuccessStatusCode)
{
using HttpContent HContent = Response.Content;

using Stream Stream = HContent.ReadAsStreamAsync().Result;
using FileStream FStream = new(Store, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None);
using Stream Stream = HContent.ReadAsStreamAsync().Result;
using FileStream FStream = new(Store, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None);

Stream.CopyTo(FStream);
Stream.CopyTo(FStream);

Stream.Dispose();
FStream.Dispose();
Stream.Dispose();
FStream.Dispose();

return true;
}
return true;
}

break;
break;
}
}
}
catch
{
return false;
}

return false;
}
Expand Down

0 comments on commit 025307b

Please sign in to comment.