Exemplo n.º 1
0
int		Panel::ProcessEvent(int Event, void *Param) {
	if (Event == FE_COMMAND) {
		PCWSTR cmd((PCWSTR)Param);
		if (cmd) {
			int		argc = 0;
			PWSTR	*argv = ::CommandLineToArgvW(cmd, &argc);
			if (argc > 1 && Eqi(argv[0], L"cd")) {
				try {
					psi.Control(this, FCTL_REDRAWPANEL, 0, nullptr);
					ConnectingToServer(argv[1]);
					winstd::shared_ptr<RemoteConnection> tmp(new RemoteConnection(argv[1]));
					WinTS tts(tmp->host());
					m_ts = tts;
					m_conn.swap(tmp);
					psi.Control(this, FCTL_SETCMDLINE, 0, (LONG_PTR)EMPTY_STR);
					psi.Control(this, FCTL_UPDATEPANEL, 0, nullptr);
					psi.Control(this, FCTL_REDRAWPANEL, 0, nullptr);
				} catch (WinError &e) {
					if (e.code() == ERROR_ACCESS_DENIED) {
						AccesDeniedErrorMessage();
					} else {
						farebox_code(e.code(), e.where().c_str());
					}
				}
			}
			::LocalFree(argv);
			return true;
		}
	}
	return	false;
}
Exemplo n.º 2
0
int		Panel::ProcessKey(int Key, unsigned int ControlState) {
	switch (Key) {
		case VK_F3:
			if (ControlState == PKF_SHIFT) {
				return	true;
			}
			break;
		case VK_F4:
			switch (ControlState) {
				case 0:
					DlgShutdown();
					return true;
				case PKF_SHIFT:
					return	true;
			}
			break;
		case VK_F6:
			switch (ControlState) {
				case 0:
					if (DlgConnection()) {
						psi.Control(this, FCTL_UPDATEPANEL, 0, nullptr);
						psi.Control(this, FCTL_REDRAWPANEL, 0, nullptr);
					}
					return	true;
				case PKF_SHIFT:
					try {
						m_conn->Open(nullptr);
					} catch (WinError &e) {
						farebox_code(e.code(), e.where().c_str());
					}
					psi.Control(this, FCTL_UPDATEPANEL, 0, nullptr);
					psi.Control(this, FCTL_REDRAWPANEL, 0, nullptr);
					return	true;
			}
			break;
		case VK_F7:
			switch (ControlState) {
				case 0:
					AutoUTF cmd = L"mstsc.exe";
					if (!Empty(m_conn->host())) {
						cmd += L" /v:";
						cmd += m_conn->host();
					}
					ExecCMD(cmd);
					return true;
			}
			break;
	}
	if ((ControlState == 0 && (Key == VK_F3 || Key == VK_F5 || Key == VK_F8)) ||
		(ControlState == PKF_SHIFT && (Key == VK_F7 || Key == VK_F8))) {
		FarPnl pInfo(this, FCTL_GETPANELINFO);
		WinTS::iterator m_cur;
		if (pInfo.ItemsNumber() && pInfo.CurrentItem() &&
			(m_cur = std::find(m_ts.begin(), m_ts.end(), pInfo[pInfo.CurrentItem()].FindData.nFileSize)) != m_ts.end()) {
			if (ControlState == 0 && Key == VK_F3) {
				AutoUTF	tmp(TempFile(TempDir()));
				HANDLE	hfile = ::CreateFileW(tmp.c_str(), GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
				if (hfile != INVALID_HANDLE_VALUE) {
					FileWrite(hfile, Info(m_cur));
					::CloseHandle(hfile);
					psi.Viewer(tmp.c_str(), nullptr, 0, 0, -1, -1,
							   VF_DELETEONLYFILEONCLOSE | VF_ENABLE_F6 | VF_DISABLEHISTORY |
							   VF_NONMODAL | VF_IMMEDIATERETURN, CP_AUTODETECT);
				}
				return	true;
			} else if (ControlState == 0 && Key == VK_F5) {
				DlgMessage(m_cur->id());
			} else 	if (ControlState == PKF_SHIFT && Key == VK_F7) {
				WinTSession::ConnectLocal(m_cur->id());
			} else 	if (ControlState == 0 && Key == VK_F8) {
				if (farquestion(GetMsg(txtAreYouSure), GetMsg(txtDisconnectSession)))
					WinTSession::Disconnect(m_cur->id(), m_conn->host());
			} else if (ControlState == PKF_SHIFT && Key == VK_F8) {
				if (farquestion(GetMsg(txtAreYouSure), GetMsg(txtLogoffSession)))
					WinTSession::LogOff(m_cur->id(), m_conn->host());
			}
			psi.Control(this, FCTL_UPDATEPANEL, 0, nullptr);
			psi.Control(this, FCTL_REDRAWPANEL, 0, nullptr);
			return	true;
		}
	}
	return	false;
}