Example #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Gets a list of books that exist for all of the files in this project.
        /// </summary>
        /// <returns>A List of integers representing 1-based canonical book numbers that exist
        /// in any source represented by these import settings</returns>
        /// <exception cref="NotSupportedException">If project is not a supported type</exception>
        /// ------------------------------------------------------------------------------------
        public static List <int> BooksForProject(this IScrImportSet importSettings)
        {
            Debug.Assert(importSettings.BasicSettingsExist, "Vernacular Scripture project not defined.");
            switch (importSettings.ImportTypeEnum)
            {
            case TypeOfImport.Paratext6:
                // TODO (TE-5903): Check BT and Notes projects as well.
                return(ParatextHelper.GetProjectBooks(importSettings.ParatextScrProj).ToList());

            case TypeOfImport.Paratext5:
            case TypeOfImport.Other:
                List <int> booksPresent = new List <int>();
                foreach (IScrImportFileInfo file in importSettings.GetImportFiles(ImportDomain.Main))
                {
                    foreach (int iBook in file.BooksInFile)
                    {
                        if (!booksPresent.Contains(iBook))
                        {
                            booksPresent.Add(iBook);
                        }
                    }
                }

                foreach (IScrImportFileInfo file in importSettings.GetImportFiles(ImportDomain.BackTrans))
                {
                    foreach (int iBook in file.BooksInFile)
                    {
                        if (!booksPresent.Contains(iBook))
                        {
                            booksPresent.Add(iBook);
                        }
                    }
                }

                foreach (IScrImportFileInfo file in importSettings.GetImportFiles(ImportDomain.Annotations))
                {
                    foreach (int iBook in file.BooksInFile)
                    {
                        if (!booksPresent.Contains(iBook))
                        {
                            booksPresent.Add(iBook);
                        }
                    }
                }
                booksPresent.Sort();
                return(booksPresent);

            default:
                throw new NotSupportedException("Unexpected type of Import Project");
            }
        }
Example #2
0
        private static bool ParatextProjectsAccessible(IScrImportSet importSettings, out StringCollection projectsNotFound)
        {
            projectsNotFound = new StringCollection();

            if (importSettings.ParatextScrProj == null)
            {
                return(false);
            }

            // Paratext seems to want to have write access to do an import...
            string filename = Path.Combine(ScriptureProvider.SettingsDirectory, importSettings.ParatextScrProj + ".ssf");

            if (!FileUtils.IsFileReadableAndWritable(filename) ||
                !ParatextHelper.GetProjectBooks(importSettings.ParatextScrProj).Any())
            {
                projectsNotFound.Add(importSettings.ParatextScrProj);
            }

            if (importSettings.ParatextBTProj != null)
            {
                filename = Path.Combine(ScriptureProvider.SettingsDirectory, importSettings.ParatextBTProj + ".ssf");
                if (!FileUtils.IsFileReadableAndWritable(filename) ||
                    !ParatextHelper.GetProjectBooks(importSettings.ParatextBTProj).Any())
                {
                    projectsNotFound.Add(importSettings.ParatextBTProj);
                }
            }

            if (importSettings.ParatextNotesProj != null)
            {
                filename = Path.Combine(ScriptureProvider.SettingsDirectory, importSettings.ParatextNotesProj + ".ssf");
                if (!FileUtils.IsFileReadableAndWritable(filename) ||
                    !ParatextHelper.GetProjectBooks(importSettings.ParatextNotesProj).Any())
                {
                    projectsNotFound.Add(importSettings.ParatextNotesProj);
                }
            }

            return(projectsNotFound.Count == 0);
        }