Files
VNCServerList/Services/VNCService.cs
backuppc d537030eb3 ..
2025-07-07 17:44:59 +09:00

80 lines
2.6 KiB
C#

using System;
using System.Diagnostics;
using System.IO;
using VNCServerList.Models;
namespace VNCServerList.Services
{
public class VNCService
{
private readonly SettingsService _settingsService;
private readonly DatabaseService _databaseService;
public VNCService(DatabaseService databaseService, SettingsService settingsService = null)
{
_settingsService = settingsService ?? new SettingsService();
_databaseService = databaseService;
}
public bool ConnectToServer(VNCServer server)
{
try
{
var vncViewerPath = _settingsService.GetSettings().VNCViewerPath;
if (!File.Exists(vncViewerPath))
{
throw new FileNotFoundException($"VNC Viewer를 찾을 수 없습니다: {vncViewerPath}");
}
// VNC Viewer 실행
var startInfo = new ProcessStartInfo
{
FileName = vncViewerPath,
Arguments = $"-host={server.IP} {server.Argument}",
UseShellExecute = true
};
Process.Start(startInfo);
// 연결 성공 (마지막 연결 시간 업데이트는 현재 테이블 구조에 없으므로 제거)
return true;
}
catch (Exception ex)
{
throw new Exception($"VNC 연결 중 오류가 발생했습니다: {ex.Message}", ex);
}
}
public bool ConnectToServer(string user, string ip)
{
var server = _databaseService.GetServerByUserAndIP(user, ip);
if (server == null)
{
throw new ArgumentException($"서버 {user}@{ip}를 찾을 수 없습니다.");
}
return ConnectToServer(server);
}
public bool IsVNCViewerInstalled()
{
var vncViewerPath = _settingsService.GetSettings().VNCViewerPath;
System.Diagnostics.Debug.WriteLine($"VNC 설치 확인: 경로='{vncViewerPath}', 존재={File.Exists(vncViewerPath)}");
return File.Exists(vncViewerPath);
}
public string GetVNCViewerPath()
{
var path = _settingsService.GetSettings().VNCViewerPath;
System.Diagnostics.Debug.WriteLine($"VNC 경로 조회: '{path}'");
return path;
}
public void SetVNCViewerPath(string path)
{
_settingsService.UpdateVNCViewerPath(path);
}
}
}