Changed: Removed unused methods and used TCHARs

--HG--
branch : develop
This commit is contained in:
kervala 2016-12-10 19:42:02 +01:00
parent a1baec9de2
commit 3d36a4bfb5

View file

@ -18,103 +18,42 @@
#include "nel_export.h" #include "nel_export.h"
//-------------------------------------------------------------------------------------------------------------- #include "nel/misc/path.h"
ULONG CNelExport::ExtractFileName(char* Path, char* Name) #ifdef DEBUG_NEW
{ #define new DEBUG_NEW
long i,j; #endif
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);
}
//-------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------
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--); std::string path, filename;
strncpy(Path,FullPath,i+1);
Path[i+1]=0;
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]) if (!FileName[0])
{ {
GetCurrentDirectory(MAX_PATH,curdir); path = NLMISC::CPath::getCurrentPath();
} }
else else
{ {
ExtractPath(FileName,curdir); path = NLMISC::CFile::getPath(FileName);
if (!curdir[0])
if (path.empty())
{ {
GetCurrentDirectory(MAX_PATH,curdir); path = NLMISC::CPath::getCurrentPath();
} }
ExtractFileName(FileName,fname);
filename = NLMISC::CFile::getFilename(FileName);
} }
memset(&ofn,0,sizeof(OPENFILENAME)); // copy path and filename to temporary buffers
ofn.lStructSize = sizeof ( OPENFILENAME ); _tcscpy_s(curdir, MAX_PATH, utf8ToTStr(path));
ofn.hwndOwner = Parent; _tcscpy_s(fname, MAX_PATH, utf8ToTStr(filename));
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);
}
OPENFILENAME ofn;
memset(&ofn,0,sizeof(OPENFILENAME)); memset(&ofn,0,sizeof(OPENFILENAME));
ofn.lStructSize = sizeof ( OPENFILENAME ); ofn.lStructSize = sizeof ( OPENFILENAME );
ofn.hwndOwner = Parent; ofn.hwndOwner = Parent;
@ -126,201 +65,40 @@ ULONG CNelExport::SelectFileForSave(HWND Parent, char* Title, const char* Mask,
ofn.nMaxFile = 500; ofn.nMaxFile = 500;
ofn.lpstrTitle = Title; ofn.lpstrTitle = Title;
ofn.Flags = OFN_HIDEREADONLY | OFN_LONGNAMES | OFN_OVERWRITEPROMPT; ofn.Flags = OFN_HIDEREADONLY | OFN_LONGNAMES | OFN_OVERWRITEPROMPT;
ofn.lpstrDefExt = "*"; ofn.lpstrDefExt = _T("*");
ofn.lpstrInitialDir = curdir; ofn.lpstrInitialDir = curdir;
r=GetSaveFileName ( &ofn ); BOOL r = GetSaveFileName ( &ofn );
strcpy(FileName,fname);
return(r); 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; TCHAR str[MAX_PATH];
char str[MAX_PATH]; _tcscpy_s(str, MAX_PATH, utf8ToTStr(Path));
ITEMIDLIST* pidl;
BROWSEINFO bi;
bi.hwndOwner=Parent; bi.hwndOwner=Parent;
bi.pidlRoot=NULL; bi.pidlRoot=NULL;
bi.pszDisplayName=Path; bi.pszDisplayName=str;
bi.lpszTitle=Title; bi.lpszTitle=Title;
bi.ulFlags=0; bi.ulFlags=0;
bi.lpfn=0; bi.lpfn=0;
bi.lParam=0; bi.lParam=0;
bi.iImage=0; bi.iImage=0;
pidl=SHBrowseForFolder(&bi);
ITEMIDLIST* pidl = SHBrowseForFolder(&bi);
if (!SHGetPathFromIDList(pidl,str) ) 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<strlen(FileName) ; i++)
{
found=0;
if (FileName[i]=='\\' && i!=0 && FileName[i-1]!='\\') { str[j]='\\'; j++; found=1; }
if (FileName[i]=='/' && i!=0 && FileName[i-1]!='/') { str[j]='/'; j++; found=1; }
if (!found) { str[j]=FileName[i]; j++; }
}
return(1);
}
//--------------------------------------------------------------------------------------------------------------
ULONG CNelExport::CreateBAKFile(char* FileName)
{
FILE *fin,*fout;
unsigned long fsize;
char *block;
char str[MAX_PATH];
if ( !FileExists(FileName) )
{
return(1);
}
fin=fopen(FileName,"rb");
if (!fin)
{
//SetError("CreateBAKFile, unable to open %s",FileName);
return(0);
}
fsize=GetFileSize(FileName);
if (!fsize)
{
//SetError("CreateBAKFile, unable to get file size for %s",FileName);
return(0);
}
block=(char*)calloc(1,fsize);
if (!block)
{
//SetError("CreateBAKFile, not enough memory");
return(0);
}
fread(block,1,fsize,fin);
fclose(fin);
strcpy(str,FileName);
str[strlen(str)-1]='K';
str[strlen(str)-2]='A';
str[strlen(str)-3]='B';
fout=fopen(str,"w+b");
if (!fout)
{
//SetError("CreateBAKFile, unable to open %s",str);
return(0);
}
fwrite(block,1,fsize,fout);
fclose(fout);
return(1);
}