Add option to rewrite file only on changes
This commit is contained in:
parent
440d0a5f31
commit
e10834fd58
1 changed files with 87 additions and 35 deletions
|
@ -87,15 +87,16 @@ bool DisplayStream = false;
|
||||||
bool DisplayReplaces = false;
|
bool DisplayReplaces = false;
|
||||||
|
|
||||||
bool ReplacePaths = true;
|
bool ReplacePaths = true;
|
||||||
bool ReplaceMapExt = true;
|
bool ReplaceMapExt = false;
|
||||||
|
|
||||||
|
bool WritePathChangesOnly = true;
|
||||||
bool WriteModified = true;
|
bool WriteModified = true;
|
||||||
bool WriteDummy = false;
|
bool WriteDummy = false;
|
||||||
|
|
||||||
bool HaltOnIssue = false;
|
bool HaltOnIssue = false;
|
||||||
|
|
||||||
const char *DatabaseDirectory = "w:\\database\\";
|
const char *DatabaseDirectory = "w:\\database\\";
|
||||||
const char *LinuxDatabaseDirectory = "/mnt/tsurugi/ryzom-assets/database/";
|
const char *LinuxDatabaseDirectory = "/mnt/y/ryzom-assets/database/";
|
||||||
bool RunningLinux = true;
|
bool RunningLinux = true;
|
||||||
|
|
||||||
//const char *SrcDirectoryRecursive = "w:\\database\\interfaces\\";
|
//const char *SrcDirectoryRecursive = "w:\\database\\interfaces\\";
|
||||||
|
@ -103,7 +104,8 @@ bool RunningLinux = true;
|
||||||
//const char *SrcDirectoryRecursive = "w:\\database\\stuff\\fyros\\city\\newpositionville\\";
|
//const char *SrcDirectoryRecursive = "w:\\database\\stuff\\fyros\\city\\newpositionville\\";
|
||||||
const char *SrcDirectoryRecursiveInit = "w:\\database\\";
|
const char *SrcDirectoryRecursiveInit = "w:\\database\\";
|
||||||
//const char *SrcDirectoryRecursiveHandle = "w:\\database\\stuff\\generique\\agents\\accessories\\";
|
//const char *SrcDirectoryRecursiveHandle = "w:\\database\\stuff\\generique\\agents\\accessories\\";
|
||||||
const char *SrcDirectoryRecursiveHandle = "w:\\database\\landscape\\ligo\\primes_racines\\max\\";
|
//const char *SrcDirectoryRecursiveHandle = "w:\\database\\landscape\\ligo\\primes_racines\\max\\";
|
||||||
|
const char *SrcDirectoryRecursiveHandle = "w:\\database\\stuff\\fyros\\decors\\constructions\\";
|
||||||
|
|
||||||
bool UseFallbackTga = false;
|
bool UseFallbackTga = false;
|
||||||
const char *FallbackTga = "w:\\database\\stuff\\lod_actors\\texture_lod\\trame.png";
|
const char *FallbackTga = "w:\\database\\stuff\\lod_actors\\texture_lod\\trame.png";
|
||||||
|
@ -204,6 +206,8 @@ inline char stripFrenchLocale(char c0)
|
||||||
|
|
||||||
std::string rewritePath(const std::string &path, const std::string &databaseDirectory)
|
std::string rewritePath(const std::string &path, const std::string &databaseDirectory)
|
||||||
{
|
{
|
||||||
|
// nldebug("Rewrite: %s", path.c_str());
|
||||||
|
|
||||||
static std::set<std::string> fileNameCache;
|
static std::set<std::string> fileNameCache;
|
||||||
|
|
||||||
std::string stdPath = standardizePath(path, false);
|
std::string stdPath = standardizePath(path, false);
|
||||||
|
@ -597,9 +601,6 @@ void runHandler()
|
||||||
nlinfo("DatabaseDirectory: '%s'", DatabaseDirectory);
|
nlinfo("DatabaseDirectory: '%s'", DatabaseDirectory);
|
||||||
|
|
||||||
doDirectoryHandler(SrcDirectoryRecursiveHandle);
|
doDirectoryHandler(SrcDirectoryRecursiveHandle);
|
||||||
|
|
||||||
for (std::set<std::string>::iterator it = MissingFiles.begin(), end = MissingFiles.end(); it != end; ++it)
|
|
||||||
nlinfo("Missing: '%s'", (*it).c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void serializeStorageContainer(PIPELINE::MAX::CStorageContainer *storageContainer, GsfInfile *infile, const char *streamName)
|
void serializeStorageContainer(PIPELINE::MAX::CStorageContainer *storageContainer, GsfInfile *infile, const char *streamName)
|
||||||
|
@ -716,6 +717,8 @@ std::string rewritePathFinal(const std::string &str)
|
||||||
|
|
||||||
bool isImportantFilePath(const std::string &str)
|
bool isImportantFilePath(const std::string &str)
|
||||||
{
|
{
|
||||||
|
// nldebug("Is important? %s", str.c_str());
|
||||||
|
|
||||||
std::string strtrimmed = cleanString(str);
|
std::string strtrimmed = cleanString(str);
|
||||||
if (strtrimmed.size() >= 4)
|
if (strtrimmed.size() >= 4)
|
||||||
{
|
{
|
||||||
|
@ -775,31 +778,51 @@ bool hasImportantFilePath(CStorageRaw *raw)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fixChunk(uint16 id, IStorageObject *chunk)
|
bool fixChunk(uint16 id, IStorageObject *chunk)
|
||||||
{
|
{
|
||||||
|
if (id == 4656)
|
||||||
|
{
|
||||||
|
// nldebug("testing 4656: %s", chunk->toString().c_str());
|
||||||
|
}
|
||||||
|
bool changed = false;
|
||||||
CStorageValue<std::string> *asString = dynamic_cast<CStorageValue<std::string> *>(chunk);
|
CStorageValue<std::string> *asString = dynamic_cast<CStorageValue<std::string> *>(chunk);
|
||||||
if (asString)
|
if (asString)
|
||||||
{
|
{
|
||||||
// nldebug("String: %s", asString->Value.c_str());
|
// nldebug("String: %s", asString->Value.c_str());
|
||||||
if (isImportantFilePath(asString->Value))
|
if (isImportantFilePath(asString->Value))
|
||||||
asString->Value = rewritePathFinal(asString->Value);
|
{
|
||||||
return;
|
std::string rewritten = rewritePathFinal(asString->Value);
|
||||||
|
if (rewritten != asString->Value)
|
||||||
|
{
|
||||||
|
asString->Value = rewritten;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return changed;
|
||||||
}
|
}
|
||||||
CStorageValue<ucstring> *asUCString = dynamic_cast<CStorageValue<ucstring> *>(chunk);
|
CStorageValue<ucstring> *asUCString = dynamic_cast<CStorageValue<ucstring> *>(chunk);
|
||||||
if (asUCString)
|
if (asUCString)
|
||||||
{
|
{
|
||||||
// nldebug("UCString: %s", asUCString->Value.toUtf8().c_str());
|
// nldebug("UCString: %s", asUCString->Value.toUtf8().c_str());
|
||||||
if (isImportantFilePath(asUCString->Value.toString()))
|
if (isImportantFilePath(asUCString->Value.toString()))
|
||||||
asUCString->Value.fromUtf8(rewritePathFinal(asUCString->Value.toString()));
|
{
|
||||||
return;
|
std::string rewritten = rewritePathFinal(asUCString->Value.toString());
|
||||||
|
if (rewritten != asUCString->Value.toString())
|
||||||
|
{
|
||||||
|
asUCString->Value.fromUtf8(rewritten);
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return changed;
|
||||||
}
|
}
|
||||||
CStorageRaw *asRaw = dynamic_cast<CStorageRaw *>(chunk);
|
CStorageRaw *asRaw = dynamic_cast<CStorageRaw *>(chunk);
|
||||||
if (asRaw)
|
if (asRaw)
|
||||||
{
|
{
|
||||||
switch (id)
|
switch (id)
|
||||||
{
|
{
|
||||||
case 256:
|
|
||||||
case 4656:
|
case 4656:
|
||||||
|
// nldebug("4656: %s", chunk->toString().c_str());
|
||||||
|
case 256:
|
||||||
case 16385:
|
case 16385:
|
||||||
case 288: // .max xref in classdata
|
case 288: // .max xref in classdata
|
||||||
if (hasImportantFilePath(asRaw))
|
if (hasImportantFilePath(asRaw))
|
||||||
|
@ -811,9 +834,14 @@ void fixChunk(uint16 id, IStorageObject *chunk)
|
||||||
memcpy(&str[0], &asRaw->Value[0], asRaw->Value.size());
|
memcpy(&str[0], &asRaw->Value[0], asRaw->Value.size());
|
||||||
// nldebug("[%s]", str.toString().c_str());
|
// nldebug("[%s]", str.toString().c_str());
|
||||||
nlassert(isImportantFilePath(str.toString()));
|
nlassert(isImportantFilePath(str.toString()));
|
||||||
str.fromUtf8(rewritePathFinal(str.toString()));
|
std::string rewritten = rewritePathFinal(str.toString());
|
||||||
|
if (rewritten != str.toString())
|
||||||
|
{
|
||||||
|
str.fromUtf8(rewritten);
|
||||||
asRaw->Value.resize(str.size() * 2);
|
asRaw->Value.resize(str.size() * 2);
|
||||||
memcpy(&asRaw->Value[0], &str[0], asRaw->Value.size());
|
memcpy(&asRaw->Value[0], &str[0], asRaw->Value.size());
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 10:
|
case 10:
|
||||||
|
@ -883,7 +911,7 @@ void fixChunk(uint16 id, IStorageObject *chunk)
|
||||||
std::string x;
|
std::string x;
|
||||||
std::cin >> x;
|
std::cin >> x;
|
||||||
}
|
}
|
||||||
return;
|
return changed;
|
||||||
}
|
}
|
||||||
std::string v;
|
std::string v;
|
||||||
if (overrideFF && size == -1)
|
if (overrideFF && size == -1)
|
||||||
|
@ -907,7 +935,7 @@ void fixChunk(uint16 id, IStorageObject *chunk)
|
||||||
std::string x;
|
std::string x;
|
||||||
std::cin >> x;
|
std::cin >> x;
|
||||||
}
|
}
|
||||||
return;
|
return changed;
|
||||||
}
|
}
|
||||||
v.resize(v.size() - 1);
|
v.resize(v.size() - 1);
|
||||||
// nldebug("%s", v.c_str());
|
// nldebug("%s", v.c_str());
|
||||||
|
@ -924,7 +952,12 @@ void fixChunk(uint16 id, IStorageObject *chunk)
|
||||||
if (isImportantFilePath(strings[i]))
|
if (isImportantFilePath(strings[i]))
|
||||||
{
|
{
|
||||||
foundone = true;
|
foundone = true;
|
||||||
strings[i] = rewritePathFinal(strings[i]);
|
std::string rewritten = rewritePathFinal(strings[i]);
|
||||||
|
if (rewritten != strings[i])
|
||||||
|
{
|
||||||
|
strings[i] = rewritten;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
nlassert(foundone);
|
nlassert(foundone);
|
||||||
|
@ -950,7 +983,7 @@ void fixChunk(uint16 id, IStorageObject *chunk)
|
||||||
}
|
}
|
||||||
//std::string x;
|
//std::string x;
|
||||||
//std::cin >> x;
|
//std::cin >> x;
|
||||||
return;
|
return changed;
|
||||||
}
|
}
|
||||||
std::string str;
|
std::string str;
|
||||||
str.resize(size - 1);
|
str.resize(size - 1);
|
||||||
|
@ -970,11 +1003,16 @@ void fixChunk(uint16 id, IStorageObject *chunk)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
str = rewritePathFinal(str);
|
std::string rewritten = rewritePathFinal(str);
|
||||||
|
if (rewritten != str)
|
||||||
|
{
|
||||||
|
str = rewritten;
|
||||||
asRaw->Value.resize(str.size() + 11 + 4 + 1);
|
asRaw->Value.resize(str.size() + 11 + 4 + 1);
|
||||||
memcpy(&asRaw->Value[15], &str[0], str.size());
|
memcpy(&asRaw->Value[15], &str[0], str.size());
|
||||||
((uint32 *)&asRaw->Value[11])[0] = str.size() + 1;
|
((uint32 *)&asRaw->Value[11])[0] = str.size() + 1;
|
||||||
asRaw->Value[asRaw->Value.size() - 1] = 0;
|
asRaw->Value[asRaw->Value.size() - 1] = 0;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 304:
|
case 304:
|
||||||
|
@ -991,10 +1029,15 @@ void fixChunk(uint16 id, IStorageObject *chunk)
|
||||||
asRaw->toString(std::cout);
|
asRaw->toString(std::cout);
|
||||||
nlerror("not important");
|
nlerror("not important");
|
||||||
}
|
}
|
||||||
str = rewritePathFinal(str);
|
std::string rewritten = rewritePathFinal(str);
|
||||||
|
if (rewritten != str)
|
||||||
|
{
|
||||||
|
str = rewritten;
|
||||||
asRaw->Value.resize(str.size() + 1);
|
asRaw->Value.resize(str.size() + 1);
|
||||||
memcpy(&asRaw->Value[0], &str[0], str.size());
|
memcpy(&asRaw->Value[0], &str[0], str.size());
|
||||||
asRaw->Value[asRaw->Value.size() - 1] = 0;
|
asRaw->Value[asRaw->Value.size() - 1] = 0;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 9730:
|
case 9730:
|
||||||
|
@ -1014,26 +1057,29 @@ void fixChunk(uint16 id, IStorageObject *chunk)
|
||||||
std::string x;
|
std::string x;
|
||||||
std::cin >> x;
|
std::cin >> x;
|
||||||
}
|
}
|
||||||
return;
|
return changed;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void fixChunks(CStorageContainer *container)
|
bool fixChunks(CStorageContainer *container)
|
||||||
{
|
{
|
||||||
|
bool changed = false;
|
||||||
for (CStorageContainer::TStorageObjectConstIt it = container->chunks().begin(), end = container->chunks().end(); it != end; ++it)
|
for (CStorageContainer::TStorageObjectConstIt it = container->chunks().begin(), end = container->chunks().end(); it != end; ++it)
|
||||||
{
|
{
|
||||||
if (it->second->isContainer())
|
if (it->second->isContainer())
|
||||||
{
|
{
|
||||||
fixChunks(static_cast<CStorageContainer *>(it->second));
|
changed = (changed || fixChunks(static_cast<CStorageContainer *>(it->second)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fixChunk(it->first, it->second);
|
changed = (changed || fixChunk(it->first, it->second));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleFile(const std::string &path)
|
void handleFile(const std::string &path)
|
||||||
|
@ -1115,11 +1161,13 @@ void handleFile(const std::string &path)
|
||||||
|
|
||||||
g_object_unref(infile);
|
g_object_unref(infile);
|
||||||
|
|
||||||
|
bool pathsChanged = !WritePathChangesOnly;
|
||||||
if (ReplacePaths)
|
if (ReplacePaths)
|
||||||
{
|
{
|
||||||
fixChunks(&classData);
|
pathsChanged = pathsChanged || fixChunks(&classData);
|
||||||
fixChunks(&scene);
|
pathsChanged = pathsChanged || fixChunks(&scene);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ReplaceMapExt)
|
if (ReplaceMapExt)
|
||||||
{
|
{
|
||||||
// Parse the scene
|
// Parse the scene
|
||||||
|
@ -1443,7 +1491,7 @@ void handleFile(const std::string &path)
|
||||||
|
|
||||||
dllDirectory.disown();
|
dllDirectory.disown();
|
||||||
classDirectory3.disown();
|
classDirectory3.disown();
|
||||||
if (WriteModified)
|
if (WriteModified && (ReplaceMapExt || pathsChanged))
|
||||||
{
|
{
|
||||||
const char *outpath = (WriteDummy ? "testdummy.max" : path.c_str());
|
const char *outpath = (WriteDummy ? "testdummy.max" : path.c_str());
|
||||||
GsfOutput *output;
|
GsfOutput *output;
|
||||||
|
@ -1506,11 +1554,15 @@ int main(int argc, char **argv)
|
||||||
//handleFile(nativeDatabasePath("w:\\database\\stuff\\generique\\agents\\accessories\\ge_fy_wea_trib_grand_bouclier.max"));
|
//handleFile(nativeDatabasePath("w:\\database\\stuff\\generique\\agents\\accessories\\ge_fy_wea_trib_grand_bouclier.max"));
|
||||||
//handleFile(nativeDatabasePath("w:\\database\\stuff\\generique\\agents\\accessories\\ge_mission_entrepot.max"));
|
//handleFile(nativeDatabasePath("w:\\database\\stuff\\generique\\agents\\accessories\\ge_mission_entrepot.max"));
|
||||||
//handleFile(nativeDatabasePath("w:\\database\\stuff\\generique\\agents\\accessories\\mesh_wip\\all_trib_weapons.max"));
|
//handleFile(nativeDatabasePath("w:\\database\\stuff\\generique\\agents\\accessories\\mesh_wip\\all_trib_weapons.max"));
|
||||||
|
//handleFile(nativeDatabasePath("w:\\database\\stuff\\fyros\\decors\\constructions\\fy_cn_smokehouse.max"));
|
||||||
//handleFile("/srv/work/database/landscape/ligo/jungle/pipeline_max/zonematerial-foret-ruine_boss.max");
|
//handleFile("/srv/work/database/landscape/ligo/jungle/pipeline_max/zonematerial-foret-ruine_boss.max");
|
||||||
//handleFile("/srv/work/database/stuff/fyros/agents/actors/male/animation/anims_non_utilisees/fy_hom_assis_boire_verre.max");
|
//handleFile("/srv/work/database/stuff/fyros/agents/actors/male/animation/anims_non_utilisees/fy_hom_assis_boire_verre.max");
|
||||||
//handleFile("/home/kaetemi/3dsMax/scenes/test_clear_add_uvw.max");
|
//handleFile("/home/kaetemi/3dsMax/scenes/test_clear_add_uvw.max");
|
||||||
//runScanner();
|
//runScanner();
|
||||||
|
|
||||||
|
for (std::set<std::string>::iterator it = MissingFiles.begin(), end = MissingFiles.end(); it != end; ++it)
|
||||||
|
nlinfo("Missing: '%s'", (*it).c_str());
|
||||||
|
|
||||||
gsf_shutdown();
|
gsf_shutdown();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in a new issue