intptr_t WINAPI ProcessSynchroEventW(const struct ProcessSynchroEventInfo *Info) { if (Info->Event != SE_COMMONSYNCHRO) return 0; if (gnInCall > 0) return 0; #if 1 OutputDebugString(L"Posting macro\n"); MacroSendMacroText mcr = {sizeof(MacroSendMacroText)}; //mcr.SequenceText = L"i = 0; if APanel.Plugin then i=i+1; end; if PPanel.Plugin then i=i+2; end; Plugin.Call(\"6197AF6C-4755-49A5-84A1-8F227BF4790E\",i)"; mcr.SequenceText = L"Plugin.Call(\"6197AF6C-4755-49A5-84A1-8F227BF4790E\",APanel.Plugin and \"\" or APanel.Path0,PPanel.Plugin and \"\" or PPanel.Path0)"; INT_PTR i = psi.MacroControl(&guid_PluginGuid, MCTL_SENDSTRING, MSSC_POST, &mcr); MacroParseResult* mpr; if (!i) { mpr = (MacroParseResult*)calloc(4096,1); mpr->StructSize = sizeof(*mpr); psi.MacroControl(&guid_PluginGuid, MCTL_GETLASTERROR, 4096, mpr); free(mpr); } else InterlockedIncrement(&gnInCall); #endif #if 0 wchar_t szDbg[100]; static LONG nCount; nCount++; wsprintf(szDbg, L"%i: PanelControl(FCTL_GETPANELINFO, PANEL_ACTIVE)...", nCount); PanelInfo piA = {sizeof(piA)}, piP = {sizeof(piP)}; INT_PTR nARc = psi.PanelControl(PANEL_ACTIVE, FCTL_GETPANELINFO, 0, &piA); OutputDebugString(L" and PANEL_PASSIVE..."); INT_PTR nPRc = psi.PanelControl(PANEL_PASSIVE, FCTL_GETPANELINFO, 0, &piP); OutputDebugString(L" Done\n"); #endif return 0; }
HANDLE WINAPI OpenW(const OpenInfo* info) { if (!info || info->StructSize < sizeof(OpenInfo)) return nullptr; //Determine file name to analyze wstring file_name; if (info->OpenFrom == OPEN_COMMANDLINE && info->Data) { const OpenCommandLineInfo* ocli = reinterpret_cast<const OpenCommandLineInfo*>(info->Data); if (!ocli || ocli->StructSize < sizeof(OpenCommandLineInfo) || !ocli->CommandLine || !ocli->CommandLine[0]) return nullptr; //Get command line wstring cmd_line = ocli->CommandLine; size_t pos = 0; while ((pos = cmd_line.find(L'\"', pos)) != string::npos) cmd_line.erase(pos, 1); while (!cmd_line.empty() && iswspace(cmd_line[0])) cmd_line.erase(0, 1); while (!cmd_line.empty() && iswspace(cmd_line[cmd_line.length() - 1])) cmd_line.erase(cmd_line.length() - 1, 1); if (cmd_line.empty()) return nullptr; //Expand environment variables in path string wstring exp_path(2048, 0); if (ExpandEnvironmentStrings(cmd_line.c_str(), &exp_path.front(), static_cast<DWORD>(exp_path.size() - 1))) exp_path.resize(lstrlen(exp_path.c_str())); else exp_path = cmd_line; const size_t path_len = _FSF.ConvertPath(CPM_FULL, exp_path.c_str(), nullptr, 0); if (path_len) { file_name.resize(path_len); _FSF.ConvertPath(CPM_FULL, exp_path.c_str(), &file_name[0], path_len); } } else if (info->OpenFrom == OPEN_PLUGINSMENU) { PanelInfo pi; ZeroMemory(&pi, sizeof(pi)); pi.StructSize = sizeof(pi); if (!_PSI.PanelControl(PANEL_ACTIVE, FCTL_GETPANELINFO, 0, &pi)) return nullptr; const intptr_t ppi_len = _PSI.PanelControl(PANEL_ACTIVE, FCTL_GETPANELITEM, static_cast<int>(pi.CurrentItem), nullptr); if (ppi_len == 0) return nullptr; vector<unsigned char> buffer(ppi_len); PluginPanelItem* ppi = reinterpret_cast<PluginPanelItem*>(&buffer.front()); FarGetPluginPanelItem fgppi; ZeroMemory(&fgppi, sizeof(fgppi)); fgppi.StructSize = sizeof(fgppi); fgppi.Size = buffer.size(); fgppi.Item = ppi; if (!_PSI.PanelControl(PANEL_ACTIVE, FCTL_GETPANELITEM, static_cast<int>(pi.CurrentItem), &fgppi)) return nullptr; const size_t file_name_len = _FSF.ConvertPath(CPM_FULL, ppi->FileName, nullptr, 0); if (file_name_len) { file_name.resize(file_name_len); _FSF.ConvertPath(CPM_FULL, ppi->FileName, &file_name[0], file_name_len); } } if (!file_name.empty()) { unlocker u; u.process(file_name.c_str()); } return nullptr; }
HANDLE WINAPI OpenW(const struct OpenInfo *Info) { const int CUR_DIR_SIZE = 100000; char* filename = 0; switch( Info->OpenFrom ) { case OPEN_COMMANDLINE: { OpenCommandLineInfo* cinfo = (OpenCommandLineInfo*)Info->Data; const wchar_t* cmdline = cinfo->CommandLine; if( !cmdline ) return INVALID_HANDLE_VALUE; while( *cmdline && *cmdline <= ' ' ) cmdline++; if( *cmdline ) filename = w2a( cmdline ); else return 0; break; } case OPEN_PLUGINSMENU: { FarGetPluginPanelItem pinfo; PluginPanelItem* pitem = (PluginPanelItem*)malloc(CUR_DIR_SIZE); ZeroMemory(&pinfo, sizeof(pinfo)); ZeroMemory(pitem, CUR_DIR_SIZE); pinfo.StructSize = sizeof(pinfo); pinfo.Size = CUR_DIR_SIZE; pinfo.Item = pitem; if(InfoW.PanelControl( PANEL_ACTIVE, FCTL_GETCURRENTPANELITEM, 0, &pinfo )) { filename = w2a( pinfo.Item->FileName ); free(pitem); } else { free(pitem); return 0; } break; } default: return 0; } if( !filename ) return 0; wchar_t comspec[MAX_PATH * 2]; if( !GetEnvironmentVariableW( L"COMSPEC", comspec, sizeofa( comspec ) ) ) lstrcpyW( comspec, L"cmd.exe" ); char pipename[100]; wsprintf( pipename, "\\\\.\\pipe\\FarCall%ul", GetCurrentProcessId() ); char* batchstr = (char*)malloc( 10000 ); wsprintf( batchstr, batch, filename, ModuleName, pipename ); // obtaining temp file name wchar_t tmp[MAX_PATH * 10]; GetTempPathW( sizeofa( tmp ), tmp ); GetTempFileNameW( tmp, L"", 0, tmp ); DeleteFileW( tmp ); lstrcatW( tmp, L".bat" ); HANDLE file = CreateFileW( tmp, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, CREATE_ALWAYS, 0, 0 ); if( !file || file == INVALID_HANDLE_VALUE ) { DeleteFileW( tmp ); free( filename ); free( batchstr ); return INVALID_HANDLE_VALUE; } DWORD written; WriteFile( file, batchstr, lstrlen( batchstr ), &written, 0 ); CloseHandle( file ); wchar_t cmd[MAX_PATH * 10] = L"\""; lstrcatW( lstrcatW( lstrcatW( lstrcatW( cmd, comspec ), L"\" /c \"" ), tmp ), L"\""); STARTUPINFOW sinfo; ZeroMemory( &sinfo, sizeof( sinfo ) ); sinfo.cb = sizeof( sinfo ); PROCESS_INFORMATION pinfo; Handle np( CreateNamedPipe( pipename, PIPE_ACCESS_DUPLEX, PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, 100, 100, 0, 0 ) ); connected = false; DWORD id; Handle thread( CreateThread( 0, 0, ListenEnv, np, 0, &id ) ); while( !connected ) Sleep( 100 ); CONSOLE_SCREEN_BUFFER_INFO csbi; GetConsoleScreenBufferInfo( GetStdHandle( STD_OUTPUT_HANDLE ), &csbi ); #ifndef LIGHTGRAY #define LIGHTGRAY 7 #endif wchar_t Blank[1024]; FSFW.sprintf(Blank,L"%*s",csbi.dwSize.X,L""); FarColor fc = {FCF_NONE, LIGHTGRAY, 0, 0}; for (int Y=0;Y<csbi.dwSize.Y;Y++) InfoW.Text(0,Y,&fc,Blank); InfoW.Text(0,0,0,NULL); COORD C; C.X=0; C.Y=csbi.dwCursorPosition.Y; SetConsoleCursorPosition( GetStdHandle( STD_OUTPUT_HANDLE ), C ); wchar_t* curr_dir = (wchar_t*)malloc(CUR_DIR_SIZE); FSFW.GetCurrentDirectory(CUR_DIR_SIZE, curr_dir); if( np && CreateProcessW( NULL, cmd, 0, 0, TRUE, 0, 0, curr_dir[0] ? curr_dir : 0, &sinfo, &pinfo ) ) { HANDLE ar[] = {pinfo.hProcess, np}; WaitForMultipleObjects( 2, ar, TRUE, INFINITE ); CloseHandle(pinfo.hProcess); CloseHandle(pinfo.hThread); SMALL_RECT src; COORD dest; CHAR_INFO fill; src.Left=0; src.Top=2; src.Right=csbi.dwSize.X; src.Bottom=csbi.dwSize.Y; dest.X=dest.Y=0; fill.Char.AsciiChar=' '; fill.Attributes=7; ScrollConsoleScreenBuffer( GetStdHandle( STD_OUTPUT_HANDLE ), &src, NULL, dest, &fill); InfoW.AdvControl(0, ACTL_REDRAWALL, 0, 0); } else Handle onp( CreateFile( pipename, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0 ) ); free( filename ); free( batchstr ); free( curr_dir ); DeleteFileW( tmp ); return 0; }