示例#1
0
intptr_t WINAPI GetContentDataW(struct GetContentDataInfo *Info)
{
	if (!Info)
		return FALSE;
	LPCWSTR FilePath = Info->FilePath;
	wchar_t** CustomData = NULL;

	for (size_t i = 0; i < Info->Count; i++)
	{
		if (!fsf.LStricmp(Info->Names[i], L"diz")
			|| !fsf.LStricmp(Info->Names[i], L"C0"))
		{
			CustomData = (wchar_t**)(Info->Values + i);
		}
	}

	if (!FilePath || !CustomData)
		return FALSE;
	
	const wchar_t* pszSlash = wcsrchr(FilePath, L'\\');
	if (!pszSlash || pszSlash <= FilePath) return FALSE;
	if (pszSlash[1] == 0) return FALSE; // Если хотят диз именно для папки - то нужно без слеша
	string  strPath(FilePath, pszSlash-FilePath);
	
	// оптимизацией чтения диз-файла занимается сам diz
	if (diz.Read(strPath) == 0)
	{
		// Если диз пустой - сразу выходим
		return FALSE;
	}

	
	const wchar_t* pszDiz = diz.GetDizTextAddr(pszSlash+1, L"", 0/*???*/);
	//if (!pszDiz || pszDiz[0] == 0) -- ConvertNameToShort занимает очень много времени
	//{
	//	string strShort;
	//	ConvertNameToShort(FilePath, strShort);
	//	pszDiz = diz.GetDizTextAddr(pszSlash+1, strShort, 0/*???*/);
	//}
	if (!pszDiz || pszDiz[0] == 0)
	{
		return FALSE;
	}
	
	size_t nLen = wcslen(pszDiz)+1;
	*CustomData = (wchar_t*)malloc(nLen*2);
	wcscpy(*CustomData, pszDiz);
	// Заменить некоторые символы
	wchar_t* pszTab = wcspbrk(*CustomData, L"\t");
	while (pszTab)
	{
		*pszTab = L' ';
		pszTab = wcspbrk(pszTab+1, L"\t");
	}

	return TRUE;
}
示例#2
0
intptr_t WINAPI GetContentFieldsW(const struct GetContentFieldsInfo *Info)
{
	for (size_t i = 0; i < Info->Count; i++)
	{
		if (!fsf.LStricmp(Info->Names[i], L"diz")
			|| !fsf.LStricmp(Info->Names[i], L"C0"))
			return 1;
	}
	return 0;
}
示例#3
0
void WINAPI FreeContentDataW(const struct GetContentDataInfo *Info)
{
	for (size_t i = 0; i < Info->Count; i++)
	{
		if (!fsf.LStricmp(Info->Names[i], L"diz")
			|| !fsf.LStricmp(Info->Names[i], L"C0"))
		{
			if (Info->Values[i])
			{
				wchar_t* ptr = (wchar_t*)Info->Values[i];
				if (ptr) free(ptr);
			}
		}
	}
}
示例#4
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;
}
示例#5
0
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;
}
示例#6
0
HANDLE	WINAPI	EXP_NAME(OpenPlugin)(int OpenFrom, INT_PTR Item) {
//	Options.Read();

	AutoUTF	cline;
	if (OpenFrom == OPEN_PLUGINSMENU) {
		FarPnl	pi(PANEL_ACTIVE);
		if (pi.IsOK()) {
			AutoUTF	buf(MAX_PATH_LEN, L'\0');
			fsf.GetCurrentDirectory(buf.capacity(), (PWSTR)buf.c_str());
			if (!buf.empty())
				::PathAddBackslash((PWSTR)buf.c_str());

			PluginPanelItem &PPI = pi[pi.CurrentItem()];
			buf += PPI.FindData.lpwszFileName;
			cline = buf;
		}
	} else if (OpenFrom == OPEN_COMMANDLINE) {
		cline = (PCWSTR)Item;
	}
	FarList	users;
	if (InitUsers(users)) {
		enum {
			HEIGHT = 14,
			WIDTH = 48,
		};
		InitDialogItemF	Items[] = {
			{DI_DOUBLEBOX, 3, 1, WIDTH - 4, HEIGHT - 2, 0, (PCWSTR)DlgTitle},
			{DI_TEXT,      5, 2, 0,  0,  0, (PCWSTR)MUsername},
			{DI_COMBOBOX,  5, 3, 42, 0,  DIF_SELECTONENTRY, L""},
			{DI_TEXT,      5, 4, 0,  0,  0, (PCWSTR)MPasword},
			{DI_PSWEDIT,   5, 5, 42, 0,  0, L""},
			{DI_CHECKBOX , 5, 6, 42, 0,  0, (PCWSTR)MRestricted},
			{DI_TEXT,      0, 7, 0,  0,  DIF_SEPARATOR, L""},
			{DI_TEXT,      5, 8, 0,  0,  0, (PCWSTR)MCommandLine},
			{DI_EDIT,      5, 9, 42, 0,  DIF_HISTORY, cline.c_str()},
			{DI_TEXT,      0,  HEIGHT - 4, 0,  0,  DIF_SEPARATOR,   L""},
			{DI_BUTTON,    0,  HEIGHT - 3, 0,  0,  DIF_CENTERGROUP, (PCWSTR)txtBtnOk},
			{DI_BUTTON,    0,  HEIGHT - 3, 0,  0,  DIF_CENTERGROUP, (PCWSTR)txtBtnCancel},
		};
		size_t	size = sizeofa(Items);
		FarDialogItem FarItems[size];
		InitDialogItemsF(Items, FarItems, size);
		FarItems[size - 2].DefaultButton = 1;
		FarItems[2].ListItems = &users;
		FarItems[8].History = L"runas.comline";

		FarDlg hDlg;
		if (hDlg.Init(psi.ModuleNumber, -1, -1, WIDTH, HEIGHT, L"Contents", FarItems, size)) {
			HRESULT	err = NO_ERROR;
			while (true) {
				int		ret = hDlg.Run();
				if (ret > 0 && Items[ret].Data == (PCWSTR)txtBtnOk) {
					AutoUTF	cmd(hDlg.Str(8));
					if (hDlg.Check(5)) {
						err = ExecRestricted(cmd.c_str());
					} else {
						AutoUTF	user(hDlg.Str(2));
						AutoUTF	pass(hDlg.Str(4));
						err = ExecAsUser(cmd.c_str(), user.c_str(), pass.c_str());
					}
					if (err == NO_ERROR) {
						break;
					} else {
						PCWSTR Msg[] = {GetMsg(MError), cmd.c_str(), L"", GetMsg(txtBtnOk), };
						::SetLastError(err);
						psi.Message(psi.ModuleNumber, FMSG_WARNING | FMSG_ERRORTYPE,
									L"Contents", Msg, sizeofa(Msg), 1);
					}
				} else {
					break;
				}
			}
		}
		FreeUsers(users);
	}
	return	INVALID_HANDLE_VALUE;
}