From 82976973d12340dbe24b24e7f207c3f58745c571 Mon Sep 17 00:00:00 2001 From: oxygen-dioxide <54425948+oxygen-dioxide@users.noreply.github.com> Date: Fri, 1 Dec 2023 14:16:43 +0800 Subject: [PATCH] windows file case check --- .../Classic/VoicebankErrorChecker.cs | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/OpenUtau.Core/Classic/VoicebankErrorChecker.cs b/OpenUtau.Core/Classic/VoicebankErrorChecker.cs index 9b003057b..39d3d6b93 100644 --- a/OpenUtau.Core/Classic/VoicebankErrorChecker.cs +++ b/OpenUtau.Core/Classic/VoicebankErrorChecker.cs @@ -101,6 +101,20 @@ public void Check() { message = $"There are duplicate aliases.{message}" }); } + //Cross platform check + //Windows path is case insensitive, while MacOS path and Linux path are case sensitive. + //On Windows, check if the wave filename in oto.ini is the same as the filename in the file system. + if(OS.IsWindows()){ + foreach(var otoSet in voicebank.OtoSets) { + WindowsCaseCheck(otoSet); + } + WindowsCaseCheck(voicebank.BasePath, new string[]{ + "chatacter.txt", + "character.yaml", + "prefix.map", + }); + } + //TODO: On MacOS and Linux, check if there are files that have the same name but different case. } bool TryGetFileDuration(string filePath, Oto oto, out double fileDuration) { @@ -240,5 +254,41 @@ bool FindDuplication(out List duplicates) { return duplicates.Count > 0; } + + /// + /// Check if the file names in the oto.ini are the same as the file names in the file system. + /// + /// otoSet to be checked + /// + bool WindowsCaseCheck(OtoSet otoSet) { + return WindowsCaseCheck( + Directory.GetParent(otoSet.File).FullName, + otoSet.Otos + .Select(oto => oto.Wav) + .Append(otoSet.File)//oto.ini itself + .ToHashSet()); + } + + bool WindowsCaseCheck(string folder, IEnumerable correctFileNames){ + bool valid = true; + Dictionary fileNamesLowerToActual = Directory.GetFiles(folder) + .Select(Path.GetFileName) + .ToDictionary(x => x.ToLower(), x => x); + foreach(string fileName in correctFileNames) { + if(!fileNamesLowerToActual.ContainsKey(fileName.ToLower())) { + continue; + } + if (fileNamesLowerToActual[fileName.ToLower()] != fileName) { + valid = false; + Infos.Add(new VoicebankError() { + message = $"Wrong case in file name: \n" + + $"expected: {Path.Join(folder,fileName)}\n" + + $"Actual: {Path.Join(folder,fileNamesLowerToActual[fileName.ToLower()])}\n" + + $"voicebank may not work on another OS." + }); + } + } + return valid; + } } }