Exemple #1
0
        private void OnFileRenamed(object sender, RenamedEventArgs e)
        {
            Console.WriteLine(@"RENAMED EVENT: {0}", FilePath);
            var eventArgs = new BackupFileRenamedEventArgs()
            {
                NewName = e.FullPath, OriginalName = e.OldFullPath
            };

            FileRenamed?.Invoke(this, eventArgs);

            Regex oldFileRegex = _fileRegex;

            TeardownFileWatcher();
            InitializeForFile(e.FullPath);

            var oldBackups = GenerateListOfBackups(oldFileRegex);

            ReconcileExistingBackups(oldBackups, false);

            // Photoshop does some weird stuff...
            // When you change a file (possibly only large files?), we actually
            // get a renamed event. So we're going to give the user the option
            // to make a backup on rename too
            if (SideSaver.instance.Settings.SaveBackupOnRename)
            {
                CopyAndSaveFile(e.FullPath);
            }
        }
Exemple #2
0
        private void OnFileRenamed(object sender, BackupFileRenamedEventArgs e)
        {
            if (_fileHandlers.ContainsKey(e.OriginalHash))
            {
                if (_fileHandlers.ContainsKey(e.NewHash))
                {
                    throw new InvalidOperationException(
                              $"New file {e.NewName} has the same hash as an existing file: {_fileHandlers[e.NewHash].FilePath }");
                }

                _fileHandlers[e.NewHash] = _fileHandlers[e.OriginalHash];
                _fileHandlers.Remove(e.OriginalHash);
            }

            Application.Current.Dispatcher.Invoke(() =>
            {
                int index = Items.IndexOf(e.OriginalName);
                if (index >= 0)
                {
                    Items[index] = e.NewName;
                }
            });
        }