Config.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Config.cpp: implementation of the CConfig class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "pch.h"
  5. #include <atlbase.h>
  6. #include "Config.h"
  7. #ifdef _DEBUG
  8. #undef THIS_FILE
  9. static char THIS_FILE[]=__FILE__;
  10. #define new DEBUG_NEW
  11. #endif
  12. //////////////////////////////////////////////////////////////////////
  13. // Construction/Destruction
  14. //////////////////////////////////////////////////////////////////////
  15. CConfig CConfig::s_Config;
  16. CConfig::CConfig()
  17. {
  18. }
  19. BOOL CConfig::SaveSetting()
  20. {
  21. BOOL bRet=FALSE;
  22. bRet=SaveToINI();
  23. return bRet;
  24. }
  25. BOOL CConfig::LoadFromINI()
  26. {
  27. TCHAR szData[_MAX_PATH];
  28. memset(szData, 0, sizeof(szData));
  29. CString strIni = GetAppPath() + _T("config.ini");
  30. GetPrivateProfileString(_T("Set"), _T("Txt"), _T(""), szData, sizeof(szData), strIni);
  31. m_strTxt = szData;
  32. GetPrivateProfileString(_T("Set"), _T("Pdf"), _T(""), szData, sizeof(szData), strIni);
  33. m_strPdf = szData;
  34. GetPrivateProfileString(_T("Set"), _T("Mode"), _T(""), szData, sizeof(szData), strIni);
  35. m_strMode = szData;
  36. GetPrivateProfileString(_T("Set"), _T("Img"), _T(""), szData, sizeof(szData), strIni);
  37. m_strImg = szData;
  38. GetPrivateProfileString(_T("Set"), _T("Cut"), _T(""), szData, sizeof(szData), strIni);
  39. m_strCut = szData;
  40. GetPrivateProfileString(_T("Set"), _T("Token"), _T("24.086aba1dfaa5d4fdba74f2c62b591b35.2592000.1668825495.282335-21782130"), szData, sizeof(szData), strIni);
  41. m_strToken = szData;
  42. return TRUE;
  43. }
  44. BOOL CConfig::SaveToINI()
  45. {
  46. TCHAR sTmp[64] = {0};
  47. std::string strPwd;
  48. CString strTmp = _T("");
  49. CString strIni = GetAppPath() + _T("config.ini");
  50. WritePrivateProfileString(_T("Set"), _T("Txt"), m_strTxt, strIni);
  51. WritePrivateProfileString(_T("Set"), _T("Pdf"), m_strPdf, strIni);
  52. WritePrivateProfileString(_T("Set"), _T("Mode"), m_strMode, strIni);
  53. WritePrivateProfileString(_T("Set"), _T("Img"), m_strImg, strIni);
  54. WritePrivateProfileString(_T("Set"), _T("Cut"), m_strCut, strIni);
  55. return TRUE;
  56. }
  57. CString CConfig::GetAppPath()
  58. {
  59. CString strAppPath;
  60. TCHAR *pBuf=strAppPath.GetBuffer(_MAX_PATH);
  61. GetModuleFileName(AfxGetApp()->m_hInstance,pBuf,_MAX_PATH);
  62. TCHAR* pch=_tcsrchr(pBuf,_T('\\'));
  63. if(pch)
  64. *(pch+1)=0;
  65. else
  66. _tcscat(pBuf,_T("\\"));
  67. strAppPath.ReleaseBuffer();
  68. return strAppPath;
  69. }