/// <summary> /// Loads Factorio instances into the manager from the location specified by the location manager /// </summary> public static async Task LoadFactorioInstancesAsync(this Manager manager, LocationManager locations, SettingManager settings) { // Since we don't intrusively redirect any directories anymore like in MMF1 we can just always load the Steam instance var(success, instance) = await Factorio.TryLoadSteamAsync(); if (success) { manager.AddInstance(instance); Log.Verbose("Successfully loaded Factorio Steam instance"); } else { Log.Verbose("Unable to load Factorio Steam instance"); } // Load instances managed by the GUI var dir = locations.GetFactorioDir(); foreach (var subDir in dir.EnumerateDirectories()) { (success, instance) = await Factorio.TryLoadAsync(subDir); if (success) { _ = manager.AddInstance(instance); Log.Verbose($"Successfully loaded managed Factorio instance from '{subDir.Name}'"); } else { Log.Verbose($"Unable to load managed Factorio instance from '{subDir.Name}'"); } } // Load external instances if (settings.TryGet(SettingName.ExternalInstances, out List <string> paths)) { foreach (var path in paths) { (success, instance) = await Factorio.TryLoadAsync(path); if (success) { _ = manager.AddInstance(instance); Log.Verbose($"Successfully loaded external Factorio instance from '{path}'"); } else { Log.Verbose($"Unable to load external Factorio instance from '{path}'"); } } } }
private async Task ImportInstanceAsync() { var ofd = new OpenSingleFileDialog { FilterName = "Factorio", FileName = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "factorio.exe" : "factorio" }; var path = await ofd.ShowAsync(App.Current.MainWindow); if (!(path is null)) { var file = new FileInfo(path); if (file.Exists) { var dir = file.Directory?.Parent?.Parent; if (dir is null) { // Invalid file selected } else { var(success, instance) = await Factorio.TryLoadAsync(dir); if (success) { var managed = Program.Manager.AddInstance(instance !); if (!Program.Settings.TryGet(SettingName.ExternalInstances, out List <string>?instPaths) || (instPaths is null)) { instPaths = new List <string>(); } instPaths.Add(dir.FullName); Program.Settings.Set(SettingName.ExternalInstances, instPaths); await Program.Settings.SaveAsync(); var vm = new FactorioInstanceViewModel(Program.Manager, managed); _instances.Add(vm); } else { // Loading failed } } } } }