|
7 | 7 | using AppKit;
|
8 | 8 | using Bluegrams.Application;
|
9 | 9 | using LibHac;
|
| 10 | +using OfficeOpenXml; |
10 | 11 | using FsTitle = LibHac.Title;
|
11 | 12 | using Title = NX_Game_Info.Common.Title;
|
12 | 13 | using ArrayOfTitle = NX_Game_Info.Common.ArrayOfTitle;
|
@@ -302,7 +303,7 @@ public void OpenSDCard(NSMenuItem menuItem)
|
302 | 303 | public void Export(NSMenuItem menuItem)
|
303 | 304 | {
|
304 | 305 | NSSavePanel savePanel = NSSavePanel.SavePanel;
|
305 |
| - savePanel.AllowedFileTypes = new string[] { "csv" }; |
| 306 | + savePanel.AllowedFileTypes = new string[] { "csv", "xlsx" }; |
306 | 307 | savePanel.Title = "Export Titles";
|
307 | 308 |
|
308 | 309 | Process.log?.WriteLine("\nExport Titles");
|
@@ -385,6 +386,134 @@ public void Export(NSMenuItem menuItem)
|
385 | 386 | alert.RunModal();
|
386 | 387 | }
|
387 | 388 | }
|
| 389 | + else if (filename.EndsWith(".xlsx", StringComparison.OrdinalIgnoreCase)) |
| 390 | + { |
| 391 | + using (ExcelPackage excel = new ExcelPackage()) |
| 392 | + { |
| 393 | + Window.BeginSheet(sheet, ProgressComplete); |
| 394 | + userCancelled = false; |
| 395 | + |
| 396 | + ExcelWorksheet worksheet = excel.Workbook.Worksheets.Add(Common.History.Default.Titles.LastOrDefault().description ?? NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleExecutable").ToString()); |
| 397 | + |
| 398 | + worksheet.Cells[1, 1, 1, Title.Properties.Count()].LoadFromArrays(new List<string[]> { Title.Properties }); |
| 399 | + worksheet.Cells["1:1"].Style.Font.Bold = true; |
| 400 | + worksheet.Cells["1:1"].Style.Font.Color.SetColor(NSColor.White); |
| 401 | + worksheet.Cells["1:1"].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; |
| 402 | + worksheet.Cells["1:1"].Style.Fill.BackgroundColor.SetColor(NSColor.Blue.ShadowWithLevel((nfloat)0.6)); |
| 403 | + |
| 404 | + uint index = 0, count = (uint)titles.Count; |
| 405 | + |
| 406 | + foreach (var title in titles) |
| 407 | + { |
| 408 | + if (userCancelled) |
| 409 | + { |
| 410 | + userCancelled = false; |
| 411 | + break; |
| 412 | + } |
| 413 | + |
| 414 | + message.StringValue = title.titleName ?? ""; |
| 415 | + progress.DoubleValue = 100f * index++ / count; |
| 416 | + |
| 417 | + var data = new List<string[]> |
| 418 | + { |
| 419 | + new string[] { |
| 420 | + title.titleID, |
| 421 | + title.baseTitleID, |
| 422 | + title.titleName, |
| 423 | + title.displayVersion, |
| 424 | + title.versionString, |
| 425 | + title.latestVersionString, |
| 426 | + title.systemUpdateString, |
| 427 | + title.systemVersionString, |
| 428 | + title.applicationVersionString, |
| 429 | + title.masterkeyString, |
| 430 | + title.titleKey, |
| 431 | + title.publisher, |
| 432 | + title.languagesString, |
| 433 | + title.filename, |
| 434 | + title.filesizeString, |
| 435 | + title.typeString, |
| 436 | + title.distribution.ToString(), |
| 437 | + title.structureString, |
| 438 | + title.signatureString, |
| 439 | + title.permissionString, |
| 440 | + title.error, |
| 441 | + } |
| 442 | + }; |
| 443 | + |
| 444 | + worksheet.Cells[(int)index + 1, 1].LoadFromArrays(data); |
| 445 | + |
| 446 | + string titleID = title.type == TitleType.AddOnContent ? title.titleID : title.baseTitleID ?? ""; |
| 447 | + |
| 448 | + Process.latestVersions.TryGetValue(titleID, out uint latestVersion); |
| 449 | + Process.versionList.TryGetValue(titleID, out uint version); |
| 450 | + Process.titleVersions.TryGetValue(titleID, out uint titleVersion); |
| 451 | + |
| 452 | + if (latestVersion < version || latestVersion < titleVersion) |
| 453 | + { |
| 454 | + worksheet.Cells[(int)index + 1, 1, (int)index + 1, Title.Properties.Count()].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; |
| 455 | + 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)); |
| 456 | + } |
| 457 | + else if (title.signature != true) |
| 458 | + { |
| 459 | + worksheet.Cells[(int)index + 1, 1, (int)index + 1, Title.Properties.Count()].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid; |
| 460 | + worksheet.Cells[(int)index + 1, 1, (int)index + 1, Title.Properties.Count()].Style.Fill.BackgroundColor.SetColor(NSColor.Gray.ColorWithAlphaComponent((nfloat)0.1)); |
| 461 | + } |
| 462 | + |
| 463 | + if (title.permission == Title.Permission.Dangerous) |
| 464 | + { |
| 465 | + worksheet.Cells[(int)index + 1, 1, (int)index + 1, Title.Properties.Count()].Style.Font.Color.SetColor(NSColor.Red); |
| 466 | + } |
| 467 | + else if (title.permission == Title.Permission.Unsafe) |
| 468 | + { |
| 469 | + worksheet.Cells[(int)index + 1, 1, (int)index + 1, Title.Properties.Count()].Style.Font.Color.SetColor(NSColor.Purple); |
| 470 | + } |
| 471 | + } |
| 472 | + |
| 473 | + ExcelRange range = worksheet.Cells[1, 1, (int)count + 1, Title.Properties.Count()]; |
| 474 | + range.Style.Border.Top.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; |
| 475 | + range.Style.Border.Left.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; |
| 476 | + range.Style.Border.Right.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; |
| 477 | + range.Style.Border.Bottom.Style = OfficeOpenXml.Style.ExcelBorderStyle.Thin; |
| 478 | + |
| 479 | + worksheet.Column(1).Width = 18; |
| 480 | + worksheet.Column(2).Width = 18; |
| 481 | + worksheet.Column(3).AutoFit(); |
| 482 | + worksheet.Column(3).Width = Math.Max(worksheet.Column(3).Width, 30); |
| 483 | + worksheet.Column(4).Width = 16; |
| 484 | + worksheet.Column(5).Width = 16; |
| 485 | + worksheet.Column(6).Width = 16; |
| 486 | + worksheet.Column(7).Width = 16; |
| 487 | + worksheet.Column(8).Width = 16; |
| 488 | + worksheet.Column(9).Width = 16; |
| 489 | + worksheet.Column(10).Width = 16; |
| 490 | + worksheet.Column(11).AutoFit(); |
| 491 | + worksheet.Column(11).Width = Math.Max(worksheet.Column(11).Width, 36); |
| 492 | + worksheet.Column(12).AutoFit(); |
| 493 | + worksheet.Column(12).Width = Math.Max(worksheet.Column(12).Width, 30); |
| 494 | + worksheet.Column(13).Width = 18; |
| 495 | + worksheet.Column(14).AutoFit(); |
| 496 | + worksheet.Column(14).Width = Math.Max(worksheet.Column(14).Width, 54); |
| 497 | + worksheet.Column(15).Width = 10; |
| 498 | + worksheet.Column(16).Width = 10; |
| 499 | + worksheet.Column(17).Width = 12; |
| 500 | + worksheet.Column(18).Width = 12; |
| 501 | + worksheet.Column(19).Width = 10; |
| 502 | + worksheet.Column(20).Width = 10; |
| 503 | + worksheet.Column(21).Width = 40; |
| 504 | + |
| 505 | + excel.SaveAs(new FileInfo(filename)); |
| 506 | + |
| 507 | + Window.EndSheet(sheet); |
| 508 | + |
| 509 | + var alert = new NSAlert() |
| 510 | + { |
| 511 | + InformativeText = String.Format("{0} of {1} titles exported", index, titles.Count), |
| 512 | + MessageText = NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleExecutable").ToString(), |
| 513 | + }; |
| 514 | + alert.RunModal(); |
| 515 | + } |
| 516 | + } |
388 | 517 | else
|
389 | 518 | {
|
390 | 519 | var alert = new NSAlert()
|
@@ -441,7 +570,7 @@ public void UpdateVersionList(NSMenuItem menuItem)
|
441 | 570 | Window.BeginSheet(sheet, ProgressComplete);
|
442 | 571 |
|
443 | 572 | title.StringValue = "";
|
444 |
| - message.StringValue = String.Format("Downloading from {0}", Common.TAGAYA_VERSIONLIST); |
| 573 | + message.StringValue = String.Format("Downloading from {0}", Common.HAC_VERSIONLIST_URI); |
445 | 574 | progress.DoubleValue = 0;
|
446 | 575 |
|
447 | 576 | if (Process.updateVersionList())
|
@@ -1079,4 +1208,14 @@ public override NSView GetViewForItem(NSTableView tableView, NSTableColumn table
|
1079 | 1208 | return textField;
|
1080 | 1209 | }
|
1081 | 1210 | }
|
| 1211 | + |
| 1212 | + public static class ExcelColorExtension |
| 1213 | + { |
| 1214 | + public static void SetColor(this OfficeOpenXml.Style.ExcelColor excelColor, NSColor color) |
| 1215 | + { |
| 1216 | + NSColor rgb = color.UsingColorSpace(NSColorSpace.DeviceRGB); |
| 1217 | + nfloat alpha = rgb.AlphaComponent; |
| 1218 | + excelColor.SetColor(255, (int)((1 + alpha * (rgb.RedComponent - 1)) * 255), (int)((1 + alpha * (rgb.GreenComponent - 1)) * 255), (int)((1 + alpha * (rgb.BlueComponent - 1)) * 255)); |
| 1219 | + } |
| 1220 | + } |
1082 | 1221 | }
|
0 commit comments