From b5612f045a35eb85e30d92446c70e10677bd56cd Mon Sep 17 00:00:00 2001 From: stax76 Date: Sun, 17 Jul 2016 14:51:28 +0200 Subject: [PATCH] - --- Controls/MacroEditorControl.vb | 2 +- Encoding/AMDEncoder.vb | 3 +-- Encoding/IntelEncoder.vb | 4 +-- Encoding/NVIDIAEncoder.vb | 4 +-- Encoding/VideoEncoder.vb | 6 ++--- Encoding/x264.vb | 7 +---- Encoding/x265.vb | 3 +-- Forms/CommandLineForm.vb | 2 -- Forms/MainForm.vb | 13 +++++----- General/AudioProfile.vb | 4 +-- General/CommandLine.vb | 4 +-- General/Extensions.vb | 7 +++++ General/GlobalCommands.vb | 4 +-- General/Misc.vb | 2 +- General/Muxer.vb | 3 +-- General/Proc.vb | 47 ++++++++-------------------------- General/Project.vb | 2 +- My Project/AssemblyInfo.vb | 2 +- UI/TipProvider.vb | 15 +++-------- 19 files changed, 45 insertions(+), 89 deletions(-) diff --git a/Controls/MacroEditorControl.vb b/Controls/MacroEditorControl.vb index 7debdc1e..0664b9e1 100644 --- a/Controls/MacroEditorControl.vb +++ b/Controls/MacroEditorControl.vb @@ -315,7 +315,7 @@ Class MacroEditorControl Private Sub llExecute_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles llExecute.LinkClicked UpdatePreview() Dim batchPath = p.TempDir + p.TargetFile.Base + "_execute.bat" - File.WriteAllText(batchPath, Proc.BatchHeader + rtbPreview.Text, Proc.BatchEncoding) + Proc.WriteBatchFile(batchPath, rtbPreview.Text) g.ShellExecute(batchPath) End Sub diff --git a/Encoding/AMDEncoder.vb b/Encoding/AMDEncoder.vb index ec291fcd..453bf219 100644 --- a/Encoding/AMDEncoder.vb +++ b/Encoding/AMDEncoder.vb @@ -64,9 +64,8 @@ Class AMDEncoder Overrides Sub Encode() p.Script.Synchronize() - Dim batchCode = Proc.BatchHeader + Params.GetCommandLine(True, False) Dim batchPath = p.TempDir + p.TargetFile.Base + "_VCEEncC.bat" - File.WriteAllText(batchPath, batchCode, Proc.BatchEncoding) + Dim batchCode = Proc.WriteBatchFile(batchPath, Params.GetCommandLine(True, False)) Using proc As New Proc proc.Init("Encoding using VCEEncC " + Package.VCEEncC.Version) diff --git a/Encoding/IntelEncoder.vb b/Encoding/IntelEncoder.vb index 413696fa..0bc49250 100644 --- a/Encoding/IntelEncoder.vb +++ b/Encoding/IntelEncoder.vb @@ -73,13 +73,11 @@ Public Class IntelEncoder Overrides Sub Encode() p.Script.Synchronize() Params.RaiseValueChanged(Nothing) - Dim batchCode = Proc.BatchHeader + Params.GetCommandLine(True, True) Dim batchPath = p.TempDir + p.TargetFile.Base + "_QSVEncC.bat" - File.WriteAllText(batchPath, batchCode, Proc.BatchEncoding) + Dim batchCode = Proc.WriteBatchFile(batchPath, Params.GetCommandLine(True, True)) Using proc As New Proc proc.Init("Encoding using QSVEncC " + Package.QSVEncC.Version) - proc.Encoding = Proc.ProcessEncoding proc.SkipStrings = {" frames: "} proc.WriteLine(batchCode + BR2) proc.File = "cmd.exe" diff --git a/Encoding/NVIDIAEncoder.vb b/Encoding/NVIDIAEncoder.vb index a2793c87..0b1acc28 100644 --- a/Encoding/NVIDIAEncoder.vb +++ b/Encoding/NVIDIAEncoder.vb @@ -68,13 +68,11 @@ Public Class NVIDIAEncoder Overrides Sub Encode() p.Script.Synchronize() - Dim batchCode = Proc.BatchHeader + Params.GetCommandLine(True, True) Dim batchPath = p.TempDir + p.TargetFile.Base + "_NVEncC.bat" - File.WriteAllText(batchPath, batchCode, Proc.BatchEncoding) + Dim batchCode = Proc.WriteBatchFile(batchPath, Params.GetCommandLine(True, True)) Using proc As New Proc proc.Init("Encoding using NVEncC " + Package.NVEncC.Version) - proc.Encoding = Proc.ProcessEncoding proc.SkipStrings = {"%]", " frames: "} proc.WriteLine(batchCode + BR2) proc.File = "cmd.exe" diff --git a/Encoding/VideoEncoder.vb b/Encoding/VideoEncoder.vb index 21af32fe..376e2e60 100644 --- a/Encoding/VideoEncoder.vb +++ b/Encoding/VideoEncoder.vb @@ -494,9 +494,8 @@ Class BatchEncoder Overrides Sub Encode() p.Script.Synchronize() - Dim batchCode = Proc.BatchHeader + Macro.Solve(CommandLines).Trim Dim batchPath = p.TempDir + Filepath.GetBase(p.TargetFile) + "_encode.bat" - File.WriteAllText(batchPath, batchCode, Proc.BatchEncoding) + Dim batchCode = Proc.WriteBatchFile(batchPath, Macro.Solve(CommandLines).Trim) Using proc As New Proc proc.Init("Encoding video command line encoder: " + Name) @@ -549,8 +548,7 @@ Class BatchEncoder script.Synchronize() Dim batchPath = p.TempDir + Filepath.GetBase(p.TargetFile) + "_CompCheck.bat" - Dim batchCode = Proc.BatchHeader + Macro.Solve(CompCheckCommandLines) - File.WriteAllText(batchPath, batchCode, Proc.BatchEncoding) + Dim batchCode = Proc.WriteBatchFile(batchPath, Macro.Solve(CompCheckCommandLines)) Log.WriteLine(batchCode + BR2) Using proc As New Proc diff --git a/Encoding/x264.vb b/Encoding/x264.vb index eceb0cf7..fc2433ec 100644 --- a/Encoding/x264.vb +++ b/Encoding/x264.vb @@ -48,15 +48,10 @@ Public Class x264Encoder If p.Script.Engine = ScriptEngine.VapourSynth Then Dim batchPath = p.TempDir + Filepath.GetBase(p.TargetFile) + "_encode.bat" - - Dim batchCode = Proc.BatchHeader + Package.vspipe.Path.Quotes + " " + - script.Path.Quotes + " - --y4m | " + Package.x264.Path.Quotes + " " + args - - File.WriteAllText(batchPath, batchCode, Proc.BatchEncoding) + Dim batchCode = Proc.WriteBatchFile(batchPath, Package.vspipe.Path.Quotes + " " + script.Path.Quotes + " - --y4m | " + Package.x264.Path.Quotes + " " + args) Using proc As New Proc proc.Init(passName) - proc.Encoding = Proc.ProcessEncoding proc.Priority = priority proc.SkipStrings = {"kb/s, eta", "%]"} proc.WriteLine(batchCode + BR2) diff --git a/Encoding/x265.vb b/Encoding/x265.vb index 92775b42..d1cd4b9e 100644 --- a/Encoding/x265.vb +++ b/Encoding/x265.vb @@ -60,9 +60,8 @@ Public Class x265Encoder priority As ProcessPriorityClass) p.Script.Synchronize() - batchCode = Proc.BatchHeader + batchCode Dim batchPath = p.TempDir + p.TargetFile.Base + "_encode.bat" - File.WriteAllText(batchPath, batchCode, Proc.BatchEncoding) + batchCode = Proc.WriteBatchFile(batchPath, batchCode) Using proc As New Proc proc.Init(passName) diff --git a/Forms/CommandLineForm.vb b/Forms/CommandLineForm.vb index dc941e65..571c8ee2 100644 --- a/Forms/CommandLineForm.vb +++ b/Forms/CommandLineForm.vb @@ -1,7 +1,5 @@ Imports System.Threading Imports System.Threading.Tasks -Imports System.Globalization - Imports StaxRip.CommandLine Imports StaxRip.UI diff --git a/Forms/MainForm.vb b/Forms/MainForm.vb index 1e15f259..3a9bce5e 100644 --- a/Forms/MainForm.vb +++ b/Forms/MainForm.vb @@ -2744,7 +2744,7 @@ Public Class MainForm Sub AudioTextChanged(tb As TextBox, ap As AudioProfile) If BlockAudioTextChanged Then Exit Sub - If tb.Text.ContainsUnicode AndAlso p.Script.Engine = ScriptEngine.AviSynth Then + If Not tb.Text.IsANSICompatible AndAlso p.Script.Engine = ScriptEngine.AviSynth Then MsgWarn(Strings.NoUnicode) tb.Text = "" Exit Sub @@ -5590,21 +5590,22 @@ Public Class MainForm Sub ShowCommandPrompt() - Dim batchCode = Proc.BatchHeader + Dim batchCode As String - For Each i In Package.Items.Values - Dim dir = i.GetDir + For Each pack In Package.Items.Values + Dim dir = pack.GetDir If Directory.Exists(dir) AndAlso Not dir.ToLower.Contains("system32") AndAlso - Not batchCode.Contains(dir) Then + Not batchCode?.Contains(dir) Then batchCode += "@set PATH=" + dir + ";%PATH%" + BR End If Next Dim batchPath = Folder.Temp + Guid.NewGuid.ToString + ".bat" - File.WriteAllText(batchPath, batchCode, Proc.BatchEncoding) + Proc.WriteBatchFile(batchPath, batchCode) + AddHandler g.MainForm.Disposed, Sub() FileHelp.Delete(batchPath) Dim batchProcess As New Process diff --git a/General/AudioProfile.vb b/General/AudioProfile.vb index 824c03a1..5641fa42 100644 --- a/General/AudioProfile.vb +++ b/General/AudioProfile.vb @@ -272,7 +272,7 @@ Public Class BatchAudioProfile Dim bitrateBefore = p.VideoBitrate Dim targetPath = GetOutputFile() - Dim batchCode = Proc.BatchHeader + { + Dim batchCode = { Package.ffmpeg.GetDir, Package.eac3to.GetDir, Package.BeSweet.GetDir}. @@ -282,7 +282,7 @@ Public Class BatchAudioProfile SolveMacros(CommandLines).Trim Dim batchPath = p.TempDir + Filepath.GetBase(File) + "_audio.bat" - IO.File.WriteAllText(batchPath, batchCode, Proc.BatchEncoding) + batchCode = Proc.WriteBatchFile(batchPath, batchCode) Using proc As New Proc proc.Init("Audio encoding: " + Name) diff --git a/General/CommandLine.vb b/General/CommandLine.vb index 0de1f829..cc815f9d 100644 --- a/General/CommandLine.vb +++ b/General/CommandLine.vb @@ -37,9 +37,7 @@ Namespace CommandLine Sub Execute() Dim batchPath = p.TempDir + p.TargetFile.Base + "_vexe.bat" - Dim batchCode = Proc.BatchHeader + GetCommandLine(True, True) - File.WriteAllText(batchPath, batchCode, Proc.BatchEncoding) - + Dim batchCode = Proc.WriteBatchFile(batchPath, GetCommandLine(True, True)) Dim batchProc As New Process batchProc.StartInfo.FileName = "cmd.exe" batchProc.StartInfo.Arguments = "/k """ + batchPath + """" diff --git a/General/Extensions.vb b/General/Extensions.vb index f361dee8..19bf7d9c 100644 --- a/General/Extensions.vb +++ b/General/Extensions.vb @@ -32,6 +32,13 @@ Module StringExtensions Return True End Function + + Function IsANSICompatible(instance As String) As Boolean + If instance = "" Then Return True + Dim bytes = Encoding.Convert(Encoding.Unicode, Encoding.Default, Encoding.Unicode.GetBytes(instance)) + Return instance = Encoding.Unicode.GetString(Encoding.Convert(Encoding.Default, Encoding.Unicode, bytes)) + End Function + Function FileName(instance As String) As String If instance = "" Then Return "" diff --git a/General/GlobalCommands.vb b/General/GlobalCommands.vb index 3bca1419..3f28e416 100644 --- a/General/GlobalCommands.vb +++ b/General/GlobalCommands.vb @@ -59,7 +59,7 @@ Public Class GlobalCommands If asBatch Then Dim batchPath = Folder.Temp + Guid.NewGuid.ToString + ".bat" Dim batchCode = Macro.Solve(commandLines) - File.WriteAllText(batchPath, batchCode, Console.InputEncoding) + File.WriteAllText(batchPath, batchCode, Encoding.Default) AddHandler g.MainForm.Disposed, Sub() FileHelp.Delete(batchPath) Using proc As New Proc @@ -126,7 +126,7 @@ Public Class GlobalCommands Dim batchPath = Folder.Temp + Guid.NewGuid.ToString + ".bat" Dim batchCode = Macro.Solve(batchScript) - File.WriteAllText(batchPath, batchCode, Console.InputEncoding) + File.WriteAllText(batchPath, batchCode, Encoding.Default) AddHandler g.MainForm.Disposed, Sub() FileHelp.Delete(batchPath) Using proc As New Proc diff --git a/General/Misc.vb b/General/Misc.vb index 21fda2d6..3757badd 100644 --- a/General/Misc.vb +++ b/General/Misc.vb @@ -75,7 +75,7 @@ Public Class GlobalClass Function ShowVideoSourceWarnings(files As IEnumerable(Of String)) As Boolean For Each i In files - If i.ContainsUnicode AndAlso p.Script.Engine = ScriptEngine.AviSynth Then + If Not i.IsANSICompatible AndAlso p.Script.Engine = ScriptEngine.AviSynth Then MsgError(Strings.NoUnicode) Return True End If diff --git a/General/Muxer.vb b/General/Muxer.vb index dcc2212f..2dee9cad 100644 --- a/General/Muxer.vb +++ b/General/Muxer.vb @@ -369,9 +369,8 @@ Class BatchMuxer Overrides Sub Mux() Log.WriteHeader("Batch Muxing") - Dim batchCode = Proc.BatchHeader + Macro.Solve(CommandLines) Dim batchPath = p.TempDir + Filepath.GetBase(p.TargetFile) + "_mux.bat" - File.WriteAllText(batchPath, batchCode, Proc.BatchEncoding) + Dim batchCode = Proc.WriteBatchFile(batchPath, Macro.Solve(CommandLines)) Using proc As New Proc proc.Init("Encoding video command line encoder: " + Name) diff --git a/General/Proc.vb b/General/Proc.vb index 864751c3..c4bd7479 100644 --- a/General/Proc.vb +++ b/General/Proc.vb @@ -53,44 +53,17 @@ Class Proc End Set End Property - Shared ReadOnly Property BatchHeader As String - Get 'unicode don't work on Windows 7 - If p.SourceFile.ContainsUnicode Then - Return "@echo off" + BR + "CHCP 65001" + BR - Else - Return "@echo off" + BR - End If - End Get - End Property + Shared Function WriteBatchFile(path As String, content As String) As String + If content.IsANSICompatible Then + content = "@echo off" + BR + "CHCP " & Encoding.Default.CodePage & BR + content + IO.File.WriteAllText(path, content, Encoding.Default) + Else + content = "@echo off" + BR + "CHCP 65001" + BR + content + IO.File.WriteAllText(path, content, New UTF8Encoding(False)) + End If - Private Shared ConsoleCPValue As Integer - - Shared ReadOnly Property ConsoleCP As Integer - Get - If ConsoleCPValue = 0 Then ConsoleCPValue = Regex.Match(ProcessHelp.GetStdOut("cmd.exe", "/C CHCP"), "\d+").Value.ToInt - Return ConsoleCPValue - End Get - End Property - - Shared ReadOnly Property BatchEncoding As Encoding - Get 'unicode don't work on Windows 7 - If p.SourceFile.ContainsUnicode Then - Return New UTF8Encoding(False) - Else - Return Encoding.GetEncoding(ConsoleCP) - End If - End Get - End Property - - Shared ReadOnly Property ProcessEncoding As Encoding - Get 'unicode don't work on Windows 7 - If p.SourceFile.ContainsUnicode Then - Return Encoding.UTF8 - Else - Return Encoding.Default - End If - End Get - End Property + Return content + End Function Property File() As String Get diff --git a/General/Project.vb b/General/Project.vb index 052bdc72..c3c02bcc 100644 --- a/General/Project.vb +++ b/General/Project.vb @@ -228,7 +228,7 @@ Public Class Project Exit Property End If - If value.ContainsUnicode AndAlso Script.Engine = ScriptEngine.AviSynth Then + If Not value.IsANSICompatible AndAlso Script.Engine = ScriptEngine.AviSynth Then MsgWarn(Strings.NoUnicode) Exit Property End If diff --git a/My Project/AssemblyInfo.vb b/My Project/AssemblyInfo.vb index e7420274..7978a894 100644 --- a/My Project/AssemblyInfo.vb +++ b/My Project/AssemblyInfo.vb @@ -8,4 +8,4 @@ Imports System.Runtime.InteropServices - \ No newline at end of file + \ No newline at end of file diff --git a/UI/TipProvider.vb b/UI/TipProvider.vb index 1c0c18f4..5c4c2583 100644 --- a/UI/TipProvider.vb +++ b/UI/TipProvider.vb @@ -132,17 +132,10 @@ Namespace UI End Sub Private Function GetTip(c As Control) As StringPair - Dim r As New StringPair - - If TipTitles.ContainsKey(c) Then - r.Name = FormatName(TipTitles(c)) - End If - - If TipTexts.ContainsKey(c) Then - r.Value = TipTexts(c) - End If - - Return r + Dim ret As New StringPair + If TipTitles.ContainsKey(c) Then ret.Name = FormatName(TipTitles(c)) + If TipTexts.ContainsKey(c) Then ret.Value = TipTexts(c) + Return ret End Function Private Function HasContextMenu(c As Control) As Boolean