From d29e8deb0aa2238b19175311aa67bb0e2b923cc6 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 27 Dec 2010 12:11:07 +0900 Subject: [PATCH] Use Qprintf for writing maps, and fileSystemRepresentation to get the path. --- tools/Forge/Bundles/MapEdit/Entity.h | 3 ++- tools/Forge/Bundles/MapEdit/Entity.m | 10 +++++----- tools/Forge/Bundles/MapEdit/Map.h | 2 +- tools/Forge/Bundles/MapEdit/Map.m | 22 +++++++++++++--------- tools/Forge/Bundles/MapEdit/QuakeEd.m | 8 ++++---- tools/Forge/Bundles/MapEdit/SetBrush.h | 3 ++- tools/Forge/Bundles/MapEdit/SetBrush.m | 15 +++++---------- 7 files changed, 32 insertions(+), 31 deletions(-) diff --git a/tools/Forge/Bundles/MapEdit/Entity.h b/tools/Forge/Bundles/MapEdit/Entity.h index 3a6919442..1b639c0f0 100644 --- a/tools/Forge/Bundles/MapEdit/Entity.h +++ b/tools/Forge/Bundles/MapEdit/Entity.h @@ -4,6 +4,7 @@ #include #include "QF/mathlib.h" +#include "QF/quakeio.h" typedef struct epair_s { struct epair_s *next; @@ -30,7 +31,7 @@ typedef struct epair_s { - (const char *) targetname; -- (void) writeToFILE: (FILE *)f region: (BOOL)reg; +- (void) writeToFile: (QFile *)file region: (BOOL)reg; - (const char *) valueForQKey: (const char *)k; - (void) getVector: (vec3_t)v forKey: (const char *)k; diff --git a/tools/Forge/Bundles/MapEdit/Entity.m b/tools/Forge/Bundles/MapEdit/Entity.m index 4ca3b4d2c..cdd47dfc3 100644 --- a/tools/Forge/Bundles/MapEdit/Entity.m +++ b/tools/Forge/Bundles/MapEdit/Entity.m @@ -393,7 +393,7 @@ int nument; return self; } -- (void) writeToFILE: (FILE *)f +- (void) writeToFile: (QFile *)file region: (BOOL)reg; { epair_t *e; @@ -417,7 +417,7 @@ int nument; } } - fprintf (f, "{\n"); + Qprintf (file, "{\n"); // set an origin epair if (!modifiable) { @@ -441,15 +441,15 @@ int nument; } for (e = epairs; e; e = e->next) - fprintf (f, "\"%s\"\t\"%s\"\n", e->key, e->value); + Qprintf (file, "\"%s\"\t\"%s\"\n", e->key, e->value); // fixed size entities don't save out brushes if (modifiable) { for (i = 0; i < [self count]; i++) - [[self objectAtIndex: i] writeToFILE: f region: reg]; + [[self objectAtIndex: i] writeToFile: file region: reg]; } - fprintf (f, "}\n"); + Qprintf (file, "}\n"); if (oldang) { [self setKey: "angle" toValue: oldang]; diff --git a/tools/Forge/Bundles/MapEdit/Map.h b/tools/Forge/Bundles/MapEdit/Map.h index f04c490d8..456b9f9d9 100644 --- a/tools/Forge/Bundles/MapEdit/Map.h +++ b/tools/Forge/Bundles/MapEdit/Map.h @@ -22,7 +22,7 @@ extern id map_i; - (id) writeStats; - (id) readMapFile: (NSString *)fname; -- (id) writeMapFile: (const char *)fname useRegion: (BOOL)reg; +- (id) writeMapFile: (NSString *)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 14844b7d4..3238b524a 100644 --- a/tools/Forge/Bundles/MapEdit/Map.m +++ b/tools/Forge/Bundles/MapEdit/Map.m @@ -1,5 +1,8 @@ #include #include +#include +#include +#include #include "QF/quakeio.h" #include "QF/script.h" @@ -301,22 +304,23 @@ readMapFile writeMapFile ================= */ -- (id) writeMapFile: (const char *)fname +- (id) writeMapFile: (NSString *)fname useRegion: (BOOL)reg { - FILE *f; unsigned int i; + QFile *file = 0; - Sys_Printf ("writeMapFile: %s\n", fname); + NSLog (@"writeMapFile: %@\n", fname); - f = fopen (fname, "w"); - if (!f) - Sys_Error ("couldn't write %s", fname); + file = Qopen ([fname fileSystemRepresentation], "wb"); + if (!file) { + NSLog (@"couldn't write %@, %s", fname, strerror (errno)); + return self; + } for (i = 0; i < [self count]; i++) - [[self objectAtIndex: i] writeToFILE: f region: reg]; - - fclose (f); + [[self objectAtIndex: i] writeToFile: file region: reg]; + Qclose (file); return self; } diff --git a/tools/Forge/Bundles/MapEdit/QuakeEd.m b/tools/Forge/Bundles/MapEdit/QuakeEd.m index 7c1225f57..bef8a99af 100644 --- a/tools/Forge/Bundles/MapEdit/QuakeEd.m +++ b/tools/Forge/Bundles/MapEdit/QuakeEd.m @@ -133,8 +133,8 @@ Every five minutes, save a modified map // automatic backup if (autodirty) { autodirty = NO; -#define FN_AUTOSAVE "/qcache/AutoSaveMap.map" - [map_i writeMapFile: (char *) FN_AUTOSAVE useRegion: NO]; +#define FN_AUTOSAVE @"/qcache/AutoSaveMap.map" + [map_i writeMapFile: FN_AUTOSAVE useRegion: NO]; } [map_i writeStats]; } @@ -676,7 +676,7 @@ saveBSP if ([regionbutton_i intValue]) { mappath = [[filename stringByDeletingPathExtension] stringByAppendingPathExtension: @"reg"]; - [map_i writeMapFile: [mappath cString] useRegion: YES]; + [map_i writeMapFile: mappath useRegion: YES]; wt = YES; // allways pop the dialog on region ops } else { mappath = filename; @@ -838,7 +838,7 @@ save: stringByAppendingPathExtension: @"bak"]; rename ([filename cString], [backup cString]); // copy old to .bak - [map_i writeMapFile: [filename cString] useRegion: NO]; + [map_i writeMapFile: filename useRegion: NO]; return self; } diff --git a/tools/Forge/Bundles/MapEdit/SetBrush.h b/tools/Forge/Bundles/MapEdit/SetBrush.h index aa7b3d691..b60c194a3 100644 --- a/tools/Forge/Bundles/MapEdit/SetBrush.h +++ b/tools/Forge/Bundles/MapEdit/SetBrush.h @@ -4,6 +4,7 @@ #include #include "QF/mathlib.h" +#include "QF/quakeio.h" #include "TexturePalette.h" @@ -75,7 +76,7 @@ winding_t *NewWinding (int points); - (id) calcWindings; -- (void) writeToFILE: (FILE *)f region: (BOOL)reg; +- (void) writeToFile: (QFile *)file region: (BOOL)reg; - (BOOL) selected; - (BOOL) regioned; diff --git a/tools/Forge/Bundles/MapEdit/SetBrush.m b/tools/Forge/Bundles/MapEdit/SetBrush.m index 19519b103..3b8cda7a2 100644 --- a/tools/Forge/Bundles/MapEdit/SetBrush.m +++ b/tools/Forge/Bundles/MapEdit/SetBrush.m @@ -778,12 +778,7 @@ ParseVerts (script_t *script, int *n_verts) return self; } -/* -=========== -writeToFILE -=========== -*/ -- (void) writeToFILE: (FILE *)f +- (void) writeToFile: (QFile *)file region: (BOOL)reg { int i, j; @@ -792,19 +787,19 @@ writeToFILE if (reg && regioned) return; - fprintf (f, "{\n"); + Qprintf (file, "{\n"); for (i = 0; i < numfaces; i++) { fa = &faces[i]; for (j = 0; j < 3; j++) { - fprintf (f, "( %d %d %d ) ", (int) fa->planepts[j][0], + Qprintf (file, "( %d %d %d ) ", (int) fa->planepts[j][0], (int) fa->planepts[j][1], (int) fa->planepts[j][2]); } td = &fa->texture; - fprintf (f, "%s %d %d %d %f %f\n", td->texture, (int) td->shift[0], + Qprintf (file, "%s %d %d %d %f %f\n", td->texture, (int) td->shift[0], (int) td->shift[1], (int) td->rotate, td->scale[0], td->scale[1]); } - fprintf (f, "}\n"); + Qprintf (file, "}\n"); return; }