diff --git a/code/nel/tools/3d/plugin_max/nel_export/nel_export_filetools.cpp b/code/nel/tools/3d/plugin_max/nel_export/nel_export_filetools.cpp index 5bafa24c5..7ecb61efe 100644 --- a/code/nel/tools/3d/plugin_max/nel_export/nel_export_filetools.cpp +++ b/code/nel/tools/3d/plugin_max/nel_export/nel_export_filetools.cpp @@ -18,103 +18,42 @@ #include "nel_export.h" -//-------------------------------------------------------------------------------------------------------------- +#include "nel/misc/path.h" -ULONG CNelExport::ExtractFileName(char* Path, char* Name) -{ - long i,j; - char temp[MAX_PATH]; - - for(j=0,i=strlen(Path)-1 ; i>=0 && Path[i]!='\\' && Path[i]!='//' ; i--,j++) - temp[j]=Path[i]; - temp[j]=0; - - for(i=strlen(temp)-1,j=0 ; i>=0 ; i--,j++) - Name[j]=temp[i]; - Name[j]=0; - - return(1); -} +#ifdef DEBUG_NEW +#define new DEBUG_NEW +#endif //-------------------------------------------------------------------------------------------------------------- -ULONG CNelExport::ExtractPath(char* FullPath, char* Path) +ULONG CNelExport::SelectFileForSave(HWND Parent, TCHAR* Title, const TCHAR* Mask, std::string &FileName) { - long i; + TCHAR curdir[MAX_PATH]; + TCHAR fname[MAX_PATH]; - for(i=strlen(FullPath)-1 ; i>=0 && FullPath[i]!='\\' && FullPath[i]!='//' ; i--); - strncpy(Path,FullPath,i+1); - Path[i+1]=0; + std::string path, filename; - return(1); -} - -//-------------------------------------------------------------------------------------------------------------- - -ULONG CNelExport::SelectFileForLoad(HWND Parent, char* Title, const char* Mask, char* FileName) -{ - OPENFILENAME ofn; - char r; - char curdir[MAX_PATH]; - char fname[MAX_PATH]; - - fname[0]=0; if (!FileName[0]) { - GetCurrentDirectory(MAX_PATH,curdir); + path = NLMISC::CPath::getCurrentPath(); } else { - ExtractPath(FileName,curdir); - if (!curdir[0]) + path = NLMISC::CFile::getPath(FileName); + + if (path.empty()) { - GetCurrentDirectory(MAX_PATH,curdir); + path = NLMISC::CPath::getCurrentPath(); } - ExtractFileName(FileName,fname); + + filename = NLMISC::CFile::getFilename(FileName); } - memset(&ofn,0,sizeof(OPENFILENAME)); - ofn.lStructSize = sizeof ( OPENFILENAME ); - ofn.hwndOwner = Parent; - ofn.hInstance = GetModuleHandle(NULL); - ofn.lpstrFilter = Mask; - ofn.lpstrCustomFilter = NULL; - ofn.nFilterIndex = 0; - ofn.lpstrFile = fname; - ofn.nMaxFile = 500; - ofn.lpstrTitle = Title; - ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_LONGNAMES | OFN_OVERWRITEPROMPT; - ofn.lpstrDefExt = "*"; - ofn.lpstrInitialDir = curdir; - r=GetOpenFileName ( &ofn ); - strcpy(FileName,fname); - return(r); -} - -//-------------------------------------------------------------------------------------------------------------- - -ULONG CNelExport::SelectFileForSave(HWND Parent, char* Title, const char* Mask, char* FileName) -{ - OPENFILENAME ofn; - char r; - char curdir[MAX_PATH]; - char fname[MAX_PATH]; - - fname[0]=0; - if (!FileName[0]) - { - GetCurrentDirectory(MAX_PATH,curdir); - } - else - { - ExtractPath(FileName,curdir); - if (!curdir[0]) - { - GetCurrentDirectory(MAX_PATH,curdir); - } - ExtractFileName(FileName,fname); - } + // copy path and filename to temporary buffers + _tcscpy_s(curdir, MAX_PATH, utf8ToTStr(path)); + _tcscpy_s(fname, MAX_PATH, utf8ToTStr(filename)); + OPENFILENAME ofn; memset(&ofn,0,sizeof(OPENFILENAME)); ofn.lStructSize = sizeof ( OPENFILENAME ); ofn.hwndOwner = Parent; @@ -126,201 +65,40 @@ ULONG CNelExport::SelectFileForSave(HWND Parent, char* Title, const char* Mask, ofn.nMaxFile = 500; ofn.lpstrTitle = Title; ofn.Flags = OFN_HIDEREADONLY | OFN_LONGNAMES | OFN_OVERWRITEPROMPT; - ofn.lpstrDefExt = "*"; + ofn.lpstrDefExt = _T("*"); ofn.lpstrInitialDir = curdir; - r=GetSaveFileName ( &ofn ); - strcpy(FileName,fname); - return(r); + BOOL r = GetSaveFileName ( &ofn ); + + FileName = tStrToUtf8(fname); + + return r; } //-------------------------------------------------------------------------------------------------------------- -ULONG CNelExport::SelectDir(HWND Parent, char* Title, char* Path) +ULONG CNelExport::SelectDir(HWND Parent, TCHAR* Title, std::string &Path) { - BROWSEINFO bi; - char str[MAX_PATH]; - ITEMIDLIST* pidl; + TCHAR str[MAX_PATH]; + _tcscpy_s(str, MAX_PATH, utf8ToTStr(Path)); + BROWSEINFO bi; bi.hwndOwner=Parent; bi.pidlRoot=NULL; - bi.pszDisplayName=Path; + bi.pszDisplayName=str; bi.lpszTitle=Title; bi.ulFlags=0; bi.lpfn=0; bi.lParam=0; bi.iImage=0; - pidl=SHBrowseForFolder(&bi); + + ITEMIDLIST* pidl = SHBrowseForFolder(&bi); + if (!SHGetPathFromIDList(pidl,str) ) { - return(0); + return 0; } - strcpy(Path,str); - return(1); + + Path = tStrToUtf8(str); + + return 1; } - -//-------------------------------------------------------------------------------------------------------------- - -ULONG CNelExport::FileExists(const char* FileName) -{ - FILE *file; - if ( !strcmp(FileName,"") ) return(0); - file=fopen(FileName,"rb"); - if (!file) return(0); - fclose(file); - return(1); -} - -//-------------------------------------------------------------------------------------------------------------- - -ULONG CNelExport::GetFileSize(char* FileName) -{ - FILE *file; - unsigned long fsize; - - file=fopen(FileName,"rb"); - if (!file) return(0); - fseek(file,0,SEEK_END); - fsize=ftell(file); - fclose(file); - return(fsize); -} - -//-------------------------------------------------------------------------------------------------------------- - -ULONG CNelExport::ProcessDir(char* Dir, const char* Mask, unsigned long flag, ULONG Fnct(char* FileName) ) -{ - char ToFound[MAX_PATH]; - char FullDir[MAX_PATH]; - char str[MAX_PATH]; - HANDLE h; - WIN32_FIND_DATA fi; - BOOL r; - - GetFullPathName(Dir,MAX_PATH,FullDir,NULL); - // --- Directory - if (flag) - { - strcpy(ToFound,Dir); - if ( ToFound[strlen(ToFound)-1]!='\\') - strcat(ToFound,"\\"); - strcat(ToFound,"*.*"); - h=FindFirstFile(ToFound,&fi); - if (h!=INVALID_HANDLE_VALUE) - { - r=1; - while(r) - { - if ( strcmp(fi.cFileName,".") && strcmp(fi.cFileName,"..") ) - { - if ( - fi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY && - !(fi.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) - ) - { - strcpy(str,Dir); - if ( str[strlen(str)-1]!='\\' ) strcat(str,"\\"); - strcat(str,fi.cFileName); - if ( !ProcessDir(str,Mask,flag,Fnct) ) return(0); - } - } - r=FindNextFile(h,&fi); - } - FindClose(h); - } - } - // --- Files - strcpy(ToFound,Dir); - if ( ToFound[strlen(ToFound)-1]!='\\') strcat(ToFound,"\\"); - strcat(ToFound,Mask); - h=FindFirstFile(ToFound,&fi); - if (h!=INVALID_HANDLE_VALUE) - { - r=1; - while(r) - { - if ( strcmp(fi.cFileName,".") && strcmp(fi.cFileName,"..") ) - { - if ( !(fi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ) - { - strcpy(str,FullDir); - if ( str[strlen(str)-1]!='\\' ) strcat(str,"\\"); - strcat(str,fi.cFileName); - ::strupr(str); - if ( !Fnct(str) ) return(0); - } - } - r=FindNextFile(h,&fi); - } - FindClose(h); - } - return(1); -} - -//-------------------------------------------------------------------------------------------------------------- - -ULONG CNelExport::CleanFileName(char* FileName) -{ - char str[MAX_PATH]; - unsigned long i,j,found; - - j=0; - for(i=0 ; i