@@ -22,7 +22,7 @@ ConfigFile::ConfigFile(const TCHAR *configDir, const TCHAR *pluginDir, HINSTANCE
2222 m_configDir(configDir)
2323{
2424 m_configFilename.append (_T (" \\ PythonScriptStartup.cnf" ));
25-
25+
2626 m_machineScriptsDir.append (_T (" \\ PythonScript\\ scripts" ));
2727 m_userScriptsDir.append (_T (" \\ PythonScript\\ scripts" ));
2828
@@ -33,61 +33,63 @@ ConfigFile::ConfigFile(const TCHAR *configDir, const TCHAR *pluginDir, HINSTANCE
3333ConfigFile::~ConfigFile ()
3434{
3535 m_hInst = NULL ;
36- // TODO: Clean up
36+ // TODO: Clean up
3737 // DeleteImage
38- //
39-
38+ //
39+
4040}
4141
4242
4343void ConfigFile::readConfig ()
4444{
45- std::basic_ifstream<TCHAR> startupFile (m_configFilename.c_str ());
46-
47- TCHAR buffer[500 ];
48-
49-
45+ // just char(UTF8) as TCHAR is not working as expected, because stream is converted to char implicitly
46+ // see also https://www.codeproject.com/Articles/38242/Reading-UTF-with-C-streams
47+ std::ifstream startupFile (m_configFilename.c_str ());
48+
49+ char buffer[500 ];
50+
51+
5052 HBITMAP hIcon;
5153
5254 while (startupFile.good ())
5355 {
5456 startupFile.getline (buffer, 500 );
55- TCHAR *context;
56- TCHAR *element = _tcstok_s (buffer, _T ( " /" ) , &context);
57+ char *context;
58+ char *element = strtok_s (buffer, " /" , &context);
5759 if (element)
5860 {
5961
6062 // Menu item
61- if (0 == _tcscmp (element, _T ( " ITEM" ) ))
63+ if (0 == strcmp (element, " ITEM" ))
6264 {
63- element = _tcstok_s (NULL , _T ( " /" ) , &context);
64- m_menuItems.push_back (tstring (element));
65- m_menuScripts.push_back (std::string (WcharMbcsConverter::tchar2char (element).get ()));
65+ element = strtok_s (NULL , " /" , &context);
66+ m_menuItems.push_back (tstring (WcharMbcsConverter::char2tchar ( element). get () ));
67+ m_menuScripts.push_back (tstring (WcharMbcsConverter::char2tchar (element).get ()));
6668 }
67-
69+
6870 // Toolbar item
69- else if (0 == _tcscmp (element, _T ( " TOOLBAR" ) ))
71+ else if (0 == strcmp (element, " TOOLBAR" ))
7072 {
71- element = _tcstok_s (NULL , _T ( " /" ) , &context);
72- TCHAR *iconPath = _tcstok_s (NULL , _T ( " /" ) , &context);
73+ element = strtok_s (NULL , " /" , &context);
74+ char *iconPath = strtok_s (NULL , " /" , &context);
7375 if (!iconPath || !(*iconPath))
7476 {
7577 hIcon = static_cast <HBITMAP>(LoadImage (m_hInst, MAKEINTRESOURCE (IDB_PYTHON), IMAGE_BITMAP, 0 , 0 , LR_DEFAULTSIZE));
7678 iconPath = NULL ;
7779 }
78- else
80+ else
7981 {
80- hIcon = static_cast <HBITMAP>(LoadImage (NULL , iconPath, IMAGE_BITMAP, 16 , 16 , LR_LOADMAP3DCOLORS | LR_LOADFROMFILE));
82+ hIcon = static_cast <HBITMAP>(LoadImage (NULL , WcharMbcsConverter::char2tchar ( iconPath). get () , IMAGE_BITMAP, 16 , 16 , LR_LOADMAP3DCOLORS | LR_LOADFROMFILE));
8183 }
8284
83-
84- m_toolbarItems.push_back (std::pair<tstring, std::pair<HBITMAP, tstring> >(tstring (element), std::pair<HBITMAP, tstring>(hIcon, iconPath ? tstring (iconPath) : tstring ())));
85+
86+ m_toolbarItems.push_back (std::pair<tstring, std::pair<HBITMAP, tstring> >(tstring (WcharMbcsConverter::char2tchar ( element). get ()) , std::pair<HBITMAP, tstring>(hIcon, iconPath ? tstring (WcharMbcsConverter::char2tchar ( iconPath). get () ) : tstring ())));
8587 }
86- else if (0 == _tcscmp (element, _T ( " SETTING" ) ))
88+ else if (0 == strcmp (element, " SETTING" ))
8789 {
88- element = _tcstok_s (NULL , _T ( " /" ) , &context);
89- TCHAR *settingValue = _tcstok_s (NULL , _T ( " /" ) , &context);
90- m_settings.insert (std::pair<tstring, tstring>(tstring (element), tstring (settingValue)));
90+ element = strtok_s (NULL , " /" , &context);
91+ char *settingValue = strtok_s (NULL , " /" , &context);
92+ m_settings.insert (std::pair<tstring, tstring>(tstring (WcharMbcsConverter::char2tchar ( element). get ()) , tstring (WcharMbcsConverter::char2tchar ( settingValue). get () )));
9193 }
9294 }
9395
@@ -104,20 +106,22 @@ void ConfigFile::clearItems()
104106
105107void ConfigFile::save ()
106108{
107- std::basic_ofstream<TCHAR> startupFile (m_configFilename.c_str (), std::ios_base::out | std::ios_base::trunc);
109+ // just char(UTF8) as TCHAR is not working as expected, because stream is converted to char implicitly
110+ // see also https://www.codeproject.com/Articles/38242/Reading-UTF-with-C-streams
111+ std::ofstream startupFile (m_configFilename.c_str (), std::ios_base::out | std::ios_base::trunc);
108112 for (MenuItemsTD::iterator it = m_menuItems.begin (); it != m_menuItems.end (); ++it)
109113 {
110- startupFile << " ITEM/" << ( *it) << " \n " ;
114+ startupFile << " ITEM/" << WcharMbcsConverter::tchar2char (( *it). c_str ()). get ( ) << " \n " ;
111115 }
112116
113117 for (ToolbarItemsTD::iterator it = m_toolbarItems.begin (); it != m_toolbarItems.end (); ++it)
114118 {
115- startupFile << _T ( " TOOLBAR/" ) << it->first << _T ( " /" ) << it->second .second << _T ( " \n " ) ;
119+ startupFile << " TOOLBAR/" << WcharMbcsConverter::tchar2char (( it->first ). c_str ()). get () << " /" << WcharMbcsConverter::tchar2char (( it->second .second ). c_str ()). get () << " \n " ;
116120 }
117121
118122 for (SettingsTD::iterator it = m_settings.begin (); it != m_settings.end (); ++it)
119123 {
120- startupFile << _T ( " SETTING/" ) << it->first << _T ( " /" ) << it->second << _T ( " \n " ) ;
124+ startupFile << " SETTING/" << WcharMbcsConverter::tchar2char (( it->first ). c_str ()). get () << " /" << WcharMbcsConverter::tchar2char (( it->second ). c_str ()). get () << " \n " ;
121125 }
122126
123127 startupFile.close ();
@@ -128,7 +132,7 @@ void ConfigFile::save()
128132void ConfigFile::addMenuItem (const tstring scriptPath)
129133{
130134 m_menuItems.push_back (scriptPath);
131- m_menuScripts.push_back (std::string ( WcharMbcsConverter::tchar2char ( scriptPath. c_str ()). get ()) );
135+ m_menuScripts.push_back (scriptPath);
132136}
133137
134138void ConfigFile::addToolbarItem (const tstring scriptPath, const tstring iconPath)
@@ -147,11 +151,11 @@ const tstring& ConfigFile::getSetting(const TCHAR *settingName)
147151 return m_settings[tstring (settingName)];
148152}
149153
150- const std::string & ConfigFile::getMenuScript (idx_t index) const
151- {
154+ const tstring & ConfigFile::getMenuScript (idx_t index) const
155+ {
152156 if (m_menuScripts.size () > index)
153157 {
154- return m_menuScripts[index];
158+ return m_menuScripts[index];
155159 }
156160 else
157161 {
0 commit comments