created a new thread to write file to drop directory on client side
This commit is contained in:
parent
8301d50ab7
commit
6e50945bf9
|
@ -68,7 +68,8 @@ CClient::CClient(IEventQueue* events,
|
||||||
m_events(events),
|
m_events(events),
|
||||||
m_cryptoStream(NULL),
|
m_cryptoStream(NULL),
|
||||||
m_crypto(crypto),
|
m_crypto(crypto),
|
||||||
m_sendFileThread(NULL)
|
m_sendFileThread(NULL),
|
||||||
|
m_writeToDropDirThread(NULL)
|
||||||
{
|
{
|
||||||
assert(m_socketFactory != NULL);
|
assert(m_socketFactory != NULL);
|
||||||
assert(m_screen != NULL);
|
assert(m_screen != NULL);
|
||||||
|
@ -722,26 +723,40 @@ void
|
||||||
CClient::onFileRecieveCompleted()
|
CClient::onFileRecieveCompleted()
|
||||||
{
|
{
|
||||||
if (isReceivedFileSizeValid()) {
|
if (isReceivedFileSizeValid()) {
|
||||||
m_fileTransferDes = m_screen->getDropTarget();
|
m_writeToDropDirThread = new CThread(
|
||||||
if (!m_fileTransferDes.empty()) {
|
new TMethodJob<CClient>(
|
||||||
std::fstream file;
|
this, &CClient::writeToDropDirThread));
|
||||||
#ifdef SYSAPI_WIN32
|
}
|
||||||
m_fileTransferDes.append("\\");
|
}
|
||||||
#else
|
|
||||||
m_fileTransferDes.append("/");
|
|
||||||
#endif
|
|
||||||
m_fileTransferDes.append(m_dragFileList.at(0));
|
|
||||||
file.open(m_fileTransferDes.c_str(), std::ios::out | std::ios::binary);
|
|
||||||
if (!file.is_open()) {
|
|
||||||
// TODO: file open failed
|
|
||||||
}
|
|
||||||
|
|
||||||
file.write(m_receivedFileData.c_str(), m_receivedFileData.size());
|
|
||||||
file.close();
|
void
|
||||||
}
|
CClient::writeToDropDirThread(void*)
|
||||||
else {
|
{
|
||||||
LOG((CLOG_ERR "drop file failed: drop target is empty"));
|
while (m_screen->getFakeDraggingStarted()) {
|
||||||
|
ARCH->sleep(.1f);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_fileTransferDes = m_screen->getDropTarget();
|
||||||
|
if (!m_fileTransferDes.empty() && m_dragFileList.size() > 0) {
|
||||||
|
std::fstream file;
|
||||||
|
CString dropTarget = m_fileTransferDes;
|
||||||
|
#ifdef SYSAPI_WIN32
|
||||||
|
dropTarget.append("\\");
|
||||||
|
#else
|
||||||
|
dropTarget.append("/");
|
||||||
|
#endif
|
||||||
|
dropTarget.append(m_dragFileList.at(0));
|
||||||
|
file.open(dropTarget.c_str(), std::ios::out | std::ios::binary);
|
||||||
|
if (!file.is_open()) {
|
||||||
|
// TODO: file open failed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
file.write(m_receivedFileData.c_str(), m_receivedFileData.size());
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LOG((CLOG_ERR "drop file failed: drop target is empty"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -182,6 +182,7 @@ private:
|
||||||
void sendConnectionFailedEvent(const char* msg);
|
void sendConnectionFailedEvent(const char* msg);
|
||||||
void sendFileChunk(const void* data);
|
void sendFileChunk(const void* data);
|
||||||
void sendFileThread(void*);
|
void sendFileThread(void*);
|
||||||
|
void writeToDropDirThread(void*);
|
||||||
void setupConnecting();
|
void setupConnecting();
|
||||||
void setupConnection();
|
void setupConnection();
|
||||||
void setupScreen();
|
void setupScreen();
|
||||||
|
@ -234,6 +235,7 @@ private:
|
||||||
CDragFileList m_dragFileList;
|
CDragFileList m_dragFileList;
|
||||||
CString m_dragFileExt;
|
CString m_dragFileExt;
|
||||||
CThread* m_sendFileThread;
|
CThread* m_sendFileThread;
|
||||||
|
CThread* m_writeToDropDirThread;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -640,19 +640,17 @@ COSXScreen::getDropTargetThread(void*)
|
||||||
void
|
void
|
||||||
COSXScreen::fakeMouseMove(SInt32 x, SInt32 y)
|
COSXScreen::fakeMouseMove(SInt32 x, SInt32 y)
|
||||||
{
|
{
|
||||||
if (CApp::instance().argsBase().m_enableDragDrop) {
|
if (m_fakeDraggingStarted) {
|
||||||
if (m_fakeDraggingStarted) {
|
// HACK: for some reason the drag icon
|
||||||
// HACK: for some reason the drag icon
|
// does not follow the cursor unless a key
|
||||||
// does not follow the cursor unless a key
|
// is pressed (except esc key)
|
||||||
// is pressed (except esc key)
|
// TODO: fake this key down properly
|
||||||
// TODO: fake this key down properly
|
fakeKeyDown(kKeyControl_L, 8194, 29);
|
||||||
fakeKeyDown(kKeyControl_L, 8194, 29);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// index 0 means left mouse button
|
// index 0 means left mouse button
|
||||||
if (m_buttonState.test(0)) {
|
if (m_buttonState.test(0)) {
|
||||||
m_draggingStarted = true;
|
m_draggingStarted = true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// synthesize event
|
// synthesize event
|
||||||
|
@ -2086,13 +2084,15 @@ COSXScreen::CFStringRefToUTF8String(CFStringRef aString)
|
||||||
void
|
void
|
||||||
COSXScreen::fakeDraggingFiles(CString str)
|
COSXScreen::fakeDraggingFiles(CString str)
|
||||||
{
|
{
|
||||||
m_fakeDraggingStarted = true;
|
if (CApp::instance().argsBase().m_enableDragDrop) {
|
||||||
|
m_fakeDraggingStarted = true;
|
||||||
#if defined(MAC_OS_X_VERSION_10_7)
|
#if defined(MAC_OS_X_VERSION_10_7)
|
||||||
// TODO: use real file extension
|
// TODO: use real file extension
|
||||||
fakeDragging("txt", 3, m_xCursor, m_yCursor);
|
fakeDragging("txt", 3, m_xCursor, m_yCursor);
|
||||||
#else
|
#else
|
||||||
LOG((CLOG_WARN "drag drop not supported"));
|
LOG((CLOG_WARN "drag drop not supported"));
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CString&
|
CString&
|
||||||
|
|
|
@ -76,7 +76,7 @@ CServer::CServer(CConfig& config, CPrimaryClient* primaryClient, CScreen* screen
|
||||||
m_lockedToScreen(false),
|
m_lockedToScreen(false),
|
||||||
m_screen(screen),
|
m_screen(screen),
|
||||||
m_sendFileThread(NULL),
|
m_sendFileThread(NULL),
|
||||||
m_writeToDropDir(NULL)
|
m_writeToDropDirThread(NULL)
|
||||||
{
|
{
|
||||||
// must have a primary client and it must have a canonical name
|
// must have a primary client and it must have a canonical name
|
||||||
assert(m_primaryClient != NULL);
|
assert(m_primaryClient != NULL);
|
||||||
|
@ -1958,7 +1958,7 @@ void
|
||||||
CServer::onFileRecieveCompleted()
|
CServer::onFileRecieveCompleted()
|
||||||
{
|
{
|
||||||
if (isReceivedFileSizeValid()) {
|
if (isReceivedFileSizeValid()) {
|
||||||
m_writeToDropDir = new CThread(
|
m_writeToDropDirThread = new CThread(
|
||||||
new TMethodJob<CServer>(
|
new TMethodJob<CServer>(
|
||||||
this, &CServer::writeToDropDirThread));
|
this, &CServer::writeToDropDirThread));
|
||||||
}
|
}
|
||||||
|
|
|
@ -469,7 +469,7 @@ private:
|
||||||
CString m_fileTransferDes;
|
CString m_fileTransferDes;
|
||||||
CDragFileList m_dragFileList;
|
CDragFileList m_dragFileList;
|
||||||
CThread* m_sendFileThread;
|
CThread* m_sendFileThread;
|
||||||
CThread* m_writeToDropDir;
|
CThread* m_writeToDropDirThread;
|
||||||
CString m_dragFileExt;
|
CString m_dragFileExt;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue