Merge pull request #972 from albertony/drop_dir

Configurable drop target directory on windows
This commit is contained in:
Povilas Kanapickas 2020-12-10 22:00:53 +02:00 committed by GitHub
commit e032d14a48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 53 additions and 17 deletions

View File

@ -176,6 +176,9 @@ App::initApp(int argc, const char** argv)
if (argsBase().m_enableDragDrop) {
LOG((CLOG_INFO "drag and drop enabled"));
if (!argsBase().m_dropTarget.empty()) {
LOG((CLOG_INFO "drop target: %s", argsBase().m_dropTarget.c_str()));
}
}
// setup file logging after parsing args

View File

@ -167,7 +167,9 @@ private:
" --no-tray disable the system tray icon.\n" \
" --enable-drag-drop enable file drag & drop.\n" \
" --enable-crypto enable the crypto (ssl) plugin.\n" \
" --profile-dir <path> use named profile directory instead.\n"
" --profile-dir <path> use named profile directory instead.\n" \
" --drop-dir <path> use named drop target directory instead.\n"
#define HELP_COMMON_INFO_2 \
" -h, --help display this help and exit.\n" \
" --version display version information and exit.\n"

View File

@ -257,6 +257,9 @@ ArgParser::parseGenericArgs(int argc, const char* const* argv, int& i)
argsBase().m_enableDragDrop = true;
}
}
else if (isArg(i, argc, argv, NULL, "--drop-dir")) {
argsBase().m_dropTarget = argv[++i];
}
else if (isArg(i, argc, argv, NULL, "--enable-crypto")) {
argsBase().m_enableCrypto = true;
}

View File

@ -39,6 +39,7 @@ m_display(NULL),
m_disableTray(false),
m_enableIpc(false),
m_enableDragDrop(false),
m_dropTarget(""),
m_shouldExit(false),
m_barrierAddress(),
m_enableCrypto(false),

View File

@ -38,6 +38,7 @@ public:
bool m_disableTray;
bool m_enableIpc;
bool m_enableDragDrop;
String m_dropTarget;
#if SYSAPI_WIN32
bool m_debugServiceWait;
bool m_pauseOnExit;

View File

@ -235,6 +235,9 @@ barrier::Screen*
ClientApp::openClientScreen()
{
barrier::Screen* screen = createScreen();
if (!argsBase().m_dropTarget.empty()) {
screen->setDropTarget(argsBase().m_dropTarget);
}
screen->setEnableDragDrop(argsBase().m_enableDragDrop);
m_events->adoptHandler(m_events->forIScreen().error(),
screen->getEventTarget(),

View File

@ -43,7 +43,7 @@ DropHelper::writeToDir(const String& destination, DragFileList& fileList, String
file.write(data.c_str(), data.size());
file.close();
LOG((CLOG_DEBUG "%s is saved to %s", fileList.at(0).getFilename().c_str(), destination.c_str()));
LOG((CLOG_INFO "dropped file \"%s\" in \"%s\"", fileList.at(0).getFilename().c_str(), destination.c_str()));
fileList.clear();
}

View File

@ -197,6 +197,7 @@ public:
virtual void fakeDraggingFiles(DragFileList fileList) = 0;
virtual const String&
getDropTarget() const = 0;
virtual void setDropTarget(const String&) = 0;
protected:
//! Handle system event

View File

@ -101,6 +101,7 @@ public:
virtual void fakeDraggingFiles(DragFileList fileList) { throw std::runtime_error("fakeDraggingFiles not implemented"); }
virtual const String&
getDropTarget() const { throw std::runtime_error("getDropTarget not implemented"); }
virtual void setDropTarget(const String&) { throw std::runtime_error("setDropTarget not implemented"); }
protected:
//! Update mouse buttons

View File

@ -466,6 +466,12 @@ Screen::getDropTarget() const
return m_screen->getDropTarget();
}
void
Screen::setDropTarget(const String& target)
{
return m_screen->setDropTarget(target);
}
void*
Screen::getEventTarget() const
{

View File

@ -290,6 +290,8 @@ public:
//! Get the drop target directory
const String& getDropTarget() const;
//! Set the drop target directory
void setDropTarget(const String&);
//@}

View File

@ -502,6 +502,9 @@ barrier::Screen*
ServerApp::openServerScreen()
{
barrier::Screen* screen = createScreen();
if (!argsBase().m_dropTarget.empty()) {
screen->setDropTarget(argsBase().m_dropTarget);
}
screen->setEnableDragDrop(argsBase().m_enableDragDrop);
m_events->adoptHandler(m_events->forIScreen().error(),
screen->getEventTarget(),

View File

@ -146,16 +146,6 @@ MSWindowsScreen::MSWindowsScreen(
LOG((CLOG_DEBUG "screen shape: %d,%d %dx%d %s", m_x, m_y, m_w, m_h, m_multimon ? "(multi-monitor)" : ""));
LOG((CLOG_DEBUG "window is 0x%08x", m_window));
// SHGetFolderPath is deprecated in vista, but use it for xp support.
char desktopPath[MAX_PATH];
if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_DESKTOP, NULL, 0, desktopPath))) {
m_desktopPath = std::string(desktopPath);
LOG((CLOG_DEBUG "using desktop for drop target: %s", m_desktopPath.c_str()));
}
else {
LOG((CLOG_ERR "failed to get desktop path, no drop target available, error=%d", GetLastError()));
}
OleInitialize(0);
m_dropWindow = createDropWindow(m_class, "DropWindow");
m_dropTarget = new MSWindowsDropTarget();
@ -1888,6 +1878,7 @@ std::string& MSWindowsScreen::getDraggingFilename()
SWP_SHOWWINDOW);
// TODO: fake these keys properly
ARCH->sleep(.05f); // A tiny sleep here makes the DragEnter event on m_dropWindow trigger much more consistently
fakeKeyDown(kKeyEscape, 8192, 1);
fakeKeyUp(1);
fakeMouseButton(kButtonLeft, false);
@ -1909,21 +1900,39 @@ std::string& MSWindowsScreen::getDraggingFilename()
m_draggingFilename = filename;
}
else {
LOG((CLOG_DEBUG "drag file name is invalid: %s", filename.c_str()));
LOG((CLOG_ERR "drag file name is invalid: %s", filename.c_str()));
}
}
if (m_draggingFilename.empty()) {
LOG((CLOG_DEBUG "failed to get drag file name from OLE"));
LOG((CLOG_ERR "failed to get drag file name from OLE"));
}
}
return m_draggingFilename;
}
const std::string& MSWindowsScreen::getDropTarget() const
const std::string&
MSWindowsScreen::getDropTarget() const
{
return m_desktopPath;
if (m_dropTargetPath.empty()) {
// SHGetFolderPath is deprecated in vista, but use it for xp support.
char desktopPath[MAX_PATH];
if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_DESKTOP, NULL, 0, desktopPath))) {
m_dropTargetPath = std::string(desktopPath);
LOG((CLOG_INFO "using desktop for drop target: %s", m_dropTargetPath.c_str()));
}
else {
LOG((CLOG_ERR "failed to get desktop path, no drop target available, error=%d", GetLastError()));
}
}
return m_dropTargetPath;
}
void
MSWindowsScreen::setDropTarget(const std::string& target)
{
m_dropTargetPath = target;
}
bool

View File

@ -120,6 +120,7 @@ public:
virtual void fakeDraggingFiles(DragFileList fileList);
virtual std::string& getDraggingFilename();
virtual const std::string& getDropTarget() const;
virtual void setDropTarget(const std::string&);
protected:
// IPlatformScreen overrides
@ -332,7 +333,7 @@ private:
IEventQueue* m_events;
std::string m_desktopPath;
mutable std::string m_dropTargetPath;
MSWindowsDropTarget*
m_dropTarget;