1
0
mirror of synced 2025-02-25 14:34:45 +01:00

added more exception guards

This commit is contained in:
NotImplementedLife 2023-07-17 13:24:28 +03:00
parent 6b1008bfae
commit c2e0f761d7
3 changed files with 49 additions and 15 deletions

View File

@ -1,4 +1,5 @@
using System.Text.Encodings.Web; using System.Diagnostics;
using System.Text.Encodings.Web;
using System.Text.Json; using System.Text.Json;
using System.Text.Unicode; using System.Text.Unicode;

View File

@ -81,12 +81,39 @@ namespace TaikoSoundEditor
}); });
private void OkButton_Click(object sender, EventArgs e) => RunGuard(() => private void OkButton_Click(object sender, EventArgs e) => RunGuard(() =>
{
try
{ {
MusicAttributes = Json.Deserialize<MusicAttributes>(GZ.DecompressString(MusicAttributePath)); MusicAttributes = Json.Deserialize<MusicAttributes>(GZ.DecompressString(MusicAttributePath));
}
catch(Exception ex)
{
throw new Exception($"Failed to parse\n{MusicAttributePath}\nReason:\n{ex.InnerException}");
}
try
{
MusicOrders = Json.Deserialize<MusicOrders>(GZ.DecompressString(MusicOrderPath)); MusicOrders = Json.Deserialize<MusicOrders>(GZ.DecompressString(MusicOrderPath));
}
catch (Exception ex)
{
throw new Exception($"Failed to parse\n{MusicOrderPath}\nReason:\n{ex.InnerException}");
}
try
{
MusicInfos = Json.Deserialize<MusicInfos>(GZ.DecompressString(MusicInfoPath)); MusicInfos = Json.Deserialize<MusicInfos>(GZ.DecompressString(MusicInfoPath));
}
catch (Exception ex)
{
throw new Exception($"Failed to parse\n{MusicInfoPath}\nReason:\n{ex.InnerException}");
}
try
{
WordList = Json.Deserialize<WordList>(GZ.DecompressString(WordListPath)); WordList = Json.Deserialize<WordList>(GZ.DecompressString(WordListPath));
}
catch (Exception ex)
{
throw new Exception($"Failed to parse\n{WordListPath}\nReason:\n{ex.InnerException}");
}
LoadedMusicBox.DataSource = MusicInfos.Items; LoadedMusicBox.DataSource = MusicInfos.Items;
TabControl.SelectedIndex = 1; TabControl.SelectedIndex = 1;
@ -98,14 +125,14 @@ namespace TaikoSoundEditor
public static void RunGuard(Action action) public static void RunGuard(Action action)
{ {
try //try
{ {
action(); action();
} }
catch (Exception ex) /*catch (Exception ex)
{ {
Error(ex); Error(ex);
} }*/
} }
public static void Error(Exception e) public static void Error(Exception e)
@ -228,7 +255,7 @@ namespace TaikoSoundEditor
ns.Word = new Word { Key = $"song_{songName}", JapaneseText = tja.Headers.Title }; ns.Word = new Word { Key = $"song_{songName}", JapaneseText = tja.Headers.Title };
ns.WordSub = new Word { Key = $"song_sub_{songName}", JapaneseText = tja.Headers.Subtitle }; ns.WordSub = new Word { Key = $"song_sub_{songName}", JapaneseText = tja.Headers.Subtitle };
ns.WordDetail = new Word { Key = $"song_detail_{songName}", JapaneseText = "[song details...]" }; ns.WordDetail = new Word { Key = $"song_detail_{songName}", JapaneseText = tja.Headers.TitleJa };
mi.EasyOnpuNum = tja.Courses[0].Converted.Notes.Length; mi.EasyOnpuNum = tja.Courses[0].Converted.Notes.Length;
mi.NormalOnpuNum = tja.Courses[1].Converted.Notes.Length; mi.NormalOnpuNum = tja.Courses[1].Converted.Notes.Length;
@ -342,6 +369,8 @@ namespace TaikoSoundEditor
var jmo = Json.Serialize(mo); var jmo = Json.Serialize(mo);
var jwl = Json.Serialize(wl); var jwl = Json.Serialize(wl);
jma = jma.Replace("\"new\": true,", "\"new\":true,");
File.WriteAllText(Path.Combine(path,"musicinfo"), jmi); File.WriteAllText(Path.Combine(path,"musicinfo"), jmi);
File.WriteAllText(Path.Combine(path,"music_attribute"), jma); File.WriteAllText(Path.Combine(path,"music_attribute"), jma);
File.WriteAllText(Path.Combine(path,"music_order"), jmo); File.WriteAllText(Path.Combine(path,"music_order"), jmo);

6
TJA.cs
View File

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Reflection;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -36,7 +37,7 @@ namespace TaikoSoundEditor
static readonly string[] HEADER_GLOBAL = new string[] static readonly string[] HEADER_GLOBAL = new string[]
{ {
"TITLE", "SUBTITLE", "BPM", "WAVE", "OFFSET", "DEMOSTART","GENRE", "TITLE", "TITLEJA", "SUBTITLE", "BPM", "WAVE", "OFFSET", "DEMOSTART","GENRE",
}; };
static readonly string[] HEADER_COURSE = new string[] static readonly string[] HEADER_COURSE = new string[]
@ -274,6 +275,8 @@ namespace TaikoSoundEditor
{ {
if (parsed.Name == "TITLE") if (parsed.Name == "TITLE")
headers.Title = parsed.Value; headers.Title = parsed.Value;
if (parsed.Name == "TITLEJA")
headers.TitleJa = parsed.Value;
if (parsed.Name == "SUBTITLE") if (parsed.Name == "SUBTITLE")
headers.Subtitle = parsed.Value; headers.Subtitle = parsed.Value;
if (parsed.Name == "BPM") if (parsed.Name == "BPM")
@ -377,6 +380,7 @@ namespace TaikoSoundEditor
{ {
public string Title { get; set; } = ""; public string Title { get; set; } = "";
public string Subtitle { get; set; } = ""; public string Subtitle { get; set; } = "";
public string TitleJa { get; set; } = "";
public float Bpm { get; set; } = 120; public float Bpm { get; set; } = 120;
public string Wave { get; set; } = ""; public string Wave { get; set; } = "";
public float Offset { get; set; } = 0; public float Offset { get; set; } = 0;