private Imgd FileLoader(string filePath, MaterialDef matDef, MapGenConfig config) { logger.Debug($"Load image from \"{filePath}\""); if (FileExtUtil.IsExtension(filePath, ".imd")) { return(ImageResizer.NormalizeImageSize(File.OpenRead(filePath).Using(s => Imgd.Read(s)))); } if (FileExtUtil.IsExtension(filePath, ".png")) { var imdFile = Path.ChangeExtension(filePath, ".imd"); if (config.skipConversionIfExists && File.Exists(imdFile)) { logger.Debug($"Skipping png to imd conversion, due to imd file existence and skipConversionIfExists option."); } else { try { logger.Debug($"Using ImgTool for png to imd conversion."); var imgtoolOptions = matDef.imgtoolOptions ?? config.imgtoolOptions ?? "-b 8"; var result = new RunCmd( "OpenKh.Command.ImgTool.exe", $"imd \"{filePath}\" -o \"{imdFile}\" {imgtoolOptions}" ); if (result.ExitCode != 0) { throw new Exception($"ImgTool failed ({result.ExitCode})"); } } catch (Win32Exception ex) { throw new Exception("ImgTool failed.", ex); } } return(FileLoader(imdFile, matDef, config)); } throw new NotSupportedException(Path.GetExtension(filePath)); }