-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathIScripts.cpp
131 lines (118 loc) · 2.97 KB
/
IScripts.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// IScripts.cpp: implementation of the CIScripts class.
#include "stdafx.h"
#include "configsvcimpl.h"
#include "IScripts.h"
#include "scriptmaneger.h"
ITypeInfo* CIScripts::m_pTypeInfo=NULL;
CIScripts* CIScripts::m_pScripts=NULL;
CIScripts::CIScripts()
{
m_pScripts=this;
}
CIScripts::~CIScripts()
{
m_pScripts=NULL;
}
STDMETHODIMP CIScripts::get_item(VARIANT Idx,IDispatch **pVal)
{
if(IsBadWritePtr(pVal,sizeof(*pVal)))
return E_POINTER;
CScripting* pScript=GetScript(Idx);
if(!pScript)
return E_FAIL;
return pScript->m_pEngine->GetScriptDispatch(NULL,pVal);
}
STDMETHODIMP CIScripts::get_Count(long *pVal)
{
if(IsBadWritePtr(pVal,sizeof(*pVal)))
return E_POINTER;
*pVal=CScriptManager::GetScriptManager()->GetScriptCount();
return S_OK;
}
STDMETHODIMP CIScripts::Load(BSTR Path,IDispatch **pRetVal)
{
if(IsBadWritePtr(pRetVal,sizeof(*pRetVal)))
return E_POINTER;
_bstr_t bPath=Path;
CScripting* pScript=CScriptManager::GetScriptManager()->LoadScript((LPCTSTR)bPath);
if(!pScript)
return SetError(E_FAIL,"Íå óäàëîñü çàãðóçèòü ñêðèïò %s",(LPCTSTR)bPath);
return pScript->m_pEngine->GetScriptDispatch(NULL,pRetVal);
}
STDMETHODIMP CIScripts::ReLoad(VARIANT Idx)
{
CScripting* pScript=GetScript(Idx);
if(!pScript)
return E_FAIL;
pScript->ReloadScript();
return S_OK;
}
STDMETHODIMP CIScripts::UnLoad(VARIANT Idx)
{
CScripting* pScript=GetScript(Idx);
if(!pScript)
return E_FAIL;
CScriptManager::GetScriptManager()->UnLoadScript(pScript);
return S_OK;
}
STDMETHODIMP CIScripts::get_Path(VARIANT idx,BSTR *pVal)
{
if(IsBadWritePtr(pVal,sizeof(*pVal)))
return E_POINTER;
CScripting* pScript=GetScript(idx);
if(!pScript)
return E_FAIL;
*pVal=pScript->m_FileName.AllocSysString();
return S_OK;
}
STDMETHODIMP CIScripts::get_Name(VARIANT idx,BSTR *pVal)
{
if(IsBadWritePtr(pVal,sizeof(*pVal)))
return E_POINTER;
CScripting* pScript=GetScript(idx);
if(!pScript)
return E_FAIL;
*pVal=pScript->m_ScriptName.AllocSysString();
return S_OK;
}
STDMETHODIMP CIScripts::get_Engine(VARIANT idx,BSTR *pVal)
{
if(IsBadWritePtr(pVal,sizeof(*pVal)))
return E_POINTER;
CScripting* pScript=GetScript(idx);
if(!pScript)
return E_FAIL;
*pVal=pScript->m_EngineName.AllocSysString();
return S_OK;
}
CScripting* CIScripts::GetScript(VARIANT& idx)
{
CScripting* pScript=NULL;
CScriptManager* pSM=CScriptManager::GetScriptManager();
if(idx.vt==VT_BSTR)
{
_bstr_t bname=idx;
pScript=pSM->GetScriptByName((LPCTSTR)bname);
if(!pScript)
SetError(E_FAIL,"Íåäîïóñòèìûé èíäåêñ: %s",(LPCTSTR)bname);
}
else
{
if(idx.vt!=VT_I4)
VariantChangeType(&idx,&idx,0,VT_I4);
if(idx.vt!=VT_I4)
SetError(E_FAIL,"Íåäîïóñòèìûé òèï èíäåêñà");
else
{
pScript=pSM->GetScriptByNum(idx.lVal);
if(!pScript)
SetError(E_FAIL,"Íåäîïóñòèìûé èíäåêñ: %i",idx.lVal);
}
}
return pScript;
}
void CIScripts::Done()
{
if(m_pScripts)
delete m_pScripts;
}