Ejemplo n.º 1
0
void ResourceManager::RemoveCacheFile(const ieResRef resref, SClass_ID ClassID)
{
	char filename[_MAX_PATH];

	PathJoinExt(filename, core->CachePath, resref, core->TypeExt(ClassID));
	unlink (filename);

	PathJoinExt(filename, resref, core->TypeExt(ClassID));
	cacheMap.remove(filename);
}
Ejemplo n.º 2
0
bool FileStream::Create(const char *folder, const char* fname, SClass_ID ClassID)
{
	char path[_MAX_PATH];
	char filename[_MAX_PATH];
	ExtractFileFromPath( filename, fname );
	PathJoinExt(path, folder, filename, core->TypeExt(ClassID));
	return Create(path);
}
Ejemplo n.º 3
0
/*
 * Return true if directory Path/slotname is a potential save game
 * slot, otherwise return false.
 */
static bool IsSaveGameSlot(const char* Path, const char* slotname)
{
	char savegameName[_MAX_PATH];
	int savegameNumber = 0;

	if (slotname[0] == '.')
		return false;

	int cnt = sscanf( slotname, SAVEGAME_DIRECTORY_MATCHER, &savegameNumber, savegameName );
	if (cnt != 2) {
		//The matcher didn't match: either this is not a valid dir
		//or the SAVEGAME_DIRECTORY_MATCHER needs updating.
		printMessage("SaveGameIterator", "Invalid savegame directory '%s' in %s.\n", LIGHT_RED,
			slotname, Path);
		return false;
	}

	//The matcher got matched correctly.
	char dtmp[_MAX_PATH];
	PathJoin(dtmp, Path, slotname, NULL);

	char ftmp[_MAX_PATH];
	PathJoinExt(ftmp, dtmp, core->GameNameResRef, "bmp");

	if (access( ftmp, R_OK )) {
		printMessage("SaveGameIterator", "Ignoring slot %s because of no appropriate preview!\n", YELLOW, dtmp);
		return false;
	}

	PathJoinExt(ftmp, dtmp, core->WorldMapName[0], "wmp");
	if (access( ftmp, R_OK )) {
		printMessage("SaveGameIterator", "Ignoring slot %s because of no appropriate worldmap!\n", YELLOW, dtmp);
		return false;
	}

	/* we might need something here as well
	PathJoinExt(ftmp, dtmp, core->WorldMapName[1], "wmp");
	if (access( ftmp, R_OK )) {
		printMessage("SaveGameIterator", "Ignoring slot %s because of no appropriate worldmap!\n", YELLOW, dtmp);
		return false;
	}
	*/

	return true;
}
SaveGame::SaveGame(const char* path, const char* name, const char* prefix, const char* slotname, int pCount, int saveID)
{
	strncpy( Prefix, prefix, sizeof( Prefix ) );
	strncpy( Path, path, sizeof( Path ) );
	strncpy( Name, name, sizeof( Name ) );
	strncpy( SlotName, slotname, sizeof( SlotName ) );
	PortraitCount = pCount;
	SaveID = saveID;
	char nPath[_MAX_PATH];
	struct stat my_stat;
	PathJoinExt(nPath, Path, Prefix, "bmp");
	memset(&my_stat,0,sizeof(my_stat));
	stat( nPath, &my_stat );
	strftime( Date, _MAX_PATH, "%c", localtime( &my_stat.st_mtime ) );
	manager.AddSource(Path, Name, PLUGIN_RESOURCE_DIRECTORY);
	GameDate[0] = '\0';
}
Ejemplo n.º 5
0
SaveGame::SaveGame(const char* path, const char* name, const char* prefix, const char* slotname, int pCount, int saveID)
{
	strlcpy( Prefix, prefix, sizeof( Prefix ) );
	strlcpy( Path, path, sizeof( Path ) );
	strlcpy( Name, name, sizeof( Name ) );
	strlcpy( SlotName, slotname, sizeof( SlotName ) );
	PortraitCount = pCount;
	SaveID = saveID;
	char nPath[_MAX_PATH];
	struct stat my_stat;
	PathJoinExt(nPath, Path, Prefix, "bmp");
	memset(&my_stat,0,sizeof(my_stat));
	if (stat(nPath, &my_stat)) {
		Log(ERROR, "SaveGameIterator", "Stat call failed, using dummy time!");
		strlcpy(Date, "Sun 31 Feb 00:00:01 2099", _MAX_PATH);
	} else {
		strftime(Date, _MAX_PATH, "%c", localtime((time_t*)&my_stat.st_mtime));
	}
	manager.AddSource(Path, Name, PLUGIN_RESOURCE_DIRECTORY);
	GameDate[0] = '\0';
}
Ejemplo n.º 6
0
/*
Currently unused. does not compile under MSVC.

FIXME: if we need this we should consider having one version of GetValueForKey call the other

const std::string* InterfaceConfig::GetValueForKey(std::string* key) const
{
	const std::string* value = NULL;
	if (key) {
		std::string* keyCopy = key;
		std::transform(keyCopy->begin(), keyCopy->end(), keyCopy->begin(),
					   (int(*)(int)) std::tolower);
		value = configVars->get(keyCopy->c_str());
		delete keyCopy;
	}
	return value;
}
*/	
CFGConfig::CFGConfig(int argc, char *argv[])
	: InterfaceConfig(argc, argv)
{
	isValid = false;
	FileStream* config = new FileStream();
	// skip arg0 (it is just gemrb)
	for (int i=1; i < argc; i++) {
		if (stricmp(argv[i], "-c") == 0) {
			const char* filename = argv[++i];

			if (!config->Open(filename)) {
				// Explicitly specified cfg file HAS to be present
				Log(FATAL, "Config", "Failed to open config file \"%s\".", filename);
			}
			isValid = InitWithINIData(config);
		}
	}
	if (!isValid) {
		// nothing passed in on CLI, so search for gemrb.cfg
		char datadir[_MAX_PATH];
		char path[_MAX_PATH];
		char name[_MAX_PATH];

		// Find basename of this program. It does the same as basename (3),
		// but that's probably missing on some archs
		char* appName = strrchr( argv[0], PathDelimiter );
		if (appName) {
			appName++;
		} else {
			appName = argv[0];
		}

		strcpy( name, appName );
		assert(name[0]);

#if TARGET_OS_MAC
		// CopyGemDataPath would give us bundle resources dir
		CopyHomePath(datadir, _MAX_PATH);
		PathAppend(datadir, PACKAGE);
#else
		CopyGemDataPath(datadir, _MAX_PATH);
#endif
		PathJoinExt( path, datadir, name, "cfg" );

#define ATTEMPT_INIT \
if (config->Open(path) \
	&& InitWithINIData(config)) { \
		goto done; \
	}

		ATTEMPT_INIT;

#ifdef SYSCONF_DIR
		PathJoinExt( path, SYSCONF_DIR, name, "cfg" );
		ATTEMPT_INIT
#endif

		// Now try ~/.gemrb folder
		CopyHomePath(datadir, _MAX_PATH);
		char confpath[_MAX_PATH] = ".";
		strcat(confpath, name);
		PathJoin(datadir, datadir, confpath, NULL);
		PathJoinExt( path, datadir, name, "cfg" );
		ATTEMPT_INIT;

		// Don't try with default binary name if we have tried it already
		if (strcmp( name, PACKAGE ) != 0) {
			PathJoinExt( path, datadir, PACKAGE, "cfg" );

			ATTEMPT_INIT;

#ifdef SYSCONF_DIR
			PathJoinExt( path, SYSCONF_DIR, PACKAGE, "cfg" );
			ATTEMPT_INIT;
#endif
		}
		// if all else has failed try current directory
		PathJoinExt(path, "./", PACKAGE, "cfg");
		ATTEMPT_INIT;
	}
#undef ATTEMPT_INIT
done:
	delete config;
}