private void CheckBackgroundTask()
        {
            _ignoreTaskSetting = true;

            chkBackgroundTask.IsChecked = TaskSchedulerUtilities.GetTask() != null;

            _ignoreTaskSetting = false;
        }
Exemple #2
0
        private static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            InitializeSettings();

#if PORTABLE
            var logDirectory = Path.Combine(Directory.GetCurrentDirectory(), "Logs");
            Settings.Default.FileLogging = false;
            Settings.Default.Save();
#else
            var appData = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Disable Nvidia Telemetry");
            if (!Directory.Exists(appData))
            {
                Directory.CreateDirectory(appData);
            }

            var logDirectory = Path.Combine(appData, "Logs");
#endif

            Logging.Prepare(logDirectory);
            Logging.Enabled = Settings.Default.FileLogging;

            // log all the errors
            AppDomain.CurrentDomain.UnhandledException += (s, e) =>
            {
                var ex = (Exception)e.ExceptionObject;
                Logging.GetFileLogger().Log(Level.Error, ex.Message, ex);
            };

            var silentMode = false;

            if (args.Length > 0)
            {
                Logging.GetFileLogger().Log(Level.Info, $"Startup params: {string.Join(" ", args)}");

                if (args.Contains(StartupParamSilent))
                {
                    silentMode = true;
                    SilentlyDisableTelemetry();
                }

                if (args.Contains(StartupParamRegisterTask))
                {
                    silentMode = true;

                    if (TaskSchedulerUtilities.GetTask() == null)
                    {
                        TaskSchedulerUtilities.Create((TaskSchedulerUtilities.TaskTrigger)Settings.Default.BackgroundTaskTrigger);
                    }
                }

                if (args.Contains(StartupParamUnregisterTask))
                {
                    silentMode = true;
                    TaskSchedulerUtilities.Remove();
                }
            }

            if (!IsAdministrator())
            {
                MessageBox.Show("Please run the program as administrator to continue.", "Administrator Required", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            if (!silentMode)
            {
                Application.Run(new FormMain());
            }
        }
        private void App_OnStartup(object sender, StartupEventArgs e)
        {
            AppUtils.InitializeSettings();

#if PORTABLE
            var logDirectory = Path.Combine(Directory.GetCurrentDirectory(), "Logs");
            Settings.Default.FileLogging = false;
            Settings.Default.Save();
#else
            var appData = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), DisableNvidiaTelemetry.Properties.Resources.Disable_Nvidia_Telemetry);
            if (!Directory.Exists(appData))
            {
                Directory.CreateDirectory(appData);
            }

            var logDirectory = Path.Combine(appData, "Logs");
#endif

            Logging.Prepare(logDirectory);
            Logging.Enabled = Settings.Default.FileLogging;

            // log all the errors
            AppDomain.CurrentDomain.UnhandledException += (s, ee) =>
            {
                var ex = (Exception)ee.ExceptionObject;
                Logging.GetFileLogger().Log(Level.Error, ex.Message, ex);
            };

            var showUI = true;

            if (e.Args.Length > 0)
            {
                Logging.GetFileLogger().Log(Level.Info, $"Startup params: {string.Join(" ", e.Args)}");

                if (e.Args.Contains(AppUtils.StartupParamSilent))
                {
                    showUI = false;
                    SilentlyDisableTelemetry();
                }

                if (e.Args.Contains(AppUtils.StartupParamRegisterTask))
                {
                    showUI = false;

                    if (TaskSchedulerUtilities.GetTask() == null)
                    {
                        TaskSchedulerUtilities.Create((TaskSchedulerUtilities.TaskTrigger)Settings.Default.BackgroundTaskTrigger);
                    }
                }

                if (e.Args.Contains(AppUtils.StartupParamUnregisterTask))
                {
                    showUI = false;
                    TaskSchedulerUtilities.Remove();
                }
            }

            if (!AppUtils.IsAdministrator())
            {
                CustomMessageBox.Show(DisableNvidiaTelemetry.Properties.Resources.Please_run_the_program_as_administrator_to_continue,
                                      DisableNvidiaTelemetry.Properties.Resources.AdministratorRequired, MessageBoxButton.OK, MessageBoxImage.Error);
            }

            if (showUI)
            {
                MainWindow = new MainWindow();
                MainWindow.Show();
            }
        }