@@ -10,6 +10,7 @@ Imports PersonalUtilities.Functions.XML
10
10
Imports PersonalUtilities.Functions.RegularExpressions
11
11
Imports PersonalUtilities.Forms.Toolbars
12
12
Imports PersonalUtilities.Tools.WEB
13
+ Imports PersonalUtilities.Tools
13
14
Imports System.IO
14
15
Imports System.Net
15
16
Imports System.Threading
@@ -115,6 +116,9 @@ Namespace API.Base
115
116
Private Const Name_PicturesCount As String = "PicturesCount"
116
117
Private Const Name_LastUpdated As String = "LastUpdated"
117
118
119
+ Private Const Name_ScriptUse As String = "ScriptUse"
120
+ Private Const Name_ScriptFile As String = "ScriptFile"
121
+
118
122
Private Const Name_DataMerging As String = "DataMerging"
119
123
# Region "Downloaded data"
120
124
Private Const Name_MediaType As String = "Type"
@@ -405,6 +409,10 @@ BlockNullPicture:
405
409
End Get
406
410
End Property
407
411
# End Region
412
+ # Region "Script"
413
+ Friend Overridable Property ScriptUse As Boolean = False Implements IUserData.ScriptUse
414
+ Friend Overridable Property ScriptFile As SFile Implements IUserData.ScriptFile
415
+ # End Region
408
416
# End Region
409
417
# Region "Plugins Support"
410
418
Protected Event ProgressChanged As IPluginContentProvider.ProgressChangedEventHandler Implements IPluginContentProvider.ProgressChanged
@@ -576,6 +584,17 @@ BlockNullPicture:
576
584
DownloadedVideos( True ) = x.Value(Name_VideoCount).FromXML( Of Integer )( 0 )
577
585
DownloadedPictures( True ) = x.Value(Name_PicturesCount).FromXML( Of Integer )( 0 )
578
586
LastUpdated = AConvert( Of Date )(x.Value(Name_LastUpdated), ADateTime.Formats.BaseDateTime, Nothing )
587
+ ScriptUse = x.Value(Name_ScriptUse).FromXML( Of Boolean )( False )
588
+ Dim s$ = x.Value(Name_ScriptFile)
589
+ If Not s.IsEmptyString Then
590
+ If SFile.IsDirectory(s) Then
591
+ ScriptFile = s
592
+ Else
593
+ ScriptFile = New SFile(s) With {.Path = MyFile.Path}
594
+ End If
595
+ Else
596
+ ScriptFile = Nothing
597
+ End If
579
598
DataMerging = x.Value(Name_DataMerging).FromXML( Of Boolean )( False )
580
599
ChangeCollectionName(x.Value(Name_CollectionName), False )
581
600
Labels.ListAddList(x.Value(Name_LabelsName).StringToList( Of String , List( Of String ))( "|" , EDP.ReturnValue), LAP.NotContainsOnly, LAP.ClearBeforeAdd)
@@ -615,6 +634,16 @@ BlockNullPicture:
615
634
x.Add(Name_VideoCount, DownloadedVideos( True ))
616
635
x.Add(Name_PicturesCount, DownloadedPictures( True ))
617
636
x.Add(Name_LastUpdated, AConvert( Of String )(LastUpdated, ADateTime.Formats.BaseDateTime, String .Empty))
637
+ x.Add(Name_ScriptUse, ScriptUse.BoolToInteger)
638
+ If Not ScriptFile.IsEmptyString Then
639
+ If ScriptFile.Path = MyFile.Path Then
640
+ x.Add(Name_ScriptFile, ScriptFile.File)
641
+ Else
642
+ x.Add(Name_ScriptFile, ScriptFile)
643
+ End If
644
+ Else
645
+ x.Add(Name_ScriptFile, String .Empty)
646
+ End If
618
647
x.Add(Name_CollectionName, CollectionName)
619
648
x.Add(Name_LabelsName, Labels.ListToString(, "|" , EDP.ReturnValue))
620
649
x.Add(Name_DataMerging, DataMerging.BoolToInteger)
@@ -760,6 +789,7 @@ BlockNullPicture:
760
789
If DownloadedTotal( False ) > 0 Or EnvirChanged.Invoke Then
761
790
If __SaveData Then
762
791
LastUpdated = Now
792
+ RunScript()
763
793
DownloadedPictures( True ) = SFile.GetFiles(User.File.CutPath, "*.jpg|*.jpeg|*.png|*.gif|*.webm" ,, EDP.ReturnValue).Count
764
794
DownloadedVideos( True ) = SFile.GetFiles(User.File.CutPath, "*.mp4|*.mkv|*.mov" , SearchOption.AllDirectories, EDP.ReturnValue).Count
765
795
If Labels.Contains(LabelsKeeper.NoParsedUser) Then Labels.Remove(LabelsKeeper.NoParsedUser)
@@ -919,16 +949,10 @@ BlockNullPicture:
919
949
Dim ff As SFile = Nothing
920
950
Try
921
951
If Not f.IsEmptyString AndAlso f.Exists Then
922
- Dim d As Date ? = m.Post.Date
923
952
If Settings.FileReplaceNameByDate Then
924
- Dim dd$ = AConvert( Of String )( If (d, Now), FileDateAppenderProvider, String .Empty)
925
953
ff = f
926
- ff.Name = dd
954
+ ff.Name = String .Format(FileDateAppenderPattern, f.Name, CStr (AConvert( Of String )( If (m.Post.Date, Now), FileDateAppenderProvider, String .Empty)))
927
955
ff = SFile.Indexed_IndexFile(ff,, New NumberedFile(ff))
928
- ElseIf d.HasValue AndAlso (Settings.FileAddDateToFileName Or Settings.FileAddTimeToFileName) AndAlso
929
- ( Not FileDateAppenderProvider Is Nothing And Not FileDateAppenderPattern.IsEmptyString) Then
930
- ff = f
931
- ff.Name = String .Format(FileDateAppenderPattern, f.Name, CStr (AConvert( Of String )(d.Value, FileDateAppenderProvider, String .Empty)))
932
956
End If
933
957
If Not ff.Name.IsEmptyString Then My.Computer.FileSystem.RenameFile(f, ff.File) : Return ff
934
958
End If
@@ -938,6 +962,27 @@ BlockNullPicture:
938
962
Return f
939
963
End Try
940
964
End Function
965
+ Private Sub RunScript()
966
+ Try
967
+ If ScriptUse Then
968
+ Dim ScriptPattern$
969
+ If Not ScriptFile.IsEmptyString Then
970
+ ScriptPattern = ScriptFile
971
+ Else
972
+ ScriptPattern = Settings.ScriptFile.Value
973
+ End If
974
+ If Not ScriptPattern.IsEmptyString Then
975
+ ScriptPattern &= " {0}"
976
+ Using b As New BatchExecutor With {.RedirectStandardError = True }
977
+ b.Execute({ String .Format(ScriptPattern, MyFile.CutPath( 1 ).ToString)}, EDP.SendInLog + EDP.ThrowException)
978
+ If b.HasError Or Not b.ErrorOutput.IsEmptyString Then Throw New Exception(b.ErrorOutput, b.ErrorException)
979
+ End Using
980
+ End If
981
+ End If
982
+ Catch ex As Exception
983
+ LogError(ex, "script execution error" )
984
+ End Try
985
+ End Sub
941
986
# End Region
942
987
# Region "Delete, Move, Merge"
943
988
Friend Overridable Function Delete() As Integer Implements IUserData.Delete
@@ -990,6 +1035,11 @@ BlockNullPicture:
990
1035
End If
991
1036
f.CutPath.Exists(SFO.Path)
992
1037
Directory.Move(UserBefore.File.CutPath(, EDP.ThrowException).Path, f.Path)
1038
+ If Not ScriptFile.IsEmptyString AndAlso ScriptFile.Path = UserBefore.File.Path Then
1039
+ Dim ff As SFile = ScriptFile
1040
+ f.Path = MyFile.Path
1041
+ ScriptFile = ff
1042
+ End If
993
1043
Settings.UsersList.Remove(UserBefore)
994
1044
Settings.UpdateUsersList(User)
995
1045
UpdateUserInformation()
@@ -1043,6 +1093,11 @@ BlockNullPicture:
1043
1093
New ErrorsDescriber( False , False , False , New List( Of SFile))).Count = 0 Then
1044
1094
UserBefore.File.CutPath.Delete(SFO.Path, Settings.DeleteMode, EDP.SendInLog)
1045
1095
End If
1096
+ If Not ScriptFile.IsEmptyString AndAlso ScriptFile.Path = UserBefore.File.Path Then
1097
+ Dim f As SFile = ScriptFile
1098
+ f.Path = MyFile.Path
1099
+ ScriptFile = f
1100
+ End If
1046
1101
UpdateUserInformation()
1047
1102
End If
1048
1103
Catch ioex As InvalidOperationException When ioex.HelpLink = 1
@@ -1207,6 +1262,8 @@ BlockNullPicture:
1207
1262
ReadOnly Property Key As String
1208
1263
Property DownloadImages As Boolean
1209
1264
Property DownloadVideos As Boolean
1265
+ Property ScriptUse As Boolean
1266
+ Property ScriptFile As SFile
1210
1267
Function GetLVI( ByVal Destination As ListView) As ListViewItem
1211
1268
Function GetLVIGroup( ByVal Destination As ListView) As ListViewGroup
1212
1269
Sub LoadUserInformation()
0 commit comments