Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var registry = ObjectFactory.ConfigureStructureMap();

            registry.IncludeRegistry(new PresenterRegistry());
            registry.For <IApp>().Singleton().Use <App>();
            ObjectFactory.SetUpContainer(registry);

            var presenterFactory = ObjectFactory.GetInstance <IPresenterFactory>();

            var app = presenterFactory.InstantiatePresenter <App>();

            if (!app.Initialize(ToolkitType.Cocoa))
            {
                return;
            }

            MacEngine.App.OpenUrl += (sender, e) =>
            {
                ObjectFactory.GetInstance <ILogger>().WriteLine($"Got url {e.Url}");

                if (e.Url.StartsWith("parkitectnexus://"))
                {
                    e.Url = e.Url;
                }
                else
                {
                    var match = Regex.Match(e.Url, "<NSAppleEventDescriptor: \"(parkitectnexus:\\/\\/.*)\">");
                    if (match.Success)
                    {
                        e.Url = match.Groups[1].Value;
                    }
                }
                NexusUrl url;

                if (NexusUrl.TryParse(e.Url, out url))
                {
                    app.HandleUrl(url);
                }
            };

            TmpFixModLoaderUtil.InstallModLoader(ObjectFactory.GetInstance <IParkitect>(), ObjectFactory.GetInstance <ILogger>());

            app.Run();
        }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            var socketPath = Path.GetTempPath() + "/parkitect_nexus.socket";
            var endPoint   = new UnixEndPoint(socketPath);
            var socket     = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.IP);

            if (!File.Exists(Path.GetTempPath() + "/parkitect_nexus.socket"))
            {
                if (!CreateSocket(socket, endPoint))
                {
                    return;
                }
            }
            else
            {
                try
                {
                    socket.Connect(endPoint);
                    using (var sr = new NetworkStream(socket))
                    {
                        using (var writer = new StreamWriter(sr))
                        {
                            writer.WriteLine(args.Length);
                            foreach (var t in args)
                            {
                                writer.WriteLine(t);
                            }
                        }
                    }
                    return;
                }
                catch
                {
                    File.Delete(Path.GetTempPath() + "/parkitect_nexus.socket");
                    if (!CreateSocket(socket, endPoint))
                    {
                        return;
                    }
                }
            }


            try
            {
                // Initialize the structure map container.
                var registry = ObjectFactory.ConfigureStructureMap();
                registry.IncludeRegistry(new PresenterRegistry());
                registry.For <IApp>().Singleton().Use <App>();
                ObjectFactory.SetUpContainer(registry);


                // Create the form and run its message loop. If arguments were specified, process them within the
                // form.
                var presenterFactory = ObjectFactory.GetInstance <IPresenterFactory>();
                App = presenterFactory.InstantiatePresenter <App>();
                if (!App.Initialize(ToolkitType.Gtk))
                {
                    return;
                }


                if (args.Any())
                {
                    ProcessArgs(args);
                }

                App.Run();
            }
            catch (Exception e)
            {
                // Report crash to the server.
                var crashReporterFactory = ObjectFactory.GetInstance <ICrashReporterFactory>();
                crashReporterFactory.Report("global", e);

                // Write the error to the log file.
                var log = ObjectFactory.GetInstance <ILogger>();
                log?.WriteLine("Application crashed!", LogLevel.Fatal);
                log?.WriteException(e);
            }
            Closed = true;
            socket.Close();
        }
Exemplo n.º 3
0
        public static void Main(string[] args)
        {
            // Look and see if this is the only running instance of the client.
            var procCount =
#if !DEBUG
                Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName)
                .Count(p => p.MainModule.FileName == Process.GetCurrentProcess().MainModule.FileName);
#else
                Process.GetProcesses().Count(p => p.ProcessName.Contains("ParkitectNexus"));
#endif

            if (procCount == 1)
            {
                // No matter if the application crashes, we must release the mutex when the app closes. Wrap the app
                // logic in a try-finally block.
#if !DEBUG
                try
                {
#endif
                // Initialize the structure map container.
                var registry = ObjectFactory.ConfigureStructureMap();
                registry.IncludeRegistry(new PresenterRegistry());
                registry.For <IApp>().Singleton().Use <App>();
                ObjectFactory.SetUpContainer(registry);


                // Create the form and run its message loop. If arguments were specified, process them within the
                // form.
                var presenterFactory = ObjectFactory.GetInstance <IPresenterFactory>();
                var app = presenterFactory.InstantiatePresenter <App>();
                if (!app.Initialize(ToolkitType.Wpf))
                {
                    return;
                }

                ParkitectNexusProtocol.Install(ObjectFactory.GetInstance <ILogger>());

                if (args.Any())
                {
                    var options = new AppCommandLineOptions();
                    Parser.Default.ParseArguments(args, options);

                    if (options.Url != null)
                    {
                        NexusUrl url;
                        if (NexusUrl.TryParse(options.Url, out url))
                        {
                            app.HandleUrl(url);
                        }
                    }
                }

                app.Run();
#if !DEBUG
            }
            catch (Exception e)
            {
                // Report crash to the server.
                var crashReporterFactory = ObjectFactory.GetInstance <ICrashReporterFactory>();
                crashReporterFactory.Report("global", e);

                // Write the error to the log file.
                var log = ObjectFactory.GetInstance <ILogger>();
                log?.WriteLine("Application crashed!", LogLevel.Fatal);
                log?.WriteException(e);
            }
#endif
                return;
            }

            // If any arguments are set, pass these on to our main application instance.
            if (args.Any())
            {
                var attempts = 0;
                do
                {
                    try
                    {
                        // Write the specified arguments to a temporary ipc.dat file.
                        using (var fileStream = File.OpenWrite(Path.Combine(AppData.Path, "ipc.dat")))
                            using (var streamWriter = new StreamWriter(fileStream))
                            {
                                var options = new AppCommandLineOptions();
                                Parser.Default.ParseArguments(args, options);

                                if (options.Url != null)
                                {
                                    streamWriter.WriteLine(options.Url);
                                }
                            }

                        return;
                    }
                    catch (IOException)
                    {
                        // If storing the arguments fails, we're in trouble. Let's try it again in a few.
                        Thread.Sleep(500);
                        attempts++;
                    }
                } while (attempts < 5); // Limit to 5 attempts.
            }
        }