P.S.:
the best way to find a path to the “optipng.exe” executable is to find a path to currentAssembly.
Besause on my work machine I have no access to HKLM registry, so no path is stored there, and sometimes current directory is changed.
Also, I recomment to use string.Format method to create an argument string.
To sum up, lines 90-107 of OptiPngFileType.cs should be changed from
if (token.Optimize) {
Process optimize = new Process {
StartInfo = {
Arguments = "\"" + tempFile + "\"" + " -o" + token.Compression + " -i" + (token.Interlace ? "1" : "0"),
WindowStyle = ProcessWindowStyle.Minimized
}
};
string startDir;
try {
startDir = (string)Registry.LocalMachine.OpenSubKey("SOFTWARE").OpenSubKey("Paint.NET").GetValue("TARGETDIR");
} catch (NullReferenceException) {
startDir = Environment.CurrentDirectory;
}
optimize.StartInfo.FileName = Path.Combine(Path.Combine(startDir, "FileTypes"), "optipng.exe");
optimize.Start();
optimize.WaitForExit();
optimize.Dispose();
}
to
if (token.Optimize) {
Process optimize = new Process {
StartInfo = {
UseShellExecute = false,
CreateNoWindow = true,
Arguments = string.Format("\"{0}\" -o{1} -i{2}", tempFile, token.Compression, token.Interlace ? "1" : "0")
}
};
string startDir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
optimize.StartInfo.FileName = Path.Combine(startDir, "optipng.exe");
optimize.Start();
optimize.WaitForExit();
optimize.Dispose();
}
btw, reference to Microsoft.Win32 can be thrown away now.