/// <summary> /// Performs mod structure validation, XML and XSD validation, resource validation and expansion requirement validation. /// </summary> /// <returns></returns> public ModValidationResult Validate() { ModValidationResult result = new ModValidationResult(); var modFolder = mod.GetDirectory(@"mod"); if (modFolder == null) { result.ModErrors.Add("The required folder, 'mod', was not found."); return(result); } var modFile = modFolder.GetFile("mod.xml"); if (modFile == null) { result.ModErrors.Add("The required file, 'mod/mod.xml', was not found."); return(result); } var xmlFiles = modFolder.EnumerateXmlFiles(DredmorInfo.XmlFilesToValidate, SearchOption.TopDirectoryOnly); XsdValidator xsd = new XsdValidator(); result.XmlErrors = xsd.Validate(xmlFiles, true); if (!result.IsValid && result.XmlErrors.Any(p => p.XmlExceptionOccurred)) { return(result); } resources.LoadResources(mod); result.XmlErrors.AddRange( XmlResourceValidator.Validate( xmlFiles.Where(p => p.Name.ToLower() != "mod.xml"), resources, ExpansionResourcesUsed ) .Where(p => p.Errors.Count > 0) ); result.ExpansionResourcedUsed = ExpansionResourcesUsed; result.ExpansionNumbersUsed = ExpansionResourcesUsed.Animations.Select(p => p.ExpansionNumber) .Concat(result.ExpansionResourcedUsed.Files.Select(p => p.ExpansionNumber)) .Concat(result.ExpansionResourcedUsed.ContentResources.Select(p => p.ExpansionNumber)) .Distinct() .OrderBy(p => p) .ToList(); AddRequirementErrors(result, modFile); return(result); }
/// <summary> /// Validates all fo the XML files. /// </summary> /// <param name="xmlFiles"></param> /// <param name="resources">An instance of <see cref="GameResources"/> containing all valid resources from the core game and optionally a mod.</param> /// <param name="expansionResourcesUsed">An instance of <see cref="GameResources"/> to which expansion resources found to be used will be added.</param> /// <returns></returns> public static List <XmlFileValidationErrorList> Validate(IEnumerable <ContentFile> xmlFiles, GameResources resources, GameResources expansionResourcesUsed = null) { List <XmlFileValidationErrorList> result = new List <XmlFileValidationErrorList>(); foreach (var file in xmlFiles) { try { XmlResourceValidator res = XmlResourceValidator.Create(file, resources, expansionResourcesUsed); result.Add(res.Validate()); } catch (XmlException ex) { result.Add(new XmlFileValidationErrorList(file.FullName, ex)); } } return(result); }
/// <summary> /// Performs XML and XSD validation. If no files are malformed the performs resource validation. /// </summary> /// <returns></returns> public CoreValidationResult Validate() { CoreValidationResult result = new CoreValidationResult(); var xmlFiles = core.EnumerateXmlFiles(DredmorInfo.XmlFilesToValidate, SearchOption.AllDirectories); XsdValidator xsd = new XsdValidator(); result.XmlErrors = xsd.Validate(xmlFiles, true); if (!result.IsValid && result.XmlErrors.Any(p => p.XmlExceptionOccurred)) { return(result); } resources.LoadResources(core); result.XmlErrors.AddRange( XmlResourceValidator.Validate(xmlFiles, resources) .Where(p => p.Errors.Count > 0) ); return(result); }