Example #1
0
        public void ChangeDisplay(double top, double left, Win32Api.UsnEntry usnEntry, UsnEntryDetail.EntryDetail entryDetail)
        {
            Top  = top;
            Left = left;

            MainWindow     mainWin    = (MainWindow)Application.Current.MainWindow;
            NtfsUsnJournal usnJournal = mainWin.Journal;
            StringBuilder  sb         = new StringBuilder();

            if (usnEntry.IsFolder)
            {
                sb.AppendFormat("Directory: {0}", usnEntry.Name);
            }
            else if (usnEntry.IsFile)
            {
                sb.AppendFormat("File: {0}", usnEntry.Name);
            }
            _nameLbl.Content = sb.ToString();
            sb = new StringBuilder();
            string path;

            NtfsUsnJournal.UsnJournalReturnCode usnRtnCode = usnJournal.GetPathFromFileReference(usnEntry.ParentFileReferenceNumber, out path);
            if (usnRtnCode == NtfsUsnJournal.UsnJournalReturnCode.USN_JOURNAL_SUCCESS && 0 != string.Compare(path, "Unavailable", true))
            {
                sb.AppendFormat("  Path:    {0}{1}\\", usnJournal.VolumeName.TrimEnd('\\'), path);
            }
            else
            {
                sb.AppendFormat("  Path:    {0}", path);
            }
            _pathLbl.Content = sb.ToString();
            sb = new StringBuilder();
            sb.AppendFormat("  File Ref No: {0}", usnEntry.FileReferenceNumber);
            sb.AppendFormat("\n  Parent FRN   {0}", usnEntry.ParentFileReferenceNumber);

            if (entryDetail == EntryDetail.UsnEntry)
            {
                sb.AppendFormat("\n  Length:  {0}", usnEntry.RecordLength);
                sb.AppendFormat("\n  USN:     {0}", usnEntry.USN);
                AddReasonData(sb, usnEntry);
            }
            if (usnEntry.IsFile)
            {
                string fullPath = System.IO.Path.Combine(path, usnEntry.Name);
                if (File.Exists(fullPath))
                {
                    FileInfo fi = new FileInfo(fullPath);
                    sb.AppendFormat("\n  File Length:   {0} (bytes)", fi.Length);
                    sb.AppendFormat("\n  Creation Time: {0} - {1}", fi.CreationTime.ToShortDateString(), fi.CreationTime.ToShortTimeString());
                    sb.AppendFormat("\n  Last Modify:   {0} - {1}", fi.LastWriteTime.ToShortDateString(), fi.LastWriteTime.ToShortTimeString());
                    sb.AppendFormat("\n  Last Access:   {0} - {1}", fi.LastAccessTime.ToShortDateString(), fi.LastAccessTime.ToShortTimeString());
                }
            }
            _entryDetailLbl.Content = sb.ToString();
            Visibility = Visibility.Visible;
        }
Example #2
0
        public void ChangeDisplay(NtfsUsnJournal usnJournal, double top, double left, Win32Api.UsnEntry usnEntry, EntryDetail entryDetail)
        {
            Top  = top;
            Left = left;

            _nameLbl.Text = string.Format(CultureInfo.InvariantCulture, usnEntry.IsFolder ? "Directory: {0}" : "File: {0}", usnEntry.Name);

            string path;

            var lastError = usnJournal.GetPathFromFileReference(usnEntry.ParentFileReferenceNumber, out path);

            if (lastError == (int)NtfsUsnJournal.UsnJournalReturnCode.USN_JOURNAL_SUCCESS && null != path)
            {
                path = string.Format(CultureInfo.InvariantCulture, "{0}{1}\\", usnJournal.VolumeName.TrimEnd('\\'), path);
            }

            _pathLbl.Text = path;


            var sb = new StringBuilder();

            sb.AppendFormat("  File Ref No: {0}", usnEntry.FileReferenceNumber);
            sb.AppendFormat("\n  Parent FRN   {0}", usnEntry.ParentFileReferenceNumber);

            if (entryDetail == EntryDetail.UsnEntry)
            {
                sb.AppendFormat("\n  Length:  {0}", usnEntry.RecordLength);
                sb.AppendFormat("\n  USN:     {0}", usnEntry.USN);
                AddReasonData(sb, usnEntry);
            }

            if (!usnEntry.IsFolder)
            {
                var fullPath = Path.Combine(_pathLbl.Text, usnEntry.Name);
                if (File.Exists(fullPath))
                {
                    var fi = new FileInfo(fullPath);
                    sb.AppendFormat("\n  File Length:   {0} (bytes)", fi.Length);
                    sb.AppendFormat("\n  Creation Time: {0} - {1}", fi.CreationTime.ToShortDateString(), fi.CreationTime.ToShortTimeString());
                    sb.AppendFormat("\n  Last Modify:   {0} - {1}", fi.LastWriteTime.ToShortDateString(), fi.LastWriteTime.ToShortTimeString());
                    sb.AppendFormat("\n  Last Access:   {0} - {1}", fi.LastAccessTime.ToShortDateString(), fi.LastAccessTime.ToShortTimeString());
                }
            }

            _entryDetailLbl.Content = sb.ToString();
            Visibility = Visibility.Visible;
        }
        private static string GetActualPath(NtfsUsnJournal journal, Win32Api.UsnEntry item)
        {
            string actualPath = null;

            string rawPath;
            var    usnRtnCode = journal.GetPathFromFileReference(item.ParentFileReferenceNumber, out rawPath);

            if (usnRtnCode == NtfsUsnJournal.UsnJournalReturnCode.USN_JOURNAL_SUCCESS && 0 != String.Compare(rawPath, "Unavailable", StringComparison.OrdinalIgnoreCase))
            {
                actualPath = $"{journal.MountPoint.TrimEnd('\\')}{rawPath.TrimEnd('\\')}\\{item.Name}";
            }
            else
            {
                return(actualPath);
            }
            if (actualPath.ToLowerInvariant().StartsWith($"{journal.MountPoint.TrimEnd('\\')}\\System Volume Information".ToLowerInvariant()))
            {
                return(actualPath);
            }
            return(actualPath);
        }
        private void resultsLb_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            ListBox lb = sender as ListBox;

            if (lb.SelectedItem != null)
            {
                if (lb.SelectedItem.GetType() == typeof(Win32Api.UsnEntry))
                {
                    Win32Api.UsnEntry usnEntry = (Win32Api.UsnEntry)lb.SelectedItem;
                    StringBuilder     sb       = new StringBuilder();
                    string            path;
                    NtfsUsnJournal.UsnJournalReturnCode usnRtnCode = _usnJournal.GetPathFromFileReference(usnEntry.ParentFileReferenceNumber, out path);
                    if (usnRtnCode == NtfsUsnJournal.UsnJournalReturnCode.USN_JOURNAL_SUCCESS && 0 != string.Compare(path, "Unavailable", true))
                    {
                        if (usnEntry.IsFile)
                        {
                            string fullPath = System.IO.Path.Combine(path, usnEntry.Name);
                            if (File.Exists(fullPath))
                            {
                                try
                                {
                                    Process.Start(fullPath);
                                }
                                catch (Exception excptn)
                                {
                                    MessageBox.Show(excptn.Message);
                                }
                            }
                            else
                            {
                                MessageBox.Show(string.Format("File '{0}' not found", fullPath));
                            }
                        }
                    }
                }
            }
        }
Example #5
0
        public IEnumerable <IFSEntry> GetNextEntry(BasePath path, string snapshottedPath)
        {
            IFileProvider itemProv = ItemProvider.GetProvider();

            try{
                if (entries == null)
                {
                    entries = GetUsnRecordsDictionary();
                }

                Logger.Append(Severity.TRIVIA, "Got " + entries.Count + " (total for whole drive)  changed entries since reference backup");
            }
            catch (Exception e) {
                Logger.Append(Severity.ERROR, "Cannot query drive USN journal : " + e.Message);
                throw(e);
            }
            // now that we got a list with only the last usn cumulated change, analyze it
            foreach (KeyValuePair <int, Win32Api.UsnEntry> entry in entries)
            {
                string ePath = "";
                Console.WriteLine(" USN entry: " + entry.ToString());
                usnJ.GetPathFromFileReference(entry.Value.FileReferenceNumber /*(ulong)entry.Key*/, out ePath);
                ePath = brd.Snapshot.MountPoint /*Path*/.TrimEnd('\\') + ePath;
                //if(ePath.ToLower().Contains("copy") ||ePath.ToLower().Contains("docs") )
                Console.WriteLine("   ///// fullpath=" + ePath);


                IFSEntry changedItem;

                /*if(((NtfsUsnJournal.UsnReasonCode)entry.Value.Reason).HasFlag(NtfsUsnJournal.UsnReasonCode.USN_REASON_FILE_CREATE))
                 *      Console.WriteLine ("***  item "+ePath+" CREATED");
                 * else */
                if ((((Win32Api.UsnReasonCode)entry.Value.Reason).HasFlag(Win32Api.UsnReasonCode.USN_REASON_FILE_DELETE)))
                {
                    /*if( (((NtfsUsnJournal.UsnReasonCode)entry.Value.Reason).HasFlag ( NtfsUsnJournal.UsnReasonCode.USN_REASON_FILE_CREATE )) ){
                     *      Console.WriteLine ("***  item "+entry.Value.Name+" CREATED+DELETED");
                     *      // TODO : handle deleted + created items (ID reused), if NTFS does so
                     *      continue;
                     * }*/
                    Console.WriteLine("***DELETEF###  item " + entry.Value.Name + " DELETED");
                    changedItem    = new NTBackupFile();
                    changedItem.ID = entry.Key;

                    changedItem.Name = entry.Value.Name;
                    //changedItem.BlockMetadata.BlockMetadata.Add(new DeletedItem());
                    changedItem.ChangeStatus = DataLayoutInfos.Deleted;


                    yield return(changedItem);

                    continue;
                }
                // item not corresponding to current wanted path.
                if (ePath.IndexOf(snapshottedPath) != 0)
                {
                    continue;
                }
                try{
                    changedItem          = itemProv.GetItemByPath(ePath);
                    changedItem.ParentID = (int)entry.Value.ParentFileReferenceNumber;


                    /*else/* if( (((NtfsUsnJournal.UsnReasonCode)entry.Value.Reason).HasFlag ( NtfsUsnJournal.UsnReasonCode.USN_REASON_DATA_EXTEND ))
                    || (((NtfsUsnJournal.UsnReasonCode)entry.Value.Reason).HasFlag ( NtfsUsnJournal.UsnReasonCode.USN_REASON_DATA_OVERWRITE ))
                    || (((NtfsUsnJournal.UsnReasonCode)entry.Value.Reason).HasFlag ( NtfsUsnJournal.UsnReasonCode.USN_REASON_DATA_TRUNCATION ))
                    || (((NtfsUsnJournal.UsnReasonCode)entry.Value.Reason).HasFlag ( NtfsUsnJournal.UsnReasonCode.USN_REASON_ENCRYPTION_CHANGE ))
                    ||      )
                    ||      {
                    ||      Console.WriteLine ("***  item "+ePath+" DATA MODIFIED");
                    ||      changedItem.BlockMetadata.BlockMetadata.Add(new Mod());
                    || }*/
                    /*else */ if ((((Win32Api.UsnReasonCode)entry.Value.Reason).HasFlag(Win32Api.UsnReasonCode.USN_REASON_RENAME_NEW_NAME) ||
                                   (((Win32Api.UsnReasonCode)entry.Value.Reason).HasFlag(Win32Api.UsnReasonCode.USN_REASON_RENAME_OLD_NAME))
                                   ))
                    {
                        Console.WriteLine("***RENAMED###  item " + ePath + " RENAMED ");
                        //RenamedOrMovedItem rmi = new RenamedOrMovedItem();
                        //rmi.OldName = entry.Value.OldName;
                        //changedItem.BlockMetadata.BlockMetadata.Add(rmi);

                        // check if there is data changes , additionally to rename:
                        Win32Api.UsnReasonCode newR = ((Win32Api.UsnReasonCode)entry.Value.Reason);
                        newR &= ~Win32Api.UsnReasonCode.USN_REASON_RENAME_NEW_NAME;
                        newR &= ~Win32Api.UsnReasonCode.USN_REASON_RENAME_OLD_NAME;
                        newR &= ~Win32Api.UsnReasonCode.USN_REASON_CLOSE;

                        if ((uint)newR == 0x00000000)
                        {
                            changedItem.ChangeStatus = DataLayoutInfos.RenameOnly;
                        }
                        //changedItem.BlockMetadata.BlockMetadata.Add(new UnchangedDataItem());
                    }

                    /*else if( (((NtfsUsnJournal.UsnReasonCode)entry.Value.Reason).HasFlag ( NtfsUsnJournal.UsnReasonCode.U )) )
                     *  Console.WriteLine ("***  item "+ePath+" MOVED");*/
                }
                catch (Exception e) {              //don't add item, but report it, put backup task in Warning state
                    Logger.Append(Severity.ERROR, "Could not add item '" + ePath + "', TODO : REPORT REPORT!!. " + e.Message);
                    continue;
                }
                //Console.WriteLine ("  == usn entry path="+ePath+", reason="+((NtfsUsnJournal.UsnReasonCode)entry.Value.Reason).ToString()+" ("+entry.Value.Reason+"), ID="+ (int)(entry.Value.FileReferenceNumber)+", pid="+(int)entry.Value.ParentFileReferenceNumber);
                yield return(changedItem);
            }

            //}
        }
        private static string GetActualPath(NtfsUsnJournal journal, Win32Api.UsnEntry item)
        {
            string actualPath = null;

            string rawPath;
            var usnRtnCode = journal.GetPathFromFileReference(item.ParentFileReferenceNumber, out rawPath);

            if (usnRtnCode == NtfsUsnJournal.UsnJournalReturnCode.USN_JOURNAL_SUCCESS && 0 != String.Compare(rawPath, "Unavailable", StringComparison.OrdinalIgnoreCase))
            {
                actualPath = $"{journal.MountPoint.TrimEnd('\\')}{rawPath.TrimEnd('\\')}\\{item.Name}";
            }
            else
            {
                return actualPath;
            }
            if (actualPath.ToLowerInvariant().StartsWith($"{journal.MountPoint.TrimEnd('\\')}\\System Volume Information".ToLowerInvariant()))
            {
                return actualPath;
            }
            return actualPath;
        }