diff --git a/tools/Forge/Bundles/MapEdit/Dict.h b/tools/Forge/Bundles/MapEdit/Dict.h index 421c7a141..a795692f9 100644 --- a/tools/Forge/Bundles/MapEdit/Dict.h +++ b/tools/Forge/Bundles/MapEdit/Dict.h @@ -12,7 +12,7 @@ struct script_s; struct plitem_s *plist; } -- (id) initFromFile: (FILE *)fp; +- (id) initFromData: (NSData *)data; - (int) getValueUnits: (const char *)key; diff --git a/tools/Forge/Bundles/MapEdit/Dict.m b/tools/Forge/Bundles/MapEdit/Dict.m index 359b5d60e..9e8926935 100644 --- a/tools/Forge/Bundles/MapEdit/Dict.m +++ b/tools/Forge/Bundles/MapEdit/Dict.m @@ -34,25 +34,19 @@ JDC return 0; } -- (id) initFromFile: (FILE *)fp +- (id) initFromData: (NSData *)data { - dstring_t *text = dstring_newstr (); char *str; - size_t read; - const size_t readsize = 1024; + size_t len; [self init]; - do { - str = dstring_reservestr (text, readsize); - read = fread (str, 1, readsize, fp); - if (read) - str[read] = 0; - } while (read == readsize); - - - plist = PL_GetPropertyList (text->str); - dstring_delete (text); + len = [data length]; + str = malloc (len + 1); + [data getBytes: str]; + str[len] = 0; + plist = PL_GetPropertyList (str); + free (str); if (!plist) return 0; return self; diff --git a/tools/Forge/Bundles/MapEdit/EntityClass.m b/tools/Forge/Bundles/MapEdit/EntityClass.m index d1d8028a6..5eaf00545 100644 --- a/tools/Forge/Bundles/MapEdit/EntityClass.m +++ b/tools/Forge/Bundles/MapEdit/EntityClass.m @@ -175,22 +175,20 @@ scanFile - (void) scanFile: (NSString *)filename { int size, line; - char *data; + const char *data; id cl; int i; NSString *path; - QFile *file; + NSData *contents; + NSFileManager *fm = [NSFileManager defaultManager]; path = [source_path stringByAppendingPathComponent: filename]; + contents = [fm contentsAtPath: path]; - file = Qopen ([path cString], "rt"); - if (!file) + if (!contents) return; - size = Qfilesize (file); - data = malloc (size + 1); - size = Qread (file, data, size); - data[size] = 0; - Qclose (file); + size = [contents length]; + data = (const char *) [contents bytes]; line = 1; for (i = 0; i < size; i++) { @@ -204,8 +202,6 @@ scanFile line++; } } - - free (data); } /* diff --git a/tools/Forge/Bundles/MapEdit/Map.h b/tools/Forge/Bundles/MapEdit/Map.h index 8d8347dc3..f04c490d8 100644 --- a/tools/Forge/Bundles/MapEdit/Map.h +++ b/tools/Forge/Bundles/MapEdit/Map.h @@ -21,7 +21,7 @@ extern id map_i; - (id) writeStats; -- (id) readMapFile: (const char *)fname; +- (id) readMapFile: (NSString *)fname; - (id) writeMapFile: (const char *)fname useRegion: (BOOL)reg; - (id) entityConnect: (vec3_t)p1: (vec3_t)p2; diff --git a/tools/Forge/Bundles/MapEdit/Map.m b/tools/Forge/Bundles/MapEdit/Map.m index cea093d49..14844b7d4 100644 --- a/tools/Forge/Bundles/MapEdit/Map.m +++ b/tools/Forge/Bundles/MapEdit/Map.m @@ -224,7 +224,7 @@ FILE METHODS readMapFile ================= */ -- (id) readMapFile: (const char *)fname +- (id) readMapFile: (NSString *)fname { char *dat; const char *wad, *cl; @@ -233,25 +233,25 @@ readMapFile int i, c; vec3_t org; float angle; - QFile *file; script_t *script; size_t size; + NSFileManager *fm = [NSFileManager defaultManager]; + NSData *contents; [self saveSelected]; - Sys_Printf ("loading %s\n", fname); + NSLog (@"loading %@\n", fname); - file = Qopen (fname, "rt"); - if (!file) + contents = [fm contentsAtPath: fname]; + if (!contents) return self; - size = Qfilesize (file); + size = [contents length]; dat = malloc (size + 1); - size = Qread (file, dat, size); - Qclose (file); + [contents getBytes: dat]; dat[size] = 0; script = Script_New (); - Script_Start (script, fname, dat); + Script_Start (script, [fname cString], dat); do { new = [[Entity alloc] initFromScript: script]; @@ -291,6 +291,7 @@ readMapFile break; } } + NSLog (@"%@ loaded\n", fname); return self; } diff --git a/tools/Forge/Bundles/MapEdit/Project.h b/tools/Forge/Bundles/MapEdit/Project.h index 488495386..7a87f9f5e 100644 --- a/tools/Forge/Bundles/MapEdit/Project.h +++ b/tools/Forge/Bundles/MapEdit/Project.h @@ -65,8 +65,6 @@ extern id project_i; const char *string_entities; // cmd-line parm int showDescriptions; // 1 = show map descs in browser - - time_t lastModified; // last time project file was modified } - (id) initProject; diff --git a/tools/Forge/Bundles/MapEdit/Project.m b/tools/Forge/Bundles/MapEdit/Project.m index 975f83bcd..68192bfed 100644 --- a/tools/Forge/Bundles/MapEdit/Project.m +++ b/tools/Forge/Bundles/MapEdit/Project.m @@ -277,24 +277,20 @@ id project_i; // Loads and parses a project file - (id) openProjectFile: (NSString *)path { - FILE *fp; - struct stat s; + NSFileManager *fm = [NSFileManager defaultManager]; + NSData *contents; - Sys_Printf ("openProjectFile: %s\n", [path cString]); + NSLog (@"openProjectFile: %@\n", path); [path retain]; [path_projectinfo release]; path_projectinfo = path; projectInfo = NULL; - fp = fopen ([path cString], "r+t"); - if (fp == NULL) + contents = [fm contentsAtPath: path]; + if (!contents) return self; - stat ([path cString], &s); - lastModified = s.st_mtime; - - projectInfo = [(Dict *)[Dict alloc] initFromFile: fp]; - fclose (fp); + projectInfo = [[Dict alloc] initFromData: contents]; return self; } diff --git a/tools/Forge/Bundles/MapEdit/QuakeEd.m b/tools/Forge/Bundles/MapEdit/QuakeEd.m index 2bd0c7ed2..7c1225f57 100644 --- a/tools/Forge/Bundles/MapEdit/QuakeEd.m +++ b/tools/Forge/Bundles/MapEdit/QuakeEd.m @@ -455,11 +455,11 @@ App delegate methods - (id) textCommand: sender { - char const *t; + NSString *t; - t = [[sender stringValue] cString]; + t = [sender stringValue]; - if (!strcmp (t, "texname")) { + if (![t isEqualToString: @"texname"]) { texturedef_t *td; id b; @@ -788,14 +788,12 @@ Called by open or the project panel [filename release]; filename = fname; - [map_i readMapFile: [filename cString]]; + [map_i readMapFile: filename]; [regionbutton_i setIntValue: 0]; [self setTitleWithRepresentedFilename: fname]; [self updateAll]; - Sys_Printf ("%s loaded\n", [fname cString]); - return self; } diff --git a/tools/Forge/Bundles/MapEdit/XYView.m b/tools/Forge/Bundles/MapEdit/XYView.m index fd95501f9..328f5bc2f 100644 --- a/tools/Forge/Bundles/MapEdit/XYView.m +++ b/tools/Forge/Bundles/MapEdit/XYView.m @@ -271,14 +271,11 @@ Called when the scaler popup on the window is used - (id) scaleMenuTarget: sender { - char const *item; NSRect rect; NSPoint mid, org, origin; float nscale; - item = [[[sender selectedCell] title] cString]; - sscanf (item, "%f", &nscale); - nscale /= 100; + nscale = [[[sender selectedCell] title] floatValue] / 100; if (nscale == scale) return NULL; @@ -381,11 +378,9 @@ Called when the scaler popup on the window is used - (id) gridMenuTarget: sender { - char const *item; int grid; - item = [[[sender selectedCell] title] cString]; - sscanf (item, "grid %d", &grid); + grid = [[[sender selectedCell] title] intValue]; if (grid == gridsize) return NULL; diff --git a/tools/Forge/Bundles/MapEdit/ZView.m b/tools/Forge/Bundles/MapEdit/ZView.m index 40d98aab5..b09733da7 100644 --- a/tools/Forge/Bundles/MapEdit/ZView.m +++ b/tools/Forge/Bundles/MapEdit/ZView.m @@ -153,14 +153,11 @@ Called when the scaler popup on the window is used */ - (id) scaleMenuTarget: sender { - char const *item; NSRect rect; NSPoint mid, org, orig; float nscale; - item = [[sender titleOfSelectedItem] cString]; - sscanf (item, "%f", &nscale); - nscale /= 100; + nscale = [[sender titleOfSelectedItem] floatValue] / 100; if (nscale == scale) return NULL;