Esempio n. 1
0
        public RegistryEditor(VirtPackage virtPackage, DelegateRequireElevation requireElevation,
            TreeView fsFolderTree, ListView fsFilesList, Label fsFolderInfoFullName, 
            ComboBox fsFolderInfoIsolationCombo, ToolStripButton regRemoveBtn, ToolStripButton regEditBtn)
        {
            this.virtPackage = virtPackage;
            this.requireElevation = requireElevation;
            this.fsFolderTree = fsFolderTree;
            this.fsFilesList = fsFilesList;
            this.fsFolderInfoFullName = fsFolderInfoFullName;
            this.fsFolderInfoIsolationCombo = fsFolderInfoIsolationCombo;
            this.regRemoveBtn = regRemoveBtn;
            this.regEditBtn = regEditBtn;

            fsFolderInfoFullName.Text = "";
            fsFolderInfoIsolationCombo.Text = "";
            fsFolderInfoIsolationCombo.Items.Add(PackageEditor.Messages.Messages.fullAccess);
            fsFolderInfoIsolationCombo.Items.Add(PackageEditor.Messages.Messages.isolated);
            fsFolderInfoIsolationCombo.Items.Add(PackageEditor.Messages.Messages.strictlyIsolated);
            fsFolderTree.AfterSelect += OnFolderTreeSelect;
            fsFolderInfoIsolationCombo.SelectionChangeCommitted += OnFolderSandboxChange;
            regRemoveBtn.Click += OnRemoveBtnClick;
            regEditBtn.Click += OnEditClick;
            dirty = false;
            treeHelper = new TreeHelper(virtPackage);

            // delegate for AddFileOrFolder init
            Del_AddFOrF = new DelegateAddFileOrFolder(this.AddFileOrFolder);
        }
Esempio n. 2
0
        public FileSystemEditor(VirtPackage virtPackage, TreeView fsFolderTree, ListView fsFilesList,
            Label fsFolderInfoFullName, ComboBox fsFolderInfoIsolationCombo,
            ToolStripButton fsAddBtn, ToolStripButton fsRemoveBtn, ToolStripButton fsAddEmptyDirBtn,
            ToolStripButton fsSaveFileAsBtn, ToolStripButton fsAddDirBtn)
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));

            this.virtPackage = virtPackage;
            this.fsFolderTree = fsFolderTree;
            this.fsFilesList = fsFilesList;
            this.fsFolderInfoFullName = fsFolderInfoFullName;
            this.fsFolderInfoIsolationCombo = fsFolderInfoIsolationCombo;
            this.fsAddBtn = fsAddBtn;
            this.fsRemoveBtn = fsRemoveBtn;
            this.fsAddEmptyDirBtn = fsAddEmptyDirBtn;
            this.fsSaveFileAsBtn = fsSaveFileAsBtn;
            this.fsAddDirBtn = fsAddDirBtn;

            fsFolderInfoFullName.Text = "";
            fsFolderInfoIsolationCombo.Text = "";
            fsFolderInfoIsolationCombo.Items.Add(PackageEditor.Messages.Messages.fullAccess);
            fsFolderInfoIsolationCombo.Items.Add(PackageEditor.Messages.Messages.isolated);
            fsFolderInfoIsolationCombo.Items.Add(PackageEditor.Messages.Messages.strictlyIsolated);
            fsFolderTree.AfterSelect += OnFolderTreeSelect;
            fsFolderInfoIsolationCombo.SelectionChangeCommitted += OnFolderSandboxChange;
            fsAddBtn.Click += OnAddBtnClick;
            fsAddDirBtn.Click += OnAddDirBtnClick;
            fsRemoveBtn.Click += OnRemoveBtnClick;
            fsAddEmptyDirBtn.Click += OnAddEmptyDirBtnClick;
            fsSaveFileAsBtn.Click += OnSaveFileAsBtnClick;
            fsFilesList.KeyDown += Vfs_KeyDown;
            fsFolderTree.KeyDown += Vfs_KeyDown;
            dirty = false;
            treeHelper = new TreeHelper(virtPackage);

            // delegate for AddFileOrFolderRecursive init
            Del_AddFOrFR = new DelegateAddFileOrFolderRecursive(this.AddFileOrFolderRecursive);
        }
Esempio n. 3
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);
        }