private void buttonPreInstallCheck_Click(object sender, EventArgs e) { clearPreCheckStatus(); buttonPreInstallCheck.Enabled = false; buttonsEnable(false); labelFinalStatus.Text = "Checking..."; labelPreMods.ForeColor = Color.FromKnownColor(KnownColor.LimeGreen); labelPreMods.Text = "Checking..."; Application.DoEvents(); memFiles = Directory.GetFiles(".", "*.mem", SearchOption.AllDirectories).Where(item => item.EndsWith(".mem", StringComparison.OrdinalIgnoreCase)).ToList(); memFiles.Sort(); if (memFiles.Count == 0) { labelPreMods.Text = "No MEM mods found!"; labelPreMods.ForeColor = Color.FromKnownColor(KnownColor.Red); labelFinalStatus.Text = "Preliminary checking failed. Issue detected..."; buttonPreInstallCheck.Enabled = true; buttonsEnable(true); return; } errors = ""; log = ""; for (int i = 0; i < memFiles.Count; i++) { using (FileStream fs = new FileStream(memFiles[i], FileMode.Open, FileAccess.Read)) { uint tag = fs.ReadUInt32(); uint version = fs.ReadUInt32(); if (tag != TexExplorer.TextureModTag || version != TexExplorer.TextureModVersion) { if (version != TexExplorer.TextureModVersion) { errors += "File " + memFiles[i] + " was made with an older version of MEM, skipping..." + Environment.NewLine; } else { errors += "File " + memFiles[i] + " is not a valid MEM mod, skipping..." + Environment.NewLine; } continue; } else { uint gameType = 0; fs.JumpTo(fs.ReadInt64()); gameType = fs.ReadUInt32(); if (gameType != gameId) { errors += "File " + memFiles[i] + " is not a MEM mod valid for this game, skipping..." + Environment.NewLine; continue; } } } } string filename = "errors-precheck.txt"; if (File.Exists(filename)) { File.Delete(filename); } if (errors != "") { labelPreMods.Text = "There are some errors while detecting MEM mods!"; labelPreMods.ForeColor = Color.FromKnownColor(KnownColor.Red); labelFinalStatus.Text = "Preliminary checking failed. Issue detected..."; buttonPreInstallCheck.Enabled = true; buttonsEnable(true); if (File.Exists(filename)) { File.Delete(filename); } using (FileStream fs = new FileStream(filename, FileMode.CreateNew)) { fs.WriteStringASCII(errors); } Process.Start(filename); return; } labelPreMods.ForeColor = Color.FromKnownColor(KnownColor.LimeGreen); labelPreMods.Text = ""; checkBoxPreMods.Checked = true; labelPreGamePath.ForeColor = Color.FromKnownColor(KnownColor.LimeGreen); labelPreGamePath.Text = "Checking..."; Application.DoEvents(); gameData = new GameData((MeType)gameId, configIni); labelPrePath.Text = GameData.GamePath; if (!Directory.Exists(GameData.GamePath)) { labelPreGamePath.Text = "Game path is wrong!"; labelPreGamePath.ForeColor = Color.FromKnownColor(KnownColor.Red); labelFinalStatus.Text = "Preliminary checking failed. Issue detected..."; buttonPreInstallCheck.Enabled = true; buttonsEnable(true); return; } if (!gameData.getPackages(true, true)) { labelPreGamePath.Text = "Missing game data!"; labelPreGamePath.ForeColor = Color.FromKnownColor(KnownColor.Red); labelFinalStatus.Text = "Preliminary checking failed. Issue detected..."; buttonPreInstallCheck.Enabled = true; buttonsEnable(true); return; } if (gameId == (int)MeType.ME1_TYPE) { if (!File.Exists(GameData.GamePath + "\\BioGame\\CookedPC\\Startup_int.upk")) { labelPreGamePath.Text = "ME1 game not found!"; labelPreGamePath.ForeColor = Color.FromKnownColor(KnownColor.Red); labelFinalStatus.Text = "Preliminary checking failed. Issue detected..."; buttonPreInstallCheck.Enabled = true; buttonsEnable(true); return; } } if (gameId == (int)MeType.ME2_TYPE) { if (!File.Exists(GameData.GamePath + "\\BioGame\\CookedPC\\Textures.tfc")) { labelPreGamePath.Text = "ME2 game not found!"; labelPreGamePath.ForeColor = Color.FromKnownColor(KnownColor.Red); labelFinalStatus.Text = "Preliminary checking failed. Issue detected..."; buttonPreInstallCheck.Enabled = true; buttonsEnable(true); return; } } if (gameId == (int)MeType.ME3_TYPE) { if (!File.Exists(GameData.GamePath + "\\BIOGame\\PCConsoleTOC.bin")) { labelPreGamePath.Text = "ME3 game not found!"; labelPreGamePath.ForeColor = Color.FromKnownColor(KnownColor.Red); labelFinalStatus.Text = "Preliminary checking failed. Issue detected..."; buttonPreInstallCheck.Enabled = true; buttonsEnable(true); return; } } labelPreGamePath.ForeColor = Color.FromKnownColor(KnownColor.LimeGreen); labelPreGamePath.Text = ""; checkBoxPrePath.Checked = true; labelPreAccess.ForeColor = Color.FromKnownColor(KnownColor.LimeGreen); labelPreAccess.Text = "Checking..."; Application.DoEvents(); bool writeAccess = false; if (Misc.checkWriteAccessDir(GameData.MainData)) { writeAccess = true; } if (gameId == (int)MeType.ME1_TYPE) { if (Misc.checkWriteAccessFile(GameData.GamePath + @"\BioGame\CookedPC\Packages\GameObjects\Characters\Humanoids\HumanMale\BIOG_HMM_HED_PROMorph.upk")) { writeAccess = true; } else { writeAccess = false; } } if (gameId == (int)MeType.ME2_TYPE) { if (Misc.checkWriteAccessFile(GameData.GamePath + @"\BioGame\CookedPC\BioD_CitAsL.pcc")) { writeAccess = true; } else { writeAccess = false; } } if (gameId == (int)MeType.ME3_TYPE) { if (Misc.checkWriteAccessFile(GameData.GamePath + @"\BioGame\CookedPCConsole\BioA_CitSam_000LevelTrans.pcc")) { writeAccess = true; } else { writeAccess = false; } } if (!writeAccess) { labelPreAccess.Text = "Write access denied to game folders!"; labelPreAccess.ForeColor = Color.FromKnownColor(KnownColor.Red); labelFinalStatus.Text = "Preliminary checking failed. Issue detected..."; buttonPreInstallCheck.Enabled = true; buttonsEnable(true); return; } labelPreAccess.ForeColor = Color.FromKnownColor(KnownColor.LimeGreen); labelPreAccess.Text = ""; checkBoxPreAccess.Checked = true; labelPreSpace.ForeColor = Color.FromKnownColor(KnownColor.LimeGreen); labelPreSpace.Text = "Checking..."; Application.DoEvents(); long diskFreeSpace = Misc.getDiskFreeSpace(GameData.GamePath); long diskUsage = 0; for (int i = 0; i < memFiles.Count; i++) { diskUsage += new FileInfo(memFiles[i]).Length; } diskUsage = (long)(diskUsage * 2.5); if (gameId == (int)MeType.ME3_TYPE) { if (Directory.Exists(GameData.DLCData)) { long diskUsageDLC = 0; List <string> sfarFiles = Directory.GetFiles(GameData.DLCData, "Default.sfar", SearchOption.AllDirectories).ToList(); for (int i = 0; i < sfarFiles.Count; i++) { if (File.Exists(Path.Combine(Path.GetDirectoryName(sfarFiles[i]), "Mount.dlc"))) { sfarFiles.RemoveAt(i--); } } for (int i = 0; i < sfarFiles.Count; i++) { diskUsageDLC += new FileInfo(sfarFiles[i]).Length; } diskUsage = (long)(diskUsageDLC * 2.1); } } if (diskUsage > diskFreeSpace) { labelPreSpace.Text = "You have not enough disk space remaining. You need about " + Misc.getBytesFormat(diskUsage) + " free."; labelPreSpace.ForeColor = Color.FromKnownColor(KnownColor.Red); labelFinalStatus.Text = "Preliminary checking failed. Issue detected..."; buttonPreInstallCheck.Enabled = true; buttonsEnable(true); return; } labelPreSpace.ForeColor = Color.FromKnownColor(KnownColor.LimeGreen); labelPreSpace.Text = ""; checkBoxPreSpace.Checked = true; labelPreVanilla.ForeColor = Color.FromKnownColor(KnownColor.LimeGreen); labelPreVanilla.Text = "Checking..."; Application.DoEvents(); if (Misc.detectBrokenMod((MeType)gameId)) { labelPreVanilla.Text = "Detected broken mod!"; labelPreVanilla.ForeColor = Color.FromKnownColor(KnownColor.Red); labelFinalStatus.Text = "Preliminary check detected issue..."; buttonPreInstallCheck.Enabled = true; buttonsEnable(true); return; } if (!checkBoxOptionVanilla.Checked) { errors = Misc.checkGameFiles((MeType)gameId, null, this); } if (errors != "") { using (FileStream fs = new FileStream(filename, FileMode.OpenOrCreate)) { fs.SeekEnd(); fs.WriteStringASCII("=========================================================" + Environment.NewLine); fs.WriteStringASCII("WARNING: looks like the following file(s) are not vanilla" + Environment.NewLine); fs.WriteStringASCII("=========================================================" + Environment.NewLine + Environment.NewLine); fs.WriteStringASCII(errors); } Process.Start(filename); labelPreVanilla.Text = "Game files are not vanilla!"; labelPreVanilla.ForeColor = Color.FromKnownColor(KnownColor.Red); labelFinalStatus.Text = "Preliminary check detected potential issue..."; } else { labelPreVanilla.ForeColor = Color.FromKnownColor(KnownColor.LimeGreen); labelPreVanilla.Text = ""; labelFinalStatus.Text = "Ready to go. Press START button!"; } checkBoxPreVanilla.Checked = true; buttonPreInstallCheck.Enabled = true; buttonsEnable(true); buttonSTART.Enabled = true; }