Beispiel #1
0
 private void UpdateFileTageDb(object sender, ShellFileOperations.ShellFileOpEventArgs e, string operationType)
 {
     if (e.Result.Succeeded)
     {
         var destination = operationType switch
         {
             "delete" => e.DestItem?.FileSystemPath,
             "rename" => (!string.IsNullOrEmpty(e.Name) ? Path.Combine(Path.GetDirectoryName(e.SourceItem.FileSystemPath), e.Name) : null),
             "copy" => (e.DestFolder?.FileSystemPath != null && !string.IsNullOrEmpty(e.Name) ? Path.Combine(e.DestFolder.FileSystemPath, e.Name) : null),
             _ => (e.DestFolder?.FileSystemPath != null && !string.IsNullOrEmpty(e.Name) ? Path.Combine(e.DestFolder.FileSystemPath, e.Name) : null)
         };
         if (destination == null)
         {
             dbInstance.SetTag(e.SourceItem.FileSystemPath, null, null); // remove tag from deleted files
         }
         else
         {
             Extensions.IgnoreExceptions(() =>
             {
                 if (operationType == "copy")
                 {
                     var tag = dbInstance.GetTag(e.SourceItem.FileSystemPath);
                     dbInstance.SetTag(destination, FileTagsHandler.GetFileFRN(destination), tag); // copy tag to new files
                     using var si = new ShellItem(destination);
                     if (si.IsFolder)                                                              // File tag is not copied automatically for folders
                     {
                         FileTagsHandler.WriteFileTag(destination, tag);
                     }
                 }
                 else
                 {
                     dbInstance.UpdateTag(e.SourceItem.FileSystemPath, FileTagsHandler.GetFileFRN(destination), destination); // move tag to new files
                 }
             }, Program.Logger);
         }
         if (e.Result == HRESULT.COPYENGINE_S_DONT_PROCESS_CHILDREN) // child items not processed, update manually
         {
             var tags = dbInstance.GetAllUnderPath(e.SourceItem.FileSystemPath).ToList();
             if (destination == null) // remove tag for items contained in the folder
             {
                 tags.ForEach(t => dbInstance.SetTag(t.FilePath, null, null));
             }
             else
             {
                 if (operationType == "copy") // copy tag for items contained in the folder
                 {
                     tags.ForEach(t =>
                     {
                         Extensions.IgnoreExceptions(() =>
                         {
                             var subPath = t.FilePath.Replace(e.SourceItem.FileSystemPath, destination);
                             dbInstance.SetTag(subPath, FileTagsHandler.GetFileFRN(subPath), t.Tag);
                         }, Program.Logger);
                     });
                 }
                 else // move tag to new files
                 {
                     tags.ForEach(t =>
                     {
                         Extensions.IgnoreExceptions(() =>
                         {
                             var subPath = t.FilePath.Replace(e.SourceItem.FileSystemPath, destination);
                             dbInstance.UpdateTag(t.FilePath, FileTagsHandler.GetFileFRN(subPath), subPath);
                         }, Program.Logger);
                     });
                 }
             }
         }
     }
 }
 static void HandleEvent(object sender, ShellFileOperations.ShellFileOpEventArgs args)
 {
     Debug.WriteLine(args);
     Assert.That(args.Result.Succeeded, Is.True);
 }
Beispiel #3
0
 static void Operation_PostMoveItem(object sender, ShellFileOperations.ShellFileOpEventArgs e) => Debug.WriteLine($"Post move ({e.DestItem?.Name})...");