public void OnModTextFilterChanges_CallsEventHandler() { var called_n = 0; var item = new MainModList(delegate { called_n++; }, delegate { return null; }); Assert.That(called_n == 1); item.ModNameFilter = "randomString"; Assert.That(called_n == 2); item.ModNameFilter = "randomString"; Assert.That(called_n == 2); }
public void OnModTypeFilterChanges_CallsEventHandler() { var called_n = 0; var item = new MainModList(delegate { called_n++; }, delegate { return null; }); Assert.That(called_n == 1); item.ModFilter = GUIModFilter.Installed; Assert.That(called_n == 2); item.ModFilter = GUIModFilter.Installed; Assert.That(called_n == 2); }
public Main(GUIUser User) { User.displayMessage = AddStatusMessage; User.displayError = ErrorDialog; controlFactory = new ControlFactory(); Instance = this; mainModList = new MainModList(source => UpdateFilters(this)); InitializeComponent(); // We need to initialize error dialog first to display errors m_ErrorDialog = controlFactory.CreateControl <ErrorDialog>(); // We want to check our current instance is null first, as it may // have already been set by a command-line option. Manager = new KSPManager(User); if (CurrentInstance == null && manager.GetPreferredInstance() == null) { Hide(); var result = new ChooseKSPInstance().ShowDialog(); if (result == DialogResult.Cancel || result == DialogResult.Abort) { Application.Exit(); return; } } m_Configuration = Configuration.LoadOrCreateConfiguration ( Path.Combine(CurrentInstance.GameDir(), "CKAN/GUIConfig.xml"), Repo.default_ckan_repo.ToString() ); FilterToolButton.MouseHover += (sender, args) => FilterToolButton.ShowDropDown(); launchKSPToolStripMenuItem.MouseHover += (sender, args) => launchKSPToolStripMenuItem.ShowDropDown(); ApplyToolButton.MouseHover += (sender, args) => ApplyToolButton.ShowDropDown(); ModList.CurrentCellDirtyStateChanged += ModList_CurrentCellDirtyStateChanged; ModList.CellValueChanged += ModList_CellValueChanged; m_TabController = new TabController(MainTabControl); m_TabController.ShowTab("ManageModsTabPage"); RecreateDialogs(); // We should run application only when we really sure. // System.Threading.Thread.CurrentThread.SetApartmentState(System.Threading.ApartmentState.STA); Util.HideConsoleWindow(); Application.Run(this); }
private async Task UpdateChangeSetAndConflicts(IRegistryQuerier registry) { IEnumerable <ModChange> full_change_set = null; Dictionary <GUIMod, string> new_conflicts = null; bool too_many_provides_thrown = false; var user_change_set = mainModList.ComputeUserChangeSet(); try { var module_installer = ModuleInstaller.GetInstance(CurrentInstance, GUI.user); full_change_set = await mainModList.ComputeChangeSetFromModList(registry, user_change_set, module_installer, CurrentInstance.VersionCriteria()); } catch (InconsistentKraken k) { // Need to be recomputed due to ComputeChangeSetFromModList possibly changing it with too many provides handling. AddStatusMessage(k.ShortDescription); user_change_set = mainModList.ComputeUserChangeSet(); new_conflicts = MainModList.ComputeConflictsFromModList(registry, user_change_set, CurrentInstance.VersionCriteria()); full_change_set = null; } catch (TooManyModsProvideKraken) { // Can be thrown by ComputeChangeSetFromModList if the user cancels out of it. // We can just rerun it as the ModInfoTabControl has been removed. too_many_provides_thrown = true; } catch (DependencyNotSatisfiedKraken k) { GUI.user.RaiseError( "{0} depends on {1}, which is not compatible with the currently installed version of KSP", k.parent, k.module ); // Uncheck the box MarkModForInstall(k.parent.identifier, true); } if (too_many_provides_thrown) { await UpdateChangeSetAndConflicts(registry); new_conflicts = Conflicts; full_change_set = ChangeSet; } last_mod_to_have_install_toggled.Clear(); Conflicts = new_conflicts; ChangeSet = full_change_set; }
private async Task UpdateChangeSetAndConflicts(IRegistryQuerier registry) { IEnumerable <ModChange> full_change_set = null; Dictionary <GUIMod, string> new_conflicts = null; bool too_many_provides_thrown = false; var user_change_set = mainModList.ComputeUserChangeSet(); try { var module_installer = ModuleInstaller.GetInstance(CurrentInstance, GUI.user); full_change_set = await mainModList.ComputeChangeSetFromModList(registry, user_change_set, module_installer, CurrentInstance.VersionCriteria()); } catch (InconsistentKraken) { //Need to be recomputed due to ComputeChangeSetFromModList possibly changing it with too many provides handling. user_change_set = mainModList.ComputeUserChangeSet(); new_conflicts = MainModList.ComputeConflictsFromModList(registry, user_change_set, CurrentInstance.VersionCriteria()); full_change_set = null; } catch (TooManyModsProvideKraken) { //Can be thrown by ComputeChangeSetFromModList if the user cancels out of it. //We can just rerun it as the ModInfoTabControl has been removed. too_many_provides_thrown = true; } if (too_many_provides_thrown) { await UpdateChangeSetAndConflicts(registry); new_conflicts = Conflicts; full_change_set = ChangeSet; } last_mod_to_have_install_toggled.Clear(); Conflicts = new_conflicts; ChangeSet = full_change_set; }
private void UpdateChangeSetAndConflicts(Registry registry) { IEnumerable <KeyValuePair <CkanModule, GUIModChangeType> > full_change_set; Dictionary <Module, string> conflicts; var user_change_set = mainModList.ComputeUserChangeSet(); try { var module_installer = ModuleInstaller.GetInstance(CurrentInstance, GUI.user); full_change_set = MainModList.ComputeChangeSetFromModList(registry, user_change_set, module_installer, CurrentInstance.Version()); conflicts = null; } catch (InconsistentKraken) { conflicts = MainModList.ComputeConflictsFromModList(registry, user_change_set, CurrentInstance.Version()); full_change_set = null; } Conflicts = conflicts; ChangeSet = full_change_set; }
public async Task ComputeChangeSetFromModList_WithConflictingMods_ThrowsInconsistentKraken() { using (var tidy = new DisposableKSP()) { KSPManager manager = new KSPManager(new NullUser(), new FakeWin32Registry(tidy.KSP)) { CurrentInstance = tidy.KSP }; var registry = Registry.Empty(); var module = TestData.FireSpitterModule(); module.conflicts = new List<RelationshipDescriptor> { new RelationshipDescriptor { name = "kOS" } }; registry.AddAvailable(TestData.FireSpitterModule()); registry.AddAvailable(TestData.kOS_014_module()); registry.RegisterModule(module, Enumerable.Empty<string>(), tidy.KSP); var main_mod_list = new MainModList(null, null); var mod = new GUIMod(TestData.FireSpitterModule(), registry, manager.CurrentInstance.Version()); var mod2 = new GUIMod(TestData.kOS_014_module(), registry, manager.CurrentInstance.Version()); mod.IsInstallChecked = true; mod2.IsInstallChecked = true; var compute_change_set_from_mod_list = main_mod_list.ComputeChangeSetFromModList(registry, main_mod_list.ComputeUserChangeSet(), null, tidy.KSP.Version()); await UtilStatic.Throws<InconsistentKraken>(async ()=> { await compute_change_set_from_mod_list; }); } }
public async Task ComputeChangeSetFromModList_WithConflictingMods_ThrowsInconsistentKraken() { using (var tidy = new DisposableKSP()) { var registry = Registry.Empty(); var module = TestData.FireSpitterModule(); module.conflicts = new List<RelationshipDescriptor> { new RelationshipDescriptor { name = "kOS" } }; registry.AddAvailable(module); registry.AddAvailable(TestData.kOS_014_module()); registry.RegisterModule(module, Enumerable.Empty<string>(), tidy.KSP); var mainList = new MainModList(null, null, new GUIUser()); var mod = new GUIMod(module, registry, tidy.KSP.VersionCriteria()); var mod2 = new GUIMod(TestData.kOS_014_module(), registry, tidy.KSP.VersionCriteria()); var mods = new List<GUIMod>() { mod, mod2 }; mainList.ConstructModList(mods, true); mainList.Modules = new ReadOnlyCollection<GUIMod>(mods); mod2.IsInstallChecked = true; var computeTask = mainList.ComputeChangeSetFromModList(registry, mainList.ComputeUserChangeSet(), null, tidy.KSP.VersionCriteria()); await UtilStatic.Throws<InconsistentKraken>(() => computeTask); } }
public void CountModsByFilter_EmptyModList_ReturnsZeroForAllFilters() { var item = new MainModList(delegate { }, null); foreach (GUIModFilter filter in Enum.GetValues(typeof(GUIModFilter))) { Assert.That(item.CountModsByFilter(filter), Is.EqualTo(0)); } }
public void Up() { _instance = new DisposableKSP(); _registry = Registry.Empty(); _manager = new KSPManager(new NullUser(), new FakeWin32Registry(_instance.KSP)); // this module contains a ksp_version of "any" which repros our issue _anyVersionModule = TestData.DogeCoinFlag_101_module(); // install it and set it as pre-installed _instance.KSP.Cache.Store(TestData.DogeCoinFlag_101_module().download, TestData.DogeCoinFlagZip()); _registry.RegisterModule(_anyVersionModule, new string[] { }, _instance.KSP); _registry.AddAvailable(_anyVersionModule); ModuleInstaller.GetInstance(_instance.KSP, _manager.User).InstallList( new List<CkanModule> { { _anyVersionModule } }, new RelationshipResolverOptions(), new NetAsyncModulesDownloader(_manager.User) ); // this module is not for "any" version, to provide another to sort against _registry.AddAvailable(TestData.kOS_014_module()); // test object _modList = new MainModList(null, null, _manager.User); _listGui = new MainModListGUI(); // todo: refactor the column header code to allow mocking of the GUI without creating columns _listGui.Columns.Add(new DataGridViewCheckBoxColumn()); _listGui.Columns.Add(new DataGridViewCheckBoxColumn()); for (int i = 0; i < 10; i++) { _listGui.Columns.Add(i.ToString(), "Column" + i); } }
public void IsVisible_WithAllAndNoNameFilter_ReturnsTrueForCompatible() { using (var tidy = new DisposableKSP()) { KSPManager manager = new KSPManager(new NullUser(), new FakeWin32Registry(tidy.KSP)) { CurrentInstance = tidy.KSP }; var ckan_mod = TestData.FireSpitterModule(); var registry = Registry.Empty(); registry.AddAvailable(ckan_mod); var item = new MainModList(delegate { }, null); Assert.That(item.IsVisible(new GUIMod(ckan_mod, registry, manager.CurrentInstance.Version()))); } }
public Main(string[] cmdlineArgs, GUIUser User, bool showConsole) { log.Info("Starting the GUI"); m_CommandLineArgs = cmdlineArgs; m_User = User; User.displayMessage = AddStatusMessage; User.displayError = ErrorDialog; controlFactory = new ControlFactory(); Instance = this; mainModList = new MainModList(source => UpdateFilters(this), TooManyModsProvide, User); InitializeComponent(); // We need to initialize error dialog first to display errors m_ErrorDialog = controlFactory.CreateControl <ErrorDialog>(); // We want to check our current instance is null first, as it may // have already been set by a command-line option. Manager = new KSPManager(User); if (CurrentInstance == null && manager.GetPreferredInstance() == null) { Hide(); var result = new ChooseKSPInstance().ShowDialog(); if (result == DialogResult.Cancel || result == DialogResult.Abort) { Application.Exit(); return; } } m_Configuration = Configuration.LoadOrCreateConfiguration ( Path.Combine(CurrentInstance.GameDir(), "CKAN/GUIConfig.xml"), Repo.default_ckan_repo.ToString() ); FilterToolButton.MouseHover += (sender, args) => FilterToolButton.ShowDropDown(); launchKSPToolStripMenuItem.MouseHover += (sender, args) => launchKSPToolStripMenuItem.ShowDropDown(); ApplyToolButton.MouseHover += (sender, args) => ApplyToolButton.ShowDropDown(); ModList.CurrentCellDirtyStateChanged += ModList_CurrentCellDirtyStateChanged; ModList.CellValueChanged += ModList_CellValueChanged; m_TabController = new TabController(MainTabControl); m_TabController.ShowTab("ManageModsTabPage"); RecreateDialogs(); if (!showConsole) { Util.HideConsoleWindow(); } // Disable the modinfo controls until a mod has been choosen. ModInfoTabControl.Enabled = false; // WinForms on Mac OS X has a nasty bug where the UI thread hogs the CPU, // making our download speeds really slow unless you move the mouse while // downloading. Yielding periodically addresses that. // https://bugzilla.novell.com/show_bug.cgi?id=663433 if (Platform.IsMac) { var yield_timer = new Timer { Interval = 2 }; yield_timer.Tick += (sender, e) => { Thread.Yield(); }; yield_timer.Start(); } Application.Run(this); }
public void ComputeChangeSetFromModList_WithEmptyList_HasEmptyChangeSet() { var item = new MainModList(delegate { }, delegate { return null; }); Assert.That(item.ComputeUserChangeSet(), Is.Empty); }
public void OnCreation_HasDefaultFilters() { var item = new MainModList(delegate { }, delegate { return null; }); Assert.AreEqual(GUIModFilter.Compatible, item.ModFilter, "ModFilter"); Assert.AreEqual(String.Empty, item.ModNameFilter, "ModNameFilter"); }
public Main(string[] cmdlineArgs, GUIUser User, bool showConsole) { log.Info("Starting the GUI"); m_CommandLineArgs = cmdlineArgs; m_User = User; User.displayMessage = AddStatusMessage; User.displayError = ErrorDialog; controlFactory = new ControlFactory(); Instance = this; mainModList = new MainModList(source => UpdateFilters(this), TooManyModsProvide, User); InitializeComponent(); // We need to initialize error dialog first to display errors m_ErrorDialog = controlFactory.CreateControl<ErrorDialog>(); // We want to check our current instance is null first, as it may // have already been set by a command-line option. Manager = new KSPManager(User); if (CurrentInstance == null && manager.GetPreferredInstance() == null) { Hide(); var result = new ChooseKSPInstance().ShowDialog(); if (result == DialogResult.Cancel || result == DialogResult.Abort) { Application.Exit(); return; } } m_Configuration = Configuration.LoadOrCreateConfiguration ( Path.Combine(CurrentInstance.GameDir(), "CKAN/GUIConfig.xml"), Repo.default_ckan_repo.ToString() ); FilterToolButton.MouseHover += (sender, args) => FilterToolButton.ShowDropDown(); launchKSPToolStripMenuItem.MouseHover += (sender, args) => launchKSPToolStripMenuItem.ShowDropDown(); ApplyToolButton.MouseHover += (sender, args) => ApplyToolButton.ShowDropDown(); ModList.CurrentCellDirtyStateChanged += ModList_CurrentCellDirtyStateChanged; ModList.CellValueChanged += ModList_CellValueChanged; m_TabController = new TabController(MainTabControl); m_TabController.ShowTab("ManageModsTabPage"); RecreateDialogs(); if (!showConsole) { Util.HideConsoleWindow(); } // Disable the modinfo controls until a mod has been choosen. ModInfoTabControl.Enabled = false; // WinForms on Mac OS X has a nasty bug where the UI thread hogs the CPU, // making our download speeds really slow unless you move the mouse while // downloading. Yielding periodically addresses that. // https://bugzilla.novell.com/show_bug.cgi?id=663433 if (Platform.IsMac) { var yield_timer = new Timer {Interval = 2}; yield_timer.Tick += (sender, e) => { Thread.Yield(); }; yield_timer.Start(); } Application.Run(this); }
public async Task TooManyProvidesCallsHandlers() { using (var tidy = new DisposableKSP()) { var registry = Registry.Empty(); var generator = new RandomModuleGenerator(new Random(0451)); var provide_ident = "provide"; var ksp_version = tidy.KSP.Version(); var mod = generator.GeneratorRandomModule(depends: new List<RelationshipDescriptor> { new RelationshipDescriptor {name = provide_ident} },ksp_version:ksp_version); var moda = generator.GeneratorRandomModule(provides: new List<string> { provide_ident } , ksp_version: ksp_version); var modb = generator.GeneratorRandomModule(provides: new List<string> { provide_ident } , ksp_version: ksp_version); var choice_of_provide = modb; registry.AddAvailable(mod); registry.AddAvailable(moda); registry.AddAvailable(modb); var installer = ModuleInstaller.GetInstance(tidy.KSP, null); var main_mod_list = new MainModList(null, async kraken => await Task.FromResult(choice_of_provide)); var a = new HashSet<ModChange> { new ModChange(new GUIMod(mod,registry,ksp_version), GUIModChangeType.Install, null) }; var mod_list = await main_mod_list.ComputeChangeSetFromModList(registry, a, installer, ksp_version); CollectionAssert.AreEquivalent( new[] { new ModChange(new GUIMod(mod,registry,ksp_version), GUIModChangeType.Install, null), new ModChange(new GUIMod(modb,registry,ksp_version),GUIModChangeType.Install, null) }, mod_list); } }
public void ConstructModList_NumberOfRows_IsEqualToNumberOfMods() { using (var tidy = new DisposableKSP()) { KSPManager manager = new KSPManager(new NullUser(), new FakeWin32Registry(tidy.KSP)) { CurrentInstance = tidy.KSP }; var registry = Registry.Empty(); registry.AddAvailable(TestData.FireSpitterModule()); registry.AddAvailable(TestData.kOS_014_module()); var main_mod_list = new MainModList(null, null); var mod_list = main_mod_list.ConstructModList(new List<GUIMod> { new GUIMod(TestData.FireSpitterModule(), registry, manager.CurrentInstance.Version()), new GUIMod(TestData.kOS_014_module(), registry, manager.CurrentInstance.Version()) }); Assert.That(mod_list, Has.Count.EqualTo(2)); } }
public Main(string[] cmdlineArgs, KSPManager mgr, GUIUser user, bool showConsole) { log.Info("Starting the GUI"); commandLineArgs = cmdlineArgs; manager = mgr ?? new KSPManager(user); currentUser = user; controlFactory = new ControlFactory(); Instance = this; mainModList = new MainModList(source => UpdateFilters(this), TooManyModsProvide, user); // History is read-only until the UI is started. We switch // out of it at the end of OnLoad() when we call NavInit(). navHistory = new NavigationHistory <GUIMod> { IsReadOnly = true }; InitializeComponent(); // Replace mono's broken, ugly toolstrip renderer if (Platform.IsMono) { menuStrip1.Renderer = new FlatToolStripRenderer(); menuStrip2.Renderer = new FlatToolStripRenderer(); fileToolStripMenuItem.DropDown.Renderer = new FlatToolStripRenderer(); settingsToolStripMenuItem.DropDown.Renderer = new FlatToolStripRenderer(); helpToolStripMenuItem.DropDown.Renderer = new FlatToolStripRenderer(); FilterToolButton.DropDown.Renderer = new FlatToolStripRenderer(); minimizedContextMenuStrip.Renderer = new FlatToolStripRenderer(); ModListContextMenuStrip.Renderer = new FlatToolStripRenderer(); ModListHeaderContextMenuStrip.Renderer = new FlatToolStripRenderer(); } // Initialize all user interaction dialogs. RecreateDialogs(); // We want to check if our current instance is null first, // as it may have already been set by a command-line option. if (CurrentInstance == null && manager.GetPreferredInstance() == null) { Hide(); var result = new ManageKspInstances(!actuallyVisible).ShowDialog(); if (result == DialogResult.Cancel || result == DialogResult.Abort) { Application.Exit(); return; } } configuration = Configuration.LoadOrCreateConfiguration ( Path.Combine(CurrentInstance.CkanDir(), "GUIConfig.xml") ); // Check if there is any other instances already running. // This is not entirely necessary, but we can show a nicer error message this way. try { #pragma warning disable 219 var lockedReg = RegistryManager.Instance(CurrentInstance).registry; #pragma warning restore 219 } catch (RegistryInUseKraken kraken) { errorDialog.ShowErrorDialog(kraken.ToString()); return; } FilterToolButton.MouseHover += (sender, args) => FilterToolButton.ShowDropDown(); launchKSPToolStripMenuItem.MouseHover += (sender, args) => launchKSPToolStripMenuItem.ShowDropDown(); ApplyToolButton.MouseHover += (sender, args) => ApplyToolButton.ShowDropDown(); ModList.CurrentCellDirtyStateChanged += ModList_CurrentCellDirtyStateChanged; ModList.CellValueChanged += ModList_CellValueChanged; tabController = new TabController(MainTabControl); tabController.ShowTab("ManageModsTabPage"); if (!showConsole) { Util.HideConsoleWindow(); } // Disable the modinfo controls until a mod has been choosen. This has an effect if the modlist is empty. ActiveModInfo = null; // WinForms on Mac OS X has a nasty bug where the UI thread hogs the CPU, // making our download speeds really slow unless you move the mouse while // downloading. Yielding periodically addresses that. // https://bugzilla.novell.com/show_bug.cgi?id=663433 if (Platform.IsMac) { var timer = new Timer { Interval = 2 }; timer.Tick += (sender, e) => { Thread.Yield(); }; timer.Start(); } // Set the window name and class for X11 if (Platform.IsX11) { HandleCreated += (sender, e) => X11.SetWMClass("CKAN", "CKAN", Handle); } Application.Run(this); var registry = RegistryManager.Instance(Manager.CurrentInstance); registry?.Dispose(); }
public Main(string[] cmdlineArgs, GUIUser user, bool showConsole) { log.Info("Starting the GUI"); commandLineArgs = cmdlineArgs; currentUser = user; user.displayMessage = AddStatusMessage; user.displayError = ErrorDialog; controlFactory = new ControlFactory(); Instance = this; mainModList = new MainModList(source => UpdateFilters(this), TooManyModsProvide, user); navHistory = new NavigationHistory <GUIMod>(); navHistory.IsReadOnly = true; // read-only until the UI is started. // we switch out of it at the end of OnLoad() // when we call NavInit() InitializeComponent(); // We need to initialize error dialog first to display errors errorDialog = controlFactory.CreateControl <ErrorDialog>(); // We want to check our current instance is null first, as it may // have already been set by a command-line option. Manager = new KSPManager(user); if (CurrentInstance == null && manager.GetPreferredInstance() == null) { Hide(); var result = new ChooseKSPInstance().ShowDialog(); if (result == DialogResult.Cancel || result == DialogResult.Abort) { Application.Exit(); return; } } configuration = Configuration.LoadOrCreateConfiguration ( Path.Combine(CurrentInstance.GameDir(), "CKAN/GUIConfig.xml"), Repo.default_ckan_repo.ToString() ); // Check if there is any other instances already running. // This is not entirely necessary, but we can show a nicer error message this way. try { #pragma warning disable 219 var lockedReg = RegistryManager.Instance(CurrentInstance).registry; #pragma warning restore 219 } catch (RegistryInUseKraken kraken) { errorDialog.ShowErrorDialog(kraken.ToString()); return; } FilterToolButton.MouseHover += (sender, args) => FilterToolButton.ShowDropDown(); launchKSPToolStripMenuItem.MouseHover += (sender, args) => launchKSPToolStripMenuItem.ShowDropDown(); ApplyToolButton.MouseHover += (sender, args) => ApplyToolButton.ShowDropDown(); ModList.CurrentCellDirtyStateChanged += ModList_CurrentCellDirtyStateChanged; ModList.CellValueChanged += ModList_CellValueChanged; tabController = new TabController(MainTabControl); tabController.ShowTab("ManageModsTabPage"); RecreateDialogs(); if (!showConsole) { Util.HideConsoleWindow(); } // Disable the modinfo controls until a mod has been choosen. ModInfoTabControl.SelectedModule = null; // WinForms on Mac OS X has a nasty bug where the UI thread hogs the CPU, // making our download speeds really slow unless you move the mouse while // downloading. Yielding periodically addresses that. // https://bugzilla.novell.com/show_bug.cgi?id=663433 if (Platform.IsMac) { var timer = new Timer { Interval = 2 }; timer.Tick += (sender, e) => { Thread.Yield(); }; timer.Start(); } Application.Run(this); var registry = RegistryManager.Instance(Manager.CurrentInstance); if (registry != null) { registry.Dispose(); } }
public Main(string[] cmdlineArgs, GUIUser user, bool showConsole) { log.Info("Starting the GUI"); commandLineArgs = cmdlineArgs; currentUser = user; user.displayMessage = AddStatusMessage; user.displayError = ErrorDialog; controlFactory = new ControlFactory(); Instance = this; mainModList = new MainModList(source => UpdateFilters(this), TooManyModsProvide, user); navHistory = new NavigationHistory<GUIMod>(); navHistory.IsReadOnly = true; // read-only until the UI is started. // we switch out of it at the end of OnLoad() // when we call NavInit() InitializeComponent(); // We need to initialize error dialog first to display errors errorDialog = controlFactory.CreateControl<ErrorDialog>(); // We want to check our current instance is null first, as it may // have already been set by a command-line option. Manager = new KSPManager(user); if (CurrentInstance == null && manager.GetPreferredInstance() == null) { Hide(); var result = new ChooseKSPInstance().ShowDialog(); if (result == DialogResult.Cancel || result == DialogResult.Abort) { Application.Exit(); return; } } configuration = Configuration.LoadOrCreateConfiguration ( Path.Combine(CurrentInstance.GameDir(), "CKAN/GUIConfig.xml"), Repo.default_ckan_repo.ToString() ); // Check if there is any other instances already running. // This is not entirely necessary, but we can show a nicer error message this way. try { #pragma warning disable 219 var lockedReg = RegistryManager.Instance(CurrentInstance).registry; #pragma warning restore 219 } catch (RegistryInUseKraken kraken) { errorDialog.ShowErrorDialog(kraken.ToString()); return; } FilterToolButton.MouseHover += (sender, args) => FilterToolButton.ShowDropDown(); launchKSPToolStripMenuItem.MouseHover += (sender, args) => launchKSPToolStripMenuItem.ShowDropDown(); ApplyToolButton.MouseHover += (sender, args) => ApplyToolButton.ShowDropDown(); ModList.CurrentCellDirtyStateChanged += ModList_CurrentCellDirtyStateChanged; ModList.CellValueChanged += ModList_CellValueChanged; tabController = new TabController(MainTabControl); tabController.ShowTab("ManageModsTabPage"); RecreateDialogs(); if (!showConsole) { Util.HideConsoleWindow(); } // Disable the modinfo controls until a mod has been choosen. ModInfoTabControl.SelectedModule = null; // WinForms on Mac OS X has a nasty bug where the UI thread hogs the CPU, // making our download speeds really slow unless you move the mouse while // downloading. Yielding periodically addresses that. // https://bugzilla.novell.com/show_bug.cgi?id=663433 if (Platform.IsMac) { var timer = new Timer { Interval = 2 }; timer.Tick += (sender, e) => { Thread.Yield(); }; timer.Start(); } Application.Run(this); var registry = RegistryManager.Instance(Manager.CurrentInstance); if (registry != null) { registry.Dispose(); } }