102 lines
4.1 KiB
VB.net
102 lines
4.1 KiB
VB.net
Imports System.IO
|
|
Imports System.IO.Compression
|
|
Imports System.Threading.Tasks
|
|
|
|
Public Class Frm_WwwrootExtract
|
|
|
|
Private Sub Frm_WwwrootExtract_Load(sender As Object, e As EventArgs) Handles MyBase.Load
|
|
|
|
Me.Show()
|
|
Application.DoEvents()
|
|
|
|
' 폼이 로드될 때 자동으로 압축 해제 시작
|
|
ExtractWwwrootAsync()
|
|
End Sub
|
|
|
|
Private Async Sub ExtractWwwrootAsync()
|
|
Try
|
|
|
|
Dim extractPath As String = Path.Combine(Application.StartupPath, "wwwroot")
|
|
Dim zipPath As String = Path.Combine(extractPath, "wwwroot.zip")
|
|
|
|
' ZIP 파일 존재 여부 확인
|
|
If Not File.Exists(zipPath) Then
|
|
lblStatus.Text = "wwwroot.zip 파일을 찾을 수 없습니다."
|
|
MessageBox.Show("wwwroot.zip 파일이 존재하지 않습니다.", "오류", MessageBoxButtons.OK, MessageBoxIcon.Error)
|
|
Me.DialogResult = DialogResult.Cancel
|
|
Me.Close()
|
|
Return
|
|
End If
|
|
|
|
' 압축 해제 작업을 별도 Task로 실행
|
|
Await Task.Run(Sub()
|
|
ExtractZipWithProgress(zipPath, extractPath)
|
|
End Sub)
|
|
|
|
' 완료
|
|
lblStatus.Text = "압축 해제 완료!"
|
|
lblPercentage.Text = "100%"
|
|
progressBar.Value = 100
|
|
Application.DoEvents()
|
|
|
|
' 잠시 대기 후 폼 닫기
|
|
Await Task.Delay(500)
|
|
Me.DialogResult = DialogResult.OK
|
|
Me.Close()
|
|
|
|
Catch ex As Exception
|
|
lblStatus.Text = "오류 발생: " & ex.Message
|
|
MessageBox.Show("압축 해제 중 오류가 발생했습니다: " & ex.Message, "오류", MessageBoxButtons.OK, MessageBoxIcon.Error)
|
|
Me.DialogResult = DialogResult.Cancel
|
|
Me.Close()
|
|
End Try
|
|
End Sub
|
|
|
|
Private Sub ExtractZipWithProgress(zipPath As String, extractPath As String)
|
|
Using archive As ZipArchive = ZipFile.OpenRead(zipPath)
|
|
Dim totalEntries As Integer = archive.Entries.Count
|
|
Dim currentEntry As Integer = 0
|
|
|
|
For Each entry As ZipArchiveEntry In archive.Entries
|
|
currentEntry += 1
|
|
|
|
' UI 업데이트 (UI 스레드에서 실행)
|
|
Me.Invoke(Sub()
|
|
Dim percentage As Integer = CInt((currentEntry / totalEntries) * 100)
|
|
progressBar.Value = percentage
|
|
lblPercentage.Text = percentage.ToString() & "%"
|
|
lblStatus.Text = $"압축 해제 중... ({currentEntry}/{totalEntries}) {entry.Name}"
|
|
Application.DoEvents()
|
|
End Sub)
|
|
|
|
' 전체 경로 생성
|
|
Dim destinationPath As String = Path.Combine(extractPath, entry.FullName)
|
|
|
|
' 디렉토리 항목인 경우
|
|
If entry.FullName.EndsWith("/") OrElse entry.FullName.EndsWith("\") Then
|
|
Directory.CreateDirectory(destinationPath)
|
|
Continue For
|
|
End If
|
|
|
|
' 파일의 디렉토리가 없으면 생성
|
|
Dim directoryPath As String = Path.GetDirectoryName(destinationPath)
|
|
If Not Directory.Exists(directoryPath) Then
|
|
Directory.CreateDirectory(directoryPath)
|
|
End If
|
|
|
|
' 파일 추출
|
|
entry.ExtractToFile(destinationPath, True)
|
|
Next
|
|
End Using
|
|
End Sub
|
|
|
|
Private Sub Frm_WwwrootExtract_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
|
|
' 압축 해제가 진행 중일 때는 폼을 닫을 수 없도록 설정 (사용자가 X 버튼을 누른 경우)
|
|
If e.CloseReason = CloseReason.UserClosing AndAlso progressBar.Value < 100 Then
|
|
e.Cancel = True
|
|
MessageBox.Show("압축 해제가 진행 중입니다. 잠시만 기다려 주세요.", "알림", MessageBoxButtons.OK, MessageBoxIcon.Information)
|
|
End If
|
|
End Sub
|
|
|
|
End Class
|