📄 scriptwriter.cpp
字号:
HRESULT hres; hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID *)&psl); if (SUCCEEDED(hres)) { IPersistFile *ppf; hres = psl->QueryInterface(IID_IPersistFile, (LPVOID *)&ppf); if (SUCCEEDED(hres)) { WORD wsz[MAX_PATH]; MultiByteToWideChar(CP_ACP, 0, path, -1, wsz, MAX_PATH); hres = ppf->Load(wsz, STGM_READ); if (SUCCEEDED(hres)) {#if defined SPECIAL_BUILD _Module.pLauncher->WriteLogFile("[launcher] IPersistFile::Load call succeeded.\n");#endif hres = psl->Resolve(0, SLR_ANY_MATCH | SLR_NO_UI); if (SUCCEEDED(hres)) {#if defined SPECIAL_BUILD _Module.pLauncher->WriteLogFile("[launcher] IShellLink::Resolve call succeeded.\n");#endif WIN32_FIND_DATA wfd; char szgotpath[MAX_PATH]; ZeroMemory(szgotpath, MAX_PATH); hres = psl->GetPath(szgotpath, MAX_PATH, &wfd, SLGP_SHORTPATH); if(SUCCEEDED(hres)) {#if defined SPECIAL_BUILD _Module.pLauncher->WriteLogFile("[launcher] IShellLink::GetPath() call succeeded; resolved path is "); if(szgotpath == 0 || strlen(szgotpath) == 0) _Module.pLauncher->WriteLogFile("<zero-length string>."); else _Module.pLauncher->WriteLogFile(szgotpath); _Module.pLauncher->WriteLogFile("\n");#endif if(szgotpath != 0 && strlen(szgotpath) != 0) strcpy(outPath, szgotpath); }#if defined SPECIAL_BUILD else { _Module.pLauncher->WriteLogFile("[launcher] IShellLink::GetPath() call did not succeed. Error code: "); char szMsg[32]; strcpy(szMsg, "0x"); ltoa(hres, szMsg + 2, 16); strcat(szMsg, "\n"); _Module.pLauncher->WriteLogFile(szMsg); }#endif }#if defined SPECIAL_BUILD else { _Module.pLauncher->WriteLogFile("[launcher] IShellLink::Resolve call failed. Error code: "); char szMsg[32]; strcpy(szMsg, "0x"); ltoa(hres, szMsg + 2, 16); strcat(szMsg, "\n"); _Module.pLauncher->WriteLogFile(szMsg); }#endif }#if defined SPECIAL_BUILD else { _Module.pLauncher->WriteLogFile("[launcher] IPersistFile::Load call failed. Error code: "); char szMsg[32]; strcpy(szMsg, "0x"); ltoa(hres, szMsg + 2, 16); strcat(szMsg, "\n"); _Module.pLauncher->WriteLogFile(szMsg); }#endif ppf->Release(); }#if defined SPECIAL_BUILD else { _Module.pLauncher->WriteLogFile("[launcher] Could not get pointer to IPersistFile object. Error code: "); char szMsg[32]; strcpy(szMsg, "0x"); ltoa(hres, szMsg + 2, 16); strcat(szMsg, "\n"); _Module.pLauncher->WriteLogFile(szMsg); }#endif psl->Release(); }#if defined SPECIAL_BUILD else { _Module.pLauncher->WriteLogFile("[launcher] Could not get pointer to IShellLink object. Error code:"); char szMsg[32]; strcpy(szMsg, "0x"); ltoa(hres, szMsg + 2, 16); strcat(szMsg, "\n"); _Module.pLauncher->WriteLogFile(szMsg); }#endif if(!SUCCEEDED(hres)) { strcpy(outPath, path); } return hres;}void ScriptWriter::AppendPath(const char* path){ if(path == 0) return; const char* s = path; char *d = pBuffer + strlen(pBuffer); *d++ = '\"'; while(*s != 0) { if(*s == '\\') *d++ = '\\'; *d++ = *s++; } *d++ = '\"'; *d = 0;}void ScriptWriter::Append(const char* source){ strcat(pBuffer, source);}// Implementation of class OpenFileScriptOpenFileScript::OpenFileScript() : ScriptWriter(), m_nFiles(0){ InitBuffer(4096);}OpenFileScript::~OpenFileScript() {}HRESULT OpenFileScript::WritePrefix(){#if defined SPECIAL_BUILD _Module.pLauncher->WriteLogFile("[launcher] Calling OpenFileScript::WritePrefix()\n");#endif ClearBuffer(); Append("v = new java.util.Vector(8); "); return S_OK;}HRESULT OpenFileScript::ProcessSinglePath(const char* pszPath){#if defined SPECIAL_BUILD _Module.pLauncher->WriteLogFile("[launcher] Calling OpenFileScript::ProcessSinglePath() with char parameter "); _Module.pLauncher->WriteLogFile(pszPath); _Module.pLauncher->WriteLogFile("\n");#endif Append("v.addElement("); AppendPath(pszPath); Append("); "); ++m_nFiles; return S_OK;}HRESULT OpenFileScript::WriteSuffix(){#if defined SPECIAL_BUILD _Module.pLauncher->WriteLogFile("[launcher] Calling OpenFileScript::WriteSuffix()\n");#endif if(m_nFiles == 0) { ClearBuffer(); Append("Macros.error(jEdit.getFirstView(), "); Append("\"No files met the supplied wild-card specification.\");"); } else { Append("s = v.size(); args = new String[s]; v.copyInto(args); "); Append("EditServer.handleClient(true, null, args); "); Append("jEdit.openFile(jEdit.getFirstView(), args[s - 1]);\n\n"); } return S_OK;}// Implementation of class OpenDiffScript/* Here is the script written by this object: // ----- prefix ----- v = jEdit.getFirstView(); if(jEdit.getPlugin("JDiffPlugin") == null) { Macros.error(v, "You must have the JDiff plugin " + "installed to use this jEditLauncher feature."); return; } if(DualDiff.isEnabledFor(v)) DualDiff.toggleFor(v); while(v.getEditPanes().length > 1) v.unsplit(); v.splitVertically(); DualDiff.toggleFor(v); openDiffFiles(vv) { v = vv; run() { buf1 = // ----- file 1 ----- jEdit.openFile(v, "<file 1>"); buf2 = // ----- file 2 ----- jEdit.openFile(v, "<file 2>"); // ----- suffix ----- VFSManager.waitForRequests(); editPanes = v.getEditPanes(); editPanes[0].setBuffer(buf1); editPanes[1].setBuffer(buf2); } return this; } SwingUtilities.invokeLater(openDiffFiles(v));*/OpenDiffScript::OpenDiffScript() : ScriptWriter(), secondFile(false){ InitBuffer(1024);}OpenDiffScript::~OpenDiffScript() {}HRESULT OpenDiffScript::WritePrefix(){ ClearBuffer(); Append("v = jEdit.getFirstView(); "); Append("if(jEdit.getPlugin(\"JDiffPlugin\") == null) { "); Append("Macros.error(v, \"You must have the JDiff plugin "); Append("installed to use this jEditLauncher feature.\"); return; } "); Append("if(DualDiff.isEnabledFor(v)) DualDiff.toggleFor(v); "); Append("while(v.getEditPanes().length > 1) v.unsplit(); "); Append("v.splitVertically(); "); Append("DualDiff.toggleFor(v); openDiffFiles(vv) { v = vv; run() { buf1 = "); return S_OK;}HRESULT OpenDiffScript::ProcessSinglePath(const char* pszPath){ Append("jEdit.openFile(v, "); AppendPath(pszPath); Append("); "); if(!secondFile) { Append("buf2 = "); secondFile = true; } return S_OK;}HRESULT OpenDiffScript::WriteSuffix(){ Append("VFSManager.waitForRequests(); editPanes = v.getEditPanes(); "); Append("editPanes[0].setBuffer(buf1); "); Append("editPanes[1].setBuffer(buf2); } return this; } "); Append("SwingUtilities.invokeLater(openDiffFiles(v));"); return S_OK;}// Implementation of class StartAppScriptStartAppScript::StartAppScript(LPCTSTR lpszCmdLine) : ScriptWriter(), bFirstFile(true), m_lpszCmdLine(lpszCmdLine){ InitBuffer(2048);}StartAppScript::~StartAppScript() {}HRESULT StartAppScript::WritePrefix(){ ClearBuffer(); Append(m_lpszCmdLine); return S_OK;}HRESULT StartAppScript::ProcessSinglePath(const char* pszPath){ if(bFirstFile) { Append("-- "); bFirstFile = false; } AppendPath(pszPath); Append(" "); return S_OK;}HRESULT StartAppScript::WriteSuffix(){ bFirstFile = true; // reset return S_OK;}// Implementation of class FileListScriptFileListScript::FileListScript() : ScriptWriter(){ InitBuffer(1024);}FileListScript::~FileListScript() {}HRESULT FileListScript::WritePrefix(){ ClearBuffer(); Append("-- "); return S_OK;}HRESULT FileListScript::ProcessSinglePath(const char* pszPath){ AppendPath(pszPath); Append(" "); return S_OK;}HRESULT FileListScript::WriteSuffix(){ return S_OK;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -