Make am2r_11 validation more efficient

pull/27/head
Miepee 5 years ago
parent a5d6b0df2a
commit 41995cad2d

@ -181,8 +181,8 @@ namespace AM2RLauncher
ProfileXML prof = Serializer.Deserialize<ProfileXML>(File.ReadAllText(dir.FullName + "/profile.xml")); ProfileXML prof = Serializer.Deserialize<ProfileXML>(File.ReadAllText(dir.FullName + "/profile.xml"));
if (prof.Installable == true || IsProfileInstalled(prof)) // Safety check for non-installable profiles if (prof.Installable == true || IsProfileInstalled(prof)) // Safety check for non-installable profiles
{ {
profileList.Add(Serializer.Deserialize<ProfileXML>(File.ReadAllText(dir.FullName + "/profile.xml"))); prof.DataPath = "/Mods/" + dir.Name;
profileList[profileList.Count - 1].DataPath = "/Mods/" + dir.Name; profileList.Add(prof);
} }
else if (!IsProfileInstalled(prof)) // if not installable and isn't installed, remove it else if (!IsProfileInstalled(prof)) // if not installable and isn't installed, remove it
{ {
@ -1077,6 +1077,7 @@ namespace AM2RLauncher
{ {
const string d3dHash = "86e39e9161c3d930d93822f1563c280d"; const string d3dHash = "86e39e9161c3d930d93822f1563c280d";
const string dataWinHash = "f2b84fe5ba64cb64e284be1066ca08ee"; const string dataWinHash = "f2b84fe5ba64cb64e284be1066ca08ee";
const string am2rHash = "15253f7a66d6ea3feef004ebbee9b438";
string tmpPath = Path.GetTempPath() + Path.GetFileNameWithoutExtension(zipPath); string tmpPath = Path.GetTempPath() + Path.GetFileNameWithoutExtension(zipPath);
@ -1084,24 +1085,38 @@ namespace AM2RLauncher
if (Directory.Exists(tmpPath)) if (Directory.Exists(tmpPath))
Directory.Delete(tmpPath, true); Directory.Delete(tmpPath, true);
//extract zip to tmp path first Directory.CreateDirectory(tmpPath);
ZipFile.ExtractToDirectory(zipPath, tmpPath);
// If the game is packed into a subfolder, throw error for that //open archive
if (Directory.GetDirectories(tmpPath).Length == 1 && new DirectoryInfo(Directory.GetDirectories(tmpPath).First()).Name != "lang") ZipArchive am2rZip = ZipFile.OpenRead(zipPath);
return IsZipAM2R11ReturnCodes.GameIsInASubfolder;
// check if exe exists // Check if exe exists anywhere
if (!File.Exists(tmpPath + "/AM2R.exe")) ZipArchiveEntry am2rExe = am2rZip.Entries.FirstOrDefault(x => x.FullName.Contains("AM2R.exe"));
return IsZipAM2R11ReturnCodes.MissingAM2RExe; if (am2rExe == null)
return IsZipAM2R11ReturnCodes.MissingOrInvalidAM2RExe;
// Check if it's not in a subfolder. if it'd be in a subfolder, fullname would be "folder/AM2R.exe"
if (am2rExe.FullName != "AM2R.exe")
return IsZipAM2R11ReturnCodes.GameIsInASubfolder;
// Check validity
am2rExe.ExtractToFile(tmpPath + "/" + am2rExe.FullName);
if (HelperMethods.CalculateMD5(tmpPath + "/" + am2rExe.FullName) != am2rHash)
return IsZipAM2R11ReturnCodes.MissingOrInvalidAM2RExe;
// Check if data.win exists / is valid
ZipArchiveEntry dataWin = am2rZip.Entries.FirstOrDefault(x => x.FullName == "data.win");
if (dataWin == null)
return IsZipAM2R11ReturnCodes.MissingOrInvalidDataWin;
dataWin.ExtractToFile(tmpPath + "/" + dataWin.FullName);
if (HelperMethods.CalculateMD5(tmpPath + "/" + dataWin.FullName) != dataWinHash)
return IsZipAM2R11ReturnCodes.MissingOrInvalidDataWin;
// check if d3d.dll exists, then check the hash of d3d.dll // Check if d3d.dll exists / is valid
if (HelperMethods.CalculateMD5(tmpPath + "/D3DX9_43.dll") != d3dHash) ZipArchiveEntry d3dx = am2rZip.Entries.FirstOrDefault(x => x.FullName == "D3DX9_43.dll");
if (d3dx == null)
return IsZipAM2R11ReturnCodes.MissingOrInvalidD3DX9_43Dll;
d3dx.ExtractToFile(tmpPath + "/" + d3dx.FullName);
if (HelperMethods.CalculateMD5(tmpPath + "/" + d3dx.FullName) != d3dHash)
return IsZipAM2R11ReturnCodes.MissingOrInvalidD3DX9_43Dll; return IsZipAM2R11ReturnCodes.MissingOrInvalidD3DX9_43Dll;
// check if data.win exists and check its hash
if (HelperMethods.CalculateMD5(tmpPath + "/data.win") != dataWinHash)
return IsZipAM2R11ReturnCodes.MissingOrInvalidDataWin;
// clean up // clean up
Directory.Delete(tmpPath, true); Directory.Delete(tmpPath, true);

@ -55,7 +55,7 @@ namespace AM2RLauncher
enum IsZipAM2R11ReturnCodes enum IsZipAM2R11ReturnCodes
{ {
Successful, Successful,
MissingAM2RExe, MissingOrInvalidAM2RExe,
MissingOrInvalidD3DX9_43Dll, MissingOrInvalidD3DX9_43Dll,
MissingOrInvalidDataWin, MissingOrInvalidDataWin,
GameIsInASubfolder GameIsInASubfolder
@ -138,8 +138,7 @@ namespace AM2RLauncher
// Log distro and version (if it exists) // Log distro and version (if it exists)
if (Platform.IsGtk) if (Platform.IsGtk)
{ {
string osRelease = ""; string osRelease = File.ReadAllText("/etc/os-release");
osRelease = File.ReadAllText("/etc/os-release");
Regex lineRegex = new Regex(".*=.*"); Regex lineRegex = new Regex(".*=.*");
var results = lineRegex.Matches(osRelease).Cast<Match>(); var results = lineRegex.Matches(osRelease).Cast<Match>();
var version = results.FirstOrDefault(x => x.Value.Contains("VERSION")); var version = results.FirstOrDefault(x => x.Value.Contains("VERSION"));

Loading…
Cancel
Save