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:
Robert Roebling
2002-10-20 12:45:51 +00:00
parent 09cb4267da
commit 7fcfab5e21

View File

@@ -261,16 +261,16 @@ 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;
rc = DosQuerySysInfo( 1L, QSV_MAX, (PVOID)aulSysInfo, sizeof(ULONG)*QSV_MAX); rc = DosQuerySysInfo( 1L, QSV_MAX, (PVOID)aulSysInfo, sizeof(ULONG)*QSV_MAX);
if (rc == 0) if (rc == 0)
@@ -278,88 +278,90 @@ 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;
} }
wxString wxFileConfig::GetLocalDir() wxString wxFileConfig::GetLocalDir()
{ {
wxString strDir; wxString strDir;
#if defined(__WXMAC__) || defined(__DOS__) #if defined(__WXMAC__) || defined(__DOS__)
// no local dir concept on Mac OS 9 or MS-DOS // no local dir concept on Mac OS 9 or MS-DOS
return GetGlobalDir() ; return GetGlobalDir() ;
#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;
} }
wxString wxFileConfig::GetGlobalFileName(const wxChar *szFile) wxString wxFileConfig::GetGlobalFileName(const wxChar *szFile)
{ {
wxString str = GetGlobalDir(); wxString str = GetGlobalDir();
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
wxString str = wxT( '.' ); // other platforms?
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;
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -368,38 +370,52 @@ wxString wxFileConfig::GetLocalFileName(const wxChar *szFile)
void wxFileConfig::Init() void wxFileConfig::Init()
{ {
m_pCurrentGroup = m_pCurrentGroup =
m_pRootGroup = new wxFileConfigGroup(NULL, "", this); m_pRootGroup = new wxFileConfigGroup(NULL, "", this);
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
Parse(fileGlobal, FALSE /* global */); if ( fileGlobal.Open( wxConvUTF8 ) )
SetRootPath(); #else
if ( fileGlobal.Open() )
#endif
{
Parse(fileGlobal, FALSE /* global */);
SetRootPath();
}
else
{
wxLogWarning(_("can't open global configuration file '%s'."), m_strGlobalFile.c_str());
}
} }
else
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); {
if ( fileLocal.Open() ) { wxTextFile fileLocal(m_strLocalFile);
Parse(fileLocal, TRUE /* local */); #if defined(__WXGTK20__) && wxUSE_UNICODE
SetRootPath(); if ( fileLocal.Open( wxConvUTF8 ) )
#else
if ( fileLocal.Open() )
#endif
{
Parse(fileLocal, TRUE /* local */);
SetRootPath();
}
else
{
wxLogWarning(_("can't open user configuration file '%s'."), m_strLocalFile.c_str() );
}
} }
else
wxLogWarning(_("can't open user configuration file '%s'."),
m_strLocalFile.c_str());
}
} }
// constructor supports creation of wxFileConfig objects of any type // constructor supports creation of wxFileConfig objects of any type
@@ -411,47 +427,43 @@ wxFileConfig::wxFileConfig(const wxString& appName, const wxString& vendorName,
style), style),
m_strLocalFile(strLocal), m_strGlobalFile(strGlobal) m_strLocalFile(strLocal), m_strGlobalFile(strGlobal)
{ {
// 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.
if ( !m_strLocalFile.IsEmpty() ) if ( !m_strLocalFile.IsEmpty() )
SetStyle(GetStyle() | wxCONFIG_USE_LOCAL_FILE); SetStyle(GetStyle() | wxCONFIG_USE_LOCAL_FILE);
if ( !m_strGlobalFile.IsEmpty() ) if ( !m_strGlobalFile.IsEmpty() )
SetStyle(GetStyle() | wxCONFIG_USE_GLOBAL_FILE); SetStyle(GetStyle() | wxCONFIG_USE_GLOBAL_FILE);
// if the path is not absolute, prepend the standard directory to it // if the path is not absolute, prepend the standard directory to it
// UNLESS wxCONFIG_USE_RELATIVE_PATH style is set // UNLESS wxCONFIG_USE_RELATIVE_PATH style is set
if ( !(style & wxCONFIG_USE_RELATIVE_PATH) ) if ( !(style & wxCONFIG_USE_RELATIVE_PATH) )
{ {
if ( !m_strLocalFile.IsEmpty() && !wxIsAbsolutePath(m_strLocalFile) ) if ( !m_strLocalFile.IsEmpty() && !wxIsAbsolutePath(m_strLocalFile) )
{ {
wxString strLocal = m_strLocalFile; wxString strLocal = m_strLocalFile;
m_strLocalFile = GetLocalDir(); m_strLocalFile = GetLocalDir();
m_strLocalFile << strLocal; m_strLocalFile << strLocal;
} }
if ( !m_strGlobalFile.IsEmpty() && !wxIsAbsolutePath(m_strGlobalFile) ) if ( !m_strGlobalFile.IsEmpty() && !wxIsAbsolutePath(m_strGlobalFile) )
{ {
wxString strGlobal = m_strGlobalFile; wxString strGlobal = m_strGlobalFile;
m_strGlobalFile = GetGlobalDir(); m_strGlobalFile = GetGlobalDir();
m_strGlobalFile << strGlobal; m_strGlobalFile << strGlobal;
} }
} }
SetUmask(-1); SetUmask(-1);
Init(); Init();
} }
#if wxUSE_STREAMS #if wxUSE_STREAMS
@@ -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