Exemplo n.º 1
0
        /// <summary>
        ///     Call the SetupHelper.exe to add, rename or delete printers
        /// </summary>
        /// <param name="arguments">Command line arguments that will be passed to SetupHelper.exe</param>
        /// <returns>true, if the action was successful</returns>
        private bool CallPrinterHelper(string arguments)
        {
            var assemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            if (assemblyPath == null)
            {
                return(false);
            }

            var printerHelperPath = Path.Combine(assemblyPath, "SetupHelper.exe");

            if (!File.Exists(printerHelperPath))
            {
                var message = TranslationHelper.Instance.TranslatorInstance.GetFormattedTranslation("Application",
                                                                                                    "SetupFileMissing",
                                                                                                    "An important clawPDF file is missing ('{0}'). Please reinstall clawPDF!",
                                                                                                    Path.GetFileName(printerHelperPath));
                var caption =
                    TranslationHelper.Instance.TranslatorInstance.GetTranslation("ApplicationSettingsWindow", "Error",
                                                                                 "Error");
                MessageWindow.ShowTopMost(message, caption, MessageWindowButtons.OK, MessageWindowIcon.Error);
                return(false);
            }

            if (Environment.OSVersion.Version.Major <= 5)
            {
                var osHelper = new OsHelper();
                if (!osHelper.UserIsAdministrator())
                {
                    var message = TranslationHelper.Instance.TranslatorInstance.GetFormattedTranslation(
                        "ApplicationSettingsWindow", "OperationRequiresAdminPrivileges",
                        "This operation requires admin privileges and it looks like you are not an admin. Do you want to continue anyway?\r\nNote: It is safe to continue even if you are unsure if you have appropriate rights, but the operation will not be completed.",
                        Path.GetFileName(printerHelperPath));
                    var caption = TranslationHelper.Instance.TranslatorInstance.GetTranslation(
                        "ApplicationSettingsWindow", "AdminPrivilegesRequired", "Admin privileges required");
                    if (MessageWindow.ShowTopMost(message, caption, MessageWindowButtons.YesNo,
                                                  MessageWindowIcon.Info) ==
                        MessageWindowResponse.No)
                    {
                        return(false);
                    }
                }
            }

            return(CallProgramAsAdmin(printerHelperPath, arguments));
        }
        /// <summary>
        ///     Call the SetupHelper.exe to add or remove explorer context menu integration
        /// </summary>
        /// <param name="arguments">Command line arguments that will be passed to SetupHelper.exe</param>
        /// <returns>true, if the action was successful</returns>
        private void CallSetupHelper(string arguments)
        {
            var assemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            if (assemblyPath == null)
            {
                return;
            }

            var setupHelperPath = Path.Combine(assemblyPath, "SetupHelper.exe");

            if (!File.Exists(setupHelperPath))
            {
                var message = _translator.GetFormattedTranslation("Application", "SetupFileMissing",
                                                                  Path.GetFileName(setupHelperPath));
                var caption = _translator.GetTranslation("ApplicationSettingsWindow", "Error");
                ShowMessage(message, caption, MessageOptions.OK, MessageIcon.Error);
                return;
            }

            if (Environment.OSVersion.Version.Major <= 5)
            {
                var osHelper = new OsHelper();
                if (!osHelper.UserIsAdministrator())
                {
                    var message = _translator.GetTranslation("ApplicationSettingsWindow", "OperationRequiresAdminPrivileges");
                    var caption = _translator.GetTranslation("ApplicationSettingsWindow", "AdminPrivilegesRequired");

                    var response = ShowMessage(message, caption, MessageOptions.YesNo, MessageIcon.Info);
                    if (response == MessageResponse.No)
                    {
                        return;
                    }
                }
            }

            CallProgramAsAdmin(setupHelperPath, arguments);
        }
Exemplo n.º 3
0
        private string GetApplicationPath(string applicationName)
        {
            var assemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            if (assemblyPath == null)
            {
                return(null);
            }

            var applicationPath = Path.Combine(assemblyPath, applicationName);

            if (!File.Exists(applicationPath))
            {
                var message = _translation.GetFormattedSetupFileMissing(Path.GetFileName(applicationPath));
                var caption = _translation.Error;
                ShowMessage(message, caption, MessageOptions.OK, MessageIcon.Error);
                return(null);
            }

            if (Environment.OSVersion.Version.Major <= 5)
            {
                var osHelper = new OsHelper();
                if (!osHelper.UserIsAdministrator())
                {
                    var message = _translation.OperationRequiresAdminPrivileges;
                    var caption = _translation.AdminPrivilegesRequired;

                    var response = ShowMessage(message, caption, MessageOptions.YesNo, MessageIcon.Info);
                    if (response == MessageResponse.No)
                    {
                        return(null);
                    }
                }
            }

            return(applicationPath);
        }