From 25544c48c9ea0ab9098c8b959485be40062db3f2 Mon Sep 17 00:00:00 2001 From: oxygen-dioxide <54425948+oxygen-dioxide@users.noreply.github.com> Date: Mon, 17 Jun 2024 14:46:57 +0800 Subject: [PATCH] check and patch moreconfig.txt when launching --- OpenUtau.Core/Classic/ExeResampler.cs | 33 +++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/OpenUtau.Core/Classic/ExeResampler.cs b/OpenUtau.Core/Classic/ExeResampler.cs index 1069d30b1..24e97541b 100644 --- a/OpenUtau.Core/Classic/ExeResampler.cs +++ b/OpenUtau.Core/Classic/ExeResampler.cs @@ -1,5 +1,7 @@ using System; +using System.Collections.Generic; using System.IO; +using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading; @@ -34,6 +36,27 @@ public ResamplerManifest LoadManifest() { } } + void FixMoreConfig(string moreConfigPath) { + var lines = new List { }; + if (File.Exists(moreConfigPath)) { + lines = File.ReadAllLines(moreConfigPath).ToList(); + } + for (int i = 0; i < lines.Count; i++) { + if (lines[i].StartsWith("resampler-compatibility")) { + if(lines[i] == "resampler-compatibility on"){ + //moreconfig.txt is correct + return; + } else { + lines[i] = "resampler-compatibility on"; + File.WriteAllLines(moreConfigPath, lines); + return; + } + } + } + lines.Add("resampler-compatibility on"); + File.WriteAllLines(moreConfigPath, lines); + } + public ExeResampler(string filePath, string basePath) { if (File.Exists(filePath)) { FilePath = filePath; @@ -42,6 +65,16 @@ public ExeResampler(string filePath, string basePath) { } //Load Resampler Manifest Manifest = LoadManifest(); + //Make moresampler happy + try{ + if(Path.GetFileNameWithoutExtension(filePath) == "moresampler"){ + //Load moreconfig.txt under the same folder with filePath + var moreConfigPath = Path.Combine(Path.GetDirectoryName(filePath), "moreconfig.txt"); + FixMoreConfig(moreConfigPath); + } + } catch (Exception ex){ + Log.Error($"Failed fixing moreconfig.txt for {filePath}: {ex}"); + } } public float[] DoResampler(ResamplerItem args, ILogger logger) {