diff --git a/README.md b/README.md index 76885dc..ac40813 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ It makes use of Assembly Load Contexts to ensure mod dependencies are managed se - Download and unzip release from [Releases](https://github.com/StarMapLoader/StarMap/releases/latest). - Run StarMap.exe, this will fail and create a StarMapConfig.json. - Open StarMapConfig.json and set the location of your KSA installation. - - `GameLocation` should be set to the location of your KSA.dll, pointing directly to that file (e.g. `C:\\games\\Kitten Space Agency\\KSA.dll`) + - `GameLocation` should be set to the location where Kitten Space Agency was installed, pointing directly to that folder (e.g. `C:\\games\\Kitten Space Agency\\`) - `RepositoryLocation` can be kept empty - Run StarMap.exe again, this should launch KSA and load your mods. diff --git a/StarMap.Types/LoaderConfig.cs b/StarMap.Types/LoaderConfig.cs index 370b273..f7646b6 100644 --- a/StarMap.Types/LoaderConfig.cs +++ b/StarMap.Types/LoaderConfig.cs @@ -13,27 +13,39 @@ public class LoaderConfig public bool TryLoadConfig() { - if (!File.Exists("./StarMapConfig.json")) { + if (!File.Exists("./StarMapConfig.json")) + { Console.WriteLine("Please fill the StarMapConfig.json and restart the program"); - File.Create("./StarMapConfig.json").Dispose(); - File.WriteAllText("./StarMapConfig.json", JsonSerializer.Serialize(new LoaderConfig())); - Console.ReadLine(); + File.WriteAllText("./StarMapConfig.json", JsonSerializer.Serialize(new LoaderConfig(), new JsonSerializerOptions { WriteIndented = true })); return false; } - + var jsonString = File.ReadAllText("./StarMapConfig.json"); var config = JsonSerializer.Deserialize(jsonString); - + if (config is null) return false; - - if (string.IsNullOrEmpty(config.GameLocation) || !File.Exists(config.GameLocation)) + + if (string.IsNullOrEmpty(config.GameLocation)) { Console.WriteLine("The 'GameLocation' property in StarMapConfig.json is either empty or points to a non-existing file."); - Console.ReadLine(); return false; } - - GameLocation = config.GameLocation; + + string path = config.GameLocation; + + if (Directory.Exists(path)) + { + path = Path.Combine(path, "KSA.dll"); + } + + if (!File.Exists(path)) + { + Console.WriteLine("Could not find KSA.dll. Make sure the folder or file path is correct:"); + Console.WriteLine(path); + return false; + } + + GameLocation = path; return true; }