Ejemplo n.º 1
0
 /// <summary> Set the directory to the folder containing Paratext projects. </summary>
 public void Initialize(string projectsPath)
 {
     SettingsDirectory = projectsPath;
     // Initialize so that Paratext.Data can find settings files
     ScrTextCollection.Implementation = new SFScrTextCollection();
     ScrTextCollection.Initialize(projectsPath);
 }
Ejemplo n.º 2
0
 /// --------------------------------------------------------------------------------
 /// <summary>
 /// Refreshes the list of Paratext projects.
 /// </summary>
 /// --------------------------------------------------------------------------------
 public void RefreshProjects()
 {
     try
     {
         if (ParatextSettingsDirectoryExists())
         {
             if (!m_IsParatextInitialized)
             {
                 // It is possible that the Projects directory was not available when we first initialized
                 // ScrTextCollection, but it now is (e.g. USB drive plugged or unplugged).  So we initialize
                 // again. ScrTextCollection.Initialize is safe to call multiple times and also refreshes texts.
                 // 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(ParatextSettingsDirectory(), false);
                 m_IsParatextInitialized = true;
             }
             else
             {
                 ScrTextCollection.RefreshScrTexts();
             }
         }
         else
         {
             m_IsParatextInitialized = false;
         }
     }
     catch (Exception e)
     {
         Logger.WriteError(e);
         m_IsParatextInitialized = false;
     }
 }
        public void SetsSettingsDirectory()
        {
            ScrTextCollection.Implementation = new SFScrTextCollection();
            ScrTextCollection.Initialize("/srv/scriptureforge/projects");
            string dir = ScrTextCollection.SettingsDirectory;

            Assert.That(dir, Is.EqualTo("/srv/scriptureforge/projects"));
        }
Ejemplo n.º 4
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Install the control.
        /// </summary>
        /// <param name="dockHost">The control that hosts the browser</param>
        /// <param name="cache">The cache (needed in case we have to create the English LDS file
        /// on the fly)</param>
        /// <param name="normalStyle">The normal style (needed in case we have to create the
        /// English LDS file on the fly)</param>
        /// <returns>
        ///     <c>true</c> if the browser was installed successfully; <c>false</c>
        /// otherwise.
        /// </returns>
        /// ------------------------------------------------------------------------------------
        public bool Install(Control dockHost, FdoCache cache, IStStyle normalStyle)
        {
            while (true)
            {
                try
                {
                    RegistrationInfo.AllowP6RegistrationCode = true;
                    RegistrationInfo.AllowAccessToResources();
                    string paratextProjectDir = ScrImportP6Project.ProjectDir;

                    if (!String.IsNullOrEmpty(paratextProjectDir))
                    {
                        string englishLdsPathname = Path.Combine(paratextProjectDir, "English.lds");
                        if (!File.Exists(englishLdsPathname))
                        {
                            ParatextLdsFileAccessor ldsAccessor     = new ParatextLdsFileAccessor(cache);
                            UsfmStyEntry            normalUsfmStyle = new UsfmStyEntry();
                            StyleInfoTable          styleTable      = new StyleInfoTable(normalStyle.Name,
                                                                                         cache.LanguageWritingSystemFactoryAccessor);
                            normalUsfmStyle.SetPropertiesBasedOnStyle(normalStyle);
                            styleTable.Add(normalStyle.Name, normalUsfmStyle);
                            styleTable.ConnectStyles();
                            ldsAccessor.WriteParatextLdsFile(englishLdsPathname,
                                                             cache.LanguageWritingSystemFactoryAccessor.GetWsFromStr("en"), normalUsfmStyle);
                        }
                    }
                    ScrTextCollection.Initialize();
                    break;
                }
                catch (Exception e)
                {
                    try
                    {
                        ReflectionHelper.SetField(typeof(ScrTextCollection), "initialized", false);
                    }
                    catch (Exception reflectionHelperException)
                    {
                        throw new ContinuableErrorException("Paratext resource browser failed to initialize." +
                                                            Environment.NewLine + reflectionHelperException.Message, e);
                    }
                    if (MessageBox.Show(dockHost.FindForm(), String.Format(
                                            Properties.Resources.kstidCannotDisplayResourcePane,
                                            Application.ProductName, e.Message), Application.ProductName,
                                        MessageBoxButtons.RetryCancel, MessageBoxIcon.Error,
                                        MessageBoxDefaultButton.Button2) != DialogResult.Retry)
                    {
                        return(false);
                    }
                }
            }
            m_toolStrip.Text = "USFM Resource Browser";
            m_extender       = new DockExtender(dockHost);
            dockHost.Controls.Add(this);
            m_floaty = m_extender.Attach(this, m_toolStrip, true);
            this.SendToBack();
            return(true);
        }
Ejemplo n.º 5
0
 static ParatextProxy()
 {
     try
     {
         ScrTextCollection.Initialize();
     }
     catch (Exception e)
     {
         Logger.WriteError(e);
     }
 }
Ejemplo n.º 6
0
 /// <summary/>
 public ParatextHelperAdapter()
 {
     try
     {
         ScrTextCollection.Initialize();
     }
     catch (Exception e)
     {
         Logger.WriteError(e);
     }
 }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            if (args.Length != 5)
            {
                Console.WriteLine("Usage: rdwrtp7 -r|-w project book chapter|0 fileName");
                Environment.Exit(-1);
            }

            ScrTextCollection.Initialize();

            string operation = args[0];
            string project = args[1];
            string book = args[2];
            string chapter = args[3];
            string file = args[4];

            ScrText scr = ScrTextCollection.Get(project);
            if (scr == null)
            {
                Console.WriteLine("Error: unknown project");
                Environment.Exit(-1);
            }

            VerifyBook(book);
            VerifyChapter(chapter);

            VerseRef vref = new VerseRef(book, chapter, "1", scr.Versification);

            try
            {
                if (operation == "-r")
                    DoRead(scr, vref, file);
                else if (operation == "-w")
                    DoWrite(scr, vref, file);
                else
                {
                    Console.WriteLine("Error: unknown operation");
                    Environment.Exit(-1);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Environment.Exit(-1);
            }
        }
Ejemplo n.º 8
0
        /// <summary> Prepare access to Paratext.Data library, authenticate, and prepare Mercurial. </summary>
        public void Init()
        {
            // Uncomment to output more info from ParatextData.dll for investigating.
            // Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));
            // Trace.AutoFlush = true;

            SyncDir = Path.Combine(_siteOptions.Value.SiteDir, "sync");
            if (!_fileSystemService.DirectoryExists(SyncDir))
            {
                _fileSystemService.CreateDirectory(SyncDir);
            }
            // Disable caching VersionedText instances since multiple repos may exist on SF server with the same GUID
            Environment.SetEnvironmentVariable("PTD_CACHE_VERSIONED_TEXT", "DISABLED");
            RegistryU.Implementation = new DotNetCoreRegistry();
            Alert.Implementation     = new DotNetCoreAlert(_logger);
            ParatextDataSettings.Initialize(new PersistedParatextDataSettings());
            PtxUtilsDataSettings.Initialize(new PersistedPtxUtilsSettings());
            SetupMercurial();
            WritingSystemRepository.Initialize();
            ScrTextCollection.Initialize(SyncDir);
            InstallStyles();
            // Allow use of custom versification systems
            Versification.Table.Implementation = new ParatextVersificationTable();
        }
Ejemplo n.º 9
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();
                }
            }
        }
Ejemplo n.º 10
0
 public void Initialize()
 {
     ScrTextCollection.Initialize();
 }
Ejemplo n.º 11
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Method adapted from TextCollectionControl method of same name, to use our dialog.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        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];
            }

            ScrTextCollection.Initialize();             // Re-initialize, just in case
            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)
                    {
                        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?
                }
            }


            ScrTextListSelectionForm selForm = new ScrTextListSelectionForm(
                ScrTextCollection.ScrTexts, 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();
            }
        }