Skip to content

Commit

Permalink
Export to CSV #18
Browse files Browse the repository at this point in the history
  • Loading branch information
garoxas committed Oct 20, 2019
1 parent 04e0bae commit c0603ca
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 88 deletions.
8 changes: 8 additions & 0 deletions NX_Game_Info/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ public bool DebugLog
set { this["DebugLog"] = value; }
}

[UserScopedSetting()]
[DefaultSettingValue("")]
public char CsvSeparator
{
get { return (char)this["CsvSeparator"]; }
set { this["CsvSeparator"] = value; }
}

#if WINDOWS
[UserScopedSetting()]
[DefaultSettingValue("0, 0")]
Expand Down
106 changes: 62 additions & 44 deletions Windows/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -385,65 +385,83 @@ private void exportToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.Title = "Export Titles";
saveFileDialog.Filter = "Text Documents (*.txt)|*.txt|All Files (*.*)|*.*";
saveFileDialog.Filter = "CSV File (*.csv)|*.csv";

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

if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
using (var writer = new StreamWriter(saveFileDialog.FileName))
string filename = saveFileDialog.FileName;

if (filename.EndsWith(".csv", StringComparison.OrdinalIgnoreCase))
{
progressDialog = (IProgressDialog)new ProgressDialog();
progressDialog.StartProgressDialog(Handle, "Exporting titles");
using (var writer = new StreamWriter(filename))
{
progressDialog = (IProgressDialog)new ProgressDialog();
progressDialog.StartProgressDialog(Handle, "Exporting titles");

writer.WriteLine("{0} {1}", Application.ProductName, Application.ProductVersion);
writer.WriteLine("--------------------------------------------------------------\n");
char separator = Common.Settings.Default.CsvSeparator;
if (separator != '\0')
{
writer.WriteLine("sep={0}", separator);
}
else
{
separator = ',';
}

writer.WriteLine("Export titles starts at {0}\n", String.Format("{0:F}", DateTime.Now));
writer.WriteLine("# publisher {0} {1}", Application.ProductName, Application.ProductVersion);
writer.WriteLine("# updated {0}", String.Format("{0:F}", DateTime.Now));

uint index = 0, count = (uint)titles.Count;
writer.WriteLine(String.Join(separator.ToString(), Common.Title.Properties));

foreach (var title in titles)
{
if (progressDialog.HasUserCancelled())
{
break;
}
uint index = 0, count = (uint)titles.Count;

progressDialog.SetLine(2, title.titleName, true, IntPtr.Zero);
progressDialog.SetProgress(index++, count);

writer.WriteLine("{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}|{9}|{10}|{11}|{12}|{13}|{14}|{15}|{16}|{17}|{18}|{19}",
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.filename,
title.filesizeString,
title.typeString,
title.distribution,
title.structureString,
title.signatureString,
title.permissionString,
title.error);
}
foreach (var title in titles)
{
if (progressDialog.HasUserCancelled())
{
break;
}

writer.WriteLine("\n{0} of {1} titles exported", index, titles.Count);
progressDialog.SetLine(2, title.titleName, true, IntPtr.Zero);
progressDialog.SetProgress(index++, count);

writer.WriteLine(String.Join(separator.ToString(), new string[] {
title.titleID.Quote(separator),
title.baseTitleID.Quote(separator),
title.titleName.Quote(separator),
title.displayVersion.Quote(separator),
title.versionString.Quote(separator),
title.latestVersionString.Quote(separator),
title.systemUpdateString.Quote(separator),
title.systemVersionString.Quote(separator),
title.applicationVersionString.Quote(separator),
title.masterkeyString.Quote(separator),
title.titleKey.Quote(separator),
title.publisher.Quote(separator),
title.filename.Quote(separator),
title.filesizeString.Quote(separator),
title.typeString.Quote(separator),
title.distribution.ToString().Quote(separator),
title.structureString.Quote(separator),
title.signatureString.Quote(separator),
title.permissionString.Quote(separator),
title.error.Quote(separator),
}));
}

Process.log?.WriteLine("\n{0} of {1} titles exported", index, titles.Count);
Process.log?.WriteLine("\n{0} of {1} titles exported", index, titles.Count);

progressDialog.StopProgressDialog();
Activate();
progressDialog.StopProgressDialog();
Activate();

MessageBox.Show(String.Format("{0} of {1} titles exported", index, titles.Count), Application.ProductName);
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 Down
111 changes: 67 additions & 44 deletions macOS/MainWindowController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public void OpenSDCard(NSMenuItem menuItem)
public void Export(NSMenuItem menuItem)
{
NSSavePanel savePanel = NSSavePanel.SavePanel;
savePanel.AllowedFileTypes = new string[] { "txt" };
savePanel.AllowedFileTypes = new string[] { "csv" };
savePanel.Title = "Export Titles";

Process.log?.WriteLine("\nExport Titles");
Expand All @@ -311,61 +311,84 @@ public void Export(NSMenuItem menuItem)
{
if (result == (int)NSModalResponse.OK)
{
using (var writer = new StreamWriter(savePanel.Url.Path))
string filename = savePanel.Url.Path;

if (filename.EndsWith(".csv", StringComparison.OrdinalIgnoreCase))
{
Window.BeginSheet(sheet, ProgressComplete);
userCancelled = false;
using (var writer = new StreamWriter(filename))
{
Window.BeginSheet(sheet, ProgressComplete);
userCancelled = false;

char separator = Common.Settings.Default.CsvSeparator;
if (separator != '\0')
{
writer.WriteLine("sep={0}", separator);
}
else
{
separator = ',';
}

writer.WriteLine("{0} {1}", NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleName").ToString(), NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleShortVersionString").ToString());
writer.WriteLine("--------------------------------------------------------------\n");
writer.WriteLine("# publisher {0} {1}", NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleName").ToString(), NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleShortVersionString").ToString());
writer.WriteLine("# updated {0}", String.Format("{0:F}", DateTime.Now));

writer.WriteLine("Export titles starts at {0}\n", String.Format("{0:F}", DateTime.Now));
writer.WriteLine(String.Join(separator.ToString(), Common.Title.Properties));

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

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

message.StringValue = title.titleName ?? "";
progress.DoubleValue = 100f * index++ / count;

writer.WriteLine(String.Join(separator.ToString(), new string[] {
title.titleID.Quote(separator),
title.baseTitleID.Quote(separator),
title.titleName.Quote(separator),
title.displayVersion.Quote(separator),
title.versionString.Quote(separator),
title.latestVersionString.Quote(separator),
title.systemUpdateString.Quote(separator),
title.systemVersionString.Quote(separator),
title.applicationVersionString.Quote(separator),
title.masterkeyString.Quote(separator),
title.titleKey.Quote(separator),
title.publisher.Quote(separator),
title.filename.Quote(separator),
title.filesizeString.Quote(separator),
title.typeString.Quote(separator),
title.distribution.ToString().Quote(separator),
title.structureString.Quote(separator),
title.signatureString.Quote(separator),
title.permissionString.Quote(separator),
title.error.Quote(separator),
}));
}

message.StringValue = title.titleName ?? "";
progress.DoubleValue = 100f * index++ / count;

writer.WriteLine("{0}|{1}|{2}|{3}|{4}|{5}|{6}|{7}|{8}|{9}|{10}|{11}|{12}|{13}|{14}|{15}|{16}|{17}|{18}|{19}",
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.filename,
title.filesizeString,
title.typeString,
title.distribution,
title.structureString,
title.signatureString,
title.permissionString,
title.error);
}

writer.WriteLine("\n{0} of {1} titles exported", index, titles.Count);
Process.log?.WriteLine("\n{0} of {1} titles exported", index, titles.Count);

Process.log?.WriteLine("\n{0} of {1} titles exported", index, titles.Count);

Window.EndSheet(sheet);
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()
{
InformativeText = String.Format("{0} of {1} titles exported", index, titles.Count),
InformativeText = String.Format("This file type is not supported {0}", Path.GetExtension(filename)),
MessageText = NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleExecutable").ToString(),
};
alert.RunModal();
Expand Down

0 comments on commit c0603ca

Please sign in to comment.