From 621e278f38535bfcbbf77e2aad006a3959785108 Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Sat, 21 Jun 2008 16:28:17 -0500 Subject: [PATCH] Actually check project info when loading. --- Timeline/Project.C | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/Timeline/Project.C b/Timeline/Project.C index f38892c..98421c4 100644 --- a/Timeline/Project.C +++ b/Timeline/Project.C @@ -47,7 +47,7 @@ extern TLE *tle; /* FIXME: wrong place for this */ #define APP_TITLE "Non-DAW" -#define PROJECT_VERSION "0.28.0" +const int PROJECT_VERSION = 1; @@ -96,7 +96,7 @@ Project::write_info ( void ) return false; } - fprintf( fp, "created by\n\t%s\nversion\n\t%s\nsample rate\n\t%lu\n", + fprintf( fp, "created by\n\t%s\nversion\n\t%d\nsample rate\n\t%lu\n", APP_TITLE " " VERSION, PROJECT_VERSION, (unsigned long)timeline->sample_rate() ); @@ -117,7 +117,38 @@ Project::read_info ( void ) return false; } - /* TODO: something */ + char *name, *value; + + while ( fscanf( fp, "%a[^\n]\n\t%a[^\n]\n", &name, &value ) == 2 ) + { + MESSAGE( "Info: %s = %s", name, value ); + + if ( ! strcmp( name, "sample rate" ) ) + { + nframes_t rate = atoll( value ); + + if ( rate != timeline->sample_rate() ) + WARNING( "incorrect samplerate" ); + } + else if ( ! strcmp( name, "version" ) ) + { + int version = atoi( value ); + + if ( version < PROJECT_VERSION ) + { + WARNING( "Incompatible project version. You must to use \"non-project-convert %d-%d\" to update this project's version", version, PROJECT_VERSION ); + return false; + } + else if ( version > PROJECT_VERSION ) + { + WARNING( "Incompatible project version (%d).", version ); + return false; + } + } + + free( name ); + free( value ); + } fclose( fp ); @@ -198,6 +229,9 @@ Project::open ( const char *name ) return Project::E_LOCKED; } + if ( ! read_info() ) + return E_INVALID; + if ( ! Loggable::open( "history" ) ) FATAL( "error opening journal" ); @@ -206,8 +240,6 @@ Project::open ( const char *name ) *_path = '\0'; fl_filename_absolute( _path, sizeof( _path ), "." ); - read_info(); - _is_open = true; tle->load_timeline_settings();