private static void SaveConnection(Settings settings) { SaveLatestConnectionString(settings.ConnectionString); var baseFileName = BuildBaseFileName(); var file = $@"{baseFileName}-Connection.dat"; var connectionString = settings.ConnectionString; if (!File.Exists(file) && connectionString.IsFilled()) { File.Create(file).Dispose(); Status.Update("[Settings] Created a new connection file."); } if (!File.Exists(file)) { return; } Status.Update("[Settings] Writing to file ..."); var encodedString = Convert.ToBase64String(Encoding.UTF8.GetBytes(connectionString)); File.WriteAllText(file, encodedString); Status.Update($"[Settings] Connection string: {ConnectionHelpers.SecureConnectionString(connectionString)}"); }
private static string LoadConnection(Settings settings) { var baseFileName = BuildBaseFileName(); var file = $@"{baseFileName}-Connection.dat"; string connectionString = null; if (File.Exists(file)) { Status.Update($"[Settings] Found connection file: {file}."); Status.Update($"[Settings] Reading content ..."); var fileContent = File.ReadAllText(file); connectionString = Encoding.UTF8.GetString(Convert.FromBase64String(fileContent)); Status.Update($"[Settings] Connection string: {ConnectionHelpers.SecureConnectionString(connectionString)}"); } if (connectionString.IsFilled()) { settings.ConnectionString = connectionString; } else { var latest = LoadLatestConnectionString(); if (latest.IsNotEmpty()) { connectionString = settings.ConnectionString = latest; Status.Update($"[Settings] Connection string: {ConnectionHelpers.SecureConnectionString(connectionString)}"); } } return(connectionString); }