public void InstanceAccessorState() { // Make sure that LoadInstancesFromRegistry sets the // internal instances_loaded variable correctly. CKAN.KSPManager manager = new CKAN.KSPManager(NullUser.User); Assert.IsTrue(manager.instances_loaded); }
public void ComputeChangeSetFromModList_WithEmptyList_HasEmptyChangeSet() { using (var tidy = new DisposableKSP()) { CKAN.KSPManager manager = new CKAN.KSPManager(new NullUser()) { _CurrentInstance = tidy.KSP }; var item = new MainModList(delegate { }); Assert.That(item.ComputeChangeSetFromModList(CKAN.Registry.Empty(), manager.CurrentInstance), Is.Empty); } }
public void NewGuiModsAreNotSelectedForUpgrade() { using (var tidy = new DisposableKSP()) { KSPManager manager = new KSPManager(new NullUser(), new FakeWin32Registry(tidy.KSP)){CurrentInstance = tidy.KSP}; var registry = Registry.Empty(); var ckan_mod = TestData.kOS_014_module(); registry.AddAvailable(ckan_mod); var mod = new GUIMod(ckan_mod, registry, manager.CurrentInstance.Version()); Assert.False(mod.IsUpgradeChecked); } }
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 void NewGuiModsAreNotSelectedForUpgrade() { using (var tidy = new DisposableKSP()) { CKAN.KSPManager manager = new CKAN.KSPManager(new NullUser()) { _CurrentInstance = tidy.KSP }; var registry = CKAN.Registry.Empty(); var ckanMod = TestData.kOS_014_module(); registry.AddAvailable(ckanMod); var mod = new GUIMod(ckanMod, registry, manager.CurrentInstance.Version()); Assert.False(mod.IsUpgradeChecked); } }
public ChooseKSPInstance() { _manager = Main.Instance.Manager; InitializeComponent(); StartPosition = FormStartPosition.CenterScreen; if (!_manager.Instances.Any()) { _manager.FindAndRegisterDefaultInstance(); } UpdateInstancesList(); UpdateButtonState(); }
public void IsVisible_WithAllAndNoNameFilter_ReturnsTrueForCompatible() { using (var tidy = new DisposableKSP()) { CKAN.KSPManager manager = new CKAN.KSPManager(new NullUser()) { _CurrentInstance = tidy.KSP }; var ckanMod = TestData.FireSpitterModule(); var registry = CKAN.Registry.Empty(); registry.AddAvailable(ckanMod); var item = new MainModList(delegate { }); Assert.That(item.IsVisible(new GUIMod(ckanMod, registry, manager.CurrentInstance.Version()))); } }
public ChooseKSPInstance() { manager = Main.Instance.Manager; InitializeComponent(); StartPosition = FormStartPosition.CenterScreen; m_BrowseKSPFolder = new FolderBrowserDialog(); if (!manager.Instances.Any()) { manager.FindAndRegisterDefaultInstance(); } UpdateInstancesList(); SetButtonsEnabled(false); }
public void UninstallModNotFound() { using (var tidy = new Tests.DisposableKSP()) { CKAN.KSPManager manager = new CKAN.KSPManager(new NullUser(), new FakeWin32Registry(tidy.KSP)) { CurrentInstance = tidy.KSP }; Assert.Throws <ModNotInstalledKraken>(delegate { // This should throw, as our tidy KSP has no mods installed. CKAN.ModuleInstaller.GetInstance(manager.CurrentInstance, NullUser.User).UninstallList("Foo"); }); manager.CurrentInstance = null; // I weep even more. } }
public void Setup() { manager = new KSPManager(new NullUser()); // Give us a registry to play with. ksp = new DisposableKSP(); registry_manager = CKAN.RegistryManager.Instance(ksp.KSP); registry = registry_manager.registry; registry.ClearDlls(); registry.Installed().Clear(); // Make sure we have a registry we can use. CKAN.Repo.Update(registry_manager, ksp.KSP, new NullUser(), TestData.TestKANZip()); // Ready our downloader. async = new CKAN.NetAsyncModulesDownloader(new NullUser(), manager.Cache); // General shortcuts cache = manager.Cache; }
public void ConstructModList_NumberOfRows_IsEqualToNumberOfMods() { using (var tidy = new DisposableKSP()) { CKAN.KSPManager manager = new CKAN.KSPManager(new NullUser()) { _CurrentInstance = tidy.KSP }; var registry = CKAN.Registry.Empty(); registry.AddAvailable(TestData.FireSpitterModule()); registry.AddAvailable(TestData.kOS_014_module()); var modList = MainModList.ConstructModList(new List <GUIMod> { new GUIMod(TestData.FireSpitterModule(), registry, manager.CurrentInstance.Version()), new GUIMod(TestData.kOS_014_module(), registry, manager.CurrentInstance.Version()) }); Assert.That(modList, Has.Count.EqualTo(2)); } }
public void HasUpdateReturnsTrueWhenUpdateAvailible() { using (var tidy = new DisposableKSP()) { CKAN.KSPManager manager = new CKAN.KSPManager(new NullUser()) { _CurrentInstance = tidy.KSP }; var generatror = new RandomModuleGenerator(new Random(0451)); var oldVersion = generatror.GeneratorRandomModule(version: new CKAN.Version("0.24"), kspVersion: tidy.KSP.Version()); var newVersion = generatror.GeneratorRandomModule(version: new CKAN.Version("0.25"), kspVersion: tidy.KSP.Version(), identifier: oldVersion.identifier); var registry = CKAN.Registry.Empty(); registry.RegisterModule(oldVersion, Enumerable.Empty <string>(), null); registry.AddAvailable(newVersion); var mod = new GUIMod(oldVersion, registry, tidy.KSP.Version()); Assert.True(mod.HasUpdate); } }
public void CanUninstallMod() { string mod_file_name = "DogeCoinFlag/Flags/dogecoin.png"; // Create a new disposable KSP instance to run the test on. using (var ksp = new Tests.DisposableKSP()) { CKAN.KSPManager manager = new CKAN.KSPManager(new NullUser(), new FakeWin32Registry(ksp.KSP)) { CurrentInstance = ksp.KSP }; System.Diagnostics.Debug.WriteLine(ksp.KSP.DownloadCacheDir()); System.Console.WriteLine(ksp.KSP.DownloadCacheDir()); Assert.IsTrue(Directory.Exists(ksp.KSP.DownloadCacheDir())); string mod_file_path = Path.Combine(ksp.KSP.GameData(), mod_file_name); // Install the test mod. ksp.KSP.Cache.Store(Tests.TestData.DogeCoinFlag_101_module().download, Tests.TestData.DogeCoinFlagZip()); ksp.KSP.Registry.AddAvailable(Tests.TestData.DogeCoinFlag_101_module()); List <string> modules = new List <string>(); modules.Add(Tests.TestData.DogeCoinFlag_101_module().identifier); CKAN.ModuleInstaller.GetInstance(manager.CurrentInstance, NullUser.User).InstallList(modules, new RelationshipResolverOptions()); // Check that the module is installed. Assert.IsTrue(File.Exists(mod_file_path)); // Attempt to uninstall it. CKAN.ModuleInstaller.GetInstance(manager.CurrentInstance, NullUser.User).UninstallList(modules); // Check that the module is not installed. Assert.IsFalse(File.Exists(mod_file_path)); } }
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 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 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"); 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); }
/// <summary> /// Initialize a cache given a KSPManager /// </summary> /// <param name="mgr">KSPManager object containing the Instances that might have old caches</param> public NetFileCache(KSPManager mgr, string path) : this(path) { manager = mgr; }
/// <summary> /// Initialize the cache /// </summary> /// <param name="mgr">KSPManager containing instances that might have legacy caches</param> public NetModuleCache(KSPManager mgr, string path) { cache = new NetFileCache(mgr, path); }
public void UninstallEmptyDirs() { string emptyFolderName = "DogeCoinFlag"; // Create a new disposable KSP instance to run the test on. using (var ksp = new DisposableKSP()) { KSPManager manager = new KSPManager(new NullUser(), new FakeWin32Registry(ksp.KSP)){CurrentInstance = ksp.KSP}; Assert.IsTrue(Directory.Exists(ksp.KSP.DownloadCacheDir())); string directoryPath = Path.Combine(ksp.KSP.GameData(), emptyFolderName); // Install the base test mod. var registry = CKAN.RegistryManager.Instance(ksp.KSP).registry; ksp.KSP.Cache.Store(TestData.DogeCoinFlag_101_module().download, TestData.DogeCoinFlagZip()); registry.AddAvailable(TestData.DogeCoinFlag_101_module()); List<string> modules = new List<string> {TestData.DogeCoinFlag_101_module().identifier}; CKAN.ModuleInstaller.GetInstance(manager.CurrentInstance, NullUser.User).InstallList(modules, new RelationshipResolverOptions()); modules.Clear(); // Install the plugin test mod. ksp.KSP.Cache.Store(TestData.DogeCoinPlugin_module().download, TestData.DogeCoinPluginZip()); registry.AddAvailable(TestData.DogeCoinPlugin_module()); modules.Add(TestData.DogeCoinPlugin_module().identifier); CKAN.ModuleInstaller.GetInstance(manager.CurrentInstance, NullUser.User).InstallList(modules, new RelationshipResolverOptions()); modules.Clear(); // Check that the directory is installed. Assert.IsTrue(Directory.Exists(directoryPath)); // Uninstall both mods. modules.Add(TestData.DogeCoinFlag_101_module().identifier); modules.Add(TestData.DogeCoinPlugin_module().identifier); CKAN.ModuleInstaller.GetInstance(manager.CurrentInstance, NullUser.User).UninstallList(modules); // Check that the directory has been deleted. Assert.IsFalse(Directory.Exists(directoryPath)); } }
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 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 void SetUp() { tidy = new DisposableKSP(); win32_reg = GetTestWin32Reg(nameInReg); manager = new KSPManager(new NullUser(), win32_reg); }
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, KSPManager mgr, bool showConsole) { log.Info("Starting the GUI"); commandLineArgs = cmdlineArgs; Configuration.IConfiguration mainConfig = ServiceLocator.Container.Resolve <Configuration.IConfiguration>(); // If the language is not set yet in the config, try to save the current language. // If it isn't supported, it'll still be null afterwards. Doesn't matter, .NET handles the resource selection. // Once the user chooses a language in the settings, the string will be no longer null, and we can change // CKAN's language here before any GUI components are initialized. if (string.IsNullOrEmpty(mainConfig.Language)) { string runtimeLanguage = Thread.CurrentThread.CurrentUICulture.IetfLanguageTag; mainConfig.Language = runtimeLanguage; } else { Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(mainConfig.Language); } InitializeComponent(); Instance = this; currentUser = new GUIUser(this, this.Wait); manager = mgr ?? new KSPManager(currentUser); controlFactory = new ControlFactory(); // React when the user clicks a tag or filter link in mod info ModInfo.OnChangeFilter += ManageMods.Filter; // Replace mono's broken, ugly toolstrip renderer if (Platform.IsMono) { menuStrip1.Renderer = new FlatToolStripRenderer(); fileToolStripMenuItem.DropDown.Renderer = new FlatToolStripRenderer(); settingsToolStripMenuItem.DropDown.Renderer = new FlatToolStripRenderer(); helpToolStripMenuItem.DropDown.Renderer = new FlatToolStripRenderer(); minimizedContextMenuStrip.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 ManageKspInstancesDialog(!actuallyVisible, currentUser).ShowDialog(); if (result == DialogResult.Cancel || result == DialogResult.Abort) { Application.Exit(); return; } } configuration = GUIConfiguration.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; } 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 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 void UninstallModNotFound() { using (var tidy = new DisposableKSP()) { KSPManager manager = new KSPManager(new NullUser(), new FakeWin32Registry(tidy.KSP)){CurrentInstance = tidy.KSP}; Assert.Throws<ModNotInstalledKraken>(delegate { // This should throw, as our tidy KSP has no mods installed. CKAN.ModuleInstaller.GetInstance(manager.CurrentInstance, NullUser.User).UninstallList("Foo"); }); manager.CurrentInstance = null; // I weep even more. } }
public void CanUninstallMod() { string mod_file_name = "DogeCoinFlag/Flags/dogecoin.png"; // Create a new disposable KSP instance to run the test on. using (var ksp = new DisposableKSP()) { KSPManager manager = new KSPManager(new NullUser(), new FakeWin32Registry(ksp.KSP)){CurrentInstance = ksp.KSP}; Assert.IsTrue(Directory.Exists(ksp.KSP.DownloadCacheDir())); string mod_file_path = Path.Combine(ksp.KSP.GameData(), mod_file_name); // Install the test mod. var registry = CKAN.RegistryManager.Instance(ksp.KSP).registry; ksp.KSP.Cache.Store(TestData.DogeCoinFlag_101_module().download, TestData.DogeCoinFlagZip()); registry.AddAvailable(TestData.DogeCoinFlag_101_module()); List<string> modules = new List<string> {TestData.DogeCoinFlag_101_module().identifier}; CKAN.ModuleInstaller.GetInstance(manager.CurrentInstance, NullUser.User).InstallList(modules, new RelationshipResolverOptions()); // Check that the module is installed. Assert.IsTrue(File.Exists(mod_file_path)); // Attempt to uninstall it. CKAN.ModuleInstaller.GetInstance(manager.CurrentInstance, NullUser.User).UninstallList(modules); // Check that the module is not installed. Assert.IsFalse(File.Exists(mod_file_path)); } }
public Repo(KSPManager manager, IUser user) { Manager = manager; User = user; }