Skip to content

Commit 4088a15

Browse files
committed
Update Latest Version List #1 and Show last opened table contents on start #5 for macOS
1 parent 263e1cc commit 4088a15

6 files changed

+230
-83
lines changed

NX_Game_Info/Common.cs

+4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Configuration;
4+
#if !MACOS
45
using System.Drawing;
6+
#endif
57
using System.IO;
68
using System.Linq;
79
using System.Runtime.InteropServices;
@@ -69,6 +71,7 @@ public bool DebugLog
6971
set { this["DebugLog"] = value; }
7072
}
7173

74+
#if !MACOS
7275
[UserScopedSetting()]
7376
[DefaultSettingValue("0, 0")]
7477
public Point WindowLocation
@@ -84,6 +87,7 @@ public Size WindowSize
8487
get { return (Size)this["WindowSize"]; }
8588
set { this["WindowSize"] = value; }
8689
}
90+
#endif
8791

8892
public static Settings Default = (Settings)Synchronized(new Settings());
8993
}

macOS/MainMenu.xib

+19-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
2+
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
33
<dependencies>
44
<deployment identifier="macosx"/>
5-
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14460.31"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14490.70"/>
66
</dependencies>
77
<objects>
88
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
@@ -75,14 +75,27 @@
7575
</connections>
7676
</menuItem>
7777
<menuItem isSeparatorItem="YES" id="qjl-x6-J91"/>
78-
<menuItem title="Debug Log" keyEquivalent="L" id="9rY-DL-2nP">
78+
<menuItem title="Export" keyEquivalent="X" id="MXh-5X-bzI">
7979
<connections>
80-
<action selector="debugLog:" target="-1" id="IW7-Qg-4l0"/>
80+
<action selector="export:" target="-1" id="UFR-7n-xR5"/>
8181
</connections>
8282
</menuItem>
83-
<menuItem title="Export" keyEquivalent="X" id="MXh-5X-bzI">
83+
</items>
84+
</menu>
85+
</menuItem>
86+
<menuItem title="Options" id="ieD-Nr-wY1">
87+
<modifierMask key="keyEquivalentModifierMask"/>
88+
<menu key="submenu" title="Options" id="cPl-OO-7ff">
89+
<items>
90+
<menuItem title="Update Version List" keyEquivalent="V" id="2ZD-1S-gOF">
8491
<connections>
85-
<action selector="export:" target="-1" id="UFR-7n-xR5"/>
92+
<action selector="updateVersionList:" target="-1" id="tyf-nr-kco"/>
93+
</connections>
94+
</menuItem>
95+
<menuItem isSeparatorItem="YES" id="Ewp-hH-lxl"/>
96+
<menuItem title="Debug Log" keyEquivalent="L" id="9rY-DL-2nP">
97+
<connections>
98+
<action selector="debugLog:" target="-1" id="IW7-Qg-4l0"/>
8699
</connections>
87100
</menuItem>
88101
</items>

macOS/MainWindowController.cs

+118-25
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Linq;
66
using Foundation;
77
using AppKit;
8+
using Bluegrams.Application;
89
using LibHac;
910
using FsTitle = LibHac.Title;
1011
using Title = NX_Game_Info.Common.Title;
@@ -69,9 +70,10 @@ public override void WindowDidLoad()
6970

7071
PortableSettingsProvider.SettingsFileName = Common.USER_SETTINGS;
7172
PortableSettingsProviderBase.SettingsDirectory = Process.path_prefix;
72-
PortableSettingsProvider.ApplyProvider(Common.Settings.Default);
73+
PortableSettingsProvider.ApplyProvider(Common.Settings.Default, Common.History.Default);
7374

7475
Common.Settings.Default.Upgrade();
76+
Common.History.Default.Upgrade();
7577

7678
NSMenuItem debugLog = Window.Menu?.ItemWithTitle("File")?.Submenu.ItemWithTitle("Debug Log");
7779
if (debugLog != null)
@@ -104,6 +106,12 @@ public override void WindowDidLoad()
104106
backgroundWorker.DoWork += BackgroundWorker_DoWork;
105107
backgroundWorker.ProgressChanged += BackgroundWorker_ProgressChanged;
106108
backgroundWorker.RunWorkerCompleted += BackgroundWorker_RunWorkerCompleted;
109+
110+
titles = Process.processHistory();
111+
112+
tableViewDataSource.Titles.AddRange(titles);
113+
114+
tableView.ReloadData();
107115
}
108116

109117
[Export("openDocument:")]
@@ -268,30 +276,6 @@ public void OpenSDCard(NSMenuItem menuItem)
268276
});
269277
}
270278

271-
[Export("debugLog:")]
272-
public void DebugLog(NSMenuItem menuItem)
273-
{
274-
menuItem.State = menuItem.State == NSCellStateValue.On ? NSCellStateValue.Off : NSCellStateValue.On;
275-
276-
Common.Settings.Default.DebugLog = menuItem.State == NSCellStateValue.On;
277-
Common.Settings.Default.Save();
278-
279-
if (Common.Settings.Default.DebugLog)
280-
{
281-
try
282-
{
283-
Process.log = File.AppendText(Process.path_prefix + Common.LOG_FILE);
284-
Process.log.AutoFlush = true;
285-
}
286-
catch { }
287-
}
288-
else
289-
{
290-
Process.log?.Close();
291-
Process.log = null;
292-
}
293-
}
294-
295279
[Export("export:")]
296280
public void Export(NSMenuItem menuItem)
297281
{
@@ -351,11 +335,109 @@ public void Export(NSMenuItem menuItem)
351335
Process.log?.WriteLine("\n{0} of {1} titles exported", index, titles.Count);
352336

353337
Window.EndSheet(sheet);
338+
339+
var alert = new NSAlert()
340+
{
341+
InformativeText = String.Format("{0} of {1} titles exported", index, titles.Count),
342+
MessageText = NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleExecutable").ToString(),
343+
};
344+
alert.RunModal();
354345
}
355346
}
356347
});
357348
}
358349

350+
[Export("updateVersionList:")]
351+
public void UpdateVersionList(NSMenuItem menuItem)
352+
{
353+
Window.BeginSheet(sheet, ProgressComplete);
354+
355+
message.StringValue = String.Format("Downloading from {0}", Common.TAGAYA_VERSIONLIST);
356+
progress.DoubleValue = 0;
357+
358+
if (Process.updateVersionList())
359+
{
360+
uint count = 0;
361+
362+
foreach (var title in titles)
363+
{
364+
if (title.type == TitleType.Application || title.type == TitleType.Patch)
365+
{
366+
if (Process.versionList.TryGetValue(title.titleIDApplication, out uint version))
367+
{
368+
if (title.latestVersion == unchecked((uint)-1) || version > title.latestVersion)
369+
{
370+
title.latestVersion = version;
371+
count++;
372+
}
373+
}
374+
}
375+
}
376+
377+
if (count != 0)
378+
{
379+
tableView.ReloadData();
380+
381+
List<List<Title>> history = new List<List<Title>>();
382+
history.AddRange(Common.History.Default.Titles);
383+
history.Add(titles.ToList());
384+
385+
Common.History.Default.Titles = new List<List<Title>>(history);
386+
if (Common.History.Default.Titles.Count > Common.HISTORY_SIZE)
387+
{
388+
Common.History.Default.Titles.RemoveRange(0, Common.History.Default.Titles.Count - Common.HISTORY_SIZE);
389+
}
390+
Common.History.Default.Save();
391+
}
392+
393+
Process.log?.WriteLine("\n{0} titles have updated version", count);
394+
395+
Window.EndSheet(sheet);
396+
397+
var alert = new NSAlert()
398+
{
399+
InformativeText = String.Format("{0} titles have updated version", count),
400+
MessageText = NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleExecutable").ToString(),
401+
};
402+
alert.RunModal();
403+
}
404+
else
405+
{
406+
Window.EndSheet(sheet);
407+
408+
var alert = new NSAlert()
409+
{
410+
InformativeText = "Failed to download version list",
411+
MessageText = NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleExecutable").ToString(),
412+
};
413+
alert.RunModal();
414+
}
415+
}
416+
417+
[Export("debugLog:")]
418+
public void DebugLog(NSMenuItem menuItem)
419+
{
420+
menuItem.State = menuItem.State == NSCellStateValue.On ? NSCellStateValue.Off : NSCellStateValue.On;
421+
422+
Common.Settings.Default.DebugLog = menuItem.State == NSCellStateValue.On;
423+
Common.Settings.Default.Save();
424+
425+
if (Common.Settings.Default.DebugLog)
426+
{
427+
try
428+
{
429+
Process.log = File.AppendText(Process.path_prefix + Common.LOG_FILE);
430+
Process.log.AutoFlush = true;
431+
}
432+
catch { }
433+
}
434+
else
435+
{
436+
Process.log?.Close();
437+
Process.log = null;
438+
}
439+
}
440+
359441
void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
360442
{
361443
BackgroundWorker worker = sender as BackgroundWorker;
@@ -494,6 +576,17 @@ void BackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventA
494576

495577
tableView.ReloadData();
496578

579+
List<List<Title>> history = new List<List<Title>>();
580+
history.AddRange(Common.History.Default.Titles);
581+
history.Add(titles.ToList());
582+
583+
Common.History.Default.Titles = new List<List<Title>>(history);
584+
if (Common.History.Default.Titles.Count > Common.HISTORY_SIZE)
585+
{
586+
Common.History.Default.Titles.RemoveRange(0, Common.History.Default.Titles.Count - Common.HISTORY_SIZE);
587+
}
588+
Common.History.Default.Save();
589+
497590
Window.EndSheet(sheet);
498591
}
499592
else if (e.Result is string error)

macOS/MainWindowController.designer.cs

+53-50
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)