]> source.dussan.org Git - tigervnc.git/commitdiff
Changed flags for reading from "r" to "rb", for writing from "w" to "wb"
authorDennis Syrovatsky <dennis@tightvnc.com>
Wed, 30 Nov 2005 04:15:40 +0000 (04:15 +0000)
committerDennis Syrovatsky <dennis@tightvnc.com>
Wed, 30 Nov 2005 04:15:40 +0000 (04:15 +0000)
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

rfb/FileManager.cxx
rfb/FileManager.h
rfb/FileReader.cxx
rfb/FileWriter.cxx
rfb/fttypes.h
vncviewer/FTDialog.cxx
vncviewer/FTDialog.h
vncviewer/FileTransfer.cxx
vncviewer/FileTransfer.h

index 9592152b9496b5f65e185e11c6dd9c407d515b5d..1bd3ab66da7433e8a38f7facb31ebc917ea9f867 100644 (file)
@@ -65,3 +65,9 @@ FileManager::close()
     return true;
   }
 }
+
+bool 
+FileManager::isCreated()
+{
+  if (m_pFile != NULL) return true; else return false;
+}
\ No newline at end of file
index 609f2818f85d49c5dcf25bc1a51e608a072a0641..a673f4d7624e65016b6337ec73805eee1e995802 100644 (file)
@@ -35,6 +35,8 @@ namespace rfb {
     bool create(char *pFilename);
     bool close();
     
+    bool isCreated();
+
   protected:
     FILE *m_pFile;
     char m_szMode[4];
index 5b533ac1c83a154a0025455876ac5b389a91e203..13c677fd87cbefa5a159326f025e6e49d680c434 100644 (file)
@@ -27,7 +27,7 @@ using namespace rfb;
 
 FileReader::FileReader()
 {
-  strcpy(m_szMode, "r");
+  strcpy(m_szMode, "rb");
 }
 
 bool 
@@ -35,15 +35,9 @@ FileReader::read(void *pBuf, unsigned int count, unsigned int *pBytesRead)
 {
   if (m_pFile == NULL) return false;
 
-  unsigned int bytesRead = fread(pBuf, 1, count, m_pFile);
-
+  *pBytesRead = fread(pBuf, 1, count, m_pFile);
+  
   if (ferror(m_pFile)) return false;
-
-  if (feof(m_pFile)) {
-    *pBytesRead = 0;
-  } else {
-    *pBytesRead = bytesRead;
-  }
-
   return true;
 }
index 6503cc9c88ca7213e45646d4cbf4696acc1d6645..9d8c4a542954dfaa7bdd7b2f088d3eefbc85cb3a 100644 (file)
@@ -27,7 +27,7 @@ using namespace rfb;
 
 FileWriter::FileWriter()
 {
-  strcpy(m_szMode, "w");
+  strcpy(m_szMode, "wb");
 }
 
 bool 
index 5b08fd01ea1fba9dad3aaca4bb48b763c438992a..1e9f601af2ebdcd3fd6043037f1dfa6784111254 100644 (file)
@@ -30,6 +30,8 @@
 #define FT_MAX_STATUS_STRINGS           255
 #define FT_MAX_LENGTH_STATUS_STRINGS 130
 
+#define FT_MAX_SENDING_SIZE 8192
+
 #define FT_ATTR_UNKNOWN                            0x00000000
 #define FT_ATTR_FILE                       0x00000001
 #define FT_ATTR_DIR                        0x00000002
index 8acebd402ce14c419655b29ac5d9064aa88413ee..404547014c5da86c28d1b26b37609b6cd9eff6c2 100644 (file)
@@ -66,6 +66,8 @@ FTDialog::createFTDialog(HWND hwndParent)
     return true;
   }
 
+  if (!initFTWndMsgs()) return false;
+
   m_hwndFTDialog = CreateDialogParam(m_hInstance, 
                                      MAKEINTRESOURCE(IDD_FILETRANSFER_DLG),
                                      hwndParent, 
@@ -74,8 +76,6 @@ FTDialog::createFTDialog(HWND hwndParent)
   
   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 @@ BOOL CALLBACK
 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 @@ FTDialog::FTDialogProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
       return FALSE;
   }
 
-  if (uMsg == _this->m_msgCheckTransferQueue)  
-    _this->m_pFileTransfer->checkTransferQueue();
-
-  if (uMsg == _this->m_msgDownloadFilePortion) 
-    _this->m_pFileTransfer->downloadFilePortion();
+  if (_this != NULL) {
+    if (uMsg == _this->m_msgCheckTransferQueue)
+      _this->m_pFileTransfer->checkTransferQueue();
 
-  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;
 }
index 82e7536776f7c054635c3ec74c60d228a08f9386..c8e9f0a83fe1d9b86ab105c385ddcbe26a14c5de 100644 (file)
@@ -60,6 +60,9 @@ namespace rfb {
       void postUploadFilePortionMsg();
       void postDownloadFilePortionMsg();
 
+      char *getLocalPath() { return m_szLocalPath; }
+      char *getRemotePath() { return m_szRemotePath; }
+
       FTProgress *m_pProgress;
       
     private:
index 0a3009a98f11daed8843011df4000d95ff39811c..fe08dd8e6c84a34acc4e95377885e3ca5af951b1 100644 (file)
@@ -68,6 +68,7 @@ FileTransfer::show(HWND hwndParent)
   if (!m_bInitialized) return false;
 
   m_bFTDlgShown = m_pFTDialog->createFTDialog(hwndParent);
+
   return m_bFTDlgShown;
 }
 
@@ -161,8 +162,8 @@ FileTransfer::checkTransferQueue()
    
     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 @@ FileTransfer::checkTransferQueue()
         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 @@ FileTransfer::checkTransferQueue()
 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 @@ FileTransfer::downloadFile()
 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 @@ FileTransfer::procFLRBrowse(FileInfo *pFI)
 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 @@ FileTransfer::requestFileList(char *pPath, int dest, bool bDirOnly)
   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;
+}
index 3a56f3f1f7e50019dd1db8bd700a0fa7e415b93c..dcc78c73c6155ebc5cc91881378b372bf050fc65 100644 (file)
@@ -78,6 +78,8 @@ namespace rfb {
       bool resizeSending();
       bool uploadFile();
       bool downloadFile();
+
+      int isExistName(FileInfo *pFI, char *pName);
       
       bool procFileListDataMsg();
       bool procFileDownloadDataMsg();