]> git.street.me.uk Git - andy/viking.git/blobdiff - src/file.c
Only the TrackWaypoint layer should handle it's internal callback type.
[andy/viking.git] / src / file.c
index bd5021ae58b1f8d1366b9629d5a61988a129d786..e3f1dc4af16ecbb45c252760b3e2e788f055491a 100644 (file)
 #include <glib/gstdio.h>
 #include <glib/gi18n.h>
 
+#include "file.h"
+
 #define TEST_BOOLEAN(str) (! ((str)[0] == '\0' || (str)[0] == '0' || (str)[0] == 'n' || (str)[0] == 'N' || (str)[0] == 'f' || (str)[0] == 'F') )
 #define VIK_MAGIC "#VIK"
 #define GPX_MAGIC "<?xm"
 #define VIK_MAGIC_LEN 4
 
-#ifdef WINDOWS
-#define FILE_SEP '\\'
-#else
-#define FILE_SEP '/'
-#endif
-
 #define VIKING_FILE_VERSION 1
 
 typedef struct _Stack Stack;
@@ -123,7 +119,7 @@ void file_write_layer_param ( FILE *f, const gchar *name, VikLayerParamType type
           case VIK_LAYER_PARAM_UINT: fprintf ( f, "%d\n", data.u ); break;
           case VIK_LAYER_PARAM_INT: fprintf ( f, "%d\n", data.i ); break;
           case VIK_LAYER_PARAM_BOOLEAN: fprintf ( f, "%c\n", data.b ? 't' : 'f' ); break;
-          case VIK_LAYER_PARAM_STRING: fprintf ( f, "%s\n", data.s ); break;
+          case VIK_LAYER_PARAM_STRING: fprintf ( f, "%s\n", data.s ? data.s : "" ); break;
           case VIK_LAYER_PARAM_COLOR: fprintf ( f, "#%.2x%.2x%.2x\n", (int)(data.c.red/256),(int)(data.c.green/256),(int)(data.c.blue/256)); break;
           default: break;
         }
@@ -612,9 +608,13 @@ VikLoadType_t a_file_load ( VikAggregateLayer *top, VikViewport *vp, const gchar
   g_return_val_if_fail ( vp != NULL, LOAD_TYPE_READ_FAILURE );
 
   char *filename = (char *)filename_or_uri;
-  if (strncmp(filename, "file://", 7) == 0)
+  if (strncmp(filename, "file://", 7) == 0) {
+    // Consider replacing this with:
+    // filename = g_filename_from_uri ( entry, NULL, NULL );
+    // Since this doesn't support URIs properly (i.e. will failure if is it has %20 characters in it)
     filename = filename + 7;
-
+    g_debug ( "Loading file %s from URI %s", filename, filename_or_uri );
+  }
   FILE *f = xfopen ( filename, "r" );
 
   if ( ! f )
@@ -722,7 +722,7 @@ const gchar *a_file_basename ( const gchar *filename )
 {
   const gchar *t = filename + strlen(filename) - 1;
   while ( --t > filename )
-    if ( *(t-1) == FILE_SEP )
+    if ( *(t-1) == G_DIR_SEPARATOR )
       break;
   if ( t >= filename )
     return t;