From 987a466903b91249ad40adef2f1916132becfe4c Mon Sep 17 00:00:00 2001 From: Garoxas Date: Sun, 10 Nov 2019 15:13:36 +0700 Subject: [PATCH] Export to XLSX #2 --- Windows/Main.cs | 134 ++++++++++++++++++++++++++++- Windows/NX_Game_Info.csproj | 7 +- Windows/Properties/AssemblyInfo.cs | 6 +- Windows/packages.config | 3 +- macOS/Info.plist | 2 +- macOS/MainWindowController.cs | 37 ++++++++ 6 files changed, 181 insertions(+), 8 deletions(-) diff --git a/Windows/Main.cs b/Windows/Main.cs index 0b1720e..6eaafca 100644 --- a/Windows/Main.cs +++ b/Windows/Main.cs @@ -12,6 +12,7 @@ using Bluegrams.Application; using BrightIdeasSoftware; using LibHac; +using OfficeOpenXml; using FsTitle = LibHac.Title; using Title = NX_Game_Info.Common.Title; using ArrayOfTitle = NX_Game_Info.Common.ArrayOfTitle; @@ -387,7 +388,7 @@ private void exportToolStripMenuItem_Click(object sender, EventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Title = "Export Titles"; - saveFileDialog.Filter = "CSV File (*.csv)|*.csv"; + saveFileDialog.Filter = "CSV File (*.csv)|*.csv|Excel Workbook (*.xlsx)|*.xlsx"; Process.log?.WriteLine("\nExport Titles"); @@ -462,6 +463,131 @@ private void exportToolStripMenuItem_Click(object sender, EventArgs e) MessageBox.Show(String.Format("{0} of {1} titles exported", index, titles.Count), Application.ProductName); } } + else if (filename.EndsWith(".xlsx", StringComparison.OrdinalIgnoreCase)) + { + using (ExcelPackage excel = new ExcelPackage()) + { + progressDialog = (IProgressDialog)new ProgressDialog(); + progressDialog.StartProgressDialog(Handle, "Exporting titles"); + + ExcelWorksheet worksheet = excel.Workbook.Worksheets.Add(Common.History.Default.Titles.LastOrDefault().description ?? Application.ProductName); + + worksheet.Cells[1, 1, 1, Title.Properties.Count()].LoadFromArrays(new List { Title.Properties }); + worksheet.Cells["1:1"].Style.Font.Bold = true; + worksheet.Cells["1:1"].Style.Font.Color.SetColor(Color.White); + worksheet.Cells["1:1"].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; + worksheet.Cells["1:1"].Style.Fill.BackgroundColor.SetColor(Color.MidnightBlue); + + uint index = 0, count = (uint)titles.Count; + + foreach (var title in titles) + { + if (progressDialog.HasUserCancelled()) + { + break; + } + + progressDialog.SetLine(2, title.titleName, true, IntPtr.Zero); + progressDialog.SetProgress(index++, count); + + var data = new List + { + new string[] { + title.titleID, + title.baseTitleID, + title.titleName, + title.displayVersion, + title.versionString, + title.latestVersionString, + title.systemUpdateString, + title.systemVersionString, + title.applicationVersionString, + title.masterkeyString, + title.titleKey, + title.publisher, + title.languagesString, + title.filename, + title.filesizeString, + title.typeString, + title.distribution.ToString(), + title.structureString, + title.signatureString, + title.permissionString, + title.error, + } + }; + + worksheet.Cells[(int)index + 1, 1].LoadFromArrays(data); + + string titleID = title.type == TitleType.AddOnContent ? title.titleID : title.baseTitleID ?? ""; + + Process.latestVersions.TryGetValue(titleID, out uint latestVersion); + Process.versionList.TryGetValue(titleID, out uint version); + Process.titleVersions.TryGetValue(titleID, out uint titleVersion); + + if (latestVersion < version || latestVersion < titleVersion) + { + worksheet.Cells[(int)index + 1, 1, (int)index + 1, Title.Properties.Count()].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; + worksheet.Cells[(int)index + 1, 1, (int)index + 1, Title.Properties.Count()].Style.Fill.BackgroundColor.SetColor(title.signature != true ? Color.OldLace : Color.LightYellow); + } + else if (title.signature != true) + { + worksheet.Cells[(int)index + 1, 1, (int)index + 1, Title.Properties.Count()].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; + worksheet.Cells[(int)index + 1, 1, (int)index + 1, Title.Properties.Count()].Style.Fill.BackgroundColor.SetColor(Color.WhiteSmoke); + } + + if (title.permission == Title.Permission.Dangerous) + { + worksheet.Cells[(int)index + 1, 1, (int)index + 1, Title.Properties.Count()].Style.Font.Color.SetColor(Color.DarkRed); + } + else if (title.permission == Title.Permission.Unsafe) + { + worksheet.Cells[(int)index + 1, 1, (int)index + 1, Title.Properties.Count()].Style.Font.Color.SetColor(Color.Indigo); + } + } + + ExcelRange range = worksheet.Cells[1, 1, (int)count + 1, Title.Properties.Count()]; + range.Style.Border.Top.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; + range.Style.Border.Left.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; + range.Style.Border.Right.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; + range.Style.Border.Bottom.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; + + worksheet.Column(1).Width = 18; + worksheet.Column(2).Width = 18; + worksheet.Column(3).AutoFit(); + worksheet.Column(3).Width = Math.Max(worksheet.Column(3).Width, 30); + worksheet.Column(4).Width = 16; + worksheet.Column(5).Width = 16; + worksheet.Column(6).Width = 16; + worksheet.Column(7).Width = 16; + worksheet.Column(8).Width = 16; + worksheet.Column(9).Width = 16; + worksheet.Column(10).Width = 16; + worksheet.Column(11).AutoFit(); + worksheet.Column(11).Width = Math.Max(worksheet.Column(11).Width, 36); + worksheet.Column(12).AutoFit(); + worksheet.Column(12).Width = Math.Max(worksheet.Column(12).Width, 30); + worksheet.Column(13).Width = 18; + worksheet.Column(14).AutoFit(); + worksheet.Column(14).Width = Math.Max(worksheet.Column(14).Width, 54); + worksheet.Column(15).Width = 10; + worksheet.Column(16).Width = 10; + worksheet.Column(17).Width = 12; + worksheet.Column(18).Width = 12; + worksheet.Column(19).Width = 10; + worksheet.Column(20).Width = 10; + worksheet.Column(21).Width = 40; + + excel.SaveAs(new FileInfo(filename)); + + Process.log?.WriteLine("\n{0} of {1} titles exported", index, titles.Count); + + progressDialog.StopProgressDialog(); + Activate(); + + MessageBox.Show(String.Format("{0} of {1} titles exported", index, titles.Count), Application.ProductName); + } + } else { MessageBox.Show(String.Format("This file type is not supported {0}", Path.GetExtension(filename)), Application.ProductName); @@ -483,12 +609,16 @@ private void updateTitleKeysToolStripMenuItem_Click(object sender, EventArgs e) progressDialog.SetLine(2, String.Format("Downloading from {0}", Common.TITLE_KEYS_URI), true, IntPtr.Zero); + int count = Process.keyset?.TitleKeys?.Count ?? 0; + if (Process.updateTitleKeys()) { + Process.log?.WriteLine("\nFound {0} updated title keys", (Process.keyset?.TitleKeys?.Count ?? 0) - count); + progressDialog.StopProgressDialog(); Activate(); - MessageBox.Show(String.Format("Found {0} title keys", Process.keyset?.TitleKeys?.Count), Application.ProductName); + MessageBox.Show(String.Format("Found {0} updated title keys", (Process.keyset?.TitleKeys?.Count ?? 0) - count), Application.ProductName); } else { diff --git a/Windows/NX_Game_Info.csproj b/Windows/NX_Game_Info.csproj index 9dd6f01..d9aec64 100644 --- a/Windows/NX_Game_Info.csproj +++ b/Windows/NX_Game_Info.csproj @@ -37,11 +37,14 @@ NX_Game_Info.ico + + ..\packages\EPPlus.4.5.3.2\lib\net40\EPPlus.dll + ..\packages\ObjectListView.2.7.1.5\lib\ListViewPrinter.dll - ..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll + ..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll ..\packages\ObjectListView.2.7.1.5\lib\ObjectListView.dll @@ -49,6 +52,7 @@ ..\packages\PortableSettingsProvider.0.2.3\lib\net45\PortableSettingsProvider.dll + ..\packages\ObjectListView.2.7.1.5\lib\SparkleLibrary.dll @@ -59,6 +63,7 @@ ..\packages\System.Runtime.CompilerServices.Unsafe.4.6.0\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll + diff --git a/Windows/Properties/AssemblyInfo.cs b/Windows/Properties/AssemblyInfo.cs index 24fdf30..368977f 100644 --- a/Windows/Properties/AssemblyInfo.cs +++ b/Windows/Properties/AssemblyInfo.cs @@ -30,6 +30,6 @@ // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -// [assembly: AssemblyVersion("0.7.0.*")] -[assembly: AssemblyVersion("0.7.0.1")] -[assembly: AssemblyFileVersion("0.7.0.1")] +// [assembly: AssemblyVersion("0.7.1.*")] +[assembly: AssemblyVersion("0.7.1.0")] +[assembly: AssemblyFileVersion("0.7.1.0")] diff --git a/Windows/packages.config b/Windows/packages.config index f2cc1f8..5fd6c26 100644 --- a/Windows/packages.config +++ b/Windows/packages.config @@ -1,6 +1,7 @@  - + + diff --git a/macOS/Info.plist b/macOS/Info.plist index fcefc4f..8b23c47 100644 --- a/macOS/Info.plist +++ b/macOS/Info.plist @@ -7,7 +7,7 @@ CFBundleIdentifier com.garoxas.NX_Game_Info CFBundleShortVersionString - 0.7.0.1 + 0.7.1.0 CFBundleVersion 14 LSMinimumSystemVersion diff --git a/macOS/MainWindowController.cs b/macOS/MainWindowController.cs index 539d63e..d781386 100644 --- a/macOS/MainWindowController.cs +++ b/macOS/MainWindowController.cs @@ -398,6 +398,43 @@ public void Export(NSMenuItem menuItem) }); } + [Export("updateTitleKeys:")] + public void UpdateTitleKeys(NSMenuItem menuItem) + { + Window.BeginSheet(sheet, ProgressComplete); + + title.StringValue = ""; + message.StringValue = String.Format("Downloading from {0}", Common.TITLE_KEYS_URI); + progress.DoubleValue = 0; + + int count = Process.keyset?.TitleKeys?.Count ?? 0; + + if (Process.updateTitleKeys()) + { + Process.log?.WriteLine("\nFound {0} updated title keys", (Process.keyset?.TitleKeys?.Count ?? 0) - count); + + Window.EndSheet(sheet); + + var alert = new NSAlert() + { + InformativeText = String.Format("Found {0} updated title keys", (Process.keyset?.TitleKeys?.Count ?? 0) - count), + MessageText = NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleExecutable").ToString(), + }; + alert.RunModal(); + } + else + { + Window.EndSheet(sheet); + + var alert = new NSAlert() + { + InformativeText = "Failed to download title keys", + MessageText = NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleExecutable").ToString(), + }; + alert.RunModal(); + } + } + [Export("updateVersionList:")] public void UpdateVersionList(NSMenuItem menuItem) {