diff --git a/goesdump/GoesDecoder/PacketManager.cs b/goesdump/GoesDecoder/PacketManager.cs index 5a57647..76650a5 100644 --- a/goesdump/GoesDecoder/PacketManager.cs +++ b/goesdump/GoesDecoder/PacketManager.cs @@ -210,13 +210,13 @@ public static string FixFileFolder(string dir, string filename, NOAAProduct prod } static PacketManager() { - FileHandler.AttachByCompressionHandler((int)CompressionType.JPEG, (filename, fileHeader) => DumpFile(filename, fileHeader, "jpg")); - FileHandler.AttachByCompressionHandler((int)CompressionType.GIF, (filename, fileHeader) => DumpFile(filename, fileHeader, "gif")); + FileHandler.AttachByCompressionHandler((int)CompressionType.JPEG, (filename, fileHeader) => DumpFile(filename, fileHeader, "jpg", true)); + FileHandler.AttachByCompressionHandler((int)CompressionType.GIF, (filename, fileHeader) => DumpFile(filename, fileHeader, "gif", true)); FileHandler.AttachByProductIdHandler((int)NOAAProductID.WEATHER_DATA, HandleWeatherData); FileHandler.AttachByProductIdHandler((int)NOAAProductID.OTHER_SATELLITES_1, HandleWeatherData); FileHandler.AttachByProductIdHandler((int)NOAAProductID.OTHER_SATELLITES_2, HandleWeatherData); FileHandler.AttachByProductIdHandler((int)NOAAProductID.NOAA_TEXT, HandleTextData); - FileHandler.AttachByProductIdHandler((int)NOAAProductID.HRIT_EMWIN, (filename, fileHeader) => DumpFile(filename, fileHeader, "txt")); + FileHandler.AttachByProductIdHandler((int)NOAAProductID.HRIT_EMWIN, (filename, fileHeader) => DumpFile(filename, fileHeader, "txt", true)); } public static void ExtractZipFile(string zipfile) { @@ -370,7 +370,7 @@ public static void HandleTextData(string filename, XRITHeader header) { } } - public static string DumpFile(string filename, XRITHeader fileHeader, string newExt) { + public static string DumpFile(string filename, XRITHeader fileHeader, string newExt, bool forceErase = false) { string dir = Path.GetDirectoryName(filename); string f = FixFileFolder(dir, fileHeader.Filename, fileHeader.Product, fileHeader.SubProduct); f = f.Replace(".lrit", "." + newExt); @@ -425,10 +425,18 @@ public static string DumpFile(string filename, XRITHeader fileHeader, string new UIConsole.GlobalConsole.Log(String.Format("Extracting Zip File {0}", f)); ExtractZipFile(f); } - - // Keep the original lrit file - File.Move(filename, f.Replace("." + newExt, ".lrit")); - return f.Replace("." + newExt, ".lrit"); + if (!forceErase) { + // Keep the original lrit file + File.Move(filename, f.Replace("." + newExt, ".lrit")); + return f.Replace("." + newExt, ".lrit"); + } else { + try { + File.Delete(filename); + } catch (Exception) { + // Do nothing, file doesn't exists + } + return null; + } } public static byte[] GenerateFillData(int pixels) {