From 12d79ba28d5bdc4c21f5dc1f2249fe5d81547d99 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sat, 9 Oct 2010 09:49:35 +0900 Subject: [PATCH] More conversions to NSString --- tools/Forge/Bundles/MapEdit/Preferences.h | 8 ++-- tools/Forge/Bundles/MapEdit/Preferences.m | 48 +++++++++----------- tools/Forge/Bundles/MapEdit/Project.m | 8 ++-- tools/Forge/Bundles/MapEdit/TexturePalette.m | 2 +- 4 files changed, 31 insertions(+), 35 deletions(-) diff --git a/tools/Forge/Bundles/MapEdit/Preferences.h b/tools/Forge/Bundles/MapEdit/Preferences.h index fecffde4d..0641c9a59 100644 --- a/tools/Forge/Bundles/MapEdit/Preferences.h +++ b/tools/Forge/Bundles/MapEdit/Preferences.h @@ -15,8 +15,8 @@ extern float lightaxis[3]; id bspSound_i; // actual sound object // internal state - char projectpath[1024]; - char bspSound[1024]; + NSString *projectpath; + NSString *bspSound; BOOL brushOffset; BOOL showBSP; @@ -50,7 +50,7 @@ extern float lightaxis[3]; // validate and set methods called by UI or defaults // - (id) setProjectPath: (const char *)path; -- (id) setBspSoundPath: (const char *)path; // set the path of the soundfile +- (id) setBspSoundPath: (NSString *)path; // set the path of the soundfile - (id) setShowBSP: (int)state; // set the state of ShowBSP - (id) setBrushOffset: (int)state; // set the state of BrushOffset - (id) setStartWad: (int)value; // set start wad (0-2) @@ -70,7 +70,7 @@ extern float lightaxis[3]; // - (id) playBspSound; -- (const char *) getProjectPath; +- (NSString *) getProjectPath; - (int) getBrushOffset; // get the state - (int) getShowBSP; // get the state diff --git a/tools/Forge/Bundles/MapEdit/Preferences.m b/tools/Forge/Bundles/MapEdit/Preferences.m index b1d8a4b35..25cab17de 100644 --- a/tools/Forge/Bundles/MapEdit/Preferences.m +++ b/tools/Forge/Bundles/MapEdit/Preferences.m @@ -81,8 +81,7 @@ _atof (const char *c) string = [[prefs stringForKey: @"ProjectPath"] cString]; [self setProjectPath: string]; - string = [[prefs stringForKey: @"BspSoundPath"] cString]; - [self setBspSoundPath: string]; + [self setBspSoundPath: [prefs stringForKey: @"BspSoundPath"]]; string = [[prefs stringForKey: @"ShowBSPOutput"] cString]; value = _atoi (string); @@ -116,8 +115,8 @@ _atof (const char *c) if (!path) path = ""; - strcpy (projectpath, path); - [startproject_i setStringValue: [NSString stringWithCString: path]]; + projectpath = [NSString stringWithCString: path]; + [startproject_i setStringValue: projectpath]; WriteStringDefault (prefs, "ProjectPath", path); return self; } @@ -129,7 +128,7 @@ _atof (const char *c) return self; } -- (const char *) getProjectPath +- (NSString *) getProjectPath { return projectpath; } @@ -147,24 +146,21 @@ _atof (const char *c) NSString *types[] = {@"snd"}; int rtn; NSArray *filenames; - char path[1024], file[64]; + NSString *path, *file; panel = [NSOpenPanel new]; - // XXX ExtractFilePath (bspSound, path); - // XXX ExtractFileBase (bspSound, file); + path = [bspSound stringByDeletingLastPathComponent]; + file = [bspSound lastPathComponent]; - rtn = [panel runModalForDirectory: [NSString stringWithCString: path] - file: [NSString stringWithCString: file] - types: [NSArray arrayWithObjects: types count: 1] + rtn = [panel runModalForDirectory: path file: file + types: [NSArray arrayWithObjects: types + count: 1] ]; if (rtn) { filenames = [panel filenames]; - strcpy (bspSound, [[panel directory] cString]); - strcat (bspSound, "/"); - strcat (bspSound, [[filenames objectAtIndex: 0] cString]); - [self setBspSoundPath: bspSound]; + [self setBspSoundPath: [filenames objectAtIndex: 0]]; [self playBspSound]; } @@ -183,27 +179,27 @@ _atof (const char *c) // // Set the bspSound path // -- (id) setBspSoundPath: (const char *)path +- (id) setBspSoundPath: (NSString *)path { - if (!path) - path = ""; - strcpy (bspSound, path); + + [path retain]; + [bspSound release]; + bspSound = path; if (bspSound_i) { [bspSound_i release]; bspSound_i = nil; } - if (path[0] && access (path, R_OK)) { - bspSound_i = - [[NSSound alloc] initWithContentsOfFile: [NSString stringWithCString: - bspSound] byReference: YES]; + if (access ([path cString], R_OK)) { + bspSound_i = [[NSSound alloc] initWithContentsOfFile: bspSound + byReference: YES]; } if (!bspSound_i) return self; - [bspSoundField_i setStringValue: [NSString stringWithCString: bspSound]]; + [bspSoundField_i setStringValue: bspSound]; - WriteStringDefault (prefs, "BspSoundPath", bspSound); + WriteStringDefault (prefs, "BspSoundPath", [bspSound cString]); return self; } @@ -345,7 +341,7 @@ Grab all the current UI state Sys_Printf ("defaults updated\n"); [self setProjectPath: [[startproject_i stringValue] cString]]; - [self setBspSoundPath: [[bspSoundField_i stringValue] cString]]; + [self setBspSoundPath: [bspSoundField_i stringValue]]; [self setShowBSP: [showBSP_i intValue]]; [self setBrushOffset: [brushOffset_i intValue]]; [self setStartWad: [startwad_i selectedRow]]; diff --git a/tools/Forge/Bundles/MapEdit/Project.m b/tools/Forge/Bundles/MapEdit/Project.m index 11aa67e1b..699193fdf 100644 --- a/tools/Forge/Bundles/MapEdit/Project.m +++ b/tools/Forge/Bundles/MapEdit/Project.m @@ -39,7 +39,7 @@ id project_i; { NSString *ts; - ts = [NSString stringWithCString: [preferences_i getProjectPath]]; + ts = [preferences_i getProjectPath]; ts = path_basepath = [[ts stringByDeletingLastPathComponent] retain]; path_progdir = [[ts stringByAppendingPathComponent: SUBDIR_ENT] retain]; @@ -266,11 +266,11 @@ id project_i; // - (id) parseProjectFile { - const char *path; + NSString *path; int rtn; path = [preferences_i getProjectPath]; - if (!path || !path[0] || access (path, 0)) { + if (![path length] || access ([path cString], 0)) { rtn = NSRunAlertPanel (@"Project Error!", @"A default project has not been found.\n", @"Open Project", NULL, NULL); @@ -281,7 +281,7 @@ id project_i; return self; } - [self openProjectFile: [NSString stringWithCString: path]]; + [self openProjectFile: path]; return self; } diff --git a/tools/Forge/Bundles/MapEdit/TexturePalette.m b/tools/Forge/Bundles/MapEdit/TexturePalette.m index 08ca9df47..55f8604c4 100644 --- a/tools/Forge/Bundles/MapEdit/TexturePalette.m +++ b/tools/Forge/Bundles/MapEdit/TexturePalette.m @@ -191,7 +191,7 @@ TEX_InitFromWad (const char *path) start = Sys_DoubleTime (); - newpath = [preferences_i getProjectPath]; + newpath = [[preferences_i getProjectPath] cString]; newpath = va ("%s%s%s", newpath, newpath[0] ? "/" : "", path); // free any textures