123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- #include "stdafx.h"
- #include "ScriptObject.h"
- #include "public.h"
- #include "Afxcoll.h"
- #include <io.h>
- #include "Const.h"
- #include "kernel.h"
- // Global instance of our IActiveScriptSite implementation.
- MyActiveScriptSite g_iActiveScriptSite;
- // This global class calls OleInitialize() at application startup
- // and calls OleUninitialize() at application exit...
- // OleInitClass g_OleInitClass;
- IActiveScript *m_iActiveScript;
- IActiveScriptParse *m_iActiveScriptParse;
- CScriptObject m_ScriptObject;
- ScriptParamList g_ScriptParamList; //系统所有脚本的运行参数链表
- void AddOneScript(CString strTitle)
- {
- ScriptParam* pScript = new ScriptParam;
- // 读脚本文件的脚本到系统
- CStdioFile file;
- if (file.Open(strTitle,CFile::modeRead))
- {
- CString line="";
- CString scrpt="";
- while (file.ReadString(line)!=NULL)
- {
- scrpt = scrpt + line + '\n';
- }
- pScript->m_strScript = scrpt;
- file.Close();
- }
- else
- {
- delete pScript;
- return;
- }
-
- CHAR strDirectory[MAX_PATH_LENGTH + 1] = {0};
- CHAR strAppName[MAX_PATH_LENGTH + 1] = {0};
- CHAR strFile[MAX_FILE_LENGTH + 1] = {0};
- CHAR strValue[MAX_VALUE_LENGTH + 1] = {0};
- int iPosFile = 0;
- int iLenghtFile = 0;
- ////////////////////////////////////////////////////////////////////////////
- //获取应用名
- GetModuleFileName(AfxGetApp()->m_hInstance, strDirectory, MAX_PATH_LENGTH);
- iLenghtFile = strlen(strDirectory);
- for (iPosFile = iLenghtFile - 1; iPosFile >= 0; iPosFile--)
- {
- if (strDirectory[iPosFile] == '\\')
- {
- memset(strAppName, 0, sizeof(strAppName));
- memcpy(strAppName, strDirectory + iPosFile + 1, iLenghtFile - iPosFile - 1);
- break;
- }
- }
-
- //获取系统路径
- #ifdef _DEBUG
- GetCurrentDirectory(MAX_PATH_LENGTH, strDirectory);
- #else
- GetModuleFileName(AfxGetApp()->m_hInstance, strDirectory, MAX_PATH_LENGTH);
- iLenghtFile = strlen(strDirectory);
- for (iPosFile = iLenghtFile - 1; iPosFile >= 0; iPosFile--)
- {
- if (strDirectory[iPosFile] == '\\')
- {
- strDirectory[iPosFile] = '\0';
- break;
- }
- }
- #endif
- strTitle.Replace(".srp", ".con");
- //char Path[128];
- CString strFindSptFile = "*.srp";
- //strcpy(Path, strDirectory);
- //strcat(Path, "\\");
- //strcat(Path, _SCRIPTDIR);
- //strcat(Path, "\\");
- //strcat(Path, strTitle);
- //strcat(Path,".con");
- char name[20];
- char result[256];
- memset(name,0,20);
- memset(result,0,256);
- sprintf(name,"CONDITON");
- int res = GetPrivateProfileString("RUNPARA", name, "", result, 256, strTitle);
- if ( res != 0)
- {
- pScript->m_strExpression = result;
- }
-
- sprintf(name,"CIRCLE");
- res = GetPrivateProfileInt("RUNPARA", name, 0, strTitle);
- if ( res != 0)
- {
- pScript->m_curcleTime = res;
- }
- sprintf(name,"USE");
- res = GetPrivateProfileInt("RUNPARA", name, 0, strTitle);
- if ( res != 0)
- {
- pScript->m_bValid = res;
- }
- sprintf(name,"TYPE");
- res = GetPrivateProfileInt("RUNPARA", name, -1, strTitle);
- if ( res != -1)
- {
- pScript->m_bCircle = TRUE;
- pScript->m_bCondition = FALSE;
- if (res == 1)
- {
- pScript->m_bCircle = FALSE;
- pScript->m_bCondition = TRUE;
- }
- }
- // 将处理好的脚本处理对象加入到链表
- ProcessScript(pScript->m_strScript);
- g_ScriptParamList.AddTail(pScript);
- }
- BOOL LoadScriptFromFiles()
- {
- CHAR strDirectory[MAX_PATH_LENGTH + 1] = {0};
- CHAR strAppName[MAX_PATH_LENGTH + 1] = {0};
- CHAR strFile[MAX_FILE_LENGTH + 1] = {0};
- CHAR strValue[MAX_VALUE_LENGTH + 1] = {0};
- int iPosFile = 0;
- int iLenghtFile = 0;
- ////////////////////////////////////////////////////////////////////////////
- //获取应用名
- GetModuleFileName(AfxGetApp()->m_hInstance, strDirectory, MAX_PATH_LENGTH);
- iLenghtFile = strlen(strDirectory);
- for (iPosFile = iLenghtFile - 1; iPosFile >= 0; iPosFile--)
- {
- if (strDirectory[iPosFile] == '\\')
- {
- memset(strAppName, 0, sizeof(strAppName));
- memcpy(strAppName, strDirectory + iPosFile + 1, iLenghtFile - iPosFile - 1);
- break;
- }
- }
-
- //获取系统路径
- //#ifdef _DEBUG
- // GetCurrentDirectory(MAX_PATH_LENGTH, strDirectory);
- //#else
- GetModuleFileName(AfxGetApp()->m_hInstance, strDirectory, MAX_PATH_LENGTH);
- iLenghtFile = strlen(strDirectory);
- for (iPosFile = iLenghtFile - 1; iPosFile >= 0; iPosFile--)
- {
- if (strDirectory[iPosFile] == '\\')
- {
- strDirectory[iPosFile] = '\0';
- break;
- }
- }
- //#endif
- char szPicDir[MAX_PATH] = {0};
- CString strFindSptFile = "*.srp";
- strcpy(szPicDir, strDirectory);
- strcat(szPicDir, "\\");
- strcat(szPicDir, _SCRIPTDIR);
- //strcat(szPicDir, "\\");
- //strcat(szPicDir, strFindSptFile);
- CString strAllPath;
- strAllPath.Format("%s\\%s", szPicDir, strFindSptFile);
- struct _finddata_t f;
- long hFile = _findfirst((char *)(LPCTSTR)strAllPath,&f);
- if (-1L != hFile)
- {
- CString strFile = (CString)f.name;
- //CString strTitle = strFile.Left(strFile.GetLength() - 4);
- AddOneScript(CString(szPicDir) + "\\" + strFile); // 处理一个文件
- while (0 == _findnext(hFile,&f))
- {
- CString strFile = (CString)f.name;
- //strTitle = strFile.Left(strFile.GetLength() - 4);
- AddOneScript(CString(szPicDir) + "\\" + strFile); // 处理一个文件
- }
- _findclose(hFile);
- }
- return TRUE;
- }
- // 错误输出
- void HRVERIFY(HRESULT hr, char * msg)
- {
- if (FAILED(hr))
- {
- CString str;
- str.Format("Error: 0x%08lx (%s)", hr, msg);
- AfxMessageBox(str, 0x10000);
- _exit(0);
- }
- }
|