Skip to content

Commit

Permalink
Merge #3964 Usability improvements for adding game instance
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Dec 18, 2023
2 parents 517be69 + e1f27c1 commit 457407e
Show file tree
Hide file tree
Showing 21 changed files with 70 additions and 50 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,7 @@ bld/
*.nuget.props
*.nuget.targets

# Python won't let me install packages globally anymore
/.venv/

quotes.txt.dat
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file.
### Bugfixes

- [Core] Oops, `HttpClient` actually sucks (#3960 by: HebaruSan; reviewed: techman83)
- [Multiple] Usability improvements for adding game instance (#3964 by: HebaruSan; reviewed: JonnyOThan)

### Internal

Expand Down
20 changes: 14 additions & 6 deletions Core/GameInstanceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using CKAN.Games.KerbalSpaceProgram;
using CKAN.Games.KerbalSpaceProgram2;
using CKAN.Extensions;
using CKAN.Games.KerbalSpaceProgram.GameVersionProviders;

namespace CKAN
{
Expand Down Expand Up @@ -43,8 +44,8 @@ public class GameInstanceManager : IDisposable

private readonly SortedList<string, GameInstance> instances = new SortedList<string, GameInstance>();

public string[] AllBuildIDFiles => knownGames
.SelectMany(g => g.BuildIDFiles)
public string[] AllInstanceAnchorFiles => knownGames
.SelectMany(g => g.InstanceAnchorFiles)
.Distinct()
.ToArray();

Expand Down Expand Up @@ -278,19 +279,26 @@ public void FakeInstance(IGame game, string newName, string newPath, GameVersion
fileMgr.CreateDirectory(Path.Combine(newPath, game.PrimaryModDirectoryRelative));
game.RebuildSubdirectories(newPath);

foreach (var anchor in game.InstanceAnchorFiles)
{
fileMgr.WriteAllText(Path.Combine(newPath, anchor), "");
}

// Don't write the buildID.txts if we have no build, otherwise it would be -1.
if (version.IsBuildDefined)
if (version.IsBuildDefined && game is KerbalSpaceProgram)
{
foreach (var b in game.BuildIDFiles)
foreach (var b in KspBuildIdVersionProvider.buildIDfilenames)
{
fileMgr.WriteAllText(
Path.Combine(newPath, b),
string.Format("build id = {0}", version.Build));
}
}

// Create the readme.txt WITHOUT build number.
fileMgr.WriteAllText(Path.Combine(newPath, "readme.txt"), string.Format("Version {0}", new GameVersion(version.Major, version.Minor, version.Patch).ToString()));
// Create the readme.txt WITHOUT build number
fileMgr.WriteAllText(Path.Combine(newPath, "readme.txt"),
string.Format("Version {0}",
version.WithoutBuild.ToString()));

// Create the needed folder structure and the readme.txt for DLCs that should be simulated.
if (dlcs != null)
Expand Down
5 changes: 3 additions & 2 deletions Core/Games/IGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public interface IGame
// Identification, used for display and saved/loaded in settings JSON
// Must be unique!
string ShortName { get; }
DateTime FirstReleaseDate { get; }

// Where are we?
bool GameInFolder(DirectoryInfo where);
Expand All @@ -31,7 +32,7 @@ public interface IGame
bool IsReservedDirectory(GameInstance inst, string path);
bool AllowInstallationIn(string name, out string path);
void RebuildSubdirectories(string absGameRoot);
string DefaultCommandLine { get; }
string DefaultCommandLine(string path);
string[] AdjustCommandLine(string[] args, GameVersion installedVersion);
IDlcDetector[] DlcDetectors { get; }

Expand All @@ -42,7 +43,7 @@ public interface IGame
GameVersion[] ParseBuildsJson(JToken json);
GameVersion DetectVersion(DirectoryInfo where);
string CompatibleVersionsFile { get; }
string[] BuildIDFiles { get; }
string[] InstanceAnchorFiles { get; }

// How to get metadata
Uri DefaultRepositoryURL { get; }
Expand Down
26 changes: 16 additions & 10 deletions Core/Games/KerbalSpaceProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ namespace CKAN.Games.KerbalSpaceProgram
public class KerbalSpaceProgram : IGame
{
public string ShortName => "KSP";
public DateTime FirstReleaseDate => new DateTime(2011, 6, 24);

public bool GameInFolder(DirectoryInfo where)
=> Directory.Exists(Path.Combine(where.FullName, "GameData"));
=> InstanceAnchorFiles.Any(f => File.Exists(Path.Combine(where.FullName, f)))
&& Directory.Exists(Path.Combine(where.FullName, "GameData"));

/// <summary>
/// Finds the Steam KSP path. Returns null if the folder cannot be located.
Expand Down Expand Up @@ -173,10 +175,14 @@ public void RebuildSubdirectories(string absGameRoot)
}
}

public string DefaultCommandLine =>
Platform.IsUnix ? "./KSP.x86_64 -single-instance"
: Platform.IsMac ? "./KSP.app/Contents/MacOS/KSP"
: "KSP_x64.exe -single-instance";
public string DefaultCommandLine(string path)
=> Platform.IsMac
? "./KSP.app/Contents/MacOS/KSP"
: string.Format(Platform.IsUnix ? "./{0} -single-instance"
: "{0} -single-instance",
InstanceAnchorFiles.FirstOrDefault(f =>
File.Exists(Path.Combine(path, f)))
?? InstanceAnchorFiles.First());

public string[] AdjustCommandLine(string[] args, GameVersion installedVersion)
{
Expand Down Expand Up @@ -254,11 +260,11 @@ public GameVersion DetectVersion(DirectoryInfo where)

public string CompatibleVersionsFile => "compatible_ksp_versions.json";

public string[] BuildIDFiles => new string[]
{
"buildID.txt",
"buildID64.txt"
};
public string[] InstanceAnchorFiles =>
// KSP.app is a directory :(
Platform.IsMac ? new string[] { "buildID64.txt", "buildID.txt" }
: Platform.IsUnix ? new string[] { "KSP.x86_64", "KSP.x86" }
: new string[] { "KSP_x64.exe", "KSP.exe" };

public Uri DefaultRepositoryURL => new Uri("https://github.com/KSP-CKAN/CKAN-meta/archive/master.tar.gz");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public KspBuildIdVersionProvider(IKspBuildMap kspBuildMap)
_kspBuildMap = kspBuildMap;
}

private static readonly string[] buildIDfilenames =
public static readonly string[] buildIDfilenames =
{
"buildID.txt", "buildID64.txt"
"buildID64.txt", "buildID.txt"
};

public bool TryGetVersion(string directory, out GameVersion result)
Expand Down
15 changes: 8 additions & 7 deletions Core/Games/KerbalSpaceProgram2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ namespace CKAN.Games.KerbalSpaceProgram2
public class KerbalSpaceProgram2 : IGame
{
public string ShortName => "KSP2";
public DateTime FirstReleaseDate => new DateTime(2023, 2, 24);

public bool GameInFolder(DirectoryInfo where)
=> where.EnumerateFiles().Any(f => f.Name == "KSP2_x64.exe")
&& where.EnumerateDirectories().Any(d => d.Name == "KSP2_x64_Data");
=> InstanceAnchorFiles.Any(f => File.Exists(Path.Combine(where.FullName, f)))
&& Directory.Exists(Path.Combine(where.FullName, "KSP2_x64_Data"));

/// <summary>
/// Finds the Steam KSP path. Returns null if the folder cannot be located.
Expand Down Expand Up @@ -147,10 +148,10 @@ public void RebuildSubdirectories(string absGameRoot)
}
}

public string DefaultCommandLine =>
Platform.IsUnix ? "./KSP2.x86_64 -single-instance"
: Platform.IsMac ? "./KSP2.app/Contents/MacOS/KSP"
: "KSP2_x64.exe -single-instance";
public string DefaultCommandLine(string path)
=> Platform.IsUnix ? "./KSP2.x86_64 -single-instance"
: Platform.IsMac ? "./KSP2.app/Contents/MacOS/KSP"
: "KSP2_x64.exe -single-instance";

public string[] AdjustCommandLine(string[] args, GameVersion installedVersion)
=> args;
Expand Down Expand Up @@ -209,7 +210,7 @@ private GameVersion VersionFromFile(string path)

public string CompatibleVersionsFile => "compatible_game_versions.json";

public string[] BuildIDFiles => new string[]
public string[] InstanceAnchorFiles => new string[]
{
"KSP2_x64.exe",
};
Expand Down
24 changes: 12 additions & 12 deletions GUI/Dialogs/ManageGameInstancesDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ public partial class ManageGameInstancesDialog : Form
/// "Build metadata files (buildID.txt;buildID64.txt)|buildID.txt;buildID64.txt"
/// </returns>
public static string GameFolderFilter(GameInstanceManager mgr)
{
return Properties.Resources.BuildIDFilterDescription
+ "|" + string.Join(";", mgr.AllBuildIDFiles);
}
=> Properties.Resources.GameProgramFileDescription
+ "|" + string.Join(";", mgr.AllInstanceAnchorFiles);

public bool HasSelections => GameInstancesListView.SelectedItems.Count > 0;

Expand Down Expand Up @@ -88,14 +86,16 @@ public void UpdateInstancesList()
AddOrRemoveColumn(GameInstancesListView, Game, !allSameGame, GameInstallVersion.Index);
AddOrRemoveColumn(GameInstancesListView, GamePlayTime, hasPlayTime, GameInstallPath.Index);

GameInstancesListView.Items.AddRange(_manager.Instances
.OrderByDescending(instance => instance.Value.Version())
.Select(instance => new ListViewItem(rowItems(instance.Value, !allSameGame, hasPlayTime))
{
Tag = instance.Key
})
.ToArray()
);
GameInstancesListView.Items.AddRange(
_manager.Instances.OrderByDescending(instance => instance.Value.game.FirstReleaseDate)
.ThenByDescending(instance => instance.Value.Version())
.ThenBy(instance => instance.Key)
.Select(instance => new ListViewItem(
rowItems(instance.Value, !allSameGame, hasPlayTime))
{
Tag = instance.Key
})
.ToArray());

GameInstancesListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
GameInstancesListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
Expand Down
2 changes: 1 addition & 1 deletion GUI/Model/GUIConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public static GUIConfiguration LoadOrCreateConfiguration(string path, IGame game
var configuration = new GUIConfiguration
{
path = path,
CommandLineArguments = game.DefaultCommandLine
CommandLineArguments = game.DefaultCommandLine(path),
};

SaveConfiguration(configuration);
Expand Down
2 changes: 1 addition & 1 deletion GUI/Properties/Resources.de-DE.resx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
<resheader name="writer"><value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value></resheader>
<data name="CKANFileFilter" xml:space="preserve"><value>CKAN Metadaten (*.ckan)|*.ckan</value></data>
<data name="ExportInstalledModsDialogTitle" xml:space="preserve"><value>Export der Modliste</value></data>
<data name="BuildIDFilterDescription" xml:space="preserve"><value>Build-Metadatendatei</value></data>
<data name="GameProgramFileDescription" xml:space="preserve"><value>Build-Metadatendatei</value></data>
<data name="CloneFakeKspDialogEnterName" xml:space="preserve"><value>Bitte gib einen Namen für die neue Instanz an.</value> </data>
<data name="CloneFakeKspDialogEnterPath" xml:space="preserve"><value>Bitte gib einen Pfad für die neue Instanz an.</value></data>
<data name="CloneFakeKspDialogCloningInstance" xml:space="preserve"><value>Klone Instanz...</value></data>
Expand Down
2 changes: 1 addition & 1 deletion GUI/Properties/Resources.fr-FR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
<data name="AboutDialogLabel2Text" xml:space="preserve">
<value>Version {0}</value>
</data>
<data name="BuildIDFilterDescription" xml:space="preserve">
<data name="GameProgramFileDescription" xml:space="preserve">
<value>Fichier de métadonnées/Build</value>
</data>
<data name="CloneFakeKspDialogEnterName" xml:space="preserve">
Expand Down
2 changes: 1 addition & 1 deletion GUI/Properties/Resources.it-IT.resx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
<data name="AboutDialogLabel2Text" xml:space="preserve">
<value>Versione {0}</value>
</data>
<data name="BuildIDFilterDescription" xml:space="preserve">
<data name="GameProgramFileDescription" xml:space="preserve">
<value>Generazione file metadati</value>
</data>
<data name="CloneFakeKspDialogEnterName" xml:space="preserve">
Expand Down
2 changes: 1 addition & 1 deletion GUI/Properties/Resources.ja-JP.resx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
<data name="CKANFileFilter" xml:space="preserve"><value>CKAN metadata (*.ckan)|*.ckan</value></data>
<data name="ExportInstalledModsDialogTitle" xml:space="preserve"><value>Modリストのエクスポート</value></data>
<data name="AboutDialogLabel2Text" xml:space="preserve"><value>バージョン {0}</value></data>
<data name="BuildIDFilterDescription" xml:space="preserve"><value>Build metadata file</value></data>
<data name="GameProgramFileDescription" xml:space="preserve"><value>Build metadata file</value></data>
<data name="CloneFakeKspDialogEnterName" xml:space="preserve"><value>新しいインスタンスの名前を入力してください。</value></data>
<data name="CloneFakeKspDialogEnterPath" xml:space="preserve"><value>新しいインスタンスの場所を入力してください。</value></data>
<data name="CloneFakeKspDialogCloningInstance" xml:space="preserve"><value>"インスタンスを複製中..."</value></data>
Expand Down
2 changes: 1 addition & 1 deletion GUI/Properties/Resources.ko-KR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
<data name="CKANFileFilter" xml:space="preserve"><value>CKAN 메타데이터 (*.ckan)|*.ckan</value></data>
<data name="ExportInstalledModsDialogTitle" xml:space="preserve"><value>모드 리스트 내보내기</value></data>
<data name="AboutDialogLabel2Text" xml:space="preserve"><value>버전 {0}</value></data>
<data name="BuildIDFilterDescription" xml:space="preserve"><value>메타데이터 파일 빌드</value></data>
<data name="GameProgramFileDescription" xml:space="preserve"><value>메타데이터 파일 빌드</value></data>
<data name="CloneFakeKspDialogEnterName" xml:space="preserve"><value>새로운 인스턴스의 이름을 입력해주세요.</value></data>
<data name="CloneFakeKspDialogEnterPath" xml:space="preserve"><value>새로운 인스턴스의 경로를 입력해주세요.</value></data>
<data name="CloneFakeKspDialogCloningInstance" xml:space="preserve"><value>"인스턴스 복제 중..."</value></data>
Expand Down
2 changes: 1 addition & 1 deletion GUI/Properties/Resources.pl-PL.resx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
<data name="AboutDialogLabel2Text" xml:space="preserve">
<value>Wersja {0}</value>
</data>
<data name="BuildIDFilterDescription" xml:space="preserve">
<data name="GameProgramFileDescription" xml:space="preserve">
<value>Zbuduj plik metadanych</value>
</data>
<data name="CloneFakeKspDialogEnterName" xml:space="preserve">
Expand Down
2 changes: 1 addition & 1 deletion GUI/Properties/Resources.pt-BR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="AboutDialogLabel2Text" xml:space="preserve"><value>Versão {0}</value></data>
<data name="BuildIDFilterDescription" xml:space="preserve"><value>Arquivo de metadados da Build</value></data>
<data name="GameProgramFileDescription" xml:space="preserve"><value>Arquivo de metadados da Build</value></data>
<data name="CloneFakeKspDialogEnterName" xml:space="preserve"><value>Por favor informe o nome da nova instância.</value></data>
<data name="CloneFakeKspDialogEnterPath" xml:space="preserve"><value>Por favor informe o caminho da nova instância.</value></data>
<data name="CloneFakeKspDialogCloningInstance" xml:space="preserve"><value>"Clonando instância..."</value></data>
Expand Down
2 changes: 1 addition & 1 deletion GUI/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
<data name="CKANFileFilter" xml:space="preserve"><value>CKAN metadata (*.ckan)|*.ckan</value></data>
<data name="ExportInstalledModsDialogTitle" xml:space="preserve"><value>Export Mod List</value></data>
<data name="AboutDialogLabel2Text" xml:space="preserve"><value>Version {0}</value></data>
<data name="BuildIDFilterDescription" xml:space="preserve"><value>Build metadata file</value></data>
<data name="GameProgramFileDescription" xml:space="preserve"><value>Game program file</value></data>
<data name="CloneFakeKspDialogEnterName" xml:space="preserve"><value>Please enter a name for the new instance.</value></data>
<data name="CloneFakeKspDialogEnterPath" xml:space="preserve"><value>Please enter a path for the new instance.</value></data>
<data name="CloneFakeKspDialogCloningInstance" xml:space="preserve"><value>"Cloning instance..."</value></data>
Expand Down
2 changes: 1 addition & 1 deletion GUI/Properties/Resources.ru-RU.resx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="AboutDialogLabel2Text" xml:space="preserve"><value>Версия {0}</value></data>
<data name="BuildIDFilterDescription" xml:space="preserve"><value>Файл метаданных сборки</value></data>
<data name="GameProgramFileDescription" xml:space="preserve"><value>Файл метаданных сборки</value></data>
<data name="CloneFakeKspDialogEnterName" xml:space="preserve"><value>Введите название новой сборки.</value></data>
<data name="CloneFakeKspDialogEnterPath" xml:space="preserve"><value>Введите путь к папке новой сборки.</value></data>
<data name="CloneFakeKspDialogCloningInstance" xml:space="preserve"><value>«Клонирование...»</value></data>
Expand Down
2 changes: 1 addition & 1 deletion GUI/Properties/Resources.zh-CN.resx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
<data name="CKANFileFilter" xml:space="preserve"><value>CKAN元数据 (*.ckan)|*.ckan</value></data>
<data name="ExportInstalledModsDialogTitle" xml:space="preserve"><value>导出Mod列表</value></data>
<data name="AboutDialogLabel2Text" xml:space="preserve"><value>版本 {0}</value></data>
<data name="BuildIDFilterDescription" xml:space="preserve"><value>Build metadata file</value></data>
<data name="GameProgramFileDescription" xml:space="preserve"><value>Build metadata file</value></data>
<data name="CloneFakeKspDialogEnterName" xml:space="preserve"><value>请输入新实例名称.</value></data>
<data name="CloneFakeKspDialogEnterPath" xml:space="preserve"><value>请输入新实例路径.</value></data>
<data name="CloneFakeKspDialogCloningInstance" xml:space="preserve"><value>"正在克隆实例..."</value></data>
Expand Down
Empty file added Tests/Data/KSP/KSP-0.25/KSP.exe
Empty file.
Empty file.

0 comments on commit 457407e

Please sign in to comment.