Optimized user settings files startup-time setup : only write local version.xml is really modified

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@3065 30fe4595-0a0c-4342-8851-515496e4dcbd

Former-commit-id: 18503ec7b18ef6f13a762557542727cf200e1c6a
Former-commit-id: 0543a8585ea6ecd3f23854d4944b68ee31153d50
This commit is contained in:
pouillot 2010-10-29 11:52:59 +00:00
parent 647042940a
commit 95c57548da

View file

@ -29,11 +29,13 @@
#include "portability.h" #include "portability.h"
static void gfFileSetupCopy( char* dataLocation, char* localLocation, int major, int minor, void *localHandle, int count ) static bool gfFileSetupCopy( char* dataLocation, char* localLocation, int major, int minor, void *localHandle, int count )
{ {
bool status;
// Copy the source file to its target place. // Copy the source file to its target place.
if( !GfFileCopy( dataLocation, localLocation ) ) if( !( status = GfFileCopy( dataLocation, localLocation ) ) )
return; return status;
// Update local version.xml file. // Update local version.xml file.
if( localHandle ) if( localHandle )
@ -55,6 +57,8 @@ static void gfFileSetupCopy( char* dataLocation, char* localLocation, int major,
GfParmSetNum( localHandle, buf, "Minor version", NULL, (tdble)minor ); GfParmSetNum( localHandle, buf, "Minor version", NULL, (tdble)minor );
} }
} }
return status;
} }
void GfFileSetup() void GfFileSetup()
@ -67,10 +71,10 @@ void GfFileSetup()
char *localLocation; char *localLocation;
char *absLocalLocation; char *absLocalLocation;
char *absDataLocation; char *absDataLocation;
bool *count; bool *isIndexUsed;
int countLength; int isIndexUsedLen;
int index; int index;
bool found; bool anyLocalChange, fileFound;
int major; int major;
int minor; int minor;
struct stat st; struct stat st;
@ -118,25 +122,26 @@ void GfFileSetup()
} }
// Setup the index of the XML files referenced in the local version.xml. // Setup the index of the XML files referenced in the local version.xml.
countLength = GfParmGetEltNb( localVersionHandle, "versions" ) isIndexUsedLen = GfParmGetEltNb( localVersionHandle, "versions" )
+ GfParmGetEltNb( dataVersionHandle, "versions" ) + 2; + GfParmGetEltNb( dataVersionHandle, "versions" ) + 2;
count = (bool*)malloc( sizeof(bool) * countLength ); isIndexUsed = (bool*)malloc( sizeof(bool) * isIndexUsedLen );
for( index = 0; index < countLength; index++ ) for( index = 0; index < isIndexUsedLen; index++ )
count[index] = false; isIndexUsed[index] = false;
if( GfParmListSeekFirst( localVersionHandle, "versions" ) == 0 ) if( GfParmListSeekFirst( localVersionHandle, "versions" ) == 0 )
{ {
do do
{ {
index = atoi( GfParmListGetCurEltName( localVersionHandle, "versions" ) ); index = atoi( GfParmListGetCurEltName( localVersionHandle, "versions" ) );
if( 0 <= index && index < countLength ) if( 0 <= index && index < isIndexUsedLen )
count[index] = true; isIndexUsed[index] = true;
} while( GfParmListSeekNext( localVersionHandle, "versions" ) == 0 ); } while( GfParmListSeekNext( localVersionHandle, "versions" ) == 0 );
} }
// For each file referenced in the installation version.xml // For each file referenced in the installation version.xml
anyLocalChange = false;
do do
{ {
found = false; fileFound = false;
// Get its installation path (data), user settings path (local), // Get its installation path (data), user settings path (local),
// and new major and minor version numbers // and new major and minor version numbers
@ -160,7 +165,7 @@ void GfFileSetup()
{ {
if( strcmp( absLocalLocation, GfParmGetCurStr( localVersionHandle, "versions", "Local location", "" ) ) == 0 ) if( strcmp( absLocalLocation, GfParmGetCurStr( localVersionHandle, "versions", "Local location", "" ) ) == 0 )
{ {
found = true; fileFound = true;
const int locMinor = (int)GfParmGetCurNum( localVersionHandle, "versions", "Minor version", NULL, 0 ); const int locMinor = (int)GfParmGetCurNum( localVersionHandle, "versions", "Minor version", NULL, 0 );
const int locMajor = (int)GfParmGetCurNum( localVersionHandle, "versions", "Major version", NULL, 0 ); const int locMajor = (int)GfParmGetCurNum( localVersionHandle, "versions", "Major version", NULL, 0 );
@ -170,15 +175,17 @@ void GfFileSetup()
{ {
GfLogTrace("obsolete (installed one is %d.%d) => updating ...\n", GfLogTrace("obsolete (installed one is %d.%d) => updating ...\n",
major, minor); major, minor);
gfFileSetupCopy( absDataLocation, absLocalLocation, major, minor, localVersionHandle, -1 ); if ( gfFileSetupCopy( absDataLocation, absLocalLocation, major, minor, localVersionHandle, -1 ) )
anyLocalChange = true;
} }
else else
{ {
GfLogTrace("up-to-date"); GfLogTrace("up-to-date");
if (stat(absLocalLocation, &st)) if (stat(absLocalLocation, &st))
{ {
GfLogTrace(", but the file is not there => installing ...\n"); GfLogTrace(", but not there => installing ...\n");
gfFileSetupCopy( absDataLocation, absLocalLocation, major, minor, localVersionHandle, -1 ); if ( gfFileSetupCopy( absDataLocation, absLocalLocation, major, minor, localVersionHandle, -1 ) )
anyLocalChange = true;
} }
else else
GfLogTrace(".\n"); GfLogTrace(".\n");
@ -189,14 +196,15 @@ void GfFileSetup()
} while( GfParmListSeekNext( localVersionHandle, "versions" ) == 0 ); } while( GfParmListSeekNext( localVersionHandle, "versions" ) == 0 );
} }
if( !found) if( !fileFound)
{ {
index = 0; index = 0;
while( count[index] ) while( isIndexUsed[index] )
++index; ++index;
GfLogTrace("not found => installing ...\n"); GfLogTrace("not found => installing ...\n");
gfFileSetupCopy( absDataLocation, absLocalLocation, major, minor, localVersionHandle, index ); if ( gfFileSetupCopy( absDataLocation, absLocalLocation, major, minor, localVersionHandle, index ) )
count[index] = true; anyLocalChange = true;
isIndexUsed[index] = true;
} }
free( dataLocation ); free( dataLocation );
@ -204,14 +212,15 @@ void GfFileSetup()
free( absDataLocation ); free( absDataLocation );
free( absLocalLocation ); free( absLocalLocation );
GfParmWriteFile( NULL, localVersionHandle, "versions" );
} while( GfParmListSeekNext( dataVersionHandle, "versions" ) == 0 ); } while( GfParmListSeekNext( dataVersionHandle, "versions" ) == 0 );
GfParmReleaseHandle( dataVersionHandle ); // Write the user settings version.xml if changed.
GfParmWriteFile( NULL, localVersionHandle, "versions" ); if (anyLocalChange)
GfParmWriteFile( NULL, localVersionHandle, "versions" );
GfParmReleaseHandle( localVersionHandle ); GfParmReleaseHandle( localVersionHandle );
free( count ); GfParmReleaseHandle( dataVersionHandle );
free( isIndexUsed );
free( filename ); free( filename );
} }