void GetFreeFunctionsInScripts(CStringArray & sNamesArray, LPCWSTR TransformationEvent) { // get an array with the available scripts PluginArray * piScriptArray = CAllThreadsScripts::GetActiveSet()->GetAvailableScripts(TransformationEvent); // fill in these structures int nFnc = 0; int iScript; for (iScript = 0 ; iScript < piScriptArray->GetSize() ; iScript++) { PluginInfo & plugin = piScriptArray->ElementAt(iScript); LPDISPATCH piScript = plugin.m_lpDispatch; BSTR * scriptNamesArray; int * scriptIdsArray; int nScriptFnc = GetMethodsFromScript(piScript, scriptNamesArray, scriptIdsArray); sNamesArray.SetSize(nFnc+nScriptFnc); int iFnc; for (iFnc = 0 ; iFnc < nScriptFnc ; iFnc++) // the CString = operator provides the conversion if UNICODE is not defined sNamesArray[nFnc+iFnc] = scriptNamesArray[iFnc]; delete [] scriptIdsArray; delete [] scriptNamesArray; nFnc += nScriptFnc; } }
void CSelectUnpackerDlg::Initialize() { //{{AFX_DATA_INIT(CSelectUnpackerDlg) m_bNoExtensionCheck = FALSE; m_strDescription = _T(""); m_strExtensions = _T(""); //}}AFX_DATA_INIT // texts for the default unpackers noPlugin = new PluginInfo; noPlugin->m_lpDispatch = NULL; noPlugin->m_filters = NULL; noPlugin->m_name = theApp.LoadString(IDS_USERCHOICE_NONE); automaticPlugin = new PluginInfo; automaticPlugin->m_lpDispatch = NULL; automaticPlugin->m_filters = NULL; automaticPlugin->m_name = LoadResString(IDS_USERCHOICE_AUTOMATIC); automaticPlugin->m_description = LoadResString(ID_UNPACK_AUTO); m_pPlugin = noPlugin; PluginArray * piFileScriptArray = CAllThreadsScripts::GetActiveSet()->GetAvailableScripts(L"FILE_PACK_UNPACK"); PluginArray * piBufferScriptArray = CAllThreadsScripts::GetActiveSet()->GetAvailableScripts(L"BUFFER_PACK_UNPACK"); // add the default unpackers to the unpackers list m_UnpackerPlugins.Add(noPlugin); m_bWithFileFlags.Add(0); m_UnpackerPlugins.Add(automaticPlugin); m_bWithFileFlags.Add(0); // add the real unpackers to the unpackers list int i; for (i = 0 ; i < piFileScriptArray->GetSize() ; i++) { // during the dialog, we use a pointer to the scriptsOfThreads array m_UnpackerPlugins.Add(&piFileScriptArray->ElementAt(i)); m_bWithFileFlags.Add(1); } for (i = 0 ; i < piBufferScriptArray->GetSize() ; i++) { // during the dialog, we use a pointer to the scriptsOfThreads array m_UnpackerPlugins.Add(&piBufferScriptArray->ElementAt(i)); m_bWithFileFlags.Add(0); } }
/** * @brief Add plugins of given event type to the list. * @param [in] pluginEvent Event type for plugins to add. * @param [in] pluginType String to use as type in the list. */ void PluginsListDlg::AddPluginsToList(LPCWSTR pluginEvent, LPCTSTR pluginType) { PluginArray * piPluginArray = CAllThreadsScripts::GetActiveSet()->GetAvailableScripts(pluginEvent); for (int iPlugin = 0 ; iPlugin < piPluginArray->GetSize() ; iPlugin++) { PluginInfo & plugin = piPluginArray->ElementAt(iPlugin); int ind = m_list.InsertItem(m_list.GetItemCount(), plugin.m_name.c_str()); m_list.SetItemText(ind, 1, pluginType); m_list.SetItemText(ind, 2, plugin.m_description.c_str()); } }
/** * @brief Write plugin names */ void CConfigLog::WritePluginsInLogFile(LPCWSTR transformationEvent) { // do nothing if actually reading config file if (!m_writing) return; // get an array with the available scripts PluginArray * piPluginArray; piPluginArray = CAllThreadsScripts::GetActiveSet()->GetAvailableScripts(transformationEvent); int iPlugin; for (iPlugin = 0 ; iPlugin < piPluginArray->GetSize() ; iPlugin++) { PluginInfo & plugin = piPluginArray->ElementAt(iPlugin); m_pfile->WriteString(_T("\r\n ")); m_pfile->WriteString(plugin.m_name.c_str()); m_pfile->WriteString(_T(" [")); m_pfile->WriteString(plugin.m_filepath.c_str()); m_pfile->WriteString(_T("]")); } }
// scan plugins for the first handler BOOL FileTransform_Prediffing(String & filepath, LPCTSTR filteredText, PrediffingInfo * handler, BOOL bMayOverwrite) { storageForPlugins bufferData; // detect Ansi or Unicode file bufferData.SetDataFileUnknown(filepath.c_str(), bMayOverwrite); // TODO : set the codepage // bufferData.SetCodepage(); // filename, to test the extension CString filename = PathFindFileName(filepath.c_str()); // control value BOOL bHandled = FALSE; // get the scriptlet files PluginArray * piFileScriptArray = CAllThreadsScripts::GetActiveSet()->GetAvailableScripts(L"FILE_PREDIFF"); // MAIN LOOP : call each handler, // stop as soon as we have a success int step; for (step = 0 ; bHandled == FALSE && step < piFileScriptArray->GetSize() ; step ++) { PluginInfo & plugin = piFileScriptArray->ElementAt(step); if (plugin.m_bAutomatic == FALSE) continue; if (plugin.TestAgainstRegList(filteredText) == FALSE) continue; handler->pluginName = plugin.m_name; handler->bWithFile = TRUE; // use a temporary dest name bHandled = InvokePrediffFile(bufferData.GetDataFileAnsi(), bufferData.GetDestFileName(), bufferData.GetNChanged(), plugin.m_lpDispatch); if (bHandled) bufferData.ValidateNewFile(); } // get the scriptlet files PluginArray * piBufferScriptArray = CAllThreadsScripts::GetActiveSet()->GetAvailableScripts(L"BUFFER_PREDIFF"); // MAIN LOOP : call each handler, // stop as soon as we have a success for (step = 0 ; bHandled == FALSE && step < piBufferScriptArray->GetSize() ; step ++) { PluginInfo & plugin = piBufferScriptArray->ElementAt(step); if (plugin.m_bAutomatic == FALSE) continue; if (plugin.TestAgainstRegList(filteredText) == FALSE) continue; handler->pluginName = plugin.m_name; handler->bWithFile = FALSE; // probably it is for VB/VBscript so use a BSTR as argument bHandled = InvokePrediffBuffer(*bufferData.GetDataBufferUnicode(), bufferData.GetNChanged(), plugin.m_lpDispatch); if (bHandled) bufferData.ValidateNewBuffer(); } if (bHandled == FALSE) { // we didn't find any prediffer, that is OK anyway handler->pluginName = _T(""); bHandled = TRUE; } // the handler is now defined handler->bToBeScanned = FALSE; // if the buffer changed, write it before leaving BOOL bSuccess = TRUE; if (bufferData.GetNChangedValid() > 0) { bSuccess = bufferData.SaveAsFile(filepath); } return bSuccess; }
// scan plugins for the first handler BOOL FileTransform_Unpacking(String & filepath, LPCTSTR filteredText, PackingInfo * handler, int * handlerSubcode) { // PLUGIN_BUILTIN_XML : read source file through custom UniFile if (handler->bToBeScanned == PLUGIN_BUILTIN_XML) { handler->pufile = new UniMarkdownFile; handler->textType = _T("xml"); handler->disallowMixedEOL = true; handler->pluginName.erase(); // Make FileTransform_Packing() a NOP // Leave bToBeScanned alone so above lines will continue to execute on // subsequent calls to this function return TRUE; } storageForPlugins bufferData; bufferData.SetDataFileAnsi(filepath.c_str()); // filename, to test the extension CString filename = PathFindFileName(filepath.c_str()); // control value BOOL bHandled = FALSE; // get the scriptlet files PluginArray * piFileScriptArray = CAllThreadsScripts::GetActiveSet()->GetAvailableScripts(L"FILE_PACK_UNPACK"); // MAIN LOOP : call each handler, // stop as soon as we have a success int step; for (step = 0 ; bHandled == FALSE && step < piFileScriptArray->GetSize() ; step ++) { PluginInfo & plugin = piFileScriptArray->ElementAt(step); if (plugin.m_bAutomatic == FALSE) continue; if (plugin.TestAgainstRegList(filteredText) == FALSE) continue; handler->pluginName = plugin.m_name; handler->bWithFile = TRUE; // use a temporary dest name bHandled = InvokeUnpackFile(bufferData.GetDataFileAnsi(), bufferData.GetDestFileName(), bufferData.GetNChanged(), plugin.m_lpDispatch, handler->subcode); if (bHandled) bufferData.ValidateNewFile(); } // We can not assume that the file is text, so use a safearray and not a BSTR // TODO : delete this event ? Is anyone going to use this ? // get the scriptlet files PluginArray * piBufferScriptArray = CAllThreadsScripts::GetActiveSet()->GetAvailableScripts(L"BUFFER_PACK_UNPACK"); // MAIN LOOP : call each handler, // stop as soon as we have a success for (step = 0 ; bHandled == FALSE && step < piBufferScriptArray->GetSize() ; step ++) { PluginInfo & plugin = piBufferScriptArray->ElementAt(step); if (plugin.m_bAutomatic == FALSE) continue; if (plugin.TestAgainstRegList(filteredText) == FALSE) continue; handler->pluginName = plugin.m_name; handler->bWithFile = FALSE; bHandled = InvokeUnpackBuffer(*bufferData.GetDataBufferAnsi(), bufferData.GetNChanged(), plugin.m_lpDispatch, handler->subcode); if (bHandled) bufferData.ValidateNewBuffer(); } if (bHandled == FALSE) { // we didn't find any unpacker, just hope it is normal Ansi/Unicode handler->pluginName = _T(""); handler->subcode = 0; bHandled = TRUE; } // the handler is now defined handler->bToBeScanned = FALSE; // assign the sucode *handlerSubcode = handler->subcode; // if the buffer changed, write it before leaving BOOL bSuccess = TRUE; if (bufferData.GetNChangedValid() > 0) { bSuccess = bufferData.SaveAsFile(filepath); } return bSuccess; }