43 lines
1.1 KiB
C#
43 lines
1.1 KiB
C#
using SQLVision.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Text.Json;
|
|
|
|
namespace SQLVision.Services;
|
|
|
|
public class ConnectionStorageService
|
|
{
|
|
private readonly string _filePath;
|
|
|
|
public ConnectionStorageService()
|
|
{
|
|
var folder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
|
var appFolder = Path.Combine(folder, "SQLVision");
|
|
|
|
if (!Directory.Exists(appFolder))
|
|
Directory.CreateDirectory(appFolder);
|
|
|
|
_filePath = Path.Combine(appFolder, "connections.json");
|
|
}
|
|
|
|
public List<ConnectionProfile> Load()
|
|
{
|
|
if (!File.Exists(_filePath))
|
|
return new List<ConnectionProfile>();
|
|
|
|
var json = File.ReadAllText(_filePath);
|
|
return JsonSerializer.Deserialize<List<ConnectionProfile>>(json) ?? new();
|
|
}
|
|
|
|
public void Save(List<ConnectionProfile> profiles)
|
|
{
|
|
var json = JsonSerializer.Serialize(profiles, new JsonSerializerOptions
|
|
{
|
|
WriteIndented = true
|
|
});
|
|
|
|
File.WriteAllText(_filePath, json);
|
|
}
|
|
}
|