Changed: Replace all path native functions by NeL methods

This commit is contained in:
kervala 2016-11-29 20:43:55 +01:00
parent a8293233ed
commit afbe840c51
13 changed files with 50 additions and 75 deletions

View file

@ -132,15 +132,12 @@ bool CMaxToLigo::loadLigoConfigFile (CLigoConfig& config, Interface& it, bool di
if (res) if (res)
{ {
// Path // Path
TCHAR sDrive[256]; std::string path = NLMISC::CFile::getPath(tStrToUtf8(sModulePath) + "ligoscape.cfg");
TCHAR sDir[256];
_tsplitpath (sModulePath, sDrive, sDir, NULL, NULL);
_tmakepath (sModulePath, sDrive, sDir, _T("ligoscape"), _T(".cfg"));
try try
{ {
// Load the config file // Load the config file
config.readConfigFile (tStrToUtf8(sModulePath), false); config.readConfigFile (path, false);
// ok // ok
return true; return true;

View file

@ -262,8 +262,8 @@ Value* export_material_cf (Value** arg_list, int count)
// Remove the files // Remove the files
if (!ok) if (!ok)
{ {
remove (fileName); CFile::deleteFile(fileName);
remove (path); CFile::deleteFile(path);
} }
} }
} }
@ -549,7 +549,7 @@ Value* export_transition_cf (Value** arg_list, int count)
for (uint file=0; file<createdfiles.size(); file++) for (uint file=0; file<createdfiles.size(); file++)
{ {
// Removing files // Removing files
remove (createdfiles[file].c_str ()); CFile::deleteFile(createdfiles[file]);
} }
} }
} }
@ -1991,8 +1991,7 @@ Value* make_snapshot_cf (Value** arg_list, int count)
#if 0 #if 0
// Write the zone // Write the zone
COFile outputLigoZone; COFile outputLigoZone;
std::string outputFilenameSnapShot = pathtga + nametga + ".tga"; std::string outputFilenameSnapShot = pathtga + nametga + ".ligozone";
_makepath (outputFilenameSnapShot, drivetga, pathtga, nametga, ".ligozone");
try try
{ {

View file

@ -93,8 +93,7 @@ using namespace NLPACS;
static char SDrive[256]; static std::string SPath;
static char SDir[256];
uint SkeletonUsedForSound = 0xFFFFFFFF; uint SkeletonUsedForSound = 0xFFFFFFFF;
CSoundContext SoundContext; CSoundContext SoundContext;
@ -285,9 +284,9 @@ std::string CObjectViewer::getModulePath() const
int res = GetModuleFileName(hModule, sModulePath, 256); nlassert(res); int res = GetModuleFileName(hModule, sModulePath, 256); nlassert(res);
nldebug("Object viewer module path is '%s'", sModulePath); nldebug("Object viewer module path is '%s'", sModulePath);
std::string path = NLMISC::CFile::getPath(tStrToUtf8(sModulePath)); SPath = NLMISC::CFile::getPath(tStrToUtf8(sModulePath));
return NLMISC::CPath::standardizeDosPath(path) + "object_viewer.cfg"; return SPath + "object_viewer.cfg";
} }
@ -812,7 +811,6 @@ bool CObjectViewer::initUI (HWND parent)
// Enable sum of vram // Enable sum of vram
CNELU::Driver->enableUsedTextureMemorySum (); CNELU::Driver->enableUsedTextureMemorySum ();
char sModulePath[256];
// load the scheme bank if one is present // load the scheme bank if one is present
CIFile iF; CIFile iF;
::_makepath (sModulePath, SDrive, SDir, "default", ".scb"); ::_makepath (sModulePath, SDrive, SDir, "default", ".scb");
@ -831,8 +829,9 @@ bool CObjectViewer::initUI (HWND parent)
iF.close(); iF.close();
// try to load a default config file for the viewer (for anitmation and particle edition setup) // try to load a default config file for the viewer (for anitmation and particle edition setup)
::_makepath (sModulePath, SDrive, SDir, "default", ".ovcgf"); path = SPath + "default.ovcgf";
if (iF.open (sModulePath))
if (iF.open (path))
{ {
try try
{ {

View file

@ -36,17 +36,13 @@ bool CNelExport::exportMesh (const std::string &sPath, INode& node, TimeValue ti
{ {
// Result to return // Result to return
bool bRet = false; bool bRet = false;
TCHAR tempFileName[MAX_PATH] = { 0 }; std::string tempFileName;
TCHAR tempPathBuffer[MAX_PATH] = { 0 }; std::string tempPathBuffer;
try try
{ {
DWORD dwRetVal = GetTempPath(MAX_PATH, tempPathBuffer); tempPathBuffer = NLMISC::CPath::getTemporaryDirectory();
if (dwRetVal > MAX_PATH || (dwRetVal == 0)) NLMISC::CFile::getTemporaryOutputFilename(tempPathBuffer + "_nel_export_mesh_", tempFileName);
nlerror("GetTempPath failed");
UINT uRetVal = GetTempFileName(tempPathBuffer, _T("_nel_export_mesh_"), 0, tempFileName);
if (uRetVal == 0)
nlerror("GetTempFileName failed");
// Eval the object a time // Eval the object a time
ObjectState os = node.EvalWorldState(time); ObjectState os = node.EvalWorldState(time);
@ -99,7 +95,7 @@ bool CNelExport::exportMesh (const std::string &sPath, INode& node, TimeValue ti
{ {
// Open a file // Open a file
COFile file; COFile file;
if (file.open(tStrToUtf8(tempFileName))) if (file.open(tempFileName))
{ {
try try
{ {
@ -126,12 +122,13 @@ bool CNelExport::exportMesh (const std::string &sPath, INode& node, TimeValue ti
{ {
} }
remove(tempFileName);
CFile::deleteFile(tempFileName);
} }
} }
else else
{ {
nlwarning("Failed to create file %s", tempFileName); nlwarning("Failed to create file %s", tempFileName.c_str());
if (_TerminateOnFileOpenIssues) if (_TerminateOnFileOpenIssues)
nelExportTerminateProcess(); nelExportTerminateProcess();
} }
@ -148,7 +145,7 @@ bool CNelExport::exportMesh (const std::string &sPath, INode& node, TimeValue ti
catch (...) catch (...)
{ {
nlwarning("Failed to delete pShape pointer! Something might be wrong."); nlwarning("Failed to delete pShape pointer! Something might be wrong.");
remove(tempFileName); CFile::deleteFile(tempFileName);
bRet = false; bRet = false;
} }
@ -173,7 +170,7 @@ bool CNelExport::exportMesh (const std::string &sPath, INode& node, TimeValue ti
} }
else else
{ {
nlwarning("Failed to open file: %s", tempFileName); nlwarning("Failed to open file: %s", tempFileName.c_str());
if (_TerminateOnFileOpenIssues) if (_TerminateOnFileOpenIssues)
nelExportTerminateProcess(); nelExportTerminateProcess();
} }
@ -181,7 +178,7 @@ bool CNelExport::exportMesh (const std::string &sPath, INode& node, TimeValue ti
catch (...) catch (...)
{ {
nlwarning("Failed to verify shape. Must crash now."); nlwarning("Failed to verify shape. Must crash now.");
remove(tempFileName); CFile::deleteFile(tempFileName);
bRet = false; bRet = false;
} }
@ -196,16 +193,9 @@ bool CNelExport::exportMesh (const std::string &sPath, INode& node, TimeValue ti
if (bRet) if (bRet)
{ {
try CFile::deleteFile(sPath);
{
remove(sPath);
}
catch (...)
{
}
CFile::moveFile(sPath, tempFileName); CFile::moveFile(sPath, tempFileName);
nlinfo("MOVE %s -> %s", tempFileName, sPath); nlinfo("MOVE %s -> %s", tempFileName.c_str(), sPath.c_str());
} }
return bRet; return bRet;
@ -250,17 +240,13 @@ bool CNelExport::exportAnim (const std::string &sPath, std::vector<INode*>& vect
{ {
// Result to return // Result to return
bool bRet=false; bool bRet=false;
char tempFileName[MAX_PATH] = { 0 }; std::string tempFileName;
char tempPathBuffer[MAX_PATH] = { 0 }; std::string tempPathBuffer;
try try
{ {
DWORD dwRetVal = GetTempPathA(MAX_PATH, tempPathBuffer); tempPathBuffer = NLMISC::CPath::getTemporaryDirectory();
if (dwRetVal > MAX_PATH || (dwRetVal == 0)) NLMISC::CFile::getTemporaryOutputFilename(tempPathBuffer + "_nel_export_mesh_", tempFileName);
nlerror("GetTempPath failed");
UINT uRetVal = GetTempFileNameA(tempPathBuffer, TEXT("_nel_export_mesh_"), 0, tempFileName);
if (uRetVal == 0)
nlerror("GetTempFileName failed");
// Create an animation file // Create an animation file
CAnimation animFile; CAnimation animFile;
@ -269,7 +255,7 @@ bool CNelExport::exportAnim (const std::string &sPath, std::vector<INode*>& vect
for (uint n=0; n<vectNode.size(); n++) for (uint n=0; n<vectNode.size(); n++)
{ {
// Get name // Get name
std::string nodeName=""; std::string nodeName;
// Get NEL3D_APPDATA_EXPORT_ANIMATION_PREFIXE_NAME // Get NEL3D_APPDATA_EXPORT_ANIMATION_PREFIXE_NAME
int prefixe = CExportNel::getScriptAppData (vectNode[n], NEL3D_APPDATA_EXPORT_ANIMATION_PREFIXE_NAME, 0); int prefixe = CExportNel::getScriptAppData (vectNode[n], NEL3D_APPDATA_EXPORT_ANIMATION_PREFIXE_NAME, 0);
@ -327,7 +313,7 @@ bool CNelExport::exportAnim (const std::string &sPath, std::vector<INode*>& vect
} }
else else
{ {
nlwarning("Failed to open file: %s", tempFileName); nlwarning("Failed to open file: %s", tempFileName.c_str());
bRet = false; bRet = false;
if (_TerminateOnFileOpenIssues) if (_TerminateOnFileOpenIssues)
nelExportTerminateProcess(); nelExportTerminateProcess();
@ -336,7 +322,7 @@ bool CNelExport::exportAnim (const std::string &sPath, std::vector<INode*>& vect
catch (...) catch (...)
{ {
nlwarning("Failed to verify shape. Must crash now."); nlwarning("Failed to verify shape. Must crash now.");
remove(tempFileName); CFile::deleteFile(tempFileName);
bRet = false; bRet = false;
} }
} }
@ -367,16 +353,9 @@ bool CNelExport::exportAnim (const std::string &sPath, std::vector<INode*>& vect
if (bRet) if (bRet)
{ {
try CFile::deleteFile(sPath);
{
remove(sPath);
}
catch (...)
{
}
CFile::moveFile(sPath, tempFileName); CFile::moveFile(sPath, tempFileName);
nlinfo("MOVE %s -> %s", tempFileName, sPath); nlinfo("MOVE %s -> %s", tempFileName.c_str(), sPath.c_str());
} }
return bRet; return bRet;
} }

View file

@ -71,5 +71,6 @@ namespace std
#endif #endif
#include "nel/misc/bsphere.h" #include "nel/misc/bsphere.h"
#include "nel/misc/path.h"
#endif #endif

View file

@ -895,12 +895,12 @@ void Browse::OnBatchLoad ()
std::string ext = NLMISC::CFile::getExtension(fullPath); std::string ext = NLMISC::CFile::getExtension(fullPath);
// look for some numbers.. // look for some numbers..
char *sNumber=sName+strlen(sName)-1; std::string::size_type pos = filename.find_last_not_of("0123456789");
while ((sNumber>sName)&&(*sNumber>='0')&&(*sNumber<='9'))
if (pos != std::string::npos)
{ {
sNumber--; filename = filename.substr(0, pos + 1);
} }
sNumber[1]=0;
bool rotate=false; bool rotate=false;
@ -1396,7 +1396,7 @@ void Browse::OnExportBorder()
try try
{ {
COFile file; COFile file;
if (file.open ((const char*)pathName)) if (file.open (tStrToUtf8(pathName)))
{ {
// Export // Export
bitmap.writeTGA (file, 32); bitmap.writeTGA (file, 32);
@ -1439,7 +1439,7 @@ void Browse::OnImportBorder()
try try
{ {
CIFile file; CIFile file;
if (file.open ((const char*)pathName)) if (file.open (tStrToUtf8(pathName)))
{ {
// Export // Export
bitmap.load (file); bitmap.load (file);

View file

@ -434,7 +434,7 @@ void CTile_browser_dlg::on_batchLoadPushButton_clicked()
QString batchNumber = transitionNumber.rightJustified(2, '0'); QString batchNumber = transitionNumber.rightJustified(2, '0');
QString nextBaseName = baseName + batchNumber; QString nextBaseName = baseName + batchNumber;
QString nextFileName = QDir::toNativeSeparators(fi.absolutePath()) + QDir::separator() + nextBaseName + QString(".") + fi.suffix(); 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 // Close the file and add the tile if opened
if (pFile) if (pFile)
@ -471,8 +471,7 @@ void CTile_browser_dlg::on_batchLoadPushButton_clicked()
// char sName2[256]; // char sName2[256];
// char sFinal[256]; // char sFinal[256];
// sprintf (sName2, "%s%02d", sName, (int)transition); // sprintf (sName2, "%s%02d", sName, (int)transition);
// _makepath (sFinal, sDrive, sPath, sName2, sExt); // FILE *pFile = nlfopen (sFinal, "rb");
// FILE *pFile=fopen (sFinal, "rb");
// // Close the file and add the tile if opened // // Close the file and add the tile if opened
// if (pFile) // if (pFile)

View file

@ -522,7 +522,7 @@ int main (int argc, char* argv[])
// Write the dependencies file // Write the dependencies file
FILE *outputFile; FILE *outputFile;
if ((outputFile=fopen (toLower (outputFileName).c_str(), "w"))) if ((outputFile = nlfopen (toLower (outputFileName), "w")))
{ {
// Add a dependency entry // Add a dependency entry
fprintf (outputFile, "dependencies =\n{\n"); fprintf (outputFile, "dependencies =\n{\n");

View file

@ -179,7 +179,7 @@ void setOutputFile(const CSString &filename)
{ {
if (Outf!=NULL) if (Outf!=NULL)
fclose(Outf); fclose(Outf);
Outf=fopen(filename.c_str(), "wt"); Outf = nlfopen(filename.c_str(), "wt");
if (Outf == NULL) if (Outf == NULL)
{ {
fprintf(stderr, "Can't open output file '%s' ! aborting.", filename.c_str()); fprintf(stderr, "Can't open output file '%s' ! aborting.", filename.c_str());

View file

@ -548,7 +548,7 @@ BOOL CGeorgesEditDoc::OnOpenDocument(LPCTSTR lpszPathName)
if (!extLower.empty ()) if (!extLower.empty ())
{ {
string dfnName = extLower.substr (1, string::npos) + ".dfn"; string dfnName = extLower + ".dfn";
// Check if the file is handled // Check if the file is handled
if (theApp.getFormDocTemplate (dfnName.c_str ()) == NULL) if (theApp.getFormDocTemplate (dfnName.c_str ()) == NULL)

View file

@ -48,6 +48,7 @@
#include "nel/misc/types_nl.h" #include "nel/misc/types_nl.h"
#include "nel/misc/debug.h" #include "nel/misc/debug.h"
#include "nel/misc/common.h" #include "nel/misc/common.h"
#include "nel/misc/path.h"
// Include from libxml2 // Include from libxml2
#include <libxml/parser.h> #include <libxml/parser.h>

View file

@ -1115,7 +1115,7 @@ int main (int argc, char**argv)
outString ("REMOVE " + CFile::getFilename (igFilename) + " \n"); outString ("REMOVE " + CFile::getFilename (igFilename) + " \n");
// Remove it // Remove it
if (remove (igFilename.c_str ()) != 0) if (!CFile::deleteFile(igFilename))
{ {
// Error in the log // Error in the log
nlwarning ("Error : Can't remove the file (%s)", igFilename.c_str ()); nlwarning ("Error : Can't remove the file (%s)", igFilename.c_str ());

View file

@ -52,7 +52,7 @@ CCharacterScanJob::CCharacterScanJob()
// open the output file for the character table // open the output file for the character table
std::string filename= "char_tbl.csv"; std::string filename= "char_tbl.csv";
_CharTblFile=fopen(filename.c_str(),"wb"); _CharTblFile = nlfopen(filename, "wb");
if (_CharTblFile==NULL) if (_CharTblFile==NULL)
{ {
nlwarning("Failed to open output file: %s",filename.c_str()); 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 // create the output file name and open the file for writing
std::string filename="char_stats_"+(*it).first+".csv"; std::string filename="char_stats_"+(*it).first+".csv";
FILE* f=fopen(filename.c_str(),"wb"); FILE* f = nlfopen(filename, "wb");
if (f==NULL) if (f==NULL)
{ {
nlwarning("Failed to open output file: %s",filename.c_str()); nlwarning("Failed to open output file: %s",filename.c_str());