-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFDController.m
4027 lines (3478 loc) · 143 KB
/
FDController.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
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
/*
File: FDController.m
Written by: eK
Implementation of FDController class
Copyright (C) 2004-2008 Eddie Kelley <[email protected]>
This file is part of FreeDMG
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#import "FDController.h"
@implementation FDController
-(id) init
{
self = [super init];
progressStrings = [[NSArray alloc] initWithObjects:
@"Calculating image size...",
@"Creating image:",
@"Device path",
@"Creating filesystem:",
@"Creating mount point:",
@"Mounting device:",
@"Copying files to image...",
@"Un-mounting device:",
@"Ejecting device:",
@"Converting image:",
@"Imaging was successful",
@"Preparing imaging engine...",
@"Reading Apple_HFS",
@"Terminating imaging engine...",
@"Adding resources...",
@"Initializing...",
@"Imaging...",
@"Verifying...",
@"Checksumming",
@"Verification completed...",
@"Attaching...",
@"Finishing...",
@"created:",
nil];
// supported SLA languages
languages = [[NSArray alloc] initWithObjects:
@"German",
@"English",
@"Spanish",
@"French",
@"Italian",
@"Japanese",
@"Dutch",
@"Swedish",
@"Brazilian Portugese",
@"Simplified Chinese",
@"Traditional Chinese",
@"Danish",
@"Finnish",
@"French Canadian",
@"Korean",
@"Norwegian",
nil];
return self;
}
-(void) dealloc
{
[progressStrings release];
[languages release];
[volumes release];
[devices release];
[super dealloc];
}
-(void)awakeFromNib{
// Make sure both mkdmg and hdiutil exist, otherwise, exit
if(![[NSBundle mainBundle] pathForResource:@"mkdmg" ofType:nil]){
NSRunAlertPanel(@"FreeDMG", NSLocalizedString(@"mkdmg_Warning", @"mkdmg not found. Re-install FreeDMG."), NSLocalizedString(@"OK", @"OK"), @"", @"");
[NSApp terminate:self];
}
else if(![[NSFileManager defaultManager] fileExistsAtPath:@"/usr/bin/hdiutil"]){
NSRunAlertPanel(@"FreeDMG", NSLocalizedString(@"hdiutil_Warning", @"hdiutil not found. Re-install Mac OS X."), NSLocalizedString(@"OK", @"OK"), @"", @"");
[NSApp terminate:self];
}
// set verbose, and factory defaults before trying to read preferences (in case a preference is not set).
freeDMGRunning = NO;
verbose = YES;
internetEnabled = NO;
compression = [NSString stringWithString:@"UDZO"];
compressionLevel = [NSNumber numberWithInt:9];
convertFormat = [NSString stringWithString:@"UDZO"];
prompt = YES;
encryption = NO;
overwrite = NO;
quit = YES;
doQuit = NO;
hasQuit = YES;
volumeFormat = @"HFS+";
imageDropAction = [NSNumber numberWithInt:0];
limitSegmentSize = FALSE;
limitSegmentSizeByte = @"MB";
segmentSize = [NSNumber numberWithDouble:1];
burnRunning = FALSE;
gotMedia = FALSE;
FDToolbarNewItemIdentifier = @"FDNewImage";
FDToolbarConvertItemIdentifier = @"FDConvertImage";
FDToolbarResizeItemIdentifier = @"FDResizeImage";
FDToolbarVerifyItemIdentifier = @"FDVerifyImage";
FDToolbarMountItemIdentifier = @"FDMountImage";
FDToolbarInspectItemIdentifier = @"FDInspectImage";
FDToolbarEjectItemIdentifier = @"FDEjectImage";
FDToolbarLogItemIdentifier = @"FDShowHideLog";
FDToolbarInternetItemIdentifier = @"FDInternetImage";
FDToolbarBurnItemIdentifier = @"FDBurnImage";
FDToolbarSLAItemIdentifier = @"FDSLAImage";
// create instance of standard user defaults
defaults = [NSUserDefaults standardUserDefaults];
// update preferences panel
[self updatePreferencesPanel];
[volumesMenu setDelegate:self];
[volumesMenu setAutoenablesItems:TRUE];
[volumesMenu setTitle:NSLocalizedString(@"Create_Volume", @"Create from Volume")];
[volumesMenuItem setSubmenu:volumesMenu];
// setup toolbar
mainToolbar = [[[NSToolbar alloc] initWithIdentifier:@"FreeDMGToolbar"] autorelease];
[mainToolbar setDelegate:self];
[FreeDMGWindow setToolbar:mainToolbar];
[mainToolbar setConfigurationFromDictionary:[defaults objectForKey:@"NSToolbar Configuration FreeDMGToolbar"]];
[mainToolbar setAutosavesConfiguration:TRUE];
[mainToolbar setAllowsUserCustomization:TRUE];
// create folder to store SLA in during license attachment process
system([[@"mkdir -p " stringByAppendingString:[NSHomeDirectory() stringByAppendingString:@"/Library/Preferences/FreeDMG/SLAs"]] UTF8String]);
[SLATextView setRichText:TRUE];
volumes = [[NSArray alloc] initWithArray:[self volumes]];
// disabled devices menu due to crashing in 10.6
//devices = [[NSArray alloc] initWithArray:[self devices]];
}
// callback happens before the application finished launching.
- (void)applicationWillFinishLaunching:(NSNotification *)aNotification
{
if(quit){
doQuit = YES;
hasQuit = NO;
}
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
if(!hasQuit)
doQuit = NO;
}
// callback by other applications (Finder) telling us to openFiles:file
- (BOOL)application:(NSApplication *)sender openFile:(NSString *)filename
{
if(quit && doQuit){
hasQuit = YES;
} else{
hasQuit = NO;
doQuit = NO;
}
if(![freeDMGTask isRunning]){
return [self createImageWithFiles:[NSArray arrayWithObjects:filename, nil]];
}else
return FALSE;
}
// callback by other applications (Finder) telling us to openFiles:files
- (BOOL)application:(NSApplication *)sender openFiles:(NSArray *)files
{
if(quit && doQuit)
hasQuit = YES;
else{
hasQuit = NO;
doQuit = NO;
}
if(![freeDMGTask isRunning])
return [self createImageWithFiles:files];
else
return FALSE;
}
// If the user attempts to close the window,
-(BOOL)windowShouldClose:(id)sender
{
// quit when idle
if(![freeDMGTask isRunning]){
[NSApp terminate:self];
return YES;
}
else
{
int choice = NSAlertDefaultReturn;
NSString *title = [NSString stringWithString:NSLocalizedString(@"Quit_Confirmation", @"FreeDMG is currently imaging. Are you sure that you want to quit?")];
choice = NSRunAlertPanel(title, NSLocalizedString(@"Quit_Warning", @"Quitting now can result in an incomplete image"),NSLocalizedString(@"Cancel", @"Cancel"), NSLocalizedString(@"Quit", @"Quit"), @"");
if (choice == NSAlertDefaultReturn) {
/* Cancel termination */
return NO;
}
else
{
[freeDMGTask stopProcess];
[NSApp terminate:self];
return YES;
}
}
}
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)app {
// Determine if task is running...
if ([freeDMGTask isRunning]) {
int choice = NSAlertDefaultReturn;
NSString *title = [NSString stringWithString:NSLocalizedString(@"Quit_Confirmation", @"FreeDMG is currently imaging. Are you sure that you want to quit?")];
choice = NSRunAlertPanel(title, NSLocalizedString(@"Quit_Warning", @"Quitting now can result in an incomplete image"),NSLocalizedString(@"Cancel", @"Cancel"), NSLocalizedString(@"Quit", @"Quit"), @"");
if (choice == NSAlertDefaultReturn) {
/* Cancel termination */
return NSTerminateCancel;
}
else
{
[freeDMGTask stopProcess];
}
}
return NSTerminateNow;
}
// delegate method for save panels (verifies name in regards to
//- (NSString *)panel:(id)sender userEnteredFilename:(NSString *)filename confirmed:(BOOL)okFlag
//{
// return filename;
//}
#pragma mark Accessors
- (id) objectForKey:(NSString *)key
{
if([defaults objectForKey:key] != nil)
return [defaults objectForKey:key];
else
{
return nil;
}
}
- (void) setValue:(id)newValue forKey:(NSString *)key
{
NSLog(@"Setting value:%@ for key:%@", newValue, key);
if([defaults objectForKey:key] != nil){
NSMutableDictionary *tempDict = [NSMutableDictionary dictionaryWithCapacity:1];
[tempDict addEntriesFromDictionary:[defaults objectForKey:@"hybridTypes"]];
[tempDict setObject:newValue forKey:key];
[defaults setObject:tempDict forKey:@"hybridTypes"];
[defaults synchronize];
NSLog(@"Finished setting value:%@ for key:%@", [defaults objectForKey:key], key);
}
}
- (NSMutableArray *) hybridTypes
{
if([defaults objectForKey:@"hybridTypes"] != nil)
return [defaults objectForKey:@"hybridTypes"];
else
{
return [NSMutableArray arrayWithCapacity:1];
}
}
- (void) setHybridTypes:(NSMutableArray *)hybridTypes
{
[defaults setObject:hybridTypes forKey:@"hybridTypes"];
}
// return the useable (as determined by diskutil -list) device attached (eg. /dev/disk0, /dev/disk1, etc.)
-(NSArray *) devices
{
// diskutil is pretty slow, but offers structured (plist) output
// NSDictionary *deviceDict = [[NSDictionary alloc] initWithDictionary:[[self openProgram:@"/usr/sbin/diskutil" withArguments:[NSArray arrayWithObjects:@"list", @"-plist", nil]] propertyList]];
// NSLog([[deviceDict objectForKey:@"AllDisks"] description]);
// return [[deviceDict objectForKey:@"AllDisks"] autorelease];
// Note: disktool is faster, but doesn't offer xml output
// Apple does not recommend using disktool in the man page?
//NSMutableString *deviceString = [[NSMutableString alloc] initWithString:[self openProgram:@"/usr/sbin/disktool" withArguments:[NSArray arrayWithObjects:@"-l", nil]]];
// [deviceString replaceOccurrencesOfString:@"***Disk Appeared ('" withString:@"" options:nil range:NSMakeRange(0, [deviceString length])];
// [deviceString replaceCharactersInRange: NSUnionRange([deviceString rangeOfString:@"',Mountpoint = '"], [deviceString rangeOfString:@"')\n"]) withString:@"\n"];
//
// return [deviceString componentsSeparatedByString:@"\n"];
// Note: disktool is faster, but doesn't offer xml output
// Apple does not recommend using disktool in the man page?
// To get acceptable speed, we're using disktool (sorry Apple)
// This allows for imaging on launch (which doesn't happen with sluggish diskutil)
NSMutableString *deviceString = [[NSMutableString alloc] initWithString:@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict><key>devices</key><array>\n"];
[deviceString appendString:[self openProgram:@"/usr/sbin/disktool" withArguments:[NSArray arrayWithObjects:@"-l", nil]]];
NSRange devStringRange = NSMakeRange(0, [deviceString length]);
[deviceString replaceOccurrencesOfString:@"***Disk Appeared ('" withString:@"<dict>\n<key>disk</key>\n<string>" options:nil range:devStringRange];
[deviceString replaceOccurrencesOfString:@"',Mountpoint = '" withString:@"</string>\n<key>mountpoint</key>\n<string>" options:nil range:devStringRange];
[deviceString replaceOccurrencesOfString:@"', fsType = '" withString:@"</string>\n<key>fstype</key>\n<string>" options:nil range:devStringRange];
[deviceString replaceOccurrencesOfString:@"', volName = '" withString:@"</string>\n<key>volname</key>\n<string>" options:nil range:devStringRange];
[deviceString replaceOccurrencesOfString:@"')" withString:@"</string>\n</dict>\n" options:nil range:devStringRange];
[deviceString replaceOccurrencesOfString:@"\n\n" withString:@"" options:nil range:devStringRange];
[deviceString appendString:@"</array></dict></plist>"];
//NSLog(deviceString);
NSDictionary *deviceDict = [[NSMutableDictionary alloc] initWithDictionary:[deviceString propertyList]];
//NSLog([deviceDict description]);
NSMutableArray *deviceArray = [[NSMutableArray alloc] initWithCapacity:1];
int i;
for(i = 0;i < [[deviceDict objectForKey:@"devices"] count]; ++i){
if(![[[[deviceDict objectForKey:@"devices"] objectAtIndex:i] objectForKey:@"fstype"] isEqual:@"afpfs"])
[deviceArray addObject:[[[deviceDict objectForKey:@"devices"] objectAtIndex:i] objectForKey:@"disk"]];
}
//NSLog([devices description]);
[deviceDict release];
[deviceString release];
return [deviceArray autorelease];
}
-(NSDictionary *) deviceDict
{
// diskutil is pretty slow, but offers structured (plist) output
// NSDictionary *deviceDict = [[NSDictionary alloc] initWithDictionary:[[self openProgram:@"/usr/sbin/diskutil" withArguments:[NSArray arrayWithObjects:@"list", @"-plist", nil]] propertyList]];
// NSLog([[deviceDict objectForKey:@"AllDisks"] description]);
// return [[deviceDict objectForKey:@"AllDisks"] autorelease];
// Note: disktool is faster, but doesn't offer xml output
// Apple does not recommend using disktool in the man page?
//NSMutableString *deviceString = [[NSMutableString alloc] initWithString:[self openProgram:@"/usr/sbin/disktool" withArguments:[NSArray arrayWithObjects:@"-l", nil]]];
// [deviceString replaceOccurrencesOfString:@"***Disk Appeared ('" withString:@"" options:nil range:NSMakeRange(0, [deviceString length])];
// [deviceString replaceCharactersInRange: NSUnionRange([deviceString rangeOfString:@"',Mountpoint = '"], [deviceString rangeOfString:@"')\n"]) withString:@"\n"];
//
// return [deviceString componentsSeparatedByString:@"\n"];
// Note: disktool is faster, but doesn't offer xml output
// Apple does not recommend using disktool in the man page?
// To get acceptable speed, we're using disktool (sorry Apple)
// This allows for imaging on launch (which doesn't happen with sluggish diskutil)
NSMutableString *deviceString = [[NSMutableString alloc] initWithString:@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n<dict><key>devices</key><array>\n"];
[deviceString appendString:[self openProgram:@"/usr/sbin/disktool" withArguments:[NSArray arrayWithObjects:@"-l", nil]]];
NSRange devStringRange = NSMakeRange(0, [deviceString length]);
[deviceString replaceOccurrencesOfString:@"***Disk Appeared ('" withString:@"<dict>\n<key>disk</key>\n<string>" options:nil range:devStringRange];
[deviceString replaceOccurrencesOfString:@"',Mountpoint = '" withString:@"</string>\n<key>mountpoint</key>\n<string>" options:nil range:devStringRange];
[deviceString replaceOccurrencesOfString:@"', fsType = '" withString:@"</string>\n<key>fstype</key>\n<string>" options:nil range:devStringRange];
[deviceString replaceOccurrencesOfString:@"', volName = '" withString:@"</string>\n<key>volname</key>\n<string>" options:nil range:devStringRange];
[deviceString replaceOccurrencesOfString:@"')" withString:@"</string>\n</dict>\n" options:nil range:devStringRange];
[deviceString replaceOccurrencesOfString:@"\n\n" withString:@"" options:nil range:devStringRange];
[deviceString appendString:@"</array></dict></plist>"];
//NSLog(deviceString);
NSDictionary *deviceDict = [[NSMutableDictionary alloc] initWithDictionary:[deviceString propertyList]];
//NSLog([deviceDict description]);
//NSMutableArray *deviceArray = [[NSMutableArray alloc] initWithCapacity:1];
//
// int i;
// for(i = 0;i < [[deviceDict objectForKey:@"devices"] count]; ++i){
// if(![[[[deviceDict objectForKey:@"devices"] objectAtIndex:i] objectForKey:@"fstype"] isEqual:@"afpfs"])
// [deviceArray addObject:[[[deviceDict objectForKey:@"devices"] objectAtIndex:i] objectForKey:@"disk"]];
// }
// //NSLog([devices description]);
// [deviceDict release];
// [deviceString release];
return [deviceDict autorelease];
}
- (NSArray *) volumes
{
// Clean, but slow
// NSDictionary *deviceDict = [[NSDictionary alloc] initWithDictionary:[[self openProgram:@"/usr/sbin/diskutil" withArguments:[NSArray arrayWithObjects:@"list", @"-plist", nil]] propertyList]];
// NSLog([[deviceDict objectForKey:@"VolumesFromDisks"] description]);
// return [[deviceDict objectForKey:@"VolumesFromDisks"] autorelease];
// Alternately, just get the list of files (excluding .DS_Store)
// at the default /Volumes directory from FileManager
NSMutableArray *volumesArray = [NSMutableArray arrayWithCapacity:1];
NSFileManager *fileManager = [NSFileManager defaultManager];
// get a list of items in the /Volumes directory
[volumesArray addObjectsFromArray:[fileManager directoryContentsAtPath:@"/Volumes"]];
// remove .DS_Store from list of options
if([volumesArray containsObject:@".DS_Store"])
[volumesArray removeObject:@".DS_Store"];
return volumesArray;
}
- (NSString *) compression
{
if([defaults objectForKey:@"compression"] != nil)
compression = [NSString stringWithString:[defaults objectForKey:@"compression"]];
else{
compression = @"UDZO";
[defaults setObject:compression forKey:@"compression"];
}
return compression;
}
- (void) setCompression:(NSString*)newCompression
{
compression = [NSString stringWithString:newCompression];
[defaults setObject:compression forKey:@"compression"];
}
- (NSNumber *) compressionLevel
{
return [defaults objectForKey:@"compressionLevel"];
}
- (void) setCompressionLevel:(NSNumber*)newCompressionLevel
{
compressionLevel = newCompressionLevel;
[defaults setObject:compressionLevel forKey:@"compressionLevel"];
}
- (NSString *) convertFormat
{
if([defaults objectForKey:@"convertFormat"] != nil){
convertFormat = [NSString stringWithString:[defaults objectForKey:@"convertFormat"]];
}
else{
convertFormat = @"UDZO";
[defaults setObject:convertFormat forKey:@"convertFormat"];
}
return convertFormat;
}
- (void) setConvertFormat:(NSString*)newFormat
{
convertFormat = [NSString stringWithString:newFormat];
[defaults setObject:convertFormat forKey:@"convertFormat"];
[sPanel setRequiredFileType:[self convertFormat]];
}
- (NSString *) encryptionType
{
return [defaults objectForKey:@"encryptionType"];
}
- (void) setEncryptionType:(NSString*)newType
{
encryptionType = [NSString stringWithString:newType];
[defaults setObject:newType forKey:@"encryptionType"];
}
- (NSString *) pathExtension
{
NSString * pathExtension, *compressionFormat = [NSString stringWithString:[self compression]];
if(([compressionFormat isEqualToString:@"UDRW"] == TRUE) ||
([compressionFormat isEqualToString:@"UDRO"] == TRUE) ||
([compressionFormat isEqualToString:@"UDCO"] == TRUE) ||
([compressionFormat isEqualToString:@"UDZO"] == TRUE) ||
([compressionFormat isEqualToString:@"UFBI"] == TRUE) ||
([compressionFormat isEqualToString:@"UDxx"] == TRUE))
{
pathExtension = [NSString stringWithString:@"dmg"];
}
else if([compressionFormat isEqualToString:@"UDTO"] == TRUE)
{
pathExtension = [NSString stringWithString:@"cdr"];
}
else if([compressionFormat isEqualToString:@"UDSP"] == TRUE)
{
pathExtension = [NSString stringWithString:@"sparseimage"];
}
else if([compressionFormat isEqualToString:@"UDSB"] == TRUE)
{
pathExtension = [NSString stringWithString:@"sparsebundle"];
}
else if(([compressionFormat isEqualToString:@"RdWr"] == TRUE) ||
([compressionFormat isEqualToString:@"Rdxx"] == TRUE) ||
([compressionFormat isEqualToString:@"ROCo"] == TRUE) ||
([compressionFormat isEqualToString:@"DC42"] == TRUE)){
pathExtension = [NSString stringWithString:@"img"];
}
else
pathExtension = [NSString stringWithString:@"dmg"];
return pathExtension;
}
- (NSString *) convertPathExtension
{
NSString * pathExtension, *fmt = [NSString stringWithString:[self convertFormat]];
if(([fmt isEqualToString:@"UDRW"] == TRUE) ||
([fmt isEqualToString:@"UDRO"] == TRUE) ||
([fmt isEqualToString:@"UDCO"] == TRUE) ||
([fmt isEqualToString:@"UDZO"] == TRUE) ||
([fmt isEqualToString:@"UFBI"] == TRUE) ||
([fmt isEqualToString:@"UDxx"] == TRUE))
{
pathExtension = [NSString stringWithString:@"dmg"];
}
else if([convertFormat isEqualToString:@"UDTO"] == TRUE)
{
pathExtension = [NSString stringWithString:@"cdr"];
}
else if([fmt isEqualToString:@"UDSP"] == TRUE)
{
pathExtension = [NSString stringWithString:@"sparseimage"];
}
else if([fmt isEqualToString:@"UDSB"] == TRUE)
{
pathExtension = [NSString stringWithString:@"sparsebundle"];
}
else if(([fmt isEqualToString:@"RdWr"] == TRUE) ||
([fmt isEqualToString:@"Rdxx"] == TRUE) ||
([fmt isEqualToString:@"ROCo"] == TRUE) ||
([fmt isEqualToString:@"DC42"] == TRUE)){
pathExtension = [NSString stringWithString:@"img"];
}
else
pathExtension = [NSString stringWithString:@"dmg"];
return pathExtension;
}
#pragma mark Delegate Methods
- (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *) toolbar {
return [NSArray arrayWithObjects:
// FreeDMG toolbar items
FDToolbarLogItemIdentifier,
FDToolbarNewItemIdentifier,
FDToolbarConvertItemIdentifier,
FDToolbarResizeItemIdentifier,
FDToolbarInternetItemIdentifier,
FDToolbarVerifyItemIdentifier,
FDToolbarInspectItemIdentifier,
FDToolbarMountItemIdentifier,
FDToolbarBurnItemIdentifier,
FDToolbarSLAItemIdentifier,
// Apple provided toolbar items
//NSToolbarPrintItemIdentifier,
// NSToolbarShowColorsItemIdentifier,
// NSToolbarShowFontsItemIdentifier,
NSToolbarCustomizeToolbarItemIdentifier,
NSToolbarFlexibleSpaceItemIdentifier,
NSToolbarSpaceItemIdentifier,
NSToolbarSeparatorItemIdentifier, nil];
}
- (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *) toolbar {
return [NSArray arrayWithObjects:
FDToolbarNewItemIdentifier,
FDToolbarConvertItemIdentifier,
FDToolbarInternetItemIdentifier,
FDToolbarVerifyItemIdentifier,
NSToolbarSeparatorItemIdentifier,
FDToolbarLogItemIdentifier, nil];
}
- (NSToolbarItem *) toolbar:(NSToolbar *)toolbar
itemForItemIdentifier:(NSString *)itemIdentifier
willBeInsertedIntoToolbar:(BOOL)flag
{
NSToolbarItem *toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdentifier] autorelease];
if ([itemIdentifier isEqual: FDToolbarNewItemIdentifier]) {
// Set the text label to be displayed in the
// toolbar and customization palette
[toolbarItem setLabel:NSLocalizedString(@"Toolbar_New", @"New Image")];
[toolbarItem setPaletteLabel:NSLocalizedString(@"Toolbar_New", @"New Image")];
// Set up a reasonable tooltip, and image
// you will likely want to localize many of the item's properties
[toolbarItem setToolTip:NSLocalizedString(@"Toolbar_New_Tip", @"Create a disk image")];
[toolbarItem setImage:[NSImage imageNamed:@"toolbar_new.png"]];
// Tell the item what message to send when it is clicked
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(createBlankImage:)];
}
else if ([itemIdentifier isEqual: FDToolbarVerifyItemIdentifier]) {
// Set the text label to be displayed in the
// toolbar and customization palette
[toolbarItem setLabel:NSLocalizedString(@"Toolbar_Verify", @"Verify Image")];
[toolbarItem setPaletteLabel:NSLocalizedString(@"Toolbar_Verify", @"Verify Image")];
// Set up a reasonable tooltip, and image
// you will likely want to localize many of the item's properties
[toolbarItem setToolTip:NSLocalizedString(@"Toolbar_Verify_Tip", @"Verify a disk image")];
[toolbarItem setImage:[NSImage imageNamed:@"toolbar_verify.png"]];
// Tell the item what message to send when it is clicked
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(verifyImage:)];
}
else if ([itemIdentifier isEqual: FDToolbarResizeItemIdentifier]) {
// Set the text label to be displayed in the
// toolbar and customization palette
[toolbarItem setLabel:NSLocalizedString(@"Toolbar_Resize", @"Resize")];
[toolbarItem setPaletteLabel:NSLocalizedString(@"Toolbar_Resize", @"Resize Image")];
// Set up a reasonable tooltip, and image
// you will likely want to localize many of the item's properties
[toolbarItem setToolTip:NSLocalizedString(@"Toolbar_Resize_Tip", @"Resize a disk image")];
[toolbarItem setImage:[NSImage imageNamed:@"toolbar_resize.png"]];
// Tell the item what message to send when it is clicked
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(resizeImage:)];
}
else if ([itemIdentifier isEqual: FDToolbarInternetItemIdentifier]) {
// Set the text label to be displayed in the
// toolbar and customization palette
[toolbarItem setLabel:NSLocalizedString(@"Toolbar_Internet_Enable", @"Internet Enable Image")];
[toolbarItem setPaletteLabel:NSLocalizedString(@"Toolbar_Internet_Enable", @"Internet Enable Image")];
// Set up a reasonable tooltip, and image
// you will likely want to localize many of the item's properties
[toolbarItem setToolTip:NSLocalizedString(@"Toolbar_Internet_Enable_Tip", @"Internet Enable a disk image")];
[toolbarItem setImage:[NSImage imageNamed:@"toolbar_internet.png"]];
// Tell the item what message to send when it is clicked
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(makeInternetEnabled:)];
}
else if ([itemIdentifier isEqual: FDToolbarConvertItemIdentifier]) {
// Set the text label to be displayed in the
// toolbar and customization palette
[toolbarItem setLabel:NSLocalizedString(@"Toolbar_Convert", @"Convert Image")];
[toolbarItem setPaletteLabel:NSLocalizedString(@"Toolbar_Convert", @"Convert Image")];
// Set up a reasonable tooltip, and image
// you will likely want to localize many of the item's properties
[toolbarItem setToolTip:NSLocalizedString(@"Toolbar_Convert_Tip", @"Convert a disk image")];
[toolbarItem setImage:[NSImage imageNamed:@"toolbar_convert.png"]];
// Tell the item what message to send when it is clicked
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(convertImage:)];
}
else if ([itemIdentifier isEqual: FDToolbarMountItemIdentifier]) {
// Set the text label to be displayed in the
// toolbar and customization palette
[toolbarItem setLabel:NSLocalizedString(@"Toolbar_Mount", @"Mount Image")];
[toolbarItem setPaletteLabel:NSLocalizedString(@"Toolbar_Mount", @"Mount Image")];
// Set up a reasonable tooltip, and image
// you will likely want to localize many of the item's properties
[toolbarItem setToolTip:NSLocalizedString(@"Toolbar_Mount_Tip", @"Mount a disk image")];
[toolbarItem setImage:[NSImage imageNamed:@"toolbar_mount.png"]];
// Tell the item what message to send when it is clicked
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(mount:)];
}
else if ([itemIdentifier isEqual: FDToolbarInspectItemIdentifier]) {
// Set the text label to be displayed in the
// toolbar and customization palette
[toolbarItem setLabel:NSLocalizedString(@"Toolbar_Get_Info", @"Get Info")];
[toolbarItem setPaletteLabel:NSLocalizedString(@"Toolbar_Get_Info", @"Get Info")];
// Set up a reasonable tooltip, and image
// you will likely want to localize many of the item's properties
[toolbarItem setToolTip:NSLocalizedString(@"Toolbar_Get_Info_Tip", @"Get Info")];
[toolbarItem setImage:[NSImage imageNamed:@"toolbar_info.png"]];
// Tell the item what message to send when it is clicked
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(getInfo:)];
}
else if ([itemIdentifier isEqual: FDToolbarEjectItemIdentifier]) {
// Set the text label to be displayed in the
// toolbar and customization palette
[toolbarItem setLabel:NSLocalizedString(@"Toolbar_Eject", @"Eject Image")];
[toolbarItem setPaletteLabel:NSLocalizedString(@"Toolbar_Eject", @"Eject Image")];
// Set up a reasonable tooltip, and image
// you will likely want to localize many of the item's properties
[toolbarItem setToolTip:NSLocalizedString(@"Toolbar_Eject_Tip", @"Eject a disk image")];
[toolbarItem setImage:[NSImage imageNamed:@"Eject.tiff"]];
// Tell the item what message to send when it is clicked
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(ejectImage:)];
}
else if ([itemIdentifier isEqual: FDToolbarLogItemIdentifier]) {
// Set the text label to be displayed in the
// toolbar and customization palette
[toolbarItem setLabel:NSLocalizedString(@"Toolbar_Log", @"Show/Hide Log")];
[toolbarItem setPaletteLabel:NSLocalizedString(@"Toolbar_Log", @"Show/Hide Log")];
// Set up a reasonable tooltip, and image
// you will likely want to localize many of the item's properties
[toolbarItem setToolTip:NSLocalizedString(@"Toolbar_Log_Tip", @"Show/Hide Log Drawer")];
[toolbarItem setImage:[NSImage imageNamed:@"toolbar_log.png"]];
// Tell the item what message to send when it is clicked
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(showHideLogAction:)];
}
else if ([itemIdentifier isEqual: FDToolbarBurnItemIdentifier]) {
// Set the text label to be displayed in the
// toolbar and customization palette
[toolbarItem setLabel:NSLocalizedString(@"Toolbar_Burn", @"Burn Image")];
[toolbarItem setPaletteLabel:NSLocalizedString(@"Toolbar_Burn", @"Burn Image")];
// Set up a reasonable tooltip, and image
// you will likely want to localize many of the item's properties
[toolbarItem setToolTip:NSLocalizedString(@"Toolbar_Burn_Tip", @"Burn a disk image")];
[toolbarItem setImage:[NSImage imageNamed:@"toolbar_burn.png"]];
// Tell the item what message to send when it is clicked
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(burnImage:)];
}
else if ([itemIdentifier isEqual: FDToolbarSLAItemIdentifier]) {
// Set the text label to be displayed in the
// toolbar and customization palette
[toolbarItem setLabel:NSLocalizedString(@"Toolbar_SLA", @"Add SLA")];
[toolbarItem setPaletteLabel:NSLocalizedString(@"Toolbar_SLA", @"Add SLA")];
// Set up a reasonable tooltip, and image
// you will likely want to localize many of the item's properties
[toolbarItem setToolTip:NSLocalizedString(@"Toolbar_SLA_Tip", @"Add Software License Agreement to Image")];
[toolbarItem setImage:[NSImage imageNamed:@"toolbar_sla.png"]];
// Tell the item what message to send when it is clicked
[toolbarItem setTarget:self];
[toolbarItem setAction:@selector(addSLAToImage:)];
}
else
{
// itemIdentifier referred to a toolbar item that is not
// provided or supported by us or Cocoa
// Returning nil will inform the toolbar
// that this kind of item is not supported
toolbarItem = nil;
}
return toolbarItem;
}
- (void) toggleToolbarShown:(id)sender
{
if([[sender title] isEqualToString:@"Hide Toolbar"])
[mainToolbar setVisible:FALSE];
else
[mainToolbar setVisible:TRUE];
}
- (void)textDidEndEditing:(NSNotification *)aNotification
{
NSLog(@"Text did end editing: %@", [aNotification description]);
if([[aNotification object] isEqual:SLATextView])
{
[self saveSLAStringValue];
}
else if([[aNotification object] isEqual: resizeProjectedTextField])
{
[resizeSlider setDoubleValue:[resizeProjectedTextField doubleValue]];
}
}
#pragma mark Methods
// Logging to our log pane
- (void)FDLog:(NSString*)logOutput
{
[[logTextView textStorage] appendAttributedString:[[[NSAttributedString alloc] initWithString:[logOutput stringByAppendingString:@"\n"]] autorelease]];
}
-(BOOL) isTiger
{
NSString *operatingSystemVersion = [[NSProcessInfo processInfo] operatingSystemVersionString], *temp = [NSString stringWithString:@""];
NSScanner *versionScanner = [NSScanner scannerWithString:operatingSystemVersion];
if([versionScanner scanUpToString:@"(" intoString:&temp]){
versionScanner = [NSScanner scannerWithString:temp];
if([versionScanner scanString:@"Version 10.4" intoString:&temp])
return TRUE;
else
return FALSE;
}
else
return FALSE;
}
// create new image, specifying size, filesystem, and volumename
-(int) createImage:(NSString*)imagePath ofSize:(NSNumber*)imageSizeInMB withFilesystem:(NSString*)imageFilesystem volumeName:(NSString*)imageVolumeName type:(NSString*)imageType
{
int status = 0;
NSMutableArray *arguments = [NSMutableArray arrayWithCapacity:1];
[arguments addObject:@"create"];
// specify image size
[arguments addObject:@"-megabytes"];
if(![[imageSizeInMB stringValue] isEqualToString:@"0"])
[arguments addObject:[imageSizeInMB stringValue]];
else
[arguments addObject:[[NSNumber numberWithInt:40] stringValue]];
// if the imageVolumeName is specified, use that
if(imageVolumeName != nil){
[arguments addObject:@"-volname"];
[arguments addObject:imageVolumeName];
}
// if the imageFilesystem is not specified, make HFS+ the default
[arguments addObject:@"-fs"];
if(imageFilesystem != nil){
[arguments addObject:imageFilesystem];
}
else{
[arguments addObject:@"HFS+"];
}
// specify image type
if(imageType != nil)
{
[arguments addObject:@"-type"];
[arguments addObject:imageType];
}
// add optional encryption options to arguments
if(encryption){
[arguments addObject:@"-encryption"];
if(![[self encryptionType] isEqual:@""])
{
[arguments addObject:[self encryptionType]];
}
}
// check if the user has chosen to overwrite
if(overwrite){
[arguments addObject:@"-ov"];
}
// verbose
if(verbose)
[arguments addObject:@"-verbose"];
[arguments addObject:@"-puppetstrings"];
// specify the image path
[arguments addObject:imagePath];
// launch the task
status = [self openTask:@"/usr/bin/hdiutil" withArguments:arguments];
return status;
}
// create disk image from files
-(int) createImageWithFiles:(NSArray*)files
{
int status = 0;
BOOL isDir = FALSE;
NSString *path = nil, *imagePath = nil, *filePath = nil;
NSMutableArray *arguments = [NSMutableArray arrayWithCapacity:1];
NSFileManager *fileManager = [NSFileManager defaultManager];
// Check to make sure our tool is still hanging out in our package
if(![[NSBundle mainBundle] pathForResource:@"mkdmg" ofType:nil])
{
NSRunAlertPanel(@"FreeDMG", NSLocalizedString(@"mkdmg_Warning", @"mkdmg tool not found. Re-install FreeDMG."), NSLocalizedString(@"OK", @"OK"), @"", @"");
status = -1;
}
else
path = [NSString stringWithString:[[NSBundle mainBundle] pathForResource:@"mkdmg" ofType:nil]];
// if the mkdmg tool is present, proceed
if (status == 0)
{
// set image file path
filePath = [NSString stringWithString:[files objectAtIndex:0]];
// if the user has chosen to skip prompt, and has dropped one file or folder,
// set the source (filePath), and destination (imagePath) based on source name
if(prompt && ![[filePath stringByDeletingLastPathComponent] isEqual:@"/Volumes"] && ([files count] == 1))
{
imagePath = [[[files objectAtIndex:0]
stringByDeletingLastPathComponent]
stringByAppendingPathComponent:[[files objectAtIndex:0] lastPathComponent]];
}
else if(([[[filePath lastPathComponent] pathExtension] isEqualToString: @"dmg"] ||
[[[filePath lastPathComponent] pathExtension] isEqualToString: @"img"] ||
[[[filePath lastPathComponent] pathExtension] isEqualToString: @"cdr"] ||
[[[filePath lastPathComponent] pathExtension] isEqualToString: @"sparseimage"] ||
[[[filePath lastPathComponent] pathExtension] isEqualToString: @"sparsebundle"]) &&
[files count] == 1)
{
// if the file is a disk image, we don't want to query for save destination
}
// otherwise, query the user for save destination.
else
{
sPanel = [NSSavePanel savePanel];
[sPanel setAccessoryView:ConvertView];
if ([sPanel runModalForDirectory:nil file:[[filePath lastPathComponent] stringByAppendingPathExtension:[self pathExtension]]] == NSOKButton) {
imagePath = [NSString stringWithString:[sPanel filename]];
}
else{
status = 1;
[statusTextField setStringValue:@"Idle"];
[imageProgress stopAnimation:self];
}
}
// Check to see if the source is a single file/folder
if(([files count] == 1) && (status == 0))
{
// if a disk image is dropped - mount it
if ([[[filePath lastPathComponent] pathExtension] isEqualToString: @"dmg"] ||
[[[filePath lastPathComponent] pathExtension] isEqualToString: @"img"] ||
[[[filePath lastPathComponent] pathExtension] isEqualToString: @"sparseimage"] ||
[[[filePath lastPathComponent] pathExtension] isEqualToString: @"sparsebundle"] ||
[[[filePath lastPathComponent] pathExtension] isEqualToString: @"cdr"] ||
[[[filePath lastPathComponent] pathExtension] isEqualToString: @"iso"])
{
switch([[imageDropMatrix selectedCell] tag]){
case 1:
status = [self burnImageAtPath:filePath];
break;
case 2:
status = [self convertImage:filePath format:[self compression] outfile:[filePath stringByAppendingPathExtension:[self pathExtension]]];
break;
case 3:
status = [self segmentImageAtPath:filePath segmentName:[filePath lastPathComponent] segmentSize:[segmentSizeButton title]];
break;
case 4:
status = [self imageInfoAtPath:filePath];
break;
case 5:
status = [self verifyImageAtPath:imagePath];
break;
case 6:
status = [self checksumImageAtPath:imagePath type:@"CRC32"];
break;
case 7:
status = [self scanImageForRestore:imagePath blockOnly:FALSE];
break;
default:
status = [self mountImage:filePath];