2015-01-22 20:44:54 +03:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015 Daniel Molkentin <danimo@owncloud.com>. All rights reserved.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU Lesser General Public License as published by the Free
|
|
|
|
* Software Foundation; either version 2.1 of the License, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
|
|
|
* details.
|
|
|
|
*/
|
|
|
|
|
2015-01-29 14:59:20 +03:00
|
|
|
#include "stdafx.h"
|
2015-01-22 20:44:54 +03:00
|
|
|
|
|
|
|
#include "OCClientInterface.h"
|
|
|
|
|
|
|
|
#include "CommunicationSocket.h"
|
|
|
|
#include "StringUtil.h"
|
|
|
|
|
|
|
|
#include <shlobj.h>
|
|
|
|
|
|
|
|
#include <Strsafe.h>
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
|
|
|
#include <iterator>
|
|
|
|
#include <unordered_set>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
#define PIPE_TIMEOUT 5*1000 //ms
|
|
|
|
#define SOCK_BUFFER 4096
|
|
|
|
|
2015-02-13 18:00:22 +03:00
|
|
|
OCClientInterface::ContextMenuInfo OCClientInterface::FetchInfo()
|
2015-01-22 20:44:54 +03:00
|
|
|
{
|
|
|
|
auto pipename = std::wstring(L"\\\\.\\pipe\\");
|
|
|
|
pipename += L"ownCloud";
|
|
|
|
|
|
|
|
CommunicationSocket socket;
|
|
|
|
if (!WaitNamedPipe(pipename.data(), PIPE_TIMEOUT)) {
|
2015-02-13 18:00:22 +03:00
|
|
|
return {};
|
2015-01-22 20:44:54 +03:00
|
|
|
}
|
|
|
|
if (!socket.Connect(pipename)) {
|
2015-02-13 18:00:22 +03:00
|
|
|
return {};
|
2015-01-22 20:44:54 +03:00
|
|
|
}
|
2015-02-13 18:00:22 +03:00
|
|
|
socket.SendMsg(L"SHARE_MENU_TITLE\n");
|
|
|
|
|
|
|
|
ContextMenuInfo info;
|
2015-01-22 20:44:54 +03:00
|
|
|
std::wstring response;
|
2015-01-23 17:43:03 +03:00
|
|
|
Sleep(50);
|
|
|
|
while (socket.ReadLine(&response)) {
|
2015-01-22 20:44:54 +03:00
|
|
|
if (StringUtil::begins_with(response, wstring(L"REGISTER_PATH:"))) {
|
|
|
|
wstring responsePath = response.substr(14); // length of REGISTER_PATH
|
2015-02-13 18:00:22 +03:00
|
|
|
info.watchedDirectories.push_back(responsePath);
|
|
|
|
}
|
|
|
|
else if (StringUtil::begins_with(response, wstring(L"SHARE_MENU_TITLE:"))) {
|
|
|
|
info.shareMenuTitle = response.substr(17); // length of SHARE_MENU_TITLE:
|
2015-01-22 20:44:54 +03:00
|
|
|
}
|
|
|
|
}
|
2015-02-13 18:00:22 +03:00
|
|
|
return info;
|
2015-01-22 20:44:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void OCClientInterface::ShareObject(const std::wstring &path)
|
|
|
|
{
|
|
|
|
auto pipename = std::wstring(L"\\\\.\\pipe\\");
|
|
|
|
pipename += L"ownCloud";
|
|
|
|
|
|
|
|
CommunicationSocket socket;
|
|
|
|
if (!WaitNamedPipe(pipename.data(), PIPE_TIMEOUT)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!socket.Connect(pipename)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wchar_t msg[SOCK_BUFFER] = { 0 };
|
|
|
|
if (SUCCEEDED(StringCchPrintf(msg, SOCK_BUFFER, L"SHARE:%s\n", path.c_str())))
|
|
|
|
{
|
|
|
|
socket.SendMsg(msg);
|
|
|
|
}
|
|
|
|
}
|