4 |
|
* |
5 |
|
* $Id$ |
6 |
|
* |
7 |
< |
* Basilisk II (C) 1997-2004 Christian Bauer |
7 |
> |
* Basilisk II (C) 1997-2008 Christian Bauer |
8 |
|
* |
9 |
|
* This program is free software; you can redistribute it and/or modify |
10 |
|
* it under the terms of the GNU General Public License as published by |
105 |
|
|
106 |
|
@end |
107 |
|
|
108 |
– |
@implementation PrefsEditor |
109 |
– |
|
108 |
|
#import <AppKit/NSImage.h> // For [NSBundle pathForImageResource:] proto |
109 |
|
|
110 |
|
#include <string> |
114 |
|
#import "sysdeps.h" // Types used in Basilisk C++ code |
115 |
|
#import "video_macosx.h" // some items that we edit here |
116 |
|
#import "misc_macosx.h" // WarningSheet() prototype |
117 |
+ |
#import "main_macosx.h" // ChoiceAlert() prototype |
118 |
+ |
|
119 |
|
|
120 |
|
#import <prefs.h> |
121 |
|
|
122 |
|
#define DEBUG 0 |
123 |
|
#import <debug.h> |
124 |
|
|
125 |
+ |
@implementation PrefsEditor |
126 |
+ |
|
127 |
|
- (PrefsEditor *) init |
128 |
|
{ |
129 |
|
self = [super init]; |
131 |
|
edited = NO; |
132 |
|
|
133 |
|
devs = @"/dev"; |
134 |
< |
home = NSHomeDirectory(); |
134 |
> |
home = [NSHomeDirectory() retain]; |
135 |
|
volsDS = [TableDS new]; |
136 |
|
SCSIds = [TableDS new]; |
137 |
|
|
140 |
|
NSLog (@"%s - Can't create NSImageCell?", __PRETTY_FUNCTION__); |
141 |
|
|
142 |
|
blank = [NSImage new]; |
143 |
< |
locked = [NSImage alloc]; |
144 |
< |
if ( [locked initWithContentsOfFile: |
145 |
< |
[[NSBundle mainBundle] |
144 |
< |
pathForImageResource: @"nowrite.icns"]] == nil ) |
143 |
> |
locked = [[NSImage alloc] initWithContentsOfFile: |
144 |
> |
[[NSBundle mainBundle] pathForImageResource: @"nowrite.icns"]]; |
145 |
> |
if (locked == nil ) |
146 |
|
NSLog(@"%s - Couldn't open write protection image", __PRETTY_FUNCTION__); |
147 |
|
|
148 |
|
return self; |
150 |
|
|
151 |
|
- (void) dealloc |
152 |
|
{ |
153 |
< |
[volsDS dealloc]; |
154 |
< |
[SCSIds dealloc]; |
155 |
< |
[lockCell dealloc]; |
156 |
< |
[locked dealloc]; |
157 |
< |
[blank dealloc]; |
153 |
> |
[home release]; |
154 |
> |
[volsDS release]; |
155 |
> |
[SCSIds release]; |
156 |
> |
[lockCell release]; |
157 |
> |
[blank release]; |
158 |
> |
[locked release]; |
159 |
|
[super dealloc]; |
160 |
|
} |
161 |
|
|
198 |
|
{ |
199 |
|
[volsDS addObject: (NSObject *) locked |
200 |
|
withPath: [oP filename] ]; |
201 |
< |
PrefsAddString("disk", [[oP filename] cString]); |
201 |
> |
PrefsAddString("disk", [[oP filename] UTF8String]); |
202 |
|
[diskImages reloadData]; |
203 |
|
edited = YES; |
204 |
|
} |
219 |
|
types:nil] == NSOKButton ) |
220 |
|
{ |
221 |
|
[extFS setStringValue: [oP directory] ]; |
222 |
< |
PrefsReplaceString("extfs", [[oP directory] cString]); |
222 |
> |
PrefsReplaceString("extfs", [[oP directory] UTF8String]); |
223 |
|
edited = YES; |
224 |
|
} |
225 |
|
} |
236 |
|
types:nil] == NSOKButton ) |
237 |
|
{ |
238 |
|
[prefsFile setStringValue: [oP filename] ]; |
239 |
< |
UserPrefsPath = [[oP filename] cString]; |
239 |
> |
UserPrefsPath = [[oP filename] UTF8String]; |
240 |
|
} |
241 |
|
} |
242 |
|
|
252 |
|
types:nil] == NSOKButton ) |
253 |
|
{ |
254 |
|
[ROMfile setStringValue: [oP filename] ]; |
255 |
< |
PrefsReplaceString("rom", [[oP filename] cString]); |
255 |
> |
PrefsReplaceString("rom", [[oP filename] UTF8String]); |
256 |
|
edited = YES; |
257 |
|
} |
258 |
|
} |
261 |
|
|
262 |
|
- (IBAction) ChangeBootFrom: (NSMatrix *)sender |
263 |
|
{ |
264 |
< |
if ( [sender selectedCell] == bootFromCD ) |
264 |
> |
if ( [sender selectedCell] == (id)bootFromCD ) |
265 |
> |
{ |
266 |
> |
[disableCD setState: NSOffState]; |
267 |
> |
|
268 |
|
PrefsReplaceInt32("bootdriver", CDROMRefNum); |
269 |
+ |
} |
270 |
|
else |
271 |
|
PrefsReplaceInt32("bootdriver", 0); |
272 |
|
edited = YES; |
280 |
|
|
281 |
|
- (IBAction) ChangeDisableCD: (NSButton *)sender |
282 |
|
{ |
283 |
< |
PrefsReplaceBool("nocdrom", [disableCD state]); |
283 |
> |
int disabled = [disableCD state]; |
284 |
> |
|
285 |
> |
PrefsReplaceBool("nocdrom", disabled); |
286 |
> |
if ( disabled ) |
287 |
> |
{ |
288 |
> |
[bootFromAny setState: NSOnState]; |
289 |
> |
[bootFromCD setState: ![disableCD state]]; |
290 |
> |
} |
291 |
|
edited = YES; |
292 |
|
} |
293 |
|
|
336 |
|
#else |
337 |
|
if ( newbpp != 32 ) |
338 |
|
WarningSheet(@"Sorry - In windowed mode, depth must be 32", panel); |
339 |
< |
return 32 |
339 |
> |
return 32; |
340 |
|
#endif |
341 |
|
} |
342 |
|
|
447 |
|
if ( [sP runModalForDirectory:NSHomeDirectory() file:@"basilisk-II.vol"] == NSOKButton ) |
448 |
|
{ |
449 |
|
char cmd[1024]; |
450 |
< |
const char *filename = [[sP filename] cString]; |
450 |
> |
const char *filename = [[sP filename] UTF8String]; |
451 |
|
int retVal, |
452 |
|
size = [newVolumeSize intValue]; |
453 |
|
|
454 |
|
sprintf(cmd, "dd if=/dev/zero \"of=%s\" bs=1024k count=%d", filename, size); |
455 |
+ |
|
456 |
|
retVal = system(cmd); |
457 |
|
if (retVal != 0) |
458 |
|
{ |
485 |
|
|
486 |
|
- (IBAction) DeleteVolume: (id)sender |
487 |
|
{ |
474 |
– |
// const char *path = [self RemoveVolumeEntry]; |
475 |
– |
// if ( unlink(path) == -1 ) |
488 |
|
NSString *Path = [self RemoveVolumeEntry]; |
489 |
|
|
490 |
+ |
if ( ! Path ) |
491 |
+ |
return; |
492 |
+ |
|
493 |
|
if ( ! [[NSFileManager defaultManager] removeFileAtPath: Path |
494 |
|
handler: self] ) |
495 |
|
{ |
496 |
|
WarningSheet(@"Unable to delete volume", panel); |
497 |
< |
// NSLog(@"%s unlink(%s) failed - %s", __PRETTY_FUNCTION__, path, strerror(errno)); |
497 |
> |
NSLog(@"%s unlink(%s) failed - %s", __PRETTY_FUNCTION__, |
498 |
> |
[Path cString], strerror(errno)); |
499 |
|
} |
500 |
|
} |
501 |
|
|
530 |
|
{ |
531 |
|
NSString *path = [etherNet stringValue]; |
532 |
|
|
533 |
< |
PrefsReplaceString("ether", [path cString]); |
533 |
> |
PrefsReplaceString("ether", [path UTF8String]); |
534 |
|
edited = YES; |
535 |
|
} |
536 |
|
|
538 |
|
{ |
539 |
|
NSString *path = [extFS stringValue]; |
540 |
|
|
541 |
< |
PrefsReplaceString("extfs", [path cString]); |
541 |
> |
PrefsReplaceString("extfs", [path UTF8String]); |
542 |
|
edited = YES; |
543 |
|
} |
544 |
|
|
555 |
|
{ |
556 |
|
NSString *path = [modem stringValue]; |
557 |
|
|
558 |
< |
PrefsReplaceString("seriala", [path cString]); |
558 |
> |
PrefsReplaceString("seriala", [path UTF8String]); |
559 |
|
edited = YES; |
560 |
|
} |
561 |
|
|
574 |
|
{ |
575 |
|
NSString *path = [printer stringValue]; |
576 |
|
|
577 |
< |
PrefsReplaceString("serialb", [path cString]); |
577 |
> |
PrefsReplaceString("serialb", [path UTF8String]); |
578 |
|
edited = YES; |
579 |
|
} |
580 |
|
|
582 |
|
{ |
583 |
|
NSString *path = [ROMfile stringValue]; |
584 |
|
|
585 |
< |
PrefsReplaceString("rom", [path cString]); |
585 |
> |
PrefsReplaceString("rom", [path UTF8String]); |
586 |
|
} |
587 |
|
|
588 |
|
- (IBAction) RemoveSCSI: (id)sender |
595 |
|
NSLog (@"%s - [SCSIds deleteRow: %d] failed", __PRETTY_FUNCTION__, row); |
596 |
|
[SCSIdisks reloadData]; |
597 |
|
sprintf(pref, "scsi%d", SCSIid); |
598 |
< |
PrefsRemoveItem(pref,0); |
598 |
> |
//PrefsRemoveItem(pref,0); |
599 |
> |
PrefsRemoveItem(pref, 1); |
600 |
|
} |
601 |
|
|
585 |
– |
//- (const char *) RemoveVolumeEntry |
602 |
|
- (NSString *) RemoveVolumeEntry |
603 |
|
{ |
604 |
|
int row = [diskImages selectedRow]; |
606 |
|
if ( row != -1 ) |
607 |
|
{ |
608 |
|
NSString *Path = [volsDS pathAtRow: row]; |
609 |
< |
const char *path = [Path cString], |
609 |
> |
const char *path = [Path UTF8String], |
610 |
|
*str; |
611 |
|
int tmp = 0; |
612 |
|
|
613 |
+ |
NSString *prompt = [NSString stringWithFormat: @"%s\n%s", |
614 |
+ |
"Are you sure you want to delete the file", |
615 |
+ |
path]; |
616 |
+ |
|
617 |
+ |
if ( ! ChoiceAlert([prompt cString], "Delete", "Cancel") ) |
618 |
+ |
return NULL; |
619 |
+ |
|
620 |
|
while ( (str = PrefsFindString("disk", tmp) ) != NULL ) |
621 |
|
{ |
622 |
|
if ( strcmp(str, path) == 0 ) |
679 |
|
char *argv[2]; |
680 |
|
|
681 |
|
argv[0] = "--prefs", |
682 |
< |
argv[1] = (char *) [[prefsFile stringValue] cString]; |
682 |
> |
argv[1] = (char *) [[prefsFile stringValue] UTF8String]; |
683 |
|
|
684 |
|
[self loadPrefs: argc |
685 |
|
args: argv]; |
692 |
|
} |
693 |
|
|
694 |
|
- (void) setStringOf: (NSTextField *) field |
695 |
< |
fromPref: (const char *) prefName |
695 |
> |
fromPref: (const char *) prefName |
696 |
|
{ |
697 |
|
const char *value = PrefsFindString(prefName, 0); |
698 |
|
|
699 |
|
if ( value ) |
700 |
< |
[field setStringValue: [NSString stringWithCString: value] ]; |
700 |
> |
[field setStringValue: [NSString stringWithUTF8String: value] ]; |
701 |
|
} |
702 |
|
|
703 |
|
- (IBAction) SavePrefs: (id)sender |
734 |
|
[self setStringOf: extFS fromPref: "extfs" ]; |
735 |
|
[self setStringOf: modem fromPref: "seriala"]; |
736 |
|
[self setStringOf: printer fromPref: "serialb"]; |
737 |
< |
[self setStringOf: ROMfile fromPref: "rom" ]; |
737 |
> |
[self setStringOf: ROMfile fromPref: "rom"]; |
738 |
|
|
739 |
< |
[prefsFile setStringValue: [NSString stringWithCString: UserPrefsPath.c_str()] ]; |
739 |
> |
[prefsFile setStringValue: [NSString stringWithUTF8String: UserPrefsPath.c_str()] ]; |
740 |
|
|
741 |
|
|
742 |
|
parse_screen_prefs(PrefsFindString("screen")); |
829 |
|
{ |
830 |
|
if ( *str == '*' ) |
831 |
|
[volsDS addObject: (NSObject *) locked |
832 |
< |
withPath: [NSString stringWithCString: str+1]]; |
832 |
> |
withPath: [NSString stringWithUTF8String: str+1]]; |
833 |
|
else |
834 |
|
[volsDS addObject: (NSObject *) blank |
835 |
< |
withPath: [NSString stringWithCString: str]]; |
835 |
> |
withPath: [NSString stringWithUTF8String: str]]; |
836 |
|
} |
837 |
|
|
838 |
|
[diskImages setDataSource: volsDS]; |