]> source.dussan.org Git - tigervnc.git/commitdiff
Added routines for deleteDir method in FolderManager class.
authorDennis Syrovatsky <dennis@tightvnc.com>
Wed, 19 Oct 2005 10:05:51 +0000 (10:05 +0000)
committerDennis Syrovatsky <dennis@tightvnc.com>
Wed, 19 Oct 2005 10:05:51 +0000 (10:05 +0000)
Changed flag for folder identification.

git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@354 3789f03b-4d11-0410-bbf8-ca57d06f2519

rfb/FileInfo.cxx
rfb/fttypes.h
rfb_win32/FolderManager.cxx
rfb_win32/FolderManager.h

index 9168806e5f6b2dafaf6d4ab7d23aa19ea0a4e1e3..8d3429f895ca2d9933b430703a3f66281c14fe67 100644 (file)
@@ -35,8 +35,8 @@ CompareFileInfo(const void *F, const void *S)
        if (pF->info.flags == pS->info.flags) {
                return strcasecmp(pF->name, pS->name);
        } else {
-               if (pF->info.flags == FT_ATTR_FOLDER) return -1;
-               if (pS->info.flags == FT_ATTR_FOLDER)
+               if (pF->info.flags == FT_ATTR_DIR) return -1;
+               if (pS->info.flags == FT_ATTR_DIR)
                        return 1;
                else
                        return strcasecmp(pF->name, pS->name);
index 176e18fe9065d0710d67adc3eb8f0181dcd4b8a4..62fd89fbfe0c05076121e2839cab24d705b3d8dc 100644 (file)
@@ -32,7 +32,7 @@
 
 #define FT_ATTR_UNKNOWN                        0x00000000
 #define FT_ATTR_FILE                   0x00000001
-#define FT_ATTR_FOLDER                 0x00000002
+#define FT_ATTR_DIR                    0x00000002
 
 typedef struct tagSIZEDATAINFO
 {
index 7cba7b51bdce25cb4befbb25810205115ea93221..d554cbb0ca9d32c0cb9b467a3b75dbb6081bb7cd 100644 (file)
@@ -55,7 +55,59 @@ FolderManager::renameDir(char *pOldName, char *pNewName)
 bool 
 FolderManager::deleteDir(char *pFullPath)
 {
-  return false;
+  FileInfo fileInfo;
+  fileInfo.add(pFullPath, 0, 0, FT_ATTR_DIR);
+
+  unsigned int num = fileInfo.getNumEntries();
+  unsigned int last = num - 1;
+
+  while (num > 0) {
+    if (fileInfo.getFlagsAt(last) & FT_ATTR_DIR) {
+      if (RemoveDirectory(fileInfo.getNameAt(last)) == 0) {
+        if (GetLastError() == ERROR_DIR_NOT_EMPTY) {
+          if (!getFolderInfoWithPrefix(fileInfo.getNameAt(last), &fileInfo)) {
+            fileInfo.free();
+            return false;
+          }
+        }
+      } else {
+        fileInfo.deleteAt(last);
+      }
+    } else {
+      if (DeleteFile(fileInfo.getNameAt(last)) == 0) {
+        fileInfo.free();
+        return false;
+      } else {
+        fileInfo.deleteAt(last);
+      }
+    }
+
+    num = fileInfo.getNumEntries();
+    last = num - 1;
+  }
+
+  return true;
+}
+
+bool 
+FolderManager::getFolderInfoWithPrefix(char *pPrefix, FileInfo *pFileInfo)
+{
+  char prefix[FT_FILENAME_SIZE];
+  strcpy(prefix, pPrefix);
+
+  FileInfo tmpFileInfo;
+  if (!getFolderInfo(prefix, &tmpFileInfo, 0)) {
+    tmpFileInfo.free();
+    return false;
+  } else {
+    char buf[FT_FILENAME_SIZE];
+    for (unsigned int i = 0; i < tmpFileInfo.getNumEntries(); i++) {
+      sprintf(buf, "%s\\%s", prefix, tmpFileInfo.getNameAt(i));
+      pFileInfo->add(buf, tmpFileInfo.getSizeAt(i), tmpFileInfo.getDataAt(i), tmpFileInfo.getFlagsAt(i));
+    }
+  }
+  tmpFileInfo.free();
+  return true;
 }
     
 bool 
@@ -81,7 +133,7 @@ FolderManager::getFolderInfo(char *pPath, FileInfo *pFileInfo, unsigned int dirO
                                li.HighPart = FindFileData.ftLastWriteTime.dwHighDateTime;                                                      
                                li.QuadPart = (li.QuadPart - 116444736000000000) / 10000000;
                                if ((FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {       
-                                       pFileInfo->add(FindFileData.cFileName, 0, li.LowPart, FT_ATTR_FOLDER);
+                                       pFileInfo->add(FindFileData.cFileName, 0, li.LowPart, FT_ATTR_DIR);
                                } else {
                                        if (!dirOnly)
                                                pFileInfo->add(FindFileData.cFileName, FindFileData.nFileSizeLow, li.LowPart, FT_ATTR_FILE);
@@ -109,7 +161,7 @@ FolderManager::getDrivesInfo(FileInfo *pFileInfo)
                char *backslash = strrchr(drive, '\\');
                if (backslash != NULL)
                        *backslash = '\0';
-               pFileInfo->add(drive, 0, 0, FT_ATTR_FOLDER);
+               pFileInfo->add(drive, 0, 0, FT_ATTR_DIR);
                free(drive);
                i += strcspn(&szDrivesList[i], "\0") + 1;
        }
index 15aa238fa5a6fd6e3ac508e8366f4b8e3b4524b6..6f1839d0873f0c3adda1add7ccb176d4fc2b16dc 100644 (file)
@@ -42,6 +42,8 @@ namespace rfb {
       
       bool getFolderInfo(char *pPath, FileInfo *pFileInfo, unsigned int dirOnly);
       bool getDrivesInfo(FileInfo *pFI);
+    private:
+      bool getFolderInfoWithPrefix(char *pPrefix, FileInfo *pFileInfo);
     };
   }
 }