From 59093dfd7aa37ea392cb163dc99895bc3723b294 Mon Sep 17 00:00:00 2001 From: Dendraspis Date: Fri, 8 Aug 2025 22:55:55 +0200 Subject: [PATCH] Add commands --- Source/Forms/MainForm.vb | 7 +- Source/General/GlobalCommands.vb | 151 +++++++++++++++++++++++++++++-- Source/General/Misc.vb | 5 +- 3 files changed, 149 insertions(+), 14 deletions(-) diff --git a/Source/Forms/MainForm.vb b/Source/Forms/MainForm.vb index d300835b..386215e3 100644 --- a/Source/Forms/MainForm.vb +++ b/Source/Forms/MainForm.vb @@ -8090,8 +8090,13 @@ Public Class MainForm g.ProcForm.Close() End If End If + + Try + g.RaiseAppEvent(ApplicationEvent.ApplicationExit) + Catch ex As Exception + End Try + g.SaveSettings() - g.RaiseAppEvent(ApplicationEvent.ApplicationExit) End Sub Protected Overrides Sub OnDeactivate(e As EventArgs) diff --git a/Source/General/GlobalCommands.vb b/Source/General/GlobalCommands.vb index ca5c9fe7..f1c33df9 100644 --- a/Source/General/GlobalCommands.vb +++ b/Source/General/GlobalCommands.vb @@ -491,6 +491,36 @@ Public Class GlobalCommands p.Script.SetFilter(category, name, script) End Sub + + Sub DisableFilterNames( filterNames As String()) + If filterNames.Any() Then + For Each filter In p.Script.Filters + For Each name In filterNames + If filter.Name = name.TrimQuotes() Then + filter.Active = False + End If + Next + Next + + g.MainForm.FiltersListView.Load() + End If + End Sub + + + Sub EnableFilterNames( filterNames As String()) + If filterNames.Any() Then + For Each filter In p.Script.Filters + For Each name In filterNames + If filter.Name = name.TrimQuotes() Then + filter.Active = True + End If + Next + Next + + g.MainForm.FiltersListView.Load() + End If + End Sub + Sub SetTargetFile( @@ -910,10 +940,55 @@ Public Class GlobalCommands End Sub - Sub AddAttachments( attachments As String()) + Sub AddAttachments( attachments As String()) For Each i In attachments If i.FileExists() Then - p.VideoEncoder.Muxer.Attachments.Add(i) + p.VideoEncoder.Muxer.Attachments.Add(i.TrimQuotes()) + End If + Next + End Sub + + + Sub AddChaptersFile( filepath As String) + If filepath.FileExists() Then + p.VideoEncoder.Muxer.ChapterFile = filepath.TrimQuotes() + End If + End Sub + + + Sub AddSubtitle( enabled As Boolean, + lang As String, + name As String, + [default] As Boolean, + forced As Boolean, + commentary As Boolean, + hearingimpaired As Boolean, + filepath As String + ) + If Not filepath.FileExists() Then Return + + Dim subtitles = Subtitle.Create(filepath.TrimQuotes()) + + For Each subtitle In subtitles + subtitle.Enabled = enabled + subtitle.Language = g.ExtractLanguageFromPath(lang) + subtitle.Title = name + subtitle.Default = [default] + subtitle.Forced = forced + subtitle.Commentary = commentary + subtitle.Hearingimpaired = hearingimpaired + Next + + If subtitles.Any() Then + p.VideoEncoder.Muxer.Subtitles.AddRange(subtitles) + End If + End Sub + + + Sub AddSubtitles( subtitles As String()) + For Each i In subtitles + If i.FileExists() Then + p.VideoEncoder.Muxer.Subtitles.AddRange(Subtitle.Create(i.TrimQuotes())) End If Next End Sub @@ -921,22 +996,78 @@ Public Class GlobalCommands Sub AddTagFile( filepath As String) If filepath.FileExists() Then - p.VideoEncoder.Muxer.TagFile = filepath + p.VideoEncoder.Muxer.TagFile = filepath.TrimQuotes() End If End Sub - Sub AddTags( - - tags As String) - + Sub AddTags( tags As String) For Each i In tags.Split(";"c) If i.Contains("=") Then - Dim left = i.Left("=").Trim - Dim right = i.Right("=").Trim + Dim left = i.Left("=").Trim().TrimQuotes() + Dim right = i.Right("=").Trim().TrimQuotes() p.VideoEncoder.Muxer.Tags.Add(New StringPair(left, right)) End If Next End Sub + + + Sub SetTitle( title As String) + If Not String.IsNullOrWhiteSpace(title.TrimQuotes()) Then + Dim muxer = TryCast(p.VideoEncoder.Muxer, MkvMuxer) + + If muxer IsNot Nothing Then + muxer.Title = title.TrimQuotes() + End If + End If + End Sub + + + Sub SetVideoTrackLanguage( lang As String) + lang = lang.TrimQuotes() + lang = If(Language.ConfusingThreeLetterISOLanguageNames.Contains(lang), $"[{lang}]", lang) + lang = If(Language.ConfusingTwoLetterISOLanguageNames.Contains(lang), $"[{lang}]", lang) + Dim el = g.ExtractLanguageFromPath(lang) + + If el IsNot Nothing Then + Dim muxer = TryCast(p.VideoEncoder.Muxer, MkvMuxer) + + If muxer IsNot Nothing Then + muxer.VideoTrackLanguage = el + End If + End If + End Sub + + + Sub SetVideoTrackName( trackName As String) + If Not String.IsNullOrWhiteSpace(trackName) Then + p.VideoEncoder.Muxer.VideoTrackName = trackName + End If + End Sub + + + Sub DisableEvents( eventNames As String()) + If eventNames.Any() AndAlso s.EventCommands.Any() Then + For Each ec As EventCommand In s.EventCommands + For Each en As String In eventNames + If ec.Name = en.TrimQuotes() Then + ec.Enabled = False + End If + Next + Next + End If + End Sub + + + Sub EnableEvents( eventNames As String()) + If eventNames.Any() AndAlso s.EventCommands.Any() Then + For Each ec As EventCommand In s.EventCommands + For Each en As String In eventNames + If ec.Name = en.TrimQuotes() Then + ec.Enabled = True + End If + Next + Next + End If + End Sub End Class diff --git a/Source/General/Misc.vb b/Source/General/Misc.vb index ad0b6685..5701b32b 100644 --- a/Source/General/Misc.vb +++ b/Source/General/Misc.vb @@ -1517,11 +1517,10 @@ Public Class Subtitle End Property Shared Function Create(path As String) As List(Of Subtitle) + path = path.TrimQuotes() Dim ret As New List(Of Subtitle) - If New FileInfo(path).Length = 0 Then - Return ret - End If + If New FileInfo(path).Length = 0 Then Return ret If path.Ext = "idx" Then Dim indexData As Integer