Ejemplo n.º 1
0
        public MainWindow(UpdateMonitor InUpdateMonitor, string InSqlConnectionString, string InDataFolder, EventWaitHandle ActivateEvent, bool bInRestoreStateOnLoad, string InOriginalExecutableFileName, string InProjectFileName, bool bInUnstable, BoundedLogWriter InLog, UserSettings InSettings)
        {
            InitializeComponent();

            NotifyMenu_OpenUnrealGameSync.Font = new Font(NotifyMenu_OpenUnrealGameSync.Font, FontStyle.Bold);

            UpdateMonitor              = InUpdateMonitor;
            SqlConnectionString        = InSqlConnectionString;
            DataFolder                 = InDataFolder;
            ActivationListener         = new ActivationListener(ActivateEvent);
            bRestoreStateOnLoad        = bInRestoreStateOnLoad;
            OriginalExecutableFileName = InOriginalExecutableFileName;
            bUnstable = bInUnstable;
            Log       = InLog;
            Settings  = InSettings;

            TabControl.OnTabChanged  += TabControl_OnTabChanged;
            TabControl.OnNewTabClick += TabControl_OnNewTabClick;
            TabControl.OnTabClicked  += TabControl_OnTabClicked;
            TabControl.OnTabClosing  += TabControl_OnTabClosing;
            TabControl.OnTabClosed   += TabControl_OnTabClosed;
            TabControl.OnTabReorder  += TabControl_OnTabReorder;
            TabControl.OnButtonClick += TabControl_OnButtonClick;

            SetupDefaultControl();

            int SelectTabIdx = -1;

            foreach (string ProjectFileName in Settings.OpenProjectFileNames)
            {
                if (!String.IsNullOrEmpty(ProjectFileName))
                {
                    int TabIdx = TryOpenProject(ProjectFileName);
                    if (TabIdx != -1 && Settings.LastProjectFileName != null && ProjectFileName.Equals(Settings.LastProjectFileName, StringComparison.InvariantCultureIgnoreCase))
                    {
                        SelectTabIdx = TabIdx;
                    }
                }
            }

            if (SelectTabIdx != -1)
            {
                TabControl.SelectTab(SelectTabIdx);
            }
            else if (TabControl.GetTabCount() > 0)
            {
                TabControl.SelectTab(0);
            }
        }
        protected override void Dispose(bool bDisposing)
        {
            base.Dispose(bDisposing);

            if (Components != null)
            {
                Components.Dispose();
                Components = null;
            }

            if (NotifyIcon != null)
            {
                NotifyIcon.Dispose();
                NotifyIcon = null;
            }

            if (Log != null)
            {
                Log.Dispose();
                Log = null;
            }

            if (UpdateMonitor != null)
            {
                UpdateMonitor.OnUpdateAvailable -= OnUpdateAvailableCallback;
                UpdateMonitor.Close();                 // prevent race condition
                UpdateMonitor = null;
            }

            if (ActivationListener != null)
            {
                ActivationListener.OnActivate -= OnActivationListenerAsyncCallback;
                ActivationListener.Stop();
                ActivationListener.Dispose();
                ActivationListener = null;
            }

            if (MainWindowInstance != null)
            {
                MainWindowInstance.ForceClose();
                MainWindowInstance = null;
            }

            if (DetectStartupProjectSettingsWindow != null)
            {
                DetectStartupProjectSettingsWindow.Close();
                DetectStartupProjectSettingsWindow = null;
            }
        }
Ejemplo n.º 3
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" : ""));
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public MainWindow(UpdateMonitor InUpdateMonitor, string InApiUrl, string InDataFolder, string InCacheFolder, bool bInRestoreStateOnLoad, string InOriginalExecutableFileName, bool bInUnstable, DetectProjectSettingsResult[] StartupProjects, LineBasedTextWriter InLog, UserSettings InSettings)
        {
            InitializeComponent();

            UpdateMonitor = InUpdateMonitor;
            MainThreadSynchronizationContext = SynchronizationContext.Current;
            ApiUrl                     = InApiUrl;
            DataFolder                 = InDataFolder;
            CacheFolder                = InCacheFolder;
            bRestoreStateOnLoad        = bInRestoreStateOnLoad;
            OriginalExecutableFileName = InOriginalExecutableFileName;
            bUnstable                  = bInUnstable;
            Log      = InLog;
            Settings = InSettings;

            // While creating tab controls during startup, we need to prevent layout calls resulting in the window handle being created too early. Disable layout calls here.
            SuspendLayout();
            TabPanel.SuspendLayout();

            TabControl.OnTabChanged  += TabControl_OnTabChanged;
            TabControl.OnNewTabClick += TabControl_OnNewTabClick;
            TabControl.OnTabClicked  += TabControl_OnTabClicked;
            TabControl.OnTabClosing  += TabControl_OnTabClosing;
            TabControl.OnTabClosed   += TabControl_OnTabClosed;
            TabControl.OnTabReorder  += TabControl_OnTabReorder;
            TabControl.OnButtonClick += TabControl_OnButtonClick;

            SetupDefaultControl();

            int SelectTabIdx = -1;

            foreach (DetectProjectSettingsResult StartupProject in StartupProjects)
            {
                int TabIdx = -1;
                if (StartupProject.bSucceeded)
                {
                    TabIdx = TryOpenProject(StartupProject.Task, -1, OpenProjectOptions.Quiet);
                }
                else if (StartupProject.ErrorMessage != null)
                {
                    CreateErrorPanel(-1, StartupProject.Task.SelectedProject, StartupProject.ErrorMessage);
                }

                if (TabIdx != -1 && Settings.LastProject != null && StartupProject.Task.SelectedProject.Equals(Settings.LastProject))
                {
                    SelectTabIdx = TabIdx;
                }
            }

            if (SelectTabIdx != -1)
            {
                TabControl.SelectTab(SelectTabIdx);
            }
            else if (TabControl.GetTabCount() > 0)
            {
                TabControl.SelectTab(0);
            }

            StartScheduleTimer();

            if (bUnstable)
            {
                Text += String.Format(" (UNSTABLE BUILD {0})", Assembly.GetExecutingAssembly().GetName().Version);
            }

            AutomationLog    = new TimestampLogWriter(new BoundedLogWriter(Path.Combine(DataFolder, "Automation.log")));
            AutomationServer = new AutomationServer(Request => { MainThreadSynchronizationContext.Post(Obj => PostAutomationRequest(Request), null); }, AutomationLog);

            // Allow creating controls from now on
            TabPanel.ResumeLayout(false);
            ResumeLayout(false);

            bAllowCreatingHandle = true;
        }
        public ProgramApplicationContext(PerforceConnection DefaultConnection, UpdateMonitor UpdateMonitor, string ApiUrl, string DataFolder, EventWaitHandle ActivateEvent, bool bRestoreState, string UpdateSpawn, string ProjectFileName, bool bUnstable, TimestampLogWriter Log)
        {
            this.DefaultConnection = DefaultConnection;
            this.UpdateMonitor     = UpdateMonitor;
            this.ApiUrl            = ApiUrl;
            this.DataFolder        = DataFolder;
            this.CacheFolder       = Path.Combine(DataFolder, "Cache");
            this.bRestoreState     = bRestoreState;
            this.UpdateSpawn       = UpdateSpawn;
            this.bUnstable         = bUnstable;
            this.Log = Log;

            // Create the directories
            Directory.CreateDirectory(DataFolder);
            Directory.CreateDirectory(CacheFolder);

            // Make sure a synchronization context is set. We spawn a bunch of threads (eg. UpdateMonitor) at startup, and need to make sure we can post messages
            // back to the main thread at any time.
            if (SynchronizationContext.Current == null)
            {
                SynchronizationContext.SetSynchronizationContext(new WindowsFormsSynchronizationContext());
            }

            // Capture the main thread's synchronization context for callbacks
            MainThreadSynchronizationContext = WindowsFormsSynchronizationContext.Current;

            // Read the user's settings
            Settings = new UserSettings(Path.Combine(DataFolder, "UnrealGameSync.ini"));
            if (!String.IsNullOrEmpty(ProjectFileName))
            {
                string FullProjectFileName = Path.GetFullPath(ProjectFileName);
                if (!Settings.OpenProjects.Any(x => x.LocalPath != null && String.Compare(x.LocalPath, FullProjectFileName, StringComparison.InvariantCultureIgnoreCase) == 0))
                {
                    Settings.OpenProjects.Add(new UserSelectedProjectSettings(null, null, UserSelectedProjectType.Local, null, FullProjectFileName));
                }
            }

            // Update the settings to the latest version
            if (Settings.Version < UserSettingsVersion.Latest)
            {
                // Clear out the server settings for anything using the default server
                if (Settings.Version < UserSettingsVersion.DefaultServerSettings)
                {
                    for (int Idx = 0; Idx < Settings.OpenProjects.Count; Idx++)
                    {
                        Settings.OpenProjects[Idx] = UpgradeSelectedProjectSettings(Settings.OpenProjects[Idx]);
                    }
                    for (int Idx = 0; Idx < Settings.RecentProjects.Count; Idx++)
                    {
                        Settings.RecentProjects[Idx] = UpgradeSelectedProjectSettings(Settings.RecentProjects[Idx]);
                    }
                }

                // Save the new settings
                Settings.Version = UserSettingsVersion.Latest;
                Settings.Save();
            }

            // Register the update listener
            UpdateMonitor.OnUpdateAvailable += OnUpdateAvailableCallback;

            // Create the activation listener
            ActivationListener = new ActivationListener(ActivateEvent);
            ActivationListener.Start();
            ActivationListener.OnActivate += OnActivationListenerAsyncCallback;

            // Create the notification menu items
            NotifyMenu_OpenUnrealGameSync        = new ToolStripMenuItem();
            NotifyMenu_OpenUnrealGameSync.Name   = nameof(NotifyMenu_OpenUnrealGameSync);
            NotifyMenu_OpenUnrealGameSync.Size   = new Size(196, 22);
            NotifyMenu_OpenUnrealGameSync.Text   = "Open UnrealGameSync";
            NotifyMenu_OpenUnrealGameSync.Click += new EventHandler(NotifyMenu_OpenUnrealGameSync_Click);
            NotifyMenu_OpenUnrealGameSync.Font   = new Font(NotifyMenu_OpenUnrealGameSync.Font, FontStyle.Bold);

            NotifyMenu_OpenUnrealGameSync_Separator      = new ToolStripSeparator();
            NotifyMenu_OpenUnrealGameSync_Separator.Name = nameof(NotifyMenu_OpenUnrealGameSync_Separator);
            NotifyMenu_OpenUnrealGameSync_Separator.Size = new Size(193, 6);

            NotifyMenu_SyncNow        = new ToolStripMenuItem();
            NotifyMenu_SyncNow.Name   = nameof(NotifyMenu_SyncNow);
            NotifyMenu_SyncNow.Size   = new Size(196, 22);
            NotifyMenu_SyncNow.Text   = "Sync Now";
            NotifyMenu_SyncNow.Click += new EventHandler(NotifyMenu_SyncNow_Click);

            NotifyMenu_LaunchEditor        = new ToolStripMenuItem();
            NotifyMenu_LaunchEditor.Name   = nameof(NotifyMenu_LaunchEditor);
            NotifyMenu_LaunchEditor.Size   = new Size(196, 22);
            NotifyMenu_LaunchEditor.Text   = "Launch Editor";
            NotifyMenu_LaunchEditor.Click += new EventHandler(NotifyMenu_LaunchEditor_Click);

            NotifyMenu_ExitSeparator      = new ToolStripSeparator();
            NotifyMenu_ExitSeparator.Name = nameof(NotifyMenu_ExitSeparator);
            NotifyMenu_ExitSeparator.Size = new Size(193, 6);

            NotifyMenu_Exit        = new ToolStripMenuItem();
            NotifyMenu_Exit.Name   = nameof(NotifyMenu_Exit);
            NotifyMenu_Exit.Size   = new Size(196, 22);
            NotifyMenu_Exit.Text   = "Exit";
            NotifyMenu_Exit.Click += new EventHandler(NotifyMenu_Exit_Click);

            // Create the notification menu
            NotifyMenu      = new ContextMenuStrip(Components);
            NotifyMenu.Name = nameof(NotifyMenu);
            NotifyMenu.Size = new System.Drawing.Size(197, 104);
            NotifyMenu.SuspendLayout();
            NotifyMenu.Items.Add(NotifyMenu_OpenUnrealGameSync);
            NotifyMenu.Items.Add(NotifyMenu_OpenUnrealGameSync_Separator);
            NotifyMenu.Items.Add(NotifyMenu_SyncNow);
            NotifyMenu.Items.Add(NotifyMenu_LaunchEditor);
            NotifyMenu.Items.Add(NotifyMenu_ExitSeparator);
            NotifyMenu.Items.Add(NotifyMenu_Exit);
            NotifyMenu.ResumeLayout(false);

            // Create the notification icon
            NotifyIcon = new NotifyIcon(Components);
            NotifyIcon.ContextMenuStrip = NotifyMenu;
            NotifyIcon.Icon             = Properties.Resources.Icon;
            NotifyIcon.Text             = "UnrealGameSync";
            NotifyIcon.Visible          = true;
            NotifyIcon.DoubleClick     += new EventHandler(NotifyIcon_DoubleClick);
            NotifyIcon.MouseDown       += new MouseEventHandler(NotifyIcon_MouseDown);

            // Find the initial list of projects to attempt to reopen
            List <DetectProjectSettingsTask> Tasks = new List <DetectProjectSettingsTask>();

            foreach (UserSelectedProjectSettings OpenProject in Settings.OpenProjects)
            {
                BufferedTextWriter StartupLog = new BufferedTextWriter();
                StartupLog.WriteLine("Detecting settings for {0}", OpenProject);
                StartupLogs.Add(StartupLog);

                Tasks.Add(new DetectProjectSettingsTask(OpenProject, DataFolder, CacheFolder, new TimestampLogWriter(new PrefixedTextWriter("  ", StartupLog))));
            }

            // Detect settings for the project we want to open
            DetectStartupProjectSettingsTask = new DetectMultipleProjectSettingsTask(DefaultConnection, Tasks);

            DetectStartupProjectSettingsWindow = new ModalTaskWindow(DetectStartupProjectSettingsTask, "Opening Projects", "Opening projects, please wait...", FormStartPosition.CenterScreen);
            if (bRestoreState)
            {
                if (Settings.bWindowVisible)
                {
                    DetectStartupProjectSettingsWindow.Show();
                }
            }
            else
            {
                DetectStartupProjectSettingsWindow.Show();
                DetectStartupProjectSettingsWindow.Activate();
            }
            DetectStartupProjectSettingsWindow.Complete += OnDetectStartupProjectsComplete;
        }
Ejemplo n.º 6
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(SqlConnectionString, Path.Combine(DataFolder, "Telemetry.log")))
            {
                try
                {
                    using (UpdateMonitor UpdateMonitor = new UpdateMonitor(new PerforceConnection(null, null, null), UpdatePath))
                    {
                        MainWindow Window = new MainWindow(UpdateMonitor, SqlConnectionString, DataFolder, ActivateEvent, bRestoreState, UpdateSpawn ?? Assembly.GetExecutingAssembly().Location, ProjectFileName, bUnstable);
                        if (bUnstable)
                        {
                            Window.Text += String.Format(" (UNSTABLE BUILD {0})", Assembly.GetExecutingAssembly().GetName().Version);
                        }
                        Application.Run(Window);

                        if (UpdateMonitor.IsUpdateAvailable && UpdateSpawn != null)
                        {
                            InstanceMutex.Close();
                            Utility.SpawnProcess(UpdateSpawn, "-restorestate" + (bUnstable? " -unstable" : ""));
                        }
                    }
                }
                catch (Exception Ex)
                {
                    TelemetryWriter.Enqueue(TelemetryErrorType.Crash, Ex.ToString(), null, DateTime.Now);
                    MessageBox.Show(String.Format("UnrealGameSync has crashed.\n\n{0}", Ex.ToString()));
                }
            }
        }
Ejemplo n.º 7
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" : ""));
                        }
                    }
                }
            }
        }
Ejemplo n.º 8
0
        public ProgramApplicationContext(UpdateMonitor UpdateMonitor, string ApiUrl, string DataFolder, EventWaitHandle ActivateEvent, bool bRestoreState, string UpdateSpawn, string ProjectFileName, bool bUnstable)
        {
            this.UpdateMonitor = UpdateMonitor;
            this.ApiUrl        = ApiUrl;
            this.DataFolder    = DataFolder;
            this.bRestoreState = bRestoreState;
            this.UpdateSpawn   = UpdateSpawn;
            this.bUnstable     = bUnstable;

            // Make sure a synchronization context is set. We spawn a bunch of threads (eg. UpdateMonitor) at startup, and need to make sure we can post messages
            // back to the main thread at any time.
            if (SynchronizationContext.Current == null)
            {
                SynchronizationContext.SetSynchronizationContext(new WindowsFormsSynchronizationContext());
            }

            // Capture the main thread's synchronization context for callbacks
            MainThreadSynchronizationContext = WindowsFormsSynchronizationContext.Current;

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

            // Read the user's settings
            Settings = new UserSettings(Path.Combine(DataFolder, "UnrealGameSync.ini"));
            if (!String.IsNullOrEmpty(ProjectFileName))
            {
                string FullProjectFileName = Path.GetFullPath(ProjectFileName);
                if (!Settings.OpenProjects.Any(x => x.LocalPath != null && String.Compare(x.LocalPath, FullProjectFileName, StringComparison.InvariantCultureIgnoreCase) == 0))
                {
                    Settings.OpenProjects.Add(new UserSelectedProjectSettings(null, null, UserSelectedProjectType.Local, null, FullProjectFileName));
                }
            }

            // Register the update listener
            UpdateMonitor.OnUpdateAvailable += OnUpdateAvailableCallback;

            // Create the activation listener
            ActivationListener = new ActivationListener(ActivateEvent);
            ActivationListener.Start();
            ActivationListener.OnActivate += OnActivationListenerAsyncCallback;

            // Create the notification menu items
            NotifyMenu_OpenUnrealGameSync        = new ToolStripMenuItem();
            NotifyMenu_OpenUnrealGameSync.Name   = nameof(NotifyMenu_OpenUnrealGameSync);
            NotifyMenu_OpenUnrealGameSync.Size   = new Size(196, 22);
            NotifyMenu_OpenUnrealGameSync.Text   = "Open UnrealGameSync";
            NotifyMenu_OpenUnrealGameSync.Click += new EventHandler(NotifyMenu_OpenUnrealGameSync_Click);
            NotifyMenu_OpenUnrealGameSync.Font   = new Font(NotifyMenu_OpenUnrealGameSync.Font, FontStyle.Bold);

            NotifyMenu_OpenUnrealGameSync_Separator      = new ToolStripSeparator();
            NotifyMenu_OpenUnrealGameSync_Separator.Name = nameof(NotifyMenu_OpenUnrealGameSync_Separator);
            NotifyMenu_OpenUnrealGameSync_Separator.Size = new Size(193, 6);

            NotifyMenu_SyncNow        = new ToolStripMenuItem();
            NotifyMenu_SyncNow.Name   = nameof(NotifyMenu_SyncNow);
            NotifyMenu_SyncNow.Size   = new Size(196, 22);
            NotifyMenu_SyncNow.Text   = "Sync Now";
            NotifyMenu_SyncNow.Click += new EventHandler(NotifyMenu_SyncNow_Click);

            NotifyMenu_LaunchEditor        = new ToolStripMenuItem();
            NotifyMenu_LaunchEditor.Name   = nameof(NotifyMenu_LaunchEditor);
            NotifyMenu_LaunchEditor.Size   = new Size(196, 22);
            NotifyMenu_LaunchEditor.Text   = "Launch Editor";
            NotifyMenu_LaunchEditor.Click += new EventHandler(NotifyMenu_LaunchEditor_Click);

            NotifyMenu_ExitSeparator      = new ToolStripSeparator();
            NotifyMenu_ExitSeparator.Name = nameof(NotifyMenu_ExitSeparator);
            NotifyMenu_ExitSeparator.Size = new Size(193, 6);

            NotifyMenu_Exit        = new ToolStripMenuItem();
            NotifyMenu_Exit.Name   = nameof(NotifyMenu_Exit);
            NotifyMenu_Exit.Size   = new Size(196, 22);
            NotifyMenu_Exit.Text   = "Exit";
            NotifyMenu_Exit.Click += new EventHandler(NotifyMenu_Exit_Click);

            // Create the notification menu
            NotifyMenu      = new ContextMenuStrip(Components);
            NotifyMenu.Name = nameof(NotifyMenu);
            NotifyMenu.Size = new System.Drawing.Size(197, 104);
            NotifyMenu.SuspendLayout();
            NotifyMenu.Items.Add(NotifyMenu_OpenUnrealGameSync);
            NotifyMenu.Items.Add(NotifyMenu_OpenUnrealGameSync_Separator);
            NotifyMenu.Items.Add(NotifyMenu_SyncNow);
            NotifyMenu.Items.Add(NotifyMenu_LaunchEditor);
            NotifyMenu.Items.Add(NotifyMenu_ExitSeparator);
            NotifyMenu.Items.Add(NotifyMenu_Exit);
            NotifyMenu.ResumeLayout(false);

            // Create the notification icon
            NotifyIcon = new NotifyIcon(Components);
            NotifyIcon.ContextMenuStrip = NotifyMenu;
            NotifyIcon.Icon             = Properties.Resources.Icon;
            NotifyIcon.Text             = "UnrealGameSync";
            NotifyIcon.Visible          = true;
            NotifyIcon.DoubleClick     += new EventHandler(NotifyIcon_DoubleClick);
            NotifyIcon.MouseDown       += new MouseEventHandler(NotifyIcon_MouseDown);

            // Find the initial list of projects to attempt to reopen
            List <DetectProjectSettingsTask> Tasks = new List <DetectProjectSettingsTask>();

            foreach (UserSelectedProjectSettings OpenProject in Settings.OpenProjects)
            {
                Tasks.Add(new DetectProjectSettingsTask(OpenProject, DataFolder, Log));
            }

            // Detect settings for the project we want to open
            DetectStartupProjectSettingsTask = new DetectMultipleProjectSettingsTask(Tasks);

            DetectStartupProjectSettingsWindow = new ModalTaskWindow(DetectStartupProjectSettingsTask, "Opening Projects", "Opening projects, please wait...", FormStartPosition.CenterScreen);
            if (Settings.bWindowVisible)
            {
                DetectStartupProjectSettingsWindow.Show();
                if (!bRestoreState)
                {
                    DetectStartupProjectSettingsWindow.Activate();
                }
            }
            DetectStartupProjectSettingsWindow.Complete += OnDetectStartupProjectsComplete;
        }
Ejemplo n.º 9
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;
                }
            }
        }
Ejemplo n.º 10
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(SqlConnectionString, Path.Combine(DataFolder, "Telemetry.log")))
			{
				try
				{
					using(UpdateMonitor UpdateMonitor = new UpdateMonitor(new PerforceConnection(null, null, null), UpdatePath))
					{
						MainWindow Window = new MainWindow(UpdateMonitor, SqlConnectionString, DataFolder, ActivateEvent, bRestoreState, UpdateSpawn ?? Assembly.GetExecutingAssembly().Location, ProjectFileName);
						if(bUnstable)
						{
							Window.Text += String.Format(" (UNSTABLE BUILD {0})", Assembly.GetExecutingAssembly().GetName().Version);
						}
						Application.Run(Window);

						if(UpdateMonitor.IsUpdateAvailable && UpdateSpawn != null)
						{
							InstanceMutex.Close();
							Utility.SpawnProcess(UpdateSpawn, "-restorestate" + (bUnstable? " -unstable" : ""));
						}
					}
				}
				catch(Exception Ex)
				{
					TelemetryWriter.Enqueue(TelemetryErrorType.Crash, Ex.ToString(), null, DateTime.Now);
					MessageBox.Show(String.Format("UnrealGameSync has crashed.\n\n{0}", Ex.ToString()));
				}
			}
		}
Ejemplo n.º 11
0
		public MainWindow(UpdateMonitor InUpdateMonitor, string InSqlConnectionString, string InDataFolder, EventWaitHandle ActivateEvent, bool bInRestoreStateOnLoad, string InOriginalExecutableFileName, string InProjectFileName)
		{
			InitializeComponent();

			NotifyMenu_OpenUnrealGameSync.Font = new Font(NotifyMenu_OpenUnrealGameSync.Font, FontStyle.Bold);

            if (Application.RenderWithVisualStyles) 
            { 
				SelectedItemRenderer = new VisualStyleRenderer("Explorer::ListView", 1, 3);
				TrackedItemRenderer = new VisualStyleRenderer("Explorer::ListView", 1, 2); 
			}

			UpdateMonitor = InUpdateMonitor;
			ActivationListener = new ActivationListener(ActivateEvent);
			SqlConnectionString = InSqlConnectionString;
			DataFolder = InDataFolder;
			bRestoreStateOnLoad = bInRestoreStateOnLoad;
			OriginalExecutableFileName = InOriginalExecutableFileName;
			
			Log = new BoundedLogWriter(Path.Combine(DataFolder, "UnrealGameSync.log"));
			Log.WriteLine("Application version: {0}", Assembly.GetExecutingAssembly().GetName().Version);
			Log.WriteLine("Started at {0}", DateTime.Now.ToString());

			Settings = new UserSettings(Path.Combine(DataFolder, "UnrealGameSync.ini"));
			if(!String.IsNullOrEmpty(InProjectFileName))
			{
				Settings.LastProjectFileName = InProjectFileName;
			}

			System.Reflection.PropertyInfo DoubleBufferedProperty = typeof(Control).GetProperty("DoubleBuffered", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
			DoubleBufferedProperty.SetValue(BuildList, true, null); 

			// force the height of the rows
			BuildList.SmallImageList = new ImageList(){ ImageSize = new Size(1, 20) };
			BuildList_FontChanged(null, null);
			BuildList.OnScroll += BuildList_OnScroll;

			Splitter.OnVisibilityChanged += Splitter_OnVisibilityChanged;
			
			UpdateTimer = new Timer();
			UpdateTimer.Interval = 30;
			UpdateTimer.Tick += TimerCallback;

			BuildAfterSyncCheckBox.Checked = Settings.bBuildAfterSync;
			RunAfterSyncCheckBox.Checked = Settings.bRunAfterSync;
			OpenSolutionAfterSyncCheckBox.Checked = Settings.bOpenSolutionAfterSync;
			Splitter.SetLogVisibility(Settings.bShowLogWindow);
			OptionsContextMenu_AutoResolveConflicts.Checked = Settings.bAutoResolveConflicts;
			OptionsContextMenu_UseIncrementalBuilds.Checked = Settings.bUseIncrementalBuilds;
			OptionsContextMenu_SyncPrecompiledEditor.Checked = Settings.bSyncPrecompiledEditor;
			
			UpdateCheckedBuildConfig();

			UpdateProjectList();
			UpdateSyncActionCheckboxes();
		}