public ViewModel([NotNull] PythonAppObject acObject) : base(acObject)
 {
     IsActivated = AcSettingsHolder.Python.IsActivated(SelectedObject.Id);
     AcSettingsHolder.Python.PropertyChanged += OnPythonPropertyChanged;
     Configs = acObject.GetAppConfigs();
 }
Ejemplo n.º 2
0
            private void CreateConfigs()
            {
                if (Configs != null)
                {
                    Configs.ValueChanged -= OnConfigsValueChanged;
                    Configs.Dispose();
                }

                if (!Directory.Exists(_dir))
                {
                    Mode    = Mode.NoShadersPatch;
                    Configs = null;
                    return;
                }

                FileUtils.EnsureDirectoryExists(Path.Combine(AcPaths.GetDocumentsCfgDirectory(), "extension"));
                var anyConfigFound = false;

                Configs = new PythonAppConfigs(new PythonAppConfigParams(_dir)
                {
                    FilesRelativeDirectory = AcRootDirectory.Instance.Value ?? _dir,
                    ScanFunc      = d => Directory.GetFiles(d, "*.ini").Where(x => !Path.GetFileName(x).StartsWith(@"data_")),
                    ConfigFactory = (p, f) => {
                        var fileName = Path.GetFileName(f);
                        if (fileName == null)
                        {
                            return(null);
                        }
                        anyConfigFound     = true;
                        var userEditedFile = Path.Combine(AcPaths.GetDocumentsCfgDirectory(), "extension", fileName);

                        var cfg = PythonAppConfig.Create(p, f, true, userEditedFile);
                        if (_isLive && cfg.Sections.GetByIdOrDefault("ℹ")?.GetByIdOrDefault("LIVE_SUPPORT")?.Value == @"0")
                        {
                            return(null);
                        }

                        return(string.IsNullOrWhiteSpace(cfg.ShortDescription) ? null : cfg);
                    },
                    SaveOnlyNonDefault = true,
                    Flags = new Dictionary <string, string> {
                        [@"IS_LIVE__"] = _isLive.As <string>()
                    }
                });

                if (Configs.Count > 0)
                {
                    Mode = Mode.EverythingIsFine;
                }
                else if (anyConfigFound)
                {
                    Mode = Mode.NoFittingConfigs;
                }
                else
                {
                    Mode = Mode.NoConfigs;
                }

                SelectedConfig        = Configs.GetByIdOrDefault(_selectedConfigId.Value) ?? Configs.FirstOrDefault();
                Configs.ValueChanged += OnConfigsValueChanged;
            }