-
Notifications
You must be signed in to change notification settings - Fork 3
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
1 parent
f885a7c
commit 08b779e
Showing
17 changed files
with
275 additions
and
285 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
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 was deleted.
Oops, something went wrong.
100 changes: 100 additions & 0 deletions
100
OpenLyricsClient/Backend/Settings/Sections/Romanization/RomanizationSection.cs
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,100 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text.Json.Nodes; | ||
using System.Threading.Tasks; | ||
using DevBase.Api.Serializer; | ||
using DevBase.Generics; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
using OpenLyricsClient.Backend.Romanization; | ||
using OpenLyricsClient.Backend.Structure; | ||
using OpenLyricsClient.Backend.Structure.Enum; | ||
using OpenLyricsClient.Backend.Utils; | ||
|
||
namespace OpenLyricsClient.Backend.Settings.Sections.Romanization; | ||
|
||
public class RomanizationSection : ISettingSection | ||
{ | ||
private FileInfo _file; | ||
private JObject _data; | ||
|
||
public RomanizationSection(string filePath) | ||
{ | ||
this._file = new FileInfo(filePath); | ||
} | ||
|
||
public async Task WriteToDisk() | ||
{ | ||
await File.WriteAllTextAsync(this._file.FullName, this._data.ToString()); | ||
} | ||
|
||
public async Task ReadFromDisk() | ||
{ | ||
if (!this._file.Exists) | ||
{ | ||
this._data = Defaults(); | ||
await WriteToDisk(); | ||
return; | ||
} | ||
|
||
await using FileStream stream = this._file.OpenRead(); | ||
using StreamReader reader = new StreamReader(stream); | ||
|
||
this._data = JObject.Parse(reader.ReadToEnd()); | ||
|
||
await stream.FlushAsync(); | ||
|
||
stream.Close(); | ||
reader.Close(); | ||
} | ||
|
||
public async Task AddRomanization(RomanizeSelection selection) | ||
{ | ||
List<RomanizeSelection> tokens = GetValue<List<RomanizeSelection>>("Selections"); | ||
tokens.Add(selection); | ||
|
||
await SetValue("Selections", tokens); | ||
} | ||
|
||
public async Task RemoveRomanization(RomanizeSelection selection) | ||
{ | ||
List<RomanizeSelection> tokens = GetValue<List<RomanizeSelection>>("Selections"); | ||
tokens.Remove(selection); | ||
|
||
await SetValue("Selections", tokens); | ||
} | ||
|
||
public bool ContainsdRomanization(RomanizeSelection selection) | ||
{ | ||
List<RomanizeSelection> tokens = GetValue<List<RomanizeSelection>>("Selections"); | ||
return tokens.Contains(selection); | ||
} | ||
|
||
public T GetValue<T>(string field) | ||
{ | ||
return (T)this._data[field].ToObject<T>(); | ||
} | ||
|
||
public async Task SetValue<T>(string field, T value) | ||
{ | ||
this._data[field] = JToken.FromObject(value); | ||
await WriteToDisk(); | ||
} | ||
|
||
public JObject Defaults() | ||
{ | ||
Structure structure = new Structure | ||
{ | ||
Selections = new List<RomanizeSelection>( | ||
new RomanizeSelection[] | ||
{ | ||
RomanizeSelection.RUSSIA_TO_LATIN, | ||
RomanizeSelection.KOREAN_TO_ROMANJI, | ||
RomanizeSelection.JAPANESE_TO_ROMANJI | ||
}) | ||
}; | ||
|
||
return new JsonDeserializer().Serialize(structure); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
OpenLyricsClient/Backend/Settings/Sections/Romanization/Structure.cs
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 @@ | ||
using System.Collections.Generic; | ||
using OpenLyricsClient.Backend.Romanization; | ||
|
||
namespace OpenLyricsClient.Backend.Settings.Sections.Romanization; | ||
|
||
public class Structure | ||
{ | ||
public List<RomanizeSelection> Selections { get; set; } | ||
} |
9 changes: 9 additions & 0 deletions
9
OpenLyricsClient/Backend/Settings/Sections/Tokens/Structure.cs
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 @@ | ||
using System.Collections.Generic; | ||
using OpenLyricsClient.Backend.Structure; | ||
|
||
namespace OpenLyricsClient.Backend.Settings.Sections.Tokens; | ||
|
||
public class Structure | ||
{ | ||
public List<MusixMatchToken> Tokens { get; set; } | ||
} |
Oops, something went wrong.