-
-
Notifications
You must be signed in to change notification settings - Fork 23
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
30 changed files
with
423 additions
and
205 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using SMR = Sucrose.Memory.Readonly; | ||
|
||
namespace Sucrose.Signal.Helper | ||
{ | ||
internal static class Reader | ||
{ | ||
public static async Task<string> Read(string filePath) | ||
{ | ||
try | ||
{ | ||
using FileStream fileStream = new(filePath, FileMode.Open, FileAccess.Read, FileShare.None); | ||
using StreamReader reader = new(fileStream); | ||
|
||
return reader.ReadToEnd(); | ||
} | ||
catch | ||
{ | ||
try | ||
{ | ||
await Task.Delay(SMR.Randomise.Next(5, 50)); | ||
|
||
using FileStream fileStream = new(filePath, FileMode.Open, FileAccess.Read, FileShare.None); | ||
using StreamReader reader = new(fileStream); | ||
|
||
return reader.ReadToEnd(); | ||
} | ||
catch | ||
{ | ||
try | ||
{ | ||
await Task.Delay(SMR.Randomise.Next(5, 50)); | ||
|
||
using FileStream fileStream = new(filePath, FileMode.Open, FileAccess.Read, FileShare.None); | ||
using StreamReader reader = new(fileStream); | ||
|
||
return reader.ReadToEnd(); | ||
} | ||
catch | ||
{ | ||
return string.Empty; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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,48 @@ | ||
using SMR = Sucrose.Memory.Readonly; | ||
|
||
namespace Sucrose.Signal.Helper | ||
{ | ||
internal static class Writer | ||
{ | ||
public static async void Write(string filePath, string fileContent) | ||
{ | ||
FileMode fileMode = File.Exists(filePath) ? FileMode.Truncate : FileMode.CreateNew; | ||
|
||
try | ||
{ | ||
using FileStream fileStream = new(filePath, fileMode, FileAccess.Write, FileShare.None); | ||
using StreamWriter writer = new(fileStream); | ||
|
||
writer.Write(fileContent); | ||
} | ||
catch | ||
{ | ||
try | ||
{ | ||
await Task.Delay(SMR.Randomise.Next(5, 50)); | ||
|
||
using FileStream fileStream = new(filePath, fileMode, FileAccess.Write, FileShare.None); | ||
using StreamWriter writer = new(fileStream); | ||
|
||
writer.Write(fileContent); | ||
} | ||
catch | ||
{ | ||
try | ||
{ | ||
await Task.Delay(SMR.Randomise.Next(5, 50)); | ||
|
||
using FileStream fileStream = new(filePath, fileMode, FileAccess.Write, FileShare.None); | ||
using StreamWriter writer = new(fileStream); | ||
|
||
writer.Write(fileContent); | ||
} | ||
catch | ||
{ | ||
// | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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,11 @@ | ||
namespace Sucrose.Signal.Interface | ||
{ | ||
public class Launcher | ||
{ | ||
public bool Hide { get; set; } = false; | ||
|
||
public bool Show { get; set; } = false; | ||
|
||
public bool Release { get; set; } = false; | ||
} | ||
} |
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,9 @@ | ||
namespace Sucrose.Signal.Interface | ||
{ | ||
public class Websiter | ||
{ | ||
public bool Hook { get; set; } = false; | ||
|
||
public string Url { get; set; } = string.Empty; | ||
} | ||
} |
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,13 @@ | ||
using SSST = Sucrose.Signal.SignalT; | ||
|
||
namespace Sucrose.Signal.Manage | ||
{ | ||
public static class Internal | ||
{ | ||
public static readonly SSST PortalManager = new("Portal.sgnl"); | ||
|
||
public static readonly SSST LauncherManager = new("Launcher.sgnl"); | ||
|
||
public static readonly SSST WebsiterManager = new("Websiter.sgnl"); | ||
} | ||
} |
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,149 @@ | ||
using System.Text.Json; | ||
using SMR = Sucrose.Memory.Readonly; | ||
using SSHR = Sucrose.Signal.Helper.Reader; | ||
using SSHW = Sucrose.Signal.Helper.Writer; | ||
|
||
namespace Sucrose.Signal | ||
{ | ||
public class SignalT(string Name) | ||
{ | ||
private readonly string Source = Path.Combine(SMR.AppDataPath, SMR.AppName, SMR.CacheFolder, SMR.Signal); | ||
private readonly JsonSerializerOptions Options = new() { WriteIndented = true }; | ||
private readonly Random Random = new(); | ||
private FileSystemWatcher FileWatcher; | ||
|
||
public FileSystemEventHandler CreatedEventHandler; | ||
public FileSystemEventHandler ChangedEventHandler; | ||
public FileSystemEventHandler DeletedEventHandler; | ||
public RenamedEventHandler RenamedEventHandler; | ||
|
||
public void StopChannel() | ||
{ | ||
if (FileWatcher != null) | ||
{ | ||
FileWatcher.EnableRaisingEvents = false; | ||
FileWatcher.Dispose(); | ||
} | ||
} | ||
|
||
public void StartChannel(FileSystemEventHandler Handler) | ||
{ | ||
CreatedEventHandler += Handler; | ||
|
||
if (Directory.Exists(Source)) | ||
{ | ||
string[] Files = Directory.GetFiles(Source, "*.*", SearchOption.TopDirectoryOnly); | ||
|
||
foreach (string Record in Files) | ||
{ | ||
if (FileCheck(Record)) | ||
{ | ||
File.Delete(Record); | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
Directory.CreateDirectory(Source); | ||
} | ||
|
||
FileWatcher = new() | ||
{ | ||
NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName, | ||
Filter = "*.*", | ||
Path = Source | ||
}; | ||
|
||
FileWatcher.Created += (s, e) => | ||
{ | ||
if (FileCheck(e.FullPath)) | ||
{ | ||
CreatedEventHandler?.Invoke(s, e); | ||
} | ||
}; | ||
|
||
FileWatcher.Changed += (s, e) => | ||
{ | ||
if (FileCheck(e.FullPath)) | ||
{ | ||
ChangedEventHandler?.Invoke(s, e); | ||
} | ||
}; | ||
|
||
FileWatcher.Deleted += (s, e) => | ||
{ | ||
if (FileCheck(e.FullPath)) | ||
{ | ||
DeletedEventHandler?.Invoke(s, e); | ||
} | ||
}; | ||
|
||
FileWatcher.Renamed += (s, e) => | ||
{ | ||
if (FileCheck(e.FullPath)) | ||
{ | ||
RenamedEventHandler?.Invoke(s, e); | ||
} | ||
}; | ||
|
||
FileWatcher.EnableRaisingEvents = true; | ||
} | ||
|
||
public void FileSave<T>(T Data) | ||
{ | ||
string Destination = Path.Combine(Source, Name); | ||
|
||
while (File.Exists(Destination)) | ||
{ | ||
Destination = Path.Combine(Source, $"{Path.GetFileNameWithoutExtension(Name)}-{Random.Next(0, int.MaxValue)}{Path.GetExtension(Name)}"); | ||
} | ||
|
||
SSHW.Write(Destination, JsonSerializer.Serialize(Data, Options)); | ||
} | ||
|
||
public string FileName(string Source) | ||
{ | ||
return Path.GetFileName(Source); | ||
} | ||
|
||
public T FileRead<T>(string Source, T Default) | ||
{ | ||
try | ||
{ | ||
string Data = SSHR.Read(Source).Result; | ||
|
||
return JsonSerializer.Deserialize<T>(Data, Options); | ||
} | ||
catch | ||
{ | ||
return Default; | ||
} | ||
} | ||
|
||
public string FileRead(string Source, string Default) | ||
{ | ||
try | ||
{ | ||
string Data = SSHR.Read(Source).Result; | ||
|
||
return Data; | ||
} | ||
catch | ||
{ | ||
return Default; | ||
} | ||
} | ||
|
||
private bool FileCheck(string Source) | ||
{ | ||
if (FileName(Source).Contains(Path.GetFileNameWithoutExtension(Name)) || FileName(Source) == Name) | ||
{ | ||
return true; | ||
} | ||
else | ||
{ | ||
return false; | ||
} | ||
} | ||
} | ||
} |
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,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<Version>$([System.DateTime]::Today.ToString(yy)).$([System.DateTime]::Today.ToString(MM)).$([System.DateTime]::Today.ToString(dd))</Version> | ||
<TargetFrameworks>netstandard2.0;netstandard2.1;net48;net481;net6.0;net7.0;net8.0</TargetFrameworks> | ||
<OutputPath>..\..\Sucrose\Signal</OutputPath> | ||
<AssemblyVersion>$(Version)</AssemblyVersion> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<AnalysisLevel>preview</AnalysisLevel> | ||
<FileVersion>$(Version)</FileVersion> | ||
<LangVersion>preview</LangVersion> | ||
</PropertyGroup> | ||
|
||
<ItemGroup Condition="$(TargetFramework.StartsWith('net48')) OR $(TargetFramework.StartsWith('netstandard'))"> | ||
<PackageReference Include="System.Text.Json" Version="8.0.0-rc.2.23479.6" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Sucrose.Memory\Sucrose.Memory.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.