scriptproc.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. #include "stdafx.h"
  2. #include "ScriptObject.h"
  3. #include "public.h"
  4. #include "Afxcoll.h"
  5. #include <io.h>
  6. #include "Const.h"
  7. #include "kernel.h"
  8. // Global instance of our IActiveScriptSite implementation.
  9. MyActiveScriptSite g_iActiveScriptSite;
  10. // This global class calls OleInitialize() at application startup
  11. // and calls OleUninitialize() at application exit...
  12. // OleInitClass g_OleInitClass;
  13. IActiveScript *m_iActiveScript;
  14. IActiveScriptParse *m_iActiveScriptParse;
  15. CScriptObject m_ScriptObject;
  16. ScriptParamList g_ScriptParamList; //系统所有脚本的运行参数链表
  17. void AddOneScript(CString strTitle)
  18. {
  19. ScriptParam* pScript = new ScriptParam;
  20. // 读脚本文件的脚本到系统
  21. CStdioFile file;
  22. if (file.Open(strTitle,CFile::modeRead))
  23. {
  24. CString line="";
  25. CString scrpt="";
  26. while (file.ReadString(line)!=NULL)
  27. {
  28. scrpt = scrpt + line + '\n';
  29. }
  30. pScript->m_strScript = scrpt;
  31. file.Close();
  32. }
  33. else
  34. {
  35. delete pScript;
  36. return;
  37. }
  38. CHAR strDirectory[MAX_PATH_LENGTH + 1] = {0};
  39. CHAR strAppName[MAX_PATH_LENGTH + 1] = {0};
  40. CHAR strFile[MAX_FILE_LENGTH + 1] = {0};
  41. CHAR strValue[MAX_VALUE_LENGTH + 1] = {0};
  42. int iPosFile = 0;
  43. int iLenghtFile = 0;
  44. ////////////////////////////////////////////////////////////////////////////
  45. //获取应用名
  46. GetModuleFileName(AfxGetApp()->m_hInstance, strDirectory, MAX_PATH_LENGTH);
  47. iLenghtFile = strlen(strDirectory);
  48. for (iPosFile = iLenghtFile - 1; iPosFile >= 0; iPosFile--)
  49. {
  50. if (strDirectory[iPosFile] == '\\')
  51. {
  52. memset(strAppName, 0, sizeof(strAppName));
  53. memcpy(strAppName, strDirectory + iPosFile + 1, iLenghtFile - iPosFile - 1);
  54. break;
  55. }
  56. }
  57. //获取系统路径
  58. #ifdef _DEBUG
  59. GetCurrentDirectory(MAX_PATH_LENGTH, strDirectory);
  60. #else
  61. GetModuleFileName(AfxGetApp()->m_hInstance, strDirectory, MAX_PATH_LENGTH);
  62. iLenghtFile = strlen(strDirectory);
  63. for (iPosFile = iLenghtFile - 1; iPosFile >= 0; iPosFile--)
  64. {
  65. if (strDirectory[iPosFile] == '\\')
  66. {
  67. strDirectory[iPosFile] = '\0';
  68. break;
  69. }
  70. }
  71. #endif
  72. strTitle.Replace(".srp", ".con");
  73. //char Path[128];
  74. CString strFindSptFile = "*.srp";
  75. //strcpy(Path, strDirectory);
  76. //strcat(Path, "\\");
  77. //strcat(Path, _SCRIPTDIR);
  78. //strcat(Path, "\\");
  79. //strcat(Path, strTitle);
  80. //strcat(Path,".con");
  81. char name[20];
  82. char result[256];
  83. memset(name,0,20);
  84. memset(result,0,256);
  85. sprintf(name,"CONDITON");
  86. int res = GetPrivateProfileString("RUNPARA", name, "", result, 256, strTitle);
  87. if ( res != 0)
  88. {
  89. pScript->m_strExpression = result;
  90. }
  91. sprintf(name,"CIRCLE");
  92. res = GetPrivateProfileInt("RUNPARA", name, 0, strTitle);
  93. if ( res != 0)
  94. {
  95. pScript->m_curcleTime = res;
  96. }
  97. sprintf(name,"USE");
  98. res = GetPrivateProfileInt("RUNPARA", name, 0, strTitle);
  99. if ( res != 0)
  100. {
  101. pScript->m_bValid = res;
  102. }
  103. sprintf(name,"TYPE");
  104. res = GetPrivateProfileInt("RUNPARA", name, -1, strTitle);
  105. if ( res != -1)
  106. {
  107. pScript->m_bCircle = TRUE;
  108. pScript->m_bCondition = FALSE;
  109. if (res == 1)
  110. {
  111. pScript->m_bCircle = FALSE;
  112. pScript->m_bCondition = TRUE;
  113. }
  114. }
  115. // 将处理好的脚本处理对象加入到链表
  116. ProcessScript(pScript->m_strScript);
  117. g_ScriptParamList.AddTail(pScript);
  118. }
  119. BOOL LoadScriptFromFiles()
  120. {
  121. CHAR strDirectory[MAX_PATH_LENGTH + 1] = {0};
  122. CHAR strAppName[MAX_PATH_LENGTH + 1] = {0};
  123. CHAR strFile[MAX_FILE_LENGTH + 1] = {0};
  124. CHAR strValue[MAX_VALUE_LENGTH + 1] = {0};
  125. int iPosFile = 0;
  126. int iLenghtFile = 0;
  127. ////////////////////////////////////////////////////////////////////////////
  128. //获取应用名
  129. GetModuleFileName(AfxGetApp()->m_hInstance, strDirectory, MAX_PATH_LENGTH);
  130. iLenghtFile = strlen(strDirectory);
  131. for (iPosFile = iLenghtFile - 1; iPosFile >= 0; iPosFile--)
  132. {
  133. if (strDirectory[iPosFile] == '\\')
  134. {
  135. memset(strAppName, 0, sizeof(strAppName));
  136. memcpy(strAppName, strDirectory + iPosFile + 1, iLenghtFile - iPosFile - 1);
  137. break;
  138. }
  139. }
  140. //获取系统路径
  141. //#ifdef _DEBUG
  142. // GetCurrentDirectory(MAX_PATH_LENGTH, strDirectory);
  143. //#else
  144. GetModuleFileName(AfxGetApp()->m_hInstance, strDirectory, MAX_PATH_LENGTH);
  145. iLenghtFile = strlen(strDirectory);
  146. for (iPosFile = iLenghtFile - 1; iPosFile >= 0; iPosFile--)
  147. {
  148. if (strDirectory[iPosFile] == '\\')
  149. {
  150. strDirectory[iPosFile] = '\0';
  151. break;
  152. }
  153. }
  154. //#endif
  155. char szPicDir[MAX_PATH] = {0};
  156. CString strFindSptFile = "*.srp";
  157. strcpy(szPicDir, strDirectory);
  158. strcat(szPicDir, "\\");
  159. strcat(szPicDir, _SCRIPTDIR);
  160. //strcat(szPicDir, "\\");
  161. //strcat(szPicDir, strFindSptFile);
  162. CString strAllPath;
  163. strAllPath.Format("%s\\%s", szPicDir, strFindSptFile);
  164. struct _finddata_t f;
  165. long hFile = _findfirst((char *)(LPCTSTR)strAllPath,&f);
  166. if (-1L != hFile)
  167. {
  168. CString strFile = (CString)f.name;
  169. //CString strTitle = strFile.Left(strFile.GetLength() - 4);
  170. AddOneScript(CString(szPicDir) + "\\" + strFile); // 处理一个文件
  171. while (0 == _findnext(hFile,&f))
  172. {
  173. CString strFile = (CString)f.name;
  174. //strTitle = strFile.Left(strFile.GetLength() - 4);
  175. AddOneScript(CString(szPicDir) + "\\" + strFile); // 处理一个文件
  176. }
  177. _findclose(hFile);
  178. }
  179. return TRUE;
  180. }
  181. // 错误输出
  182. void HRVERIFY(HRESULT hr, char * msg)
  183. {
  184. if (FAILED(hr))
  185. {
  186. CString str;
  187. str.Format("Error: 0x%08lx (%s)", hr, msg);
  188. AfxMessageBox(str, 0x10000);
  189. _exit(0);
  190. }
  191. }