public static void GetParatextProjects() { var apiFolder = Util.ApiFolder(); if (!ParatextInfo.IsParatextInstalled) { return; } try { ParatextData.Initialize(); var paratextProjects = ScrTextCollection.ScrTexts(IncludeProjects.ScriptureOnly); if (paratextProjects == null) { return; } var jsonList = ParatextProjectsJsonList(paratextProjects); using (var sw = new StreamWriter(Path.Combine(apiFolder, "GetParatextProjects"))) { sw.Write($"[{string.Join(",", jsonList)}]"); } } catch (Exception ex) { string error = ex.Message; Debug.Print(error); Logger.WriteEvent(error); } }
/// -------------------------------------------------------------------------------- /// <summary> /// Gets the list of Paratext projects. /// </summary> /// -------------------------------------------------------------------------------- public IEnumerable <ScrText> GetProjects() { RefreshProjects(); if (m_IsParatextInitialized) { try { // The booleans say we are including resources (translations etc that are part of the Paratext release) // and non-Scripture items (not sure what these are). // Most likely neither of these are necessary, but I'm preserving the behavior we had with 7.3, // which did not have these arguments. // We also filter out invalid ScrTexts, because there is a bug in Paratext that allows them to get through. return(ScrTextCollection.ScrTexts(true, true).Where(st => Directory.Exists(st.Directory))); } catch (Exception e) { Logger.WriteError(e); m_IsParatextInitialized = false; } } return(new ScrText[0]); }
private void SelectTexts() { // Create list of current items List <ScrText> currentItems = new List <ScrText>(); foreach (TextCollectionItem item in m_textCollection.Items) { currentItems.Add(item.ScrText); } TextCollectionItem currentItem = null; if (m_textCollection.CurItem >= 0 && m_textCollection.CurItem < m_textCollection.Items.Count) { currentItem = m_textCollection.Items[m_textCollection.CurItem]; } // Re-initialize, just in case. // We pass the directory (rather than passing no arguments, and letting the paratext dll figure // it out) because the figuring out goes wrong on Linux, where both programs are simulating // the registry. ScrTextCollection.Initialize(ParatextHelper.ProjectsDirectory, false); List <string> textNames = ScrTextCollection.ScrTextNames; foreach (string nameVar in textNames) { if (nameVar.Length < 1) { continue; } string name = nameVar.ToLower(); // Ignore P6 source language texts. if (name == "lxx" || name == "grk" || name == "heb") { continue; } try { if (ScrTextCollection.Get(nameVar) == null) { // REVIEW: I'm not sure how/if ScrTextCollection gets disposed ScrText scrText = new ScrText(nameVar); ScrTextCollection.Add(scrText); } } catch (Exception) { //MessageBox.Show(name + ": " + exception.Message); // TODO What will happen if a text can't be loaded? } } // the two booleans indicate we want all the available texts, including resources (part of the Paratext distribution) // and non-scriptural materials (things like commentaries maybe?) using (ScrTextListSelectionForm selForm = new ScrTextListSelectionForm( ScrTextCollection.ScrTexts(true, true), currentItems)) { if (selForm.ShowDialog(this) == DialogResult.OK) { // Create new list of items, keeping data from old one (to preserve zoom etc) List <TextCollectionItem> newItems = new List <TextCollectionItem>(); foreach (ScrText scrText in selForm.Selections) { // Attempt to find in old list bool found = false; foreach (TextCollectionItem item in m_textCollection.Items) { if (item.ScrText == scrText) { newItems.Add(item); found = true; break; } } if (!found) { newItems.Add(new TextCollectionItem(scrText, 1)); } } m_textCollection.Items = newItems; int curItemIndex = -1; // none selected for (int i = 0; i < newItems.Count; i++) { if (newItems[i] == currentItem) { curItemIndex = i; break; } } // select some current item if possible; out of range does not cause problem. // Currently it seems to cause a crash if the item is out of range for the OLD items; // I think this is a bug in the Paratext code. if (curItemIndex == -1 && m_textCollection.Items.Count > 0 && currentItems.Count > 0) { curItemIndex = 0; } m_textCollection.CurItem = curItemIndex; tryReloadTextCollection(); } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Restore settings (currently the list of texts displayed). /// </summary> /// <param name="key">The key.</param> /// ------------------------------------------------------------------------------------ public void LoadSettings(RegistryKey key) { try { m_floaty.LoadSettings(key); string texts = key.GetValue("UsfmTexts", "") as string; if (string.IsNullOrEmpty(texts)) { return; // foreach below does one iteration for empty string, which is bad. } List <TextCollectionItem> items = new List <TextCollectionItem>(); foreach (string name in texts.Split(',')) { ScrText text = null; try { foreach (ScrText st in ScrTextCollection.ScrTexts(true, true)) { if (st.Name == name) { text = st; break; } } } catch (Exception) { // If we for some reason can't make that text, carry on with the others. continue; } if (text == null) { continue; // forget any saved item that is no longer an option. } items.Add(new TextCollectionItem(text, 1.0)); } m_textCollection.Items = items; string curItemName = key.GetValue("UsfmCurItem", "") as string; if (string.IsNullOrEmpty(curItemName)) { for (int i = 0; i < m_textCollection.Items.Count; i++) { if (m_textCollection.Items[i].ScrText.Name == curItemName) { m_textCollection.CurItem = i; break; } } } // Paratext now requires a versification for Reload(), // so we'll default to English at this point. m_textCollection.Reference = new VerseRef("MAT 1:1", ScrVers.English); tryReloadTextCollection(); VerseRef vr = new VerseRef("MAT 1:1"); // default string reference = key.GetValue("UsfmCurRef", null) as string; if (!string.IsNullOrEmpty(reference)) { vr = new VerseRef(reference); } m_textCollection.CurItem = (int)key.GetValue("UsfmCurSel", -1); SetScriptureReference(vr); } catch { // ignore any problems. } }
public IEnumerable <IScrText> ScrTexts() { return(ScriptureProvider.WrapPtCollection(ScrTextCollection.ScrTexts(IncludeProjects.ScriptureOnly), new Func <ScrText, IScrText>(ptText => new PT8ScrTextWrapper(ptText)))); }
// Note: This method is very similar to the method by the same name in HearThis' ChooseProject dialog. If improvements // are made here, they should also be made there if applicable. // TODO: Move this into libpalaso private IEnumerable <ScrText> GetParatextProjects() { ScrText[] paratextProjects = null; try { paratextProjects = ScrTextCollection.ScrTexts(IncludeProjects.AccessibleScripture).ToArray(); var loadErrors = Program.CompatibleParatextProjectLoadErrors.ToList(); if (loadErrors.Any()) { StringBuilder sb = new StringBuilder(String.Format(LocalizationManager.GetString("DialogBoxes.OpenProjectDlg.ParatextProjectLoadErrors", "The following {0} project load errors occurred:", "Param 0: \"Paratext\" (product name)"), ParatextScrTextWrapper.kParatextProgramName)); foreach (var errMsgInfo in loadErrors) { sb.Append("\n\n"); try { switch (errMsgInfo.Reason) { case UnsupportedReason.UnknownType: AppendVersionIncompatibilityMessage(sb, errMsgInfo); sb.AppendFormat(LocalizationManager.GetString("DialogBoxes.OpenProjectDlg.ParatextProjectLoadError.UnknownProjectType", "This project has a project type ({0}) that is not supported.", "Param 0: Paratext project type"), errMsgInfo.ProjecType); break; case UnsupportedReason.CannotUpgrade: // Glyssen is newer than project version AppendVersionIncompatibilityMessage(sb, errMsgInfo); sb.AppendFormat(LocalizationManager.GetString("DialogBoxes.OpenProjectDlg.ParatextProjectLoadError.ProjectOutdated", "The project administrator needs to update it by opening it with {0} {1} or later. " + "Alternatively, you might be able to revert to an older version of {2}.", "Param 0: \"Paratext\" (product name); " + "Param 1: Paratext version number; " + "Param 2: \"Glyssen\" (product name)"), ParatextScrTextWrapper.kParatextProgramName, ParatextInfo.MinSupportedParatextDataVersion, GlyssenInfo.kProduct); break; case UnsupportedReason.FutureVersion: // Project version is newer than Glyssen AppendVersionIncompatibilityMessage(sb, errMsgInfo); sb.AppendFormat(LocalizationManager.GetString("DialogBoxes.OpenProjectDlg.ParatextProjectLoadError.GlyssenVersionOutdated", "To read this project, a version of {0} compatible with {1} {2} is required.", "Param 0: \"Glyssen\" (product name); " + "Param 1: \"Paratext\" (product name); " + "Param 2: Paratext version number"), GlyssenInfo.kProduct, ParatextScrTextWrapper.kParatextProgramName, ScrTextCollection.ScrTexts(IncludeProjects.Everything).First( p => p.Name == errMsgInfo.ProjectName).Settings.MinParatextDataVersion); break; case UnsupportedReason.Corrupted: case UnsupportedReason.Unspecified: sb.AppendFormat(LocalizationManager.GetString("DialogBoxes.OpenProjectDlg.ParatextProjectLoadError.Generic", "Project: {0}\nError message: {1}", "Param 0: Paratext project name; Param 1: error details"), errMsgInfo.ProjectName, errMsgInfo.Exception.Message); break; default: throw errMsgInfo.Exception; } } catch (Exception e) { ErrorReport.ReportNonFatalException(e); } } MessageBox.Show(sb.ToString(), Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception err) { NotifyUserOfParatextProblem(String.Format(LocalizationManager.GetString("DialogBoxes.OpenProjectDlg.CantAccessParatext", "There was a problem accessing {0} data files.", "Param: \"Paratext\" (product name)"), ParatextScrTextWrapper.kParatextProgramName), string.Format(LocalizationManager.GetString("DialogBoxes.OpenProjectDlg.ParatextError", "The error was: {0}"), err.Message)); paratextProjects = new ScrText[0]; } // ENHANCE (PG-63): Implement something like this if we decide to give the user the option of manually // specifying the location of Paratext data files if the program isn’t actually installed. // to select the location of Paratext data files. //if (paratextProjects.Any()) //{ // _lblNoParatextProjectsInFolder.Visible = false; // _lblNoParatextProjects.Visible = false; //} //else //{ // if (ParatextInfo.IsParatextInstalled) // _lblNoParatextProjects.Visible = true; // else // { // _lblNoParatextProjectsInFolder.Visible = _tableLayoutPanelParatextProjectsFolder.Visible; // } //} return(paratextProjects); }
public IEnumerable <IScrText> ScrTexts() { return(ScriptureProvider.WrapPtCollection(ScrTextCollection.ScrTexts(true, true), new Func <ScrText, IScrText>(ptText => new PT7ScrTextWrapper(ptText)))); }