- new commandline options to discover and optional delete unused files in techtrees

This commit is contained in:
Mark Vejvoda
2011-03-15 15:30:28 +00:00
parent 6eab8f905e
commit 7d38aec84a
33 changed files with 609 additions and 252 deletions

View File

@@ -207,7 +207,8 @@ string Mesh::findAlternateTexture(vector<string> conversionList, string textureF
return result;
}
void Mesh::loadV2(int meshIndex, const string &dir, FILE *f, TextureManager *textureManager,bool deletePixMapAfterLoad) {
void Mesh::loadV2(int meshIndex, const string &dir, FILE *f, TextureManager *textureManager,
bool deletePixMapAfterLoad, std::map<string,int> *loadedFileList) {
this->textureManager = textureManager;
//read header
MeshHeaderV2 meshHeader;
@@ -267,6 +268,9 @@ void Mesh::loadV2(int meshIndex, const string &dir, FILE *f, TextureManager *tex
if(fileExists(texPath) == true) {
textures[mtDiffuse]= textureManager->newTexture2D();
textures[mtDiffuse]->load(texPath);
if(loadedFileList) {
(*loadedFileList)[texPath]++;
}
texturesOwned[mtDiffuse]=true;
textures[mtDiffuse]->init(textureManager->getTextureFilter(),textureManager->getMaxAnisotropy());
if(deletePixMapAfterLoad == true) {
@@ -291,7 +295,9 @@ void Mesh::loadV2(int meshIndex, const string &dir, FILE *f, TextureManager *tex
readBytes = fread(indices, sizeof(uint32)*indexCount, 1, f);
}
void Mesh::loadV3(int meshIndex, const string &dir, FILE *f, TextureManager *textureManager,bool deletePixMapAfterLoad) {
void Mesh::loadV3(int meshIndex, const string &dir, FILE *f,
TextureManager *textureManager,bool deletePixMapAfterLoad,
std::map<string,int> *loadedFileList) {
this->textureManager = textureManager;
//read header
@@ -348,6 +354,10 @@ void Mesh::loadV3(int meshIndex, const string &dir, FILE *f, TextureManager *tex
if(fileExists(texPath) == true) {
textures[mtDiffuse]= textureManager->newTexture2D();
textures[mtDiffuse]->load(texPath);
if(loadedFileList) {
(*loadedFileList)[texPath]++;
}
texturesOwned[mtDiffuse]=true;
textures[mtDiffuse]->init(textureManager->getTextureFilter(),textureManager->getMaxAnisotropy());
if(deletePixMapAfterLoad == true) {
@@ -374,8 +384,10 @@ void Mesh::loadV3(int meshIndex, const string &dir, FILE *f, TextureManager *tex
readBytes = fread(indices, sizeof(uint32)*indexCount, 1, f);
}
Texture2D* Mesh::loadMeshTexture(int meshIndex, int textureIndex, TextureManager *textureManager, string textureFile,
int textureChannelCount, bool &textureOwned, bool deletePixMapAfterLoad) {
Texture2D* Mesh::loadMeshTexture(int meshIndex, int textureIndex,
TextureManager *textureManager, string textureFile,
int textureChannelCount, bool &textureOwned, bool deletePixMapAfterLoad,
std::map<string,int> *loadedFileList) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s] #1 load texture [%s]\n",__FUNCTION__,textureFile.c_str());
@@ -400,6 +412,9 @@ Texture2D* Mesh::loadMeshTexture(int meshIndex, int textureIndex, TextureManager
texture->getPixmap()->init(textureChannelCount);
}
texture->load(textureFile);
if(loadedFileList) {
(*loadedFileList)[textureFile]++;
}
//if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s] texture loaded [%s]\n",__FUNCTION__,textureFile.c_str());
@@ -421,7 +436,7 @@ Texture2D* Mesh::loadMeshTexture(int meshIndex, int textureIndex, TextureManager
}
void Mesh::load(int meshIndex, const string &dir, FILE *f, TextureManager *textureManager,
bool deletePixMapAfterLoad) {
bool deletePixMapAfterLoad,std::map<string,int> *loadedFileList) {
this->textureManager = textureManager;
//read header
@@ -470,7 +485,8 @@ void Mesh::load(int meshIndex, const string &dir, FILE *f, TextureManager *textu
mapFullPath += mapPath;
textures[i] = loadMeshTexture(meshIndex, i, textureManager, mapFullPath,
meshTextureChannelCount[i],texturesOwned[i],deletePixMapAfterLoad);
meshTextureChannelCount[i],texturesOwned[i],
deletePixMapAfterLoad, loadedFileList);
}
flag *= 2;
}
@@ -749,10 +765,11 @@ uint32 Model::getVertexCount() const {
// ==================== io ====================
void Model::load(const string &path, bool deletePixMapAfterLoad) {
void Model::load(const string &path, bool deletePixMapAfterLoad,
std::map<string,int> *loadedFileList) {
string extension= path.substr(path.find_last_of('.')+1);
if(extension=="g3d" || extension=="G3D"){
loadG3d(path,deletePixMapAfterLoad);
loadG3d(path,deletePixMapAfterLoad,loadedFileList);
}
else{
throw runtime_error("Unknown model format: " + extension);
@@ -773,7 +790,8 @@ void Model::save(const string &path, string convertTextureToFormat,
}
//load a model from a g3d file
void Model::loadG3d(const string &path, bool deletePixMapAfterLoad) {
void Model::loadG3d(const string &path, bool deletePixMapAfterLoad,
std::map<string,int> *loadedFileList) {
try{
FILE *f=fopen(path.c_str(),"rb");
@@ -782,6 +800,10 @@ void Model::loadG3d(const string &path, bool deletePixMapAfterLoad) {
throw runtime_error("Error opening g3d model file [" + path + "]");
}
if(loadedFileList) {
(*loadedFileList)[path]++;
}
string dir= extractDirectoryPathFromFile(path);
//file header
@@ -811,7 +833,8 @@ void Model::loadG3d(const string &path, bool deletePixMapAfterLoad) {
//load meshes
meshes= new Mesh[meshCount];
for(uint32 i = 0; i < meshCount; ++i) {
meshes[i].load(i, dir, f, textureManager,deletePixMapAfterLoad);
meshes[i].load(i, dir, f, textureManager,deletePixMapAfterLoad,
loadedFileList);
meshes[i].buildInterpolationData();
}
}
@@ -823,7 +846,8 @@ void Model::loadG3d(const string &path, bool deletePixMapAfterLoad) {
meshes= new Mesh[meshCount];
for(uint32 i = 0; i < meshCount; ++i) {
meshes[i].loadV3(i, dir, f, textureManager,deletePixMapAfterLoad);
meshes[i].loadV3(i, dir, f, textureManager,deletePixMapAfterLoad,
loadedFileList);
meshes[i].buildInterpolationData();
}
}
@@ -835,7 +859,8 @@ void Model::loadG3d(const string &path, bool deletePixMapAfterLoad) {
meshes= new Mesh[meshCount];
for(uint32 i = 0; i < meshCount; ++i){
meshes[i].loadV2(i,dir, f, textureManager,deletePixMapAfterLoad);
meshes[i].loadV2(i,dir, f, textureManager,deletePixMapAfterLoad,
loadedFileList);
meshes[i].buildInterpolationData();
}
}

View File

@@ -65,7 +65,6 @@ using namespace std;
namespace Shared { namespace PlatformCommon {
// Refresh every 3 days
const time_t REFRESH_CRC_DAY_SECONDS = 1 * 60 * 24;
static string crcCachePath = "";
@@ -210,6 +209,30 @@ void Tokenize(const string& str,vector<string>& tokens,const string& delimiters)
}
}
void findDirs(string path, vector<string> &results, bool errorOnNotFound,bool keepDuplicates) {
results.clear();
string currentPath = path;
endPathWithSlash(currentPath);
string searchpath = currentPath + "*.";
vector<string> current_results;
findAll(searchpath, current_results, false, errorOnNotFound);
if(current_results.size() > 0) {
for(unsigned int folder_index = 0; folder_index < current_results.size(); folder_index++) {
const string current_folder = current_results[folder_index];
const string current_folder_path = currentPath + current_folder;
if(isdir(current_folder_path.c_str()) == true) {
if(keepDuplicates == true || std::find(results.begin(),results.end(),current_folder) == results.end()) {
results.push_back(current_folder);
}
}
}
}
std::sort(results.begin(),results.end());
}
void findDirs(const vector<string> &paths, vector<string> &results, bool errorOnNotFound,bool keepDuplicates) {
results.clear();
size_t pathCount = paths.size();
@@ -412,6 +435,37 @@ void endPathWithSlash(string &path) {
}
}
void trimPathWithStartingSlash(string &path) {
if(StartsWith(path, "/") == true || StartsWith(path, "\\") == true) {
path.erase(path.begin(),path.begin()+1);
//printf("************* trimPathWithStartingSlash changed path [%s]\n",path.c_str());
}
}
void updatePathClimbingParts(string &path) {
// Update paths with ..
string::size_type pos = path.rfind("..");
if(pos != string::npos && pos != 0) {
string orig = path;
path.erase(pos,2);
pos--;
if(path[pos] == '/' || path[pos] == '\\') {
path.erase(pos,1);
}
for(int x = pos; x >= 0; --x) {
//printf("x [%d][%c] pos [%ld][%c] [%s]\n",x,path[x],(long int)pos,path[pos],path.substr(0,x+1).c_str());
if((path[x] == '/' || path[x] == '\\') && x != pos) {
path.erase(x,pos-x);
break;
}
}
//printf("CHANGED relative path from [%s] to [%s]\n",orig.c_str(),path.c_str());
}
}
string getCRCCacheFilePath() {
return crcCachePath;
}
@@ -467,7 +521,7 @@ void writeCachedFileCRCValue(string crcCacheFile, int32 &crcValue) {
FILE *fp = fopen(crcCacheFile.c_str(),"w");
if(fp != NULL) {
RandomGen random;
int offset = random.randRange(1, 5);
int offset = random.randRange(5, 15);
time_t refreshDate = time(NULL) + (REFRESH_CRC_DAY_SECONDS * offset);
fprintf(fp,"%ld,%d",refreshDate,crcValue);
fclose(fp);

View File

@@ -494,7 +494,7 @@ void SystemFlags::logDebugEntry(DebugType type, string debugEntry, time_t debugT
}
string lastDir(const string &s){
string lastDir(const string &s) {
size_t i= s.find_last_of('/');
size_t j= s.find_last_of('\\');
size_t pos;
@@ -513,7 +513,18 @@ string lastDir(const string &s){
throw runtime_error(string(__FILE__)+" lastDir - i==string::npos");
}
return (s.substr(pos+1, s.length()));
if( pos + 1 == s.length() && s.length() > 0 &&
(s[pos] == '/' || s[pos] == '\\')) {
string retry = s.substr(0, pos);
return lastDir(retry);
}
string result = s.substr(pos+1, s.length());
replaceAll(result,"/","");
replaceAll(result,"\\","");
//printf("=-=-=-=- LASTDIR in [%s] out [%s]\n",s.c_str(),result.c_str());
return result;
}
string lastFile(const string &s){