Пример #1
0
        static void InnerMain(Mutex InstanceMutex, EventWaitHandle ActivateEvent, string[] Args)
        {
            List <string> RemainingArgs = new List <string>(Args);

            string UpdatePath;

            ParseArgument(RemainingArgs, "-updatepath=", out UpdatePath);

            string UpdateSpawn;

            ParseArgument(RemainingArgs, "-updatespawn=", out UpdateSpawn);

            string ServerAndPort;

            ParseArgument(RemainingArgs, "-p4port=", out ServerAndPort);

            string UserName;

            ParseArgument(RemainingArgs, "-p4user="******"-restorestate", out bRestoreState);

            bool bUnstable;

            ParseOption(RemainingArgs, "-unstable", out bUnstable);

            string ProjectFileName;

            ParseArgument(RemainingArgs, "-project=", out ProjectFileName);

            string UpdateConfigFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "AutoUpdate.ini");

            MergeUpdateSettings(UpdateConfigFile, ref UpdatePath, ref UpdateSpawn);

            string SyncVersionFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "SyncVersion.txt");

            if (File.Exists(SyncVersionFile))
            {
                try
                {
                    SyncVersion = File.ReadAllText(SyncVersionFile).Trim();
                }
                catch (Exception)
                {
                    SyncVersion = null;
                }
            }

            string DataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "UnrealGameSync");

            Directory.CreateDirectory(DataFolder);

            using (TelemetryWriter Telemetry = new TelemetryWriter(DeploymentSettings.ApiUrl, Path.Combine(DataFolder, "Telemetry.log")))
            {
                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
                using (UpdateMonitor UpdateMonitor = new UpdateMonitor(new PerforceConnection(UserName, null, ServerAndPort), UpdatePath))
                {
                    ProgramApplicationContext Context = new ProgramApplicationContext(UpdateMonitor, DeploymentSettings.ApiUrl, DataFolder, ActivateEvent, bRestoreState, UpdateSpawn, ProjectFileName, bUnstable);
                    Application.Run(Context);

                    if (UpdateMonitor.IsUpdateAvailable && UpdateSpawn != null)
                    {
                        InstanceMutex.Close();
                        bool bLaunchUnstable = UpdateMonitor.RelaunchUnstable ?? bUnstable;
                        Utility.SpawnProcess(UpdateSpawn, "-restorestate" + (bLaunchUnstable? " -unstable" : ""));
                    }
                }
            }
        }
Пример #2
0
        static void InnerMain(Mutex InstanceMutex, EventWaitHandle ActivateEvent, string[] Args)
        {
            List <string> RemainingArgs = new List <string>(Args);

            string UpdatePath;

            ParseArgument(RemainingArgs, "-updatepath=", out UpdatePath);

            string UpdateSpawn;

            ParseArgument(RemainingArgs, "-updatespawn=", out UpdateSpawn);

            bool bRestoreState;

            ParseOption(RemainingArgs, "-restorestate", out bRestoreState);

            bool bUnstable;

            ParseOption(RemainingArgs, "-unstable", out bUnstable);

            string ProjectFileName;

            ParseArgument(RemainingArgs, "-project=", out ProjectFileName);

            string UpdateConfigFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "AutoUpdate.ini");

            MergeUpdateSettings(UpdateConfigFile, ref UpdatePath, ref UpdateSpawn);

            string SyncVersionFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "SyncVersion.txt");

            if (File.Exists(SyncVersionFile))
            {
                try
                {
                    SyncVersion = File.ReadAllText(SyncVersionFile).Trim();
                }
                catch (Exception)
                {
                    SyncVersion = null;
                }
            }

            string DataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "UnrealGameSync");

            Directory.CreateDirectory(DataFolder);

            using (TelemetryWriter Telemetry = new TelemetryWriter(ApiUrl, Path.Combine(DataFolder, "Telemetry.log")))
            {
                try
                {
                    using (UpdateMonitor UpdateMonitor = new UpdateMonitor(new PerforceConnection(null, null, null), UpdatePath))
                    {
                        ProgramApplicationContext Context = new ProgramApplicationContext(UpdateMonitor, ApiUrl, DataFolder, ActivateEvent, bRestoreState, UpdateSpawn, ProjectFileName, bUnstable);
                        Application.Run(Context);

                        if (UpdateMonitor.IsUpdateAvailable && UpdateSpawn != null)
                        {
                            InstanceMutex.Close();
                            Utility.SpawnProcess(UpdateSpawn, "-restorestate" + (bUnstable? " -unstable" : ""));
                        }
                    }
                }
                catch (Exception Ex)
                {
                    StringBuilder ExceptionTrace = new StringBuilder(Ex.ToString());
                    for (Exception InnerEx = Ex.InnerException; InnerEx != null; InnerEx = InnerEx.InnerException)
                    {
                        ExceptionTrace.Append("\nInner Exception:\n");
                        ExceptionTrace.Append(InnerEx.ToString());
                    }
                    TelemetryWriter.Enqueue(TelemetryErrorType.Crash, ExceptionTrace.ToString(), null, DateTime.Now);
                    MessageBox.Show(String.Format("UnrealGameSync has crashed.\n\n{0}", ExceptionTrace.ToString()));
                }
            }
        }
Пример #3
0
        static void InnerMain(Mutex InstanceMutex, EventWaitHandle ActivateEvent, string[] Args)
        {
            string ServerAndPort = null;
            string UserName      = null;
            string UpdatePath    = null;

            Utility.ReadGlobalPerforceSettings(ref ServerAndPort, ref UserName, ref UpdatePath);

            List <string> RemainingArgs = new List <string>(Args);

            string UpdateSpawn;

            ParseArgument(RemainingArgs, "-updatespawn=", out UpdateSpawn);

            bool bRestoreState;

            ParseOption(RemainingArgs, "-restorestate", out bRestoreState);

            bool bUnstable;

            ParseOption(RemainingArgs, "-unstable", out bUnstable);

            string ProjectFileName;

            ParseArgument(RemainingArgs, "-project=", out ProjectFileName);

            string UpdateConfigFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "AutoUpdate.ini");

            MergeUpdateSettings(UpdateConfigFile, ref UpdatePath, ref UpdateSpawn);

            string SyncVersionFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "SyncVersion.txt");

            if (File.Exists(SyncVersionFile))
            {
                try
                {
                    SyncVersion = File.ReadAllText(SyncVersionFile).Trim();
                }
                catch (Exception)
                {
                    SyncVersion = null;
                }
            }

            string DataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "UnrealGameSync");

            Directory.CreateDirectory(DataFolder);

            using (TelemetryWriter Telemetry = new TelemetryWriter(DeploymentSettings.ApiUrl, Path.Combine(DataFolder, "Telemetry.log")))
            {
                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

                // Create the log file
                using (TimestampLogWriter Log = new TimestampLogWriter(new BoundedLogWriter(Path.Combine(DataFolder, "UnrealGameSync.log"))))
                {
                    Log.WriteLine("Application version: {0}", Assembly.GetExecutingAssembly().GetName().Version);
                    Log.WriteLine("Started at {0}", DateTime.Now.ToString());

                    if (ServerAndPort == null || UserName == null)
                    {
                        Log.WriteLine("Missing server settings; finding defaults.");
                        GetDefaultServerSettings(ref ServerAndPort, ref UserName, Log);
                        Utility.SaveGlobalPerforceSettings(ServerAndPort, UserName, UpdatePath);
                    }

                    PerforceConnection DefaultConnection = new PerforceConnection(UserName, null, ServerAndPort);
                    using (UpdateMonitor UpdateMonitor = new UpdateMonitor(DefaultConnection, UpdatePath))
                    {
                        ProgramApplicationContext Context = new ProgramApplicationContext(DefaultConnection, UpdateMonitor, DeploymentSettings.ApiUrl, DataFolder, ActivateEvent, bRestoreState, UpdateSpawn, ProjectFileName, bUnstable, Log);
                        Application.Run(Context);

                        if (UpdateMonitor.IsUpdateAvailable && UpdateSpawn != null)
                        {
                            InstanceMutex.Close();
                            bool bLaunchUnstable = UpdateMonitor.RelaunchUnstable ?? bUnstable;
                            Utility.SpawnProcess(UpdateSpawn, "-restorestate" + (bLaunchUnstable? " -unstable" : ""));
                        }
                    }
                }
            }
        }
Пример #4
0
        static void InnerMain(Mutex InstanceMutex, EventWaitHandle ActivateEvent, string[] Args)
        {
            string ServerAndPort  = null;
            string UserName       = null;
            string BaseUpdatePath = null;

            Utility.ReadGlobalPerforceSettings(ref ServerAndPort, ref UserName, ref BaseUpdatePath);

            List <string> RemainingArgs = new List <string>(Args);

            string UpdateSpawn;

            ParseArgument(RemainingArgs, "-updatespawn=", out UpdateSpawn);

            string UpdatePath;

            ParseArgument(RemainingArgs, "-updatepath=", out UpdatePath);

            bool bRestoreState;

            ParseOption(RemainingArgs, "-restorestate", out bRestoreState);

            bool bUnstable;

            ParseOption(RemainingArgs, "-unstable", out bUnstable);

            string ProjectFileName;

            ParseArgument(RemainingArgs, "-project=", out ProjectFileName);

            string Uri;

            ParseArgument(RemainingArgs, "-uri=", out Uri);

            string UpdateConfigFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "AutoUpdate.ini");

            MergeUpdateSettings(UpdateConfigFile, ref UpdatePath, ref UpdateSpawn);

            string SyncVersionFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "SyncVersion.txt");

            if (File.Exists(SyncVersionFile))
            {
                try
                {
                    SyncVersion = File.ReadAllText(SyncVersionFile).Trim();
                }
                catch (Exception)
                {
                    SyncVersion = null;
                }
            }

            string DataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "UnrealGameSync");

            Directory.CreateDirectory(DataFolder);

            // Enable TLS 1.1 and 1.2. TLS 1.0 is now deprecated and not allowed by default in NET Core servers.
            ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

            // Create the log file
            using (TimestampLogWriter Log = new TimestampLogWriter(new BoundedLogWriter(Path.Combine(DataFolder, "UnrealGameSync.log"))))
            {
                Log.WriteLine("Application version: {0}", Assembly.GetExecutingAssembly().GetName().Version);
                Log.WriteLine("Started at {0}", DateTime.Now.ToString());

                string SessionId = Guid.NewGuid().ToString();
                Log.WriteLine("SessionId: {0}", SessionId);

                if (ServerAndPort == null || UserName == null)
                {
                    Log.WriteLine("Missing server settings; finding defaults.");
                    GetDefaultServerSettings(ref ServerAndPort, ref UserName, Log);
                    Utility.SaveGlobalPerforceSettings(ServerAndPort, UserName, BaseUpdatePath);
                }

                using (BoundedLogWriter TelemetryLog = new BoundedLogWriter(Path.Combine(DataFolder, "Telemetry.log")))
                {
                    TelemetryLog.WriteLine("Creating telemetry sink for session {0}", SessionId);

                    ITelemetrySink PrevTelemetrySink = Telemetry.ActiveSink;
                    using (ITelemetrySink TelemetrySink = DeploymentSettings.CreateTelemetrySink(UserName, SessionId, TelemetryLog))
                    {
                        Telemetry.ActiveSink = TelemetrySink;

                        Telemetry.SendEvent("Startup", new { User = Environment.UserName, Machine = Environment.MachineName });

                        AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

                        PerforceConnection DefaultConnection = new PerforceConnection(UserName, null, ServerAndPort);
                        using (UpdateMonitor UpdateMonitor = new UpdateMonitor(DefaultConnection, UpdatePath))
                        {
                            ProgramApplicationContext Context = new ProgramApplicationContext(DefaultConnection, UpdateMonitor, DeploymentSettings.ApiUrl, DataFolder, ActivateEvent, bRestoreState, UpdateSpawn, ProjectFileName, bUnstable, Log, Uri);
                            Application.Run(Context);

                            if (UpdateMonitor.IsUpdateAvailable && UpdateSpawn != null)
                            {
                                InstanceMutex.Close();
                                bool bLaunchUnstable = UpdateMonitor.RelaunchUnstable ?? bUnstable;
                                Utility.SpawnProcess(UpdateSpawn, "-restorestate" + (bLaunchUnstable ? " -unstable" : ""));
                            }
                        }
                    }
                    Telemetry.ActiveSink = PrevTelemetrySink;
                }
            }
        }