예제 #1
0
 //
 // VirtFs functions
 private bool EnumFilesCallback(
     ref Object Data,
     [MarshalAs(UnmanagedType.LPWStr)] String FileName,
     UInt32 FileFlags,
     UInt64 CreationTime,
     UInt64 LastAccessTime,
     UInt64 LastWriteTime,
     UInt64 ChangeTime,
     UInt64 EndOfFile,
     UInt32 FileAttributes)
 {
     VirtFsNode virtFsNode = new VirtFsNode();
     virtFsNode.FileName = FileName;
     virtFsNode.FileFlags = (VIRT_FILE_FLAGS)FileFlags;
     virtFsNode.CreationTime = CreationTime;
     virtFsNode.LastAccessTime = LastAccessTime;
     virtFsNode.LastWriteTime = LastWriteTime;
     virtFsNode.ChangeTime = ChangeTime;
     virtFsNode.EndOfFile = EndOfFile;
     virtFsNode.FileAttributes = FileAttributes;
     ((List<VirtFsNode>)Data).Add(virtFsNode);
     return true;
 }
예제 #2
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);
                        }
                    }*/
                }
            }
        }
예제 #3
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);
        }
예제 #4
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;
        }
예제 #5
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;
        }
예제 #6
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);
        }