Skip to content

Commit

Permalink
Export to XLSX #2
Browse files Browse the repository at this point in the history
  • Loading branch information
garoxas committed Nov 10, 2019
1 parent e5f77c3 commit 987a466
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 8 deletions.
134 changes: 132 additions & 2 deletions Windows/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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<string[]> { 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<string[]>
{
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);
Expand All @@ -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
{
Expand Down
7 changes: 6 additions & 1 deletion Windows/NX_Game_Info.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,22 @@
<ApplicationIcon>NX_Game_Info.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="EPPlus, Version=4.5.3.2, Culture=neutral, PublicKeyToken=ea159fdaa78159a1, processorArchitecture=MSIL">
<HintPath>..\packages\EPPlus.4.5.3.2\lib\net40\EPPlus.dll</HintPath>
</Reference>
<Reference Include="ListViewPrinter, Version=2.7.1.31255, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ObjectListView.2.7.1.5\lib\ListViewPrinter.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
<HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="ObjectListView, Version=2.7.1.31255, Culture=neutral, PublicKeyToken=b1c5bf581481bcd4, processorArchitecture=MSIL">
<HintPath>..\packages\ObjectListView.2.7.1.5\lib\ObjectListView.dll</HintPath>
</Reference>
<Reference Include="PortableSettingsProvider, Version=0.2.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\PortableSettingsProvider.0.2.3\lib\net45\PortableSettingsProvider.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="SparkleLibrary, Version=2.7.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ObjectListView.2.7.1.5\lib\SparkleLibrary.dll</HintPath>
</Reference>
Expand All @@ -59,6 +63,7 @@
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.6.0\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Security" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand Down
6 changes: 3 additions & 3 deletions Windows/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
3 changes: 2 additions & 1 deletion Windows/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="12.0.2" targetFramework="net471" />
<package id="EPPlus" version="4.5.3.2" targetFramework="net471" />
<package id="Newtonsoft.Json" version="12.0.3" targetFramework="net471" />
<package id="ObjectListView" version="2.7.1.5" targetFramework="net471" />
<package id="PortableSettingsProvider" version="0.2.3" targetFramework="net471" />
<package id="System.Runtime.CompilerServices.Unsafe" version="4.6.0" targetFramework="net471" />
Expand Down
2 changes: 1 addition & 1 deletion macOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleIdentifier</key>
<string>com.garoxas.NX_Game_Info</string>
<key>CFBundleShortVersionString</key>
<string>0.7.0.1</string>
<string>0.7.1.0</string>
<key>CFBundleVersion</key>
<string>14</string>
<key>LSMinimumSystemVersion</key>
Expand Down
37 changes: 37 additions & 0 deletions macOS/MainWindowController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit 987a466

Please sign in to comment.