Beispiel #1
0
        public static string GetXMatterDirectory(string nameOfXMatterPack, IFileLocator fileLocator, string errorMsg, bool throwIfError, bool silent = false)
        {
            var directoryName = nameOfXMatterPack + "-XMatter";

            if (Program.RunningHarvesterMode)
            {
                // Get a new file locator that also searches the Custom XMatter directory.
                // This allows the Harvseter to preserve custom branding if those books are uploaded to web. (See BL-BL-9084)
                var extraSearchPaths = new string[]  { BloomFileLocator.GetCustomXMatterDirectory() };
                fileLocator = fileLocator.CloneAndCustomize(extraSearchPaths);
            }

            if (silent)
            {
                // Using LocateDirectoryWithThrow is quite expensive for directories we don't find...the Exception it creates, which we don't use,
                // includes a concatenation of a long list of paths it searched in. (It's quite common now to search for an xmatter directory
                // we don't often find, such as looking for one called Traditional-Device when publishing something with Traditional xmatter
                // on a device.
                try
                {
                    var result = fileLocator.LocateDirectory(directoryName);
                    if (result == null || !Directory.Exists(result))
                    {
                        return(null);
                    }
                    return(result);
                }
                catch (ApplicationException)
                {
                    return(null);
                }
            }
            try
            {
                return(fileLocator.LocateDirectoryWithThrow(directoryName));
            }
            catch (ApplicationException error)
            {
                if (silent)
                {
                    return(null);
                }
                var frontBackMatterProblem = LocalizationManager.GetString("Errors.XMatterProblemLabel", "Front/Back Matter Problem", "This shows in the 'toast' that pops up to notify the user of a non-fatal problem.");
                NonFatalProblem.Report(ModalIf.None, PassiveIf.All, frontBackMatterProblem, errorMsg, error);
                if (throwIfError)
                {
                    throw new ApplicationException(errorMsg);
                }
            }
            return(null);
        }