/// ------------------------------------------------------------------------------------ /// <summary> /// Make sure the stylesheet for the specified object is current. /// </summary> /// <param name="progressDlg">The progress dialog if one is already up.</param> /// ------------------------------------------------------------------------------------ public void EnsureCurrentResource(IAdvInd4 progressDlg) { T doc = LoadDoc(); Guid newVersion = new Guid(); try { newVersion = GetVersion(doc); } catch (Exception e) { ReportInvalidInstallation(string.Format( FrameworkStrings.ksInvalidResourceFileVersion, ResourceFileName), e); } // Get the current version of the settings used in this project. CmResource resource = CmResource.GetResource(ResourceOwner.Cache, ResourceOwner.Hvo, ResourcesFlid, ResourceName); // Re-load the factory settings if they are not at current version. if (resource == null || newVersion != resource.Version) { using (ProgressDialogWithTask dlg = new ProgressDialogWithTask( Application.OpenForms.Count > 0 ? Application.OpenForms[0] : null)) { ProcessResources(dlg, progressDlg, doc); #if DEBUG Debug.Assert(m_fVersionUpdated); #endif } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Sets the new resource version in the DB (if the owner has such a property). /// </summary> /// <param name="newVersion">The new version.</param> /// ------------------------------------------------------------------------------------ protected void SetNewResourceVersion(Guid newVersion) { if (ResourcesFlid != 0) { CmResource.SetResource(ResourceOwner.Cache, ResourceOwner.Hvo, ResourcesFlid, ResourceName, newVersion); } #if DEBUG m_fVersionUpdated = true; #endif }
/// ------------------------------------------------------------------------------------ /// <summary> /// Fixes any orphaned footnotes or pictures caused by TE-8674/TE-8719. /// </summary> /// <returns>List of descriptions of any problems fix or any remaining problems that the /// user might still need to fix</returns> /// ------------------------------------------------------------------------------------ private List <string> FixOrcsWithoutProps() { // If we've already checked this project out and fixed any orphans, we're done. foreach (ICmResource res in m_scr.ResourcesOC) { if (res.Name == ksFixedOrphanedFootnotes && res.Version == kguidFixedOrphanedFootnotes) { return(null); } } List <string> issuesToReport = null; // Do the cleanup. foreach (IScrBook book in m_scr.ScriptureBooksOS) { List <FootnoteOrcLocation> footnotes = new List <FootnoteOrcLocation>(book.FootnotesOS.Count); foreach (IStFootnote footnote in book.FootnotesOS) { footnotes.Add(new FootnoteOrcLocation(footnote)); } List <OrcLocation> parasWithOrcs = new List <OrcLocation>(book.FootnotesOS.Count); BCVRef startRef = new BCVRef(book.CanonicalNum, 0, 0); BCVRef endRef = new BCVRef(startRef); bool foundProblem = FindOrcsWithoutPropsInText(book.TitleOA, null, ref startRef, ref endRef, footnotes, parasWithOrcs); int sectionNumber = 1; foreach (IScrSection section in book.SectionsOS) { startRef = new BCVRef(section.VerseRefStart); endRef = new BCVRef(section.VerseRefEnd); string sLocationFmt = (section.IsIntro) ? "Section {1}, {0}" : "Section {0}"; string sLocation = String.Format(sLocationFmt, "Heading", sectionNumber); foundProblem |= FindOrcsWithoutPropsInText(section.HeadingOA, sLocation, ref startRef, ref endRef, footnotes, parasWithOrcs); sLocation = (section.IsIntro) ? String.Format(sLocationFmt, "Contents", sectionNumber) : null; foundProblem |= FindOrcsWithoutPropsInText(section.ContentOA, sLocation, ref startRef, ref endRef, footnotes, parasWithOrcs); sectionNumber++; } if (!foundProblem) { // Might still have orphaned footnotes, so look through list to check foreach (FootnoteOrcLocation fn in footnotes) { if (fn.location == null) { foundProblem = true; break; } } } if (foundProblem) { if (issuesToReport == null) { issuesToReport = new List <string>(); } FixOrcsWithoutProps(book, parasWithOrcs, footnotes, issuesToReport); } } // Make an entry in the "Resources" so that we know this project has been fixed up. ICmResource resourceFixed = new CmResource(); m_scr.ResourcesOC.Add(resourceFixed); resourceFixed.Name = ksFixedOrphanedFootnotes; resourceFixed.Version = kguidFixedOrphanedFootnotes; return(issuesToReport); }