Ejemplo n.º 1
0
/* loadConfigFile
 *
 * Returns 0 - successful.
 *		  -1 - unsuccesful.
 */
int loadConfigFile (const char *configFile, config_file_t *config)
{
	int fd, count;

	if ((fd = open_bvdev("bt(0,0)", configFile, 0)) < 0) {
		return -1;
	}
	// read file
	count = read(fd, config->plist, IO_CONFIG_DATA_SIZE);
	close(fd);
	
	// build xml dictionary
	ParseXMLFile(config->plist, &config->dictionary);
	return 0;
}
Ejemplo n.º 2
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;
}
Ejemplo n.º 3
0
int initGUI()
{
	int len;
	char dirspec[256];

	

#ifdef EMBED_THEME

	config_file_t *embedded = &bootInfo->themeDefault;

	// build xml dictionary for embedded theme.plist
	ParseXMLFile( (char *) __theme_plist, &embedded->dictionary);

	// determine screen params form edid
	getResolution(&screen_params[0], &screen_params[1], &screen_params[2]);


	
#else

	/*
	 * Return Error since GUI can't run when embedtheme is not used.
	 */
	
	return 1;
	
#endif

  // Initalizing GUI strucutre.
  bzero(&gui, sizeof(gui_t));
	
	
	// find theme name in boot.plist
	getValueForKey( "Theme", &theme_name, &len, &bootInfo->bootConfig );
	
	sprintf(dirspec, "/Extra/Themes/%s/theme.plist", theme_name);

	loadConfigFile(dirspec, &bootInfo->themeConfig);


	// find best matching vesa mode for our requested width & height
	getGraphicModeParams(screen_params);

	// set our screen structure with the mode width & height
	gui.screen.width = screen_params[0];	
	gui.screen.height = screen_params[1];
	
	// load graphics otherwise fail and return
	if( !loadGraphics() )
	{
		// set embedded theme.plist as defaults
		loadThemeValues(&bootInfo->themeDefault, YES);
		
		// set user overides
		loadThemeValues(&bootInfo->themeConfig, NO);
		
		colorFont(&font_small,   gui.screen.font_small_color);
		colorFont(&font_console, gui.screen.font_console_color);
		
		// create the screen & window buffers
		if( !createBackBuffer( &gui.screen ) )
			if( !createWindowBuffer( &gui.screen ) )
				if( !createWindowBuffer( &gui.devicelist ) )
					if( !createWindowBuffer( &gui.bootprompt ) )
						if( !createWindowBuffer( &gui.infobox ) )
							if( !createWindowBuffer( &gui.menu ) ) 
							{							
								drawBackground();

								// lets copy the screen into the back buffer
								memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );

								setVideoMode( GRAPHICS_MODE, 0 );
								
								gui.initialised = YES;
									
								return 0;
							}	
	}

	// something went wrong
	return 1;
}
Ejemplo n.º 4
0
Archivo: gui.c Proyecto: JrCs/Chameleon
int initGUI(void)
{
	int		val;
#ifdef EMBED_THEME
	config_file_t	*config;
	
	config = &bootInfo->themeConfig;
	if (ParseXMLFile((char *)__theme_plist, &config->dictionary) != 0) {
		return 1;
	}
#else
	int	len;
	char	dirspec[256];

	getValueForKey( "Theme", &theme_name, &len, &bootInfo->bootConfig );
	if ((strlen(theme_name) + 27) > sizeof(dirspec)) {
		return 1;
	}
	sprintf(dirspec, "/Extra/Themes/%s/theme.plist", theme_name);
	if (loadConfigFile(dirspec, &bootInfo->themeConfig) != 0) {
		return 1;
	}
#endif
	// parse display size parameters
	if (getIntForKey("screen_width", &val, &bootInfo->themeConfig)) {
		screen_params[0] = val;
	}
	if (getIntForKey("screen_height", &val, &bootInfo->themeConfig)) {
		screen_params[1] = val;
	}
	screen_params[2] = 32;

	// Initalizing GUI strucutre.
	bzero(&gui, sizeof(gui_t));
	
	// find best matching vesa mode for our requested width & height
	getGraphicModeParams(screen_params);

	// set our screen structure with the mode width & height
	gui.screen.width = screen_params[0];	
	gui.screen.height = screen_params[1];

	// load graphics otherwise fail and return
	if (loadGraphics() == 0) {
		loadThemeValues(&bootInfo->themeConfig, true);
		colorFont(&font_small, gui.screen.font_small_color);
		colorFont(&font_console, gui.screen.font_console_color);

		// create the screen & window buffers
		if (createBackBuffer(&gui.screen) == 0) {
			if (createWindowBuffer(&gui.screen) == 0) {
				if (createWindowBuffer(&gui.devicelist) == 0) {
					if (createWindowBuffer(&gui.bootprompt) == 0) {
						if (createWindowBuffer(&gui.infobox) == 0) {
							if (createWindowBuffer(&gui.menu) == 0) {							
								drawBackground();
								// lets copy the screen into the back buffer
								memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );
								setVideoMode( GRAPHICS_MODE, 0 );
								gui.initialised = true;
								return 0;
							}
						}
					}
				}
			}
		}
	}
	return 1;
}
Ejemplo n.º 5
0
/*
   ===========
   QE_LoadProject
   NOTE: rather than bumping "version", consider bumping "template_version" (see above)
   NOTE: when QE_LoadProject is called, the prefs are updated with path to the latest project and saved on disk
   ===========
 */
bool QE_LoadProject( const char *projectfile ){
	char buf[1024];
	xmlDocPtr doc;
	xmlNodePtr node, project;

	Sys_Printf( "Loading project file: \"%s\"\n", projectfile );
	doc = ParseXMLFile( projectfile, true );

	if ( doc == NULL ) {
		return false;
	}

	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\n" );
		return false;
	}

	while ( node->type != XML_ELEMENT_NODE ) node = node->next;
	// <project>
	project = node;

	if ( g_qeglobals.d_project_entity != NULL ) {
		Entity_Free( g_qeglobals.d_project_entity );
	}
	g_qeglobals.d_project_entity = Entity_Alloc();

	for ( node = project->children; node != NULL; node = node->next )
	{
		if ( node->type != XML_ELEMENT_NODE ) {
			continue;
		}

		// <key>
		ReplaceTemplates( buf, (char*)node->properties->next->children->content );

		SetKeyValue( g_qeglobals.d_project_entity, (char*)node->properties->children->content, buf );
	}

	xmlFreeDoc( doc );

	// project file version checking
	// add a version checking to avoid people loading later versions of the project file and bitching
	int ver = IntForKey( g_qeglobals.d_project_entity, "version" );
	if ( ver > PROJECT_VERSION ) {
		char strMsg[1024];
		sprintf( strMsg, "This is a version %d project file. This build only supports <=%d project files.\n"
						 "Please choose another project file or upgrade your version of Radiant.", ver, PROJECT_VERSION );
		gtk_MessageBox( g_pParentWnd->m_pWidget, strMsg, "Can't load project file", MB_ICONERROR | MB_OK );
		// set the project file to nothing so we are sure we'll ask next time?
		g_PrefsDlg.m_strLastProject = "";
		g_PrefsDlg.SavePrefs();
		return false;
	}

	// set here some default project settings you need
	if ( strlen( ValueForKey( g_qeglobals.d_project_entity, "brush_primit" ) ) == 0 ) {
		SetKeyValue( g_qeglobals.d_project_entity, "brush_primit", "0" );
	}

	g_qeglobals.m_bBrushPrimitMode = IntForKey( g_qeglobals.d_project_entity, "brush_primit" );

	g_qeglobals.m_strHomeMaps = g_qeglobals.m_strHomeGame;
	const char* str = ValueForKey( g_qeglobals.d_project_entity, "gamename" );
	if ( str[0] == '\0' ) {
		str = g_pGameDescription->mBaseGame.GetBuffer();
	}
	g_qeglobals.m_strHomeMaps += str;
	g_qeglobals.m_strHomeMaps += '/';

	// don't forget to create the dirs
	Q_mkdir( g_qeglobals.m_strHomeGame.GetBuffer(), 0775 );
	Q_mkdir( g_qeglobals.m_strHomeMaps.GetBuffer(), 0775 );

	// usefull for the log file and debuggin f****d up configurations from users:
	// output the basic information of the .qe4 project file
	// SPoG
	// all these paths should be unix format, with a trailing slash at the end
	// if not.. to debug, check that the project file paths are set up correctly
	Sys_Printf( "basepath    : %s\n", ValueForKey( g_qeglobals.d_project_entity, "basepath" ) );
	Sys_Printf( "entitypath  : %s\n", ValueForKey( g_qeglobals.d_project_entity, "entitypath" ) );


	// check whether user_project key exists..
	// if not, save the current project under a new name
	if ( ValueForKey( g_qeglobals.d_project_entity, "user_project" )[0] == '\0' ) {
		Sys_Printf( "Loaded a template project file\n" );

		// create the user_project key
		SetKeyValue( g_qeglobals.d_project_entity, "user_project", "1" );

		if ( IntForKey( g_qeglobals.d_project_entity, "version" ) != PROJECT_VERSION ) {
			char strMsg[2048];
			sprintf( strMsg,
					 "The template project '%s' has version %d. The editor binary is configured for version %d.\n"
					 "This indicates a problem in your setup.\n"
					 "I will keep going with this project till you fix this",
					 projectfile, IntForKey( g_qeglobals.d_project_entity, "version" ), PROJECT_VERSION );
			gtk_MessageBox( g_pParentWnd->m_pWidget, strMsg, "Can't load project file", MB_ICONERROR | MB_OK );
		}

		// create the writable project file path
		strcpy( buf, g_qeglobals.m_strHomeGame.GetBuffer() );
		strcat( buf, g_pGameDescription->mBaseGame.GetBuffer() );
		strcat( buf, "/scripts/" );
		// while the filename is already in use, increment the number we add to the end
		int counter = 0;
		char pUser[PATH_MAX];
		while ( 1 )
		{
			sprintf( pUser, "%suser%d." PROJECT_FILETYPE, buf, counter );
			counter++;
			if ( access( pUser, R_OK ) != 0 ) {
				// this is the one
				strcpy( buf, pUser );
				break;
			}
		}
		// saving project will cause a save prefs
		g_PrefsDlg.m_strLastProject = buf;
		g_PrefsDlg.m_nLastProjectVer = IntForKey( g_qeglobals.d_project_entity, "version" );
		QE_SaveProject( buf );
	}
	else
	{
		// update preferences::LastProject with path of this successfully-loaded project
		// save preferences
		Sys_Printf( "Setting current project in prefs to \"%s\"\n", g_PrefsDlg.m_strLastProject.GetBuffer() );
		g_PrefsDlg.m_strLastProject = projectfile;
		g_PrefsDlg.SavePrefs();
	}

	return true;
}
Ejemplo n.º 6
0
/* Returns 0 if requested config files were loaded,
 *         1 if default files were loaded,
 *        -1 if no files were loaded.
 * Prints error message if files cannot be loaded.
 */
int
loadSystemConfig(
    const char *which,
    int size
)
{
    char *buf, *bp;
    const char *cp;
    int ret, len, doDefault=0;

    buf = bp = malloc(512);
    if (which && size) {
        for(cp = which, len = size; len && *cp && *cp != LP; cp++, len--) ;
        if (*cp == LP) {
            while (len-- && *cp && *cp++ != RP) ;
            /* cp now points past device */
            strlcpy(buf,which,cp - which + 1);
            bp += cp - which;
        } else {
            cp = which;
            len = size;
        }
        if (*cp != '/') {
            strcpy(bp, systemConfigDir());
            strcat(bp, "/");
            strncat(bp, cp, len);
            if (strncmp(cp + len - strlen(CONFIG_EXT),
                        CONFIG_EXT, strlen(CONFIG_EXT)) != 0)
                strcat(bp, CONFIG_EXT);
        } else {
            strlcpy(bp, cp, len + 1);
        }
        if ((strcmp(bp, SYSTEM_CONFIG_PATH) == 0)) {
            doDefault = 1;
        }
        bp = buf;
        ret = loadConfigFile(bp);
    } else {
        /* First try LRE file */
        strcpy(bp, systemConfigDir());
        strcat(bp, LRE_CONFIG_FILE);
        ret = loadConfigFile(bp);

        if (ret < 0) {
            /* If not found, try default file */
            strcpy(bp, systemConfigDir());
            strcat(bp, SYSTEM_CONFIG_FILE);
            ret = loadConfigFile(bp);
        }
    }
    if (ret < 0) {
	error("System config file '%s' not found\n", bp);
	sleep(1);
    } else {
	sysConfigValid = 1;
        // Check for XML file;
        // if not XML, gConfigDict will remain 0.
        ParseXMLFile(bootArgs->config, &gConfigDict);
    }
    free(buf);
    return (ret < 0 ? ret : doDefault);
}