-
Notifications
You must be signed in to change notification settings - Fork 5
/
PreferencesController.m
executable file
·708 lines (605 loc) · 26 KB
/
PreferencesController.m
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
//
// PreferencesController.m
// PermanentEraser
//
// Created by Administrator on 6/16/10.
// Copyright 2010 Edenwaith. All rights reserved.
//
#import "PreferencesController.h"
#define WINDOW_TITLE_HEIGHT 78
static NSString *GeneralToolbarItemIdentifier = @"General";
static NSString *UpdateToolbarItemIdentifier = @"Update";
static NSString *PlugInsToolbarItemIdentifier = @"Plug-Ins";
static PreferencesController *_sharedWindowController = nil;
@implementation PreferencesController
// Created: 2 July 2010 22:45
+ (PreferencesController *) sharedWindowController
{
if (_sharedWindowController == NULL)
{
_sharedWindowController = [[self alloc] initWithWindowNibName: [self nibName]];
}
[_sharedWindowController window]; // load the nib
// Do any preperations here
[_sharedWindowController loadSettings];
[_sharedWindowController showWindow: NULL];
[[NSApplication sharedApplication] runModalForWindow: [_sharedWindowController window]];
// Need to also register when the window closes
return NULL;
}
// Created: 2 July 2010 22:45
+ (NSString *) nibName
{
return @"Preferences";
}
// Created: 2 July 2010 22:45
- (void) dealloc
{
// Unregister the NSWindowWillCloseNotification
[[NSNotificationCenter defaultCenter] removeObserver: self name: NSWindowWillCloseNotification object: [_sharedWindowController window]];
[super dealloc];
}
- (void) awakeFromNib
{
toolbar = [[[NSToolbar alloc] initWithIdentifier:@"preferences toolbar"] autorelease];
[toolbar setAllowsUserCustomization:NO];
[toolbar setAutosavesConfiguration:NO];
[toolbar setSizeMode:NSToolbarSizeModeDefault];
[toolbar setDisplayMode:NSToolbarDisplayModeIconAndLabel];
[toolbar setDelegate:self];
[toolbar setSelectedItemIdentifier:GeneralToolbarItemIdentifier];
[[self window] setToolbar:toolbar];
[[self window] setShowsToolbarButton:NO]; // Supported in Mac OS 10.4 and later
[self setActiveView:generalPreferenceView animate:NO];
[[self window] setTitle:NSLocalizedString(GeneralToolbarItemIdentifier, nil)];
[[self window] center];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(prefWindowClosed:)
name:NSWindowWillCloseNotification
object: [_sharedWindowController window]];
}
// =========================================================================
// (void) prefWindowClosed: (NSNotification *) aNotification
// -------------------------------------------------------------------------
//
// -------------------------------------------------------------------------
// Created: 16 July 2010
// Version: 1 January 2012 21:29
// =========================================================================
- (void) prefWindowClosed: (NSNotification *) aNotification
{
[[NSUserDefaults standardUserDefaults] synchronize]; // Force the defaults to update
[[NSApplication sharedApplication] stopModal];
[[NSApp delegate] preferencesClosed];
}
// =========================================================================
// (void) loadSettings
// -------------------------------------------------------------------------
// Load the settings from preferences.
// Some values (such as the checkboxes) are automatically set through bindings.
// -------------------------------------------------------------------------
// Created: 31 July 2010 15:35
// Version: 17 April 2011 19:44
// =========================================================================
- (void) loadSettings
{
id opticalErasingLevel = [[NSUserDefaults standardUserDefaults] objectForKey: @"OpticalDiscErasingLevel"];
id fileErasingLevel = [[NSUserDefaults standardUserDefaults] objectForKey: @"FileErasingLevel"];
id lastCheckedDate = [[NSUserDefaults standardUserDefaults] objectForKey: @"LastCheckedDate"];
// GENERAL -----
// Set the file and disc erasing level text
#ifdef MAC_APP_STORE
// For the MAS version, there is only the General Prefs pane, so hide the toolbar
[toolbar setVisible:NO];
#endif
NSArray *fileErasingTitles = [NSArray arrayWithObjects:NSLocalizedString(@"FileErasingSimple", nil), NSLocalizedString(@"FileErasingDoE", nil), NSLocalizedString(@"FileErasingMedium", nil), NSLocalizedString(@"FileErasingGutmann", nil), nil];
NSArray *discErasingTitles = [NSArray arrayWithObjects:NSLocalizedString(@"Quick", nil), NSLocalizedString(@"Complete", nil), nil];
[fileErasingButton removeAllItems];
[fileErasingButton addItemsWithTitles: fileErasingTitles];
[opticalDiscErasingButton removeAllItems];
[opticalDiscErasingButton addItemsWithTitles: discErasingTitles];
// Set file erasing level
if ((fileErasingLevel != nil) && ([fileErasingButton itemWithTitle: NSLocalizedString(fileErasingLevel, nil)] != nil))
{
[fileErasingButton selectItemWithTitle: NSLocalizedString(fileErasingLevel, nil)];
}
else
{ // Default setting is DoD 7x
[fileErasingButton selectItemWithTitle: NSLocalizedString(@"FileErasingMedium", nil)];
}
// Set CD/DVD erasing level
if ( (opticalErasingLevel != nil) && ([opticalDiscErasingButton itemWithTitle: NSLocalizedString(opticalErasingLevel, nil)] != nil) )
{
[opticalDiscErasingButton selectItemWithTitle: NSLocalizedString(opticalErasingLevel, nil)];
}
else
{
[opticalDiscErasingButton selectItemWithTitle: NSLocalizedString(@"Complete", nil)];
}
[fileErasingLabel setStringValue: NSLocalizedString(@"FileErasingLevel", nil)];
[discErasingLabel setStringValue: NSLocalizedString(@"CDDVDErasingLevel", nil)];
[warnBeforeErasingButton setTitle: NSLocalizedString(@"WarnBeforeErasing", nil)];
[playSoundsButton setTitle: NSLocalizedString(@"PlaySounds", nil)];
// UPDATE -----
[checkNowButton setTitle: NSLocalizedString(@"CheckNow", nil)];
[lastCheckedLabel setStringValue: NSLocalizedString(@"LastChecked", nil)];
// if lastCheckedDate is nil, set the lastCheckedTextField string to "Never"
if (lastCheckedDate != nil)
{
[lastCheckedTextField setStringValue: [self formatLocalizedDate: lastCheckedDate]];
}
else
{
[lastCheckedTextField setStringValue: NSLocalizedString(@"Never", nil)];
}
// PLUG-INS -----
// Mac OS 10.6+
if ([[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){10, 6, 0}] == YES)
{
pluginPath = [@"~/Library/Services/Erase.workflow" stringByExpandingTildeInPath];
}
else
{
pluginPath = @"";
}
if ([[NSFileManager defaultManager] fileExistsAtPath: pluginPath] == YES)
{
[pluginInstalledButton setState: NSOnState];
}
[pluginInstalledButton setTitle: NSLocalizedString(@"InstallContextualPlugIn", nil)];
if ([pluginPath isEqualToString: @""] == NO)
{
[pluginMsgField setStringValue: [NSString stringWithFormat: NSLocalizedString(@"PluginInstallMessage", nil), [pluginPath lastPathComponent], [self displayLocalizedPath: [pluginPath stringByDeletingLastPathComponent]] ]];
}
}
#pragma mark -
#pragma mark Toolbar methods
// Version: 15 January 2012 1:00
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar
{
#ifdef MAC_APP_STORE
return [NSArray arrayWithObjects:
GeneralToolbarItemIdentifier,
nil];
#else
return [NSArray arrayWithObjects:
GeneralToolbarItemIdentifier,
UpdateToolbarItemIdentifier,
PlugInsToolbarItemIdentifier,
nil];
#endif
}
// Version: 15 January 2012 1:00
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar
{
#ifdef MAC_APP_STORE
return [NSArray arrayWithObjects:
GeneralToolbarItemIdentifier,
nil];
#else
return [NSArray arrayWithObjects:
GeneralToolbarItemIdentifier,
UpdateToolbarItemIdentifier,
PlugInsToolbarItemIdentifier,
nil];
#endif
}
// Version: 15 January 2012 1:00
- (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar
{
#ifdef MAC_APP_STORE
return [NSArray arrayWithObjects:
GeneralToolbarItemIdentifier,
nil];
#else
return [NSArray arrayWithObjects:
GeneralToolbarItemIdentifier,
UpdateToolbarItemIdentifier,
PlugInsToolbarItemIdentifier,
nil];
#endif
}
- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)identifier willBeInsertedIntoToolbar:(BOOL)willBeInserted
{
NSToolbarItem *item = [[[NSToolbarItem alloc] initWithItemIdentifier:identifier] autorelease];
if ([identifier isEqualToString:GeneralToolbarItemIdentifier])
{
[item setLabel: NSLocalizedString(@"General", nil)];
[item setImage:[NSImage imageNamed:NSImageNamePreferencesGeneral]];
[item setTarget:self];
[item setAction:@selector(toggleActivePreferenceView:)];
}
else if ([identifier isEqualToString:UpdateToolbarItemIdentifier])
{
[item setLabel:NSLocalizedString(@"Update", nil)];
[item setImage:[NSImage imageNamed:@"software_update"]];
[item setTarget:self];
[item setAction:@selector(toggleActivePreferenceView:)];
}
else if ([identifier isEqualToString:PlugInsToolbarItemIdentifier])
{
[item setLabel:NSLocalizedString(@"Plug-Ins", nil)];
[item setImage:[NSImage imageNamed:@"plugin"]];
[item setTarget:self];
[item setAction:@selector(toggleActivePreferenceView:)];
}
else
{
item = nil;
}
return item;
}
// Version: 21 August 2007 21:24
- (void)togglePreferenceView:(NSString *)identifier
{
NSView *view;
if ([identifier isEqualToString:GeneralToolbarItemIdentifier])
view = generalPreferenceView;
else if ([identifier isEqualToString:UpdateToolbarItemIdentifier])
view = updatePreferenceView;
else if ([identifier isEqualToString:PlugInsToolbarItemIdentifier])
{
view = pluginsPreferenceView;
}
else // Otherwise, default to the General view
view = generalPreferenceView;
[self setActiveView:view animate:YES];
[[self window] setTitle:NSLocalizedString(identifier, nil)];
}
- (void)toggleActivePreferenceView:(id)sender
{
NSView *view;
if ([[sender itemIdentifier] isEqualToString:GeneralToolbarItemIdentifier])
view = generalPreferenceView;
else if ([[sender itemIdentifier] isEqualToString:UpdateToolbarItemIdentifier])
view = updatePreferenceView;
else if ([[sender itemIdentifier] isEqualToString:PlugInsToolbarItemIdentifier])
view = pluginsPreferenceView;
else // Otherwise, default to the General view
view = generalPreferenceView;
[self setActiveView:view animate:YES];
[[self window] setTitle: NSLocalizedString([sender itemIdentifier], nil)];
}
- (void)setActiveView:(NSView *)view animate:(BOOL)flag
{
// set the new frame and animate the change
NSRect windowFrame = [[self window] frame];
windowFrame.size.height = [view frame].size.height + WINDOW_TITLE_HEIGHT;
windowFrame.size.width = [view frame].size.width;
windowFrame.origin.y = NSMaxY([[self window] frame]) - ([view frame].size.height + WINDOW_TITLE_HEIGHT);
if ([[activeContentView subviews] count] != 0)
[[[activeContentView subviews] objectAtIndex:0] removeFromSuperview];
[[self window] setFrame:windowFrame display:YES animate:flag];
[activeContentView setFrame:[view frame]];
[activeContentView addSubview:view];
}
#pragma mark -
#pragma mark General
// =========================================================================
// (IBAction) fileErasingLevelSelected: (id) sender
// -------------------------------------------------------------------------
//
// -------------------------------------------------------------------------
// Created: 18 July 2010 20:40
// Version: 27 April 2011 22:34
// =========================================================================
- (IBAction) fileErasingLevelSelected: (id) sender
{
if ([[fileErasingButton titleOfSelectedItem] isEqualToString: NSLocalizedString(@"FileErasingSimple", nil)])
{
[[NSUserDefaults standardUserDefaults] setObject: @"Simple (1x)" forKey:@"FileErasingLevel"];
}
else if ([[fileErasingButton titleOfSelectedItem] isEqualToString: NSLocalizedString(@"FileErasingDoE", nil)])
{
[[NSUserDefaults standardUserDefaults] setObject: [fileErasingButton titleOfSelectedItem] forKey:@"FileErasingLevel"];
}
else if ([[fileErasingButton titleOfSelectedItem] isEqualToString: NSLocalizedString(@"FileErasingMedium", nil)])
{
[[NSUserDefaults standardUserDefaults] setObject: [fileErasingButton titleOfSelectedItem] forKey:@"FileErasingLevel"];
}
else if ([[fileErasingButton titleOfSelectedItem] isEqualToString: NSLocalizedString(@"FileErasingGutmann", nil)])
{
[[NSUserDefaults standardUserDefaults] setObject: [fileErasingButton titleOfSelectedItem] forKey:@"FileErasingLevel"];
}
}
// =========================================================================
// (IBAction) opticalDiscErasingLevelSelected: (id) sender
// -------------------------------------------------------------------------
//
// -------------------------------------------------------------------------
// Created: 18 July 2010 20:40
// Version: 9 March 2011 21:35
// =========================================================================
- (IBAction) opticalDiscErasingLevelSelected: (id) sender
{
if ([[opticalDiscErasingButton titleOfSelectedItem] isEqualToString: NSLocalizedString(@"Quick", nil)])
{
[[NSUserDefaults standardUserDefaults] setObject: @"Quick" forKey:@"OpticalDiscErasingLevel"];
}
else if ([[opticalDiscErasingButton titleOfSelectedItem] isEqualToString: NSLocalizedString(@"Complete", nil)])
{
[[NSUserDefaults standardUserDefaults] setObject: @"Complete" forKey:@"OpticalDiscErasingLevel"];
}
}
// =========================================================================
// (IBAction) warnBeforeErasingSelected: (id) sender
// -------------------------------------------------------------------------
//
// -------------------------------------------------------------------------
// Created: 18 July 2010 20:30
// Version: 18 July 2010 20:30
// =========================================================================
- (IBAction) warnBeforeErasingSelected: (id) sender
{
[[NSUserDefaults standardUserDefaults] setBool: [warnBeforeErasingButton state] forKey:@"WarnBeforeErasing"];
}
// =========================================================================
// (IBAction) playSoundsSelected: (id) sender
// -------------------------------------------------------------------------
//
// -------------------------------------------------------------------------
// Created: 18 July 2010 20:50
// Version: 18 July 2010 20:50
// =========================================================================
- (IBAction) playSoundsSelected: (id) sender
{
[[NSUserDefaults standardUserDefaults] setBool: [playSoundsButton state] forKey:@"BeepBeforeTerminating"];
}
#pragma mark -
#pragma mark Update
// =========================================================================
// (IBAction) checkForNewVersion: (id) sender
// -------------------------------------------------------------------------
// Added some new code to check if there is no network connection present.
// This resulted when the !%@# network went down at my house. I learned
// something, but I still want my internet! Screw MTV! I want the Internet!
// -------------------------------------------------------------------------
// Created: 7. February 2004 19:25
// Version: 12 April 2018 21:34
// =========================================================================
- (IBAction) checkForNewVersion: (id) sender
{
NSString *currentVersionNumber = [[[NSBundle bundleForClass:[self class]] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
NSDictionary *productVersionDict = [NSDictionary dictionaryWithContentsOfURL: [NSURL URLWithString:@"http://www.edenwaith.com/xml/version.xml"]];
NSDictionary *peDictionary = [productVersionDict objectForKey:@"PermanentEraser"];
NSString *latestVersionNumber = [peDictionary valueForKey:@"version"];
NSString *minimumSystemVersion = [peDictionary valueForKey:@"minimumsystemversion"];
int button = 0;
NSInteger major = 0;
NSInteger minor = 0;
NSInteger patch = 0;
NSDate *theDate = [NSDate date];
[lastCheckedTextField setStringValue: [self formatLocalizedDate: theDate]];
// Need save the date here in preferences...
[[NSUserDefaults standardUserDefaults] setObject: theDate forKey: @"LastCheckedDate"];
[[NSUserDefaults standardUserDefaults] synchronize];
if (minimumSystemVersion != nil)
{ // Parse out the minimum OS version required for the upgrade.
NSArray *parts = [minimumSystemVersion componentsSeparatedByString:@"."];
major = [parts count] > 0 ? [[parts objectAtIndex:0] integerValue] : 0;
minor = [parts count] > 1 ? [[parts objectAtIndex:1] integerValue] : 0;
patch = [parts count] > 2 ? [[parts objectAtIndex:2] integerValue] : 0;
}
if ( latestVersionNumber == nil )
{
NSBeep();
NSRunAlertPanel(NSLocalizedString(@"UpdateFailure", nil),
NSLocalizedString(@"UpdateFailureMsg", nil), NSLocalizedString(@"OK", nil), nil, nil);
}
else if ( [latestVersionNumber isEqualTo: currentVersionNumber] )
{
NSRunAlertPanel(NSLocalizedString(@"SoftwareUpToDate", nil),
NSLocalizedString(@"RecentVersionMsg", nil), NSLocalizedString(@"OK", nil), nil, nil);
}
else
{ // If the current OS meets the minimum system requirement
if ([[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){major, minor, patch}] == YES)
{
// Ensure that the new version is ahead of the current version
if ([self isLatestVersion:latestVersionNumber newerThanCurrentVersion:currentVersionNumber] == YES)
{
button = NSRunAlertPanel(NSLocalizedString(@"NewVersionAvailable", nil),
NSLocalizedString(@"NewVersionAvailableMsg", nil), NSLocalizedString(@"Download", nil), NSLocalizedString(@"Cancel", nil), NSLocalizedString(@"MoreInfo", nil), latestVersionNumber);
if (NSOKButton == button)
{
[[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString:@"http://www.edenwaith.com/downloads/permanent%20eraser.php"]];
}
else if (NSAlertOtherReturn == button) // More Info
{
[[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString:@"http://www.edenwaith.com/products/permanent%20eraser/"]];
}
}
else
{
// This is an edge case for future builds that might be ahead of the release build and not
// falsely assume their is a newer version available
NSRunAlertPanel(NSLocalizedString(@"SoftwareUpToDate", nil),
NSLocalizedString(@"RecentVersionMsg", nil), NSLocalizedString(@"OK", nil), nil, nil);
}
}
else
{ // If the current OS is too old to run the latest version, alert the user that they are on the
// most up-to-date version for their system.
NSRunAlertPanel(NSLocalizedString(@"SoftwareUpToDate", nil),
NSLocalizedString(@"RecentVersionMsg", nil), NSLocalizedString(@"OK", nil), nil, nil);
}
}
}
// =========================================================================
// (BOOL) isLatestVersion: (NSString *)latestVersion newerThanCurrentVersion: (NSString *)currentVersion
// -------------------------------------------------------------------------
// Compare if the latest version of the app is newer than the current version
// -------------------------------------------------------------------------
// Created: 30 May 2020
// Version: 30 May 2020
// =========================================================================
- (BOOL) isLatestVersion: (NSString *)latestVersion newerThanCurrentVersion: (NSString *)currentVersion
{
NSInteger latestVersionMajor = 0;
NSInteger latestVersionMinor = 0;
NSInteger latestVersionPatch = 0;
NSInteger currentVersionMajor = 0;
NSInteger currentVersionMinor = 0;
NSInteger currentVersionPatch = 0;
if (latestVersion != nil)
{
NSArray *parts = [latestVersion componentsSeparatedByString:@"."];
latestVersionMajor = [parts count] > 0 ? [[parts objectAtIndex:0] integerValue] : 0;
latestVersionMinor = [parts count] > 1 ? [[parts objectAtIndex:1] integerValue] : 0;
latestVersionPatch = [parts count] > 2 ? [[parts objectAtIndex:2] integerValue] : 0;
}
if (currentVersion != nil)
{
NSArray *parts = [currentVersion componentsSeparatedByString:@"."];
currentVersionMajor = [parts count] > 0 ? [[parts objectAtIndex:0] integerValue] : 0;
currentVersionMinor = [parts count] > 1 ? [[parts objectAtIndex:1] integerValue] : 0;
currentVersionPatch = [parts count] > 2 ? [[parts objectAtIndex:2] integerValue] : 0;
}
if (latestVersionMajor == currentVersionMajor)
{
if (latestVersionMinor == currentVersionMinor)
{
return latestVersionPatch >= currentVersionPatch;
}
return latestVersionMinor >= currentVersionMinor;
}
return latestVersionMajor >= currentVersionMajor;
}
// =========================================================================
// (NSString *) formatLocalizedDate: (NSDate *) theDate
// -------------------------------------------------------------------------
// Format the date using the long style (instead of full), which will format
// using the appropriate locale.
// -------------------------------------------------------------------------
// Created: 12 March 2011 20:52
// Version: 7 December 2017 19:45
// =========================================================================
- (NSString *) formatLocalizedDate: (NSDate *) theDate
{
[NSDateFormatter setDefaultFormatterBehavior:NSDateFormatterBehavior10_4];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterLongStyle];
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
NSString *formattedDateString = [dateFormatter stringFromDate:theDate];
// NSLog(@"Formatted date string for locale %@: %@", [[dateFormatter locale] localeIdentifier], formattedDateString);
return (formattedDateString);
}
#pragma mark -
#pragma mark Plug-Ins
// =========================================================================
// (IBAction) installPluginSelected: (id) sender
// -------------------------------------------------------------------------
//
// -------------------------------------------------------------------------
// Created: 31 July 2010 16:23
// Version: 16 September 2012 16:51
// =========================================================================
- (IBAction) installPluginSelected: (id) sender
{
NSFileManager *fm = [NSFileManager defaultManager];
if ([sender state] == NSOnState) // Selected, install plug-in
{
// Copy plugin to the appropriate location
// Mac OS 10.6+
if ([[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){10, 6, 0}] == YES)
{
NSString *pluginSourcePath = [[[NSBundle mainBundle] builtInPlugInsPath] stringByAppendingPathComponent: @"Erase.workflow"];
if ([fm fileExistsAtPath: pluginSourcePath] == YES)
{
NSError *err = nil;
// If the ~/Library/Services folder does not exist, create it first
if ([fm createDirectoryAtPath:[pluginPath stringByDeletingLastPathComponent] withIntermediateDirectories: YES attributes: nil error: &err] == NO)
{
NSLog(@"Error: Failed to create directory %@ (%@)", [pluginPath stringByDeletingLastPathComponent], [err localizedDescription]);
}
if ([fm copyItemAtPath: pluginSourcePath toPath: pluginPath error: &err] == NO)
{
NSLog(@"Error: Failed to copy plug-in to %@ pluginPath (%@)", pluginPath, [err localizedDescription]);
}
}
}
}
else // Remove plug-in
{
if ([fm fileExistsAtPath: pluginPath] == YES)
{
NSError *err = nil;
if ([fm removeItemAtPath: pluginPath error: &err] == NO)
{
NSLog(@"Error: Failed to delete file %@ (%@)", pluginPath, [err localizedDescription]);
}
}
}
// For the Contextual Menu Item plug-in, restart the Finder
if ([[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){10, 6, 0}] == NO)
{
[self removeOldPlugin];
[[NSTask launchedTaskWithLaunchPath:@"/usr/bin/killall" arguments:[NSArray arrayWithObject:@"Finder"]] waitUntilExit];
}
}
// =========================================================================
// (void) removeOldPlugin
// -------------------------------------------------------------------------
// For Leopard, remove the old workflow which is no longer used due to the
// new EraseCMI.plugin.
// -------------------------------------------------------------------------
// Created: 12 December 2015 21:30
// Version: 12 December 2015 21:30
// =========================================================================
- (void) removeOldPlugin
{
NSString *oldPluginPath = [@"~/Library/Workflows/Applications/Finder/Permanent Eraser.workflow" stringByExpandingTildeInPath];
if ([[NSFileManager defaultManager] fileExistsAtPath: oldPluginPath] == YES)
{
NSError *err = nil;
if ([[NSFileManager defaultManager] removeItemAtPath: oldPluginPath error: &err] == NO)
{
NSLog(@"Error: Failed to delete file %@ (%@)", oldPluginPath, [err localizedDescription]);
}
}
}
// =========================================================================
// (NSString *) displayLocalizedPath: (NSString *) path
// -------------------------------------------------------------------------
// Parse through a path and display the localized name for each folder.
// -------------------------------------------------------------------------
// Created: 9 July 2011 19:58
// Version: 9 July 2011 21:25
// =========================================================================
- (NSString *) displayLocalizedPath: (NSString *) path
{
if ([path isEqualToString:@"/"] == YES)
{
return (@"");
}
else
{
return ([NSString stringWithFormat: @"%@/%@", [self displayLocalizedPath:[path stringByDeletingLastPathComponent]], [[NSFileManager defaultManager] displayNameAtPath: path]]);
}
}
// =========================================================================
// (IBAction) openHelpPage: (id) sender
// -------------------------------------------------------------------------
//
// -------------------------------------------------------------------------
// Created: 14 November 2010 12:00
// Version: 14 November 2010 12:00
// =========================================================================
- (IBAction) openHelpPage: (id) sender
{
NSString *anchorName = NULL;
NSString *helpBookName = [[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleHelpBookFolder"];
if ([sender tag] == 2)
{
anchorName = @"prefs-plugins-help";
}
if (anchorName != NULL)
{
[[NSHelpManager sharedHelpManager] openHelpAnchor: anchorName inBook: helpBookName];
}
else
{
[[NSApplication sharedApplication] showHelp: self];
}
}
@end