Skip to content

Commit

Permalink
Export to XLSX for macOS. Close #2
Browse files Browse the repository at this point in the history
  • Loading branch information
garoxas committed Nov 10, 2019
1 parent 987a466 commit 84f324a
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 13 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ The application will look for these files at the following locations (other file
- Directory of the executable file (.exe) for Windows or (.app) for macOS
- `$HOME/.switch` e.g. C:\\Users\\_yourname_\\.switch for Windows, /Users/_yourname_/.switch for macOS or /home/_yourname_/.switch for Linux

`Export` menu supports exporting current list to either `CSV` or `XLSX`. For `CSV` file default delimiter to use is `comma ( , )` and user defined character can be set in `user.settings` by specifying the delimiter character in `CsvSeparator` field

Compressed NCA is not supported, but there is an option to make the application accept `XCZ` and `NSZ` file extension by setting `NszExtension` field `user.settings`. Please note that issues related to these file extensions will not be supported

# macOS
### Open File/Directory
![NX_Game_Info_macOS.png](NX_Game_Info_macOS.png)
Expand Down
6 changes: 3 additions & 3 deletions cli/NX_Game_Info.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
<ApplicationIcon>NX_Game_Info.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<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>
</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>
Expand All @@ -53,6 +50,9 @@
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="..\NX_Game_Info\Common.cs" />
Expand Down
6 changes: 3 additions & 3 deletions cli/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,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")]
2 changes: 1 addition & 1 deletion cli/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="12.0.2" targetFramework="net461" />
<package id="Newtonsoft.Json" version="12.0.3" targetFramework="net471" />
<package id="System.Runtime.CompilerServices.Unsafe" version="4.6.0" targetFramework="net471" />
</packages>
10 changes: 8 additions & 2 deletions macOS/MainMenu.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14868" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14490.70"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14868"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
Expand Down Expand Up @@ -87,6 +87,11 @@
<modifierMask key="keyEquivalentModifierMask"/>
<menu key="submenu" title="Options" id="cPl-OO-7ff">
<items>
<menuItem title="Update Title Keys" keyEquivalent="T" id="Xic-D0-2VE">
<connections>
<action selector="updateTitleKeys:" target="-1" id="7on-KA-6oP"/>
</connections>
</menuItem>
<menuItem title="Update Version List" keyEquivalent="V" id="2ZD-1S-gOF">
<connections>
<action selector="updateVersionList:" target="-1" id="tyf-nr-kco"/>
Expand All @@ -106,6 +111,7 @@
<menu key="submenu" title="History" id="h0J-2S-vTz"/>
</menuItem>
</items>
<point key="canvasLocation" x="139" y="154"/>
</menu>
</objects>
</document>
143 changes: 141 additions & 2 deletions macOS/MainWindowController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using AppKit;
using Bluegrams.Application;
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 @@ -302,7 +303,7 @@ public void OpenSDCard(NSMenuItem menuItem)
public void Export(NSMenuItem menuItem)
{
NSSavePanel savePanel = NSSavePanel.SavePanel;
savePanel.AllowedFileTypes = new string[] { "csv" };
savePanel.AllowedFileTypes = new string[] { "csv", "xlsx" };
savePanel.Title = "Export Titles";

Process.log?.WriteLine("\nExport Titles");
Expand Down Expand Up @@ -385,6 +386,134 @@ public void Export(NSMenuItem menuItem)
alert.RunModal();
}
}
else if (filename.EndsWith(".xlsx", StringComparison.OrdinalIgnoreCase))
{
using (ExcelPackage excel = new ExcelPackage())
{
Window.BeginSheet(sheet, ProgressComplete);
userCancelled = false;

ExcelWorksheet worksheet = excel.Workbook.Worksheets.Add(Common.History.Default.Titles.LastOrDefault().description ?? NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleExecutable").ToString());

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(NSColor.White);
worksheet.Cells["1:1"].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
worksheet.Cells["1:1"].Style.Fill.BackgroundColor.SetColor(NSColor.Blue.ShadowWithLevel((nfloat)0.6));

uint index = 0, count = (uint)titles.Count;

foreach (var title in titles)
{
if (userCancelled)
{
userCancelled = false;
break;
}

message.StringValue = title.titleName ?? "";
progress.DoubleValue = 100f * 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 ? NSColor.Orange.ColorWithAlphaComponent((nfloat)0.1) : NSColor.Yellow.ColorWithAlphaComponent((nfloat)0.1));
}
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(NSColor.Gray.ColorWithAlphaComponent((nfloat)0.1));
}

if (title.permission == Title.Permission.Dangerous)
{
worksheet.Cells[(int)index + 1, 1, (int)index + 1, Title.Properties.Count()].Style.Font.Color.SetColor(NSColor.Red);
}
else if (title.permission == Title.Permission.Unsafe)
{
worksheet.Cells[(int)index + 1, 1, (int)index + 1, Title.Properties.Count()].Style.Font.Color.SetColor(NSColor.Purple);
}
}

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));

Window.EndSheet(sheet);

var alert = new NSAlert()
{
InformativeText = String.Format("{0} of {1} titles exported", index, titles.Count),
MessageText = NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleExecutable").ToString(),
};
alert.RunModal();
}
}
else
{
var alert = new NSAlert()
Expand Down Expand Up @@ -441,7 +570,7 @@ public void UpdateVersionList(NSMenuItem menuItem)
Window.BeginSheet(sheet, ProgressComplete);

title.StringValue = "";
message.StringValue = String.Format("Downloading from {0}", Common.TAGAYA_VERSIONLIST);
message.StringValue = String.Format("Downloading from {0}", Common.HAC_VERSIONLIST_URI);
progress.DoubleValue = 0;

if (Process.updateVersionList())
Expand Down Expand Up @@ -1079,4 +1208,14 @@ public override NSView GetViewForItem(NSTableView tableView, NSTableColumn table
return textField;
}
}

public static class ExcelColorExtension
{
public static void SetColor(this OfficeOpenXml.Style.ExcelColor excelColor, NSColor color)
{
NSColor rgb = color.UsingColorSpace(NSColorSpace.DeviceRGB);
nfloat alpha = rgb.AlphaComponent;
excelColor.SetColor(255, (int)((1 + alpha * (rgb.RedComponent - 1)) * 255), (int)((1 + alpha * (rgb.GreenComponent - 1)) * 255), (int)((1 + alpha * (rgb.BlueComponent - 1)) * 255));
}
}
}
3 changes: 3 additions & 0 deletions macOS/MainWindowController.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion macOS/NX_Game_Info.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<Reference Include="mscorlib" />
<Reference Include="System.Numerics" />
<Reference Include="Newtonsoft.Json">
<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="System.Xml" />
<Reference Include="System.Xml.Linq" />
Expand Down Expand Up @@ -95,6 +95,13 @@
</Reference>
<Reference Include="System.Net.Http" />
<Reference Include="System.Net.Http.WebRequest" />
<Reference Include="EPPlus">
<HintPath>..\packages\EPPlus.4.5.3.2\lib\net40\EPPlus.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Security" />
</ItemGroup>
<ItemGroup>
<ImageAsset Include="Assets.xcassets\AppIcon.appiconset\Contents.json" />
Expand Down
3 changes: 2 additions & 1 deletion macOS/packages.config
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EPPlus" version="4.5.3.2" targetFramework="net471" />
<package id="Microsoft.Bcl" version="1.1.10" targetFramework="net471" />
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net471" />
<package id="Microsoft.Net.Http" version="2.2.29" targetFramework="net471" />
<package id="Newtonsoft.Json" version="12.0.2" targetFramework="net471" />
<package id="Newtonsoft.Json" version="12.0.3" targetFramework="net471" />
<package id="PortableSettingsProvider" version="0.2.2" targetFramework="net471" />
<package id="System.IO" version="4.3.0" targetFramework="net471" />
<package id="System.Runtime" version="4.3.0" targetFramework="net471" />
Expand Down

0 comments on commit 84f324a

Please sign in to comment.