diff --git a/Qwilight/Assets/Language.json b/Qwilight/Assets/Language.json index 60acaab..375cd7e 100644 --- a/Qwilight/Assets/Language.json +++ b/Qwilight/Assets/Language.json @@ -2643,9 +2643,9 @@ "ko-KR": "아직 서로 친구가 아님", "en-US": "We're not friends yet." }, - "NotValidNetLevelContents": { - "ko-KR": "올바르지 않은 주소입니다. ({0})", - "en-US": "Invalid address. ({0})" + "NotValidLevelContents": { + "ko-KR": "올바르지 않은 난이도 테이블입니다. ({0})", + "en-US": "Invalid difficulty table. ({0})" }, "NotValidNoteFile": { "ko-KR": "노트 파일을 먼저 선택하세요", diff --git a/Qwilight/System/Configure/Configure.cs b/Qwilight/System/Configure/Configure.cs index 2ccacb2..87c8e3e 100644 --- a/Qwilight/System/Configure/Configure.cs +++ b/Qwilight/System/Configure/Configure.cs @@ -2281,7 +2281,7 @@ void OnSetLastDefaultEntryItem() { - LevelSystem.Instance.LoadJSON(false); + LevelSystem.Instance.Load(false); } public UIItem UIItemValue diff --git a/Qwilight/System/LanguageSystem/LanguageSystem.g.cs b/Qwilight/System/LanguageSystem/LanguageSystem.g.cs index f80e263..4139526 100644 --- a/Qwilight/System/LanguageSystem/LanguageSystem.g.cs +++ b/Qwilight/System/LanguageSystem/LanguageSystem.g.cs @@ -663,7 +663,7 @@ public string NotSupportedFileContents { get; set; } public string NotTubeText { get; set; } public string NotUbuntuSituationContents { get; set; } - public string NotValidNetLevelContents { get; set; } + public string NotValidLevelContents { get; set; } public string NotValidNoteFile { get; set; } public string NotVESAText { get; set; } public string NotVibrationModeText { get; set; } diff --git a/Qwilight/System/LevelSystem.cs b/Qwilight/System/LevelSystem.cs index f366c57..0486648 100644 --- a/Qwilight/System/LevelSystem.cs +++ b/Qwilight/System/LevelSystem.cs @@ -38,7 +38,7 @@ public void LoadLevelFiles() => Utility.SetUICollection(LevelFileNames, Utility.GetFiles(EntryPath).Where(levelFile => !Path.GetFileName(levelFile).StartsWith('#') && levelFile.IsTailCaselsss(".json")).Select(levelFile => Path.GetFileNameWithoutExtension(levelFile)).ToArray()); - public void LoadJSON(bool isNotify) + public void Load(bool isNotify) { LevelID128s.Clear(); LevelID256s.Clear(); @@ -106,21 +106,35 @@ public async ValueTask LoadWww(string www) { - using var sr = new StreamReader(await TwilightSystem.Instance.GetWwwParallel(www).ConfigureAwait(false)); - return await LoadHTML(await sr.ReadToEndAsync().ConfigureAwait(false), www); + using var s = await TwilightSystem.Instance.GetWwwParallel(www).ConfigureAwait(false); + using var sr = new StreamReader(s); + return await (www.IsTailCaselsss(".json") ? LoadJSON(s, www) : LoadHTML(await sr.ReadToEndAsync().ConfigureAwait(false), www)); } public async ValueTask LoadHTML(string text, string www) { - var data = ArrayPool.Shared.Rent(QwilightComponent.SendUnit); try { var levelCompiler = new HtmlDocument(); levelCompiler.LoadHtml(text); using var s = await TwilightSystem.Instance.GetWwwParallel(WebUtility.HtmlDecode(ModifyDataValue(levelCompiler.CreateNavigator().SelectSingleNode("/html/head/meta[@name='bmstable']/@content")?.ToString() ?? levelCompiler.CreateNavigator().SelectSingleNode("/html/body/meta[@name='bmstable']/@content")?.ToString() - ?? levelCompiler.CreateNavigator().SelectSingleNode("/html/head/body/meta[@name='bmstable']/@content")?.ToString()))).ConfigureAwait(false); - var levelTable = await Utility.GetJSON(s).ConfigureAwait(false); + ?? levelCompiler.CreateNavigator().SelectSingleNode("/html/head/body/meta[@name='bmstable']/@content")?.ToString(), www))).ConfigureAwait(false); + return await LoadJSON(s, www); + } + catch (Exception e) + { + NotifySystem.Instance.Notify(NotifySystem.NotifyVariety.Warning, NotifySystem.NotifyConfigure.Default, string.Format(LanguageSystem.Instance.NotValidLevelContents, e.Message), true, null, null, NotifySystem.SaveLevelID); + } + return false; + } + + public async ValueTask LoadJSON(Stream s, string www) + { + var data = ArrayPool.Shared.Rent(QwilightComponent.SendUnit); + try + { + var levelTable = await Utility.GetJSON(s); if (levelTable.HasValue) { var levelTableValue = levelTable.Value; @@ -132,7 +146,7 @@ }; UIHandler.Instance.HandleParallel(() => ViewModels.Instance.NotifyValue.NotifyItemCollection.Insert(0, savingLevelItem)); NotifySystem.Instance.Notify(NotifySystem.NotifyVariety.Info, NotifySystem.NotifyConfigure.NotSave, savingLevelItem.Text, true, null, null, NotifySystem.SaveLevelID); - var target = ModifyDataValue(levelTableValue.data_url); + var target = ModifyDataValue(levelTableValue.data_url, www); var levelTableFileName = levelTableValue.name; foreach (var targetFileName in Path.GetInvalidFileNameChars()) { @@ -176,29 +190,10 @@ return true; } } - - string ModifyDataValue(string dataValue) - { - if (!Uri.IsWellFormedUriString(dataValue, UriKind.Absolute)) - { - if (www.Substring(www.LastIndexOf('/')).Contains('.') || www.EndsWith('/')) - { - return $"{www}/../{dataValue}"; - } - else - { - return $"{www}/{dataValue}"; - } - } - else - { - return dataValue; - } - } } catch (Exception e) { - NotifySystem.Instance.Notify(NotifySystem.NotifyVariety.Warning, NotifySystem.NotifyConfigure.Default, string.Format(LanguageSystem.Instance.NotValidNetLevelContents, e.Message), true, null, null, NotifySystem.SaveLevelID); + NotifySystem.Instance.Notify(NotifySystem.NotifyVariety.Warning, NotifySystem.NotifyConfigure.Default, string.Format(LanguageSystem.Instance.NotValidLevelContents, e.Message), true, null, null, NotifySystem.SaveLevelID); } finally { @@ -206,5 +201,24 @@ } return false; } + + string ModifyDataValue(string dataValue, string www) + { + if (!Uri.IsWellFormedUriString(dataValue, UriKind.Absolute)) + { + if (www.Substring(www.LastIndexOf('/')).Contains('.') || www.EndsWith('/')) + { + return $"{www}/../{dataValue}"; + } + else + { + return $"{www}/{dataValue}"; + } + } + else + { + return dataValue; + } + } } } diff --git a/Qwilight/ViewModel/AvatarViewModel.cs b/Qwilight/ViewModel/AvatarViewModel.cs index 39bbd0a..1ea16fe 100644 --- a/Qwilight/ViewModel/AvatarViewModel.cs +++ b/Qwilight/ViewModel/AvatarViewModel.cs @@ -1228,7 +1228,7 @@ var filePath = StrongReferenceMessenger.Default.Send(new ViewFileWindow { Filters = [".png"] - }); + }).Response; if (!string.IsNullOrEmpty(filePath) && await TwilightSystem.Instance.PostAvatarDrawingParallel($"{QwilightComponent.TaehuiNetAPI}/avatar/drawing", filePath).ConfigureAwait(false)) { AvatarWwwValue = new(TwilightSystem.Instance.AvatarID, AvatarWwwValue.AvatarTitleValue, AvatarWwwValue.AvatarEdge, true); diff --git a/Qwilight/ViewModel/ConfigureViewModel.cs b/Qwilight/ViewModel/ConfigureViewModel.cs index 2e28460..5183afc 100644 --- a/Qwilight/ViewModel/ConfigureViewModel.cs +++ b/Qwilight/ViewModel/ConfigureViewModel.cs @@ -264,7 +264,7 @@ var filePath = StrongReferenceMessenger.Default.Send(new ViewFileWindow { Filters = QwilightComponent.DrawingFileFormats - }); + }).Response; if (!string.IsNullOrEmpty(filePath)) { Configure.Instance.DefaultDrawingFilePath = filePath; @@ -769,7 +769,7 @@ var filePath = StrongReferenceMessenger.Default.Send(new ViewFileWindow { Filters = QwilightComponent.AudioFileFormats - }); + }).Response; if (!string.IsNullOrEmpty(filePath)) { Configure.Instance.BanalAudioFilePath = filePath; @@ -793,7 +793,7 @@ var filePath = StrongReferenceMessenger.Default.Send(new ViewFileWindow { Filters = QwilightComponent.DrawingFileFormats.Concat(QwilightComponent.MediaFileFormats) - }); + }).Response; if (!string.IsNullOrEmpty(filePath)) { Configure.Instance.BanalMediaFilePath = filePath; @@ -814,7 +814,7 @@ var filePath = StrongReferenceMessenger.Default.Send(new ViewFileWindow { Filters = QwilightComponent.DrawingFileFormats.Concat(QwilightComponent.MediaFileFormats) - }); + }).Response; if (!string.IsNullOrEmpty(filePath)) { Configure.Instance.BanalFailedMediaFilePath = filePath; diff --git a/Qwilight/ViewModel/LevelViewModel.cs b/Qwilight/ViewModel/LevelViewModel.cs index 5595a96..a89babb 100644 --- a/Qwilight/ViewModel/LevelViewModel.cs +++ b/Qwilight/ViewModel/LevelViewModel.cs @@ -39,7 +39,7 @@ { if (IsLoaded) { - LevelSystem.Instance.LoadJSON(true); + LevelSystem.Instance.Load(true); SetLevelItemCollection(); } } @@ -71,7 +71,7 @@ { if (await LevelSystem.Instance.LoadWww(text)) { - LevelSystem.Instance.LoadJSON(true); + LevelSystem.Instance.Load(true); SetLevelItemCollection(); } } @@ -82,7 +82,7 @@ { if (await LevelSystem.Instance.LoadWww(www)) { - LevelSystem.Instance.LoadJSON(true); + LevelSystem.Instance.Load(true); SetLevelItemCollection(); } } @@ -94,10 +94,10 @@ var filePath = StrongReferenceMessenger.Default.Send(new ViewFileWindow { Filters = [".htm", ".html"] - }); + }).Response; if (!string.IsNullOrEmpty(filePath) && await LevelSystem.Instance.LoadHTML(await File.ReadAllTextAsync(filePath).ConfigureAwait(false), string.Empty)) { - LevelSystem.Instance.LoadJSON(true); + LevelSystem.Instance.Load(true); SetLevelItemCollection(); } } @@ -109,7 +109,7 @@ { if (await LevelSystem.Instance.LoadWww(target)) { - LevelSystem.Instance.LoadJSON(true); + LevelSystem.Instance.Load(true); SetLevelItemCollection(); } } diff --git a/Qwilight/ViewModel/NoteFileViewModel.cs b/Qwilight/ViewModel/NoteFileViewModel.cs index 4962c78..15526d9 100644 --- a/Qwilight/ViewModel/NoteFileViewModel.cs +++ b/Qwilight/ViewModel/NoteFileViewModel.cs @@ -93,7 +93,7 @@ var filePath = StrongReferenceMessenger.Default.Send(new ViewFileWindow { Filters = [".exe"] - }); + }).Response; if (!string.IsNullOrEmpty(filePath)) { Configure.Instance.BMSEditorFilePath = filePath; @@ -189,7 +189,7 @@ var filePath = StrongReferenceMessenger.Default.Send(new ViewFileWindow { Filters = [".exe"] - }); + }).Response; if (!string.IsNullOrEmpty(filePath)) { Configure.Instance.BMSONEditorFilePath = filePath; diff --git a/Qwilight/ViewModel/SiteViewModel.cs b/Qwilight/ViewModel/SiteViewModel.cs index 19353e7..e9658f2 100644 --- a/Qwilight/ViewModel/SiteViewModel.cs +++ b/Qwilight/ViewModel/SiteViewModel.cs @@ -251,7 +251,7 @@ var filePath = StrongReferenceMessenger.Default.Send(new ViewFileWindow { Filters = ["*"] - }); + }).Response; if (!string.IsNullOrEmpty(filePath)) { TwilightSystem.Instance.SendParallel(Event.Types.EventID.PostFile, Path.GetFileName(filePath), UnsafeByteOperations.UnsafeWrap(await File.ReadAllBytesAsync(filePath).ConfigureAwait(false)));