From 25a4d6bbed8473140cf6f774b2668fe0557f51b8 Mon Sep 17 00:00:00 2001 From: kervala Date: Tue, 29 Nov 2016 20:43:55 +0100 Subject: [PATCH] Changed: Replace all path native functions by NeL methods --HG-- branch : develop --- .../tools/3d/ligo/plugin_max/max_to_ligo.cpp | 7 +- code/nel/tools/3d/ligo/plugin_max/script.cpp | 9 ++- .../tools/3d/object_viewer/object_viewer.cpp | 13 ++-- .../nel_export/nel_export_export.cpp | 65 +++++++------------ .../tools/3d/plugin_max/nel_export/std_afx.h | 1 + code/nel/tools/3d/tile_edit/Browse.cpp | 12 ++-- .../3d/tile_edit_qt/tile_browser_dlg.cpp | 5 +- .../zone_dependencies/zone_dependencies.cpp | 2 +- .../tools/georges/georges2csv/georges2csv.cpp | 2 +- .../georges_dll/georges_edit_doc.cpp | 2 +- .../tools/leveldesign/georges_dll/stdafx.h | 1 + .../tools/leveldesign/prim_export/main.cpp | 2 +- .../tools/stats_scan/character_scan_job.cpp | 4 +- 13 files changed, 50 insertions(+), 75 deletions(-) diff --git a/code/nel/tools/3d/ligo/plugin_max/max_to_ligo.cpp b/code/nel/tools/3d/ligo/plugin_max/max_to_ligo.cpp index 1abe022f8..44b43beed 100644 --- a/code/nel/tools/3d/ligo/plugin_max/max_to_ligo.cpp +++ b/code/nel/tools/3d/ligo/plugin_max/max_to_ligo.cpp @@ -132,15 +132,12 @@ bool CMaxToLigo::loadLigoConfigFile (CLigoConfig& config, Interface& it, bool di if (res) { // Path - TCHAR sDrive[256]; - TCHAR sDir[256]; - _tsplitpath (sModulePath, sDrive, sDir, NULL, NULL); - _tmakepath (sModulePath, sDrive, sDir, _T("ligoscape"), _T(".cfg")); + std::string path = NLMISC::CFile::getPath(tStrToUtf8(sModulePath) + "ligoscape.cfg"); try { // Load the config file - config.readConfigFile (tStrToUtf8(sModulePath), false); + config.readConfigFile (path, false); // ok return true; diff --git a/code/nel/tools/3d/ligo/plugin_max/script.cpp b/code/nel/tools/3d/ligo/plugin_max/script.cpp index 077aa4054..effc3a2a2 100644 --- a/code/nel/tools/3d/ligo/plugin_max/script.cpp +++ b/code/nel/tools/3d/ligo/plugin_max/script.cpp @@ -262,8 +262,8 @@ Value* export_material_cf (Value** arg_list, int count) // Remove the files if (!ok) { - remove (fileName); - remove (path); + CFile::deleteFile(fileName); + CFile::deleteFile(path); } } } @@ -549,7 +549,7 @@ Value* export_transition_cf (Value** arg_list, int count) for (uint file=0; fileenableUsedTextureMemorySum (); - char sModulePath[256]; // load the scheme bank if one is present CIFile iF; ::_makepath (sModulePath, SDrive, SDir, "default", ".scb"); @@ -831,8 +829,9 @@ bool CObjectViewer::initUI (HWND parent) iF.close(); // try to load a default config file for the viewer (for anitmation and particle edition setup) - ::_makepath (sModulePath, SDrive, SDir, "default", ".ovcgf"); - if (iF.open (sModulePath)) + path = SPath + "default.ovcgf"; + + if (iF.open (path)) { try { diff --git a/code/nel/tools/3d/plugin_max/nel_export/nel_export_export.cpp b/code/nel/tools/3d/plugin_max/nel_export/nel_export_export.cpp index a5490dc2a..a41c3134c 100644 --- a/code/nel/tools/3d/plugin_max/nel_export/nel_export_export.cpp +++ b/code/nel/tools/3d/plugin_max/nel_export/nel_export_export.cpp @@ -36,17 +36,13 @@ bool CNelExport::exportMesh (const std::string &sPath, INode& node, TimeValue ti { // Result to return bool bRet = false; - TCHAR tempFileName[MAX_PATH] = { 0 }; - TCHAR tempPathBuffer[MAX_PATH] = { 0 }; + std::string tempFileName; + std::string tempPathBuffer; try { - DWORD dwRetVal = GetTempPath(MAX_PATH, tempPathBuffer); - if (dwRetVal > MAX_PATH || (dwRetVal == 0)) - nlerror("GetTempPath failed"); - UINT uRetVal = GetTempFileName(tempPathBuffer, _T("_nel_export_mesh_"), 0, tempFileName); - if (uRetVal == 0) - nlerror("GetTempFileName failed"); + tempPathBuffer = NLMISC::CPath::getTemporaryDirectory(); + NLMISC::CFile::getTemporaryOutputFilename(tempPathBuffer + "_nel_export_mesh_", tempFileName); // Eval the object a time ObjectState os = node.EvalWorldState(time); @@ -99,7 +95,7 @@ bool CNelExport::exportMesh (const std::string &sPath, INode& node, TimeValue ti { // Open a file COFile file; - if (file.open(tStrToUtf8(tempFileName))) + if (file.open(tempFileName)) { try { @@ -126,12 +122,13 @@ bool CNelExport::exportMesh (const std::string &sPath, INode& node, TimeValue ti { } - remove(tempFileName); + + CFile::deleteFile(tempFileName); } } else { - nlwarning("Failed to create file %s", tempFileName); + nlwarning("Failed to create file %s", tempFileName.c_str()); if (_TerminateOnFileOpenIssues) nelExportTerminateProcess(); } @@ -148,7 +145,7 @@ bool CNelExport::exportMesh (const std::string &sPath, INode& node, TimeValue ti catch (...) { nlwarning("Failed to delete pShape pointer! Something might be wrong."); - remove(tempFileName); + CFile::deleteFile(tempFileName); bRet = false; } @@ -173,7 +170,7 @@ bool CNelExport::exportMesh (const std::string &sPath, INode& node, TimeValue ti } else { - nlwarning("Failed to open file: %s", tempFileName); + nlwarning("Failed to open file: %s", tempFileName.c_str()); if (_TerminateOnFileOpenIssues) nelExportTerminateProcess(); } @@ -181,7 +178,7 @@ bool CNelExport::exportMesh (const std::string &sPath, INode& node, TimeValue ti catch (...) { nlwarning("Failed to verify shape. Must crash now."); - remove(tempFileName); + CFile::deleteFile(tempFileName); bRet = false; } @@ -196,16 +193,9 @@ bool CNelExport::exportMesh (const std::string &sPath, INode& node, TimeValue ti if (bRet) { - try - { - remove(sPath); - } - catch (...) - { - - } + CFile::deleteFile(sPath); CFile::moveFile(sPath, tempFileName); - nlinfo("MOVE %s -> %s", tempFileName, sPath); + nlinfo("MOVE %s -> %s", tempFileName.c_str(), sPath.c_str()); } return bRet; @@ -250,17 +240,13 @@ bool CNelExport::exportAnim (const std::string &sPath, std::vector& vect { // Result to return bool bRet=false; - char tempFileName[MAX_PATH] = { 0 }; - char tempPathBuffer[MAX_PATH] = { 0 }; + std::string tempFileName; + std::string tempPathBuffer; try { - DWORD dwRetVal = GetTempPathA(MAX_PATH, tempPathBuffer); - if (dwRetVal > MAX_PATH || (dwRetVal == 0)) - nlerror("GetTempPath failed"); - UINT uRetVal = GetTempFileNameA(tempPathBuffer, TEXT("_nel_export_mesh_"), 0, tempFileName); - if (uRetVal == 0) - nlerror("GetTempFileName failed"); + tempPathBuffer = NLMISC::CPath::getTemporaryDirectory(); + NLMISC::CFile::getTemporaryOutputFilename(tempPathBuffer + "_nel_export_mesh_", tempFileName); // Create an animation file CAnimation animFile; @@ -269,7 +255,7 @@ bool CNelExport::exportAnim (const std::string &sPath, std::vector& vect for (uint n=0; n& vect } else { - nlwarning("Failed to open file: %s", tempFileName); + nlwarning("Failed to open file: %s", tempFileName.c_str()); bRet = false; if (_TerminateOnFileOpenIssues) nelExportTerminateProcess(); @@ -336,7 +322,7 @@ bool CNelExport::exportAnim (const std::string &sPath, std::vector& vect catch (...) { nlwarning("Failed to verify shape. Must crash now."); - remove(tempFileName); + CFile::deleteFile(tempFileName); bRet = false; } } @@ -367,16 +353,9 @@ bool CNelExport::exportAnim (const std::string &sPath, std::vector& vect if (bRet) { - try - { - remove(sPath); - } - catch (...) - { - - } + CFile::deleteFile(sPath); CFile::moveFile(sPath, tempFileName); - nlinfo("MOVE %s -> %s", tempFileName, sPath); + nlinfo("MOVE %s -> %s", tempFileName.c_str(), sPath.c_str()); } return bRet; } diff --git a/code/nel/tools/3d/plugin_max/nel_export/std_afx.h b/code/nel/tools/3d/plugin_max/nel_export/std_afx.h index 9b4b18357..ba7b4b4c0 100644 --- a/code/nel/tools/3d/plugin_max/nel_export/std_afx.h +++ b/code/nel/tools/3d/plugin_max/nel_export/std_afx.h @@ -71,5 +71,6 @@ namespace std #endif #include "nel/misc/bsphere.h" +#include "nel/misc/path.h" #endif diff --git a/code/nel/tools/3d/tile_edit/Browse.cpp b/code/nel/tools/3d/tile_edit/Browse.cpp index 9572ce0a4..89e45c62d 100644 --- a/code/nel/tools/3d/tile_edit/Browse.cpp +++ b/code/nel/tools/3d/tile_edit/Browse.cpp @@ -895,12 +895,12 @@ void Browse::OnBatchLoad () std::string ext = NLMISC::CFile::getExtension(fullPath); // look for some numbers.. - char *sNumber=sName+strlen(sName)-1; - while ((sNumber>sName)&&(*sNumber>='0')&&(*sNumber<='9')) + std::string::size_type pos = filename.find_last_not_of("0123456789"); + + if (pos != std::string::npos) { - sNumber--; + filename = filename.substr(0, pos + 1); } - sNumber[1]=0; bool rotate=false; @@ -1396,7 +1396,7 @@ void Browse::OnExportBorder() try { COFile file; - if (file.open ((const char*)pathName)) + if (file.open (tStrToUtf8(pathName))) { // Export bitmap.writeTGA (file, 32); @@ -1439,7 +1439,7 @@ void Browse::OnImportBorder() try { CIFile file; - if (file.open ((const char*)pathName)) + if (file.open (tStrToUtf8(pathName))) { // Export bitmap.load (file); diff --git a/code/nel/tools/3d/tile_edit_qt/tile_browser_dlg.cpp b/code/nel/tools/3d/tile_edit_qt/tile_browser_dlg.cpp index 2d1ca4cbe..a6ca57fd3 100644 --- a/code/nel/tools/3d/tile_edit_qt/tile_browser_dlg.cpp +++ b/code/nel/tools/3d/tile_edit_qt/tile_browser_dlg.cpp @@ -434,7 +434,7 @@ void CTile_browser_dlg::on_batchLoadPushButton_clicked() QString batchNumber = transitionNumber.rightJustified(2, '0'); QString nextBaseName = baseName + batchNumber; QString nextFileName = QDir::toNativeSeparators(fi.absolutePath()) + QDir::separator() + nextBaseName + QString(".") + fi.suffix(); - FILE *pFile=fopen (nextFileName.toUtf8().constData(), "rb"); + FILE *pFile = nlfopen (nextFileName.toUtf8().constData(), "rb"); // Close the file and add the tile if opened if (pFile) @@ -471,8 +471,7 @@ void CTile_browser_dlg::on_batchLoadPushButton_clicked() // char sName2[256]; // char sFinal[256]; // sprintf (sName2, "%s%02d", sName, (int)transition); - // _makepath (sFinal, sDrive, sPath, sName2, sExt); - // FILE *pFile=fopen (sFinal, "rb"); + // FILE *pFile = nlfopen (sFinal, "rb"); // // Close the file and add the tile if opened // if (pFile) diff --git a/code/nel/tools/3d/zone_dependencies/zone_dependencies.cpp b/code/nel/tools/3d/zone_dependencies/zone_dependencies.cpp index b109c2db2..846902cde 100644 --- a/code/nel/tools/3d/zone_dependencies/zone_dependencies.cpp +++ b/code/nel/tools/3d/zone_dependencies/zone_dependencies.cpp @@ -522,7 +522,7 @@ int main (int argc, char* argv[]) // Write the dependencies file FILE *outputFile; - if ((outputFile=fopen (toLower (outputFileName).c_str(), "w"))) + if ((outputFile = nlfopen (toLower (outputFileName), "w"))) { // Add a dependency entry fprintf (outputFile, "dependencies =\n{\n"); diff --git a/code/nel/tools/georges/georges2csv/georges2csv.cpp b/code/nel/tools/georges/georges2csv/georges2csv.cpp index 29fb393c9..131e5961c 100644 --- a/code/nel/tools/georges/georges2csv/georges2csv.cpp +++ b/code/nel/tools/georges/georges2csv/georges2csv.cpp @@ -179,7 +179,7 @@ void setOutputFile(const CSString &filename) { if (Outf!=NULL) fclose(Outf); - Outf=fopen(filename.c_str(), "wt"); + Outf = nlfopen(filename.c_str(), "wt"); if (Outf == NULL) { fprintf(stderr, "Can't open output file '%s' ! aborting.", filename.c_str()); diff --git a/code/ryzom/tools/leveldesign/georges_dll/georges_edit_doc.cpp b/code/ryzom/tools/leveldesign/georges_dll/georges_edit_doc.cpp index 213ea3171..ec5a64010 100644 --- a/code/ryzom/tools/leveldesign/georges_dll/georges_edit_doc.cpp +++ b/code/ryzom/tools/leveldesign/georges_dll/georges_edit_doc.cpp @@ -548,7 +548,7 @@ BOOL CGeorgesEditDoc::OnOpenDocument(LPCTSTR lpszPathName) if (!extLower.empty ()) { - string dfnName = extLower.substr (1, string::npos) + ".dfn"; + string dfnName = extLower + ".dfn"; // Check if the file is handled if (theApp.getFormDocTemplate (dfnName.c_str ()) == NULL) diff --git a/code/ryzom/tools/leveldesign/georges_dll/stdafx.h b/code/ryzom/tools/leveldesign/georges_dll/stdafx.h index 3ed671a13..91a0d1f9a 100644 --- a/code/ryzom/tools/leveldesign/georges_dll/stdafx.h +++ b/code/ryzom/tools/leveldesign/georges_dll/stdafx.h @@ -48,6 +48,7 @@ #include "nel/misc/types_nl.h" #include "nel/misc/debug.h" #include "nel/misc/common.h" +#include "nel/misc/path.h" // Include from libxml2 #include diff --git a/code/ryzom/tools/leveldesign/prim_export/main.cpp b/code/ryzom/tools/leveldesign/prim_export/main.cpp index f9c33d953..be875b350 100644 --- a/code/ryzom/tools/leveldesign/prim_export/main.cpp +++ b/code/ryzom/tools/leveldesign/prim_export/main.cpp @@ -1115,7 +1115,7 @@ int main (int argc, char**argv) outString ("REMOVE " + CFile::getFilename (igFilename) + " \n"); // Remove it - if (remove (igFilename.c_str ()) != 0) + if (!CFile::deleteFile(igFilename)) { // Error in the log nlwarning ("Error : Can't remove the file (%s)", igFilename.c_str ()); diff --git a/code/ryzom/tools/stats_scan/character_scan_job.cpp b/code/ryzom/tools/stats_scan/character_scan_job.cpp index 4ee45f037..47593ba81 100644 --- a/code/ryzom/tools/stats_scan/character_scan_job.cpp +++ b/code/ryzom/tools/stats_scan/character_scan_job.cpp @@ -52,7 +52,7 @@ CCharacterScanJob::CCharacterScanJob() // open the output file for the character table std::string filename= "char_tbl.csv"; - _CharTblFile=fopen(filename.c_str(),"wb"); + _CharTblFile = nlfopen(filename, "wb"); if (_CharTblFile==NULL) { nlwarning("Failed to open output file: %s",filename.c_str()); @@ -73,7 +73,7 @@ CCharacterScanJob::~CCharacterScanJob() { // create the output file name and open the file for writing std::string filename="char_stats_"+(*it).first+".csv"; - FILE* f=fopen(filename.c_str(),"wb"); + FILE* f = nlfopen(filename, "wb"); if (f==NULL) { nlwarning("Failed to open output file: %s",filename.c_str());