1 /////////////////////////////////////////////////////////////////////////////
2 // WinMerge: an interactive diff/merge utility
3 // Copyright (C) 1997-2000 Thingamahoochie Software
5 // SPDX-License-Identifier: GPL-2.0-or-later
6 /////////////////////////////////////////////////////////////////////////////
10 * @brief Declaration file for VBS Scriptlets, VB ActiveX DLL, VC++ COM DLL
14 #include <Poco/Foundation.h>
20 #include "UnicodeString.h"
22 struct FileFilterElement;
23 typedef std::shared_ptr<FileFilterElement> FileFilterElementPtr;
26 * @brief List of transformation categories (events)
28 * @note If you add some event, you have to complete this array in FileTransform.cpp
30 extern const wchar_t *TransformationCategories[];
33 * @brief Information structure for a plugin
39 : m_lpDispatch(nullptr), m_filters(NULL), m_bAutomatic(false), m_nFreeFunctions(0), m_disabled(false)
45 if (m_lpDispatch!=nullptr)
46 m_lpDispatch->Release();
49 int LoadPlugin(const String & scriptletFilepath);
51 /// Parse the filter string (only for files), and create the filters
52 void LoadFilterString();
54 * @brief Does the plugin handles this(ese) filename(s) ?
56 * @param szTest String of filenames, delimited with '|'
58 bool TestAgainstRegList(const String& szTest) const;
62 LPDISPATCH m_lpDispatch;
63 String m_name; // usually filename, except for special cases (like auto or no)
66 String m_filtersTextDefault;
71 std::vector<FileFilterElementPtr> m_filters;
72 /// only for plugins with free function names (EDITOR_SCRIPT)
76 PluginInfo( const PluginInfo& other ); // non construction-copyable
77 PluginInfo& operator=( const PluginInfo& ); // non copyable
80 typedef std::shared_ptr<PluginInfo> PluginInfoPtr;
82 typedef std::vector<PluginInfoPtr> PluginArray;
83 typedef std::shared_ptr<PluginArray> PluginArrayPtr;
86 * @brief Cache for the scriptlets' interfaces during the life of a thread.
87 * One instance and only one for each thread (necessary for VB)
89 * @note Never create CScriptsOfThread directly : use the class CAssureScriptsForThread
90 * to guarantee unicity
92 class CScriptsOfThread
94 friend class CAssureScriptsForThread;
95 friend class CAllThreadsScripts;
97 PluginArray * GetAvailableScripts(const wchar_t *transformationEvent);
98 PluginInfo * GetAutomaticPluginByFilter(const wchar_t *transformationEvent, const String& filteredText);
99 PluginInfo * GetPluginByName(const wchar_t *transformationEvent, const String& name);
100 PluginInfo * GetPluginInfo(LPDISPATCH piScript);
103 void FreeAllScripts();
104 void FreeScriptsForEvent(const wchar_t *transformationEvent);
109 void Lock() { m_nLocks ++; };
110 bool Unlock() { m_nLocks --; return (m_nLocks == 0); };
111 /// Tell if this scripts is the one for main thread (by convention, the first in the repository)
112 bool bInMainThread();
116 unsigned long m_nThreadId;
117 /// Result of CoInitialize
118 HRESULT hrInitialize;
119 int nTransformationEvents;
120 std::map<String, PluginArrayPtr> m_aPluginsByEvent;
125 * @brief Repository of CScriptsOfThread
127 class CAllThreadsScripts
129 friend class CAssureScriptsForThread;
131 static void Add(CScriptsOfThread * scripts);
132 static void Remove(CScriptsOfThread * scripts);
133 static CScriptsOfThread * GetActiveSetNoAssert();
135 /// main public function : get the plugins array for the current thread
136 static CScriptsOfThread * GetActiveSet();
137 /// by convention, the scripts for main thread must be created before all others
138 static bool bInMainThread(CScriptsOfThread * scripts);
140 // fixed size array, advantage : no mutex to allocate/free
141 static std::vector<CScriptsOfThread *> m_aAvailableThreads;
145 * @brief Simple control to add/remove a CScriptsOfThread in the repository.
146 * Create at least one CAssumeScriptsForThread for each thread, including the main one.
147 * It's OK to create several CAssumeScriptsForThread for the same thread (if you need scripts in one function
148 * and do not know what happened before the function).
150 class CAssureScriptsForThread
153 CAssureScriptsForThread();
154 ~CAssureScriptsForThread();
161 * @brief Check for the presence of Windows Script
163 * .sct plugins require this optional component
165 bool IsWindowsScriptThere();
167 * @brief Get a list of the function IDs and names in a script or activeX/COM DLL
169 * @return Returns the number of functions
172 int GetMethodsFromScript(LPDISPATCH piDispatch, std::vector<String>& namesArray, std::vector<int>& IdArray);
175 * @brief Get the number of methods in the script
176 * @note For free function scripts (EDITOR_SCRIPT)
178 int CountMethodsInScript(LPDISPATCH piDispatch);
181 * @brief Get the ID of the a free function
182 * @param methodOrdinal : index of the free function (0,1,2...)
184 int GetMethodIDInScript(LPDISPATCH piDispatch, int methodIndex);
188 // Wrappers to call plugins methods
191 * @brief Call the plugin "PrediffBufferW" method, events PREDIFFING
193 * @param bstrBuf Overwrite/realloc this buffer
195 bool InvokePrediffBuffer(BSTR & bstrBuf, int & nChanged, LPDISPATCH piScript);
198 * @brief Call custom plugin functions : text transformation
200 bool InvokeTransformText(String & text, int & changed, LPDISPATCH piScript, int fncId);
203 * @brief Call the plugin "UnpackBufferA" method, event BUFFER_PACK_UNPACK
205 * @param pszBuf has unknown format, so a simple char*
206 * never owervrites this source buffer
208 bool InvokeUnpackBuffer(VARIANT & array, int & nChanged, LPDISPATCH piScript, int & subcode);
210 * @brief Call the plugin "PackBufferA" method, event BUFFER_PACK_UNPACK
212 * @param pszBuf has unknown format, so a simple char*
213 * never owervrites this source buffer
215 bool InvokePackBuffer(VARIANT & array, int & nChanged, LPDISPATCH piScript, int subcode);
217 * @brief Call the plugin "UnpackFile" method, event FILE_PACK_UNPACK
219 bool InvokeUnpackFile(const String& fileSource, const String& fileDest, int & nChanged, LPDISPATCH piScript, int & subCode);
221 * @brief Call the plugin "PackFile" method, event FILE_PACK_UNPACK
223 bool InvokePackFile(const String& fileSource, const String& fileDest, int & nChanged, LPDISPATCH piScript, int subCode);
225 * @brief Call the plugin "IsFolder" method, event FILE_FOLDER_PACK_UNPACK
227 bool InvokeIsFolder(const String& file, IDispatch *piScript);
229 * @brief Call the plugin "UnpackFolder" method, event FILE_FOLDER_PACK_UNPACK
231 bool InvokeUnpackFolder(const String& fileSource, const String& folderDest, int & nChanged, IDispatch *piScript, int & subCode);
233 * @brief Call the plugin "PackFolder" method, event FILE_FOLDER_PACK_UNPACK
235 bool InvokePackFolder(const String& folderSource, const String& fileDest, int & nChanged, IDispatch *piScript, int subCode);
237 * @brief Call the plugin "PrediffFile" method, event FILE_PREDIFF
239 bool InvokePrediffFile(const String& fileSource, const String& fileDest, int & nChanged, LPDISPATCH piScript);
241 * @brief Call the plugin "ShowSettingsDialog" method
243 bool InvokeShowSettingsDialog(LPDISPATCH piScript);