Config.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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("Repeat"), _T(""), szData, sizeof(szData), strIni);
  41. m_strRepeat = szData;
  42. GetPrivateProfileString(_T("Set"), _T("Token"), _T(""), szData, sizeof(szData), strIni);
  43. m_strToken = szData;
  44. GetPrivateProfileString(_T("Set"), _T("CsvPath"), _T(""), szData, sizeof(szData), strIni);
  45. m_strCsvPath = szData;
  46. GetPrivateProfileString(_T("Set"), _T("CsvFileDir"), _T(""), szData, sizeof(szData), strIni);
  47. m_strCsvFileDir = szData;
  48. return TRUE;
  49. }
  50. BOOL CConfig::SaveToINI()
  51. {
  52. TCHAR sTmp[64] = {0};
  53. std::string strPwd;
  54. CString strTmp = _T("");
  55. CString strIni = GetAppPath() + _T("config.ini");
  56. WritePrivateProfileString(_T("Set"), _T("Txt"), m_strTxt, strIni);
  57. WritePrivateProfileString(_T("Set"), _T("Pdf"), m_strPdf, strIni);
  58. WritePrivateProfileString(_T("Set"), _T("Mode"), m_strMode, strIni);
  59. WritePrivateProfileString(_T("Set"), _T("Img"), m_strImg, strIni);
  60. WritePrivateProfileString(_T("Set"), _T("Cut"), m_strCut, strIni);
  61. WritePrivateProfileString(_T("Set"), _T("Repeat"), m_strRepeat, strIni);
  62. WritePrivateProfileString(_T("Set"), _T("CsvPath"), m_strCsvPath, strIni);
  63. WritePrivateProfileString(_T("Set"), _T("CsvFileDir"), m_strCsvFileDir, strIni);
  64. return TRUE;
  65. }
  66. CString CConfig::GetAppPath()
  67. {
  68. CString strAppPath;
  69. TCHAR *pBuf=strAppPath.GetBuffer(_MAX_PATH);
  70. GetModuleFileName(AfxGetApp()->m_hInstance,pBuf,_MAX_PATH);
  71. TCHAR* pch=_tcsrchr(pBuf,_T('\\'));
  72. if(pch)
  73. *(pch+1)=0;
  74. else
  75. _tcscat(pBuf,_T("\\"));
  76. strAppPath.ReleaseBuffer();
  77. return strAppPath;
  78. }