Skip to content

Commit 75039ac

Browse files
committed
2024.2.24.0
Feed: improve move/copy
1 parent 03e3a07 commit 75039ac

14 files changed

Lines changed: 755 additions & 89 deletions

SCrawler/Channels/ChannelViewForm.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Imports ADB = PersonalUtilities.Forms.Controls.Base.ActionButton.DefaultButtons
2020
Imports RButton = PersonalUtilities.Forms.Toolbars.RangeSwitcherToolbar.ControlItem
2121
Friend Class ChannelViewForm : Implements IChannelLimits
2222
#Region "Events"
23-
Friend Event OnUsersAdded(ByVal StartIndex As Integer)
23+
Friend Event OnUsersAdded As UsersAddedEventHandler
2424
Friend Event OnDownloadDone As NotificationEventHandler
2525
#End Region
2626
#Region "Appended user structure"

SCrawler/Download/Feed/DownloadFeedForm.vb

Lines changed: 90 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ Imports UserMediaD = SCrawler.DownloadObjects.TDownloader.UserMediaD
1616
Imports DTSModes = PersonalUtilities.Forms.DateTimeSelectionForm.Modes
1717
Namespace DownloadObjects
1818
Friend Class DownloadFeedForm
19+
#Region "Events"
20+
Friend Event UsersAdded As UsersAddedEventHandler
21+
#End Region
1922
#Region "Declarations"
2023
Private Const FeedTitleDefault As String = "Feed"
2124
Private WithEvents MyDefs As DefaultFormOptions
@@ -495,13 +498,15 @@ Namespace DownloadObjects
495498
Private Sub BTT_COPY_MOVE_TO_Click(sender As Object, e As EventArgs) Handles BTT_COPY_TO.Click, BTT_MOVE_TO.Click
496499
MoveCopyFiles(True, sender, Nothing, Nothing)
497500
End Sub
498-
Private Function MoveCopyFiles(ByVal IsInternal As Boolean, ByVal Sender As Object, ByVal NewDestination As SFile, ByVal FeedMediaFile As SFile) As Boolean
501+
Private Function MoveCopyFiles(ByVal IsInternal As Boolean, ByVal Sender As Object, ByVal MCTOptions As FeedMoveCopyTo, ByVal FeedMediaData As FeedMedia) As Boolean
499502
Const MsgTitle$ = "Copy/Move checked files"
500503
Try
501504
Dim isCopy As Boolean = Not Sender Is Nothing AndAlso Sender Is BTT_COPY_TO
502-
Dim dest As SFile = Nothing
505+
Dim moveOptions As FeedMoveCopyTo = Nothing
503506
Dim ff As SFile = Nothing, df As SFile
504-
Dim files As IEnumerable(Of SFile) = Nothing
507+
Dim data As IEnumerable(Of UserMediaD) = Nothing
508+
Dim dd As UserMediaD
509+
Dim data_files As IEnumerable(Of SFile) = Nothing
505510
Dim mm As UserMediaD
506511
Dim mm_data As API.Base.UserMedia
507512
Dim indx%
@@ -514,42 +519,91 @@ Namespace DownloadObjects
514519
Dim sesFile As SFile
515520
Dim sesFilesReplaced As Boolean = False
516521
Dim filesReplace As New List(Of KeyValuePair(Of SFile, SFile))
517-
Dim updateFileLocations As Boolean = Settings.FeedUpdateFileLocationOnMove
522+
Dim updateFileLocations As Boolean = Settings.FeedMoveCopyUpdateFileLocationOnMove
518523
Dim result As Boolean = False
519524

520-
If FeedMediaFile.IsEmptyString Then
521-
With GetCheckedMedia()
522-
If .ListExists Then files = .Select(Function(m) m.Data.File)
525+
If FeedMediaData Is Nothing Then
526+
data = GetCheckedMedia()
527+
With data
528+
If .ListExists Then data_files = .Select(Function(m) m.Data.File)
523529
End With
524530
Else
525-
files = {FeedMediaFile}
531+
data = {FeedMediaData.Media}
532+
data_files = {FeedMediaData.File}
526533
End If
527-
If files.ListExists Then
528-
If NewDestination.IsEmptyString Then
529-
Using f As New FeedCopyToForm(files, isCopy)
534+
If data.ListExists Then
535+
If MCTOptions.Destination.IsEmptyString Then
536+
Using f As New FeedCopyToForm(data_files, isCopy)
530537
f.ShowDialog()
531-
If f.DialogResult = DialogResult.OK Then dest = f.Destination
538+
If f.DialogResult = DialogResult.OK Then moveOptions = f.Result
532539
End Using
533540
Else
534-
dest = NewDestination
541+
moveOptions = MCTOptions
535542
End If
536-
If Not dest.IsEmptyString Then
543+
544+
With moveOptions
545+
If Not .Destination.IsEmptyString And .ReplaceUserProfile And .ReplaceUserProfile_CreateIfNull And .ReplaceUserProfile_Profile Is Nothing Then
546+
Dim existingPathInstances As IEnumerable(Of String) = Nothing
547+
Dim __user As UserInfo
548+
Dim __host As Plugin.Hosts.SettingsHost = Settings(API.PathPlugin.PluginKey).Default
549+
Dim __userName$ = .Destination.Segments.LastOrDefault
550+
If Settings.UsersList.Count > 0 Then _
551+
existingPathInstances = (From __uu As UserInfo In Settings.UsersList
552+
Where __uu.Plugin = API.PathPlugin.PluginKey
553+
Select __uu.Name.ToLower)
554+
Do
555+
__userName = InputBoxE("Enter a new username for the 'path' plugin:", MsgTitle, __userName)
556+
If __userName.IsEmptyString Then
557+
Return False
558+
Else
559+
If Not existingPathInstances.ListExists OrElse Not existingPathInstances.Contains(__userName.ToLower) Then
560+
Exit Do
561+
ElseIf MsgBoxE({$"The name you entered ({__userName}) already exists", MsgTitle}, vbCritical,,, {"Retry", "Cancel"}) = 1 Then
562+
Return False
563+
End If
564+
End If
565+
Loop
566+
__user = New UserInfo(__userName, __host) With {.SpecialPath = moveOptions.Destination.CSFilePS}
567+
__user.UpdateUserFile()
568+
If Settings.UsersList.Count = 0 OrElse Not Settings.UsersList.Contains(__user) Then
569+
Settings.UpdateUsersList(__user)
570+
With Settings.Users
571+
Dim startIndx% = .Count
572+
.Add(API.Base.UserDataBase.GetInstance(__user))
573+
With .Last
574+
If Not .FileExists Then .UpdateUserInformation()
575+
End With
576+
RaiseEvent UsersAdded(startIndx)
577+
moveOptions.ReplaceUserProfile_Profile = .Last
578+
End With
579+
580+
Else
581+
MsgBoxE({$"The user list already contains the user you want to add.{vbCr}Operation canceled.", MsgTitle}, vbCritical)
582+
Return False
583+
End If
584+
End If
585+
End With
586+
587+
If Not moveOptions.Destination.IsEmptyString Then
537588
If Not isCopy Then
538-
eFiles = files.Where(Function(ByVal fff As SFile) As Boolean
539-
fff.Path = dest
540-
Return fff.Exists
541-
End Function)
589+
Dim eFileResult As Func(Of UserMediaD, SFile) = Function(ByVal fff As UserMediaD) As SFile
590+
Dim _fff As SFile = fff.Data.File
591+
_fff.Path = moveOptions.DestinationTrue(fff).Path
592+
Return _fff
593+
End Function
594+
eFiles = (From ef As UserMediaD In data Where eFileResult.Invoke(ef).Exists Select eFileResult.Invoke(ef))
542595
If eFiles.ListExists Then _
543596
renameExisting = MsgBoxE(New MMessage("The following files already exist at the destination. " &
544597
"Do you still want to move them? These files will be renamed and moved." & vbCr &
545-
$"Destination: {dest.PathWithSeparator}{vbCr}{vbCr}" &
546-
eFiles.ListToString(vbCr), MsgTitle, {"Move", "Cancel"}, vbExclamation)) = 0
598+
$"Destination: {moveOptions.Destination.PathWithSeparator}{vbCr}{vbCr}" &
599+
eFiles.ListToString(vbCr), MsgTitle, {"Move", "Cancel"}, vbExclamation) With {.Editable = True}) = 0
547600

548601
End If
549-
For Each ff In files
550-
If Not ff.IsEmptyString Then
602+
For Each dd In data
603+
If Not dd.Data.File.IsEmptyString Then
604+
ff = dd.Data.File
551605
df = ff
552-
df.Path = dest.Path
606+
df.Path = moveOptions.DestinationTrue(dd).Path
553607
If isCopy Then
554608
If ff.Copy(df) Then result = True
555609
Else
@@ -563,7 +617,7 @@ Namespace DownloadObjects
563617
mm = Downloader.Files(indx)
564618
mm_data = mm.Data
565619
mm_data.File = df
566-
mm = New UserMediaD(mm_data, mm.User, mm.Session, mm.Date)
620+
mm = New UserMediaD(mm_data, If(moveOptions.ReplaceUserProfile_Profile, mm.User), mm.Session, mm.Date)
567621
Downloader.Files(indx) = mm
568622
downloaderFilesUpdated = True
569623
End If
@@ -580,7 +634,7 @@ Namespace DownloadObjects
580634
sessionData.Clear()
581635
x = New XmlFile(sesFile, Protector.Modes.All, False) With {.AllowSameNames = True}
582636
x.LoadData()
583-
If x.Count > 0 Then sessionData.ListAddList(x)
637+
If x.Count > 0 Then sessionData.ListAddList(x, LAP.IgnoreICopier)
584638
x.Dispose()
585639
If sessionData.Count > 0 Then
586640
For Each rfile As KeyValuePair(Of SFile, SFile) In filesReplace
@@ -591,9 +645,13 @@ Namespace DownloadObjects
591645
mm = sessionData(indx)
592646
mm_data = mm.Data
593647
mm_data.File = df
594-
mm = New UserMediaD(mm_data, mm.User, mm.Session, mm.Date)
648+
mm = New UserMediaD(mm_data, If(moveOptions.ReplaceUserProfile_Profile, mm.User), mm.Session, mm.Date)
595649
sessionData(indx) = mm
596650
sesFilesReplaced = True
651+
If DataList.Count > 0 Then
652+
indx = DataList.FindIndex(finder)
653+
If indx >= 0 Then DataList(indx) = mm
654+
End If
597655
End If
598656
Next
599657
If sesFilesReplaced Then
@@ -607,11 +665,11 @@ Namespace DownloadObjects
607665
End If
608666
End If
609667
End If
610-
If filesReplace.Count > 0 Then filesReplace.ForEach(Sub(fr) Settings.Feeds.UpdateDataByFile(fr.Key, fr.Value))
668+
If filesReplace.Count > 0 Then filesReplace.ForEach(Sub(fr) Settings.Feeds.UpdateDataByFile(fr.Key, fr.Value, moveOptions))
611669
filesReplace.Clear()
612-
RefillList()
613670
End If
614-
If IsInternal Then MsgBoxE({$"The following files were {IIf(isCopy, "copied", "moved")} to{vbCr}{dest}{vbCr}{vbCr}{files.ListToString(vbCr)}", MsgTitle})
671+
If IsInternal Then MsgBoxE(New MMessage($"The following files were {IIf(isCopy, "copied", "moved")} to{vbCr}{moveOptions.Destination}{vbCr}{vbCr}{data_files.ListToString(vbCr)}", MsgTitle) With {.Editable = True})
672+
If Not isCopy And updateFileLocations Then RefillList()
615673
End If
616674
Else
617675
MsgBoxE({"No files selected", MsgTitle}, vbExclamation)
@@ -899,7 +957,7 @@ Namespace DownloadObjects
899957
Else
900958
MsgBoxE({"No destination selected", msgTitle}, vbExclamation)
901959
End If
902-
ElseIf mfrom.ListExists(1) Then
960+
ElseIf mFrom.ListExists(1) Then
903961
MsgBoxE({"You must select two or more files to merge feeds", msgTitle}, vbExclamation)
904962
Else
905963
MsgBoxE({"You haven't selected any feeds", msgTitle}, vbExclamation)
@@ -957,8 +1015,8 @@ Namespace DownloadObjects
9571015
End Sub
9581016
#End Region
9591017
#Region "FeedMedia handlers"
960-
Private Sub FeedMedia_MediaMove(ByVal Sender As FeedMedia, ByVal Destination As SFile, ByRef Result As Boolean)
961-
Result = MoveCopyFiles(False, Nothing, Destination, Sender.File)
1018+
Private Sub FeedMedia_MediaMove(ByVal Sender As FeedMedia, ByVal MCTOptions As FeedMoveCopyTo, ByRef Result As Boolean)
1019+
Result = MoveCopyFiles(False, Nothing, MCTOptions, Sender)
9621020
End Sub
9631021
Private Sub FeedMedia_MediaDeleted(ByVal Sender As FeedMedia)
9641022
Try

0 commit comments

Comments
 (0)