mirror of
https://github.com/1dot13/source.git
synced 2026-09-09 14:46:05 +02:00
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:
@@ -599,6 +599,7 @@ BOOLEAN InitializeStandardGamingPlatform(HINSTANCE hInstance, int sCommandShow)
|
|||||||
}
|
}
|
||||||
catch(CBasicException& ex)
|
catch(CBasicException& ex)
|
||||||
{
|
{
|
||||||
|
LogException(ex);
|
||||||
// nothing is set up, no vfs, no video manager
|
// nothing is set up, no vfs, no video manager
|
||||||
// regular error processing wouldn't work here
|
// regular error processing wouldn't work here
|
||||||
// set default values and continue as if nothing has happened
|
// set default values and continue as if nothing has happened
|
||||||
@@ -1224,6 +1225,7 @@ void SGPExit(void)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern bool g_VFS_NO_UNICODE;
|
||||||
void GetRuntimeSettings( )
|
void GetRuntimeSettings( )
|
||||||
{
|
{
|
||||||
#ifndef USE_VFS
|
#ifndef USE_VFS
|
||||||
@@ -1248,6 +1250,8 @@ void GetRuntimeSettings( )
|
|||||||
#else
|
#else
|
||||||
iResolution = oProps.GetIntProperty(L"Ja2 Settings", L"SCREEN_RESOLUTION", -1);
|
iResolution = oProps.GetIntProperty(L"Ja2 Settings", L"SCREEN_RESOLUTION", -1);
|
||||||
|
|
||||||
|
g_VFS_NO_UNICODE = oProps.GetBoolProperty(L"Ja2 Settings", L"VFS_NO_UNICODE", false);
|
||||||
|
|
||||||
std::list<utf8string> ini_list;
|
std::list<utf8string> ini_list;
|
||||||
if(oProps.GetStringListProperty(L"Ja2 Settings", L"VFS_CONFIG_INI", ini_list, L""))
|
if(oProps.GetStringListProperty(L"Ja2 Settings", L"VFS_CONFIG_INI", ini_list, L""))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
#include "../Interface/vfs_directory_interface.h"
|
#include "../Interface/vfs_directory_interface.h"
|
||||||
#include "../iteratedir.h"
|
#include "../iteratedir.h"
|
||||||
|
|
||||||
|
extern bool g_VFS_NO_UNICODE;
|
||||||
|
|
||||||
vfs::Path vfs::CVFSFile::GetFullPath()
|
vfs::Path vfs::CVFSFile::GetFullPath()
|
||||||
{
|
{
|
||||||
if(_pLoc_)
|
if(_pLoc_)
|
||||||
@@ -65,7 +67,10 @@ bool vfs::CVFSFile::OpenRead()
|
|||||||
// try to open
|
// try to open
|
||||||
Mode = std::ios::in|std::ios::binary;
|
Mode = std::ios::in|std::ios::binary;
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
m_oFile.open(sFileName().c_wcs().c_str(),Mode);
|
utf8string::str_t const& fname = sFileName().c_wcs();
|
||||||
|
g_VFS_NO_UNICODE ?
|
||||||
|
m_oFile.open(utf8string::narrow(fname.c_str(),fname.length()).c_str(),Mode) :
|
||||||
|
m_oFile.open(fname.c_str(),Mode);
|
||||||
#else
|
#else
|
||||||
m_oFile.open(sFileName().utf8().c_str(),Mode);
|
m_oFile.open(sFileName().utf8().c_str(),Mode);
|
||||||
#endif
|
#endif
|
||||||
@@ -106,7 +111,10 @@ bool vfs::CVFSFile::OpenWrite(bool bCreateWhenNotExist, bool bTruncate)
|
|||||||
Mode |= std::ios::trunc;
|
Mode |= std::ios::trunc;
|
||||||
}
|
}
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
m_oFile.open(sFileName().c_wcs().c_str(),Mode);
|
utf8string::str_t const& fname = sFileName().c_wcs();
|
||||||
|
g_VFS_NO_UNICODE ?
|
||||||
|
m_oFile.open(utf8string::narrow(fname.c_str(),fname.length()).c_str(),Mode) :
|
||||||
|
m_oFile.open(fname.c_str(),Mode);
|
||||||
#else
|
#else
|
||||||
m_oFile.open(sFileName().utf8().c_str(),Mode);
|
m_oFile.open(sFileName().utf8().c_str(),Mode);
|
||||||
#endif
|
#endif
|
||||||
@@ -122,7 +130,9 @@ bool vfs::CVFSFile::OpenWrite(bool bCreateWhenNotExist, bool bTruncate)
|
|||||||
Mode |= std::ios::trunc;
|
Mode |= std::ios::trunc;
|
||||||
}
|
}
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
m_oFile.open(sFileName().c_wcs().c_str(),Mode);
|
g_VFS_NO_UNICODE ?
|
||||||
|
m_oFile.open(utf8string::narrow(fname.c_str(),fname.length()).c_str(),Mode) :
|
||||||
|
m_oFile.open(fname.c_str(),Mode);
|
||||||
#else
|
#else
|
||||||
m_oFile.open(sFileName().utf8().c_str(),Mode);
|
m_oFile.open(sFileName().utf8().c_str(),Mode);
|
||||||
#endif
|
#endif
|
||||||
@@ -133,7 +143,9 @@ bool vfs::CVFSFile::OpenWrite(bool bCreateWhenNotExist, bool bTruncate)
|
|||||||
m_oFile.close();
|
m_oFile.close();
|
||||||
Mode |= std::ios::in;
|
Mode |= std::ios::in;
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
m_oFile.open(sFileName().c_wcs().c_str(),Mode);
|
g_VFS_NO_UNICODE ?
|
||||||
|
m_oFile.open(utf8string::narrow(fname.c_str(),fname.length()).c_str(),Mode) :
|
||||||
|
m_oFile.open(fname.c_str(),Mode);
|
||||||
#else
|
#else
|
||||||
m_oFile.open(sFileName().utf8().c_str(),Mode);
|
m_oFile.open(sFileName().utf8().c_str(),Mode);
|
||||||
#endif
|
#endif
|
||||||
@@ -185,7 +197,10 @@ bool vfs::CVFSTextFile::OpenRead()
|
|||||||
std::ios::openmode Mode;
|
std::ios::openmode Mode;
|
||||||
Mode = std::ios::in;
|
Mode = std::ios::in;
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
m_oFile.open(sFileName().c_wcs().c_str(),Mode);
|
utf8string::str_t const& fname = sFileName().c_wcs();
|
||||||
|
g_VFS_NO_UNICODE ?
|
||||||
|
m_oFile.open(utf8string::narrow(fname.c_str(),fname.length()).c_str(),Mode) :
|
||||||
|
m_oFile.open(fname.c_str(),Mode);
|
||||||
#else
|
#else
|
||||||
m_oFile.open(sFileName().utf8().c_str(),Mode);
|
m_oFile.open(sFileName().utf8().c_str(),Mode);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+27
-7
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
extern bool g_VFS_NO_UNICODE;
|
||||||
|
|
||||||
vfs::CFile::CFile(vfs::Path const& sFileName)
|
vfs::CFile::CFile(vfs::Path const& sFileName)
|
||||||
: vfs::IFileTemplate<vfs::IReadable,vfs::IWriteable>(sFileName), m_bIsOpen_read(false), m_bIsOpen_write(false)
|
: vfs::IFileTemplate<vfs::IReadable,vfs::IWriteable>(sFileName), m_bIsOpen_read(false), m_bIsOpen_write(false)
|
||||||
{
|
{
|
||||||
@@ -58,7 +60,10 @@ bool vfs::CFile::OpenRead()
|
|||||||
// try to open
|
// try to open
|
||||||
Mode = std::ios::in|std::ios::binary;
|
Mode = std::ios::in|std::ios::binary;
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
m_oFile.open(m_sFileName().c_wcs().c_str(), Mode);
|
utf8string::str_t const& fname = m_sFileName().c_wcs();
|
||||||
|
g_VFS_NO_UNICODE ?
|
||||||
|
m_oFile.open( utf8string::narrow(fname.c_str(),fname.length()).c_str(), Mode ) :
|
||||||
|
m_oFile.open( fname.c_str(), Mode);
|
||||||
#else
|
#else
|
||||||
m_oFile.open(m_sFileName().utf8().c_str(), Mode);
|
m_oFile.open(m_sFileName().utf8().c_str(), Mode);
|
||||||
#endif
|
#endif
|
||||||
@@ -144,7 +149,10 @@ bool vfs::CFile::OpenWrite(bool bCreateWhenNotExist, bool bTruncate)
|
|||||||
Mode |= std::ios::trunc;
|
Mode |= std::ios::trunc;
|
||||||
}
|
}
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
m_oFile.open(m_sFileName().c_wcs().c_str(),Mode);
|
utf8string::str_t const& fname = m_sFileName().c_wcs();
|
||||||
|
g_VFS_NO_UNICODE ?
|
||||||
|
m_oFile.open(utf8string::narrow(fname.c_str(),fname.length()).c_str(),Mode) :
|
||||||
|
m_oFile.open(fname.c_str(),Mode);
|
||||||
#else
|
#else
|
||||||
m_oFile.open(m_sFileName().utf8().c_str(),Mode);
|
m_oFile.open(m_sFileName().utf8().c_str(),Mode);
|
||||||
#endif
|
#endif
|
||||||
@@ -161,7 +169,9 @@ bool vfs::CFile::OpenWrite(bool bCreateWhenNotExist, bool bTruncate)
|
|||||||
}
|
}
|
||||||
//m_oFile.open(VfsString(sFileName).AsString().c_str(),Mode);
|
//m_oFile.open(VfsString(sFileName).AsString().c_str(),Mode);
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
m_oFile.open(m_sFileName().c_wcs().c_str(),Mode);
|
g_VFS_NO_UNICODE ?
|
||||||
|
m_oFile.open(utf8string::narrow(fname.c_str(),fname.length()).c_str(),Mode) :
|
||||||
|
m_oFile.open(fname.c_str(),Mode);
|
||||||
#else
|
#else
|
||||||
m_oFile.open(m_sFileName().utf8().c_str(),Mode);
|
m_oFile.open(m_sFileName().utf8().c_str(),Mode);
|
||||||
#endif
|
#endif
|
||||||
@@ -172,7 +182,9 @@ bool vfs::CFile::OpenWrite(bool bCreateWhenNotExist, bool bTruncate)
|
|||||||
m_oFile.close();
|
m_oFile.close();
|
||||||
Mode |= std::ios::in;
|
Mode |= std::ios::in;
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
m_oFile.open(m_sFileName().c_wcs().c_str(),Mode);
|
g_VFS_NO_UNICODE ?
|
||||||
|
m_oFile.open(utf8string::narrow(fname.c_str(),fname.length()).c_str(),Mode) :
|
||||||
|
m_oFile.open(fname.c_str(),Mode);
|
||||||
#else
|
#else
|
||||||
m_oFile.open(m_sFileName().utf8().c_str(),Mode);
|
m_oFile.open(m_sFileName().utf8().c_str(),Mode);
|
||||||
#endif
|
#endif
|
||||||
@@ -299,7 +311,10 @@ bool vfs::CTextFile::OpenRead()
|
|||||||
std::ios::openmode Mode;
|
std::ios::openmode Mode;
|
||||||
Mode = std::ios::in;
|
Mode = std::ios::in;
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
m_oFile.open(m_sFileName().c_wcs().c_str(),Mode);
|
utf8string::str_t const& fname = m_sFileName().c_wcs();
|
||||||
|
g_VFS_NO_UNICODE ?
|
||||||
|
m_oFile.open(utf8string::narrow(fname.c_str(),fname.length()).c_str(),Mode) :
|
||||||
|
m_oFile.open(fname.c_str(),Mode);
|
||||||
#else
|
#else
|
||||||
m_oFile.open(m_sFileName().utf8().c_str(),Mode);
|
m_oFile.open(m_sFileName().utf8().c_str(),Mode);
|
||||||
#endif
|
#endif
|
||||||
@@ -322,7 +337,10 @@ bool vfs::CTextFile::OpenWrite(bool bCreateWhenNotExist, bool bTruncate)
|
|||||||
std::ios::openmode Mode;
|
std::ios::openmode Mode;
|
||||||
Mode = std::ios::out|std::ios::app;
|
Mode = std::ios::out|std::ios::app;
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
m_oFile.open(m_sFileName().c_wcs().c_str(),Mode);
|
utf8string::str_t const& fname = m_sFileName().c_wcs();
|
||||||
|
g_VFS_NO_UNICODE ?
|
||||||
|
m_oFile.open(utf8string::narrow(fname.c_str(),fname.length()).c_str(),Mode) :
|
||||||
|
m_oFile.open(fname.c_str(),Mode);
|
||||||
#else
|
#else
|
||||||
m_oFile.open(m_sFileName().utf8().c_str(),Mode);
|
m_oFile.open(m_sFileName().utf8().c_str(),Mode);
|
||||||
#endif
|
#endif
|
||||||
@@ -335,7 +353,9 @@ bool vfs::CTextFile::OpenWrite(bool bCreateWhenNotExist, bool bTruncate)
|
|||||||
Mode = std::ios::out;
|
Mode = std::ios::out;
|
||||||
Mode |= bTruncate ? std::ios::trunc : std::ios::app;
|
Mode |= bTruncate ? std::ios::trunc : std::ios::app;
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
m_oFile.open(m_sFileName().c_wcs().c_str(),Mode);
|
g_VFS_NO_UNICODE ?
|
||||||
|
m_oFile.open(utf8string::narrow(fname.c_str(),fname.length()).c_str(),Mode) :
|
||||||
|
m_oFile.open(fname.c_str(),Mode);
|
||||||
#else
|
#else
|
||||||
m_oFile.open(m_sFileName().utf8().c_str(),Mode);
|
m_oFile.open(m_sFileName().utf8().c_str(),Mode);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+60
-12
@@ -24,10 +24,21 @@ int file_select(struct direct *entry)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
extern bool g_VFS_NO_UNICODE;
|
||||||
|
|
||||||
os::CIterateDirectory::CIterateDirectory(vfs::Path const& sPath, utf8string const& searchPattern)
|
os::CIterateDirectory::CIterateDirectory(vfs::Path const& sPath, utf8string const& searchPattern)
|
||||||
{
|
{
|
||||||
#ifdef WIN32
|
#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)
|
if (fSearchHandle == INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
DWORD error = GetLastError();
|
DWORD error = GetLastError();
|
||||||
@@ -58,12 +69,27 @@ bool os::CIterateDirectory::NextFile(utf8string &fileName, CIterateDirectory::EF
|
|||||||
{
|
{
|
||||||
fFirstRequest = false;
|
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;
|
return true;
|
||||||
#else
|
#else
|
||||||
if(current_pos < count)
|
if(current_pos < count)
|
||||||
@@ -84,15 +110,33 @@ bool os::CreateRealDirecory(vfs::Path& sDir, bool bDoNotCreate)
|
|||||||
if(bDoNotCreate)
|
if(bDoNotCreate)
|
||||||
{
|
{
|
||||||
bool bDirExists = false;
|
bool bDirExists = false;
|
||||||
WIN32_FIND_DATAW fd;
|
if(g_VFS_NO_UNICODE)
|
||||||
memset(&fd,0,sizeof(WIN32_FIND_DATAW));
|
{
|
||||||
HANDLE hFile = FindFirstFileW( sDir().c_wcs().c_str(), &fd);
|
WIN32_FIND_DATAA fd;
|
||||||
bDirExists = fd.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY;
|
memset(&fd,0,sizeof(WIN32_FIND_DATAA));
|
||||||
FindClose(hFile);
|
|
||||||
|
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;
|
return bDirExists;
|
||||||
}
|
}
|
||||||
BOOL success;
|
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)
|
if(success == 0)
|
||||||
{
|
{
|
||||||
DWORD error = GetLastError();
|
DWORD error = GetLastError();
|
||||||
@@ -110,7 +154,11 @@ bool os::CreateRealDirecory(vfs::Path& sDir, bool bDoNotCreate)
|
|||||||
bool os::DeleteRealFile(vfs::Path &sDir)
|
bool os::DeleteRealFile(vfs::Path &sDir)
|
||||||
{
|
{
|
||||||
#ifdef WIN32
|
#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
|
#else
|
||||||
return (remove( sDir().utf8().c_str() ) == 0);
|
return (remove( sDir().utf8().c_str() ) == 0);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+5
-1
@@ -35,7 +35,11 @@ namespace os
|
|||||||
private:
|
private:
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
HANDLE fSearchHandle;
|
HANDLE fSearchHandle;
|
||||||
WIN32_FIND_DATAW fFileInfo;
|
union
|
||||||
|
{
|
||||||
|
WIN32_FIND_DATAA fFileInfoA;
|
||||||
|
WIN32_FIND_DATAW fFileInfoW;
|
||||||
|
};
|
||||||
#else
|
#else
|
||||||
struct direct **files;
|
struct direct **files;
|
||||||
int count, current_pos;
|
int count, current_pos;
|
||||||
|
|||||||
@@ -5,6 +5,9 @@
|
|||||||
#include "vfs_debug.h"
|
#include "vfs_debug.h"
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
bool g_VFS_NO_UNICODE = false;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
namespace _StrCmp
|
namespace _StrCmp
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////
|
||||||
@@ -242,6 +245,61 @@ std::string utf8string::as_utf8(std::string const& str)
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t utf8string::narrow(std::wstring const& src, std::string& dst)
|
||||||
|
{
|
||||||
|
size_t len = utf8string::narrow(src.c_str(),src.length(),NULL,0);
|
||||||
|
dst.resize(len);
|
||||||
|
return utf8string::narrow(src.c_str(),src.length(),&dst[0],len);
|
||||||
|
}
|
||||||
|
std::string utf8string::narrow(wchar_t const* str, size_t length)
|
||||||
|
{
|
||||||
|
size_t len = utf8string::narrow(str,length,NULL,0);
|
||||||
|
std::string s;
|
||||||
|
s.resize(len);
|
||||||
|
utf8string::narrow(str,length,&s[0],len);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
size_t utf8string::narrow(wchar_t const* src_str, size_t src_len, char* dst_str, size_t dst_len)
|
||||||
|
{
|
||||||
|
if(src_str && src_len>0)
|
||||||
|
{
|
||||||
|
if(!dst_str || dst_len==0)
|
||||||
|
{
|
||||||
|
return wcstombs(NULL, src_str, src_len);
|
||||||
|
}
|
||||||
|
return wcstombs(dst_str, src_str, std::min<size_t>(src_len,dst_len));
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
std::wstring utf8string::widen(char const* str, size_t length)
|
||||||
|
{
|
||||||
|
size_t len = utf8string::widen(str,length,NULL,0);
|
||||||
|
std::wstring ws;
|
||||||
|
ws.resize(len);
|
||||||
|
utf8string::widen(str,length,&ws[0],len);
|
||||||
|
return ws;
|
||||||
|
}
|
||||||
|
size_t utf8string::widen(std::string const& src, std::wstring& dst)
|
||||||
|
{
|
||||||
|
size_t len = utf8string::widen(src.c_str(),src.length(),NULL,0);
|
||||||
|
dst.resize(len);
|
||||||
|
return utf8string::widen(src.c_str(),src.length(),&dst[0],len);
|
||||||
|
}
|
||||||
|
size_t utf8string::widen(char const* src_str, size_t src_len, wchar_t* dst_str, size_t dst_len)
|
||||||
|
{
|
||||||
|
if(src_str && src_len>0)
|
||||||
|
{
|
||||||
|
if(!dst_str || dst_len==0)
|
||||||
|
{
|
||||||
|
return mbstowcs(NULL, src_str, src_len);
|
||||||
|
}
|
||||||
|
return mbstowcs(dst_str, src_str, std::min<size_t>(src_len,dst_len));
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
/// get string methods
|
/// get string methods
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
+10
-3
@@ -51,11 +51,18 @@ public:
|
|||||||
static utf8string::str_t as_utf16(std::string const& str);
|
static utf8string::str_t as_utf16(std::string const& str);
|
||||||
static void as_utf16(std::string const& str, utf8string::str_t &str16);
|
static void as_utf16(std::string const& str, utf8string::str_t &str16);
|
||||||
// fast conversion without creating an internal copy
|
// fast conversion without creating an internal copy
|
||||||
static std::string as_utf8(utf8string const& str);
|
static std::string as_utf8(utf8string const& str);
|
||||||
static std::string as_utf8(std::wstring const& str);
|
static std::string as_utf8(std::wstring const& str);
|
||||||
// if 'strlen' is 0, length is determined automatically
|
// if 'strlen' is 0, length is determined automatically
|
||||||
static std::string as_utf8(const wchar_t* str, unsigned int strlength=0);
|
static std::string as_utf8(const wchar_t* str, unsigned int strlength=0);
|
||||||
//
|
//
|
||||||
|
static std::string narrow(wchar_t const* str, size_t length);
|
||||||
|
static size_t narrow(wchar_t const* src_str, size_t src_len, char* dst_str, size_t dst_len);
|
||||||
|
static size_t narrow(std::wstring const& src, std::string& dst);
|
||||||
|
//
|
||||||
|
static std::wstring widen(char const* str, size_t length);
|
||||||
|
static size_t widen(char const* src_str, size_t src_len, wchar_t* dst_str, size_t dst_len);
|
||||||
|
static size_t widen(std::string const& src, std::wstring& dst);
|
||||||
|
|
||||||
// convenience method, for the case it should be used in generic code (overloading)
|
// convenience method, for the case it should be used in generic code (overloading)
|
||||||
static std::string as_utf8(std::string const& str);
|
static std::string as_utf8(std::string const& str);
|
||||||
|
|||||||
+7
-4
@@ -10,12 +10,14 @@
|
|||||||
#include "PropertyContainer.h"
|
#include "PropertyContainer.h"
|
||||||
#include "Tools/Log.h"
|
#include "Tools/Log.h"
|
||||||
|
|
||||||
//#define LOG_VFS_INITIALIZATION
|
#define LOG_VFS_INITIALIZATION
|
||||||
#ifdef LOG_VFS_INITIALIZATION
|
#ifdef LOG_VFS_INITIALIZATION
|
||||||
#define LOG(x) (x)
|
#define LOG(x) x
|
||||||
#else
|
#else
|
||||||
#define LOG(x)
|
#define LOG(x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
extern bool g_VFS_NO_UNICODE;
|
||||||
/********************************************************************/
|
/********************************************************************/
|
||||||
/********************************************************************/
|
/********************************************************************/
|
||||||
|
|
||||||
@@ -41,8 +43,9 @@ bool InitVirtualFileSystem(CPropertyContainer& oVFSProps)
|
|||||||
|
|
||||||
vfs::CVirtualFileSystem *pVirtFileSys = GetVFS();
|
vfs::CVirtualFileSystem *pVirtFileSys = GetVFS();
|
||||||
|
|
||||||
LOG(_LOG << "Initializing Virtual File System");
|
LOG(_LOG << "Initializing Virtual File System" << CLog::endl);
|
||||||
LOG(_LOG.Endl());
|
|
||||||
|
if(g_VFS_NO_UNICODE){ LOG(_LOG.Endl() << "UNICODE disabled" << CLog::endl); }
|
||||||
|
|
||||||
LOG(_LOG.Endl() << "reading profiles .. ");
|
LOG(_LOG.Endl() << "reading profiles .. ");
|
||||||
std::list<utf8string> lProfiles, lLocSections;
|
std::list<utf8string> lProfiles, lLocSections;
|
||||||
|
|||||||
Reference in New Issue
Block a user