예제 #1
0
static void dump(PakDirectory & dir, const fs::path & dirname = fs::path()) {
	
	if(!fs::create_directories(dirname)) {
		LogWarning << "Failed to create target directory";
	}
	
	for(PakDirectory::files_iterator i = dir.files_begin(); i != dir.files_end(); ++i) {
		
		fs::path filenameISO = dirname / i->first;
		
		PakFile * file = i->second;
		
#if ARX_PLATFORM == ARX_PLATFORM_WIN32
		std::string filename = filenameISO.string();
#else
		std::string filename = util::convert<util::ISO_8859_1, util::UTF8>(filenameISO.string().c_str());
#endif
		
		printf("%s\n", filename.c_str());
		
		fs::ofstream ofs(filename, fs::fstream::out | fs::fstream::binary | fs::fstream::trunc);
		if(!ofs.is_open()) {
			printf("error opening file for writing: %s\n", filename.c_str());
			exit(1);
		}
		
		if(file->size() > 0) {
			
			char * data = (char*)file->readAlloc();
			arx_assert(data != NULL);
			
			if(ofs.write(data, file->size()).fail()) {
				printf("error writing to file: %s\n", filename.c_str());
				exit(1);
			}
			
			free(data);
			
		}
		
	}
	
	for(PakDirectory::dirs_iterator i = dir.dirs_begin(); i != dir.dirs_end(); ++i) {
		dump(i->second, dirname / i->first);
	}
	
}
예제 #2
0
void dump(PakDirectory & dir, const fs::path & dirname = fs::path()) {
	
	fs::create_directories(dirname);
	
	for(PakDirectory::files_iterator i = dir.files_begin(); i != dir.files_end(); ++i) {
		
		fs::path filename = dirname / i->first;
		
		PakFile * file = i->second;
		
		printf("%s\n", filename.string().c_str());
		
		fs::ofstream ofs(filename, fs::fstream::out | fs::fstream::binary | fs::fstream::trunc);
		if(!ofs.is_open()) {
			printf("error opening file for writing: %s\n", filename.string().c_str());
			exit(1);
		}
		
		if(file->size() > 0) {
			
			char * data = (char*)file->readAlloc();
			arx_assert(data != NULL);
			
			if(ofs.write(data, file->size()).fail()) {
				printf("error writing to file: %s\n", filename.string().c_str());
				exit(1);
			}
			
			free(data);
			
		}
		
	}
	
	for(PakDirectory::dirs_iterator i = dir.dirs_begin(); i != dir.dirs_end(); ++i) {
		dump(i->second, dirname / i->first);
	}
	
}
예제 #3
0
static EERIE_MULTI3DSCENE * PAK_MultiSceneToEerie_Impl(const res::path & dirr) {
	
	EERIE_MULTI3DSCENE * es = allocStructZero<EERIE_MULTI3DSCENE>();
	
	LastLoadedScene = dirr;
	
	PakDirectory * dir = resources->getDirectory(dirr);
	if(dir) {
		bool loaded = false;
		for(PakDirectory::files_iterator i = dir->files_begin(); i != dir->files_end(); i++) {
			if(!res::path(i->first).has_ext("scn")) {
				continue;
			}
			
			char * adr = i->second->readAlloc();
			if(adr) {
				es->scenes[es->nb_scenes] = ScnToEerie(adr, i->second->size(), dirr);
				es->nb_scenes++;
				free(adr);
			} else {
				LogError << "Could not read scene " << dirr << '/' << i->first;
			}
			
			loaded = true;
		}
		if(!loaded) {
			LogWarning << "Empty multiscene: " << dirr;
		}
	} else {
		LogWarning << "Multiscene not found: " << dirr;
	}
	
	es->cub.xmax = -9999999999.f;
	es->cub.xmin = 9999999999.f;
	es->cub.ymax = -9999999999.f;
	es->cub.ymin = 9999999999.f;
	es->cub.zmax = -9999999999.f;
	es->cub.zmin = 9999999999.f;
	
	for(long i = 0; i < es->nb_scenes; i++) {
		es->cub.xmax = std::max(es->cub.xmax, es->scenes[i]->cub.xmax);
		es->cub.xmin = std::min(es->cub.xmin, es->scenes[i]->cub.xmin);
		es->cub.ymax = std::max(es->cub.ymax, es->scenes[i]->cub.ymax);
		es->cub.ymin = std::min(es->cub.ymin, es->scenes[i]->cub.ymin);
		es->cub.zmax = std::max(es->cub.zmax, es->scenes[i]->cub.zmax);
		es->cub.zmin = std::min(es->cub.zmin, es->scenes[i]->cub.zmin);
		es->pos = es->scenes[i]->pos;
		
		if((es->scenes[i]->point0.x != -999999999999.f) &&
		   (es->scenes[i]->point0.y != -999999999999.f) &&
		   (es->scenes[i]->point0.z != -999999999999.f)) {
			es->point0 = es->scenes[i]->point0;
		}
	}
	
	if(es->nb_scenes == 0) {
		free(es);
		return NULL;
	}
	
	return es;
}
예제 #4
0
static PakFile * autodetectLanguage() {
	
	PakDirectory * dir = resources->getDirectory("localisation");
	if(!dir) {
		LogCritical << "Missing 'localisation' directory. Is 'loc.pak' present?";
		return NULL;
	}
	
	std::ostringstream languages;
	PakFile * localisation = NULL;
	
	PakDirectory::files_iterator file = dir->files_begin();
	for(; file != dir->files_end(); ++file) {
		
		const std::string & name = file->first;
		
		const std::string prefix = "utext_";
		const std::string suffix = ".ini";
		if(!boost::starts_with(name, prefix) || !boost::ends_with(name, suffix)) {
			// Not a localisation file.
			continue;
		}
		
		if(name.length() <= prefix.length() + suffix.length()) {
			// Missing language name.
			continue;
		}
		
		// Extract the language name.
		size_t length = name.length() - prefix.length() - suffix.length();
		std::string language = name.substr(prefix.length(), length);
		
		if(!localisation) {
			
			localisation = file->second;
			config.language = language;
			
		} else {
			
			if(!languages.tellp()) {
				languages << config.language;
			}
			languages << ", " << language;
			
			// Prefer english if there are multiple localisations.
			if(language == "english") {
				localisation = file->second;
				config.language = language;
			}
		}
	}
	
	if(!localisation) {
		LogCritical << "Could not find any localisation file. (localisation/utext_*.ini)";
		return NULL;
	}
	
	if(languages.tellp()) {
		LogWarning << "Multiple localisations avalable: " << languages.rdbuf();
	}
	
	LogInfo << "Autodetected language: " << config.language;
	
	return localisation;
}