コード例 #1
0
ファイル: Program.cs プロジェクト: nzbr/amonguscapture
        private static URIStartResult HandleURIStart(string[] args)
        {
            Console.WriteLine(GetExecutablePath());
            const string appName = "AmongUsCapture";

            mutex = new Mutex(true, appName, out bool createdNew);
            bool           wasURIStart = args.Length > 0 && args[0].StartsWith(UriScheme + "://");
            URIStartResult result      = URIStartResult.CONTINUE;

            if (!createdNew) // send it to already existing instance if applicable, then close
            {
                if (wasURIStart)
                {
                    var pipeClient = new NamedPipeClientStream(".", "AmongUsCapturePipe", PipeDirection.InOut, PipeOptions.None, TokenImpersonationLevel.Impersonation);
                    pipeClient.Connect();
                    var ss = new StreamString(pipeClient);
                    ss.WriteString(args[0]);
                    pipeClient.Close();
                }
                return(URIStartResult.CLOSE);
            }
            else if (wasURIStart) // URI start on new instance, continue as normal but also handle current argument
            {
                result = URIStartResult.PARSE;
            }

            RegisterProtocol();

            return(result);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: nzbr/amonguscapture
        static void Main(string[] args)
        {
            if (Settings.PersistentSettings.debugConsole)
            {
                AllocConsole(); // needs to be the first call in the program to prevent weird bugs
            }

            URIStartResult uriRes = HandleURIStart(args);

            if (uriRes == URIStartResult.CLOSE)
            {
                return;
            }

            Application.SetHighDpiMode(HighDpiMode.SystemAware);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            ClientSocket socket = new ClientSocket();

            form                  = new UserForm(socket);
            Settings.form         = form;
            Settings.conInterface = new FormConsole(form);                                                                  //Create the Form Console interface.
            Task.Factory.StartNew(() => socket.Init()).Wait();                                                              // run socket in background. Important to wait for init to have actually finished before continuing
            Task.Factory.StartNew(() => GameMemReader.getInstance().RunLoop());                                             // run loop in background
            Task.Factory.StartNew(() => IPCadapter.getInstance().RunLoop(uriRes == URIStartResult.PARSE ? args[0] : null)); // Run listener for tokens

            //AllocConsole();
            Application.Run(form);

            //test
        }
コード例 #3
0
        private static void Main(string[] args)
        {
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && Settings.PersistentSettings.debugConsole)
            {
                AllocConsole(); // needs to be the first call in the program to prevent weird bugs
            }
            if (!Directory.Exists(Settings.StorageLocation))
            {
                // Create Settings directory if it doesn't exist, as we need to stick our pidfile there.
                Directory.CreateDirectory(Settings.StorageLocation);
            }

            URIStartResult uriRes = URIStartResult.CLOSE;

            uriRes = IPCadapter.getInstance().HandleURIStart(args);
            switch (uriRes)
            {
            case URIStartResult.CLOSE:
                Environment.Exit(0);
                break;

            case URIStartResult.PARSE:
                Console.WriteLine($"Starting with args : {args[0]}");
                break;

            case URIStartResult.CONTINUE:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            socket = new ClientSocket();

            //Create the Form Console interface.
            var thread = new Thread(OpenGUI);

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                thread.SetApartmentState(ApartmentState.STA);
            }
            thread.Start();
            while (Settings.conInterface is null)
            {
                Thread.Sleep(250);
            }
            Task.Factory.StartNew(() => socket.Init())
            .Wait();     // run socket in background. Important to wait for init to have actually finished before continuing
            Task.Factory.StartNew(() => IPCadapter.getInstance().RegisterMinion()).Wait();

            // Add a GLib Idle handler to fix the issue here.
            Idle.Add(delegate
            {
                Task.Factory.StartNew(() => GameMemReader.getInstance().RunLoop()); // run loop in background
                if (uriRes == URIStartResult.PARSE)
                {
                    IPCadapter.getInstance().SendToken(args[0]);
                }
                return(false);
            });

            thread.Join();
        }