diff --git a/Igniter/Utilities/IOUtility.cs b/Igniter/Utilities/IOUtility.cs index 128a545..fdb5454 100644 --- a/Igniter/Utilities/IOUtility.cs +++ b/Igniter/Utilities/IOUtility.cs @@ -1,80 +1,10 @@ using System; -using System.Diagnostics; using System.IO; namespace Igniter.Utilities { public static partial class Utility { - public static void CopyFile(string src, string target) - { - try - { - if (File.Exists(src)) - { - if (File.Exists(target)) - { - using (var fs0 = File.OpenRead(src)) - using (var fs1 = File.OpenRead(target)) - { - if (Utility.GetID128(fs0) == Utility.GetID128(fs1)) - { - return; - } - } - - WipeFile(target); - WipeEntry(target); - } - Directory.CreateDirectory(Path.GetDirectoryName(target)); - File.Copy(src, target, true); - } - } - catch - { - } - } - - public static void WipeFile(string filePath) - { - try - { - if (File.Exists(filePath)) - { - File.Delete(filePath); - } - } - catch - { - } - } - - public static void WipeEntry(string entryPath) - { - try - { - if (Directory.Exists(entryPath)) - { - Directory.Delete(entryPath, true); - } - } - catch - { - } - } - - public static void CopyEntry(string src, string target) - { - foreach (var filePath in GetFiles(src)) - { - CopyFile(filePath, Path.Combine(target, Path.GetFileName(filePath))); - } - foreach (var entryPath in GetEntry(src)) - { - CopyEntry(entryPath, Path.Combine(target, Path.GetFileName(entryPath))); - } - } - public static string[] GetFiles(string entryPath, string o = "*") { try diff --git a/Igniter/View/MainWindow.xaml.cs b/Igniter/View/MainWindow.xaml.cs index 001536e..82b5df6 100644 --- a/Igniter/View/MainWindow.xaml.cs +++ b/Igniter/View/MainWindow.xaml.cs @@ -11,7 +11,7 @@ { InitializeComponent(); - StrongReferenceMessenger.Default.Register(this, (recipient, message) => message.Reply(MessageBox.Show(this, message.Text, "Qwilight", message.Input, message.Drawing))); + StrongReferenceMessenger.Default.Register(this, (recipient, message) => message.Reply(MessageBox.Show(recipient as Window, message.Text, "Qwilight", message.Input, message.Drawing))); } void OnLoaded(object sender, RoutedEventArgs e) => _ = (DataContext as MainViewModel).OnLoaded(); diff --git a/Igniter/ViewModels/MainViewModel.cs b/Igniter/ViewModels/MainViewModel.cs index 70740d5..69bbbe4 100644 --- a/Igniter/ViewModels/MainViewModel.cs +++ b/Igniter/ViewModels/MainViewModel.cs @@ -83,11 +83,11 @@ if (new FileInfo(filePath).Length > 0) { - Utility.CopyFile(filePath, targetFilePath); + File.Copy(filePath, targetFilePath, true); } else { - Utility.WipeFile(targetFilePath); + File.Delete(targetFilePath); } } }); @@ -143,7 +143,7 @@ } } case MessageBoxResult.Cancel: - Environment.Exit(1); + Environment.Exit(0); break; } } diff --git a/Qwilight/Assets/Language.json b/Qwilight/Assets/Language.json index 21e2ec6..57d2aa2 100644 --- a/Qwilight/Assets/Language.json +++ b/Qwilight/Assets/Language.json @@ -36,8 +36,8 @@ "en-US": "This ID is already registered." }, "AlreadyLatestDate": { - "ko-KR": "새 버전이 존재하지 않습니다. 강제로 업데이트 할까요?", - "en-US": "Already up to date. Do you want to force an update?" + "ko-KR": "새 버전이 존재하지 않습니다.", + "en-US": "No new version exists." }, "AlreadyLoadingBundle": { "ko-KR": "이미 꾸러미 전송이 진행중입니다.", diff --git a/Qwilight/Compute/DefaultCompute.cs b/Qwilight/Compute/DefaultCompute.cs index 8f5f905..6b39b90 100644 --- a/Qwilight/Compute/DefaultCompute.cs +++ b/Qwilight/Compute/DefaultCompute.cs @@ -4371,7 +4371,7 @@ try { DB.Instance.SaveComment(date, NoteFile, string.Empty, commentID, AvatarName, TotallyLevyingMultiplier, TotallyLevyingAudioMultiplier, ModeComponentValue, Stand.TargetValue, HighestBand, IsBand1, Point.TargetValue, IsPaused, _inputFlags); - using var fs = File.OpenWrite(Path.Combine(QwilightComponent.CommentEntryPath, commentID)); + using var fs = File.Open(Path.Combine(QwilightComponent.CommentEntryPath, commentID), FileMode.Create); _comments.Single().WriteTo(fs); } catch (Exception e) diff --git a/Qwilight/QwilightComponent.cs b/Qwilight/QwilightComponent.cs index 52f17ce..f2ec231 100644 --- a/Qwilight/QwilightComponent.cs +++ b/Qwilight/QwilightComponent.cs @@ -35,7 +35,6 @@ public static readonly string[] DrawingFileFormats = [".bmp", ".gif", ".jpeg", ".jpg", ".png"]; public static readonly string[] MediaFileFormats = [".avi", ".flv", ".m1v", ".mkv", ".mov", ".mp4", ".mpeg", ".mpg", ".wmv"]; public static readonly string[] ModifyMediaFileFormats = [".avi", ".flv", ".m1v", ".mpeg", ".mpg"]; - public static readonly string HashText = Utility.GetID512(File.ReadAllBytes(Path.Combine(AppContext.BaseDirectory, "Qwilight.dll"))); public static readonly Version Date = Assembly.GetEntryAssembly().GetName().Version; public static readonly string DateText = $"{Date.Major}.{Date.Minor}.{Date.Build}"; public static readonly JSON.AssetClient AssetsClientJSON; @@ -102,7 +101,7 @@ QwilightComponent.QwilightAPI = "https://taehui.ddns.net/qwilight/www"; break; case "taehui": - QwilightComponent.TaehuiNetFE = "http://taehui"; + QwilightComponent.TaehuiNetFE = "https://taehui"; QwilightComponent.TaehuiNetAPI = "http://taehui:3000/www"; QwilightComponent.QwilightAPI = "http://taehui:3001/qwilight/www"; break; diff --git a/Qwilight/System/BaseUI/BaseUI.cs b/Qwilight/System/BaseUI/BaseUI.cs index a60aa5a..8677ea9 100644 --- a/Qwilight/System/BaseUI/BaseUI.cs +++ b/Qwilight/System/BaseUI/BaseUI.cs @@ -1437,7 +1437,7 @@ var hashMediaFilePath = Path.Combine(QwilightComponent.MediaEntryPath, $"{hash}{Path.GetExtension(fileName)}"); if (!File.Exists(hashMediaFilePath)) { - using var fs = File.OpenWrite(hashMediaFilePath); + using var fs = File.Open(hashMediaFilePath, FileMode.Open); rms.WriteTo(fs); } handledMediaValues[Path.GetFileName(fileName)] = MediaSystem.Instance.Load(hashMediaFilePath, this, true); diff --git a/Qwilight/System/LevelSystem.cs b/Qwilight/System/LevelSystem.cs index 2792c9c..cb79099 100644 --- a/Qwilight/System/LevelSystem.cs +++ b/Qwilight/System/LevelSystem.cs @@ -3,7 +3,6 @@ using Qwilight.UIComponent; using Qwilight.Utilities; using Qwilight.ViewModel; -using SharpCompress.Common; using System.Buffers; using System.Collections.ObjectModel; using System.IO; @@ -107,27 +106,32 @@ public async ValueTask GetWww(string www) { - return await GetLevelNotifyItem(async levelNotifyItem => + return await GetLevelNotifyItem(async (levelNotifyItem, setCancelGet) => { - using var s = await TwilightSystem.Instance.GetWwwParallel(www); + using var s = await TwilightSystem.Instance.GetWwwParallel(www, setCancelGet); using var sr = new StreamReader(s); - return await (www.IsTailCaselsss(".json") ? GetJSON(levelNotifyItem, s, www) : GetHTML(levelNotifyItem, await sr.ReadToEndAsync(), www)); + return await (www.IsTailCaselsss(".json") ? GetJSON(levelNotifyItem, setCancelGet, s, www) : GetHTML(levelNotifyItem, setCancelGet, await sr.ReadToEndAsync(setCancelGet.Token), www)); }); } - public async ValueTask GetLevelNotifyItem(Func> onNotifyItem) + public async ValueTask GetLevelNotifyItem(Func> onNotifyItem) { + using var setCancelGet = new CancellationTokenSource(); var levelNotifyItem = new NotifyItem { Text = LanguageSystem.Instance.SavingLevelContents, Variety = NotifySystem.NotifyVariety.Handling, - OnStop = wipeTotal => false + OnStop = wipeTotal => + { + setCancelGet.Cancel(); + return false; + } }; try { UIHandler.Instance.HandleParallel(() => ViewModels.Instance.NotifyValue.HandlingNotifyItemCollection.Insert(0, levelNotifyItem)); NotifySystem.Instance.Notify(NotifySystem.NotifyVariety.Info, NotifySystem.NotifyConfigure.NotSave, levelNotifyItem.Text, false, null, null, NotifySystem.SaveLevelID); - return await onNotifyItem(levelNotifyItem); + return await onNotifyItem(levelNotifyItem, setCancelGet); } catch (OperationCanceledException) { @@ -145,17 +149,17 @@ return false; } - public async ValueTask GetHTML(NotifyItem levelNotifyItem, string text, string www) + public async ValueTask GetHTML(NotifyItem levelNotifyItem, CancellationTokenSource setCancelGet, string text, string www) { 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(), www))); - return await GetJSON(levelNotifyItem, s, www); + return await GetJSON(levelNotifyItem, setCancelGet, s, www); } - async ValueTask GetJSON(NotifyItem levelNotifyItem, Stream s, string www) + async ValueTask GetJSON(NotifyItem levelNotifyItem, CancellationTokenSource setCancelGet, Stream s, string www) { var levelTable = await Utility.GetJSON(s); if (levelTable.HasValue) @@ -170,23 +174,23 @@ using (var wwwClient = new HttpClient()) { wwwClient.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0"); - using (var hrm = await wwwClient.GetAsync(target, HttpCompletionOption.ResponseHeadersRead)) + using (var hrm = await wwwClient.GetAsync(target, HttpCompletionOption.ResponseHeadersRead, setCancelGet.Token)) { levelNotifyItem.MaxStatus = hrm.Content.Headers.ContentLength ?? 0L; } using var fs = File.Open(Path.Combine(EntryPath, $"{levelTableFileName}.json"), FileMode.Create); - using var ws = await wwwClient.GetStreamAsync(target); + using var ws = await wwwClient.GetStreamAsync(target, setCancelGet.Token); var data = ArrayPool.Shared.Rent(QwilightComponent.SendUnit); try { var length = 0; - while ((length = await ws.ReadAsync(data.AsMemory(0, data.Length))) > 0) + while ((length = await ws.ReadAsync(data.AsMemory(0, data.Length), setCancelGet.Token)) > 0) { if (levelNotifyItem.IsStopped) { throw new OperationCanceledException(); } - await fs.WriteAsync(data.AsMemory(0, length)); + await fs.WriteAsync(data.AsMemory(0, length), setCancelGet.Token); levelNotifyItem.Status += length; } } @@ -198,7 +202,7 @@ using (var fs = File.Open(Path.Combine(EntryPath, $"#{levelTableFileName}.json"), FileMode.Create)) { s.Position = 0; - await s.CopyToAsync(fs); + await s.CopyToAsync(fs, setCancelGet.Token); } levelNotifyItem.Variety = NotifySystem.NotifyVariety.Closed; levelNotifyItem.Text = LanguageSystem.Instance.SavedLevelContents; diff --git a/Qwilight/System/RGBSystem/RGBSystem.cs b/Qwilight/System/RGBSystem/RGBSystem.cs index 78e5f28..3fd31d1 100644 --- a/Qwilight/System/RGBSystem/RGBSystem.cs +++ b/Qwilight/System/RGBSystem/RGBSystem.cs @@ -356,7 +356,7 @@ var inputs = Configure.Instance.DefaultInputBundlesV6.Inputs[(int)defaultComputer.InputMode]; if (inputs != null) { - for (var i = inputs.Length - 1; i > 0; --i) + for (var i = inputs.Length - 1; i > 0; --i) { foreach (var defaultInput in inputs[i]) { diff --git a/Qwilight/System/TelnetSystem/TelnetSystem.cs b/Qwilight/System/TelnetSystem/TelnetSystem.cs index bf0bbe4..3eece49 100644 --- a/Qwilight/System/TelnetSystem/TelnetSystem.cs +++ b/Qwilight/System/TelnetSystem/TelnetSystem.cs @@ -1,5 +1,4 @@ -using Qwilight.ViewModel; -using System.IO; +using System.IO; using Windows.Win32; using Windows.Win32.UI.WindowsAndMessaging; diff --git a/Qwilight/System/TwilightSystem.cs b/Qwilight/System/TwilightSystem.cs index 25f8722..5f5276e 100644 --- a/Qwilight/System/TwilightSystem.cs +++ b/Qwilight/System/TwilightSystem.cs @@ -15,12 +15,9 @@ using System.IO; using System.Net; using System.Net.Http; -using System.Net.Http.Headers; using System.Net.Security; using System.Net.Sockets; -using System.Security.Authentication; using System.Text; -using System.Windows.Documents; using Windows.Win32.UI.WindowsAndMessaging; namespace Qwilight @@ -235,7 +232,6 @@ } var textEstablish = new { - hash = QwilightComponent.HashText, date = QwilightComponent.DateText, language = Configure.Instance.Language, qwilightName = QwilightName, @@ -1007,7 +1003,7 @@ NotifySystem.Instance.Notify(NotifySystem.NotifyVariety.Info, NotifySystem.NotifyConfigure.NotSave, bundleNotifyItem.Text, false, null, null, NotifySystem.SaveBundleID); } using var setCancelZip = new CancellationTokenSource(); - zipFile.ExtractToDirectory(bundleEntryPath, e => + zipFile.SaveZipEntry(bundleEntryPath, e => { OnSavingZipFile(setCancelZip, e); }, setCancelZip.Token); @@ -1034,7 +1030,7 @@ NotifySystem.Instance.Notify(NotifySystem.NotifyVariety.Info, NotifySystem.NotifyConfigure.NotSave, bundleNotifyItem.Text, false, null, null, NotifySystem.SaveBundleID); } using var setCancelZip = new CancellationTokenSource(); - zipFile.ExtractToDirectory(string.IsNullOrEmpty(Path.GetDirectoryName(zipFile.Entries.Where(zipEntry => zipEntry.Key.IsTailCaselsss(".yaml")).OrderBy(zipEntry => zipEntry.Key).FirstOrDefault().Key)) ? Path.Combine(QwilightComponent.UIEntryPath, twilightSavedBundle.bundleName) : QwilightComponent.UIEntryPath, e => + zipFile.SaveZipEntry(string.IsNullOrEmpty(Path.GetDirectoryName(zipFile.Entries.Where(zipEntry => zipEntry.Key.IsTailCaselsss(".yaml")).OrderBy(zipEntry => zipEntry.Key).FirstOrDefault().Key)) ? Path.Combine(QwilightComponent.UIEntryPath, twilightSavedBundle.bundleName) : QwilightComponent.UIEntryPath, e => { OnSavingZipFile(setCancelZip, e); }); @@ -1051,7 +1047,7 @@ } break; case BundleItem.BundleVariety.Qwilight: - using (var fs = File.OpenWrite(Path.Combine(QwilightComponent.QwilightEntryPath, "Qwilight.zip"))) + using (var fs = File.Open(Path.Combine(QwilightComponent.QwilightEntryPath, "Qwilight.zip"), FileMode.Open)) { dataFlow.CopyTo(fs); } @@ -1092,7 +1088,7 @@ bundleNotifyItem.Text = LanguageSystem.Instance.SavingBundleContents; NotifySystem.Instance.Notify(NotifySystem.NotifyVariety.Info, NotifySystem.NotifyConfigure.NotSave, bundleNotifyItem.Text, false, null, null, NotifySystem.SaveBundleID); using var setCancelZip = new CancellationTokenSource(); - zipFile.ExtractToDirectory(noteFile.EntryItem.EntryPath, e => + zipFile.SaveZipEntry(noteFile.EntryItem.EntryPath, e => { OnSavingZipFile(setCancelZip, e); }); @@ -1433,16 +1429,16 @@ Stop(); } - public async ValueTask GetWwwParallel(string target) + public async ValueTask GetWwwParallel(string target, CancellationTokenSource setCancelWww = null) { if (!target.IsFrontCaselsss(QwilightComponent.QwilightAPI) || IsEstablished) { try { var dataGet = new HttpRequestMessage(HttpMethod.Get, target); - var www = await _wwwClient.SendAsync(dataGet); + var www = await _wwwClient.SendAsync(dataGet, setCancelWww.Token); www.EnsureSuccessStatusCode(); - return await www.Content.ReadAsStreamAsync(); + return await www.Content.ReadAsStreamAsync(setCancelWww.Token); } catch { @@ -1452,16 +1448,16 @@ return Stream.Null; } - public async Task GetWwwParallel(string target) + public async Task GetWwwParallel(string target, CancellationTokenSource setCancelWww = null) { if (target.EqualsCaseless($"{QwilightComponent.TaehuiNetFE}/qwilight/qwilight.json") || !target.IsFrontCaselsss(QwilightComponent.TaehuiNetFE) || IsEstablished) { try { var dataGet = new HttpRequestMessage(HttpMethod.Get, target); - using var www = await _wwwClient.SendAsync(dataGet); + using var www = await _wwwClient.SendAsync(dataGet, setCancelWww.Token); www.EnsureSuccessStatusCode(); - var text = await www.Content.ReadAsStringAsync(); + var text = await www.Content.ReadAsStringAsync(setCancelWww.Token); if (!string.IsNullOrEmpty(text)) { return Utility.GetJSON(text); diff --git a/Qwilight/UIComponent/BundleItem.cs b/Qwilight/UIComponent/BundleItem.cs index ec65e6e..c9656e7 100644 --- a/Qwilight/UIComponent/BundleItem.cs +++ b/Qwilight/UIComponent/BundleItem.cs @@ -32,7 +32,7 @@ public BundleVariety Variety { get; init; } - public bool IsNameVisible => Variety != BundleVariety.Qwilight; + public bool IsQwilightBundle => Variety == BundleVariety.Qwilight; public BundleCompetence BundleCompetence { diff --git a/Qwilight/Utilities/ZipUtility.cs b/Qwilight/Utilities/ZipUtility.cs new file mode 100644 index 0000000..ea802a1 --- /dev/null +++ b/Qwilight/Utilities/ZipUtility.cs @@ -0,0 +1,34 @@ +using SharpCompress.Archives; +using System.IO; + +namespace Qwilight.Utilities +{ + public static partial class Utility + { + public static void SaveZipEntry(this IArchive zipFile, string targetEntryPath, Action onSavingZipFile = null, CancellationToken setCancelSave = default) + { + var totalLength = zipFile.TotalUncompressSize; + var length = 0L; + using var entries = zipFile.ExtractAllEntries(); + while (entries.MoveToNextEntry()) + { + setCancelSave.ThrowIfCancellationRequested(); + + var entry = entries.Entry; + if (!entry.IsDirectory) + { + var entryPath = Path.Combine(targetEntryPath, entry.Key); + Directory.CreateDirectory(entryPath); + + using (var fs = File.Open(entryPath, FileMode.Create)) + { + entries.WriteEntryTo(fs); + } + + length += entry.Size; + onSavingZipFile?.Invoke(length / (double)totalLength); + } + } + } + } +} diff --git a/Qwilight/View/BundleWindow/BundleView.xaml b/Qwilight/View/BundleWindow/BundleView.xaml index 2195133..72d84fb 100644 --- a/Qwilight/View/BundleWindow/BundleView.xaml +++ b/Qwilight/View/BundleWindow/BundleView.xaml @@ -15,13 +15,13 @@ - +