private static string GetFileNameToUseForSavingImage(string bookFolderPath, PalasoImage imageInfo, bool isJpeg)
{
var extension = isJpeg ? ".jpg" : ".png";
// Some images, like from a scanner or camera, won't have a name yet. Some will need a number
// in order to differentiate from what is already there. We don't try and be smart somehow and
// know when to just replace the existing one with the same name... some other process will have
// to remove unused images.
string basename;
if (string.IsNullOrEmpty(imageInfo.FileName) || imageInfo.FileName.StartsWith("tmp"))
{
basename = "image";
}
else
{
// Even pictures that aren't obviously unnamed or temporary may have the same name.
// See https://silbloom.myjetbrains.com/youtrack/issue/BL-2627 ("Weird Image Problem").
basename = Path.GetFileNameWithoutExtension(imageInfo.FileName);
}
var i = 0;
var suffix = "";
while (RobustFile.Exists(Path.Combine(bookFolderPath, basename + suffix + extension)))
{
++i;
suffix = i.ToString(CultureInfo.InvariantCulture);
}
return basename + suffix + extension;
}