public ProblemCheckView() { InitializeComponent(); var appStyle = ThemeManager.DetectAppStyle(Application.Current); if (((AppTheme)appStyle.Item1).Name.Equals("BaseDark")) { textColor = "White"; secondaryTextColor = "LightBlue"; } _gameDirectory = new DirectoryInfo(Properties.Settings.Default.FFXIV_Directory); _problemChecker = new ProblemChecker(_gameDirectory); RunChecks(); }
private async void Menu_Backup_Click(object sender, RoutedEventArgs e) { var result = FlexibleMessageBox.Show(UIMessages.CreateBackupsMessage, UIMessages.CreateBackupsTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (result == System.Windows.Forms.DialogResult.Yes) { var gameDirectory = new DirectoryInfo(Settings.Default.FFXIV_Directory); var problemChecker = new ProblemChecker(gameDirectory); var backupsDirectory = new DirectoryInfo(Properties.Settings.Default.Backup_Directory); try { await problemChecker.BackupIndexFiles(backupsDirectory); } catch (Exception ex) { FlexibleMessageBox.Show(string.Format(UIMessages.BackupFailedErrorMessage, ex.Message), UIMessages.BackupFailedTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning); } await this.ShowMessageAsync(UIMessages.BackupCompleteTitle, UIMessages.BackupCompleteMessage); } }
private async Task <bool> CheckIndexFiles() { var xivDataFiles = new XivDataFile[] { XivDataFile._0A_Exd, XivDataFile._01_Bgcommon, XivDataFile._04_Chara, XivDataFile._06_Ui }; var problemChecker = new ProblemChecker(_gameDirectory); try { foreach (var xivDataFile in xivDataFiles) { var errorFound = await problemChecker.CheckIndexDatCounts(xivDataFile); if (errorFound) { await problemChecker.RepairIndexDatCounts(xivDataFile); } } } catch (Exception ex) { var result = FlexibleMessageBox.Show("A critical error occurred when attempting to read the FFXIV index files.\n\nWould you like to restore your index backups?\n\nError: " + ex.Message, "Critical Index Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); if (result == DialogResult.Yes) { var indexBackupsDirectory = new DirectoryInfo(Settings.Default.Backup_Directory); var success = await problemChecker.RestoreBackups(indexBackupsDirectory); if (!success) { FlexibleMessageBox.Show("Unable to restore Index Backups, shutting down TexTools.", "Critical Error Shutdown", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); return(false); } } else { FlexibleMessageBox.Show("Shutting Down TexTools.", "Critical Error Shutdown", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); return(false); } } return(true); }
/// <summary> /// Event handler for the start over menu item clicked /// </summary> private async void Menu_StartOver_Click(object sender, RoutedEventArgs e) { var gameDirectory = new DirectoryInfo(Settings.Default.FFXIV_Directory); var index = new Index(gameDirectory); if (index.IsIndexLocked(XivDataFile._0A_Exd)) { FlexibleMessageBox.Show(UIMessages.IndexLockedErrorMessage, UIMessages.IndexLockedErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var result = FlexibleMessageBox.Show(UIMessages.StartOverMessage, UIMessages.StartOverTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (result == System.Windows.Forms.DialogResult.Yes) { var indexBackupsDirectory = new DirectoryInfo(Settings.Default.Backup_Directory); if (!Directory.Exists(indexBackupsDirectory.FullName)) { FlexibleMessageBox.Show(UIMessages.BackupFolderAccessErrorMessage, UIMessages.IndexBackupsErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var problemChecker = new ProblemChecker(gameDirectory); var progressController = await this.ShowProgressAsync(UIStrings.Start_Over, UIMessages.PleaseStandByMessage); progressController.SetIndeterminate(); IProgress <string> progress = new Progress <string>((update) => { progressController.SetMessage(update); }); try { await problemChecker.PerformStartOver(indexBackupsDirectory, progress, XivLanguages.GetXivLanguage(Settings.Default.Application_Language)); } catch { FlexibleMessageBox.Show(UIMessages.StartOverErrorMessage, UIMessages.StartOverErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); await progressController.CloseAsync(); return; } MainWindow.GetMainWindow().RefreshTree(this); await progressController.CloseAsync(); var c = (ItemTreeView.SelectedItem as Category); UpdateViews(c); await this.ShowMessageAsync(UIMessages.StartOverCompleteTitle, UIMessages.StartOverCompleteMessage); } }
public Builder(OptimizationProblem optimizationProblem) { ProblemChecker.Check(optimizationProblem); this.optimizationProblem = optimizationProblem; }
/// <summary> /// Performs post-patch modlist corrections and validation, prompting user also to generate backups after a successful completion. /// </summary> /// <returns></returns> public async Task DoPostPatchCleanup() { FlexibleMessageBox.Show(_mainWindow.Win32Window, UIMessages.PatchDetectedMessage, "Post Patch Cleanup Starting", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); MainWindow.MakeHighlander(); var resetLumina = false; await _mainWindow.LockUi("Performing Post-Patch Maintenence", "This may take a few minutes if you have many mods installed.", this); var gi = XivCache.GameInfo; if (XivCache.GameInfo.UseLumina) { resetLumina = true; XivCache.SetGameInfo(gi.GameDirectory, gi.GameLanguage, gi.DxMode, false, false, gi.LuminaDirectory, gi.UseLumina); } var workerStatus = XivCache.CacheWorkerEnabled; if (workerStatus) { // Stop the cache worker if it's running. XivCache.CacheWorkerEnabled = false; } try { var modding = new Modding(_gameDirectory); var _index = new Index(_gameDirectory); var _dat = new Dat(_gameDirectory); var validTypes = new List <int>() { 2, 3, 4 }; // We have to do a few things here. // 1. Save a list of what mods were enabled. // 2. Go through and validate everything that says it is enabled actually is enabled, or mark it as disabled and update its original index offset if it is not. // 3. Prompt the user for either a full disable and backup creation, or a restore to normal state (re-enable anything that was enabled before but is not now) var modList = modding.GetModList(); Dictionary <XivDataFile, IndexFile> indexFiles = new Dictionary <XivDataFile, IndexFile>(); // Cache our currently enabled stuff. List <Mod> enabledMods = modList.Mods.Where(x => x.enabled == true).ToList(); var toRemove = new List <Mod>(); foreach (var mod in modList.Mods) { if (!String.IsNullOrEmpty(mod.fullPath)) { var df = IOUtil.GetDataFileFromPath(mod.fullPath); if (!indexFiles.ContainsKey(df)) { indexFiles[df] = await _index.GetIndexFile(df); } var index1Value = indexFiles[df].Get8xDataOffset(mod.fullPath); var index2Value = indexFiles[df].Get8xDataOffsetIndex2(mod.fullPath); var oldOriginalOffset = mod.data.originalOffset; var modOffset = mod.data.modOffset; // In any event where an offset does not match either of our saved offsets, we must assume this is a new // default file offset for post-patch. if (index1Value != oldOriginalOffset && index1Value != modOffset && index1Value != 0) { // Index 1 value is our new base offset. var type = _dat.GetFileType(index1Value, df); // Make sure the file it's trying to point to is actually valid. if (validTypes.Contains(type)) { mod.data.originalOffset = index1Value; mod.enabled = false; } else { // Oh dear. The new index is f****d. Is the old Index Ok? type = _dat.GetFileType(oldOriginalOffset, df); if (validTypes.Contains(type) && oldOriginalOffset != 0) { // Old index is fine, so keep using that. // But mark the index value as invalid, so that we stomp on the index value after this. index1Value = -1; mod.enabled = false; } else { // Okay... Maybe the new Index2 Value? if (index2Value != 0) { type = _dat.GetFileType(index2Value, df); if (validTypes.Contains(type)) { // Set the index 1 value to invalid so that the if later down the chain stomps the index1 value. index1Value = -1; mod.data.originalOffset = index2Value; mod.enabled = false; } else { // We be f****d. throw new Exception("Unable to determine working original offset for file:" + mod.fullPath); } } else { // We be f****d. throw new Exception("Unable to determine working original offset for file:" + mod.fullPath); } } } } else if (index2Value != oldOriginalOffset && index2Value != modOffset && index2Value != 0) { // Our Index 1 was normal, but our Index 2 is changed to an unknown value. // If the index 2 points to a valid file, we must assume that this new file // is our new base data offset. var type = _dat.GetFileType(index2Value, df); if (validTypes.Contains(type) && index2Value != 0) { mod.data.originalOffset = index2Value; mod.enabled = false; } else { // Oh dear. The new index is f****d. Is the old Index Ok? type = _dat.GetFileType(oldOriginalOffset, df); if (validTypes.Contains(type) && oldOriginalOffset != 0) { // Old index is fine, so keep using that, but set the index2 value to invalid to ensure we // stomp on the current broken index value. index2Value = -1; } else { // We be f****d. throw new Exception("Unable to determine working original offset for file:" + mod.fullPath); } } } // Indexes don't match. This can occur if SE adds something to index2 that didn't exist in index2 before. if (index1Value != index2Value && index2Value != 0) { // We should never actually get to this state for file-addition mods. If we do, uh.. I guess correct the indexes and yolo? // ( Only way we get here is if SE added a new file at the same name as a file the user had created via modding, in which case, it's technically no longer a file addition mod ) indexFiles[df].SetDataOffset(mod.fullPath, mod.data.originalOffset); index1Value = mod.data.originalOffset; index2Value = mod.data.originalOffset; mod.enabled = false; } // Set it to the corrected state. if (index1Value == mod.data.modOffset) { mod.enabled = true; } else { mod.enabled = false; } // Perform a basic file type check on our results. var fileType = _dat.GetFileType(mod.data.modOffset, IOUtil.GetDataFileFromPath(mod.fullPath)); var originalFileType = _dat.GetFileType(mod.data.modOffset, IOUtil.GetDataFileFromPath(mod.fullPath)); if (!validTypes.Contains(fileType) || mod.data.modOffset == 0) { // Mod data is busted. Fun. toRemove.Add(mod); } if ((!validTypes.Contains(originalFileType)) || mod.data.originalOffset == 0) { if (mod.IsCustomFile()) { // Okay, in this case this is recoverable as the mod is a custom addition anyways, so we can just delete it. if (!toRemove.Contains(mod)) { toRemove.Add(mod); } } else { // Update ended up with us unable to find a working offset. Double fun. throw new Exception("Unable to determine working offset for file:" + mod.fullPath); } } } // Okay, this mod is now represented in the modlist in it's actual post-patch index state. var datNum = (int)((mod.data.modOffset / 8) & 0x0F) / 2; var dat = XivDataFiles.GetXivDataFile(mod.datFile); var originalDats = await _dat.GetUnmoddedDatList(dat); var datPath = $"{dat.GetDataFileName()}{Dat.DatExtension}{datNum}"; // Test for SE Dat file rollover. if (originalDats.Contains(datPath)) { // Shit. This means that the dat file where this mod lived got eaten by SE. We have to destroy the modlist entry at this point. toRemove.Add(mod); } } // Save any index changes we made. foreach (var dkv in indexFiles) { await _index.SaveIndexFile(dkv.Value); } // The modlist is now saved in its current index-represented post patch state. modding.SaveModList(modList); // We now need to clear out any mods that are irreparably f****d, and clear out all of our // internal data files so we can rebuild them later. var internalFiles = modList.Mods.Where(x => x.IsInternal()); toRemove.AddRange(internalFiles); if (toRemove.Count > 0) { var removedString = ""; // Soft-Disable all metadata mods, since we're going to purge their internal file entries. var metadata = modList.Mods.Where(x => x.fullPath.EndsWith(".meta") || x.fullPath.EndsWith(".rgsp")); foreach (var mod in metadata) { var df = IOUtil.GetDataFileFromPath(mod.fullPath); await modding.ToggleModUnsafe(false, mod, true, false, indexFiles[df], modList); } foreach (var mod in toRemove) { if (mod.data.modOffset == 0 || mod.data.originalOffset == 0) { if (mod.data.originalOffset == 0 && mod.enabled) { // This is awkward. We have a mod whose data got bashed, but has no valid original offset to restore. // So the indexes here are f****d if we do, f****d if we don't. throw new Exception("Patch-Broken file has no valid index to restore. Clean Index Restoration required."); } modList.Mods.Remove(mod); enabledMods.Remove(mod); removedString += mod.fullPath + "\n"; } else { if (mod.enabled) { var df = IOUtil.GetDataFileFromPath(mod.fullPath); await modding.ToggleModUnsafe(false, mod, true, false, indexFiles[df], modList); } modList.Mods.Remove(mod); // Since we're deleting this entry entirely, we can't leave it in the other cached list either to get re-enabled later. enabledMods.Remove(mod); if (!mod.IsInternal()) { removedString += mod.fullPath + "\n"; } } } // Save the index files and modlist again now that we've removed all the invalid entries. foreach (var dkv in indexFiles) { await _index.SaveIndexFile(dkv.Value); } modding.SaveModList(modList); // Show the user a message if we purged any real files. if (toRemove.Any(x => !String.IsNullOrEmpty(x.fullPath) && !x.IsInternal())) { var text = String.Format(UIMessages.PatchDestroyedFiles, removedString); FlexibleMessageBox.Show(_mainWindow.Win32Window, text, "Destroyed Files Notification", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); } } // Always create clean index backups after this process is completed. _mainWindow.LockProgress.Report("Disabling Mods..."); await modding.ToggleAllMods(false); _mainWindow.LockProgress.Report("Creating Index Backups..."); var pc = new ProblemChecker(_gameDirectory); DirectoryInfo backupDir; try { Directory.CreateDirectory(Settings.Default.Backup_Directory); backupDir = new DirectoryInfo(Settings.Default.Backup_Directory); } catch { throw new Exception("Unable to create index backups.\nThe Index Backup directory is invalid or inaccessible: " + Settings.Default.Backup_Directory); } await pc.BackupIndexFiles(backupDir); // Now restore the modlist enable/disable state back to how the user had it before. _mainWindow.LockProgress.Report("Re-Enabling mods..."); // Re-enable things. await modding.ToggleMods(true, enabledMods.Select(x => x.fullPath)); FlexibleMessageBox.Show(_mainWindow.Win32Window, UIMessages.PostPatchComplete, "Post-Patch Process Complete", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); } catch (Exception Ex) { // Show the user the error, then let them go about their business of fixing things. FlexibleMessageBox.Show(_mainWindow.Win32Window, String.Format(UIMessages.PostPatchError, Ex.Message), "Post-Patch Failure", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); } finally { if (resetLumina) { // Reset lumina mode back to on if we disabled it to perform update checks. XivCache.SetGameInfo(gi.GameDirectory, gi.GameLanguage, gi.DxMode, true, false, gi.LuminaDirectory, true); } XivCache.CacheWorkerEnabled = workerStatus; await _mainWindow.UnlockUi(this); } }
/// <summary> /// Event handler for the start over menu item clicked /// </summary> private async void Menu_StartOver_Click(object sender, RoutedEventArgs e) { var gameDirectory = new DirectoryInfo(Settings.Default.FFXIV_Directory); var index = new Index(gameDirectory); var outdated = false; if (index.IsIndexLocked(XivDataFile._0A_Exd)) { FlexibleMessageBox.Show(UIMessages.IndexLockedErrorMessage, UIMessages.IndexLockedErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var result = FlexibleMessageBox.Show(UIMessages.StartOverMessage, UIMessages.StartOverTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (result == System.Windows.Forms.DialogResult.Yes) { var indexBackupsDirectory = new DirectoryInfo(Settings.Default.Backup_Directory); if (!Directory.Exists(indexBackupsDirectory.FullName)) { FlexibleMessageBox.Show(UIMessages.BackupFolderAccessErrorMessage, UIMessages.IndexBackupsErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var filesToCheck = new XivDataFile[] { XivDataFile._01_Bgcommon, XivDataFile._04_Chara, XivDataFile._06_Ui }; var problemChecker = new ProblemChecker(gameDirectory); foreach (var xivDataFile in filesToCheck) { var backupFile = new DirectoryInfo($"{indexBackupsDirectory.FullName}\\{xivDataFile.GetDataFileName()}.win32.index"); if (!File.Exists(backupFile.FullName)) { continue; } var outdatedCheck = await problemChecker.CheckForOutdatedBackups(xivDataFile, indexBackupsDirectory); if (!outdatedCheck) { FlexibleMessageBox.Show(UIMessages.OutdatedBackupsErrorMessage, UIMessages.IndexBackupsErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); outdated = true; } } await Task.Run(async() => { var modding = new Modding(gameDirectory); await modding.DeleteAllFilesAddedByTexTools(); var dat = new Dat(gameDirectory); var modListDirectory = new DirectoryInfo(Path.Combine(gameDirectory.Parent.Parent.FullName, XivStrings.ModlistFilePath)); var backupFiles = Directory.GetFiles(indexBackupsDirectory.FullName); // Make sure backups exist if (backupFiles.Length == 0) { FlexibleMessageBox.Show(string.Format(UIMessages.NoBackupsFoundErrorMessage, indexBackupsDirectory.FullName), UIMessages.BackupFilesMissingTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning); // Toggle off all mods await modding.ToggleAllMods(false); } else if (outdated) { // Toggle off all mods await modding.ToggleAllMods(false); } else { // Copy backups to ffxiv folder foreach (var backupFile in backupFiles) { if (backupFile.Contains(".win32.index")) { File.Copy(backupFile, $"{gameDirectory}/{Path.GetFileName(backupFile)}", true); } } } // Delete modded dat files foreach (var xivDataFile in (XivDataFile[])Enum.GetValues(typeof(XivDataFile))) { var datFiles = await dat.GetModdedDatList(xivDataFile); foreach (var datFile in datFiles) { File.Delete(datFile); } if (datFiles.Count > 0) { await problemChecker.RepairIndexDatCounts(xivDataFile); } } // Delete mod list File.Delete(modListDirectory.FullName); modding.CreateModlist(); }); UpdateViews(ItemTreeView.SelectedItem as Category); await this.ShowMessageAsync(UIMessages.StartOverCompleteTitle, UIMessages.StartOverCompleteMessage); } }
public IOptimizationAlgorithm Build() { ProblemChecker.Check(optimizationProblem); return(new DifferentialEvolutionAlgorithm(optimizationProblem, PopulationSize, MutationFactor, CrossoverProbability, ConvergenceCriterion, RandomNumberGenerator)); }
public static Problem Parse(string filePath, char problemLetter, string problemColor) { var zip = ZipFile.OpenRead(filePath); var zipEntries = zip.Entries.ToArray(); var xmlEntry = zip.GetEntry("problem.xml") ?? throw new Exception("problem.xml not found"); var problemXml = XDocument.Load(xmlEntry.Open()); // Problem element var problemElem = problemXml.Root; AssertNoOtherAttributes(problemElem, "url", "short-name", "revision"); AssertNoOtherChildren(problemElem, "names", "statements", "tutorials", "judging", "files", "assets", "properties", "stresses", "documents", "tags"); var problemId = problemElem.Attribute("short-name").Value; // Problem names collection var problemNamesElem = SingleChild(problemElem, "names"); AssertNoAttributes(problemNamesElem); AssertNoOtherChildren(problemNamesElem, "name"); // Problem names children var problemNamesElems = problemNamesElem.Elements("name"); var problemNameElem = problemNamesElems.SingleOrDefault(e => { AssertNoChildren(e); AssertNoOtherAttributes(e, "language", "value"); return(e.Attribute("language").Value == "english"); }) ?? throw new Exception("Problem name in English not found."); var problemName = problemNameElem.Attribute("value").Value; // We ignore tutorials // Judging info var judgingElem = SingleChild(problemElem, "judging"); AssertNoOtherAttributes(judgingElem, "cpu-name", "cpu-speed", "input-file", "output-file"); //AssertAttributeIs(judgingElem, "cpu-speed", "3600"); AssertAttributeIs(judgingElem, "input-file", ""); AssertAttributeIs(judgingElem, "output-file", ""); AssertNoOtherChildren(judgingElem, "testset"); var problemTests = judgingElem.Elements("testset").Select(testSetsElem => { AssertNoOtherAttributes(testSetsElem, "name"); AssertNoOtherChildren(testSetsElem, "time-limit", "memory-limit", "test-count", "input-path-pattern", "answer-path-pattern", "tests"); AssertDirectChildrenHaveNoAttributes(testSetsElem); var testsElem = SingleChild(testSetsElem, "tests"); AssertNoOtherChildren(testsElem, "test"); AssertChildrenCountIs(testsElem, int.Parse(testSetsElem.Element("test-count").Value)); return(new { TimeLimit = int.Parse(testSetsElem.Element("time-limit").Value), MemoryLimit = int.Parse(testSetsElem.Element("memory-limit").Value), Tests = testsElem.Elements("test").Select((testElem, idx) => { AssertNoOtherAttributes(testElem, "method", "from-file", "cmd", "sample"); int realIdx = idx + 1; // polygon is 1-based... return new ProblemTestCase( isSample: testElem.Attribute("sample")?.Value == "true", input: ReadZipEntryText(zip.GetEntry(Printf(testSetsElem.Element("input-path-pattern").Value, realIdx))), output: ReadZipEntryText(zip.GetEntry(Printf(testSetsElem.Element("answer-path-pattern").Value, realIdx))) ); }).ToArray() // NOTE: always use eager eval to avoid later errors }); }).Aggregate((a, b) => { if (a.TimeLimit != b.TimeLimit) { throw new Exception("Different time limits per test set are not supported."); } if (a.MemoryLimit != b.MemoryLimit) { throw new Exception("Different memory limits per test set are not supported."); } return(new { TimeLimit = a.TimeLimit, MemoryLimit = b.MemoryLimit, Tests = a.Tests.Concat(b.Tests).ToArray() }); }); // Files var filesElem = SingleChild(problemElem, "files"); AssertNoAttributes(filesElem); AssertNoOtherChildren(filesElem, "resources", "executables"); // we ignore executables var resourcesElem = SingleChild(filesElem, "resources"); AssertNoAttributes(resourcesElem); AssertNoOtherChildren(resourcesElem, "file"); var allFiles = resourcesElem.Elements("file").Select(fileElem => { AssertNoOtherAttributes(fileElem, "type", "path"); AssertNoChildren(fileElem); var path = fileElem.Attribute("path").Value; AssertFileHasType(path, "h", "cpp", "sty", "tex", "ftl"); return(path); }); var cppAndHFiles = allFiles.Where(s => s.EndsWith(".h") || s.EndsWith(".cpp")).Select(path => ReadZipEntry(zip.GetEntry(path)) ); // Assets var assetsElem = SingleChild(problemElem, "assets"); AssertNoAttributes(assetsElem); AssertNoOtherChildren(assetsElem, "checker", "validators", "solutions"); var checkerElem = SingleChild(assetsElem, "checker"); AssertNoOtherAttributes(checkerElem, "name", "type"); AssertAttributeIs(checkerElem, "type", "testlib"); AssertNoOtherChildren(checkerElem, "source", "binary", "copy", "testset"); // We ignore copy and testset var checkerSourceElem = SingleChild(checkerElem, "source"); AssertNoOtherAttributes(checkerSourceElem, "type", "path"); AssertNoChildren(checkerSourceElem); var checkerSourceEntry = zip.GetEntry(checkerSourceElem.Attribute("path").Value); var checkerFile = ReadZipEntry(checkerSourceEntry); var problemChecker = new ProblemChecker( language: ParseProgrammingLanguage(checkerSourceElem.Attribute("type").Value), files: cppAndHFiles.Append(checkerFile).ToImmutableArray(), mainFile: checkerFile ); // Statement var statementsElem = SingleChild(problemElem, "statements"); AssertNoAttributes(statementsElem); AssertNoOtherChildren(statementsElem, "statement"); var statementPath = statementsElem.Elements("statement").Where(s => s.Attribute("language").Value == "english").Single(statementElem => { AssertNoOtherAttributes(statementElem, "language", "path", "type", "charset", "mathjax"); AssertNoChildren(statementElem); return(statementElem.Attribute("type").Value == "application/pdf"); }).Attribute("path").Value; // solutions var solutions = new List <(ProblemFile, ProblemJudgement)>(); var solutionsElem = SingleChild(assetsElem, "solutions"); foreach (var sol in solutionsElem.Elements()) { var result = sol.Attribute("tag").Value; var j = result == "accepted" ? ProblemJudgement.Accepted : result == "main" ? ProblemJudgement.Accepted : result == "wrong-answer" ? ProblemJudgement.WrongAnswer : result == "time-limit-exceeded" ? ProblemJudgement.TimeLimit : ProblemJudgement.OtherError; var source = sol.Element("source").Attribute("path").Value; solutions.Add((ReadZipEntry(zip.GetEntry(source)), j)); } // We ignore properties, stresses and documents return(new Problem( id: problemLetter.ToString(), name: problemName, color: problemColor, statement: ReadZipEntry(zip.GetEntry(statementPath)), checker: problemChecker, limits: new ProblemLimits(problemTests.TimeLimit / 1000.0M, problemTests.MemoryLimit), testCases: problemTests.Tests.ToImmutableArray(), solutions: solutions.ToImmutableArray() )); }