/// <summary> /// Deletes the entire logs folder. /// </summary> public static void DeleteAllLogs() { if (!Directory.Exists($"{RootPath}/{LogFolder}")) { ModPrompt.CreatePrompt("Log folder doesn't exist.", "MOP"); return; } ModPrompt.CreateYesNoPrompt("Are you sure you want to delete all logs?", "MOP", () => Directory.Delete($"{RootPath}/{LogFolder}", true)); }
public static void VerifySave() { if (!File.Exists(SavePath)) { return; } // Passenger bucket seat. // Check if driver bucket seat is bought and check the same for passenger one. // If they do not match, fix it. try { saveBugs = new List <SaveBugs>(); bool bucketPassengerSeat = ES2.Load <bool>(SavePath + "?tag=bucket seat passenger(Clone)Purchased", setting); bool bucketDriverSeat = ES2.Load <bool>(SavePath + "?tag=bucket seat driver(Clone)Purchased", setting); if (bucketDriverSeat != bucketPassengerSeat) { saveBugs.Add(SaveBugs.New("Bucket Seats", "One bucket seat is present in the game world, while the other isn't - both should be in game world.", () => { ES2.Save(true, SavePath + "?tag=bucket seat passenger(Clone)Purchased"); ES2.Save(true, SavePath + "?tag=bucket seat driver(Clone)Purchased"); })); } } catch (Exception e) { ExceptionManager.New(e, false, "VERIFY_SAVE_BUCKET_SEAT"); } try { bool tractorTrailerAttached = ES2.Load <bool>(SavePath + "?tag=TractorTrailerAttached", setting); Transform flatbedTransform = ES2.Load <Transform>(SavePath + "?tag=FlatbedTransform", setting); Transform kekmetTransform = ES2.Load <Transform>(SavePath + "?tag=TractorTransform", setting); if (tractorTrailerAttached && Vector3.Distance(flatbedTransform.position, kekmetTransform.position) > 5.5f) { saveBugs.Add(SaveBugs.New("Flatbed Trailer Attached", "Trailer and tractor are too far apart from each other - impossible for them to be attached.", () => { ES2.Save(false, SavePath + "?tag=TractorTrailerAttached", new ES2Settings()); })); } } catch (Exception ex) { ExceptionManager.New(ex, false, "VERIFY_SAVE_FLATBED"); } try { // This one applies fix quietly, as it happens so often, // it would be annoying to nag player about that error. if (SaveFileExists) { MopSaveData save = ModSave.Load <MopSaveData>(mopSavePath); bool bumperRearInstalled = ES2.Load <bool>(SavePath + "?tag=bumper rear(Clone)Installed", setting); float bumperTightness = ES2.Load <float>(SavePath + "?tag=Bumper_RearTightness", setting); if (bumperRearInstalled && bumperTightness != save.rearBumperTightness) { ES2.Save(save.rearBumperTightness, SavePath + "?tag=Bumper_RearTightness"); ES2.Save(save.rearBumperBolts, SavePath + "?tag=Bumper_RearBolts"); } } } catch (Exception ex) { ExceptionManager.New(ex, false, "VERIFY_BUMPER_REAR"); } if (saveBugs.Count > 0) { ModPrompt.CreateYesNoPrompt($"MOP found <color=yellow>{saveBugs.Count}</color> problem{(saveBugs.Count > 1 ? "s" : "")} with your save:\n\n" + $"<color=yellow>{string.Join(", ", saveBugs.Select(f => f.BugName).ToArray())}</color>\n\n" + $"Would you like MOP to try and fix {((saveBugs.Count > 1) ? "them" : "it")}?", "MOP - Save Integrity Verification", FixAllProblems); } else { ModConsole.Log("[MOP] MOP didn't find any problems with your save :)"); } }
public void BugReport() { if (Directory.Exists(BugReportPath)) { Directory.Delete(BugReportPath, true); } Directory.CreateDirectory(BugReportPath); // Get output_log.txt if (File.Exists($"{ExceptionManager.RootPath}/output_log.txt")) { File.Copy($"{ExceptionManager.RootPath}/output_log.txt", $"{BugReportPath}/output_log.txt"); } // Now we are getting logs generated today. string today = DateTime.Now.ToString("yyyy-MM-dd"); foreach (string log in Directory.GetFiles(ExceptionManager.LogFolder, $"*{today}*.txt")) { string pathToFile = log.Replace("\\", "/"); string nameOfFile = log.Split('\\')[1]; ModConsole.Log(nameOfFile); File.Copy(pathToFile, $"{BugReportPath}/{nameOfFile}"); } // Generate a MOP report. using (StreamWriter sw = new StreamWriter($"{BugReportPath}/MOP_REPORT.txt")) { sw.WriteLine(ExceptionManager.GetGameInfo()); } // Now we are packing up everything. string lastZipFilePath = $"{BugReportPath}/MOP Bug Report - {DateTime.Now:yyyy-MM-dd_HH-mm}.zip"; using (ZipFile zip = new ZipFile()) { foreach (string file in Directory.GetFiles(BugReportPath, "*.txt")) { zip.AddFile(file, ""); } zip.Save(lastZipFilePath); } // Now we are deleting all .txt files. foreach (string file in Directory.GetFiles(BugReportPath, "*.txt")) { File.Delete(file); } // Create the tutorial. using (StreamWriter sw = new StreamWriter($"{BugReportPath}/README.txt")) { sw.WriteLine("A MOP report archive has been successfully generated.\n"); sw.WriteLine("Upload .zip file to some file hosting site, such as https://www.mediafire.com/. \n\n" + "Remember to describe how you stumbled uppon the error!"); } // We are asking the user if he wants to add his game save to the zip file. if (File.Exists(SaveManager.SavePath)) { ModPrompt.CreateYesNoPrompt("Would you like to your include save file?\n\n" + "This may greatly improve finding and fixing the bug.", "MOP - Bug Report", () => { using (ZipFile zip = ZipFile.Read(lastZipFilePath)) { // Create folder called Save in the zip and get defaultES2Save.txt and items.txt. zip.AddDirectoryByName("Save"); if (File.Exists(SaveManager.SavePath)) { zip.AddFile(SaveManager.SavePath, "Save"); } if (File.Exists(SaveManager.ItemsPath)) { zip.AddFile(SaveManager.ItemsPath, "Save"); } zip.Save(); } }, onPromptClose: () => { Process.Start(BugReportPath); Process.Start($"{BugReportPath}/README.txt"); }); } }