Use UTF8 for writing file configuation data in
Unicode mode. I assume that the registry also will use Unicode in Unicode mode. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@17581 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -261,13 +261,13 @@ wxString wxFileConfig::GetGlobalDir()
|
|||||||
{
|
{
|
||||||
wxString strDir;
|
wxString strDir;
|
||||||
|
|
||||||
#ifdef __VMS__ // Note if __VMS is defined __UNIX is also defined
|
#ifdef __VMS__ // Note if __VMS is defined __UNIX is also defined
|
||||||
strDir = wxT("sys$manager:");
|
strDir = wxT("sys$manager:");
|
||||||
#elif defined(__WXMAC__)
|
#elif defined(__WXMAC__)
|
||||||
strDir = wxMacFindFolder( (short) kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder ) ;
|
strDir = wxMacFindFolder( (short) kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder ) ;
|
||||||
#elif defined( __UNIX__ )
|
#elif defined( __UNIX__ )
|
||||||
strDir = wxT("/etc/");
|
strDir = wxT("/etc/");
|
||||||
#elif defined(__WXPM__)
|
#elif defined(__WXPM__)
|
||||||
ULONG aulSysInfo[QSV_MAX] = {0};
|
ULONG aulSysInfo[QSV_MAX] = {0};
|
||||||
UINT drive;
|
UINT drive;
|
||||||
APIRET rc;
|
APIRET rc;
|
||||||
@@ -278,19 +278,19 @@ wxString wxFileConfig::GetGlobalDir()
|
|||||||
drive = aulSysInfo[QSV_BOOT_DRIVE - 1];
|
drive = aulSysInfo[QSV_BOOT_DRIVE - 1];
|
||||||
strDir.Printf(wxT("%c:\\OS2\\"), 'A'+drive-1);
|
strDir.Printf(wxT("%c:\\OS2\\"), 'A'+drive-1);
|
||||||
}
|
}
|
||||||
#elif defined(__WXSTUBS__)
|
#elif defined(__WXSTUBS__)
|
||||||
wxASSERT_MSG( FALSE, wxT("TODO") ) ;
|
wxASSERT_MSG( FALSE, wxT("TODO") ) ;
|
||||||
#elif defined(__DOS__)
|
#elif defined(__DOS__)
|
||||||
// There's no such thing as global cfg dir in MS-DOS, let's return
|
// There's no such thing as global cfg dir in MS-DOS, let's return
|
||||||
// current directory (FIXME_MGL?)
|
// current directory (FIXME_MGL?)
|
||||||
return wxT(".\\");
|
return wxT(".\\");
|
||||||
#else // Windows
|
#else // Windows
|
||||||
wxChar szWinDir[MAX_PATH];
|
wxChar szWinDir[MAX_PATH];
|
||||||
::GetWindowsDirectory(szWinDir, MAX_PATH);
|
::GetWindowsDirectory(szWinDir, MAX_PATH);
|
||||||
|
|
||||||
strDir = szWinDir;
|
strDir = szWinDir;
|
||||||
strDir << wxT('\\');
|
strDir << wxT('\\');
|
||||||
#endif // Unix/Windows
|
#endif // Unix/Windows
|
||||||
|
|
||||||
return strDir;
|
return strDir;
|
||||||
}
|
}
|
||||||
@@ -305,14 +305,14 @@ wxString wxFileConfig::GetLocalDir()
|
|||||||
#else
|
#else
|
||||||
wxGetHomeDir(&strDir);
|
wxGetHomeDir(&strDir);
|
||||||
|
|
||||||
# ifdef __UNIX__
|
#ifdef __UNIX__
|
||||||
# ifdef __VMS
|
#ifdef __VMS
|
||||||
if (strDir.Last() != wxT(']'))
|
if (strDir.Last() != wxT(']'))
|
||||||
# endif
|
#endif
|
||||||
if (strDir.Last() != wxT('/')) strDir << wxT('/');
|
if (strDir.Last() != wxT('/')) strDir << wxT('/');
|
||||||
# else
|
#else
|
||||||
if (strDir.Last() != wxT('\\')) strDir << wxT('\\');
|
if (strDir.Last() != wxT('\\')) strDir << wxT('\\');
|
||||||
# endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return strDir;
|
return strDir;
|
||||||
@@ -324,41 +324,43 @@ wxString wxFileConfig::GetGlobalFileName(const wxChar *szFile)
|
|||||||
str << szFile;
|
str << szFile;
|
||||||
|
|
||||||
if ( wxStrchr(szFile, wxT('.')) == NULL )
|
if ( wxStrchr(szFile, wxT('.')) == NULL )
|
||||||
#if defined( __WXMAC__ )
|
#if defined( __WXMAC__ )
|
||||||
str << " Preferences";
|
str << " Preferences";
|
||||||
#elif defined( __UNIX__ )
|
#elif defined( __UNIX__ )
|
||||||
str << wxT(".conf");
|
str << wxT(".conf");
|
||||||
#else // Windows
|
#else // Windows
|
||||||
str << wxT(".ini");
|
str << wxT(".ini");
|
||||||
#endif // UNIX/Win
|
#endif // UNIX/Win
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString wxFileConfig::GetLocalFileName(const wxChar *szFile)
|
wxString wxFileConfig::GetLocalFileName(const wxChar *szFile)
|
||||||
{
|
{
|
||||||
#ifdef __VMS__ // On VMS I saw the problem that the home directory was appended
|
#ifdef __VMS__
|
||||||
// twice for the configuration file. Does that also happen for other
|
// On VMS I saw the problem that the home directory was appended
|
||||||
// platforms?
|
// twice for the configuration file. Does that also happen for
|
||||||
|
// other platforms?
|
||||||
wxString str = wxT( '.' );
|
wxString str = wxT( '.' );
|
||||||
#else
|
#else
|
||||||
wxString str = GetLocalDir();
|
wxString str = GetLocalDir();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined( __UNIX__ ) && !defined( __VMS ) && !defined( __WXMAC__ )
|
#if defined( __UNIX__ ) && !defined( __VMS ) && !defined( __WXMAC__ )
|
||||||
str << wxT('.');
|
str << wxT('.');
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
str << szFile;
|
str << szFile;
|
||||||
|
|
||||||
#if defined(__WINDOWS__) || defined(__DOS__)
|
#if defined(__WINDOWS__) || defined(__DOS__)
|
||||||
if ( wxStrchr(szFile, wxT('.')) == NULL )
|
if ( wxStrchr(szFile, wxT('.')) == NULL )
|
||||||
str << wxT(".ini");
|
str << wxT(".ini");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __WXMAC__
|
#ifdef __WXMAC__
|
||||||
str << " Preferences";
|
str << " Preferences";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -374,31 +376,45 @@ void wxFileConfig::Init()
|
|||||||
m_linesHead =
|
m_linesHead =
|
||||||
m_linesTail = NULL;
|
m_linesTail = NULL;
|
||||||
|
|
||||||
// it's not an error if (one of the) file(s) doesn't exist
|
// It's not an error if (one of the) file(s) doesn't exist.
|
||||||
|
|
||||||
// parse the global file
|
// parse the global file
|
||||||
if ( !m_strGlobalFile.IsEmpty() && wxFile::Exists(m_strGlobalFile) ) {
|
if ( !m_strGlobalFile.IsEmpty() && wxFile::Exists(m_strGlobalFile) )
|
||||||
|
{
|
||||||
wxTextFile fileGlobal(m_strGlobalFile);
|
wxTextFile fileGlobal(m_strGlobalFile);
|
||||||
|
|
||||||
if ( fileGlobal.Open() ) {
|
#if defined(__WXGTK20__) && wxUSE_UNICODE
|
||||||
|
if ( fileGlobal.Open( wxConvUTF8 ) )
|
||||||
|
#else
|
||||||
|
if ( fileGlobal.Open() )
|
||||||
|
#endif
|
||||||
|
{
|
||||||
Parse(fileGlobal, FALSE /* global */);
|
Parse(fileGlobal, FALSE /* global */);
|
||||||
SetRootPath();
|
SetRootPath();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
wxLogWarning(_("can't open global configuration file '%s'."),
|
{
|
||||||
m_strGlobalFile.c_str());
|
wxLogWarning(_("can't open global configuration file '%s'."), m_strGlobalFile.c_str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse the local file
|
// parse the local file
|
||||||
if ( !m_strLocalFile.IsEmpty() && wxFile::Exists(m_strLocalFile) ) {
|
if ( !m_strLocalFile.IsEmpty() && wxFile::Exists(m_strLocalFile) )
|
||||||
|
{
|
||||||
wxTextFile fileLocal(m_strLocalFile);
|
wxTextFile fileLocal(m_strLocalFile);
|
||||||
if ( fileLocal.Open() ) {
|
#if defined(__WXGTK20__) && wxUSE_UNICODE
|
||||||
|
if ( fileLocal.Open( wxConvUTF8 ) )
|
||||||
|
#else
|
||||||
|
if ( fileLocal.Open() )
|
||||||
|
#endif
|
||||||
|
{
|
||||||
Parse(fileLocal, TRUE /* local */);
|
Parse(fileLocal, TRUE /* local */);
|
||||||
SetRootPath();
|
SetRootPath();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
wxLogWarning(_("can't open user configuration file '%s'."),
|
{
|
||||||
m_strLocalFile.c_str());
|
wxLogWarning(_("can't open user configuration file '%s'."), m_strLocalFile.c_str() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -413,14 +429,10 @@ wxFileConfig::wxFileConfig(const wxString& appName, const wxString& vendorName,
|
|||||||
{
|
{
|
||||||
// Make up names for files if empty
|
// Make up names for files if empty
|
||||||
if ( m_strLocalFile.IsEmpty() && (style & wxCONFIG_USE_LOCAL_FILE) )
|
if ( m_strLocalFile.IsEmpty() && (style & wxCONFIG_USE_LOCAL_FILE) )
|
||||||
{
|
|
||||||
m_strLocalFile = GetLocalFileName(GetAppName());
|
m_strLocalFile = GetLocalFileName(GetAppName());
|
||||||
}
|
|
||||||
|
|
||||||
if ( m_strGlobalFile.IsEmpty() && (style & wxCONFIG_USE_GLOBAL_FILE) )
|
if ( m_strGlobalFile.IsEmpty() && (style & wxCONFIG_USE_GLOBAL_FILE) )
|
||||||
{
|
|
||||||
m_strGlobalFile = GetGlobalFileName(GetAppName());
|
m_strGlobalFile = GetGlobalFileName(GetAppName());
|
||||||
}
|
|
||||||
|
|
||||||
// Check if styles are not supplied, but filenames are, in which case
|
// Check if styles are not supplied, but filenames are, in which case
|
||||||
// add the correct styles.
|
// add the correct styles.
|
||||||
@@ -546,7 +558,9 @@ void wxFileConfig::Parse(wxTextBuffer& buffer, bool bLocal)
|
|||||||
wxString strLine;
|
wxString strLine;
|
||||||
|
|
||||||
size_t nLineCount = buffer.GetLineCount();
|
size_t nLineCount = buffer.GetLineCount();
|
||||||
for ( size_t n = 0; n < nLineCount; n++ ) {
|
|
||||||
|
for ( size_t n = 0; n < nLineCount; n++ )
|
||||||
|
{
|
||||||
strLine = buffer[n];
|
strLine = buffer[n];
|
||||||
|
|
||||||
// add the line to linked list
|
// add the line to linked list
|
||||||
|
Reference in New Issue
Block a user