Skip to content

Commit

Permalink
Merge pull request #1008 from sdercolin/feature/unix-vb-check
Browse files Browse the repository at this point in the history
Add case check on case-insensitive systems in voicebank check
  • Loading branch information
stakira authored Feb 6, 2024
2 parents a76b259 + b02ef25 commit e39c3b3
Showing 1 changed file with 34 additions and 18 deletions.
52 changes: 34 additions & 18 deletions OpenUtau.Core/Classic/VoicebankErrorChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,15 @@ 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",
});
foreach(var otoSet in voicebank.OtoSets) {
CheckCaseMatchForFileReference(otoSet);
CheckDuplicatedNameIgnoringCase(otoSet);
}
//TODO: On MacOS and Linux, check if there are files that have the same name but different case.
CheckCaseMatchForFileReference(voicebank.BasePath, new string[]{
"chatacter.txt",
"character.yaml",
"prefix.map",
});
}

bool TryGetFileDuration(string filePath, Oto oto, out double fileDuration) {
Expand Down Expand Up @@ -260,16 +255,16 @@ bool FindDuplication(out List<Oto> duplicates) {
/// </summary>
/// <param name="otoSet">otoSet to be checked</param>
/// <returns></returns>
bool WindowsCaseCheck(OtoSet otoSet) {
return WindowsCaseCheck(
bool CheckCaseMatchForFileReference(OtoSet otoSet) {
return CheckCaseMatchForFileReference(
Directory.GetParent(otoSet.File).FullName,
otoSet.Otos
.Select(oto => oto.Wav)
.Append(otoSet.File)//oto.ini itself
.ToHashSet());
}

bool WindowsCaseCheck(string folder, IEnumerable<string> correctFileNames){
bool CheckCaseMatchForFileReference(string folder, IEnumerable<string> correctFileNames){
bool valid = true;
Dictionary<string, string> fileNamesLowerToActual = Directory.GetFiles(folder)
.Select(Path.GetFileName)
Expand All @@ -280,15 +275,36 @@ bool WindowsCaseCheck(string folder, IEnumerable<string> correctFileNames){
}
if (fileNamesLowerToActual[fileName.ToLower()] != fileName) {
valid = false;
Infos.Add(new VoicebankError() {
Errors.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."
+ $"The voicebank may not work on another OS."
});
}
}
return valid;
}

/// <summary>
/// Check if the file names are duplicated when converted to lower case.
/// </summary>
/// <param name="otoSet">otoSet to be checked</param>
/// <returns></returns>
bool CheckDuplicatedNameIgnoringCase(OtoSet otoSet) {
var wavNames = otoSet.Otos.Select(x => x.Wav).Distinct().ToList();
var duplicatedGroups = wavNames.GroupBy(x => x.ToLower())
.Where(group => group.Count() > 1)
.ToList();
foreach (var group in duplicatedGroups) {
Errors.Add(new VoicebankError() {
message = $"Duplicated file names found when ignoreing case in oto set \"{otoSet.Name}\":"
+ string.Join(", ", group.Select(x => $"\"{x}\""))
+ ".\n"
+ "The voicebank may not work on another OS with case-sensitivity."
});
}
return duplicatedGroups.Count == 0;
}
}
}

0 comments on commit e39c3b3

Please sign in to comment.