public static ModDownloader GetDownloader(KerbalMod mod)
 {
     if (!Downloaders.ContainsKey(mod.PluginName))
     {
         Downloaders[mod.PluginName] = new ModDownloader(mod);
     }
     return Downloaders[mod.PluginName];
 }
 public ModDownloader(KerbalMod mod)
 {
     Mod = mod;
     CurrentState = (mod.UpToDate ? State.Ignored : State.Ready);
 }
 /// <summary>
 /// Render a row in the plugin list
 /// </summary>
 /// <param name="left">The left string</param>
 /// <param name="right">The right string</param>
 /// <param name="mod"></param>
 private void RenderRow(string left, string right, KerbalMod mod)
 {
     GUILayout.BeginHorizontal();
     UpdaterConfiguration.SetToggle(mod,
         GUILayout.Toggle(UpdaterConfiguration.GetToggle(mod), "", Resources.TOGGLE_STYLE)
         );
     GUILayout.Label(left);
     GUILayout.FlexibleSpace();
     GUILayout.Label(right);
     GUILayout.EndHorizontal();
 }
 private void RenderOptions(KerbalMod mod, ModDownloader downloader)
 {
     GUILayout.BeginHorizontal();
     if (mod.Configured)
     {
         GUILayout.Space(10);
         if (GUILayout.Button("ID: " + mod.SpacePortID, Resources.URL_STYLE))
         {
             Application.OpenURL(String.Format(Constants.SpaceportUrl, mod.SpacePortID));
         }
         if (!mod.Automatic)
         {
             GUILayout.Label("(Manual)");
         }
         GUILayout.FlexibleSpace();
         switch (downloader.CurrentState)
         {
             case ModDownloader.State.Ignored:
                 if (GUILayout.Button("Force Reinstall", Resources.ACTION_BUTTON_STYLE))
                 {
                     downloader.BeginDownload();
                 }
                 break;
             case ModDownloader.State.Downloading:
                 if (GUILayout.Button("Cancel", Resources.ACTION_BUTTON_STYLE))
                 {
                     downloader.CancelDownload();
                 }
                 if (downloader.Progress == 100)
                 {   // workaround for odd callback issue
                     downloader.BeginStaging();
                 }
                 break;
             case ModDownloader.State.Staging:
                 break;
             case ModDownloader.State.Ready:
                 if (GUILayout.Button("Update", Resources.ACTION_BUTTON_STYLE))
                 {
                     downloader.BeginDownload();
                 }
                 if (GUILayout.Button("Ignore", Resources.ACTION_BUTTON_STYLE))
                 {
                     downloader.IgnoreDownload();
                 }
                 break;
             case ModDownloader.State.Complete:
                 break;
             case ModDownloader.State.Error:
                 break;
         }
     }
     else
     {
         GUILayout.FlexibleSpace();
     }
     if (!mod.Automatic)
     {
         if (GUILayout.Button("Configure", Resources.ACTION_BUTTON_STYLE))
         {
             _manualConfiguration = mod;
         }
     }
     GUILayout.EndHorizontal();
 }
 private ModDownloader RenderMod(KerbalMod mod)
 {
     if (!mod.Configured || !UpdaterConfiguration.GetToggle(mod))
     {
         RenderRow(mod.DisplayName, (UpdaterConfiguration.GetToggle(mod) ? "Not Configured" : "Not Monitored"), mod);
         return null;
     }
     ModDownloader downloader = ModDownloader.GetDownloader(mod);
     switch (downloader.CurrentState)
     {
         case ModDownloader.State.Ignored:
             RenderRow(mod.DisplayName, mod.LastUpdated.ToLongDateString(), mod);
             break;
         case ModDownloader.State.Downloading:
             RenderRow(mod.DisplayName, "Downloading (" + downloader.Progress + "%)", mod);
             break;
         case ModDownloader.State.Staging:
             RenderRow(mod.DisplayName, "Staging Update...", mod);
             break;
         case ModDownloader.State.Ready:
             RenderRow(mod.DisplayName, "Update Available", mod);
             break;
         case ModDownloader.State.Complete:
             RenderRow(mod.DisplayName, "Restart Required", mod);
             break;
         case ModDownloader.State.Error:
             RenderRow(mod.DisplayName, "Error", mod);
             GUILayout.Label(downloader.ErrorMessage);
             break;
     }
     return downloader;
 }
 /// <summary>
 /// Draw the manual override window
 /// </summary> 
 /// <param name="windowID">The associated window ID</param>
 private void RenderManualConfigurationWindow(int windowID)
 {
     GUILayout.BeginVertical();
     GUILayout.Label("Enter the Kerbal SpacePort URL for this plugin:");
     _manualConfigurationUrl = GUILayout.TextField(_manualConfigurationUrl);
     GUILayout.BeginHorizontal();
     GUILayout.Label(_message);
     GUILayout.FlexibleSpace();
     if (GUILayout.Button("Apply", Resources.ACTION_BUTTON_STYLE))
     {
         try
         {
             SpacePortPage page = new SpacePortPage(_manualConfigurationUrl);
             _manualConfiguration.SetSpacePortPage(page);
             UpdaterConfiguration.SetClientVersion(_manualConfiguration.SpacePortID, null);
             UpdaterConfiguration.SetOverride(_manualConfiguration.DisplayName, _manualConfiguration.SpacePortID);
             _manualConfiguration = null;
         }
         catch (UriFormatException ex)
         {
             _message = "Couldn't use that page: " + ex.Message;
         }
     }
     if (GUILayout.Button("Cancel", Resources.ACTION_BUTTON_STYLE))
     {
         _manualConfiguration = null;
     }
     GUILayout.EndHorizontal();
     GUILayout.EndVertical();
 }