Пример #1
0
        // handler for the key down in the virtual filesystem view
        // it now handles CTRL+V and CANC
        private void Vfs_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Control && e.KeyCode == Keys.V && Clipboard.ContainsFileDropList())
            {
                FolderTreeNode parentNode = (FolderTreeNode)fsFolderTree.SelectedNode;
                if (parentNode == null)
                {
                    MessageBox.Show("Please select a folder to add files into");
                    return;
                }
                if (parentNode.deleted)
                {
                    MessageBox.Show("Folder was deleted");
                    return;
                }

                StringCollection paths = Clipboard.GetFileDropList();
                foreach (String path in paths)
                {
                    AddFileOrFolderRecursive(parentNode, path);
                }
            }
            else if (e.KeyCode == Keys.Delete)
            {
                OnRemoveBtnClick(fsRemoveBtn, null);
            }
        }
Пример #2
0
        private void Populate()
        {
            fsFolderTree.Nodes.Clear();//
            FolderTreeNode folderTree = fileSystemEditor.getFileTree();

            AddItems(fsFolderTree.Nodes, folderTree);
        }
Пример #3
0
        private void OnAddBtnClick(object sender, EventArgs e)
        {
            FolderTreeNode parentNode = (FolderTreeNode)fsFolderTree.SelectedNode;

            if (parentNode == null)
            {
                MessageBox.Show("Please select a folder to add files into");
                return;
            }
            if (parentNode.deleted)
            {
                MessageBox.Show("Folder was deleted");
                return;
            }

            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter      = "All file types|*.*";
            openFileDialog.Multiselect = true;
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                foreach (String srcFileName in openFileDialog.FileNames)
                {
                    AddFileOrFolderRecursive(parentNode, srcFileName);
                }
            }
        }
Пример #4
0
        // handler for the add dir button
        private void OnAddDirBtnClick(object sender, EventArgs e)
        {
            FolderTreeNode parentNode = (FolderTreeNode)fsFolderTree.SelectedNode;

            if (parentNode == null)
            {
                MessageBox.Show("Please select a folder to add to");
                return;
            }
            if (parentNode.deleted)
            {
                MessageBox.Show("Folder was deleted");
                return;
            }

            String selectedFolder            = "";
            FolderBrowserDialog selectFolder = new FolderBrowserDialog();

            selectFolder.ShowNewFolderButton = false;

            if (selectFolder.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            selectedFolder = selectFolder.SelectedPath;

            AddFileOrFolderRecursive(parentNode, selectedFolder);
        }
Пример #5
0
        public void RefreshFolderNodeRecursively(FolderTreeNode node, int iteration)
        {
            FolderTreeNode curNode = node;

            if (iteration == 0)
            {
                VirtFsNode virtFsNode = curNode.virtFsNode;         // Avoids CS1690
                curNode.sandboxFlags = virtPackage.GetFileSandbox(virtFsNode.FileName, false);
                treeHelper.SetFolderNodeImage(curNode, curNode.deleted, (virtFsNode.FileFlags & VIRT_FILE_FLAGS.DELETED) != 0, curNode.sandboxFlags);
                if (curNode.Nodes.Count > 0)
                {
                    RefreshFolderNodeRecursively((FolderTreeNode)curNode.Nodes[0], iteration + 1);
                }
            }
            else
            {
                while (curNode != null)
                {
                    VirtFsNode virtFsNode = curNode.virtFsNode;     // Avoids CS1690
                    curNode.sandboxFlags = virtPackage.GetFileSandbox(virtFsNode.FileName, false);
                    treeHelper.SetFolderNodeImage(curNode, curNode.deleted, (virtFsNode.FileFlags & VIRT_FILE_FLAGS.DELETED) != 0, curNode.sandboxFlags);
                    if (curNode.Nodes.Count > 0)
                    {
                        RefreshFolderNodeRecursively((FolderTreeNode)curNode.Nodes[0], iteration + 1);
                    }
                    curNode = (FolderTreeNode)curNode.NextNode;
                }
            }
        }
Пример #6
0
        public void OnPackageOpen()
        {
            List <VirtFsNode> virtFsNodes = new List <VirtFsNode>();

            virtPackage.EnumFiles(ref virtFsNodes);
            fsFolderTree.Nodes.Clear();

            // Add first "FileSystem" root node"
            FolderTreeNode newNode = new FolderTreeNode();

            newNode.Text       = "FileSystem";
            newNode.virtFsNode = new VirtFsNode();
            treeHelper.SetFolderNodeImage(newNode,
                                          false, false, virtPackage.GetFileSandbox("", false));
            fsFolderTree.Nodes.Add(newNode);

            foreach (VirtFsNode virtFsNode in virtFsNodes)
            {
                AddFileOrFolder(virtFsNode, "");
            }

            // %Temp Internet% has predefined "WriteCopy" attribute, set by Packager
            // Add it here just so that user can edit its Sandbox flags.

            /*VirtFsNode tempVirtFsNode = new VirtFsNode();
             * tempVirtFsNode.FileName = "%Temp Internet%";
             * tempVirtFsNode.FileFlags = 0;               // Folder, not file
             * AddFileOrFolder(tempVirtFsNode, "");*/

            fsFolderTree.Nodes[0].Expand();             // Expand the "FileSystem" node
            fsFolderTree.SelectedNode = fsFolderTree.Nodes[0];
            dirty = false;
        }
Пример #7
0
        internal void ShowProperties()
        {
            FileProperties fp = new FileProperties(virtPackage);

            if (fp.Open(getSelectedFiles()))
            {
                FolderTreeNode    node = (FolderTreeNode)fsFolderTree.SelectedNode;
                TreeViewEventArgs ev   = new TreeViewEventArgs(node);
                OnFolderTreeSelect(null, ev);
            }
        }
Пример #8
0
        private void OnSaveFileAsBtnClick(object sender, EventArgs e)
        {
            FolderTreeNode folderNode = (FolderTreeNode)fsFolderTree.SelectedNode;

            if (folderNode == null)
            {
                MessageBox.Show("Please select a file to save");
                return;
            }

            if (fileSaveTargetDir == null || !Directory.Exists(fileSaveTargetDir))
            {
                if (!string.IsNullOrEmpty(virtPackage.openedFile))
                {
                    fileSaveTargetDir = Path.GetDirectoryName(virtPackage.openedFile);
                }
                else
                {
                    fileSaveTargetDir = "";
                }
            }

            ListView.SelectedListViewItemCollection fileItems = fsFilesList.SelectedItems;
            if (fileItems.Count == 0)    // In this case, folderNode is always selected too
            {
                if (TreeHelper.InputFolderBrowserDialog("Select the destination path on your hard disk to save the files.", ref fileSaveTargetDir) != DialogResult.OK)
                {
                    return;
                }
                SaveFolderContent(folderNode, fileSaveTargetDir);
                //MessageBox.Show("Please select a file, not a folder");
                return;
            }

            if (TreeHelper.InputFolderBrowserDialog("Select the destination path on your hard disk to save the file.", ref fileSaveTargetDir) != DialogResult.OK)
            {
                return;
            }

            // Save files
            if (folderNode.childFiles.Count == 0)
            {
                return;     // Should never happen
            }
            List <FileData> files = getSelectedFiles();

            foreach (FileData item in files)
            {
                SaveFile(item, fileSaveTargetDir);
            }
        }
Пример #9
0
 private void AddItems(TreeNodeCollection fsFolderTree, FolderTreeNode folderTree)
 {
     foreach (FolderTreeNode folder in folderTree.Nodes)
     {
         if (!folder.deleted)
         {
             TreeNode folderNode = fsFolderTree.Add(folder.Text);
             folderNode.ImageIndex         = 0;
             folderNode.SelectedImageIndex = 0;
             AddItems(folderNode.Nodes, folder);
             ShowFiles(folderNode.Nodes, folder);
         }
     }
 }
Пример #10
0
 private void AddItems(TreeNodeCollection fsFolderTree, FolderTreeNode folderTree)
 {
   foreach(FolderTreeNode folder in folderTree.Nodes)
   {
     if (!folder.deleted)
     {
       TreeNode folderNode  = fsFolderTree.Add(folder.Text);
       folderNode.ImageIndex = 0;
       folderNode.SelectedImageIndex = 0;
       AddItems(folderNode.Nodes, folder);
       ShowFiles(folderNode.Nodes, folder);
     }
   }
 }
Пример #11
0
 private void ShowFiles(TreeNodeCollection treeNodeCollection, FolderTreeNode folder)
 {
   if (folder.childFiles != null)
   {
     foreach (FileData fd in folder.childFiles)
     {
       if (!fd.deleted)
       {
         TreeNode filenode = treeNodeCollection.Add(Path.GetFileName(fd.virtFsNode.FileName));
         filenode.ImageIndex = 3;
         filenode.SelectedImageIndex = 3;
       }
     }
   }
 }
Пример #12
0
 private void ShowFiles(TreeNodeCollection treeNodeCollection, FolderTreeNode folder)
 {
     if (folder.childFiles != null)
     {
         foreach (FileData fd in folder.childFiles)
         {
             if (!fd.deleted)
             {
                 TreeNode filenode = treeNodeCollection.Add(Path.GetFileName(fd.virtFsNode.FileName));
                 filenode.ImageIndex         = 6;
                 filenode.SelectedImageIndex = 6;
             }
         }
     }
 }
Пример #13
0
 private void SaveFolderContent(FolderTreeNode node, string fileSaveTargetDir)
 {
     if (node.childFiles != null)
     {
         foreach (FileData f in node.childFiles)
         {
             SaveFile(f, fileSaveTargetDir);
         }
     }
     foreach (FolderTreeNode f in node.Nodes)
     {
         String subFolder = fileSaveTargetDir + '\\' + f.Text;
         Directory.CreateDirectory(subFolder);
         SaveFolderContent(f, subFolder);
     }
 }
Пример #14
0
        private void OnFolderSandboxChange(object sender, EventArgs e)
        {
            FolderTreeNode node = (FolderTreeNode)fsFolderTree.SelectedNode;

            if (node == null)
            {
                return;
            }
            String fullName = treeHelper.GetFullNodeName(node);

            virtPackage.SetFileSandbox(fullName,
                                       treeHelper.ComboIndexToSandboxFlags(fsFolderInfoIsolationCombo.SelectedIndex), false);
            node.sandboxFlags = virtPackage.GetFileSandbox(fullName, false);
            RefreshFolderNodeRecursively(node, 0);
            dirty = true;
        }
Пример #15
0
        /*[DllImport("kernel32.dll")]
         * static extern bool FileTimeToLocalFileTime([In] ref System.Runtime.InteropServices.ComTypes.FILETIME lpFileTime, out System.Runtime.InteropServices.ComTypes.FILETIME lpLocalFileTime);
         * [DllImport("Kernel32.dll", SetLastError = true)]
         * private static extern long FileTimeToSystemTime(ref System.Runtime.InteropServices.ComTypes.FILETIME FileTime, ref SYSTEMTIME SystemTime);*/

        private List <FileData> getSelectedFiles()
        {
            FolderTreeNode currentfolder = (FolderTreeNode)fsFolderTree.SelectedNode;

            List <FileData> result = new List <FileData>();

            foreach (FileListViewItem file in fsFilesList.SelectedItems)
            {
                foreach (FileData fd in currentfolder.childFiles)
                {
                    if (Path.GetFileName(fd.virtFsNode.FileName).Equals(file.Text, StringComparison.CurrentCultureIgnoreCase))
                    {
                        result.Add(fd);
                    }
                }
            }
            return(result);
        }
Пример #16
0
        List <FileData> getAllFilesUnderNode(FolderTreeNode node)
        {
            List <FileData> files = new List <FileData>();

            FileData fileData = new FileData();

            fileData.virtFsNode          = new VirtFsNode();
            fileData.virtFsNode.FileName = treeHelper.GetFullNodeName(node) + "\\";
            if (fileData.virtFsNode.FileName != "\\")
            {
                files.Add(fileData);
            }

            if (node.childFiles != null)
            {
                files.AddRange(node.childFiles);
            }
            foreach (FolderTreeNode subnode in node.Nodes)
            {
                files.AddRange(getAllFilesUnderNode(subnode));
            }
            return(files);
        }
Пример #17
0
        public void OnFolderTreeSelect(object sender, TreeViewEventArgs e)
        {
            FolderTreeNode folderNode = (FolderTreeNode)e.Node;

            fsFolderInfoFullName.Text = "";
            fsFolderInfoIsolationCombo.SelectedIndex = -1;
            if (folderNode == null)
            {
                return;
            }
            fsFolderInfoIsolationCombo.Enabled = true;     //(folderNode != fsFolderTree.Nodes[0]);
            VirtFsNode virtFsNode = folderNode.virtFsNode; // Avoids CS1690

            // Fill info panel
            String fullName = treeHelper.GetFullNodeName(folderNode);

            fsFolderInfoFullName.Text = "[" + Win32Function.StrFormatByteSize64(virtFsNode.EndOfFile) + "] " + fullName;
            fsFolderInfoIsolationCombo.SelectedIndex = treeHelper.SandboxFlagsToComboIndex(
                virtPackage.GetFileSandbox(fullName, false));

            // Fill fsFilesList
            fsFilesList.Items.Clear();
            if (folderNode.childFiles != null)
            {
                for (int i = folderNode.childFiles.Count - 1; i >= 0; i--)
                {
                    FileData         childFile = folderNode.childFiles[i];
                    FileListViewItem newItem   = new FileListViewItem();
                    newItem.Text = Path.GetFileName(childFile.virtFsNode.FileName);
                    newItem.SubItems.Add(Win32Function.StrFormatByteSize64(childFile.virtFsNode.EndOfFile));

                    newItem.flags = (VIRT_FILE_FLAGS)childFile.virtFsNode.FileFlags;

                    if ((newItem.flags & VirtPackageAPI.VIRT_FILE_FLAGS.DEPLOY_UPON_PRELOAD) != 0)
                    {
                        newItem.ImageIndex = 7;
                    }
                    else
                    {
                        newItem.ImageIndex = 6;
                    }
                    //ListViewItem.ListViewSubItem x = new ListViewItem.ListViewSubItem();
                    //x.Text = ((VIRT_FILE_FLAGS)childFile.virtFsNode.FileFlags).ToString();
                    //newItem.SubItems.Add(x);
                    newItem.SubItems.Add(Path.GetExtension(newItem.Text));

                    newItem.fileSize = childFile.virtFsNode.EndOfFile;
                    if (childFile.addedFrom != "")
                    {
                        if (folderNode.deleted)
                        {
                            folderNode.childFiles.Remove(childFile);       // Added file in a Removed folder. Forbidden!!
                            continue;
                        }
                        else
                        {
                            newItem.ForeColor = Color.Green;               // Newly-added
                        }
                    }
                    else if (folderNode.ImageIndex == 5)                   // deleted
                    {
                        newItem.ForeColor = Color.Red;
                    }
                    else if (childFile.deleted)
                    {
                        newItem.ForeColor = Color.Red;
                    }
                    fsFilesList.Items.Add(newItem);
                }
            }
        }
Пример #18
0
        private FolderTreeNode AddFileOrFolder(VirtFsNode virtFsNode, String SourceFileName)
        {
            FolderTreeNode newNode = null;
            FolderTreeNode curParent;
            TreeNode node;
            bool bFound;

            curParent = null;
            String fileName = "FileSystem\\" + virtFsNode.FileName;
            String[] tokens = fileName.Split('\\');
            foreach (String curToken in tokens)
            {
                if (curParent == null)
                    node = fsFolderTree.Nodes[0]; // There's always a top-node, since we've added "FileSystem" node
                //(fsFolderTree.Nodes.Count > 0 ? fsFolderTree.Nodes[0] : null);   // Top-most node
                else
                    node = curParent.FirstNode;

                bFound = false;
                while (node != null)
                {
                    if (node.Text == curToken)
                    {
                        curParent = (FolderTreeNode)node;
                        bFound = true;
                        break;
                    }
                    node = node.NextNode;
                }
                if (bFound == false)
                {
                    if ((virtFsNode.FileFlags & VIRT_FILE_FLAGS.ISFILE) == 0)
                    {
                        // Adding Folder
                        newNode = new FolderTreeNode();
                        newNode.Text = Path.GetFileName(virtFsNode.FileName);
                        newNode.virtFsNode = virtFsNode;
                        newNode.sandboxFlags = virtPackage.GetFileSandbox(virtFsNode.FileName, false);
                        newNode.deleted = false;
                        newNode.addedEmpty = false;
                        treeHelper.SetFolderNodeImage(newNode, newNode.deleted, (virtFsNode.FileFlags & VIRT_FILE_FLAGS.DELETED) != 0, newNode.sandboxFlags);
                        //if (newNode.sandboxFlags == SANDBOXFLAGS_COPY_ON_WRITE) newNode.ImageIndex = 3;
                        if (curParent != null)
                            curParent.Nodes.Add(newNode);
                        else
                            fsFolderTree.Nodes.Add(newNode);
                        curParent = newNode;
                    }
                    else
                    {
                        // Adding File
                        if (curParent != null)
                        {
                            FileData childFile = new FileData();
                            childFile.virtFsNode = virtFsNode;
                            if (curParent.childFiles == null)
                                curParent.childFiles = new List<FileData>();
                            childFile.addedFrom = SourceFileName;
                            childFile.deleted = false;
                            curParent.childFiles.Add(childFile);
                        }
                    }
                    if (curParent != null)
                    {
                        FolderTreeNode upperParent = curParent;
                        while (upperParent != null)
                        {
            #pragma warning disable 1690
                            upperParent.virtFsNode.EndOfFile += virtFsNode.EndOfFile;   // CS1690 is OK
            #pragma warning restore 1690
                            upperParent = (FolderTreeNode)upperParent.Parent;
                        }
                    }
                }
            }
            dirty = true;
            return newNode;
        }
Пример #19
0
        private void AddFileOrFolder(VirtFsNode virtFsNode, String SourceFileName)
        {
            FolderTreeNode newNode;
            FolderTreeNode curParent;
            TreeNode       node;
            bool           bFound;

            curParent = null;
            String fileName = virtFsNode.FileName;

            String[] tokens = fileName.Split('\\');
            foreach (String curToken in tokens)
            {
                if (curParent == null)
                {
                    node = (FolderTreeNode)(fsFolderTree.Nodes.Count > 0 ? fsFolderTree.Nodes[0] : null);
                }
                else
                {
                    node = curParent.FirstNode;
                }

                bFound = false;
                while (node != null)
                {
                    if (node.Text == curToken)
                    {
                        curParent = (FolderTreeNode)node;
                        bFound    = true;
                        break;
                    }
                    node = node.NextNode;
                }
                if (bFound == false)
                {
                    // Adding Folder
                    newNode            = new FolderTreeNode();
                    newNode.Text       = System.IO.Path.GetFileName(virtFsNode.FileName);
                    newNode.virtFsNode = virtFsNode;
                    newNode.ImageIndex = newNode.SelectedImageIndex =
                        (virtFsNode.FileFlags & VIRT_FILE_FLAGS.ISFILE) > 0 ? IMGINDEX_FILE : IMGINDEX_FOLDER;
                    if (curParent != null)
                    {
                        curParent.Nodes.Add(newNode);
                    }
                    else
                    {
                        fsFolderTree.Nodes.Add(newNode);
                    }
                    curParent = newNode;

                    /*if ((virtFsNode.FileFlags & VirtPackage.VIRT_FILE_FLAGS_ISFILE) == 0)
                     * {
                     *  // Adding Folder
                     *  newNode = new FolderTreeNode();
                     *  newNode.Text = System.IO.Path.GetFileName(virtFsNode.FileName);
                     *  newNode.virtFsNode = virtFsNode;
                     *  newNode.ImageIndex = newNode.SelectedImageIndex = 0;
                     *  if (curParent != null)
                     *      curParent.Nodes.Add(newNode);
                     *  else
                     *      fsFolderTree.Nodes.Add(newNode);
                     *  curParent = newNode;
                     * }
                     * else
                     * {
                     *  // Adding File
                     *  if (curParent != null)
                     *  {
                     *      FileData childFile = new FileData();
                     *      childFile.virtFsNode = virtFsNode;
                     *      if (curParent.childFiles == null)
                     *          curParent.childFiles = new List<FileData>();
                     *      curParent.childFiles.Add(childFile);
                     *  }
                     * }*/
                }
            }
        }
Пример #20
0
        private void OnAddEmptyDirBtnClick(object sender, EventArgs e)
        {
            FolderTreeNode parentNode = (FolderTreeNode)fsFolderTree.SelectedNode;

            if (parentNode == null)
            {
                MessageBox.Show("Please select a folder to add to");
                return;
            }
            if (parentNode.deleted)
            {
                MessageBox.Show("Folder was deleted");
                return;
            }
retry_input:
            String newFolderName = "";

            if (TreeHelper.InputBox("Add empty folder", "Folder name:", ref newFolderName) != DialogResult.OK ||
                string.IsNullOrEmpty(newFolderName))
            {
                return;
            }

            // Help user: don't let them allow root dirs such as "SomeDir". Instead, force "C_" or "%Program Files%" for root nodes.
            if (parentNode.Parent == null)   // Adding to root dir
            {
                if ((newFolderName.Length < 2) ||
                    (newFolderName.Length == 2 && newFolderName[1] != '_') ||
                    (newFolderName.Length > 2 && newFolderName[0] != '%'))
                {
                    if (MessageBox.Show(Messages.Messages.incorrectRootDir, "Warning", MessageBoxButtons.YesNo) != DialogResult.Yes)
                    {
                        goto retry_input;
                    }
                }
            }

            if (newFolderName.Contains("\\"))
            {
                MessageBox.Show("Folder must not contain '\\'. Please specify one folder at a time.");
                return;
            }

            VirtFsNode virtFsNode = new VirtFsNode();

#pragma warning disable 1690
            virtFsNode.FileName = TreeHelper.FullPath(parentNode.virtFsNode.FileName, newFolderName);
#pragma warning restore 1690
            virtFsNode.FileFlags = 0;                       // Folder, not file

            //String[] subdirs = newFolderName.Split('\\');
            FolderTreeNode curParentNode   = parentNode;
            FolderTreeNode folderOverwrite = null;
            //foreach (String subdir in subdirs)
            {
                foreach (FolderTreeNode childNode in curParentNode.Nodes)
                {
                    if (childNode.Text.Equals(newFolderName, StringComparison.CurrentCultureIgnoreCase))
                    {
                        if (!childNode.deleted)
                        {
                            MessageBox.Show("Folder already exists");
                            return;
                        }
                        else
                        {
                            folderOverwrite   = childNode;
                            childNode.deleted = false;
                            if (childNode.childFiles != null)
                            {
                                foreach (FileData file in childNode.childFiles)
                                {
                                    file.deleted = true;// make sure files from a previously deleted folder dont come back..
                                }
                            }
                        }
                    }
                }
            }

            FolderTreeNode newNode;
            if (folderOverwrite != null)
            {
                newNode = folderOverwrite;
            }
            else
            {
                newNode = AddFileOrFolder(virtFsNode, newFolderName);     // Also sets dirty = true
                if (newNode != null)
                {
                    newNode.addedEmpty = true;
                }
            }
            RefreshFolderNodeRecursively(parentNode, 0);
            TreeViewEventArgs ev = new TreeViewEventArgs(parentNode);
            OnFolderTreeSelect(sender, ev);
        }
Пример #21
0
        // function to add files and folders recursively
        private bool AddFileOrFolderRecursive(FolderTreeNode parentNode, String path)
        {
            // if path is a file
            if (File.Exists(path))
            {
                VirtFsNode virtFsFileNode;
                FileData   fileOverwrite = null;
                if (parentNode.childFiles != null)
                {
                    foreach (FileData file in parentNode.childFiles)
                    {
                        if (!file.deleted && Path.GetFileName(file.virtFsNode.FileName).Equals(Path.GetFileName(path), StringComparison.CurrentCultureIgnoreCase))
                        {
                            if (MessageBox.Show(String.Format("File \"{0}\" already exists, overwrite?", file.virtFsNode.FileName), "Overwrite?", MessageBoxButtons.YesNo) == DialogResult.No)
                            {
                                return(false);
                            }
                            else
                            {
                                if ((file.addedFrom != ""))
                                {
                                    fileOverwrite = file;
                                }
                                else
                                {
                                    file.deleted = true;
                                }
                                break;
                            }
                        }
                    }
                }


                virtFsFileNode = new VirtFsNode();
#pragma warning disable 1690
                virtFsFileNode.FileName = TreeHelper.FullPath(parentNode.virtFsNode.FileName, Path.GetFileName(path));
#pragma warning restore 1690
                virtFsFileNode.FileFlags = VIRT_FILE_FLAGS.ISFILE;      //it's a file
                if (Path.GetExtension(virtFsFileNode.FileName).Equals(".dll"))
                {
                    virtFsFileNode.FileFlags |= VIRT_FILE_FLAGS.DEPLOY_UPON_PRELOAD;
                }


                System.IO.FileInfo fi = new System.IO.FileInfo(path);
                virtFsFileNode.EndOfFile = (ulong)fi.Length;

                if (fileOverwrite != null)
                {
                    fileOverwrite.virtFsNode = virtFsFileNode;
                }
                else
                {
                    AddFileOrFolder(virtFsFileNode, path);     // Also sets dirty = true
                }
                if (parentNode == fsFolderTree.SelectedNode)
                {
                    RefreshFolderNodeRecursively(parentNode, 0);
                    TreeViewEventArgs ev = new TreeViewEventArgs(parentNode);
                    OnFolderTreeSelect(null, ev);
                }
                return(true);
            }

            if (!Directory.Exists(path))
            {
                return(false);
            }

            FolderTreeNode folderOverwrite = null;
            //foreach (String subdir in subdirs)
            {
                foreach (FolderTreeNode childNode in parentNode.Nodes)
                {
                    if (childNode.Text.Equals(Path.GetFileName(path), StringComparison.CurrentCultureIgnoreCase))
                    {
#pragma warning disable 1690
                        if (!childNode.deleted && MessageBox.Show(String.Format("Folder \"{0}\" already exists, overwrite?", childNode.virtFsNode.FileName), "Overwrite?", MessageBoxButtons.YesNo) == DialogResult.No)
#pragma warning restore 1690
                        {
                            return(false);
                        }
                        else
                        {
                            folderOverwrite   = childNode;
                            childNode.deleted = false;
                            if (childNode.childFiles != null)
                            {
                                foreach (FileData file in childNode.childFiles)
                                {
                                    file.deleted = true;// make sure files from a previously deleted folder dont come back..
                                }
                            }
                            break;
                        }
                    }
                }
            }

            String[] lsFiles = Directory.GetFiles(path);
            String[] lsDirs  = Directory.GetDirectories(path);
            FolderTreeNode subdirNode;
            if (folderOverwrite == null)
            {
                // if path is a folder
                VirtFsNode virtFsDirNode = new VirtFsNode();
#pragma warning disable 1690
                virtFsDirNode.FileName = TreeHelper.FullPath(parentNode.virtFsNode.FileName, Path.GetFileName(path));
#pragma warning restore 1690
                virtFsDirNode.FileFlags = 0;                           //it's a dir
                subdirNode = AddFileOrFolder(virtFsDirNode, path);     // Also sets dirty = true
            }
            else
            {
                subdirNode = folderOverwrite;
            }


            foreach (String file in lsFiles)
            {
                if (!AddFileOrFolderRecursive(subdirNode, file))
                {
                    return(false);
                }
            }
            foreach (String dir in lsDirs)
            {
                if (!AddFileOrFolderRecursive(subdirNode, dir))
                {
                    return(false);
                }
            }
            if (parentNode == fsFolderTree.SelectedNode)
            {
                RefreshFolderNodeRecursively(parentNode, 0);
                TreeViewEventArgs ev = new TreeViewEventArgs(parentNode);
                OnFolderTreeSelect(null, ev);
            }
            return(true);
        }
Пример #22
0
        // function to add files and folders recursively
        private bool AddFileOrFolderRecursive(FolderTreeNode parentNode, String path)
        {
            // if path is a file
            if (File.Exists(path))
            {
                VirtFsNode virtFsFileNode;
                FileData fileOverwrite = null;
                if (parentNode.childFiles != null)
                {

                    foreach (FileData file in parentNode.childFiles)
                    {
                        if (!file.deleted && Path.GetFileName(file.virtFsNode.FileName).Equals(Path.GetFileName(path), StringComparison.CurrentCultureIgnoreCase))
                        {
                            if (MessageBox.Show(String.Format("File \"{0}\" already exists, overwrite?", file.virtFsNode.FileName), "Overwrite?", MessageBoxButtons.YesNo) == DialogResult.No)
                                return false;
                            else
                            {
                                if ((file.addedFrom != ""))
                                    fileOverwrite = file;
                                else
                                    file.deleted = true;
                                break;
                            }
                        }
                    }
                }

                virtFsFileNode = new VirtFsNode();
            #pragma warning disable 1690
                virtFsFileNode.FileName = TreeHelper.FullPath(parentNode.virtFsNode.FileName, Path.GetFileName(path));
            #pragma warning restore 1690
                virtFsFileNode.FileFlags = VIRT_FILE_FLAGS.ISFILE;      //it's a file
                if (Path.GetExtension(virtFsFileNode.FileName).Equals(".dll"))
                {
                    virtFsFileNode.FileFlags |= VIRT_FILE_FLAGS.DEPLOY_UPON_PRELOAD;
                }

                System.IO.FileInfo fi = new System.IO.FileInfo(path);
                virtFsFileNode.EndOfFile = (ulong)fi.Length;

                if (fileOverwrite != null)
                    fileOverwrite.virtFsNode = virtFsFileNode;
                else
                    AddFileOrFolder(virtFsFileNode, path);     // Also sets dirty = true

                if (parentNode == fsFolderTree.SelectedNode)
                {
                    RefreshFolderNodeRecursively(parentNode, 0);
                    TreeViewEventArgs ev = new TreeViewEventArgs(parentNode);
                    OnFolderTreeSelect(null, ev);
                }
                return true;
            }

            if (!Directory.Exists(path))
                return false;

            FolderTreeNode folderOverwrite = null;
            //foreach (String subdir in subdirs)
            {
                foreach (FolderTreeNode childNode in parentNode.Nodes)
                {
                    if (childNode.Text.Equals(Path.GetFileName(path), StringComparison.CurrentCultureIgnoreCase))
                    {

            #pragma warning disable 1690
                        if (!childNode.deleted && MessageBox.Show(String.Format("Folder \"{0}\" already exists, overwrite?", childNode.virtFsNode.FileName), "Overwrite?", MessageBoxButtons.YesNo) == DialogResult.No)
            #pragma warning restore 1690
                            return false;
                        else
                        {
                            folderOverwrite = childNode;
                            childNode.deleted = false;
                            if (childNode.childFiles != null)
                                foreach (FileData file in childNode.childFiles)
                                    file.deleted = true;// make sure files from a previously deleted folder dont come back..
                            break;
                        }
                    }
                }
            }

            String[] lsFiles = Directory.GetFiles(path);
            String[] lsDirs = Directory.GetDirectories(path);
            FolderTreeNode subdirNode;
            if (folderOverwrite == null)
            {
                // if path is a folder
                VirtFsNode virtFsDirNode = new VirtFsNode();
            #pragma warning disable 1690
                virtFsDirNode.FileName = TreeHelper.FullPath(parentNode.virtFsNode.FileName, Path.GetFileName(path));
            #pragma warning restore 1690
                virtFsDirNode.FileFlags = 0;                                       //it's a dir
                subdirNode = AddFileOrFolder(virtFsDirNode, path);     // Also sets dirty = true
            }
            else
                subdirNode = folderOverwrite;

            foreach (String file in lsFiles)
            {
                if (!AddFileOrFolderRecursive(subdirNode, file))
                    return false;
            }
            foreach (String dir in lsDirs)
            {
                if (!AddFileOrFolderRecursive(subdirNode, dir))
                    return false;
            }
            if (parentNode == fsFolderTree.SelectedNode)
            {
                RefreshFolderNodeRecursively(parentNode, 0);
                TreeViewEventArgs ev = new TreeViewEventArgs(parentNode);
                OnFolderTreeSelect(null, ev);
            }
            return true;
        }
Пример #23
0
        List<FileData> getAllFilesUnderNode(FolderTreeNode node)
        {
            List<FileData> files = new List<FileData>();

              FileData fileData = new FileData();
              fileData.virtFsNode = new VirtFsNode();
              fileData.virtFsNode.FileName = treeHelper.GetFullNodeName(node) + "\\";
              if (fileData.virtFsNode.FileName != "\\")
              {
            files.Add(fileData);
              }

              if (node.childFiles != null)
              {
            files.AddRange(node.childFiles);
              }
              foreach (FolderTreeNode subnode in node.Nodes)
              {
            files.AddRange(getAllFilesUnderNode(subnode));
              }
              return files;
        }
Пример #24
0
        private void OnAddEmptyDirBtnClick(object sender, EventArgs e)
        {
            FolderTreeNode parentNode = (FolderTreeNode)fsFolderTree.SelectedNode;

            if (parentNode == null)
            {
                MessageBox.Show("Please select a folder to add to");
                return;
            }
            if (parentNode.deleted)
            {
                MessageBox.Show("Folder was deleted");
                return;
            }
            String newFolderName = "";

            if (TreeHelper.InputBox("Add empty folder", "Folder name:", ref newFolderName) != DialogResult.OK ||
                string.IsNullOrEmpty(newFolderName))
            {
                return;
            }
            if (newFolderName.Contains("\\"))
            {
                MessageBox.Show("Folder must not contain '\\'. Please specify one folder at a time.");
                return;
            }

            VirtFsNode virtFsNode = new VirtFsNode();

#pragma warning disable 1690
            virtFsNode.FileName = TreeHelper.FullPath(parentNode.virtFsNode.FileName, newFolderName);
#pragma warning restore 1690
            virtFsNode.FileFlags = 0;                       // Folder, not file

            //String[] subdirs = newFolderName.Split('\\');
            FolderTreeNode curParentNode   = parentNode;
            FolderTreeNode folderOverwrite = null;
            //foreach (String subdir in subdirs)
            {
                foreach (FolderTreeNode childNode in curParentNode.Nodes)
                {
                    if (childNode.Text.Equals(newFolderName, StringComparison.CurrentCultureIgnoreCase))
                    {
                        if (!childNode.deleted)
                        {
                            MessageBox.Show("Folder already exists");
                            return;
                        }
                        else
                        {
                            folderOverwrite   = childNode;
                            childNode.deleted = false;
                            if (childNode.childFiles != null)
                            {
                                foreach (FileData file in childNode.childFiles)
                                {
                                    file.deleted = true;// make sure files from a previously deleted folder dont come back..
                                }
                            }
                        }
                    }
                }
            }

            FolderTreeNode newNode;
            if (folderOverwrite != null)
            {
                newNode = folderOverwrite;
            }
            else
            {
                newNode = AddFileOrFolder(virtFsNode, newFolderName);     // Also sets dirty = true
                if (newNode != null)
                {
                    newNode.addedEmpty = true;
                }
            }
            RefreshFolderNodeRecursively(parentNode, 0);
            TreeViewEventArgs ev = new TreeViewEventArgs(parentNode);
            OnFolderTreeSelect(sender, ev);
        }
Пример #25
0
        private FolderTreeNode AddFileOrFolder(VirtFsNode virtFsNode, String SourceFileName)
        {
            FolderTreeNode newNode = null;
            FolderTreeNode curParent;
            TreeNode       node;
            bool           bFound;

            curParent = null;
            String fileName = "FileSystem\\" + virtFsNode.FileName;

            String[] tokens = fileName.Split('\\');
            foreach (String curToken in tokens)
            {
                if (curParent == null)
                {
                    node = fsFolderTree.Nodes[0]; // There's always a top-node, since we've added "FileSystem" node
                }
                //(fsFolderTree.Nodes.Count > 0 ? fsFolderTree.Nodes[0] : null);   // Top-most node
                else
                {
                    node = curParent.FirstNode;
                }

                bFound = false;
                while (node != null)
                {
                    if (node.Text == curToken)
                    {
                        curParent = (FolderTreeNode)node;
                        bFound    = true;
                        break;
                    }
                    node = node.NextNode;
                }
                if (bFound == false)
                {
                    if ((virtFsNode.FileFlags & VIRT_FILE_FLAGS.ISFILE) == 0)
                    {
                        // Adding Folder
                        newNode              = new FolderTreeNode();
                        newNode.Text         = Path.GetFileName(virtFsNode.FileName);
                        newNode.virtFsNode   = virtFsNode;
                        newNode.sandboxFlags = virtPackage.GetFileSandbox(virtFsNode.FileName, false);
                        newNode.deleted      = false;
                        newNode.addedEmpty   = false;
                        treeHelper.SetFolderNodeImage(newNode, newNode.deleted, (virtFsNode.FileFlags & VIRT_FILE_FLAGS.DELETED) != 0, newNode.sandboxFlags);
                        //if (newNode.sandboxFlags == SANDBOXFLAGS_COPY_ON_WRITE) newNode.ImageIndex = 3;
                        if (curParent != null)
                        {
                            curParent.Nodes.Add(newNode);
                        }
                        else
                        {
                            fsFolderTree.Nodes.Add(newNode);
                        }
                        curParent = newNode;
                    }
                    else
                    {
                        // Adding File
                        if (curParent != null)
                        {
                            FileData childFile = new FileData();
                            childFile.virtFsNode = virtFsNode;
                            if (curParent.childFiles == null)
                            {
                                curParent.childFiles = new List <FileData>();
                            }
                            childFile.addedFrom = SourceFileName;
                            childFile.deleted   = false;
                            curParent.childFiles.Add(childFile);
                        }
                    }
                    if (curParent != null)
                    {
                        FolderTreeNode upperParent = curParent;
                        while (upperParent != null)
                        {
#pragma warning disable 1690
                            upperParent.virtFsNode.EndOfFile += virtFsNode.EndOfFile;   // CS1690 is OK
#pragma warning restore 1690
                            upperParent = (FolderTreeNode)upperParent.Parent;
                        }
                    }
                }
            }
            dirty = true;
            return(newNode);
        }
Пример #26
0
        public void RefreshFolderNodeRecursively(FolderTreeNode node, int iteration)
        {
            FolderTreeNode curNode = node;

            if (iteration == 0)
            {
                VirtFsNode virtFsNode = curNode.virtFsNode;         // Avoids CS1690
                curNode.sandboxFlags = virtPackage.GetFileSandbox(virtFsNode.FileName, false);
                treeHelper.SetFolderNodeImage(curNode, curNode.deleted, (virtFsNode.FileFlags & VIRT_FILE_FLAGS.DELETED) != 0, curNode.sandboxFlags);
                if (curNode.Nodes.Count > 0)
                    RefreshFolderNodeRecursively((FolderTreeNode)curNode.Nodes[0], iteration + 1);
            }
            else
            {
                while (curNode != null)
                {
                    VirtFsNode virtFsNode = curNode.virtFsNode;     // Avoids CS1690
                    curNode.sandboxFlags = virtPackage.GetFileSandbox(virtFsNode.FileName, false);
                    treeHelper.SetFolderNodeImage(curNode, curNode.deleted, (virtFsNode.FileFlags & VIRT_FILE_FLAGS.DELETED) != 0, curNode.sandboxFlags);
                    if (curNode.Nodes.Count > 0)
                        RefreshFolderNodeRecursively((FolderTreeNode)curNode.Nodes[0], iteration + 1);
                    curNode = (FolderTreeNode)curNode.NextNode;
                }
            }
        }
Пример #27
0
        private void AddFileOrFolder(VirtFsNode virtFsNode, String SourceFileName)
        {
            FolderTreeNode newNode;
            FolderTreeNode curParent;
            TreeNode node;
            bool bFound;

            curParent = null;
            String fileName = virtFsNode.FileName;
            String[] tokens = fileName.Split('\\');
            foreach (String curToken in tokens)
            {
                if (curParent == null)
                    node = (FolderTreeNode)(fsFolderTree.Nodes.Count > 0 ? fsFolderTree.Nodes[0] : null);
                else
                    node = curParent.FirstNode;

                bFound = false;
                while (node != null)
                {
                    if (node.Text == curToken)
                    {
                        curParent = (FolderTreeNode)node;
                        bFound = true;
                        break;
                    }
                    node = node.NextNode;
                }
                if (bFound == false)
                {
                    // Adding Folder
                    newNode = new FolderTreeNode();
                    newNode.Text = System.IO.Path.GetFileName(virtFsNode.FileName);
                    newNode.virtFsNode = virtFsNode;
                    newNode.ImageIndex = newNode.SelectedImageIndex =
                        (virtFsNode.FileFlags & VIRT_FILE_FLAGS.ISFILE) > 0 ? IMGINDEX_FILE : IMGINDEX_FOLDER;
                    if (curParent != null)
                        curParent.Nodes.Add(newNode);
                    else
                        fsFolderTree.Nodes.Add(newNode);
                    curParent = newNode;
                    /*if ((virtFsNode.FileFlags & VirtPackage.VIRT_FILE_FLAGS_ISFILE) == 0)
                    {
                        // Adding Folder
                        newNode = new FolderTreeNode();
                        newNode.Text = System.IO.Path.GetFileName(virtFsNode.FileName);
                        newNode.virtFsNode = virtFsNode;
                        newNode.ImageIndex = newNode.SelectedImageIndex = 0;
                        if (curParent != null)
                            curParent.Nodes.Add(newNode);
                        else
                            fsFolderTree.Nodes.Add(newNode);
                        curParent = newNode;
                    }
                    else
                    {
                        // Adding File
                        if (curParent != null)
                        {
                            FileData childFile = new FileData();
                            childFile.virtFsNode = virtFsNode;
                            if (curParent.childFiles == null)
                                curParent.childFiles = new List<FileData>();
                            curParent.childFiles.Add(childFile);
                        }
                    }*/
                }
            }
        }
Пример #28
0
        public void OnPackageOpen()
        {
            List<VirtFsNode> virtFsNodes = new List<VirtFsNode>();
            virtPackage.EnumFiles(ref virtFsNodes);
            fsFolderTree.Nodes.Clear();

            // Add first "FileSystem" root node"
            FolderTreeNode newNode = new FolderTreeNode();
            newNode.Text = "FileSystem";
            newNode.virtFsNode = new VirtFsNode();
            treeHelper.SetFolderNodeImage(newNode,
                false, false, virtPackage.GetFileSandbox("", false));
            fsFolderTree.Nodes.Add(newNode);

            foreach (VirtFsNode virtFsNode in virtFsNodes)
            {
                AddFileOrFolder(virtFsNode, "");
            }

            // %Temp Internet% has predefined "WriteCopy" attribute, set by Packager
            // Add it here just so that user can edit its Sandbox flags.
            /*VirtFsNode tempVirtFsNode = new VirtFsNode();
            tempVirtFsNode.FileName = "%Temp Internet%";
            tempVirtFsNode.FileFlags = 0;               // Folder, not file
            AddFileOrFolder(tempVirtFsNode, "");*/

            fsFolderTree.Nodes[0].Expand();             // Expand the "FileSystem" node
            fsFolderTree.SelectedNode = fsFolderTree.Nodes[0];
            dirty = false;
        }
Пример #29
0
 private void SaveFolderContent(FolderTreeNode node, string fileSaveTargetDir)
 {
     if (node.childFiles != null)
     {
         foreach (FileData f in node.childFiles)
         {
             SaveFile(f, fileSaveTargetDir);
         }
     }
     foreach (FolderTreeNode f in node.Nodes)
     {
         String subFolder = fileSaveTargetDir + '\\' + f.Text;
         Directory.CreateDirectory(subFolder);
         SaveFolderContent(f, subFolder);
     }
 }