Skip to content

Commit

Permalink
UI for editing preferred hosts setting
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Aug 8, 2023
1 parent 2d405a8 commit 985292b
Show file tree
Hide file tree
Showing 15 changed files with 812 additions and 4 deletions.
1 change: 1 addition & 0 deletions Core/HelpURLs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public static class HelpURLs

public const string CloneFakeInstances = "https://github.com/KSP-CKAN/CKAN/pull/2627";
public const string DeleteDirectories = "https://github.com/KSP-CKAN/CKAN/pull/2962";
public const string PreferredHosts = "https://github.com/KSP-CKAN/CKAN/pull/3877";
public const string Filters = "https://github.com/KSP-CKAN/CKAN/pull/3458";
public const string Labels = "https://github.com/KSP-CKAN/CKAN/pull/2936";
public const string PlayTime = "https://github.com/KSP-CKAN/CKAN/pull/3543";
Expand Down
22 changes: 22 additions & 0 deletions Core/Registry/Registry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,28 @@ public Dictionary<string, List<CkanModule>> GetDownloadHashIndex()
return index;
}

/// <summary>
/// Return all hosts from latest versions of all available modules,
/// sorted by number of occurrences, most common first
/// </summary>
/// <returns>Host strings without duplicates</returns>
public IEnumerable<string> GetAllHosts()
=> available_modules.Values
// Pick all modules where download is not null
.Where(availMod => availMod?.Latest()?.download != null)
// Merge all the URLs into one sequence
.SelectMany(availMod => availMod.Latest().download)
// Skip relative URLs because they don't have hosts
.Where(dlUri => dlUri.IsAbsoluteUri)
// Group the URLs by host
.GroupBy(dlUri => dlUri.Host)
// Put most commonly used hosts first
.OrderByDescending(grp => grp.Count())
// Alphanumeric sort if same number of usages
.ThenBy(grp => grp.Key)
// Return the host from each group
.Select(grp => grp.Key);

/// <summary>
/// Partition all CkanModules in available_modules into
/// compatible and incompatible groups.
Expand Down
12 changes: 12 additions & 0 deletions GUI/CKAN-GUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@
<Compile Include="Dialogs\InstallFiltersDialog.Designer.cs">
<DependentUpon>InstallFiltersDialog.cs</DependentUpon>
</Compile>
<Compile Include="Dialogs\PreferredHostsDialog.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Dialogs\PreferredHostsDialog.Designer.cs">
<DependentUpon>PreferredHostsDialog.cs</DependentUpon>
</Compile>
<Compile Include="Dialogs\NewRepoDialog.cs">
<SubType>Form</SubType>
</Compile>
Expand Down Expand Up @@ -816,6 +822,12 @@
<EmbeddedResource Include="Localization\ru-RU\InstallFiltersDialog.ru-RU.resx">
<DependentUpon>..\..\Dialogs\InstallFiltersDialog.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Dialogs\PreferredHostsDialog.resx">
<DependentUpon>PreferredHostsDialog.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Localization\en-US\PreferredHostsDialog.en-US.resx">
<DependentUpon>..\..\Dialogs\PreferredHostsDialog.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Main\Main.resx">
<DependentUpon>Main.cs</DependentUpon>
<SubType>Designer</SubType>
Expand Down
4 changes: 2 additions & 2 deletions GUI/Controls/EditModpack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public EditModpack()
this.ToolTip.SetToolTip(NameTextBox, Properties.Resources.EditModpackTooltipName);
this.ToolTip.SetToolTip(AbstractTextBox, Properties.Resources.EditModpackTooltipAbstract);
this.ToolTip.SetToolTip(VersionTextBox, Properties.Resources.EditModpackTooltipVersion);
this.ToolTip.SetToolTip(GameVersionMinComboBox, Properties.Resources.EditModpackTooltipGameVersionMin);
this.ToolTip.SetToolTip(GameVersionMaxComboBox, Properties.Resources.EditModpackTooltipGameVersionMax);
this.ToolTip.SetToolTip(GameVersionMinComboBox, Properties.Resources.EditModpackTooltipGameVersionMin);
this.ToolTip.SetToolTip(GameVersionMaxComboBox, Properties.Resources.EditModpackTooltipGameVersionMax);
this.ToolTip.SetToolTip(LicenseComboBox, Properties.Resources.EditModpackTooltipLicense);
this.ToolTip.SetToolTip(IncludeVersionsCheckbox, Properties.Resources.EditModpackTooltipIncludeVersions);
this.ToolTip.SetToolTip(DependsRadioButton, Properties.Resources.EditModpackTooltipDepends);
Expand Down
234 changes: 234 additions & 0 deletions GUI/Dialogs/PreferredHostsDialog.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 985292b

Please sign in to comment.