Only validate am2r_11 again if file has changed

pull/30/head
Miepee 5 years ago
parent e66cfc5b3f
commit 6db8e521b6

@ -284,14 +284,16 @@ namespace AM2RLauncher
// If we have a cache, return that instead
if (isAM2R11InstalledCache != null) return isAM2R11InstalledCache.Value;
string am2r11file = CrossPlatformOperations.CURRENTPATH + "/AM2R_11.zip";
// Return safely if file doesn't exist
if (!File.Exists(CrossPlatformOperations.CURRENTPATH + "/AM2R_11.zip")) return false;
var returnCode = HelperMethods.CheckIfZipIsAM2R11(CrossPlatformOperations.CURRENTPATH + "/AM2R_11.zip");
if (!File.Exists(am2r11file)) return false;
lastAM2R11ZipMD5 = HelperMethods.CalculateMD5(am2r11file);
var returnCode = HelperMethods.CheckIfZipIsAM2R11(am2r11file);
// Check if it's valid, if not log it, rename it and silently leave
if (returnCode != IsZipAM2R11ReturnCodes.Successful)
{
log.Info("Detected invalid AM2R_11 zip with following error code: " + returnCode);
HelperMethods.RecursiveRollover(CrossPlatformOperations.CURRENTPATH + "/AM2R_11.zip");
HelperMethods.RecursiveRollover(am2r11file);
isAM2R11InstalledCache = false;
return false;
}
@ -304,6 +306,11 @@ namespace AM2RLauncher
/// </summary>
public static void InvalidateAM2R11InstallCache()
{
// If the file exists, and its hash matches with ours, don't invalidate
if (File.Exists(CrossPlatformOperations.CURRENTPATH + "/AM2R_11.zip") &&
HelperMethods.CalculateMD5(CrossPlatformOperations.CURRENTPATH + "/AM2R_11.zip") == lastAM2R11ZipMD5)
return;
isAM2R11InstalledCache = null;
}

@ -95,6 +95,12 @@ namespace AM2RLauncher
/// </summary>
static private bool? isAM2R11InstalledCache = null;
/// <summary>
/// Caches the MD5 hash of the provided AM2R_11.zip so we don't end up checking the zip if it hasn't changed.
/// </summary>
//TODO: worth reading / writing to config?
static private string lastAM2R11ZipMD5 = "";
/// <summary>
/// Checks if the AM2RLauncher is run via WINE.
/// </summary>

Loading…
Cancel
Save