예제 #1
0
 internal void InvokeNodeHasLocalChanged(FSNode sender)
 {
     if (NodeHasLocalChanged != null)
         NodeHasLocalChanged(sender);
 }
예제 #2
0
 public FileTreeDirChangedEventArgs(FSNodeDir parent, FSNode child, FileTreeActions action)
 {
     Parent = parent;
     Child = child;
     Action = action;
 }
예제 #3
0
 public void RemoveChild(FSNode child)
 {
     child.Parent = null;
 }
예제 #4
0
 internal void RemoveChildIntern(FSNode child, bool forceLocal = false)
 {
     if (child is FSNodeDir)
     {
         m_subdirs.Remove(child.Name);
         LocalCountAdd(-((FSNodeDir) child).LocalCount, true);
     }
     else
     {
         m_files.Remove(child.Name);
         if ((child).HasLocal || forceLocal)
             LocalCountAdd(-1);
     }
     if (NodeRemoved != null)
         NodeRemoved(this, new FileTreeDirChangedEventArgs(this, child, FileTreeActions.FT_NODE_REMOVED));
     if (m_tree != null)
         m_tree.InvokeNodeRemoved(this,
                                  new FileTreeDirChangedEventArgs(this, child, FileTreeActions.FT_NODE_REMOVED));
 }
예제 #5
0
 public void AddChild(FSNode child)
 {
     child.Parent = this;
 }
예제 #6
0
 internal void AddChildIntern(FSNode child)
 {
     if (child is FSNodeDir)
     {
         m_subdirs.Add(child.Name, (FSNodeDir) child);
         LocalCountAdd(((FSNodeDir) child).LocalCount, true);
     }
     else
     {
         m_files.Add(child.Name, (FSNodeFile) child);
         if ((child).HasLocal)
             LocalCountAdd(1);
     }
     if (NodeAdded != null)
         NodeAdded(this, new FileTreeDirChangedEventArgs(this, child, FileTreeActions.FT_NODE_ADDED));
     if (m_tree != null)
         m_tree.InvokeNodeAdded(this, new FileTreeDirChangedEventArgs(this, child, FileTreeActions.FT_NODE_ADDED));
 }
예제 #7
0
파일: MFTScanner.cs 프로젝트: 1Joy/Searcher
        public IEnumerable <String> EnumerateFiles(string szDriveLetter, string[] targetSuffixs)
        {
            try
            {
                var usnRecord    = default(USN_RECORD);
                var mft          = default(MFT_ENUM_DATA);
                var dwRetBytes   = 0;
                var cb           = 0;
                var dicFRNLookup = new Dictionary <long, FSNode>();
                var bIsFile      = false;

                // This shouldn't be called more than once.
                if (m_Buffer.ToInt32() != 0)
                {
                    throw new Exception("invalid buffer");
                }

                // Assign buffer size
                m_BufferSize = 65536;
                //64KB

                // Allocate a buffer to use for reading records.
                m_Buffer = Marshal.AllocHGlobal(m_BufferSize);

                // correct path
                szDriveLetter = szDriveLetter.TrimEnd('\\');

                // Open the volume handle
                m_hCJ = OpenVolume(szDriveLetter);

                // Check if the volume handle is valid.
                if (m_hCJ == INVALID_HANDLE_VALUE)
                {
                    throw new Exception("Couldn't open handle to the volume.");
                }

                mft.StartFileReferenceNumber = 0;
                mft.LowUsn  = 0;
                mft.HighUsn = long.MaxValue;

                do
                {
                    if (DeviceIoControl(m_hCJ, FSCTL_ENUM_USN_DATA, ref mft, Marshal.SizeOf(mft), m_Buffer, m_BufferSize, ref dwRetBytes, IntPtr.Zero))
                    {
                        cb = dwRetBytes;
                        // Pointer to the first record
                        IntPtr pUsnRecord = new IntPtr(m_Buffer.ToInt32() + 8);

                        while ((dwRetBytes > 8))
                        {
                            // Copy pointer to USN_RECORD structure.
                            usnRecord = (USN_RECORD)Marshal.PtrToStructure(pUsnRecord, usnRecord.GetType());

                            // The filename within the USN_RECORD.
                            string FileName = Marshal.PtrToStringUni(new IntPtr(pUsnRecord.ToInt32() + usnRecord.FileNameOffset), usnRecord.FileNameLength / 2);

                            bIsFile = !usnRecord.FileAttributes.HasFlag(FileAttributes.Directory);
                            dicFRNLookup.Add(usnRecord.FileReferenceNumber, new FSNode(usnRecord.FileReferenceNumber, usnRecord.ParentFileReferenceNumber, FileName, bIsFile));

                            // Pointer to the next record in the buffer.
                            pUsnRecord = new IntPtr(pUsnRecord.ToInt32() + usnRecord.RecordLength);

                            dwRetBytes -= usnRecord.RecordLength;
                        }

                        // The first 8 bytes is always the start of the next USN.
                        mft.StartFileReferenceNumber = Marshal.ReadInt64(m_Buffer, 0);
                    }
                    else
                    {
                        break; // TODO: might not be correct. Was : Exit Do
                    }
                } while (!(cb <= 8));

                // Resolve all paths for Files
                foreach (FSNode oFSNode in dicFRNLookup.Values.Where(o => o.IsFile && targetSuffixs.Contains(Path.GetExtension(o.FileName))))
                {
                    string sFullPath = oFSNode.FileName;

                    FSNode oParentFSNode = oFSNode;

                    while (dicFRNLookup.TryGetValue(oParentFSNode.ParentFRN, out oParentFSNode))
                    {
                        sFullPath = string.Concat(oParentFSNode.FileName, "\\", sFullPath);
                    }
                    sFullPath = string.Concat(szDriveLetter, "\\", sFullPath);

                    yield return(sFullPath);
                }
            }
            finally
            {
                //// cleanup
                Cleanup();
            }
        }
예제 #8
0
        private static void PasteNode(FSNode node, FSNodeDir into, string newName)
        {
            if (node == null || into == null)
                return;
            try
            {
                string dirPath = into.Path + '\\';

                if (File.Exists(dirPath + newName))
                {
                    string name = newName.SubstringBeforeLast('.');
                    string ext = newName.SubstringAfterLast('.', true);
                    int numOfThatKind = into.Directories.Count(d => d.Name.StartsWith(name + "_copy"));
                    numOfThatKind += into.Files.Count(d => d.Name.StartsWith(name + "_copy"));
                    if (numOfThatKind > 0)
                        PasteNode(node, into, name + "_copy_" + (numOfThatKind + 1) + ext);
                    else
                        PasteNode(node, into, name + "_copy" + ext);
                    return;
                }

                if (node is FSNodeVirtualFile)
                {
                    var virtualFile = node as FSNodeVirtualFile;
                    if (virtualFile.HasLocal)
                    {
                        if (!Directory.Exists(dirPath))
                            Directory.CreateDirectory(dirPath);
                        File.Copy(virtualFile.Path, dirPath + newName);
                    }
                    else
                        virtualFile.Extract(dirPath + newName);
                }
                else if (node is FSNodeFile)
                {
                    var file = node as FSNodeFile;
                    if (!Directory.Exists(dirPath))
                        Directory.CreateDirectory(dirPath);
                    File.Copy(file.Path, dirPath + newName);
                }
                else if (node is FSNodeDir)
                {
                    var dir = node as FSNodeDir;
                    if (!Directory.Exists(dirPath + newName))
                        Directory.CreateDirectory(dirPath + newName);

                    into = into.GetDirectory(newName);
                    foreach (var d in dir.Directories)
                        PasteNode(d, into, d.Name);
                    foreach (var f in dir.Files)
                        PasteNode(f, into, f.Name);
                }
            }
            catch (Exception ex)
            {
                 UIHelper.ShowError("Failed to paste: " + ex.Message);
            }
        }
예제 #9
0
 private void CopyFileToolStripMenuItemVirtualClick(object sender, EventArgs e)
 {
     var node = m_fitVirtual.GetSelectedNode();// as FSNodeFile;
     if (node == null)
         return;
     m_fileTreeClipboard = node;
 }
예제 #10
0
 private void CopyToolStripMenuItemCombinedClick(object sender, EventArgs e)
 {
     var node = m_fitCombined.GetSelectedNode() as FSNodeFile;
     if (node == null)
         return;
     m_fileTreeClipboard = node;
 }
예제 #11
0
 void NodeHasLocalChanged(FSNode sender)
 {
     var dir = (FSNodeDir)sender;
     TreeNode tn = m_trvFileTreeView.GetFileTreeNodeByPath(m_fileTrees[dir.Tree] + '\\' + dir.GetPathInTree(), false);
     if (tn == null)
     {
         // a tree without virtuals might just not include that node; therefore it must be created
         if (m_noVirtual && dir.HasLocal)
         {
             // the recursive nature of the FileTree class causes the upper-most node to trigger this event first
             TreeNode parent = m_trvFileTreeView.GetFileTreeNodeByPath(m_fileTrees[dir.Tree] + '\\' + dir.GetPathInTree().SubstringBeforeLast('\\'), false);
             TreeNode tmp = dir.ConvertToTreeNode(m_noVirtual, m_noLocal, true, m_colorLocalFiles, m_colorLocalDirectories);
             if (m_trvFileTreeView.InvokeRequired)
                 m_trvFileTreeView.Invoke(new TreeNodeAddInvoke(parent.Nodes.InsertNodeSorted), tmp);
             else
                 parent.Nodes.InsertNodeSorted(tmp);
         }
         return;
     }
     if (dir.HasLocal && m_colorLocalDirectories && !m_noLocal)
         tn.ForeColor = Color.Red;
     else
     {
         if (m_noVirtual)
         {
             tn.Remove();
             return;
         }
         tn.ForeColor = Color.Blue;
     }
 }