Ejemplo n.º 1
0
        /// <summary>
        /// First run initialization of config directory.
        /// </summary>
        protected static void CreateConfigDir()
        {
            string path = KSPPathHelper.GetPath(KSPPaths.AppConfig);

            path = Directory.GetParent(path).ToString();
            if (!Directory.Exists(path))
            {
                Messenger.AddDebug("Creating config directory: " + path);
                Directory.CreateDirectory(path);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Downloads the mod.
        /// </summary>
        /// <param name="modInfo">The infos of the mod. Must have at least ModURL and LocalPath</param>
        /// <param name="downloadProgressCallback">Callback function for download progress.</param>
        /// <returns>True if the mod was downloaded.</returns>
        public bool DownloadMod(ref ModInfo modInfo, DownloadProgressCallback downloadProgressCallback = null)
        {
            if (modInfo == null)
            {
                return(false);
            }

            var          downloadInfos = GetDownloadInfo(modInfo);
            DownloadInfo selected      = null;

            if (downloadInfos.Count > 1)
            {
                // create new selection form if more than one download option found
                var dlg = new frmSelectDownload(downloadInfos);
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    selected = dlg.SelectedLink;
                }
            }
            else if (downloadInfos.Count == 1)
            {
                selected = downloadInfos.First();
            }
            else
            {
                string msg = string.Format(Messages.MSG_NO_BINARY_DOWNLOAD_FOUND_AT_0, modInfo.SiteHandlerName);
                MessageBox.Show(msg, Messages.MSG_TITLE_ERROR);
                Messenger.AddDebug(msg);
                return(false);
            }

            if (selected != null)
            {
                string downloadUrl = selected.DownloadURL;
                modInfo.LocalPath = Path.Combine(OptionsController.DownloadPath, selected.Filename);
                Www.DownloadFile(downloadUrl, modInfo.LocalPath, downloadProgressCallback);
            }

            return(File.Exists(modInfo.LocalPath));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Loads all Plugins for KSP Mod Admin.
        /// </summary>
        protected static void LoadPlugins()
        {
            Messenger.AddDebug("Loading plugins ...");
            List <IKSPMAPlugin> plugins = null;

            try
            {
                plugins = PluginLoader.LoadPlugins <IKSPMAPlugin>(KSPPathHelper.GetPath(KSPPaths.KSPMA_Plugins));
            }
            catch (Exception ex)
            {
                Messenger.AddError("Error during plugin loading! Plugin loading aborded!", ex);
            }

            if (plugins == null)
            {
                return;
            }

            foreach (IKSPMAPlugin plugin in plugins)
            {
                try
                {
                    Messenger.AddDebug(string.Format("Try add plugin \"{0}\" ...", plugin.Name));

                    TabView[] tabViews = plugin.MainTabViews;
                    foreach (TabView tabView in tabViews)
                    {
                        if (!mAddedTabViews.ContainsKey(tabView.TabUserControl.GetTabCaption()))
                        {
                            Log.AddDebugS(string.Format("Try add TabPage \"{0}\" ...", tabView.TabUserControl.GetTabCaption()));

                            TabPage tabPage = new TabPage();
                            tabPage.Tag  = tabView.UniqueIdentifier.ToString();
                            tabPage.Text = tabView.TabUserControl.GetTabCaption();
                            tabPage.Name = tabView.UniqueIdentifier.ToString(); // this is needed so that tabs can be switched to by plugin GUID
                            tabPage.Controls.Add(tabView.TabUserControl);
                            tabView.TabUserControl.Dock = DockStyle.Fill;
                            if (tabView.TabIcon != null)
                            {
                                View.TabControl.ImageList.Images.Add(tabView.TabIcon);
                                tabPage.ImageIndex = View.TabControl.ImageList.Images.Count - 1;
                            }
                            View.TabControl.TabPages.Add(tabPage);

                            mAddedTabViews.Add(tabView.TabUserControl.GetTabCaption(), tabView);
                        }
                        else
                        {
                            Messenger.AddError(string.Format(Messages.MSG_ERROR_PLUGIN_LOADING_TABVIEWS_0,
                                                             tabView.TabUserControl.GetTabCaption()));
                        }
                    }

                    tabViews = plugin.OptionTabViews;
                    if (tabViews == null)
                    {
                        continue;
                    }

                    foreach (TabView tabView in tabViews)
                    {
                        if (!mAddedTabViews.ContainsKey(tabView.TabUserControl.GetTabCaption()))
                        {
                            Log.AddDebugS(string.Format("Try add Options TabPage \"{0}\" ...", tabView.TabUserControl.GetTabCaption()));

                            TabPage tabPage = new TabPage();
                            tabPage.Text = tabView.TabUserControl.GetTabCaption();
                            tabPage.Name = tabView.UniqueIdentifier.ToString();
                            tabPage.Controls.Add(tabView.TabUserControl);
                            tabView.TabUserControl.Dock = DockStyle.Fill;
                            OptionsController.View.TabControl.TabPages.Add(tabPage);

                            mAddedTabViews.Add(tabView.TabUserControl.GetTabCaption(), tabView);
                        }
                        else
                        {
                            Messenger.AddError(string.Format(Messages.MSG_ERROR_PLUGIN_LOADING_OPTIONVIEWS_0,
                                                             tabView.TabUserControl.GetTabCaption()));
                        }
                    }
                }
                catch (Exception ex)
                {
                    Messenger.AddError(string.Format("Error during loading of plugin \"{0}\"", plugin.Name), ex);
                }
            }
        }