Files
Groupware/Project/Program.cs
2025-06-04 15:08:11 +09:00

133 lines
5.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.IO.Compression;
using System.IO;
using System.DirectoryServices;
using System.ServiceModel.Configuration;
namespace Project
{
static class Program
{
/// <summary>
/// 해당 응용 프로그램의 주 진입점입니다.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
// AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
var fi = new System.IO.FileInfo("WebView2Runtime.zip");
if (fi.Exists)
{
var existlen = 0;
var webruntimepath = new System.IO.DirectoryInfo("WebView2Runtime");
if (webruntimepath.Exists)
{
var filen = new System.IO.FileInfo("WebView2Runtime\\version.txt");
if(filen.Exists)
{
var verstr = System.IO.File.ReadAllText(filen.FullName);
int.TryParse(verstr, out existlen);
}
}
if(existlen != fi.Length)
{
//fi 파일의 압축을 해제한다.
var fprogress = new Dialog.fUnZip();
fprogress.TopMost = true;
fprogress.Show();
Application.DoEvents();
try
{
if (webruntimepath.Exists)
{
fprogress.label1.Text = "기존폴더삭제";
Application.DoEvents();
webruntimepath.Delete(true);
}
var diruntime = new System.IO.DirectoryInfo("runtimes");
if (diruntime.Exists) diruntime.Delete(true);
webruntimepath.Create();
diruntime.Create();
using (var archive = ZipFile.OpenRead(fi.FullName))
{
int totalFiles = archive.Entries.Count;
int currentFile = 0;
long totalSize = archive.Entries.Sum(e => e.Length);
long extractedSize = 0;
foreach (var entry in archive.Entries)
{
currentFile++;
extractedSize += entry.Length;
int progress = (int)((extractedSize * 100) / totalSize);
fprogress.label1.Text = $"압축 해제 중... ({currentFile}/{totalFiles})";
fprogress.label2.Text = $"{entry.FullName} ({progress}%)";
fprogress.progressBar1.Value = progress;
Application.DoEvents();
string destinationPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, entry.FullName);
string destinationDir = Path.GetDirectoryName(destinationPath);
if (!Directory.Exists(destinationDir))
Directory.CreateDirectory(destinationDir);
if (entry.Length > 0)
entry.ExtractToFile(destinationPath, true);
}
}
System.IO.File.WriteAllText("WebView2Runtime\\version.txt", fi.Length.ToString());
}
catch (Exception ex)
{
fprogress.Hide();
MessageBox.Show($"WebView2 Runtime 압축 해제 중 오류가 발생했습니다: {ex.Message}", "오류", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally {
fprogress.Dispose();
}
}
}
SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);
Application.Run(new fMain());
}
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
string emsg = "Fatal Error(UHE)\n\n" + e.ExceptionObject.ToString();
Pub.log.AddE(emsg);
Pub.log.Flush();
Util.SaveBugReport(emsg);
var f = new fErrorException(emsg);
f.ShowDialog();
Application.ExitThread();
}
static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
{
string emsg = "Fatal Error(ATE)\n\n" + e.Exception.ToString();
Pub.log.AddE(emsg);
Pub.log.Flush();
Util.SaveBugReport(emsg);
var f = new fErrorException(emsg);
f.ShowDialog();
Application.ExitThread();
}
}
}