@@ -180,7 +180,7 @@ Namespace DownloadObjects
180180 DataList.Clear()
181181 End Sub
182182 Private Sub DownloadFeedForm_KeyDown(sender As Object , e As KeyEventArgs) Handles Me .KeyDown
183- If e.KeyCode = Keys.F5 Then RefillList0 () : e.Handled = True
183+ If e.KeyCode = Keys.F5 Then RefillList () : e.Handled = True
184184 End Sub
185185# End Region
186186# Region "Feeds handlers"
@@ -340,19 +340,19 @@ Namespace DownloadObjects
340340 MyRange.HandlersSuspended = True
341341 MyRange.Limit = c
342342 MyRange.HandlersSuspended = False
343- If Not MyDefs.Initializing Then RefillList0 ()
343+ If Not MyDefs.Initializing Then RefillList ()
344344 End With
345345 End Sub
346346# End Region
347347# Region "Refill"
348- Private Sub RefillList0 (Optional ByVal RememberPosition As Boolean ? = Nothing )
348+ Private Overloads Sub RefillList (Optional ByVal RememberPosition As Boolean ? = Nothing )
349349 If IsSession Then
350350 RefillList(FeedMode = FeedModes.Current, If (RememberPosition, True ))
351351 Else
352352 RefillSpecialFeedsData()
353353 End If
354354 End Sub
355- Private Sub RefillList( Optional ByVal RefillDataList As Boolean = True , Optional ByVal RememberPosition As Boolean = False )
355+ Private Overloads Sub RefillList( ByVal RefillDataList As Boolean , ByVal RememberPosition As Boolean )
356356 DataPopulated = False
357357 Dim rIndx% = - 1
358358 If RememberPosition Then rIndx = MyRange.CurrentIndex
@@ -493,39 +493,136 @@ Namespace DownloadObjects
493493 End Sub
494494# End Region
495495 Private Sub BTT_COPY_MOVE_TO_Click(sender As Object , e As EventArgs) Handles BTT_COPY_TO.Click, BTT_MOVE_TO.Click
496+ MoveCopyFiles( True , sender, Nothing , Nothing )
497+ End Sub
498+ Private Function MoveCopyFiles( ByVal IsInternal As Boolean , ByVal Sender As Object , ByVal NewDestination As SFile, ByVal FeedMediaFile As SFile) As Boolean
496499 Const MsgTitle$ = "Copy/Move checked files"
497500 Try
498- Dim isCopy As Boolean = sender Is BTT_COPY_TO
501+ Dim isCopy As Boolean = Not Sender Is Nothing AndAlso Sender Is BTT_COPY_TO
499502 Dim dest As SFile = Nothing
500- Dim ff As SFile, df As SFile
503+ Dim ff As SFile = Nothing , df As SFile
501504 Dim files As IEnumerable( Of SFile) = Nothing
505+ Dim mm As UserMediaD
506+ Dim mm_data As API.Base.UserMedia
507+ Dim indx%
508+ Dim renameExisting As Boolean = False
509+ Dim downloaderFilesUpdated As Boolean = False
510+ Dim eFiles As IEnumerable( Of SFile)
511+ Dim finder As Predicate( Of UserMediaD) = Function (media) media.Data.File = ff
512+ Dim x As XmlFile
513+ Dim sessionData As New List( Of UserMediaD)
514+ Dim sesFile As SFile
515+ Dim sesFilesReplaced As Boolean = False
516+ Dim filesReplace As New List( Of KeyValuePair( Of SFile, SFile))
517+ Dim updateFileLocations As Boolean = Settings.FeedUpdateFileLocationOnMove
518+ Dim result As Boolean = False
502519
503- With GetCheckedMedia()
504- If .ListExists Then files = .Select( Function (m) m.Data.File)
505- End With
520+ If FeedMediaFile.IsEmptyString Then
521+ With GetCheckedMedia()
522+ If .ListExists Then files = .Select( Function (m) m.Data.File)
523+ End With
524+ Else
525+ files = {FeedMediaFile}
526+ End If
506527 If files.ListExists Then
507- Using f As New FeedCopyToForm(files, isCopy)
508- f.ShowDialog()
509- If f.DialogResult = DialogResult.OK Then dest = f.Destination
510- End Using
528+ If NewDestination.IsEmptyString Then
529+ Using f As New FeedCopyToForm(files, isCopy)
530+ f.ShowDialog()
531+ If f.DialogResult = DialogResult.OK Then dest = f.Destination
532+ End Using
533+ Else
534+ dest = NewDestination
535+ End If
511536 If Not dest.IsEmptyString Then
537+ 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 )
542+ If eFiles.ListExists Then _
543+ renameExisting = MsgBoxE( New MMessage( "The following files already exist at the destination. " &
544+ "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
547+
548+ End If
512549 For Each ff In files
513550 If Not ff.IsEmptyString Then
514551 df = ff
515552 df.Path = dest.Path
516- If isCopy Then ff.Copy(df) Else SFile.Move(ff, df)
553+ If isCopy Then
554+ If ff.Copy(df) Then result = True
555+ Else
556+ If df.Exists And renameExisting Then df = SFile.IndexReindex(df,,,, New ErrorsDescriber( False , False , False , df))
557+ If SFile.Move(ff, df) Then
558+ result = True
559+ If updateFileLocations Then
560+ filesReplace.Add( New KeyValuePair( Of SFile, SFile)(ff, df))
561+ indx = Downloader.Files.FindIndex(finder)
562+ If indx >= 0 Then
563+ mm = Downloader.Files(indx)
564+ mm_data = mm.Data
565+ mm_data.File = df
566+ mm = New UserMediaD(mm_data, mm.User, mm.Session, mm.Date)
567+ Downloader.Files(indx) = mm
568+ downloaderFilesUpdated = True
569+ End If
570+ End If
571+ End If
572+ End If
517573 End If
518574 Next
519- If Not isCopy Then RefillList0()
520- MsgBoxE({ $"The following files were copied to{vbCr}{dest}{vbCr}{vbCr}{files.ListToString(vbCr)}" , MsgTitle})
575+ If Not isCopy And updateFileLocations Then
576+ If downloaderFilesUpdated Then Downloader.FilesSave()
577+ If FeedMode = FeedModes.Saved And Not LoadedSessionName.IsEmptyString And filesReplace.Count > 0 Then
578+ sesFile = $"{TDownloader.SessionsPath.CSFilePS}{LoadedSessionName}.xml"
579+ If sesFile.Exists Then
580+ sessionData.Clear()
581+ x = New XmlFile(sesFile, Protector.Modes.All, False ) With {.AllowSameNames = True }
582+ x.LoadData()
583+ If x.Count > 0 Then sessionData.ListAddList(x)
584+ x.Dispose()
585+ If sessionData.Count > 0 Then
586+ For Each rfile As KeyValuePair( Of SFile, SFile) In filesReplace
587+ ff = rfile.Key
588+ df = rfile.Value
589+ indx = sessionData.FindIndex(finder)
590+ If indx >= 0 Then
591+ mm = sessionData(indx)
592+ mm_data = mm.Data
593+ mm_data.File = df
594+ mm = New UserMediaD(mm_data, mm.User, mm.Session, mm.Date)
595+ sessionData(indx) = mm
596+ sesFilesReplaced = True
597+ End If
598+ Next
599+ If sesFilesReplaced Then
600+ x = New XmlFile With {.AllowSameNames = True }
601+ x.AddRange(sessionData)
602+ x.Name = TDownloader.Name_SessionXML
603+ x.Save(sesFile, EDP.SendToLog)
604+ x.Dispose()
605+ End If
606+ sessionData.Clear()
607+ End If
608+ End If
609+ End If
610+ If filesReplace.Count > 0 Then filesReplace.ForEach( Sub (fr) Settings.Feeds.UpdateDataByFile(fr.Key, fr.Value))
611+ filesReplace.Clear()
612+ RefillList()
613+ End If
614+ If IsInternal Then MsgBoxE({ $"The following files were {IIf(isCopy, " copied ", " moved ")} to{vbCr}{dest}{vbCr}{vbCr}{files.ListToString(vbCr)}" , MsgTitle})
521615 End If
522616 Else
523617 MsgBoxE({ "No files selected" , MsgTitle}, vbExclamation)
524618 End If
619+ Return result
525620 Catch ex As Exception
526- ErrorsDescriber.Execute(EDP.LogMessageValue, ex, MsgTitle)
621+ Return ErrorsDescriber.Execute(EDP.LogMessageValue, ex, MsgTitle, False )
622+ Finally
623+ Settings.Feeds.UpdateWhereDataReplaced()
527624 End Try
528- End Sub
625+ End Function
529626# Region "Load fav, spec"
530627 Private Sub BTT_LOAD_FAV_Click(sender As Object , e As EventArgs) Handles BTT_LOAD_FAV.Click
531628 FeedChangeMode(FeedModes.Special, {FeedSpecial.FavoriteName})
@@ -713,7 +810,7 @@ Namespace DownloadObjects
713810 If MsgBoxE({ "Are you sure you want to clear this session data?" , "Clear session" }, vbExclamation,,, { "Process" , "Cancel" }) = 0 Then
714811 Downloader.Files.Clear()
715812 ClearTable()
716- RefillList0 ()
813+ RefillList ()
717814 End If
718815 End Sub
719816# End Region
@@ -848,18 +945,21 @@ Namespace DownloadObjects
848945 Settings.FeedLastModeSubscriptions.Value = OPT_SUBSCRIPTIONS.Checked
849946 MENU_DOWN.Visible = OPT_SUBSCRIPTIONS.Checked
850947 End Sub , EDP.None)
851- If __refill Then RefillList0 ()
948+ If __refill Then RefillList ()
852949 End Sub
853950# End Region
854951 Friend Sub Downloader_FilesChanged( ByVal Added As Boolean )
855952 ControlInvokeFast(ToolbarTOP, BTT_REFRESH, Sub () BTT_REFRESH.ToolTipText = If (Added, "New files found" , "Some files have been removed" ))
856953 BTT_REFRESH.ControlChangeColor(ToolbarTOP, Added, False )
857954 End Sub
858955 Private Sub BTT_REFRESH_Click(sender As Object , e As EventArgs) Handles BTT_REFRESH.Click
859- RefillList0 ()
956+ RefillList ()
860957 End Sub
861958# End Region
862959# 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)
962+ End Sub
863963 Private Sub FeedMedia_MediaDeleted( ByVal Sender As FeedMedia)
864964 Try
865965 ControlInvoke(TP_DATA, Sub () TPRemoveControl(Sender, True ))
@@ -1061,7 +1161,7 @@ Namespace DownloadObjects
10611161 If d.ListExists AndAlso Not IsSubscription AndAlso d.All(FileNotExist) Then
10621162 i = Sender.CurrentIndex
10631163 Sender.HandlersSuspended = True
1064- RefillList0 (False )
1164+ RefillList (False )
10651165 If Sender.Count > 0 Then
10661166 If i.ValueBetween( 0 , Sender.Count - 1 ) Then Sender.CurrentIndex = i
10671167 Sender.HandlersSuspended = False
@@ -1087,6 +1187,7 @@ Namespace DownloadObjects
10871187 With fmList.Last
10881188 AddHandler .MediaDeleted, AddressOf FeedMedia_MediaDeleted
10891189 AddHandler .MediaDownload, AddressOf FeedMedia_Download
1190+ AddHandler .MediaMove, AddressOf FeedMedia_MediaMove
10901191 AddHandler .FeedAddWithRemove, AddressOf FeedMedia_FeedAddWithRemove
10911192 End With
10921193 End Sub )
0 commit comments