Example #1
0
        /// <summary>
        /// Save user settings.
        /// </summary>
        /// <param name="settings"></param>
        /// <returns>Task which saves the user settings.</returns>
        private async Task SaveUserSettingsAsync(SubtitleDownloaderSettings settings)
        {
            var settingsJson      = JsonConvert.SerializeObject(settings, Formatting.Indented);
            var settingsDirectory = SubtitleDownloaderSettingsLocator.GetUserSettingsDirectory();
            var settingsFileName  = SubtitleDownloaderSettingsLocator.GetUserSettingsFileName();

            if (!Directory.Exists(settingsDirectory))
            {
                Directory.CreateDirectory(settingsDirectory);
            }

            await File.WriteAllTextAsync(
                settingsFileName,
                settingsJson
                );
        }
Example #2
0
        /// <summary>
        /// Delete the user settings.
        /// </summary>
        /// <returns>Task which deletes the user settings.</returns>
        private async Task DeleteUserSettingsAsync()
        {
            try
            {
                var settingsDirectory = SubtitleDownloaderSettingsLocator.GetUserSettingsDirectory();

                if (Directory.Exists(settingsDirectory))
                {
                    Directory.Delete(settingsDirectory, true);
                }

                await Task.CompletedTask;
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "Failed to delete user settings.");
                Console.WriteLine("Failed to delete user settings.");
                throw;
            }
        }