main
This commit is contained in:
182
StudioInstaller_Project/StudioClient/Form1.cs
Normal file
182
StudioInstaller_Project/StudioClient/Form1.cs
Normal file
@@ -0,0 +1,182 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Reflection.Emit;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using Newtonsoft.Json;
|
||||
using System.Security.Cryptography;
|
||||
using System.Net.Http;
|
||||
using Microsoft.Win32;
|
||||
using System.Security.Policy;
|
||||
|
||||
namespace StudioClient
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
static string serverUrl = "http://xr.flexing.ai:3030/XR_Server/";
|
||||
|
||||
static string appName_Studio = "Studio";
|
||||
static string appName_Chunil = "Chunil";
|
||||
|
||||
static string setupFileTag = "Setup.exe";
|
||||
|
||||
static readonly HttpClient httpClient = new HttpClient();
|
||||
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private async void StudioButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
await OnClickButton(serverUrl, appName_Studio);
|
||||
}
|
||||
|
||||
private async void ChunilButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
await OnClickButton(serverUrl, appName_Chunil);
|
||||
}
|
||||
|
||||
private async void WriteText(string text)
|
||||
{
|
||||
label1.Text = text;
|
||||
}
|
||||
|
||||
private async Task OnClickButton(string serverUrl, string appName)
|
||||
{
|
||||
string appUrl = Path.Combine(serverUrl, appName);
|
||||
|
||||
// 이미 Setup으로 설치를 진행했는지 체크
|
||||
string installPath = GetInstalledPathFromRegistry(appName);
|
||||
string exeFilePath;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(installPath) && Directory.Exists(installPath)) // 이미 설치 되있으면 경로에서 exe파일 실행
|
||||
{
|
||||
WriteText("런처 실행");
|
||||
|
||||
exeFilePath = Directory.GetFiles(installPath, "*.exe", SearchOption.TopDirectoryOnly).FirstOrDefault();
|
||||
|
||||
if (string.IsNullOrEmpty(exeFilePath))
|
||||
{
|
||||
WriteText("❌ 설치 경로에 실행할 수 있는 exe 파일이 없습니다.");
|
||||
return;
|
||||
}
|
||||
|
||||
StartExecutableFile(exeFilePath, installPath);
|
||||
}
|
||||
else // 설치 안되있으면 Setup 다운받고 Setup 실행
|
||||
{
|
||||
WriteText("설치 진행중");
|
||||
|
||||
// Setup 파일이 이미 있으면 삭제하고 서버에서 새로 다운로드
|
||||
string setupFileName = appName + setupFileTag;
|
||||
if (File.Exists(setupFileName))
|
||||
{
|
||||
File.Delete(setupFileName);
|
||||
}
|
||||
string setupFileUrl = Path.Combine(appUrl, setupFileName);
|
||||
await DownloadFile(setupFileUrl);
|
||||
|
||||
string currentDir = AppContext.BaseDirectory;
|
||||
exeFilePath = Path.Combine(currentDir, setupFileName);
|
||||
StartExecutableFile(exeFilePath, currentDir);
|
||||
}
|
||||
}
|
||||
|
||||
private string GetInstalledPathFromRegistry(string appName)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (RegistryKey key = Registry.CurrentUser.OpenSubKey($@"Software\UVC\{appName}"))
|
||||
{
|
||||
if (key != null)
|
||||
{
|
||||
return key.GetValue("InstallPath") as string ?? "";
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
WriteText($"❌ 레지스트리 읽기 실패 ({appName}): {ex.Message}");
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
private async Task DownloadFile(string url)
|
||||
{
|
||||
try
|
||||
{
|
||||
string currentDir = AppContext.BaseDirectory;
|
||||
string fileName = Path.GetFileName(new Uri(url).LocalPath);
|
||||
string fullPath = Path.Combine(currentDir, fileName);
|
||||
|
||||
using (var response = await httpClient.GetAsync(url, HttpCompletionOption.ResponseHeadersRead))
|
||||
{
|
||||
response.EnsureSuccessStatusCode(); // 200 OK가 아닐 경우 예외 발생
|
||||
|
||||
using (var stream = await response.Content.ReadAsStreamAsync())
|
||||
using (var fileStream = new FileStream(fullPath, FileMode.Create, FileAccess.Write, FileShare.None))
|
||||
{
|
||||
await stream.CopyToAsync(fileStream);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
WriteText($"❌ 다운로드 실패: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private void StartExecutableFile(string exeFilePath, string workingDirectory)
|
||||
{
|
||||
ProcessStartInfo startInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = exeFilePath,
|
||||
WorkingDirectory = workingDirectory,
|
||||
UseShellExecute = true // Windows에서 기본 프로그램으로 실행
|
||||
};
|
||||
|
||||
Process.Start(startInfo);
|
||||
}
|
||||
|
||||
/*
|
||||
private async void Form1_Load(object sender, EventArgs e)
|
||||
{
|
||||
SetControlsEnabled(false);
|
||||
UpdateStateMessage.Text = "업데이트 확인 중...";
|
||||
|
||||
bool surverConnect = await TryConnectToServerAsync();
|
||||
|
||||
if (surverConnect)
|
||||
{
|
||||
SetControlsEnabled(true);
|
||||
UpdateStateMessage.Visible = false;
|
||||
UpdateStateMessage.Enabled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateStateMessage.Text = "네트워크 연결 상태를 확인하세요.";
|
||||
UpdateStateMessage.Visible = true;
|
||||
UpdateStateMessage.Enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetControlsEnabled(bool enabled)
|
||||
{
|
||||
StudioButton.Visible = enabled;
|
||||
StudioButton.Enabled = enabled;
|
||||
ChunilButton.Visible = enabled;
|
||||
ChunilButton.Enabled = enabled;
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user