-
Notifications
You must be signed in to change notification settings - Fork 37
/
ViewController.swift
1414 lines (1241 loc) · 75.4 KB
/
ViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// ViewController.swift
// OpenCore Configurator
//
// Created by notiflux on 15.04.19.
// Copyright © 2019 notiflux. All rights reserved.
//
import Cocoa
public let kNotification = Notification.Name("kNotification")
public var acpiLimitString: String = String() // variables for use in acpi popovover view controller
public var acpiMaskString: String = String()
public var acpiOemTableIdString: String = String()
public var acpiReplaceMaskString: String = String()
public var acpiSkipString: String = String()
public var acpiTableLengthString: String = String()
public var acpiCountString: String = String()
public var kernelBaseString: String = String()
public var kernelCountString: String = String()
public var kernelIdentifierString: String = String()
public var kernelLimitString: String = String()
public var kernelMaskString: String = String()
public var kernelReplaceString: String = String()
public var kernelSkipString: String = String()
public var mountedESP: String = String()
public var mountedESPID: String = String()
public var tableLookup: [NSTableView: [[String: String]]] = [NSTableView: [[String: String]]]()
public var serialDict: [String: [String]] = [String: [String]]()
public var viewLookup: [Int: NSTabView] = [Int: NSTabView]()
class ViewController: NSViewController {
// tabs
@IBOutlet weak var acpiTab: NSTabView!
@IBOutlet weak var deviceTab: NSTabView!
@IBOutlet weak var kernelTab: NSTabView!
@IBOutlet weak var miscTab: NSTabView!
@IBOutlet weak var nvramTab: NSTabView!
@IBOutlet weak var platformTab: NSTabView!
@IBOutlet weak var uefiTab: NSTabView!
// tables
@IBOutlet weak var sectionsTable:NSTableView!
@IBOutlet weak var acpiAddTable: NSTableView!
@IBOutlet weak var acpiBlockTable: NSTableView!
@IBOutlet weak var acpiPatchTable: NSTableView!
@IBOutlet weak var deviceAddTable: NSTableView!
@IBOutlet weak var deviceBlockTable: NSTableView!
@IBOutlet weak var kernelAddTable: NSTableView!
@IBOutlet weak var kernelBlockTable: NSTableView!
@IBOutlet weak var kernelPatchTable: NSTableView!
@IBOutlet weak var nvramBootTable: NSTableView!
@IBOutlet weak var nvramVendorTable: NSTableView!
@IBOutlet weak var nvramCustomTable: NSTableView!
@IBOutlet weak var nvramBlockTable: NSTableView!
@IBOutlet weak var uefiDriverTable: NSTableView!
@IBOutlet weak var platformSmbiosTable: NSTableView!
@IBOutlet weak var platformDatahubTable: NSTableView!
@IBOutlet weak var platformGenericTable: NSTableView!
@IBOutlet weak var platformNvramTable: NSTableView!
// misc boot options
@IBOutlet weak var timeoutTextfield: NSTextField!
@IBOutlet weak var timeoutStepper: NSStepper!
@IBOutlet weak var showPicker: NSButton!
@IBOutlet weak var resolution: NSComboBox!
@IBOutlet weak var consoleMode: NSComboBox!
@IBOutlet weak var OsBehavior: NSPopUpButton!
@IBOutlet weak var UiBehavior: NSPopUpButton!
@IBOutlet weak var hideSelf: NSButton!
// misc debug options
@IBOutlet weak var miscDelayText: NSTextField!
@IBOutlet weak var miscDisplayLevelText: NSTextField!
@IBOutlet weak var miscExposeBootPath: NSButton!
@IBOutlet weak var miscTargetText: NSTextField!
@IBOutlet weak var disableWatchdog: NSButton!
// misc security options
@IBOutlet weak var miscRequireSignature: NSButton!
@IBOutlet weak var miscRequireVault: NSButton!
@IBOutlet weak var miscHaltlevel: NSTextField!
// acpi quirks
@IBOutlet weak var FadtEnableReset: NSButton!
@IBOutlet weak var IgnoreForWindows: NSButton!
@IBOutlet weak var NormalizeHeaders: NSButton!
@IBOutlet weak var RebaseRegions: NSButton!
@IBOutlet weak var ResetLogoStatus: NSButton!
// device quirks
// @IBOutlet weak var ReinstallProtocol: NSButton!
// kernel quirks
@IBOutlet weak var AppleCpuPmCfgLock: NSButton!
@IBOutlet weak var AppleXcpmCfgLock: NSButton!
@IBOutlet weak var ExternalDiskIcons: NSButton!
@IBOutlet weak var ThirdPartyTrim: NSButton!
@IBOutlet weak var XhciPortLimit: NSButton!
// uefi quirks
@IBOutlet weak var uefiConnectDrivers: NSButton!
@IBOutlet weak var IgnoreTextInGraphics: NSButton!
@IBOutlet weak var IgnoreInvalidFlexRatio: NSButton!
@IBOutlet weak var ProvideConsoleControl: NSButton!
@IBOutlet weak var ProvideConsoleGop: NSButton!
@IBOutlet weak var ReleaseUsbOwnership: NSButton!
@IBOutlet weak var RequestBootVarRouting: NSButton!
@IBOutlet weak var SanitiseClearScreen: NSButton!
@IBOutlet weak var ExitBootServicesDelay: NSTextField!
@IBOutlet weak var AppleBootPolicy: NSButton!
@IBOutlet weak var DeviceProperties: NSButton!
// smbios options
@IBOutlet weak var smbiosAutomatic: NSButton!
@IBOutlet weak var updateDatahub: NSButton!
@IBOutlet weak var updateNvram: NSButton!
@IBOutlet weak var updateSmbios: NSButton!
@IBOutlet weak var smbioUpdateModePopup: NSPopUpButton!
@IBOutlet weak var espPopup: NSPopUpButton!
var acpiQuirks: [String: NSButton] = [String: NSButton]()
var deviceQuirks: [String: NSButton] = [String: NSButton]()
var kernelQuirks: [String: NSButton] = [String: NSButton]()
var uefiQuirks: [String: NSButton] = [String: NSButton]()
var topLevelBools: [NSButton: Bool] = [NSButton: Bool]()
var uefiProtocols: [String: NSButton] = [String: NSButton]()
func windowShouldClose() {
}
var dragDropKernelAdd = NSPasteboard.PasteboardType(rawValue: "private.table-row.kernelAdd")
var dragDropAcpiPatch = NSPasteboard.PasteboardType(rawValue: "private.table-row.acpiPatch")
var dragDropKernelPatch = NSPasteboard.PasteboardType(rawValue: "private.table-row.kernelPatch")
var dragDropAcpiAdd = NSPasteboard.PasteboardType(rawValue: "private.table-row.acpiAdd")
var drivesDict: [String: String] = [:]
override func viewDidLoad() {
super.viewDidLoad()
reloadEsps()
resetTables() // initialize table datasources
for table in Array(tableLookup.keys) { // setup table delegate and datasource
table.delegate = self as NSTableViewDelegate
table.dataSource = self
}
kernelAddTable.registerForDraggedTypes([dragDropKernelAdd]) // allow row reordering for kexts + acpi pactches table
acpiPatchTable.registerForDraggedTypes([dragDropAcpiPatch])
kernelPatchTable.registerForDraggedTypes([dragDropKernelPatch])
acpiAddTable.registerForDraggedTypes([dragDropAcpiAdd])
sectionsTable.action = #selector(onItemClicked) // on section selection
viewLookup = [
0: acpiTab,
1: deviceTab,
2: kernelTab,
3: miscTab,
4: nvramTab,
5: platformTab,
6: uefiTab
]
acpiQuirks = [
"FadtEnableReset": self.FadtEnableReset,
"IgnoreForWindows": self.IgnoreForWindows,
"NormalizeHeaders": self.NormalizeHeaders,
"RebaseRegions": self.RebaseRegions,
"ResetLogoStatus": self.ResetLogoStatus
]
/*deviceQuirks = [
"ReinstallProtocol": self.ReinstallProtocol
]*/
kernelQuirks = [
"AppleCpuPmCfgLock": self.AppleCpuPmCfgLock,
"AppleXcpmCfgLock": self.AppleXcpmCfgLock,
"ExternalDiskIcons": self.ExternalDiskIcons,
"ThirdPartyTrim": self.ThirdPartyTrim,
"XhciPortLimit": self.XhciPortLimit
]
uefiQuirks = [
"IgnoreTextInGraphics": self.IgnoreTextInGraphics,
"IgnoreInvalidFlexRatio": self.IgnoreInvalidFlexRatio,
"ProvideConsoleControl": self.ProvideConsoleControl,
"ProvideConsoleGop": self.ProvideConsoleGop,
"ReleaseUsbOwnership": self.ReleaseUsbOwnership,
"RequestBootVarRouting": self.RequestBootVarRouting,
"SanitiseClearScreen": self.SanitiseClearScreen
]
uefiProtocols = [
"AppleBootPolicy": self.AppleBootPolicy,
"DeviceProperties": self.DeviceProperties
]
NotificationCenter.default.addObserver(self, selector: #selector(onPlistOpen(_:)), name: .plistOpen, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(onPlistSave(_:)), name: .plistSave, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(onAcpiSyncPopover(_:)), name: .syncAcpiPopoverAndDict, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(onKernelSyncPopover(_:)), name: .syncKernelPopoverAndDict, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(onPasteVC(_:)), name: .paste, object: nil)
}
func reloadEsps() {
if let tempDir = createTempDirectory() {
print(tempDir)
let _ = shell(launchPath: "/bin/bash", arguments: ["-c", "diskutil list -plist > \(tempDir)/diskutil.plist"])
let _ = shell(launchPath: "/bin/bash", arguments: ["-c", "diskutil apfs list -plist > \(tempDir)/apfs.plist"])
let disks = shell(launchPath: "/bin/bash", arguments: ["-c", "ls /Volumes | grep -v EFI"])?.components(separatedBy: "\n")
let diskutil = NSDictionary(contentsOfFile: "\(tempDir)/diskutil.plist")
let allDisksAndPartitioins = diskutil?.object(forKey: "AllDisksAndPartitions") as! NSArray
for disk in disks! {
if disk != "" {
for diskEntry in allDisksAndPartitioins {
let diskEntryDict = diskEntry as! NSDictionary
let partitionsForDisk = diskEntryDict.object(forKey: "Partitions") as! NSArray
if partitionsForDisk.count > 0 {
for partition in partitionsForDisk {
let partitionDict = partition as! NSDictionary
if disk == partitionDict.value(forKey: "VolumeName") as? String ?? String() {
for innerPartition in partitionsForDisk {
let innerPartitionDict = innerPartition as! NSDictionary
if innerPartitionDict.value(forKey: "VolumeName") as? String ?? String() == "EFI" {
drivesDict[disk] = (innerPartitionDict.value(forKey: "DeviceIdentifier") as! String)
}
}
}
}
} else {
let apfsDict = NSDictionary(contentsOfFile: "\(tempDir)/apfs.plist")
let apfsVolumesForDisk = diskEntryDict.object(forKey: "APFSVolumes") as! NSArray
for volume in apfsVolumesForDisk {
let volumeDict = volume as! NSDictionary
if disk == volumeDict.value(forKey: "VolumeName") as? String ?? String() {
let apfsIdentifier = String((volumeDict.value(forKey: "DeviceIdentifier") as! String).dropLast(2))
let apfsContainers = apfsDict?.object(forKey: "Containers") as! NSArray
for container in apfsContainers {
let containerDict = container as! NSDictionary
if containerDict.value(forKey: "ContainerReference") as? String ?? String() == apfsIdentifier {
let containerDriveIdentifier = String((containerDict.value(forKey: "DesignatedPhysicalStore") as! String).dropLast(2))
for innerDiskEntry in allDisksAndPartitioins {
let innerDiskEntryDict = innerDiskEntry as! NSDictionary
if innerDiskEntryDict.value(forKey: "DeviceIdentifier") as? String ?? String() == containerDriveIdentifier {
let innerPartitions = innerDiskEntryDict.object(forKey: "Partitions") as! NSArray
for innerPartition in innerPartitions {
let innerPartitionDict = innerPartition as! NSDictionary
if innerPartitionDict.value(forKey: "VolumeName") as? String ?? String() == "EFI" {
drivesDict[disk] = (innerPartitionDict.value(forKey: "DeviceIdentifier") as! String)
}
}
}
}
}
}
}
}
}
}
}
}
}
espPopup.removeAllItems()
espPopup.addItem(withTitle: "Select an EFI partition...")
espPopup.menu?.addItem(NSMenuItem.separator())
for drive in Array(drivesDict.keys) {
espPopup.addItem(withTitle: drive)
}
}
func resetTables() {
tableLookup = [ // lookup table holding the datasources to the tableviews
sectionsTable: [["section": "ACPI"],["section": "Device Properties"],["section": "Kernel"],["section": "Misc"],["section": "NVRAM"],["section": "Platform Info"],["section": "UEFI"]],
acpiAddTable: [[String: String]](),
acpiBlockTable: [[String: String]](),
acpiPatchTable: [[String: String]](),
deviceAddTable: [[String: String]](),
deviceBlockTable: [[String: String]](),
kernelAddTable: [[String: String]](),
kernelBlockTable: [[String: String]](),
kernelPatchTable: [[String: String]](),
nvramBootTable: [[String: String]](),
nvramVendorTable: [[String: String]](),
nvramCustomTable: [[String: String]](),
nvramBlockTable: [[String: String]](),
uefiDriverTable: [[String: String]](),
platformSmbiosTable: [["property": "BIOSVendor", "value": ""],
["property": "BIOSVersion", "value": ""],
["property": "BIOSReleaseDate", "value": ""],
["property": "SystemManufacturer", "value": ""],
["property": "SystemProductName", "value": ""],
["property": "SystemVersion", "value": ""],
["property": "SystemSerialNumber", "value": ""],
["property": "SystemUUID", "value": ""],
["property": "SystemSKUNumber", "value": ""],
["property": "SystemFamily", "value": ""],
["property": "BoardManufacturer", "value": ""],
["property": "BoardProduct", "value": ""],
["property": "BoardVersion", "value": ""],
["property": "BoardSerialNumber", "value": ""],
["property": "BoardAssetTag", "value": ""],
["property": "BoardType", "value": ""],
["property": "BoardLocationInChassis", "value": ""],
["property": "ChassisManufacturer", "value": ""],
["property": "ChassisType", "value": ""],
["property": "ChassisVersion", "value": ""],
["property": "ChassisSerialNumber", "value": ""],
["property": "ChassisAssetTag", "value": ""],
["property": "PlatformFeature", "value": ""],
["property": "FirmwareFeatures", "value": ""],
["property": "FirmwareFeaturesMask", "value": ""],
["property": "ProcessorType", "value": ""],
["property": "MemoryFormFactor", "value": ""]],
platformDatahubTable: [["property": "ARTFrequency", "value": ""],
["property": "BoardProduct", "value": ""],
["property": "BoardRevision", "value": ""],
["property": "DevicePathsSupported", "value": ""],
["property": "FSBFrequency", "value": ""],
["property": "InitialTSC", "value": ""],
["property": "PlatformName", "value": ""],
["property": "SmcBranch", "value": ""],
["property": "SmcPlatform", "value": ""],
["property": "SmcRevision", "value": ""],
["property": "StartupPowerEvents", "value": ""],
["property": "SystemProductName", "value": ""],
["property": "SystemSerialNumber", "value": ""],
["property": "SystemUUID", "value": ""]],
platformGenericTable: [["property": "SystemUUID", "value": ""],
["property": "MLB", "value": ""],
["property": "ROM", "value": ""],
["property": "SystemProductName", "value": ""],
["property": "SystemSerialNumber", "value": ""]],
platformNvramTable: [["property": "BID", "value": ""],
["property": "MLB", "value": ""],
["property": "ROM", "value": ""],
["property": "FirmwareFeatures", "value": ""],
["property": "FirmwareFeaturesMask", "value": ""]]
]
}
@objc func acpiAdvanced(_ sender: NSButton) {
let acpiVc = AcpiPopoverController.loadFromNib() // load popover viewcontroller set up in AcpiPopoverController.swift
acpiPatchTable.selectRowIndexes(IndexSet(integer: Int(sender.identifier!.rawValue)!), byExtendingSelection: false) // select row the button belongs to for the code below to work
// TODO: rely only on button identifier, not selected row, so we can allow an empty selection like in all other tables
acpiLimitString = tableLookup[acpiPatchTable]![Int(sender.identifier!.rawValue)!]["Limit"] ?? "" // fill variables with contents of plist file
acpiMaskString = tableLookup[acpiPatchTable]![Int(sender.identifier!.rawValue)!]["Mask"] ?? ""
acpiOemTableIdString = tableLookup[acpiPatchTable]![Int(sender.identifier!.rawValue)!]["OemTableId"] ?? ""
acpiReplaceMaskString = tableLookup[acpiPatchTable]![Int(sender.identifier!.rawValue)!]["ReplaceMask"] ?? ""
acpiSkipString = tableLookup[acpiPatchTable]![Int(sender.identifier!.rawValue)!]["Skip"] ?? ""
acpiTableLengthString = tableLookup[acpiPatchTable]![Int(sender.identifier!.rawValue)!]["TableLength"] ?? ""
acpiCountString = tableLookup[acpiPatchTable]![Int(sender.identifier!.rawValue)!]["Count"] ?? ""
acpiVc.showPopover(button: sender)
}
@objc func kernelAdvanced(_ sender: NSButton) {
let kernelVc = KernelPopoverController.loadFromNib()
kernelPatchTable.selectRowIndexes(IndexSet(integer: Int(sender.identifier!.rawValue)!), byExtendingSelection: false)
kernelBaseString = tableLookup[kernelPatchTable]![Int(sender.identifier!.rawValue)!]["Base"] ?? ""
kernelCountString = tableLookup[kernelPatchTable]![Int(sender.identifier!.rawValue)!]["Count"] ?? ""
kernelIdentifierString = tableLookup[kernelPatchTable]![Int(sender.identifier!.rawValue)!]["Identifier"] ?? ""
kernelLimitString = tableLookup[kernelPatchTable]![Int(sender.identifier!.rawValue)!]["Limit"] ?? ""
kernelMaskString = tableLookup[kernelPatchTable]![Int(sender.identifier!.rawValue)!]["Mask"] ?? ""
kernelReplaceString = tableLookup[kernelPatchTable]![Int(sender.identifier!.rawValue)!]["ReplaceMask"] ?? ""
kernelSkipString = tableLookup[kernelPatchTable]![Int(sender.identifier!.rawValue)!]["Skip"] ?? ""
kernelVc.showPopover(button: sender)
}
@objc func onAcpiSyncPopover(_ notification: Notification) {
tableLookup[acpiPatchTable]![acpiPatchTable.selectedRow][(acpiCurrentTextField.identifier?.rawValue)!] = acpiCurrentTextField.stringValue
}
@objc func onKernelSyncPopover(_ notification: Notification) {
tableLookup[kernelPatchTable]![kernelPatchTable.selectedRow][(kernelCurrentTextField.identifier?.rawValue)!] = kernelCurrentTextField.stringValue
}
@objc func onPasteVC(_ notification: Notification) {
if sectionsTable.selectedRow == 0, (viewLookup[sectionsTable.selectedRow]!.selectedTabViewItem?.view?.subviews[0].subviews[1].subviews[0] as! NSTableView) == acpiPatchTable {
let currentTable = viewLookup[sectionsTable.selectedRow]!.selectedTabViewItem?.view?.subviews[0].subviews[1].subviews[0] as! NSTableView
let pastedDictString = NSPasteboard.general.string(forType: .string) ?? ""
do {
if let pastedPlist = try PropertyListSerialization.propertyList(from: pastedDictString.data(using: .utf8)!, format: .none)
as? NSMutableDictionary {
// Successfully read property list.
parsePastedPlist(currentTable: currentTable, pastedPlist: pastedPlist)
} else if let pastedPlist = try PropertyListSerialization.propertyList(from: pastedDictString.data(using: .utf8)!, format: .none)
as? NSMutableArray {
for dict in pastedPlist {
parsePastedPlist(currentTable: currentTable, pastedPlist: dict as! NSMutableDictionary)
}
} else {
print("not a dictionary")
}
} catch let error {
print("not a plist:", error.localizedDescription)
}
}
}
func parsePastedPlist(currentTable: NSTableView, pastedPlist: NSMutableDictionary) {
let tempDict: NSMutableDictionary = NSMutableDictionary()
if (pastedPlist.allKeys as! [String]).contains("Find") {
tempDict.addEntries(from: ["Comment": pastedPlist.value(forKey: "Comment") as? String ?? String()])
tempDict.addEntries(from: ["Count": String(pastedPlist.value(forKey: "Count") as? Int ?? Int())])
tempDict.addEntries(from: ["Limit": String(pastedPlist.value(forKey: "Limit") as? Int ?? Int())])
tempDict.addEntries(from: ["Skip": String(pastedPlist.value(forKey: "Skip") as? Int ?? Int())])
tempDict.addEntries(from: ["TableLength": String(pastedPlist.value(forKey: "TableLength") as? Int ?? Int())])
tempDict.addEntries(from: ["Find": (pastedPlist.value(forKey: "Find") as? Data)?.hexEncodedString(options: .upperCase) ?? String()])
tempDict.addEntries(from: ["Replace": (pastedPlist.value(forKey: "Replace") as? Data)?.hexEncodedString(options: .upperCase) ?? String()])
tempDict.addEntries(from: ["Mask": (pastedPlist.value(forKey: "Mask") as? Data)?.hexEncodedString(options: .upperCase) ?? String()])
tempDict.addEntries(from: ["OemTableId": (pastedPlist.value(forKey: "OemTableId") as? Data)?.hexEncodedString(options: .upperCase) ?? String()])
tempDict.addEntries(from: ["ReplaceMask": (pastedPlist.value(forKey: "ReplaceMask") as? Data)?.hexEncodedString(options: .upperCase) ?? String()])
tempDict.addEntries(from: ["TableSignature": String(data: pastedPlist.value(forKey: "Count") as? Data ?? Data(), encoding: .ascii) ?? String()])
}
if (pastedPlist.value(forKey: "Enabled") as? Bool ?? false) == true {
tempDict.setValue("1", forKey: "Enabled")
} else {
tempDict.setValue("0", forKey: "Enabled")
}
if (pastedPlist.allKeys as! [String]).contains("Disabled") {
if (pastedPlist.value(forKey: "Disabled") as? Bool ?? true) == false {
tempDict.setValue("1", forKey: "Enabled")
} else {
tempDict.setValue("0", forKey: "Enabled")
}
}
if tempDict != ["Find": ""] {
tableLookup[currentTable]?.append(tempDict as! [String: String])
currentTable.reloadData()
}
}
@objc func deviceEdit(_ sender: NSButton) {
let customItem = NSAlert()
customItem.addButton(withTitle: "OK") // 1st button
customItem.addButton(withTitle: "Cancel") // 2nd button
customItem.messageText = "Edit value as String"
customItem.informativeText = ""
let txt = NSTextField(frame: NSRect(x: 0, y: 0, width: 200, height: 24))
txt.stringValue = String(decoding: Data(hexString: tableLookup[deviceAddTable]![Int(sender.identifier!.rawValue)!]["value"]!)!, as: UTF8.self)
customItem.accessoryView = txt
let response: NSApplication.ModalResponse = customItem.runModal()
if (response == NSApplication.ModalResponse.alertFirstButtonReturn) {
tableLookup[deviceAddTable]![Int(sender.identifier!.rawValue)!]["value"] = txt.stringValue.data(using: .ascii)?.hexEncodedString(options: .upperCase)
deviceAddTable.reloadData()
}
}
var acpiDict: NSMutableDictionary = NSMutableDictionary()
var acpiQuirksDict: NSMutableDictionary = NSMutableDictionary()
var acpiAddArray: NSMutableArray = NSMutableArray()
var acpiBlockArray: NSMutableArray = NSMutableArray()
var acpiPatchArray: NSMutableArray = NSMutableArray()
var deviceDict: NSMutableDictionary = NSMutableDictionary()
var deviceAddDict: NSMutableDictionary = NSMutableDictionary()
var deviceBlockDict: NSMutableDictionary = NSMutableDictionary()
var deviceQuirksDict: NSMutableDictionary = NSMutableDictionary()
var kernelDict: NSMutableDictionary = NSMutableDictionary()
var kernelAddArray: NSMutableArray = NSMutableArray()
var kernelBlockArray: NSMutableArray = NSMutableArray()
var kernelPatchArray: NSMutableArray = NSMutableArray()
var kernelQuirksDict: NSMutableDictionary = NSMutableDictionary()
var miscDict: NSMutableDictionary = NSMutableDictionary()
var miscBootDict: NSMutableDictionary = NSMutableDictionary()
var miscDebugDict: NSMutableDictionary = NSMutableDictionary()
var miscSecurityDict: NSMutableDictionary = NSMutableDictionary()
var nvramDict: NSMutableDictionary = NSMutableDictionary()
var nvramAddDict: NSMutableDictionary = NSMutableDictionary()
var nvramBlockDict: NSMutableDictionary = NSMutableDictionary()
var uefiDict: NSMutableDictionary = NSMutableDictionary()
var uefiDriverArray: NSMutableArray = NSMutableArray()
var uefiConnectDriversBool: Bool = Bool()
var uefiQuirksDict: NSMutableDictionary = NSMutableDictionary()
var uefiProtocolsDict: NSMutableDictionary = NSMutableDictionary()
var platformInfoDict: NSMutableDictionary = NSMutableDictionary()
var platformSmbiosDict: NSMutableDictionary = NSMutableDictionary()
var platformDatahubDict: NSMutableDictionary = NSMutableDictionary()
var platformGenericDict: NSMutableDictionary = NSMutableDictionary()
var platformNvramDict: NSMutableDictionary = NSMutableDictionary()
var platformAutomaticBool: Bool = Bool()
var platformUpdateDatahubBool: Bool = Bool()
var platformUpdateNvramBool: Bool = Bool()
var platformUpdateSmbiosBool: Bool = Bool()
var platformUpdateSmbiosModeStr: String = String()
func createTempDirectory() -> String? {
let tempDirectoryTemplate = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("OpenCore-Configurator")
let fileManager = FileManager.default
do {
try fileManager.createDirectory(at: tempDirectoryTemplate, withIntermediateDirectories: true, attributes: nil)
return tempDirectoryTemplate.path
} catch {
return nil
}
}
@objc func onPlistOpen(_ notification: Notification) {
resetTables() // clear tables before adding new data to them
let OHF = openHandlerFunctions()
let plistDict = NSMutableDictionary(contentsOfFile: path)
acpiDict = plistDict?.object(forKey: "ACPI") as? NSMutableDictionary ?? NSMutableDictionary() // for now we're manually extracting each individual dict entry, this should be changed to doing this in a loop in the future,
acpiQuirksDict = acpiDict.object(forKey: "Quirks") as? NSMutableDictionary ?? NSMutableDictionary()
acpiAddArray = acpiDict.object(forKey: "Add") as? NSMutableArray ?? NSMutableArray()
if acpiAddArray.count > 0 {
for i in 0...(acpiAddArray.count - 1) {
let tempDict = (acpiAddArray[i] as! NSDictionary).mutableCopy() as! NSMutableDictionary
if (tempDict.value(forKey: "Enabled") as! Bool) == true {
tempDict.setValue("1", forKey: "Enabled")
} else {
tempDict.setValue("0", forKey: "Enabled")
}
acpiAddArray[i] = tempDict
}
}
acpiBlockArray = acpiDict.object(forKey: "Block") as? NSMutableArray ?? NSMutableArray()
if acpiBlockArray.count > 0 {
for i in 0...(acpiBlockArray.count - 1) {
let tempDict = (acpiBlockArray[i] as! NSDictionary).mutableCopy() as! NSMutableDictionary
tempDict.setValue(String(data: tempDict.value(forKey: "TableSignature") as? Data ?? Data(), encoding: .ascii), forKey: "TableSignature") // since the popup button is now reading the value directly instead of decoding it, we need to decode it here manually
acpiBlockArray[i] = tempDict
}
}
acpiPatchArray = acpiDict.object(forKey: "Patch") as? NSMutableArray ?? NSMutableArray()
if acpiPatchArray.count > 0 { // decode all non-String data into Strings. Not using the openHander function because these tables need support
for i in 0...(acpiPatchArray.count - 1) { // for reordering and the openHanderfunctions don't ensure the correct order
let tempDict = (acpiPatchArray[i] as! NSDictionary).mutableCopy() as! NSMutableDictionary
if (tempDict.value(forKey: "Enabled") as? Bool ?? false) == true {
tempDict.setValue("1", forKey: "Enabled")
} else {
tempDict.setValue("0", forKey: "Enabled")
}
tempDict.setValue(String(tempDict.value(forKey: "Count") as? Int ?? Int()), forKey: "Count")
tempDict.setValue(String(tempDict.value(forKey: "Limit") as? Int ?? Int()), forKey: "Limit")
tempDict.setValue(String(tempDict.value(forKey: "Skip") as? Int ?? Int()), forKey: "Skip")
tempDict.setValue(String(tempDict.value(forKey: "TableLength") as? Int ?? Int()), forKey: "TableLength")
tempDict.setValue((tempDict.value(forKey: "Find") as? Data)?.hexEncodedString(options: .upperCase) ?? String(), forKey: "Find")
tempDict.setValue((tempDict.value(forKey: "Replace") as? Data)?.hexEncodedString(options: .upperCase) ?? String(), forKey: "Replace")
tempDict.setValue((tempDict.value(forKey: "Mask") as? Data)?.hexEncodedString(options: .upperCase) ?? String(), forKey: "Mask")
tempDict.setValue((tempDict.value(forKey: "OemTableId") as? Data)?.hexEncodedString(options: .upperCase) ?? String(), forKey: "OemTableId")
tempDict.setValue((tempDict.value(forKey: "ReplaceMask") as? Data)?.hexEncodedString(options: .upperCase) ?? String(), forKey: "ReplaceMask")
tempDict.setValue(String(data: tempDict.value(forKey: "TableSignature") as? Data ?? Data(), encoding: .ascii), forKey: "TableSignature")
acpiPatchArray[i] = tempDict
}
}
deviceDict = plistDict?.object(forKey: "DeviceProperties") as? NSMutableDictionary ?? NSMutableDictionary()
deviceAddDict = deviceDict.object(forKey: "Add") as? NSMutableDictionary ?? NSMutableDictionary()
deviceBlockDict = deviceDict.object(forKey: "Block") as? NSMutableDictionary ?? NSMutableDictionary()
deviceQuirksDict = deviceDict.object(forKey: "Quirks") as? NSMutableDictionary ?? NSMutableDictionary()
kernelDict = plistDict?.object(forKey: "Kernel") as? NSMutableDictionary ?? NSMutableDictionary()
kernelAddArray = kernelDict.object(forKey: "Add") as? NSMutableArray ?? NSMutableArray()
if kernelAddArray.count > 0 {
for i in 0...(kernelAddArray.count - 1) {
let tempDict = (kernelAddArray[i] as! NSDictionary).mutableCopy() as! NSMutableDictionary
if (tempDict.value(forKey: "Enabled") as? Bool ?? false) == true {
tempDict.setValue("1", forKey: "Enabled")
} else {
tempDict.setValue("0", forKey: "Enabled")
}
kernelAddArray[i] = tempDict
}
}
kernelBlockArray = kernelDict.object(forKey: "Block") as? NSMutableArray ?? NSMutableArray()
kernelPatchArray = kernelDict.object(forKey: "Patch") as? NSMutableArray ?? NSMutableArray()
if kernelPatchArray.count > 0 {
for i in 0...(kernelPatchArray.count - 1) {
let tempDict = (kernelPatchArray[i] as! NSDictionary).mutableCopy() as! NSMutableDictionary
if (tempDict.value(forKey: "Enabled") as? Bool ?? false) == true {
tempDict.setValue("1", forKey: "Enabled")
} else {
tempDict.setValue("0", forKey: "Enabled")
}
tempDict.setValue(String(tempDict.value(forKey: "Count") as? Int ?? Int()), forKey: "Count")
tempDict.setValue(String(tempDict.value(forKey: "Limit") as? Int ?? Int()), forKey: "Limit")
tempDict.setValue(String(tempDict.value(forKey: "Skip") as? Int ?? Int()), forKey: "Skip")
tempDict.setValue((tempDict.value(forKey: "Find") as? Data)?.hexEncodedString(options: .upperCase) ?? String(), forKey: "Find")
tempDict.setValue((tempDict.value(forKey: "Replace") as? Data)?.hexEncodedString(options: .upperCase) ?? String(), forKey: "Replace")
tempDict.setValue((tempDict.value(forKey: "Mask") as? Data)?.hexEncodedString(options: .upperCase) ?? String(), forKey: "Mask")
tempDict.setValue((tempDict.value(forKey: "ReplaceMask") as? Data)?.hexEncodedString(options: .upperCase) ?? String(), forKey: "ReplaceMask")
kernelPatchArray[i] = tempDict
}
}
kernelQuirksDict = kernelDict.object(forKey: "Quirks") as? NSMutableDictionary ?? NSMutableDictionary()
miscDict = plistDict?.object(forKey: "Misc") as? NSMutableDictionary ?? NSMutableDictionary()
miscBootDict = miscDict.object(forKey: "Boot") as? NSMutableDictionary ?? NSMutableDictionary()
miscDebugDict = miscDict.object(forKey: "Debug") as? NSMutableDictionary ?? NSMutableDictionary()
miscSecurityDict = miscDict.object(forKey: "Security") as? NSMutableDictionary ?? NSMutableDictionary()
nvramDict = plistDict?.object(forKey: "NVRAM") as? NSMutableDictionary ?? NSMutableDictionary()
nvramAddDict = nvramDict.object(forKey: "Add") as? NSMutableDictionary ?? NSMutableDictionary()
nvramBlockDict = nvramDict.object(forKey: "Block") as? NSMutableDictionary ?? NSMutableDictionary()
uefiDict = plistDict?.object(forKey: "UEFI") as? NSMutableDictionary ?? NSMutableDictionary()
uefiDriverArray = uefiDict.object(forKey: "Drivers") as? NSMutableArray ?? NSMutableArray()
uefiConnectDriversBool = uefiDict.object(forKey: "ConnectDrivers") as? Bool ?? false
uefiQuirksDict = uefiDict.object(forKey: "Quirks") as? NSMutableDictionary ?? NSMutableDictionary()
uefiProtocolsDict = uefiDict.object(forKey: "Protocols") as? NSMutableDictionary ?? NSMutableDictionary()
let uefiExitBootInt = uefiQuirksDict.object(forKey: "ExitBootServicesDelay") as? Int ?? Int()
platformInfoDict = plistDict?.object(forKey: "PlatformInfo") as? NSMutableDictionary ?? NSMutableDictionary()
platformSmbiosDict = platformInfoDict.object(forKey: "SMBIOS") as? NSMutableDictionary ?? NSMutableDictionary()
platformDatahubDict = platformInfoDict.object(forKey: "DataHub") as? NSMutableDictionary ?? NSMutableDictionary()
platformGenericDict = platformInfoDict.object(forKey: "Generic") as? NSMutableDictionary ?? NSMutableDictionary()
platformNvramDict = platformInfoDict.object(forKey: "PlatformNVRAM") as? NSMutableDictionary ?? NSMutableDictionary()
platformAutomaticBool = platformInfoDict.object(forKey: "Automatic") as? Bool ?? false
platformUpdateDatahubBool = platformInfoDict.object(forKey: "UpdateDataHub") as? Bool ?? false
platformUpdateNvramBool = platformInfoDict.object(forKey: "UpdateNVRAM") as? Bool ?? false
platformUpdateSmbiosBool = platformInfoDict.object(forKey: "UpdateSMBIOS") as? Bool ?? false
platformUpdateSmbiosModeStr = platformInfoDict.object(forKey: "UpdateSMBIOSMode") as? String ?? String()
topLevelBools = [
uefiConnectDrivers: uefiConnectDriversBool,
smbiosAutomatic: platformAutomaticBool,
updateDatahub: platformUpdateDatahubBool,
updateNvram: platformUpdateNvramBool,
updateSmbios: platformUpdateSmbiosBool
]
for (key, value) in miscBootDict { // we're not dealing with tables here so it's easier to just parse the data manually. This sucks but I don't have a better idea for this atm
switch key as! String {
case "ShowPicker":
if value as! Bool {
showPicker.state = .on
}
else {
showPicker.state = .off
}
case "Timeout":
timeoutStepper.stringValue = String(value as! Int)
timeoutTextfield.stringValue = String(value as! Int)
case "ConsoleMode":
consoleMode.stringValue = value as! String
case "ConsoleBehaviourOs":
if value as! String != "" {
if OsBehavior.itemTitles.contains(value as! String) {
OsBehavior.selectItem(withTitle: value as! String)
}
} else {
OsBehavior.selectItem(withTitle: "Don't change")
}
case "ConsoleBehaviourUi":
if value as! String != "" {
if UiBehavior.itemTitles.contains(value as! String) {
UiBehavior.selectItem(withTitle: value as! String)
}
} else {
UiBehavior.selectItem(withTitle: "Don't change")
}
case "HideSelf":
if value as! Bool {
hideSelf.state = .on
}
else {
hideSelf.state = .off
}
case "Resolution":
resolution.stringValue = value as! String
default:
break
}
}
for (key, value) in miscDebugDict {
switch key as! String {
case "DisplayDelay":
miscDelayText.stringValue = String(value as! Int)
case "DisplayLevel":
miscDisplayLevelText.stringValue = String(value as! Int)
case "ExposeBootPath":
if value as! Bool {
miscExposeBootPath.state = .on
}
else {
miscExposeBootPath.state = .off
}
case "Target":
miscTargetText.stringValue = String(value as! Int)
case "DisableWatchDog":
if value as! Bool {
disableWatchdog.state = .on
} else {
disableWatchdog.state = .off
}
default:
break
}
}
for (key, value) in miscSecurityDict {
switch key as! String {
case "HaltLevel":
miscHaltlevel.stringValue = String(value as! Int)
case "RequireSignature":
if value as! Bool {
miscRequireSignature.state = .on
}
else {
miscRequireSignature.state = .off
}
case "RequireVault":
if value as! Bool {
miscRequireVault.state = .on
}
else {
miscRequireVault.state = .off
}
default:
break
}
}
for (key, value) in nvramAddDict {
switch key as! String {
case "7C436110-AB2A-4BBB-A880-FE41995C9F82":
OHF.createNvramData(value: value as! NSMutableDictionary, table: &nvramBootTable)
case "4D1EDE05-38C7-4A6A-9CC6-4BCCA8B38C14":
OHF.createNvramData(value: value as! NSMutableDictionary, table: &nvramVendorTable)
default:
OHF.createNvramData(value: value as! NSMutableDictionary, table: &nvramCustomTable, guidString: key as? String)
}
}
for (key, value) in nvramBlockDict {
OHF.createNvramData(value: value as! NSMutableArray, table: &nvramBlockTable, guidString: key as? String)
}
OHF.createTopLevelBools(buttonDict: &topLevelBools)
if smbioUpdateModePopup.itemTitles.contains(platformUpdateSmbiosModeStr) {
smbioUpdateModePopup.selectItem(withTitle: platformUpdateSmbiosModeStr)
} else {
smbioUpdateModePopup.selectItem(withTitle: "Auto")
}
//OHF.createData(input: acpiAddArray, table: &acpiAddTable, predefinedKey: "acpiAdd")
tableLookup[acpiAddTable] = acpiAddArray as? Array ?? Array()
acpiAddTable.reloadData()
OHF.createData(input: acpiBlockArray, table: &acpiBlockTable)
//OHF.createData(input: acpiPatchArray, table: &acpiPatchTable)
tableLookup[acpiPatchTable] = acpiPatchArray as? Array ?? Array()
acpiPatchTable.reloadData()
OHF.createQuirksData(input: acpiQuirksDict, quirksDict: acpiQuirks)
OHF.createData(input: deviceAddDict, table: &deviceAddTable)
OHF.createData(input: deviceBlockDict, table: &deviceBlockTable)
// OHF.createQuirksData(input: deviceQuirksDict, quirksDict: deviceQuirks) // device properties quirks don't exist anymore. leaving this here in case they come back
//OHF.createData(input: kernelAddArray, table: &kernelAddTable)
tableLookup[kernelAddTable] = kernelAddArray as? Array ?? Array()
kernelAddTable.reloadData()
OHF.createData(input: kernelBlockArray, table: &kernelBlockTable)
//OHF.createData(input: kernelPatchArray, table: &kernelPatchTable)
tableLookup[kernelPatchTable] = kernelPatchArray as? Array ?? Array()
kernelPatchTable.reloadData()
OHF.createQuirksData(input: kernelQuirksDict, quirksDict: kernelQuirks)
OHF.createData(input: uefiDriverArray, table: &uefiDriverTable, predefinedKey: "driver")
OHF.createQuirksData(input: uefiQuirksDict, quirksDict: uefiQuirks)
OHF.createQuirksData(input: uefiProtocolsDict, quirksDict: uefiProtocols)
ExitBootServicesDelay.stringValue = String(uefiExitBootInt)
OHF.createData(input: platformSmbiosDict, table: &platformSmbiosTable)
OHF.createData(input: platformDatahubDict, table: &platformDatahubTable)
OHF.createData(input: platformGenericDict, table: &platformGenericTable)
OHF.createData(input: platformNvramDict, table: &platformNvramTable)
self.view.window?.title = "\((path as NSString).lastPathComponent) - OpenCore Configurator"
self.view.window?.representedURL = URL(fileURLWithPath: path)
}
@objc func onPlistSave(_ notification: Notification) {
let SHF = saveHandlerFunctions()
SHF.saveArrayOfDictData(table: acpiAddTable, array: &acpiAddArray)
SHF.saveArrayOfDictData(table: acpiBlockTable, array: &acpiBlockArray)
//SHF.saveArrayOfDictData(table: acpiPatchTable, array: &acpiPatchArray)
acpiPatchArray = (tableLookup[acpiPatchTable]! as NSArray).mutableCopy() as! NSMutableArray
if acpiPatchArray.count > 0 {
for i in 0...(acpiPatchArray.count - 1) {
let tempDict = (acpiPatchArray[i] as! NSDictionary).mutableCopy() as! NSMutableDictionary
if (tempDict.value(forKey: "Enabled") as! String) == "1" {
tempDict.setValue(true, forKey: "Enabled")
} else {
tempDict.setValue(false, forKey: "Enabled")
}
tempDict.setValue(Int(tempDict.value(forKey: "Count") as! String), forKey: "Count")
tempDict.setValue(Int(tempDict.value(forKey: "Limit") as! String), forKey: "Limit")
tempDict.setValue(Int(tempDict.value(forKey: "Skip") as! String), forKey: "Skip")
tempDict.setValue(Int(tempDict.value(forKey: "TableLength") as! String), forKey: "TableLength")
tempDict.setValue(Data(hexString: tempDict.value(forKey: "Find") as! String), forKey: "Find")
tempDict.setValue(Data(hexString: tempDict.value(forKey: "Replace") as! String), forKey: "Replace")
tempDict.setValue(Data(hexString: tempDict.value(forKey: "Mask") as! String), forKey: "Mask")
tempDict.setValue(Data(hexString: tempDict.value(forKey: "OemTableId") as! String), forKey: "OemTableId")
tempDict.setValue(Data(hexString: tempDict.value(forKey: "ReplaceMask") as! String), forKey: "ReplaceMask")
tempDict.setValue((tempDict.value(forKey: "TableSignature") as! String).data(using: .ascii), forKey: "TableSignature")
tempDict.removeObject(forKey: "advanced")
acpiPatchArray[i] = tempDict
}
}
SHF.saveQuirksData(dict: acpiQuirks, quirksDict: &acpiQuirksDict)
//SHF.saveArrayOfDictData(table: kernelAddTable, array: &kernelAddArray)
kernelAddArray = (tableLookup[kernelAddTable]! as NSArray).mutableCopy() as! NSMutableArray
if kernelAddArray.count > 0 {
for i in 0...(kernelAddArray.count - 1) {
let tempDict = (kernelAddArray[i] as! NSDictionary).mutableCopy() as! NSMutableDictionary
if (tempDict.value(forKey: "Enabled") as! String) == "1" {
tempDict.setValue(true, forKey: "Enabled")
} else {
tempDict.setValue(false, forKey: "Enabled")
}
kernelAddArray[i] = tempDict
}
}
SHF.saveArrayOfDictData(table: kernelBlockTable, array: &kernelBlockArray)
//SHF.saveArrayOfDictData(table: kernelPatchTable, array: &kernelPatchArray)
kernelPatchArray = (tableLookup[kernelPatchTable]! as NSArray).mutableCopy() as! NSMutableArray
if kernelPatchArray.count > 0 {
for i in 0...(kernelPatchArray.count - 1) {
let tempDict = (kernelPatchArray[i] as! NSDictionary).mutableCopy() as! NSMutableDictionary
if (tempDict.value(forKey: "Enabled") as! String) == "1" {
tempDict.setValue(true, forKey: "Enabled")
} else {
tempDict.setValue(false, forKey: "Enabled")
}
tempDict.setValue(Int(tempDict.value(forKey: "Count") as! String), forKey: "Count")
tempDict.setValue(Int(tempDict.value(forKey: "Limit") as! String), forKey: "Limit")
tempDict.setValue(Int(tempDict.value(forKey: "Skip") as! String), forKey: "Skip")
tempDict.setValue(Data(hexString: tempDict.value(forKey: "Find") as! String), forKey: "Find")
tempDict.setValue(Data(hexString: tempDict.value(forKey: "Replace") as! String), forKey: "Replace")
tempDict.setValue(Data(hexString: tempDict.value(forKey: "Mask") as! String), forKey: "Mask")
tempDict.setValue(Data(hexString: tempDict.value(forKey: "ReplaceMask") as! String), forKey: "ReplaceMask")
tempDict.removeObject(forKey: "kernelAdvanced")
kernelPatchArray[i] = tempDict
}
}
SHF.saveQuirksData(dict: kernelQuirks, quirksDict: &kernelQuirksDict)
SHF.saveDeviceData(table: deviceAddTable, dict: &deviceAddDict)
SHF.saveDeviceData(table: deviceBlockTable, dict: &deviceBlockDict)
SHF.saveQuirksData(dict: deviceQuirks, quirksDict: &deviceQuirksDict)
// only process platform dicts if they're not empty. This is not necessary because we're checking this when appending to the platform dict too, but this is cleaner because we don't do unnecessary work
if isNotEmpty(platformGenericDict) { SHF.saveDictOfDictData(table: platformGenericTable, dict: &platformGenericDict) }
if isNotEmpty(platformNvramDict) { SHF.saveDictOfDictData(table: platformNvramTable, dict: &platformNvramDict) }
if isNotEmpty(platformSmbiosDict) { SHF.saveDictOfDictData(table: platformSmbiosTable, dict: &platformSmbiosDict) }
if isNotEmpty(platformDatahubDict) { SHF.saveDictOfDictData(table: platformDatahubTable, dict: &platformDatahubDict) }
SHF.saveStringData(table: uefiDriverTable, array: &uefiDriverArray)
SHF.saveQuirksData(dict: uefiQuirks, quirksDict: &uefiQuirksDict)
uefiQuirksDict.addEntries(from: ["ExitBootServicesDelay": Int(ExitBootServicesDelay.stringValue) ?? 0])
SHF.saveQuirksData(dict: uefiProtocols, quirksDict: &uefiProtocolsDict)
SHF.saveNvramBootData(table: nvramBootTable, dict: &nvramAddDict) // TODO: create subdicts for GUID, handle custom table seperately
SHF.saveNvramVendorData(table: nvramVendorTable, dict: &nvramAddDict)
SHF.saveNvramCustomData(table: nvramCustomTable, dict: &nvramAddDict)
clearDict = true // we split data from the same dict into 3 tables, so we don't want to clear it for each of them
SHF.saveNvramBlockData(table: nvramBlockTable, dict: &nvramBlockDict)
acpiDict.removeAllObjects()
acpiDict.addEntries(from: ["Add": acpiAddArray])
acpiDict.addEntries(from: ["Block": acpiBlockArray])
acpiDict.addEntries(from: ["Patch": acpiPatchArray])
acpiDict.addEntries(from: ["Quirks": acpiQuirksDict])
kernelDict.removeAllObjects()
kernelDict.addEntries(from: ["Add": kernelAddArray])
kernelDict.addEntries(from: ["Block": kernelBlockArray])
kernelDict.addEntries(from: ["Patch": kernelPatchArray])
kernelDict.addEntries(from: ["Quirks": kernelQuirksDict])
deviceDict.removeAllObjects()
deviceDict.addEntries(from: ["Add": deviceAddDict])
deviceDict.addEntries(from: ["Block": deviceBlockDict])
//deviceDict.addEntries(from: ["Quirks": deviceQuirksDict])
platformInfoDict.removeAllObjects()
if smbiosAutomatic.state == .on {
platformInfoDict.addEntries(from: ["Automatic": true])
} else {
platformInfoDict.addEntries(from: ["Automatic": false])
} // only add platform dicts if they're not empty
if isNotEmpty(platformDatahubDict) { platformInfoDict.addEntries(from: ["DataHub": platformDatahubDict]) }
if isNotEmpty(platformGenericDict) { platformInfoDict.addEntries(from: ["Generic": platformGenericDict]) }
if isNotEmpty(platformNvramDict) { platformInfoDict.addEntries(from: ["PlatformNVRAM": platformNvramDict]) }
if isNotEmpty(platformSmbiosDict) { platformInfoDict.addEntries(from: ["SMBIOS": platformSmbiosDict]) }
if updateDatahub.state == .on {
platformInfoDict.addEntries(from: ["UpdateDataHub": true])
} else {
platformInfoDict.addEntries(from: ["UpdateDataHub": false])
}
if updateNvram.state == .on {
platformInfoDict.addEntries(from: ["UpdateNVRAM": true])
} else {
platformInfoDict.addEntries(from: ["UpdateNVRAM": false])
}
if updateSmbios.state == .on {
platformInfoDict.addEntries(from: ["UpdateSMBIOS": true])
} else {
platformInfoDict.addEntries(from: ["UpdateSMBIOS": false])
}
platformInfoDict.addEntries(from: ["UpdateSMBIOSMode": (smbioUpdateModePopup.selectedItem?.title)!])
uefiDict.removeAllObjects()
if uefiConnectDrivers.state == .on {
uefiDict.addEntries(from: ["ConnectDrivers": true])
} else {
uefiDict.addEntries(from: ["ConnectDrivers": false])
}
uefiDict.addEntries(from: ["Drivers": uefiDriverArray])
uefiDict.addEntries(from: ["Quirks": uefiQuirksDict])
uefiDict.addEntries(from: ["Protocols": uefiProtocolsDict])
nvramDict.removeAllObjects()
nvramDict.addEntries(from: ["Add": nvramAddDict])
nvramDict.addEntries(from: ["Block": nvramBlockDict])
saveMisc()
let plistDict = NSMutableDictionary()
plistDict.addEntries(from: ["ACPI": acpiDict])
plistDict.addEntries(from: ["Kernel": kernelDict])
plistDict.addEntries(from: ["DeviceProperties": deviceDict])
plistDict.addEntries(from: ["PlatformInfo": platformInfoDict])
plistDict.addEntries(from: ["UEFI": uefiDict])
plistDict.addEntries(from: ["NVRAM": nvramDict])
plistDict.addEntries(from: ["Misc": miscDict])
plistDict.write(toFile: path, atomically: true)
// open the file as a string to strip newlines from <data></data> entries.
// Idea from CorpNewt's ProperTree commit in which he fixed the same issue
let plistString = shell(launchPath: "/bin/cat", arguments: [path]) ?? "" // load plist as a string
let plistArray = plistString.components(separatedBy: "\n") // split it into an array by newlines
var entriesContainingData: [Int] = [Int]()
var newPlistString = ""
for x in 0...(plistArray.count - 1) {
if plistArray[x].trimmingCharacters(in: .whitespacesAndNewlines) == "<data>" { // fill array with item numbers that contain contain "<data>"
entriesContainingData.append(x)
}
}
for x in 0...(plistArray.count - 3) {
if plistArray[x + 1].trimmingCharacters(in: .whitespacesAndNewlines) == "</data>" { // some data fields are empty. In that case we only need to trim