#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
+#ifdef WINDOWS
+#define realpath(X,Y) _fullpath(Y,X,MAX_PATH)
+#endif
#include <glib.h>
#include <glib/gstdio.h>
#include <glib/gi18n.h>
-/* Relax some dependencies */
-#if ! GLIB_CHECK_VERSION(2,12,0)
-static gboolean return_true (gpointer a, gpointer b, gpointer c) { return TRUE; }
-static g_hash_table_remove_all (GHashTable *ght) { g_hash_table_foreach_remove ( ght, (GHRFunc) return_true, FALSE ); }
-#endif
-
#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 FILE_SEP '/'
#endif
+#define VIKING_FILE_VERSION 1
+
typedef struct _Stack Stack;
struct _Stack {
return FALSE;
}
-static guint16 layer_type_from_string ( const gchar *str )
-{
- guint8 i;
- for ( i = 0; i < VIK_LAYER_NUM_TYPES; i++ )
- if ( strcasecmp ( str, vik_layer_get_interface(i)->name ) == 0 )
- return i;
- return -1;
-}
-
-void file_write_layer_param ( FILE *f, const gchar *name, guint8 type, VikLayerParamData data ) {
+void file_write_layer_param ( FILE *f, const gchar *name, VikLayerParamType type, VikLayerParamData data ) {
/* string lists are handled differently. We get a GList (that shouldn't
* be freed) back for get_param and if it is null we shouldn't write
* anything at all (otherwise we'd read in a list with an empty string,
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_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;
}
}
}
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\nhighlightcolor=%s\ndrawscale=%s\ndrawcentermark=%s\ndrawhighlight=%s\n",
+ fprintf ( f, "#VIKING GPS Data file " VIKING_URL "\n" );
+ fprintf ( f, "FILE_VERSION=%d\n", VIKING_FILE_VERSION );
+ fprintf ( f, "\nxmpp=%f\nympp=%f\nlat=%f\nlon=%f\nmode=%s\ncolor=%s\nhighlightcolor=%s\ndrawscale=%s\ndrawcentermark=%s\ndrawhighlight=%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_highlight_color(VIK_VIEWPORT(vp)),
while (stack && stack->data)
{
current_layer = VIK_LAYER(((GList *)stack->data)->data);
- fprintf ( f, "\n~Layer %s\n", vik_layer_get_interface(current_layer->type)->name );
+ fprintf ( f, "\n~Layer %s\n", vik_layer_get_interface(current_layer->type)->fixed_layer_name );
write_layer_params_and_data ( current_layer, f );
if ( current_layer->type == VIK_LAYER_AGGREGATE && !vik_aggregate_layer_is_empty(VIK_AGGREGATE_LAYER(current_layer)) )
{
}
else
{
- gint16 type = layer_type_from_string ( line+6 );
+ VikLayerTypeEnum type = vik_layer_type_from_string ( line+6 );
push(&stack);
- if ( type == -1 )
+ if ( type == VIK_LAYER_NUM_TYPES )
{
successful_read = FALSE;
g_warning ( "Line %ld: Unknown type %s", line_num, line+6 );
if ( stack->data && stack->under->data )
{
if (VIK_LAYER(stack->under->data)->type == VIK_LAYER_AGGREGATE) {
- vik_aggregate_layer_add_layer ( VIK_AGGREGATE_LAYER(stack->under->data), VIK_LAYER(stack->data) );
+ vik_aggregate_layer_add_layer ( VIK_AGGREGATE_LAYER(stack->under->data), VIK_LAYER(stack->data), FALSE );
vik_layer_post_read ( VIK_LAYER(stack->data), vp, TRUE );
}
else if (VIK_LAYER(stack->under->data)->type == VIK_LAYER_GPS) {
if ( line[i] == '=' )
eq_pos = i;
- if ( stack->under == NULL && eq_pos == 4 && strncasecmp ( line, "xmpp", eq_pos ) == 0) /* "hard coded" params: global & for all layer-types */
+ if ( stack->under == NULL && eq_pos == 12 && strncasecmp ( line, "FILE_VERSION", eq_pos ) == 0) {
+ gint version = strtol(line+13, NULL, 10);
+ g_debug ( "%s: reading file version %d", __FUNCTION__, version );
+ if ( version > VIKING_FILE_VERSION )
+ successful_read = FALSE;
+ // However we'll still carry and attempt to read whatever we can
+ }
+ else if ( stack->under == NULL && eq_pos == 4 && strncasecmp ( line, "xmpp", eq_pos ) == 0) /* "hard coded" params: global & for all layer-types */
vik_viewport_set_xmpp ( VIK_VIEWPORT(vp), strtod ( line+5, NULL ) );
else if ( stack->under == NULL && eq_pos == 4 && strncasecmp ( line, "ympp", eq_pos ) == 0)
vik_viewport_set_ympp ( VIK_VIEWPORT(vp), strtod ( line+5, NULL ) );
{
if ( stack->under && stack->under->data && stack->data )
{
- vik_aggregate_layer_add_layer ( VIK_AGGREGATE_LAYER(stack->under->data), VIK_LAYER(stack->data) );
+ vik_aggregate_layer_add_layer ( VIK_AGGREGATE_LAYER(stack->under->data), VIK_LAYER(stack->data), FALSE );
vik_layer_post_read ( VIK_LAYER(stack->data), vp, TRUE );
}
pop(&stack);
if ( ! f )
return LOAD_TYPE_READ_FAILURE;
+ // Enables relative paths in a .vik file to work
+ // Also allows us to remember what directory we where using
+ gchar *dir = g_path_get_dirname ( filename );
+ if ( dir ) {
+ if ( g_chdir ( dir ) ) {
+ g_warning ( "Could not change directory to %s", dir );
+ }
+ g_free (dir);
+ }
+
VikLoadType_t load_answer = LOAD_TYPE_OTHER_SUCCESS;
// Attempt loading the primary file type first - our internal .vik file:
// In fact both kml & gpx files start the same as they are in xml
if ( check_file_ext ( filename, ".kml" ) && check_magic ( f, GPX_MAGIC ) ) {
// Implicit Conversion
- if ( ! ( success = a_babel_convert_from ( VIK_TRW_LAYER(vtl), "-i kml", filename, NULL, NULL ) ) ) {
+ if ( ! ( success = a_babel_convert_from ( VIK_TRW_LAYER(vtl), "-i kml", filename, NULL, NULL, NULL ) ) ) {
load_answer = LOAD_TYPE_GPSBABEL_FAILURE;
}
}
// Complete the setup from the successful load
vik_layer_rename ( vtl, a_file_basename ( filename ) );
vik_layer_post_read ( vtl, vp, TRUE );
- vik_aggregate_layer_add_layer ( top, vtl );
+ vik_aggregate_layer_add_layer ( top, vtl, FALSE );
vik_trw_layer_auto_set_view ( VIK_TRW_LAYER(vtl), vp );
}
}
if ( ! f )
return FALSE;
+ // Enable relative paths in .vik files to work
+ // Also allows us to remember what directory we where using
+ gchar *dir = g_path_get_dirname ( filename );
+ if ( dir ) {
+ if ( g_chdir ( dir ) ) {
+ g_warning ( "Could not change directory to %s", dir );
+ }
+ g_free (dir);
+ }
+
file_write ( top, f, vp );
fclose(f);
*/
gboolean a_file_export ( VikTrwLayer *vtl, const gchar *filename, VikFileType_t file_type, VikTrack *trk, gboolean write_hidden )
{
- GpxWritingOptions options = { FALSE, FALSE, write_hidden };
+ GpxWritingOptions options = { FALSE, FALSE, write_hidden, FALSE };
FILE *f = g_fopen ( filename, "w" );
if ( f )
{
if ( trk ) {
switch ( file_type ) {
case FILE_TYPE_GPX:
+ // trk defined so can set the option
+ options.is_route = trk->is_route;
a_gpx_write_track_file ( trk, f, &options );
break;
default:
return FALSE;
}
+/**
+ * Just a wrapper around realpath, which itself is platform dependent
+ */
+char *file_realpath ( const char *path, char *real )
+{
+ return realpath ( path, real );
+}
+