..
This commit is contained in:
@@ -10,9 +10,11 @@ namespace VNCServerList.Services
|
||||
public class DatabaseService
|
||||
{
|
||||
private readonly string _connectionString;
|
||||
private readonly SettingsService _settingsService;
|
||||
|
||||
public DatabaseService()
|
||||
public DatabaseService(SettingsService settingsService = null)
|
||||
{
|
||||
_settingsService = settingsService ?? new SettingsService();
|
||||
_connectionString = Properties.Settings.Default.VNCServerDB;
|
||||
InitializeDatabase();
|
||||
}
|
||||
|
||||
88
Services/SettingsService.cs
Normal file
88
Services/SettingsService.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Newtonsoft.Json;
|
||||
using VNCServerList.Models;
|
||||
|
||||
namespace VNCServerList.Services
|
||||
{
|
||||
public class SettingsService
|
||||
{
|
||||
private readonly string _settingsFilePath;
|
||||
private AppSettings _settings;
|
||||
|
||||
public SettingsService()
|
||||
{
|
||||
_settingsFilePath = Path.Combine(
|
||||
AppDomain.CurrentDomain.BaseDirectory,
|
||||
"VNCServerList",
|
||||
"settings.json"
|
||||
);
|
||||
LoadSettings();
|
||||
}
|
||||
|
||||
public AppSettings GetSettings()
|
||||
{
|
||||
return _settings;
|
||||
}
|
||||
|
||||
public void SaveSettings(AppSettings settings)
|
||||
{
|
||||
_settings = settings;
|
||||
|
||||
// 디버깅용 로그
|
||||
System.Diagnostics.Debug.WriteLine($"설정 저장 시작: 파일 경로={_settingsFilePath}");
|
||||
System.Diagnostics.Debug.WriteLine($"저장할 설정: VNCViewerPath={settings.VNCViewerPath}, WebServerPort={settings.WebServerPort}");
|
||||
|
||||
// 디렉토리가 없으면 생성
|
||||
var directory = Path.GetDirectoryName(_settingsFilePath);
|
||||
if (!Directory.Exists(directory))
|
||||
{
|
||||
Directory.CreateDirectory(directory);
|
||||
System.Diagnostics.Debug.WriteLine($"디렉토리 생성: {directory}");
|
||||
}
|
||||
|
||||
// JSON으로 직렬화하여 저장
|
||||
var json = JsonConvert.SerializeObject(settings, Formatting.Indented);
|
||||
System.Diagnostics.Debug.WriteLine($"JSON 데이터: {json}");
|
||||
|
||||
File.WriteAllText(_settingsFilePath, json);
|
||||
System.Diagnostics.Debug.WriteLine("설정 파일 저장 완료");
|
||||
}
|
||||
|
||||
private void LoadSettings()
|
||||
{
|
||||
try
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine($"설정 로드 시작: 파일 경로={_settingsFilePath}");
|
||||
|
||||
if (File.Exists(_settingsFilePath))
|
||||
{
|
||||
var json = File.ReadAllText(_settingsFilePath);
|
||||
System.Diagnostics.Debug.WriteLine($"읽은 JSON: {json}");
|
||||
_settings = JsonConvert.DeserializeObject<AppSettings>(json);
|
||||
System.Diagnostics.Debug.WriteLine($"로드된 설정: VNCViewerPath={_settings.VNCViewerPath}, WebServerPort={_settings.WebServerPort}");
|
||||
}
|
||||
else
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("설정 파일이 없어서 기본값으로 초기화");
|
||||
_settings = new AppSettings();
|
||||
SaveSettings(_settings);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 설정 파일 로드 실패 시 기본값 사용
|
||||
System.Diagnostics.Debug.WriteLine($"설정 로드 오류: {ex.Message}");
|
||||
_settings = new AppSettings();
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateVNCViewerPath(string path)
|
||||
{
|
||||
_settings.VNCViewerPath = path;
|
||||
SaveSettings(_settings);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -7,12 +7,12 @@ namespace VNCServerList.Services
|
||||
{
|
||||
public class VNCService
|
||||
{
|
||||
private readonly string _vncViewerPath;
|
||||
private readonly SettingsService _settingsService;
|
||||
private readonly DatabaseService _databaseService;
|
||||
|
||||
public VNCService(DatabaseService databaseService)
|
||||
public VNCService(DatabaseService databaseService, SettingsService settingsService = null)
|
||||
{
|
||||
_vncViewerPath = @"C:\Program Files\TightVNC\tvnviewer.exe";
|
||||
_settingsService = settingsService ?? new SettingsService();
|
||||
_databaseService = databaseService;
|
||||
}
|
||||
|
||||
@@ -20,15 +20,17 @@ namespace VNCServerList.Services
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!File.Exists(_vncViewerPath))
|
||||
var vncViewerPath = _settingsService.GetSettings().VNCViewerPath;
|
||||
|
||||
if (!File.Exists(vncViewerPath))
|
||||
{
|
||||
throw new FileNotFoundException($"VNC Viewer를 찾을 수 없습니다: {_vncViewerPath}");
|
||||
throw new FileNotFoundException($"VNC Viewer를 찾을 수 없습니다: {vncViewerPath}");
|
||||
}
|
||||
|
||||
// VNC Viewer 실행
|
||||
var startInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = _vncViewerPath,
|
||||
FileName = vncViewerPath,
|
||||
Arguments = $"-host={server.IP} {server.Argument}",
|
||||
UseShellExecute = true
|
||||
};
|
||||
@@ -58,12 +60,21 @@ namespace VNCServerList.Services
|
||||
|
||||
public bool IsVNCViewerInstalled()
|
||||
{
|
||||
return File.Exists(_vncViewerPath);
|
||||
var vncViewerPath = _settingsService.GetSettings().VNCViewerPath;
|
||||
System.Diagnostics.Debug.WriteLine($"VNC 설치 확인: 경로='{vncViewerPath}', 존재={File.Exists(vncViewerPath)}");
|
||||
return File.Exists(vncViewerPath);
|
||||
}
|
||||
|
||||
public string GetVNCViewerPath()
|
||||
{
|
||||
return _vncViewerPath;
|
||||
var path = _settingsService.GetSettings().VNCViewerPath;
|
||||
System.Diagnostics.Debug.WriteLine($"VNC 경로 조회: '{path}'");
|
||||
return path;
|
||||
}
|
||||
|
||||
public void SetVNCViewerPath(string path)
|
||||
{
|
||||
_settingsService.UpdateVNCViewerPath(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user