示例#1
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            runShutdown = true;
            skipSave    = true;

            ArgumentParser parser = new ArgumentParser();

            parser.Parse(e.Args);
            CheckOptions(parser);

            if (exitApp)
            {
                return;
            }

            try
            {
                Process.GetCurrentProcess().PriorityClass =
                    ProcessPriorityClass.High;
            }
            catch { } // Ignore problems raising the priority.

            // Force Normal IO Priority
            IntPtr ioPrio = new IntPtr(2);

            DS4Windows.Util.NtSetInformationProcess(Process.GetCurrentProcess().Handle,
                                                    DS4Windows.Util.PROCESS_INFORMATION_CLASS.ProcessIoPriority, ref ioPrio, 4);

            // Force Normal Page Priority
            IntPtr pagePrio = new IntPtr(5);

            DS4Windows.Util.NtSetInformationProcess(Process.GetCurrentProcess().Handle,
                                                    DS4Windows.Util.PROCESS_INFORMATION_CLASS.ProcessPagePriority, ref pagePrio, 4);

            try
            {
                // another instance is already running if OpenExisting succeeds.
                threadComEvent = EventWaitHandle.OpenExisting(SingleAppComEventName,
                                                              System.Security.AccessControl.EventWaitHandleRights.Synchronize |
                                                              System.Security.AccessControl.EventWaitHandleRights.Modify);
                threadComEvent.Set();  // signal the other instance.
                threadComEvent.Close();
                Current.Shutdown();    // Quit temp instance
                runShutdown = false;
                return;
            }
            catch { /* don't care about errors */ }

            // Create the Event handle
            threadComEvent = new EventWaitHandle(false, EventResetMode.ManualReset, SingleAppComEventName);
            CreateTempWorkerThread();

            CreateControlService();
            RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;

            DS4Windows.Global.FindConfigLocation();
            bool firstRun = DS4Windows.Global.firstRun;

            if (firstRun)
            {
                DS4Forms.SaveWhere savewh = new DS4Forms.SaveWhere(false);
                savewh.ShowDialog();
            }

            DS4Windows.Global.Load();
            if (!CreateConfDirSkeleton())
            {
                MessageBox.Show($"Cannot create config folder structure in {DS4Windows.Global.appdatapath}. Exiting",
                                "DS4Windows", MessageBoxButton.OK, MessageBoxImage.Error);
                Current.Shutdown(1);
            }

            logHolder = new LoggerHolder(rootHub);
            DispatcherUnhandledException += App_DispatcherUnhandledException;
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            Logger logger  = logHolder.Logger;
            string version = DS4Windows.Global.exeversion;

            logger.Info($"DS4Windows version {version}");
            logger.Info($"DS4Windows exe file: {DS4Windows.Global.exeFileName}");
            logger.Info($"DS4Windows Assembly Architecture: {(Environment.Is64BitProcess ? "x64" : "x86")}");
            logger.Info($"OS Version: {Environment.OSVersion}");
            logger.Info($"OS Product Name: {DS4Windows.Util.GetOSProductName()}");
            logger.Info($"OS Release ID: {DS4Windows.Util.GetOSReleaseId()}");
            logger.Info($"System Architecture: {(Environment.Is64BitOperatingSystem ? "x64" : "x86")}");
            //logger.Info("DS4Windows version 2.0");
            logger.Info("Logger created");

            //DS4Windows.Global.ProfilePath[0] = "mixed";
            //DS4Windows.Global.LoadProfile(0, false, rootHub, false, false);
            if (firstRun)
            {
                logger.Info("No config found. Creating default config");
                //Directory.CreateDirectory(DS4Windows.Global.appdatapath);
                AttemptSave();

                //Directory.CreateDirectory(DS4Windows.Global.appdatapath + @"\Profiles\");
                //Directory.CreateDirectory(DS4Windows.Global.appdatapath + @"\Macros\");
                DS4Windows.Global.SaveAsNewProfile(0, "Default");
                DS4Windows.Global.ProfilePath[0] = DS4Windows.Global.OlderProfilePath[0] = "Default";

                /*DS4Windows.Global.ProfilePath[1] = DS4Windows.Global.OlderProfilePath[1] = "Default";
                 * DS4Windows.Global.ProfilePath[2] = DS4Windows.Global.OlderProfilePath[2] = "Default";
                 * DS4Windows.Global.ProfilePath[3] = DS4Windows.Global.OlderProfilePath[3] = "Default";
                 */
                logger.Info("Default config created");
            }

            skipSave = false;

            if (!DS4Windows.Global.LoadActions())
            {
                DS4Windows.Global.CreateStdActions();
            }

            SetUICulture(DS4Windows.Global.UseLang);
            DS4Windows.AppThemeChoice themeChoice = DS4Windows.Global.UseCurrentTheme;
            if (themeChoice != DS4Windows.AppThemeChoice.Default)
            {
                ChangeTheme(DS4Windows.Global.UseCurrentTheme, false);
            }

            DS4Windows.Global.LoadLinkedProfiles();
            DS4Forms.MainWindow window = new DS4Forms.MainWindow(parser);
            MainWindow = window;
            window.Show();
            HwndSource source = PresentationSource.FromVisual(window) as HwndSource;

            CreateIPCClassNameMMF(source.Handle);

            window.CheckMinStatus();
            rootHub.LogDebug($"Running as {(DS4Windows.Global.IsAdministrator() ? "Admin" : "User")}");
            rootHub.LaunchHidGuardHelper();
            rootHub.LoadPermanentSlotsConfig();
            window.LateChecks(parser);
        }
示例#2
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            runShutdown = true;
            skipSave    = true;

            ArgumentParser parser = new ArgumentParser();

            parser.Parse(e.Args);
            CheckOptions(parser);

            if (exitApp)
            {
                return;
            }

            try
            {
                Process.GetCurrentProcess().PriorityClass =
                    ProcessPriorityClass.High;
            }
            catch { } // Ignore problems raising the priority.

            // Force Normal IO Priority
            IntPtr ioPrio = new IntPtr(2);

            Util.NtSetInformationProcess(Process.GetCurrentProcess().Handle,
                                         Util.PROCESS_INFORMATION_CLASS.ProcessIoPriority, ref ioPrio, 4);

            // Force Normal Page Priority
            IntPtr pagePrio = new IntPtr(5);

            Util.NtSetInformationProcess(Process.GetCurrentProcess().Handle,
                                         Util.PROCESS_INFORMATION_CLASS.ProcessPagePriority, ref pagePrio, 4);

            try
            {
                // another instance is already running if OpenExisting succeeds.
                ThreadComEvent = EventWaitHandle.OpenExisting(SingleAppComEventName,
                                                              System.Security.AccessControl.EventWaitHandleRights.Synchronize |
                                                              System.Security.AccessControl.EventWaitHandleRights.Modify);
                ThreadComEvent.Set();  // signal the other instance.
                ThreadComEvent.Close();
                Current.Shutdown();    // Quit temp instance
                return;
            }
            catch { /* don't care about errors */ }

            // Create the Event handle
            ThreadComEvent = new EventWaitHandle(false, EventResetMode.ManualReset, SingleAppComEventName);
            CreateTempWorkerThread();

            CreateControlService();

            Global.FindConfigLocation();
            bool firstRun = Global.FirstRun;

            if (firstRun)
            {
                SaveWhere savewh = new SaveWhere(false);
                savewh.ShowDialog();
            }

            Global.Load();
            if (!CreateConfDirSkeleton())
            {
                MessageBox.Show($"Cannot create config folder structure in {Global.AppDataPath}. Exiting",
                                "DS4Windows", MessageBoxButton.OK, MessageBoxImage.Error);
                Current.Shutdown(1);
            }

            logHolder = new LoggerHolder(RootHub);
            DispatcherUnhandledException += App_DispatcherUnhandledException;
            Logger logger  = logHolder.Logger;
            string version = Global.ExeVersion;

            logger.Info($"DS4Windows version {version}");
            //logger.Info("DS4Windows version 2.0");
            logger.Info("Logger created");

            //DS4Windows.Global.ProfilePath[0] = "mixed";
            //DS4Windows.Global.LoadProfile(0, false, rootHub, false, false);
            if (firstRun)
            {
                logger.Info("No config found. Creating default config");
                //Directory.CreateDirectory(DS4Windows.Global.appdatapath);
                AttemptSave();

                //Directory.CreateDirectory(DS4Windows.Global.appdatapath + @"\Profiles\");
                //Directory.CreateDirectory(DS4Windows.Global.appdatapath + @"\Macros\");
                Global.SaveProfile(0, "Default");
                Global.ProfilePath[0] = Global.OlderProfilePath[0] = "Default";

                /*DS4Windows.Global.ProfilePath[1] = DS4Windows.Global.OlderProfilePath[1] = "Default";
                 * DS4Windows.Global.ProfilePath[2] = DS4Windows.Global.OlderProfilePath[2] = "Default";
                 * DS4Windows.Global.ProfilePath[3] = DS4Windows.Global.OlderProfilePath[3] = "Default";
                 */
                logger.Info("Default config created");
            }

            skipSave = false;

            if (!Global.LoadActions())
            {
                Global.CreateStdActions();
            }

            SetUICulture(Global.UseLang);
            Global.LoadLinkedProfiles();
            MainWindow window = new MainWindow(parser);

            MainWindow = window;
            window.Show();
            window.CheckMinStatus();
            HwndSource source = PresentationSource.FromVisual(window) as HwndSource;

            CreateIPCClassNameMMF(source.Handle);
        }