public MainSettingsProvider(ILogger <MainSettingsProvider> logger, IPathProvider pathProvider)
        {
            _logger           = logger;
            _pathProvider     = pathProvider;
            _configSerializer = new ObjectSerializer();
            string path = Path.Combine(_pathProvider.GetDataPath(), "settings.ini");

            _configSerializer.Load(this, path);
            _configSerializer.Save(this, path);
        }
Beispiel #2
0
        public MainSettingsProvider(IPathProvider pathProvider)
        {
            _pathProvider     = pathProvider;
            _configSerializer = new ObjectSerializer();

            var path = Path.Combine(_pathProvider.GetDataPath(), "settings.ini");

            _configSerializer.Load(this, path);
            _configSerializer.Save(this, path);
        }
        public UserAuthProvider(ILogger <UserAuthProvider> logger, IPathProvider pathProvider)
        {
            _credentialsPath      = Path.Combine(pathProvider.GetDataPath(), "auth.ini");
            _credentialSerializer = new ObjectSerializer();
            _credentialSerializer.Load(Credentials, _credentialsPath);

            Task.Delay(1000).ContinueWith(_ =>
            {
                if (!string.IsNullOrEmpty(OldConfigPath) && File.Exists(OldConfigPath))
                {
                    logger.LogInformation($"Trying to convert old StreamCore config at path {OldConfigPath}");
                    var old = new OldStreamCoreConfig();
                    _credentialSerializer.Load(old, OldConfigPath);

                    if (!string.IsNullOrEmpty(old.TwitchChannelName))
                    {
                        var oldName = old.TwitchChannelName?.ToLower().Replace(" ", "");
                        if (oldName != null && !Credentials.Twitch_Channels.Contains(oldName))
                        {
                            Credentials.Twitch_Channels.Add(oldName);
                            logger.LogInformation($"Added channel {oldName} from old StreamCore config.");
                        }
                    }

                    if (!string.IsNullOrEmpty(old.TwitchOAuthToken))
                    {
                        Credentials.Twitch_OAuthToken = old.TwitchOAuthToken !;
                        logger.LogInformation($"Pulled in old Twitch auth info from StreamCore config.");
                    }

                    var convertedPath = OldConfigPath + ".converted";
                    try
                    {
                        if (!File.Exists(convertedPath))
                        {
                            File.Move(OldConfigPath, convertedPath);
                        }
                        else
                        {
                            File.Delete(OldConfigPath);
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.LogWarning(ex, "An exception occurred while trying to yeet old StreamCore config!");
                    }
                }
            });
        }
 public void Save()
 {
     _configSerializer.Save(this, Path.Combine(_pathProvider.GetDataPath(), "settings.ini"));
 }