g_critical("Houston, we've had a problem. mode=%d", mode);
}
- fprintf ( f, "#VIKING GPS Data file " VIKING_URL "\n\nxmpp=%f\nympp=%f\nlat=%f\nlon=%f\nmode=%s\ncolor=%s\ndrawscale=%s\ndrawcentermark=%s",
+ fprintf ( f, "#VIKING GPS Data file " VIKING_URL "\n\nxmpp=%f\nympp=%f\nlat=%f\nlon=%f\nmode=%s\ncolor=%s\ndrawscale=%s\ndrawcentermark=%s\n",
vik_viewport_get_xmpp ( VIK_VIEWPORT(vp) ), vik_viewport_get_ympp ( VIK_VIEWPORT(vp) ), ll.lat, ll.lon,
modestring, vik_viewport_get_background_color(VIK_VIEWPORT(vp)),
vik_viewport_get_draw_scale(VIK_VIEWPORT(vp)) ? "t" : "f",
}
/* 0 on failure, 1 on success (vik file) 2 on success (other file) */
-gshort a_file_load ( VikAggregateLayer *top, VikViewport *vp, const gchar *filename )
+gshort a_file_load ( VikAggregateLayer *top, VikViewport *vp, const gchar *filename_or_uri )
{
+ char *filename = filename_or_uri;
+ if (strncmp(filename, "file://", 7) == 0)
+ filename = filename + 7;
+
+ gboolean is_gpx_file = check_file_ext ( filename, ".gpx" );
FILE *f = xfopen ( filename, "r" );
g_assert ( vp );
if ( ! f )
return 0;
- if ( check_magic ( f, VIK_MAGIC ) )
+ if ( !is_gpx_file && check_magic ( f, VIK_MAGIC ) )
{
file_read ( top, f, vp );
if ( f != stdin )
VikLayer *vtl = vik_layer_create ( VIK_LAYER_TRW, vp, NULL, FALSE );
vik_layer_rename ( vtl, a_file_basename ( filename ) );
- if ( check_magic ( f, GPX_MAGIC ) )
+ if ( is_gpx_file || check_magic ( f, GPX_MAGIC ) )
a_gpx_read_file ( VIK_TRW_LAYER(vtl), f );
else
a_gpspoint_read_file ( VIK_TRW_LAYER(vtl), f );
gboolean a_file_save ( VikAggregateLayer *top, gpointer vp, const gchar *filename )
{
- FILE *f = g_fopen(filename, "w");
+ FILE *f;
+
+ if (strncmp(filename, "file://", 7) == 0)
+ filename = filename + 7;
+
+ f = g_fopen(filename, "w");
if ( ! f )
return FALSE;
return filename;
}
+/* example:
+ gboolean is_gpx = check_file_ext ( "a/b/c.gpx", ".gpx" );
+*/
+gboolean check_file_ext ( const gchar *filename, const gchar *fileext )
+{
+ const gchar *basename = a_file_basename(filename);
+ g_assert( filename );
+ g_assert( fileext && fileext[0]=='.' );
+ if (!basename)
+ return FALSE;
+
+ const char * dot = strrchr(basename, '.');
+ if (dot && !strcmp(dot, fileext))
+ return TRUE;
+
+ return FALSE;
+}
+
gboolean a_file_export ( VikTrwLayer *vtl, const gchar *filename, gshort file_type )
{
FILE *f = g_fopen ( filename, "w" );