Win 98 VFS Fixes (by BirdFlu)

- add ini option to disable UNICODE in VFS (and use the current codepage)
- when UNICODE disabled in VFS, open files with default encoding (instead of UTF8/16) filenames


git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@3118 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
Wanne
2009-07-20 08:14:37 +00:00
parent 98507b972b
commit 06a2af0fa6
8 changed files with 191 additions and 32 deletions
+60 -12
View File
@@ -24,10 +24,21 @@ int file_select(struct direct *entry)
#endif
extern bool g_VFS_NO_UNICODE;
os::CIterateDirectory::CIterateDirectory(vfs::Path const& sPath, utf8string const& searchPattern)
{
#ifdef WIN32
fSearchHandle = FindFirstFileW((sPath+searchPattern)().c_wcs().c_str(), &fFileInfo);
if(g_VFS_NO_UNICODE)
{
std::string s;
utf8string::narrow((sPath+searchPattern)().c_wcs(), s);
fSearchHandle = FindFirstFileA(s.c_str(), &fFileInfoA);
}
else
{
fSearchHandle = FindFirstFileW((sPath+searchPattern)().c_wcs().c_str(), &fFileInfoW);
}
if (fSearchHandle == INVALID_HANDLE_VALUE)
{
DWORD error = GetLastError();
@@ -58,12 +69,27 @@ bool os::CIterateDirectory::NextFile(utf8string &fileName, CIterateDirectory::EF
{
fFirstRequest = false;
}
else if ( !FindNextFileW(fSearchHandle, &fFileInfo) )
//else
{
return false;
if(g_VFS_NO_UNICODE)
{
if( !FindNextFileA(fSearchHandle, &fFileInfoA) )
{
return false;
}
fileName.r_wcs().assign( utf8string::widen( fFileInfoA.cFileName, strlen(fFileInfoA.cFileName) ) );
attrib = (fFileInfoA.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? CIterateDirectory::FA_DIRECTORY : CIterateDirectory::FA_FILE;
}
else
{
if ( !FindNextFileW(fSearchHandle, &fFileInfoW) )
{
return false;
}
fileName.r_wcs().assign(fFileInfoW.cFileName);
attrib = (fFileInfoW.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? CIterateDirectory::FA_DIRECTORY : CIterateDirectory::FA_FILE;
}
}
fileName.r_wcs().assign(fFileInfo.cFileName);
attrib = (fFileInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? CIterateDirectory::FA_DIRECTORY : CIterateDirectory::FA_FILE;
return true;
#else
if(current_pos < count)
@@ -84,15 +110,33 @@ bool os::CreateRealDirecory(vfs::Path& sDir, bool bDoNotCreate)
if(bDoNotCreate)
{
bool bDirExists = false;
WIN32_FIND_DATAW fd;
memset(&fd,0,sizeof(WIN32_FIND_DATAW));
HANDLE hFile = FindFirstFileW( sDir().c_wcs().c_str(), &fd);
bDirExists = fd.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY;
FindClose(hFile);
if(g_VFS_NO_UNICODE)
{
WIN32_FIND_DATAA fd;
memset(&fd,0,sizeof(WIN32_FIND_DATAA));
std::string s;
utf8string::narrow(sDir().c_wcs(), s);
HANDLE hFile = FindFirstFileA( s.c_str(), &fd);
bDirExists = fd.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY;
FindClose(hFile);
}
else
{
WIN32_FIND_DATAW fd;
memset(&fd,0,sizeof(WIN32_FIND_DATAW));
HANDLE hFile = FindFirstFileW( sDir().c_wcs().c_str(), &fd);
bDirExists = fd.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY;
FindClose(hFile);
}
return bDirExists;
}
BOOL success;
success = CreateDirectoryW(sDir().c_wcs().c_str(),NULL);
utf8string::str_t const& str = sDir().c_wcs();
success = g_VFS_NO_UNICODE ?
CreateDirectoryA( utf8string::narrow( str.c_str(), str.length() ).c_str(), NULL ) :
CreateDirectoryW(sDir().c_wcs().c_str(),NULL);
if(success == 0)
{
DWORD error = GetLastError();
@@ -110,7 +154,11 @@ bool os::CreateRealDirecory(vfs::Path& sDir, bool bDoNotCreate)
bool os::DeleteRealFile(vfs::Path &sDir)
{
#ifdef WIN32
return (DeleteFileW( sDir().c_wcs().c_str() ) != FALSE);
utf8string::str_t const& str = sDir().c_wcs();
BOOL del = g_VFS_NO_UNICODE ?
DeleteFileA( utf8string::narrow(str.c_str(), str.length()).c_str() ) :
DeleteFileW( str.c_str() );
return (del != FALSE);
#else
return (remove( sDir().utf8().c_str() ) == 0);
#endif