Skip to content

Commit

Permalink
Fix some .lrit files not being erased after processing.
Browse files Browse the repository at this point in the history
*	Fix #47
  • Loading branch information
racerxdl committed May 13, 2017
1 parent 364b118 commit e3569cb
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions goesdump/GoesDecoder/PacketManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit e3569cb

Please sign in to comment.