コード例 #1
0
ファイル: app.cpp プロジェクト: zer0infinity/OGR2GUI
void App::initData(void) {
    QFile resFormats(":/formats");
    QFile resDatabases(":/databases");
    QFile resWebServices(":/webservices");
    readResources(resFormats, formatsListReadOnly, formatsListReadWrite);
    readResources(resDatabases, databaseListReadOnly, databaseListReadWrite);
    readResources(resWebServices, webServiceList);
}
コード例 #2
0
ファイル: erffile.cpp プロジェクト: Hellzed/xoreos
void ERFFile::load() {
	Common::File erf;
	open(erf);

	readHeader(erf);

	if ((_id != kERFID) && (_id != kMODID) && (_id != kHAKID) && (_id != kSAVID))
		throw Common::Exception("Not an ERF file");

	if ((_version != kVersion1) && (_version != kVersion2))
		throw Common::Exception("Unsupported ERF file version %08X", _version);

	if ((_version == kVersion2) && !_utf16le)
		throw Common::Exception("ERF file version 2.0, but not UTF-16LE");

	try {

		ERFHeader erfHeader;

		readERFHeader  (erf, erfHeader);
		readDescription(erf, erfHeader);

		if (!_noResources)
			readResources(erf, erfHeader);

		if (erf.err())
			throw Common::Exception(Common::kReadError);

	} catch (Common::Exception &e) {
		e.add("Failed reading ERF file");
		throw e;
	}

}
コード例 #3
0
ファイル: boardbuilder.cpp プロジェクト: Commnets/QGAMES
// ---
QGAMES::Board* QGAMES::BasicBoardAddsOn::createBoard 
	(const QGAMES::BoardBuilder::BoardDefinition& def, const std::string& bP)
{
	TiXmlDocument doc (def._fileDefinition.c_str ());
	int e = doc.LoadFile ();
	assert (e); // Is it a valid doc?

	TiXmlElement* rootElement = doc.RootElement ();
	assert (rootElement); // One element minimum...

	// Read all parts of the file defining the 
	QGAMES::BoardResources resources; QGAMES::BoardSquares squares;
	std::list <QGAMES::BasicBoardAddsOn::SquareConnectionDefinition> connections;
	for (TiXmlElement* groupElement = rootElement -> FirstChildElement ();
		groupElement != NULL; groupElement = groupElement -> NextSiblingElement ())
	{
		if (strcmp (groupElement -> Value (), __QGAMES_BOARDRESOURCESTAG__) == 0)
			resources = createBoardResources (readResources (groupElement));
		if (strcmp (groupElement -> Value (), __QGAMES_BOARDSQUARESTAG__) == 0)
			squares = createBoardSquares (readSquares (groupElement));
		if (strcmp (groupElement -> Value (), __QGAMES_BOARDSQUARECONNECTIONSTAG__) == 0)
			connections = readConnections (groupElement);
	}

	// Once everything has been read, the instance is created...
	// and then the squares connected.
	QGAMES::Board* result = createBoardInstance (def._id, squares, resources); 
	setConnections (squares, connections);
	return (result); // The result is returned!
}
コード例 #4
0
ファイル: boardbuilder.cpp プロジェクト: Commnets/QGAMES
// ---
std::map <int, QGAMES::BasicBoardAddsOn::SquareDefinition> 
	QGAMES::BasicBoardAddsOn::readSquares (TiXmlElement* e)
{
	std::map <int, QGAMES::BasicBoardAddsOn::SquareDefinition> result;

	for (TiXmlElement* element = e -> FirstChildElement ();
		element != NULL; element = element -> NextSiblingElement ())
	{
		QGAMES::BasicBoardAddsOn::SquareDefinition def;
		element -> Attribute (__QGAMES_BOARDSQUAREATTRID__, &def._id);
		for (TiXmlElement* subElement = element -> FirstChildElement ();
			subElement != NULL; subElement = subElement -> NextSiblingElement ())
		{
			if (strcmp (subElement -> Value (), __QGAMES_BOARDRESOURCESTAG__) == 0)
				def._resources = readResources (subElement);
			if (strcmp (subElement -> Value (), __QGAMES_BOARDDATASTAG__) == 0)
				def._properties = readProperties (subElement);
		}

		result.insert (std::map <int, 
			QGAMES::BasicBoardAddsOn::SquareDefinition>::value_type (def._id, def));
	}

	return (result);
}
コード例 #5
0
ファイル: dmgfile.c プロジェクト: hamstergene/libdmg-hfsplus
io_func* openDmgFile(AbstractFile* abstractIn) {
	off_t fileLength;
	DMG* dmg;	
	ResourceData* blkx;
	ResourceData* curData;
	
	io_func* toReturn;

	if(abstractIn == NULL) {
		return NULL;
	}

    dmg = (DMG*) malloc(sizeof(DMG));
	dmg->dmg = abstractIn;

	fileLength = abstractIn->getLength(abstractIn);
	abstractIn->seek(abstractIn, fileLength - sizeof(UDIFResourceFile));
	readUDIFResourceFile(abstractIn, &dmg->resourceFile);
	
    dmg->resourceXML = malloc(dmg->resourceFile.fUDIFXMLLength + 1);
    ASSERT( abstractIn->seek(abstractIn, (off_t)(dmg->resourceFile.fUDIFXMLOffset)) == 0, "fseeko" );
    ASSERT( abstractIn->read(abstractIn, dmg->resourceXML, (size_t)dmg->resourceFile.fUDIFXMLLength) == (size_t)dmg->resourceFile.fUDIFXMLLength, "fread" );
    dmg->resourceXML[dmg->resourceFile.fUDIFXMLLength] = 0;
    
	dmg->resources = readResources(dmg->resourceXML, dmg->resourceFile.fUDIFXMLLength);
	dmg->numBLKX = 0;
	
	blkx = (getResourceByKey(dmg->resources, "blkx"))->data;
	
	curData = blkx;
	while(curData != NULL) {
		dmg->numBLKX++;
		curData = curData->next;	
	}
	
	dmg->blkx = (BLKXTable**) malloc(sizeof(BLKXTable*) * dmg->numBLKX);
	
	int i = 0;
	while(blkx != NULL) {
		dmg->blkx[i] = (BLKXTable*)(blkx->data);
		i++;
		blkx = blkx->next;
	}

	dmg->offset = 0;
	dmg->runType = BLOCK_TERMINATOR; // causes cacheOffset on first read attempt
	dmg->runData = NULL;

	toReturn = (io_func*) malloc(sizeof(io_func));
	
	toReturn->data = dmg;
	toReturn->read = &dmgFileRead;
	toReturn->write = &dmgFileWrite;
	toReturn->close = &closeDmgFile;
	
	return toReturn;
}
コード例 #6
0
ファイル: dmgfile.c プロジェクト: Ormu/xpwn
io_func* openDmgFile(AbstractFile* abstractIn) {
	off_t fileLength;
	UDIFResourceFile resourceFile;
	DMG* dmg;	
	ResourceData* blkx;
	ResourceData* curData;
	int i;
	
	io_func* toReturn;

	if(abstractIn == NULL) {
		return NULL;
	}
	
	fileLength = abstractIn->getLength(abstractIn);
	abstractIn->seek(abstractIn, fileLength - sizeof(UDIFResourceFile));
	readUDIFResourceFile(abstractIn, &resourceFile);
	
	dmg = (DMG*) malloc(sizeof(DMG));
	dmg->dmg = abstractIn;
	dmg->resources = readResources(abstractIn, &resourceFile);
	dmg->numBLKX = 0;
	
	blkx = (getResourceByKey(dmg->resources, "blkx"))->data;
	
	curData = blkx;
	while(curData != NULL) {
		dmg->numBLKX++;
		curData = curData->next;	
	}
	
	dmg->blkx = (BLKXTable**) malloc(sizeof(BLKXTable*) * dmg->numBLKX);
	
	i = 0;
	while(blkx != NULL) {
		dmg->blkx[i] = (BLKXTable*)(blkx->data);
		i++;
		blkx = blkx->next;
	}

	dmg->offset = 0;
	
	dmg->runData = NULL;
	cacheOffset(dmg, 0);
	
	toReturn = (io_func*) malloc(sizeof(io_func));
	
	toReturn->data = dmg;
	toReturn->read = &dmgFileRead;
	toReturn->write = &dmgFileWrite;
	toReturn->close = &closeDmgFile;
	
	return toReturn;
}
コード例 #7
0
ファイル: mainwindow.cpp プロジェクト: makemeunsee/kiten-plus
void MainWindow::setUserResourceDir(const QString &dirname)
{
    resourceDir = QDir(dirname);
    readResources();
}
コード例 #8
0
ファイル: cpm.c プロジェクト: atluxity/cpm
/* if don't have any envorin variable at all */
int main(int argc, char **argv, char **envp)
#endif
#endif
  {
    rlim_t              memlock_limit = -2;
    int                 error = 0,
                        max_mem_lock = 0,
                        memory_safe = 0,
                        ptrace_safe = 0;
#ifdef TEST_OPTION
    int                 testrun = 0;
#endif
    char*               binaryname;

    savetermios();
    TRACE(99, "main()", NULL);

#ifndef HAVE_EXTERN_ENVIRON
#ifndef MANUAL_EXTERN_ENVIRON
    /* since in solaris environ does not exist, we manually pass it along */
    environ = envp;
#endif
#endif

    if (initSecurity(&max_mem_lock, &memory_safe, &ptrace_safe, &memlock_limit))
      { exit(1); }

    /* we initialize gettext */
    setlocale(LC_ALL, "");
#ifdef TEST_OPTION
    bindtextdomain(PACKAGE_NAME, "./po/");
#else
    bindtextdomain(PACKAGE_NAME, LOCALEDIR);
#endif
    textdomain(PACKAGE_NAME);

#ifndef LIBXML_TREE_ENABLED
    fprintf(stderr, _("Tree support not compiled in to libxml2 %s\n"),
        LIBXML_DOTTED_VERSION);
    exit(1);
#endif

    /*
     * This function installs "sighandler" to handle the SIGINT and returns a
     * pointer to the previously installed handler for this signal (which is
     * the default handler SIG_DFL initially). If we try to install another
     * handler to handle SIGINT at some other time... Then the new handler
     * replaces this current one and returns a pointer to this handler.
     */
    signal(SIGINT, sighandler);
    signal(SIGTERM, sighandler);
    /* the SIGWINCH handler is set in userInterface() */

    initConfiguration();

    runtime -> memlock_limit  = memlock_limit;
    runtime -> max_mem_lock   = max_mem_lock;
    runtime -> memory_safe    = memory_safe;
    runtime -> ptrace_safe    = ptrace_safe;

    initKeys();
    initPatternparser();
    initXML();
    initXMLInterface();

    if (getOptions(argc, argv))
      {
        fprintf(stderr, _("Try `%s --help' for more information.\n"), argv[0]);
        error = 1;
      }
    if (!error && config -> help)
      { showHelp(); }
    else if (!error && config -> version)
      { showVersion(); }
    else if (!error)
      {
        getDefaultOptions();
        if (readResources())
            return 1;

        if (config -> dbfilecmd)
          {   /* the --file option must overwrite the resource file */
            runtime -> dbfile = resolveFilelink(config -> dbfilecmd);
          }
        else
          {   /* we use the resource file configuration or the compiletime
               * default
               */
            runtime -> dbfile = resolveFilelink(config -> dbfilerc);
          }
      }

    /* we switch to read-only mode on request */
    if (config -> readonly)
      { runtime -> readonly = 1; }

    /* in case our basename is cpmv, we switch to read-only mode */
    binaryname = basename(argv[0]);
    if (!strcmp(binaryname, "cpmv"))
      { runtime -> readonly = 1; }

    initGPG();

    if (!error && config -> security)
      { checkSecurity(0); }

#ifdef TEST_OPTION
    if (!error &&
        config -> testrun &&
        !strncmp(config -> testrun, "compress", 8))
      {
        testCompress();
        testrun = 1;
      }
    if (!error &&
        config -> testrun &&
        !strcmp(config -> testrun, "environment"))
      {
        testEnvironment();
        testrun = 1;
      }
    if (!error &&
        config -> testrun && (
        !strcmp(config -> testrun, "backup") ||
        !strcmp(config -> testrun, "garbage") ||
        !strcmp(config -> testrun, "searchpattern")))
      { testrun = 1; }
#endif

    if (config -> configtest &&
        !error)
      { fprintf(stderr, _("configuration ok.\n")); }

    if (config -> environtmentlist &&
        !error)
      { listEnvironment(); }

    if (!error &&
        !config -> configtest &&
        !config -> environtmentlist &&
        !config -> help &&
        !config -> security &&
        !config -> version)
      {
#ifdef TEST_OPTION
        if (checkSecurity(1) != MAX_SECURITY_LEVEL &&
            !config -> testrun)
#else
        if (checkSecurity(1) != MAX_SECURITY_LEVEL)
#endif
          {
            checkSecurity(0);
            printf("\n%s %s\n%s\n",
                _("Maximum security level not reached."),
                _("Your database will be less protected while CPM is running."),
                _("Are you sure you want to continue?"),
                _("Press CTRL+C to stop now or ENTER to continue."));

            fgetc(stdin);
          }
        if (runtime -> guimode)
          {   /* we run in interactive mode */
            userInterface();
          }
        else
          {   /* we run in CLI mode */
            error = cliInterface();
#ifdef TEST_OPTION
            if (error == 2)
              {   /* for testruns, we must modify the stuff a little */
                error = 0;
                testrun = 1;
              }
#endif
          }
      }

    freeGPG();
    freeXMLInterface();
    freeUTF8Interface();
    freeXML();
    freePatternparser();
    freeKeys();
    freeConfiguration();

    if (memCheck())
      {   /* we validate our memory consumption */
        fprintf(stderr, _("error: memory leak detected.\n"));
        if (memCheck() > 0)
          {
            fprintf(stderr, _("%ld byte of memory were not freed.\n"),
                memCheck());
          }
        else
          {
            fprintf(stderr,
                _("%ld byte of memory were freed without being allocated.\n"),
                memCheck());
          }

        fprintf(stderr, _("Please send a report about this problem to Harry Brueckner <*****@*****.**>.\n"));

        error = 1;
      }

#ifdef TEST_OPTION
    if (testrun)
      { return 0; }
    else
      { return error; }
#else
    return error;
#endif
  }