Changed flags for reading from "r" to "rb", for writing from "w" to "wb"
in the FileReader and FileWriter.
Added FileTransfer::procFLRUpload(...) method.
Now It's possible the upload files and folders.
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@423 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/vncviewer/FTDialog.cxx b/vncviewer/FTDialog.cxx
index 8acebd4..4045470 100644
--- a/vncviewer/FTDialog.cxx
+++ b/vncviewer/FTDialog.cxx
@@ -66,6 +66,8 @@
return true;
}
+ if (!initFTWndMsgs()) return false;
+
m_hwndFTDialog = CreateDialogParam(m_hInstance,
MAKEINTRESOURCE(IDD_FILETRANSFER_DLG),
hwndParent,
@@ -74,8 +76,6 @@
if (m_hwndFTDialog == NULL) return false;
- if (!initFTWndMsgs()) return false;
-
HWND hwndLocalList = GetDlgItem(m_hwndFTDialog, IDC_FTLOCALLIST);
HWND hwndRemoteList = GetDlgItem(m_hwndFTDialog, IDC_FTREMOTELIST);
@@ -169,9 +169,11 @@
FTDialog::FTDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
FTDialog *_this = (FTDialog *) GetWindowLong(hwnd, GWL_USERDATA);
+
switch (uMsg)
{
case WM_INITDIALOG:
+ _this = (FTDialog*)lParam;
SetWindowLong(hwnd, GWL_USERDATA, (LONG) lParam);
SetForegroundWindow(hwnd);
return TRUE;
@@ -278,14 +280,16 @@
return FALSE;
}
- if (uMsg == _this->m_msgCheckTransferQueue)
- _this->m_pFileTransfer->checkTransferQueue();
+ if (_this != NULL) {
+ if (uMsg == _this->m_msgCheckTransferQueue)
+ _this->m_pFileTransfer->checkTransferQueue();
- if (uMsg == _this->m_msgDownloadFilePortion)
- _this->m_pFileTransfer->downloadFilePortion();
-
- if (uMsg == _this->m_msgUploadFilePortion)
- _this->m_pFileTransfer->uploadFilePortion();
+ if (uMsg == _this->m_msgUploadFilePortion)
+ _this->m_pFileTransfer->uploadFilePortion();
+
+ if (uMsg == _this->m_msgDownloadFilePortion)
+ _this->m_pFileTransfer->downloadFilePortion();
+ }
return FALSE;
}
diff --git a/vncviewer/FTDialog.h b/vncviewer/FTDialog.h
index 82e7536..c8e9f0a 100644
--- a/vncviewer/FTDialog.h
+++ b/vncviewer/FTDialog.h
@@ -60,6 +60,9 @@
void postUploadFilePortionMsg();
void postDownloadFilePortionMsg();
+ char *getLocalPath() { return m_szLocalPath; }
+ char *getRemotePath() { return m_szRemotePath; }
+
FTProgress *m_pProgress;
private:
diff --git a/vncviewer/FileTransfer.cxx b/vncviewer/FileTransfer.cxx
index 0a3009a..fe08dd8 100644
--- a/vncviewer/FileTransfer.cxx
+++ b/vncviewer/FileTransfer.cxx
@@ -68,6 +68,7 @@
if (!m_bInitialized) return false;
m_bFTDlgShown = m_pFTDialog->createFTDialog(hwndParent);
+
return m_bFTDlgShown;
}
@@ -161,8 +162,8 @@
if (flag0 & FT_ATTR_COPY_UPLOAD) {
if (flag0 & FT_ATTR_FILE) {
- uploadFile();
- return;
+ uploadFile();
+ return;
}
if (flag0 & FT_ATTR_DIR) {
char *pFullPath = m_TransferQueue.getFullRemPathAt(0);
@@ -172,7 +173,7 @@
char *pPath = m_TransferQueue.getRemPathAt(0);
m_TransferQueue.setFlagsAt(0, (flag0 | FT_ATTR_FLR_UPLOAD_CHECK));
m_queueFileListRqst.add(pPath, 0, 0, FT_FLR_DEST_UPLOAD);
- m_pWriter->writeFileListRqst(strlen(pPath), pPath, 0);
+ m_pWriter->writeFileListRqst(strlen(pPath), pPath, false);
return;
}
} else {
@@ -191,6 +192,13 @@
bool
FileTransfer::uploadFile()
{
+ if (m_TransferQueue.getFlagsAt(0) & FT_ATTR_FILE) {
+ if (m_fileReader.create(m_TransferQueue.getFullLocPathAt(0))) {
+ m_pWriter->writeFileUploadRqst(strlen(m_TransferQueue.getFullRemPathAt(0)),
+ m_TransferQueue.getFullRemPathAt(0), 0);
+ uploadFilePortion();
+ }
+ }
return false;
}
@@ -203,7 +211,25 @@
void
FileTransfer::uploadFilePortion()
{
-
+ if (m_fileReader.isCreated()) {
+ char buf[FT_MAX_SENDING_SIZE];
+ unsigned int bytesRead = 0;
+ if (m_fileReader.read((void *)buf, FT_MAX_SENDING_SIZE, &bytesRead)) {
+ if (bytesRead == 0) {
+ m_pWriter->writeFileUploadData(m_TransferQueue.getDataAt(0));
+ m_fileReader.close();
+ m_TransferQueue.deleteAt(0);
+ m_pFTDialog->postCheckTransferQueueMsg();
+ } else {
+ m_pWriter->writeFileUploadData(bytesRead, (char *)buf);
+ m_pFTDialog->postUploadFilePortionMsg();
+ }
+ } else {
+ m_fileReader.close();
+ m_TransferQueue.deleteAt(0);
+ m_pFTDialog->postCheckTransferQueueMsg();
+ }
+ }
}
void
@@ -301,7 +327,36 @@
bool
FileTransfer::procFLRUpload(FileInfo *pFI)
{
- return false;
+ unsigned int flags = m_TransferQueue.getFlagsAt(0);
+ if (flags & FT_ATTR_FLR_UPLOAD_CHECK) {
+ int num = isExistName(pFI, m_TransferQueue.getRemNameAt(0));
+ if (num >= 0) {
+ if ((m_bFTDlgShown) && (strcmp(m_TransferQueue.getRemPathAt(0), m_pFTDialog->getRemotePath()) == 0)) {
+ m_pFTDialog->addRemoteLVItems(pFI);
+ }
+ } else {
+ if (flags & FT_ATTR_DIR) {
+ m_TransferQueue.deleteAt(0);
+ if (m_bFTDlgShown) m_pFTDialog->setStatusText("Create Remote Folder Failed.");
+ }
+ }
+ }
+ FolderManager fm;
+ FileInfo fi;
+ flags = m_TransferQueue.getFlagsAt(0);
+ if (flags & FT_ATTR_FILE) {
+ uploadFile();
+ return true;
+ } else {
+ if (fm.getDirInfo(m_TransferQueue.getFullLocPathAt(0), &fi, 0)) {
+ m_TransferQueue.add(m_TransferQueue.getFullLocPathAt(0),
+ m_TransferQueue.getFullRemPathAt(0),
+ &fi, FT_ATTR_COPY_UPLOAD);
+ }
+ }
+ m_TransferQueue.deleteAt(0);
+ m_pFTDialog->postCheckTransferQueueMsg();
+ return true;
}
bool
@@ -328,4 +383,15 @@
m_queueFileListRqst.add(pPath, 0, 0, dest);
m_pWriter->writeFileListRqst(strlen(pPath), pPath, bDirOnly);
-}
\ No newline at end of file
+}
+
+int
+FileTransfer::isExistName(FileInfo *pFI, char *pName)
+{
+ for (int i = 0; i < pFI->getNumEntries(); i++) {
+ if (strcmp(pFI->getNameAt(i), pName) == 0) {
+ return i;
+ }
+ }
+ return -1;
+}
diff --git a/vncviewer/FileTransfer.h b/vncviewer/FileTransfer.h
index 3a56f3f..dcc78c7 100644
--- a/vncviewer/FileTransfer.h
+++ b/vncviewer/FileTransfer.h
@@ -78,6 +78,8 @@
bool resizeSending();
bool uploadFile();
bool downloadFile();
+
+ int isExistName(FileInfo *pFI, char *pName);
bool procFileListDataMsg();
bool procFileDownloadDataMsg();