예제 #1
0
        private void newFolderToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int idParent = EFS.idRootFolder;

            if (null != tree.SelectedNode)
            {
                idParent = (int)tree.SelectedNode.Tag;
            }

            EfsEntry newFolder = CreateFolder(idParent);

            var items = AddUiItem(newFolder);

            switch (getPane())
            {
            case eCurrentPane.cpTree:
                if (null != items.Item1)
                {
                    items.Item1.BeginEdit();
                }
                return;

            case eCurrentPane.cpList:
                if (null != items.Item2)
                {
                    items.Item2.BeginEdit();
                }
                return;
            }
        }
예제 #2
0
        /// <summary>Construct file or folder's UI items.</summary>
        /// <remarks>This method may create duplicate UI items if called more then once.</remarks>
        /// <param name="ne"></param>
        /// <returns></returns>
        private Tuple <TreeNode, ListViewItem> AddUiItem(EfsEntry ne)
        {
            // List
            ListViewItem lvi = null;

            if (ne.idParent == this.idCurrentFolder)
            {
                lvi = newItem(ne);
                list.Items.Add(lvi);
            }

            // Tree
            TreeNode tn = null;

            if (ne.isDirectory)
            {
                var p = tree.Nodes.AllRecursive()
                        .Where(n => (ne.idParent == (int)n.Tag))
                        .FirstOrDefault();
                if (null != p)
                {
                    tn = newNode(ne);
                    p.Nodes.Add(tn);
                }
            }

            return(Tuple.Create(tn, lvi));
        }
예제 #3
0
        /// <summary>Create a virtual file from the EFS file.</summary>
        /// <param name="ee">EFS entry</param>
        /// <param name="path">Relative file name.</param>
        /// <returns>A newly-created file descriptor for <see cref="VirtualFileDataObject"/>.</returns>
        Delay.VirtualFileDataObject.FileDescriptor getFileDescr(EfsEntry ee, string path)
        {
            var res = new Delay.VirtualFileDataObject.FileDescriptor();

            res.Name           = path;
            res.Length         = ee.Length;
            res.ChangeTimeUtc  = ee.dtModification;
            res.StreamContents = stm => CopyFileToStream(stm, ee.id);
            return(res);
        }
예제 #4
0
        private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!Clipboard.ContainsFileDropList())
            {
                return;
            }

            int?idWhere = this.idCurrentFolder;

            if (!idWhere.HasValue)
            {
                return;
            }

            int  nFiles = 0;
            long nBytes = 0;

            Cursor.Current = Cursors.WaitCursor;
            Stopwatch       swAll      = new Stopwatch();
            List <EfsEntry> newEntries = new List <EfsEntry>();

            swAll.Start();
            using (var trans = sess.BeginTransaction())
            {
                foreach (string strPath in Clipboard.GetFileDropList().Cast <string>())
                {
                    EfsEntry ne = null;
                    if (File.Exists(strPath))                           // Single file
                    {
                        nFiles++;
                        long len;
                        ne      = EFS.AddFile(rs, idWhere.Value, fileIo, strPath, out len);
                        nBytes += len;
                        trans.LazyCommitAndReopen();
                    }
                    else if (Directory.Exists(strPath))
                    {
                        ne = AddFolder(trans, idWhere.Value, strPath, ref nFiles, ref nBytes);
                    }
                    if (null != ne)
                    {
                        newEntries.Add(ne);
                    }
                }
                trans.Commit();
                swAll.Stop();
            }
            Cursor.Current = Cursors.Default;

            newEntries.ForEach(ne => this.AddUiItem(ne));

            string msg = FormatCopyRateSummary(nFiles, nBytes, swAll.Elapsed);

            MessageBox.Show(this, msg, "Paste Complete", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
예제 #5
0
        /// <summary>Construct list item for a file or folder.</summary>
        /// <param name="f"></param>
        /// <returns></returns>
        ListViewItem newItem(EfsEntry f)
        {
            ListViewItem res = new ListViewItem();

            res.Tag  = f.id;
            res.Text = f.name;
            if (f.isDirectory)
            {
                res.ImageIndex = 1;
            }
            else
            {
                res.ImageIndex = 2;
            }
            return(res);
        }
예제 #6
0
        EfsEntry AddFolder(iSerializerTransaction trans, int idParent, string strPath, ref int nFiles, ref long cbTotalBytes)
        {
            string name   = Path.GetFileName(strPath);
            int?   idFile = EFS.FindFile(rs, idParent, name);

            if (idFile.HasValue)
            {
                EFS.DeleteFile(rs, idFile.Value);
                trans.LazyCommitAndReopen();
            }

            EfsEntry res = EFS.CreateFolder(rs.cursor, idParent, name);

            idParent = res.id;
            // Inspired by http://stackoverflow.com/questions/2085452/fast-lowlevel-method-to-recursively-process-files-in-folders/2085872#2085872
            var pending = new Queue <Tuple <string, int> >();

            pending.Enqueue(Tuple.Create(strPath, idParent));

            string[] tmp;
            while (pending.Count > 0)
            {
                Tuple <string, int> p = pending.Dequeue();

                tmp = Directory.GetDirectories(p.Item1);
                foreach (var childFolder in tmp)
                {
                    name     = Path.GetFileName(childFolder);
                    idParent = EFS.CreateFolder(rs.cursor, p.Item2, name).id;
                    pending.Enqueue(Tuple.Create(childFolder, idParent));
                    trans.LazyCommitAndReopen();
                }

                tmp = Directory.GetFiles(p.Item1);
                foreach (var filePath in tmp)
                {
                    nFiles++;
                    long len;
                    EFS.AddFile(rs, p.Item2, fileIo, filePath, out len);
                    cbTotalBytes += len;
                    trans.LazyCommitAndReopen();
                }
            }

            return(res);
        }
예제 #7
0
        /// <summary>Construct tree node for a folder</summary>
        /// <param name="f"></param>
        /// <returns></returns>
        TreeNode newNode(EfsEntry f)
        {
            TreeNode res = new TreeNode();

            res.Tag = f.id;
            if (string.IsNullOrEmpty(f.name))
            {
                res.Text       = "[root]";
                res.ImageIndex = 0;
            }
            else
            {
                res.Text               = f.name;
                res.ImageIndex         = 1;
                res.SelectedImageIndex = 1;
            }
            m_dictNodes[f.id] = res;
            return(res);
        }
예제 #8
0
        /// <summary>Iterate over the selected files and folders.</summary>
        /// <param name="itemIds">Selected item IDs.</param>
        /// <param name="actFile">Will be called for every file in the selection, including the files in a sumbolders.</param>
        /// <param name="actFolder">Will be called for every folder in the selection.</param>
        void IterateSelection(IEnumerable <int> itemIds, Action <EfsEntry, string> actFile, Action <EfsEntry, string> actFolder)
        {
            foreach (int idFile in itemIds)
            {
                EfsEntry ee = EFS.byId(rs, idFile);
                if (ee.isDirectory)
                {
                    actFolder(ee, ee.name);
                    var pending = new Queue <Tuple <string, int> >();
                    pending.Enqueue(Tuple.Create(ee.name, ee.id));

                    while (pending.Count > 0)
                    {
                        var p = pending.Dequeue();

                        foreach (EfsEntry eChild in EFS.ListChildren(rs, p.Item2))
                        {
                            string path = Path.Combine(p.Item1, eChild.name);
                            if (eChild.isDirectory)
                            {
                                pending.Enqueue(Tuple.Create(path, eChild.id));
                                actFolder(eChild, path);
                            }
                            else
                            {
                                actFile(eChild, path);
                            }
                        }
                    }
                }
                else
                {
                    actFile(ee, ee.name);
                }
            }
        }
예제 #9
0
        private void list_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            var fi = list.FocusedItem;

            if (null == fi || null == fi.Tag)
            {
                return;
            }

            int      idFile = (int)(fi.Tag);
            EfsEntry eFile  = EFS.byId(rs, idFile);

            if (eFile.isDirectory)
            {
                if (!nodeCurrent.IsExpanded)
                {
                    nodeCurrent.Expand();
                }

                tree.SelectedNode = nodeCurrent.Nodes.All()
                                    .Where(n => n.Tag != null && (int)n.Tag == idFile)
                                    .FirstOrDefault();
            }
        }