CConfigDlg.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // CConfigDlg.cpp: 实现文件
  2. //
  3. #include "pch.h"
  4. #include "resource.h" // 主符号
  5. #include "CConfigDlg.h"
  6. #include "afxdialogex.h"
  7. //********************************通用配置类********************************
  8. nsCFG::CConfigDlg::CConfigDlg(Dev_Type type, string& libName, string& fileName) : CDialogEx(IDD_ABOUTBOX)
  9. {
  10. m_emType = type;
  11. m_pLib = &libName;
  12. m_pCfgFile = &fileName;
  13. mLog::Debug("Enter CConfigDlg:{$}", (int)type);
  14. }
  15. void nsCFG::CConfigDlg::DoDataExchange(CDataExchange* pDX)
  16. {
  17. CDialogEx::DoDataExchange(pDX);
  18. DDX_Control(pDX, IDC_EDIT1, m_Edit_Unitdll);
  19. DDX_Control(pDX, IDC_COMBO1, m_Combo_CfgFileList);
  20. }
  21. BEGIN_MESSAGE_MAP(nsCFG::CConfigDlg, CDialogEx)
  22. ON_BN_CLICKED(IDOK, &nsCFG::CConfigDlg::OnBnClickedOk)
  23. ON_CBN_SELCHANGE(IDC_COMBO1, &nsCFG::CConfigDlg::OnCbnSelchangeCombo1)
  24. END_MESSAGE_MAP()
  25. //初始化配置
  26. BOOL nsCFG::CConfigDlg::OnInitDialog()
  27. {
  28. CDialogEx::OnInitDialog();
  29. CString tempStr = "";
  30. tempStr.Format("%s", m_pLib->c_str());
  31. m_Edit_Unitdll.SetWindowText(tempStr);
  32. vector<string> cfgFileList;
  33. string strCFGPath = GetProcessDirectory() + R"(\DriverConfig\)";
  34. GetAllCFGFiles(strCFGPath, cfgFileList);
  35. for (int i = 0; i < cfgFileList.size(); i++)
  36. {
  37. m_Combo_CfgFileList.AddString(TEXT(cfgFileList[i].c_str()));
  38. if (cfgFileList[i] == m_pCfgFile->c_str())
  39. {
  40. m_Combo_CfgFileList.SetCurSel(i);
  41. }
  42. }
  43. return TRUE;
  44. }
  45. //配置确认
  46. void nsCFG::CConfigDlg::OnBnClickedOk()
  47. {
  48. // TODO: 在此添加控件通知处理程序代码
  49. CString tempStr;
  50. m_Edit_Unitdll.GetWindowText(tempStr);
  51. *m_pLib = tempStr;
  52. int index = m_Combo_CfgFileList.GetCurSel();//int类型的返回值index接收到的就是当前位置的索引
  53. m_Combo_CfgFileList.GetLBText(index, tempStr);//根据当前位置的索引index找到具体内容
  54. *m_pCfgFile = tempStr;
  55. mLog::Debug("Confirm Config:ID[{$}],lib[{$]],file[{$}]", (int)m_emType, m_pLib->c_str(), m_pCfgFile->c_str());
  56. //SetToolDefaultConfig(glo_UnitList);
  57. CDialogEx::OnOK();
  58. }
  59. //返回用户选择的配置文件
  60. void nsCFG::CConfigDlg::OnCbnSelchangeCombo1()
  61. {
  62. CString log;
  63. try {
  64. //拿到索引位置
  65. int index = m_Combo_CfgFileList.GetCurSel();//int类型的返回值index接收到的就是当前位置的索引
  66. //获取索引位置的内容
  67. CString strCFGFile;
  68. m_Combo_CfgFileList.GetLBText(index, strCFGFile);//根据当前位置的索引index找到具体内容
  69. //弹出用户选中位置的具体内容
  70. //MessageBox(strCFGFile);
  71. string procdir = GetProcessDirectory();
  72. string strCFGPath = procdir + R"(\DriverConfig\)" + strCFGFile.GetBuffer();
  73. mLog::Debug("Read module config_file:[{$}]", strCFGPath.c_str());
  74. ResDataObject tempConfig;
  75. if (!(tempConfig.loadFile(strCFGPath.c_str())))
  76. {
  77. mLog::Debug("Load reading module config_file[{$}]failed", strCFGPath.c_str());
  78. return;
  79. }
  80. string strDLL("");
  81. if (tempConfig[UnitTool_CONFIGURATION].GetKeyCount("LoadDll") > 0)
  82. strDLL = (string)tempConfig[UnitTool_CONFIGURATION]["LoadDll"];
  83. if (strDLL.rfind(".dll") != string::npos)
  84. {
  85. CString tempStr(strDLL.c_str());
  86. m_Edit_Unitdll.SetWindowText(tempStr);
  87. }
  88. }
  89. catch (const ResDataObjectExption&)
  90. {
  91. mLog::Error("open file failed");
  92. return;
  93. }
  94. catch (...)
  95. {
  96. mLog::Error("open file catch");
  97. return;
  98. }
  99. }
  100. //********************************状态机配置类********************************
  101. nsCFG::CSMachineCfgDlg::CSMachineCfgDlg(Dev_Type type, string& libName) : CDialogEx(IDD_ABOUTBOX1)
  102. {
  103. m_emType = type;
  104. m_pLib = &libName;
  105. mLog::Debug("Enter CSMachineCfgDlg:{$}", (int)type);
  106. }
  107. void nsCFG::CSMachineCfgDlg::DoDataExchange(CDataExchange* pDX)
  108. {
  109. CDialogEx::DoDataExchange(pDX);
  110. DDX_Control(pDX, IDC_COMBO1, m_Combo_CfgFileList);
  111. }
  112. BEGIN_MESSAGE_MAP(nsCFG::CSMachineCfgDlg, CDialogEx)
  113. ON_BN_CLICKED(IDOK, &nsCFG::CSMachineCfgDlg::OnBnClickedOk)
  114. END_MESSAGE_MAP()
  115. //初始化配置
  116. BOOL nsCFG::CSMachineCfgDlg::OnInitDialog()
  117. {
  118. CDialogEx::OnInitDialog();
  119. vector<string> cfgFileList;
  120. string strCFGPath = GetProcessDirectory(true);
  121. GetAllLibrary(strCFGPath, cfgFileList,"Machine");
  122. for (int i = 0; i < cfgFileList.size(); i++)
  123. {
  124. m_Combo_CfgFileList.AddString(TEXT(cfgFileList[i].c_str()));
  125. if (cfgFileList[i] == m_pLib->c_str())
  126. {
  127. m_Combo_CfgFileList.SetCurSel(i);
  128. }
  129. }
  130. return TRUE;
  131. }
  132. //配置确认
  133. void nsCFG::CSMachineCfgDlg::OnBnClickedOk()
  134. {
  135. // TODO: 在此添加控件通知处理程序代码
  136. CString tempStr;
  137. int index = m_Combo_CfgFileList.GetCurSel();//int类型的返回值index接收到的就是当前位置的索引
  138. m_Combo_CfgFileList.GetLBText(index, tempStr);//根据当前位置的索引index找到具体内容
  139. *m_pLib = tempStr;
  140. mLog::Debug("Confirm Config:ID[{$}],lib[{$]]", (int)m_emType, m_pLib->c_str());
  141. //SetToolDefaultConfig(glo_UnitList);
  142. CDialogEx::OnOK();
  143. }