Skip to content

Commit 987a466

Browse files
committed
Export to XLSX #2
1 parent e5f77c3 commit 987a466

File tree

6 files changed

+181
-8
lines changed

6 files changed

+181
-8
lines changed

Windows/Main.cs

+132-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using Bluegrams.Application;
1313
using BrightIdeasSoftware;
1414
using LibHac;
15+
using OfficeOpenXml;
1516
using FsTitle = LibHac.Title;
1617
using Title = NX_Game_Info.Common.Title;
1718
using ArrayOfTitle = NX_Game_Info.Common.ArrayOfTitle;
@@ -387,7 +388,7 @@ private void exportToolStripMenuItem_Click(object sender, EventArgs e)
387388
{
388389
SaveFileDialog saveFileDialog = new SaveFileDialog();
389390
saveFileDialog.Title = "Export Titles";
390-
saveFileDialog.Filter = "CSV File (*.csv)|*.csv";
391+
saveFileDialog.Filter = "CSV File (*.csv)|*.csv|Excel Workbook (*.xlsx)|*.xlsx";
391392

392393
Process.log?.WriteLine("\nExport Titles");
393394

@@ -462,6 +463,131 @@ private void exportToolStripMenuItem_Click(object sender, EventArgs e)
462463
MessageBox.Show(String.Format("{0} of {1} titles exported", index, titles.Count), Application.ProductName);
463464
}
464465
}
466+
else if (filename.EndsWith(".xlsx", StringComparison.OrdinalIgnoreCase))
467+
{
468+
using (ExcelPackage excel = new ExcelPackage())
469+
{
470+
progressDialog = (IProgressDialog)new ProgressDialog();
471+
progressDialog.StartProgressDialog(Handle, "Exporting titles");
472+
473+
ExcelWorksheet worksheet = excel.Workbook.Worksheets.Add(Common.History.Default.Titles.LastOrDefault().description ?? Application.ProductName);
474+
475+
worksheet.Cells[1, 1, 1, Title.Properties.Count()].LoadFromArrays(new List<string[]> { Title.Properties });
476+
worksheet.Cells["1:1"].Style.Font.Bold = true;
477+
worksheet.Cells["1:1"].Style.Font.Color.SetColor(Color.White);
478+
worksheet.Cells["1:1"].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
479+
worksheet.Cells["1:1"].Style.Fill.BackgroundColor.SetColor(Color.MidnightBlue);
480+
481+
uint index = 0, count = (uint)titles.Count;
482+
483+
foreach (var title in titles)
484+
{
485+
if (progressDialog.HasUserCancelled())
486+
{
487+
break;
488+
}
489+
490+
progressDialog.SetLine(2, title.titleName, true, IntPtr.Zero);
491+
progressDialog.SetProgress(index++, count);
492+
493+
var data = new List<string[]>
494+
{
495+
new string[] {
496+
title.titleID,
497+
title.baseTitleID,
498+
title.titleName,
499+
title.displayVersion,
500+
title.versionString,
501+
title.latestVersionString,
502+
title.systemUpdateString,
503+
title.systemVersionString,
504+
title.applicationVersionString,
505+
title.masterkeyString,
506+
title.titleKey,
507+
title.publisher,
508+
title.languagesString,
509+
title.filename,
510+
title.filesizeString,
511+
title.typeString,
512+
title.distribution.ToString(),
513+
title.structureString,
514+
title.signatureString,
515+
title.permissionString,
516+
title.error,
517+
}
518+
};
519+
520+
worksheet.Cells[(int)index + 1, 1].LoadFromArrays(data);
521+
522+
string titleID = title.type == TitleType.AddOnContent ? title.titleID : title.baseTitleID ?? "";
523+
524+
Process.latestVersions.TryGetValue(titleID, out uint latestVersion);
525+
Process.versionList.TryGetValue(titleID, out uint version);
526+
Process.titleVersions.TryGetValue(titleID, out uint titleVersion);
527+
528+
if (latestVersion < version || latestVersion < titleVersion)
529+
{
530+
worksheet.Cells[(int)index + 1, 1, (int)index + 1, Title.Properties.Count()].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
531+
worksheet.Cells[(int)index + 1, 1, (int)index + 1, Title.Properties.Count()].Style.Fill.BackgroundColor.SetColor(title.signature != true ? Color.OldLace : Color.LightYellow);
532+
}
533+
else if (title.signature != true)
534+
{
535+
worksheet.Cells[(int)index + 1, 1, (int)index + 1, Title.Properties.Count()].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
536+
worksheet.Cells[(int)index + 1, 1, (int)index + 1, Title.Properties.Count()].Style.Fill.BackgroundColor.SetColor(Color.WhiteSmoke);
537+
}
538+
539+
if (title.permission == Title.Permission.Dangerous)
540+
{
541+
worksheet.Cells[(int)index + 1, 1, (int)index + 1, Title.Properties.Count()].Style.Font.Color.SetColor(Color.DarkRed);
542+
}
543+
else if (title.permission == Title.Permission.Unsafe)
544+
{
545+
worksheet.Cells[(int)index + 1, 1, (int)index + 1, Title.Properties.Count()].Style.Font.Color.SetColor(Color.Indigo);
546+
}
547+
}
548+
549+
ExcelRange range = worksheet.Cells[1, 1, (int)count + 1, Title.Properties.Count()];
550+
range.Style.Border.Top.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin;
551+
range.Style.Border.Left.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin;
552+
range.Style.Border.Right.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin;
553+
range.Style.Border.Bottom.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin;
554+
555+
worksheet.Column(1).Width = 18;
556+
worksheet.Column(2).Width = 18;
557+
worksheet.Column(3).AutoFit();
558+
worksheet.Column(3).Width = Math.Max(worksheet.Column(3).Width, 30);
559+
worksheet.Column(4).Width = 16;
560+
worksheet.Column(5).Width = 16;
561+
worksheet.Column(6).Width = 16;
562+
worksheet.Column(7).Width = 16;
563+
worksheet.Column(8).Width = 16;
564+
worksheet.Column(9).Width = 16;
565+
worksheet.Column(10).Width = 16;
566+
worksheet.Column(11).AutoFit();
567+
worksheet.Column(11).Width = Math.Max(worksheet.Column(11).Width, 36);
568+
worksheet.Column(12).AutoFit();
569+
worksheet.Column(12).Width = Math.Max(worksheet.Column(12).Width, 30);
570+
worksheet.Column(13).Width = 18;
571+
worksheet.Column(14).AutoFit();
572+
worksheet.Column(14).Width = Math.Max(worksheet.Column(14).Width, 54);
573+
worksheet.Column(15).Width = 10;
574+
worksheet.Column(16).Width = 10;
575+
worksheet.Column(17).Width = 12;
576+
worksheet.Column(18).Width = 12;
577+
worksheet.Column(19).Width = 10;
578+
worksheet.Column(20).Width = 10;
579+
worksheet.Column(21).Width = 40;
580+
581+
excel.SaveAs(new FileInfo(filename));
582+
583+
Process.log?.WriteLine("\n{0} of {1} titles exported", index, titles.Count);
584+
585+
progressDialog.StopProgressDialog();
586+
Activate();
587+
588+
MessageBox.Show(String.Format("{0} of {1} titles exported", index, titles.Count), Application.ProductName);
589+
}
590+
}
465591
else
466592
{
467593
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)
483609

484610
progressDialog.SetLine(2, String.Format("Downloading from {0}", Common.TITLE_KEYS_URI), true, IntPtr.Zero);
485611

612+
int count = Process.keyset?.TitleKeys?.Count ?? 0;
613+
486614
if (Process.updateTitleKeys())
487615
{
616+
Process.log?.WriteLine("\nFound {0} updated title keys", (Process.keyset?.TitleKeys?.Count ?? 0) - count);
617+
488618
progressDialog.StopProgressDialog();
489619
Activate();
490620

491-
MessageBox.Show(String.Format("Found {0} title keys", Process.keyset?.TitleKeys?.Count), Application.ProductName);
621+
MessageBox.Show(String.Format("Found {0} updated title keys", (Process.keyset?.TitleKeys?.Count ?? 0) - count), Application.ProductName);
492622
}
493623
else
494624
{

Windows/NX_Game_Info.csproj

+6-1
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,22 @@
3737
<ApplicationIcon>NX_Game_Info.ico</ApplicationIcon>
3838
</PropertyGroup>
3939
<ItemGroup>
40+
<Reference Include="EPPlus, Version=4.5.3.2, Culture=neutral, PublicKeyToken=ea159fdaa78159a1, processorArchitecture=MSIL">
41+
<HintPath>..\packages\EPPlus.4.5.3.2\lib\net40\EPPlus.dll</HintPath>
42+
</Reference>
4043
<Reference Include="ListViewPrinter, Version=2.7.1.31255, Culture=neutral, processorArchitecture=MSIL">
4144
<HintPath>..\packages\ObjectListView.2.7.1.5\lib\ListViewPrinter.dll</HintPath>
4245
</Reference>
4346
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
44-
<HintPath>..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
47+
<HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
4548
</Reference>
4649
<Reference Include="ObjectListView, Version=2.7.1.31255, Culture=neutral, PublicKeyToken=b1c5bf581481bcd4, processorArchitecture=MSIL">
4750
<HintPath>..\packages\ObjectListView.2.7.1.5\lib\ObjectListView.dll</HintPath>
4851
</Reference>
4952
<Reference Include="PortableSettingsProvider, Version=0.2.3.0, Culture=neutral, processorArchitecture=MSIL">
5053
<HintPath>..\packages\PortableSettingsProvider.0.2.3\lib\net45\PortableSettingsProvider.dll</HintPath>
5154
</Reference>
55+
<Reference Include="PresentationCore" />
5256
<Reference Include="SparkleLibrary, Version=2.7.1.0, Culture=neutral, processorArchitecture=MSIL">
5357
<HintPath>..\packages\ObjectListView.2.7.1.5\lib\SparkleLibrary.dll</HintPath>
5458
</Reference>
@@ -59,6 +63,7 @@
5963
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
6064
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.6.0\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
6165
</Reference>
66+
<Reference Include="System.Security" />
6267
<Reference Include="System.Xml.Linq" />
6368
<Reference Include="System.Data.DataSetExtensions" />
6469
<Reference Include="Microsoft.CSharp" />

Windows/Properties/AssemblyInfo.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@
3030
//
3131
// You can specify all the values or you can default the Build and Revision Numbers
3232
// by using the '*' as shown below:
33-
// [assembly: AssemblyVersion("0.7.0.*")]
34-
[assembly: AssemblyVersion("0.7.0.1")]
35-
[assembly: AssemblyFileVersion("0.7.0.1")]
33+
// [assembly: AssemblyVersion("0.7.1.*")]
34+
[assembly: AssemblyVersion("0.7.1.0")]
35+
[assembly: AssemblyFileVersion("0.7.1.0")]

Windows/packages.config

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Newtonsoft.Json" version="12.0.2" targetFramework="net471" />
3+
<package id="EPPlus" version="4.5.3.2" targetFramework="net471" />
4+
<package id="Newtonsoft.Json" version="12.0.3" targetFramework="net471" />
45
<package id="ObjectListView" version="2.7.1.5" targetFramework="net471" />
56
<package id="PortableSettingsProvider" version="0.2.3" targetFramework="net471" />
67
<package id="System.Runtime.CompilerServices.Unsafe" version="4.6.0" targetFramework="net471" />

macOS/Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<key>CFBundleIdentifier</key>
88
<string>com.garoxas.NX_Game_Info</string>
99
<key>CFBundleShortVersionString</key>
10-
<string>0.7.0.1</string>
10+
<string>0.7.1.0</string>
1111
<key>CFBundleVersion</key>
1212
<string>14</string>
1313
<key>LSMinimumSystemVersion</key>

macOS/MainWindowController.cs

+37
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,43 @@ public void Export(NSMenuItem menuItem)
398398
});
399399
}
400400

401+
[Export("updateTitleKeys:")]
402+
public void UpdateTitleKeys(NSMenuItem menuItem)
403+
{
404+
Window.BeginSheet(sheet, ProgressComplete);
405+
406+
title.StringValue = "";
407+
message.StringValue = String.Format("Downloading from {0}", Common.TITLE_KEYS_URI);
408+
progress.DoubleValue = 0;
409+
410+
int count = Process.keyset?.TitleKeys?.Count ?? 0;
411+
412+
if (Process.updateTitleKeys())
413+
{
414+
Process.log?.WriteLine("\nFound {0} updated title keys", (Process.keyset?.TitleKeys?.Count ?? 0) - count);
415+
416+
Window.EndSheet(sheet);
417+
418+
var alert = new NSAlert()
419+
{
420+
InformativeText = String.Format("Found {0} updated title keys", (Process.keyset?.TitleKeys?.Count ?? 0) - count),
421+
MessageText = NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleExecutable").ToString(),
422+
};
423+
alert.RunModal();
424+
}
425+
else
426+
{
427+
Window.EndSheet(sheet);
428+
429+
var alert = new NSAlert()
430+
{
431+
InformativeText = "Failed to download title keys",
432+
MessageText = NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleExecutable").ToString(),
433+
};
434+
alert.RunModal();
435+
}
436+
}
437+
401438
[Export("updateVersionList:")]
402439
public void UpdateVersionList(NSMenuItem menuItem)
403440
{

0 commit comments

Comments
 (0)