Bloom.MiscUI.BloomIntegrityDialog.CheckIntegrity C# (CSharp) Method

CheckIntegrity() public static method

We've had a number of user reports that suggest that files were either missing or inaccessible. The idea here is to check a set of files and folders at the start of each launch, and generate a useful report if anything is missing.
public static CheckIntegrity ( ) : bool
return bool
        public static bool CheckIntegrity()
        {
            var errors = new StringBuilder();
            var files = new[] { "Bloom.chm", "PdfDroplet.exe",
            #if Chorus
                "Chorus.exe",
            #endif
                "BloomPdfMaker.exe", "optipng.exe" };

                string[] dirs;
            if (SIL.PlatformUtilities.Platform.IsWindows)
                dirs = new[] { "AndikaNewBasic", "localization", "xslts" };
            else
                dirs = new[] { "localization", "xslts" };

            foreach(var fileName in files)
            {
                if(!Platform.IsWindows && fileName == "optipng.exe")
                {
                    // optipng is provided by a package dependency, will be found as /usr/bin/optipng (no .exe)
                    continue;
                }
                if(FileLocator.GetFileDistributedWithApplication(true, fileName) == null)
                {
                    //In a code directory, the FileLocator considers the solution the root, so it can't find files in output\debug
                    if(!RobustFile.Exists(Path.Combine(FileLocator.DirectoryOfTheApplicationExecutable, fileName)))
                    {
                        //maybe it's an exe in distfiles?
                        if(fileName.EndsWith(".exe") && RobustFile.Exists(Path.Combine(FileLocator.DirectoryOfApplicationOrSolution, "DistFiles")))
                        {
                            continue;
                        }
                        errors.AppendFormat("Missing File: {0}{1}{1}", fileName, Environment.NewLine);
                    }
                }
            }
            foreach(var directory in dirs)
            {
                if(FileLocator.GetDirectoryDistributedWithApplication(true, directory) == null)
                {
                    errors.AppendFormat("Missing Directory: {0}{1}{1}", directory, Environment.NewLine);
                }
            }
            if(errors.Length == 0)
                return true;

            using(var dlg = new BloomIntegrityDialog())
            {
                var messagePath = BloomFileLocator.GetBestLocalizableFileDistributedWithApplication(false,"IntegrityFailureAdvice-en.md");
                string message;
                if(messagePath == null) // maybe we can't even get at this file we need for a good description of the problem
                {
                    message = "Bloom cannot find some of its own files, and cannot continue. After you submit this report, we will contact you and help you work this out. In the meantime, you can run the Bloom installer again.";
                }
                else
                {
                    var installFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
                            .CombineForPath(Application.ProductName);
                    message = RobustFile.ReadAllText(messagePath).Replace("{installFolder}", installFolder);
                }

                message = message + Environment.NewLine + Environment.NewLine + errors.ToString();
                dlg.markDownTextBox1.MarkDownText = message;
                dlg.ShowDialog();
            }
            using(var dlg = new ProblemReporterDialog())
            {
                dlg.Summary = "Bloom Integrity Check Failed: {0}";
                dlg.Description = "Please answer any of these questions that you understand:"
                                  + Environment.NewLine + Environment.NewLine
                                  + "Did you install Bloom just now, or maybe allow it to update?"
                                  + Environment.NewLine + Environment.NewLine
                                  + "Is your computer locked down against installing new software?"
                                  + Environment.NewLine + Environment.NewLine
                                  + "What antivirus program do you use?"
                                  + Environment.NewLine + Environment.NewLine
                                  + "--------------------------------------------"
                                  + Environment.NewLine + Environment.NewLine
                                  + "The following information is for Bloom developers to see just what is and isn't missing:"
                                  + Environment.NewLine + Environment.NewLine
                                  + errors.ToString()
                                  + GetDirectoryListing(FileLocator.DirectoryOfTheApplicationExecutable)
                                  + Environment.NewLine + Environment.NewLine
                                  + "Detected Antivirus Program(s): " + InstalledAntivirusPrograms();

            #if !__MonoCS__

                try
                {
                    var logPath =
                        Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
                            .CombineForPath(Application.ProductName, "SquirrelSetup.log");
                    dlg.Description += "=Squirrel Log=" + Environment.NewLine;
                    dlg.Description += logPath + Environment.NewLine;
                    if(RobustFile.Exists(logPath))
                    {
                        dlg.Description += RobustFile.ReadAllText(logPath);
                    }
                    else
                    {
                        dlg.Description += logPath + "not found";
                    }
                }
                catch(Exception error)
                {
                    dlg.Description += error.Message;
                }
            #endif
                dlg.ShowDialog();
            }

            return false; //Force termination of the current process.
        }