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