app_config.cpp
上传用户:looem2003
上传日期:2014-07-20
资源大小:13733k
文件大小:3k
- #include "app_config.h"
- #include <shlobj.h>
- LPCTSTR appName = _T("SETTINGS");
- BOOL load_app_config( HINSTANCE hInst, LPAPPCONFIG ac, LPCTSTR iniFileName,
- t_load_additional_config lac, LPVOID param )
- {
- BOOL ret = FALSE;
-
- if( NULL != ac )
- {
- GetModuleFileName( (NULL!=hInst)?hInst:GetModuleHandle(NULL), ac->workPath, ARRAYSIZE(ac->workPath) );
- //load the current path of the module
- _tsplitpath_s( ac->workPath, ac->lang, ARRAYSIZE(ac->lang), ac->langFile, ARRAYSIZE(ac->langFile),
- NULL, 0, NULL, 0);
- _stprintf_s( ac->workPath, ARRAYSIZE(ac->workPath), _T("%s%s"), ac->lang, ac->langFile );
- //check if app_config.ini exists
- _stprintf_s( ac->iniFile, ARRAYSIZE(ac->iniFile), _T("%s%s"), ac->workPath, (NULL!=iniFileName)?iniFileName:_T("app_config.ini") );
- if(CheckConfigFile(ac->iniFile))
- {
- TCHAR newPath[MAX_PATH];
- if(SUCCEEDED(SHGetFolderPath(NULL,CSIDL_APPDATA|CSIDL_FLAG_CREATE,NULL,0,newPath)))
- {
- _stprintf_s(newPath,ARRAYSIZE(newPath),_T("%s\%s"),newPath,(NULL!=iniFileName)?iniFileName:_T("app_config.ini"));
-
- MoveFileEx(ac->iniFile,newPath,MOVEFILE_REPLACE_EXISTING);
- _stprintf_s(ac->iniFile,ARRAYSIZE(ac->iniFile),_T("%s"),newPath);
- }
- }
- else
- {
-
- TCHAR newPath[MAX_PATH];
- if(SUCCEEDED(SHGetFolderPath(NULL,CSIDL_APPDATA|CSIDL_FLAG_CREATE,NULL,0,newPath)))
- {
- _stprintf_s( ac->iniFile, ARRAYSIZE(ac->iniFile), _T("%s\%s"),newPath, (NULL!=iniFileName)?iniFileName:_T("app_config.ini") );
- }
- }
- GetPrivateProfileString( appName, _T("lang"), _T("en"), ac->lang, ARRAYSIZE(ac->lang), ac->iniFile );
- GetPrivateProfileString( appName, _T("langFile"), _T("lang.ini"), ac->langFile, ARRAYSIZE(ac->langFile), ac->iniFile );
- if( (NULL == _tcschr( ac->langFile, _T(':') )) )
- {
- _tcscpy_s( ac->langFile, ARRAYSIZE(ac->langFile), ac->workPath );
- GetPrivateProfileString( appName, _T("langFile"), _T("lang.ini"), ac->langFile+_tcslen(ac->langFile),
- ARRAYSIZE(ac->langFile)-(DWORD)_tcslen(ac->langFile), ac->iniFile );
- }
- if( -1 == _taccess( ac->langFile, 0 ) )
- _stprintf_s( ac->langFile, ARRAYSIZE(ac->langFile), _T("%s%s"), ac->workPath, _T("lang.ini") );
- lm.init_lang( ac->langFile, ac->lang );
- //while( lm.get_lang_from_file( i++, lg, lgs, lnm, lnms ) );
- }
- if( NULL != lac )
- lac( ac, param );
- return ret;
- }
- BOOL save_app_config( LPAPPCONFIG ac, t_save_additional_config sac )
- {
- BOOL ret = FALSE;
- if( NULL != ac )
- {
- WritePrivateProfileString( appName, _T("lang"), ac->lang, ac->iniFile );
- WritePrivateProfileString( appName, _T("langFile"), ac->langFile, ac->iniFile );
- }
- if( NULL != sac )
- sac( ac );
- return ret;
- }
- BOOL CheckConfigFile(const TCHAR * link)
- {
- return _access((char*)link,06);
- }