Exemplo n.º 1
0
        private async Task ImportArchiveAsync()
        {
            var extensions = PlatformHelper.GetFactorioArchiveExtensions();
            var filter     = new FileDialogFilter();

            filter.Extensions.AddRange(extensions);
            filter.Name = (string)App.Current.Locales.GetResource("ArchiveFileType");

            var ofd = new OpenFileDialog {
                AllowMultiple = false
            };

            ofd.Filters.Add(filter);

            var paths = await ofd.ShowAsync(App.Current.MainWindow);

            if (!(paths is null) && (paths.Length > 0))
            {
                var file = new FileInfo(paths[0]);
                if (file.Exists)
                {
                    var vm = new FactorioInstanceViewModel(Program.Manager, Program.Locations, false);
                    _instances.Add(vm);

                    if (!await vm.TryCreateExtractAsync(file))
                    {
                        _instances.Remove(vm);
                    }
                }
            }
        }
Exemplo n.º 2
0
 private void ReloadInstances()
 {
     _instances.Clear();
     foreach (var instance in Program.Manager.ManagedInstances)
     {
         var vm = new FactorioInstanceViewModel(Program.Manager, instance);
         vm.InstanceRemoved += OnInstanceRemoved;
         _instances.Add(vm);
     }
 }
Exemplo n.º 3
0
        private async Task DownloadAsync(bool experimental)
        {
            var vm = new FactorioInstanceViewModel(Program.Manager, Program.Locations, true);

            _instances.Add(vm);

            if (!await vm.TryCreateDownloadAsync(_downloadQueue, experimental))
            {
                _instances.Remove(vm);
            }
        }
Exemplo n.º 4
0
        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
                        }
                    }
                }
            }
        }