$"{nameof(CDTXCompanionFileFinder)} could not find expected file '{expectedCompanionPath}' and could not check the existence of a file via {prefix} '{encoding.EncodingName}'. Possible illegal file path when combining directory '{directory}' with encoded file name '{decodedCompanionFileName}'.");
foundCompanionFileName=null;
returnfalse;
}
Trace.TraceInformation(
$"{nameof(CDTXCompanionFileFinder)} could not find expected file '{expectedCompanionPath}' but found '{decodedCompanionFileName}' via {prefix} '{encoding.EncodingName}', Code Page {encoding.CodePage}, Windows Code Page {encoding.WindowsCodePage}.");
foundCompanionFileName=decodedCompanionFileName;
returntrue;
}
// Attempt to find the file as if the companion file's name was
// mangled into codepage 437 (effectively the legacy DOS codepage,
// and the one used by zip tools that are not unicode aware.)
// This step finds >99% of files with mangled names.
if(TryFindViaDecodedFileName(
"Encoding.GetEncoding(437)",
Encoding.GetEncoding(437),
outvarfoundCompanionFileNameViaEncoding437))
{
returnfoundCompanionFileNameViaEncoding437;
}
// Attempt to find the file as if the companion file's name
// was mangled into this computer's default encoding. This case
// has not been observed during testing on US English computers,
// but it is safe to perform and may assist other locales.
if(TryFindViaDecodedFileName(
"Encoding.Default",
Encoding.Default,
outvarfoundCompanionFileNameViaEncodingDefault))
{
returnfoundCompanionFileNameViaEncodingDefault;
}
// If the companion file still cannot be found, try to find a file
// with the expected extension but having the same file name as the
// main file with which it is associated (in most use cases: the .tja file.)
if(TryFindViaMainFileName(
directory,
mainFileName,
expectedCompanionPath,
outvarfoundCompanionFileNameByMainFileName))
{
returnfoundCompanionFileNameByMainFileName;
}
// If the file still cannot be found, try to find a single file
// with the expected supplementary file extension. (If more than
// one file is found with the same extension, we can't reliably
// choose the right one of them.)
if(TryFindViaCompanionFileExtension(
directory,
expectedCompanionPath,
outvarfoundCompanionFileNameByExtension))
{
returnfoundCompanionFileNameByExtension;
}
// If the file still cannot be found, produce a warning
// and return the original file name unchanged.
Trace.TraceWarning(
$"{nameof(CDTXCompanionFileFinder)} could not find expected file '{expectedCompanionPath}' by any available means.");
$"{nameof(CDTXCompanionFileFinder)} could not find expected file '{expectedCompanionPath}' but found '{mainFileNameWithCompanionFileExtension}' by matching the '{mainFileName}' file name with the expected file extension.");
$"{nameof(CDTXCompanionFileFinder)} could not find expected file '{expectedCompanionPath}' and could not search for appropriate sibling files because this file has no extension.");
}
else
{
// If no more precise approach can find the right file, we can
// usually safely find it by looking for any file with the
// expected file extension in the same folder as the main file.
// However, if someone extracts a collection of songs into a
// single folder, we will see many files with the expected
// extension. Therefore, we will only treat the file as found
// if there is one and only one file with the expected file
$"{nameof(CDTXCompanionFileFinder)} could not find expected file '{expectedCompanionPath}' but found '{foundCompanionFileName}' by searching for a single sibling file with the expected extension.");