support versioning the project template and triggering regeneration of the user project

This commit is contained in:
Timothee 'TTimo' Besset 2012-07-04 14:28:32 -05:00
parent ea96f0741a
commit b2d34e0367
3 changed files with 57 additions and 3 deletions

View file

@ -3638,6 +3638,7 @@ void MainFrame::CreateQEChildren(){
char buf[PATH_MAX]; char buf[PATH_MAX];
const char *r; const char *r;
bool bTriedTemplate = false; bool bTriedTemplate = false;
int templateVersion = 0;
if ( g_PrefsDlg.m_nLastProjectVer != 0 && g_PrefsDlg.m_nLastProjectVer != PROJECT_VERSION ) { if ( g_PrefsDlg.m_nLastProjectVer != 0 && g_PrefsDlg.m_nLastProjectVer != PROJECT_VERSION ) {
// we need to regenerate from template // we need to regenerate from template
@ -3645,9 +3646,17 @@ void MainFrame::CreateQEChildren(){
g_PrefsDlg.m_strLastProject = ""; g_PrefsDlg.m_strLastProject = "";
} }
// check to see if the project template is versioned
strcpy( buf, g_pGameDescription->mEnginePath.GetBuffer() );
strcat( buf, g_pGameDescription->mBaseGame.GetBuffer() );
strcat( buf, "/scripts/" );
strcat( buf, PROJECT_TEMPLATE_NAME );
templateVersion = QE_GetTemplateVersionForProject( buf );
r = g_PrefsDlg.m_strLastProject.GetBuffer(); r = g_PrefsDlg.m_strLastProject.GetBuffer();
while ( r == NULL || *r == '\0' || access( r, R_OK ) != 0 || !QE_LoadProject( r ) ) while ( r == NULL || *r == '\0' || access( r, R_OK ) != 0 || !QE_LoadProject( r ) || templateVersion != IntForKey( g_qeglobals.d_project_entity, "template_version" ) )
{ {
if ( !bTriedTemplate ) { if ( !bTriedTemplate ) {
// try default project location // try default project location
@ -3666,8 +3675,7 @@ void MainFrame::CreateQEChildren(){
filename = file_dialog( m_pWidget, TRUE, _( "Choose Project File" ), buf, "project" ); filename = file_dialog( m_pWidget, TRUE, _( "Choose Project File" ), buf, "project" );
if ( filename != NULL ) { if ( filename != NULL ) {
r = filename; r = filename;
} } else {
else{
Error( "Cannot continue without loading a project..." ); Error( "Cannot continue without loading a project..." );
} }
} }

View file

@ -472,6 +472,50 @@ void ReplaceTemplates( char* w, const char* r ){
*w = '\0'; *w = '\0';
} }
/*
Load up a project file to get the current version
*/
int QE_GetTemplateVersionForProject( const char * projectfile ) {
xmlDocPtr doc;
xmlNodePtr node, project;
int ret;
Sys_Printf( "Scanning template version in %s\n", projectfile );
doc = ParseXMLFile( projectfile, true );
if ( doc == NULL ) {
Sys_FPrintf( SYS_ERR, "ERROR: XML parse failed %s\n", projectfile );
return 0;
}
node = doc->children;
while ( node != NULL && node->type != XML_DTD_NODE ) {
node = node->next;
}
if ( node == NULL || strcmp( (char*)node->name, "project" ) != 0 ) {
Sys_FPrintf( SYS_ERR, "ERROR: invalid file type %s\n", projectfile );
xmlFree( doc );
return 0;
}
while ( node->type != XML_ELEMENT_NODE ) {
node = node->next;
}
// <project>
project = node;
for ( node = project->children; node != NULL; node = node->next ) {
if ( node->type != XML_ELEMENT_NODE ) {
continue;
}
if ( strcmp( (char*)node->properties->children->content, "template_version" ) == 0 ) {
ret = atoi( (char*)node->properties->next->children->content );
xmlFreeDoc( doc );
return ret;
}
}
Sys_FPrintf( SYS_WRN, "Version key not found in %s\n", projectfile );
xmlFreeDoc( doc );
return 0;
}
/* /*
=========== ===========
QE_LoadProject QE_LoadProject

View file

@ -337,6 +337,8 @@ qboolean QE_KeyDown( int key, int nFlags = 0 );
// does some sanity checks on the project entity, such as removing ending filename seperators from paths // does some sanity checks on the project entity, such as removing ending filename seperators from paths
// (this usually gets propagated to the actual project file since most of the time we save right after calling the check) // (this usually gets propagated to the actual project file since most of the time we save right after calling the check)
void QE_CheckProjectEntity(); void QE_CheckProjectEntity();
// peek in a project file to retrieve the version key
int QE_GetTemplateVersionForProject( const char * projectfile );
// this will load a new project entity in memory, and potentially process it from a template // this will load a new project entity in memory, and potentially process it from a template
// NOTE TTimo calling QE_LoadProject won't take care of the various initialisation that are performed depending on the project settings // NOTE TTimo calling QE_LoadProject won't take care of the various initialisation that are performed depending on the project settings
// you should then call QE_Init for that // you should then call QE_Init for that