private static string SafelyGetAppInstalledPath()
 {
     try
     {
         return(MsiUtilities.GetAppInstalledPath());
     }
     catch (InvalidOperationException e)
     {
         ExceptionReporter.ReportException(e);
         return(null);
     }
 }
        /// <summary>
        /// Infer UIAccess state from the existing manifest files. Assume false unless proven otherwise
        /// </summary>
        private static bool IsUIAccessEnabled()
        {
            try
            {
                string appPath                 = Path.GetDirectoryName(MsiUtilities.GetAppInstalledPath());
                string appManifestContents     = File.ReadAllText(Path.Combine(appPath, AppManifestFile));
                string enabledManifestContents = File.ReadAllText(Path.Combine(appPath, EnabledManifestFile));
                return(appManifestContents == enabledManifestContents);
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception e)
            {
                // Report the error, assume no UIAccess
                EventLogger.WriteWarningMessage("Unable to determine UIAccess status. Assuming disabled. Detail: {0}", e.ToString());
                return(false);
            }
#pragma warning restore CA1031 // Do not catch general exception types
        }
        /// <summary>
        /// Update manifest files as needed for UIAccess support
        /// </summary>
        /// <param name="enableUIAccess">Desired state of UIAccess.</param>
        private static void SetManifestForUIAccess(bool enableUIAccess)
        {
            if (!enableUIAccess)
            {
                return;   // UIAccess is disabled by default
            }
            try
            {
                string appPath = Path.GetDirectoryName(MsiUtilities.GetAppInstalledPath());
                string enabledManifestContents = File.ReadAllText(Path.Combine(appPath, EnabledManifestFile));
                File.WriteAllText(Path.Combine(appPath, AppManifestFile), enabledManifestContents, System.Text.Encoding.UTF8);
                EventLogger.WriteInformationalMessage("UIAccess has been enabled");
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception e)
            {
                // Report the error, assume no UIAccess
                EventLogger.WriteWarningMessage("Unable to enable UIAccess. Detail: {0}", e.ToString());
            }
#pragma warning restore CA1031 // Do not catch general exception types
        }