Package 버전에 따라 무삭제 기능 추가 시작점
This commit is contained in:
@@ -1,13 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace CommonLibrary
|
namespace CommonLibrary
|
||||||
{
|
{
|
||||||
|
|
||||||
internal class ProgressStream : Stream
|
internal class ProgressStream : Stream
|
||||||
{
|
{
|
||||||
private readonly Stream insideStream;
|
private readonly Stream insideStream;
|
||||||
@@ -21,36 +18,24 @@ namespace CommonLibrary
|
|||||||
insideWriteProgress = writeProgress;
|
insideWriteProgress = writeProgress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool CanRead { get { return insideStream.CanRead; } }
|
public override bool CanRead => insideStream.CanRead;
|
||||||
public override bool CanSeek { get { return insideStream.CanSeek; } }
|
public override bool CanSeek => insideStream.CanSeek;
|
||||||
public override bool CanWrite { get { return insideStream.CanWrite; } }
|
public override bool CanWrite => insideStream.CanWrite;
|
||||||
public override long Length { get { return insideStream.Length; } }
|
public override long Length => insideStream.Length;
|
||||||
|
|
||||||
public override long Position
|
public override long Position
|
||||||
{
|
{
|
||||||
get { return insideStream.Position; }
|
get => insideStream.Position;
|
||||||
set { insideStream.Position = value; }
|
set => insideStream.Position = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Flush()
|
public override void Flush() => insideStream.Flush();
|
||||||
{
|
public override long Seek(long offset, SeekOrigin origin) => insideStream.Seek(offset, origin);
|
||||||
insideStream.Flush();
|
public override void SetLength(long value) => insideStream.SetLength(value);
|
||||||
}
|
|
||||||
|
|
||||||
public override long Seek(long offset, SeekOrigin origin)
|
|
||||||
{
|
|
||||||
return insideStream.Seek(offset, origin);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void SetLength(long value)
|
|
||||||
{
|
|
||||||
insideStream.SetLength(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int Read(byte[] buffer, int offset, int count)
|
public override int Read(byte[] buffer, int offset, int count)
|
||||||
{
|
{
|
||||||
int bytesRead = insideStream.Read(buffer, offset, count);
|
int bytesRead = insideStream.Read(buffer, offset, count);
|
||||||
|
|
||||||
insideReadProgress?.Report(bytesRead);
|
insideReadProgress?.Report(bytesRead);
|
||||||
return bytesRead;
|
return bytesRead;
|
||||||
}
|
}
|
||||||
@@ -74,30 +59,30 @@ namespace CommonLibrary
|
|||||||
|
|
||||||
using (ZipArchive zipArchive = ZipFile.Open(packFileName, ZipArchiveMode.Create))
|
using (ZipArchive zipArchive = ZipFile.Open(packFileName, ZipArchiveMode.Create))
|
||||||
{
|
{
|
||||||
|
|
||||||
foreach (FileInfo file in sourceFiles)
|
foreach (FileInfo file in sourceFiles)
|
||||||
{
|
{
|
||||||
string entryName = file.FullName.Substring(sourceDirectoryName.Length + 1);
|
// 경로 구분자를 '/' 로 통일 (Windows 탐색기 호환)
|
||||||
ZipArchiveEntry entry = zipArchive.CreateEntry(entryName);
|
string entryName = file.FullName.Substring(sourceDirectoryName.Length + 1)
|
||||||
|
.Replace(Path.DirectorySeparatorChar, '/');
|
||||||
|
|
||||||
|
ZipArchiveEntry entry = zipArchive.CreateEntry(entryName);
|
||||||
entry.LastWriteTime = file.LastWriteTime;
|
entry.LastWriteTime = file.LastWriteTime;
|
||||||
|
|
||||||
using (Stream inputStream = file.OpenRead())
|
using (Stream inputStream = file.OpenRead())
|
||||||
{
|
|
||||||
using (Stream outputStream = entry.Open())
|
using (Stream outputStream = entry.Open())
|
||||||
{
|
using (Stream progressStream = new ProgressStream(inputStream,
|
||||||
Stream progressStream = new ProgressStream(inputStream,
|
|
||||||
new BasicProgress<int>(i =>
|
new BasicProgress<int>(i =>
|
||||||
{
|
{
|
||||||
currentBytes += i;
|
currentBytes += i;
|
||||||
progress.Report(currentBytes / totalBytes);
|
progress?.Report(currentBytes / totalBytes);
|
||||||
}), null);
|
}), null))
|
||||||
|
{
|
||||||
|
// ✅ 방향 수정: inputStream → progressStream → outputStream
|
||||||
progressStream.CopyTo(outputStream);
|
progressStream.CopyTo(outputStream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void UnPack(string packFileName, string destinationDirectoryName, IProgress<double> progress)
|
public void UnPack(string packFileName, string destinationDirectoryName, IProgress<double> progress)
|
||||||
{
|
{
|
||||||
@@ -105,35 +90,33 @@ namespace CommonLibrary
|
|||||||
{
|
{
|
||||||
double totalBytes = zipArchive.Entries.Sum(f => f.Length);
|
double totalBytes = zipArchive.Entries.Sum(f => f.Length);
|
||||||
long currentBytes = 0;
|
long currentBytes = 0;
|
||||||
|
|
||||||
foreach (ZipArchiveEntry entry in zipArchive.Entries)
|
foreach (ZipArchiveEntry entry in zipArchive.Entries)
|
||||||
{
|
{
|
||||||
string fileName = Path.Combine(destinationDirectoryName, entry.FullName);
|
// 디렉터리 엔트리 건너뜀
|
||||||
if (entry.Name == "") continue;
|
if (string.IsNullOrEmpty(entry.Name))
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(fileName));
|
continue;
|
||||||
using (Stream inputStream = entry.Open())
|
|
||||||
{
|
|
||||||
using (Stream outputStream = File.OpenWrite(fileName))
|
|
||||||
{
|
|
||||||
|
|
||||||
Stream progressStream = new ProgressStream(outputStream, null,
|
string fileName = Path.Combine(destinationDirectoryName, entry.FullName);
|
||||||
|
Directory.CreateDirectory(Path.GetDirectoryName(fileName));
|
||||||
|
|
||||||
|
using (Stream inputStream = entry.Open())
|
||||||
|
using (Stream outputStream = File.OpenWrite(fileName))
|
||||||
|
using (Stream progressStream = new ProgressStream(outputStream, null,
|
||||||
new BasicProgress<int>(i =>
|
new BasicProgress<int>(i =>
|
||||||
{
|
{
|
||||||
currentBytes += i;
|
currentBytes += i;
|
||||||
if (progress != null)
|
progress?.Report(currentBytes / totalBytes);
|
||||||
|
})))
|
||||||
{
|
{
|
||||||
progress.Report(currentBytes / totalBytes);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
inputStream.CopyTo(progressStream);
|
inputStream.CopyTo(progressStream);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
File.SetLastWriteTime(fileName, entry.LastWriteTime.LocalDateTime);
|
File.SetLastWriteTime(fileName, entry.LastWriteTime.LocalDateTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public class BasicProgress<T> : IProgress<T>
|
public class BasicProgress<T> : IProgress<T>
|
||||||
{
|
{
|
||||||
@@ -144,10 +127,9 @@ namespace CommonLibrary
|
|||||||
actionHandler = handler;
|
actionHandler = handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IProgress<T>.Report(T value)
|
public void Report(T value)
|
||||||
{
|
{
|
||||||
actionHandler(value);
|
actionHandler(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -124,6 +124,7 @@ namespace Mitria_Minecraft_Launcher.Updater
|
|||||||
CommonLibrary.Log.INFO("[Package] LocalVersion : " + thisVersion);
|
CommonLibrary.Log.INFO("[Package] LocalVersion : " + thisVersion);
|
||||||
CommonLibrary.Log.INFO("[Package] RemoteVersion : " + remoteVersion);
|
CommonLibrary.Log.INFO("[Package] RemoteVersion : " + remoteVersion);
|
||||||
result = remoteVersion.CompareTo(thisVersion);
|
result = remoteVersion.CompareTo(thisVersion);
|
||||||
|
|
||||||
//TODO: 만약 Major 버전이 바뀌면 전부삭제, 아니면 있는 폴더면 선별후 삭제
|
//TODO: 만약 Major 버전이 바뀌면 전부삭제, 아니면 있는 폴더면 선별후 삭제
|
||||||
// 1 : 리모트가 큼, 0 : 같음, -1 리모트가 적음
|
// 1 : 리모트가 큼, 0 : 같음, -1 리모트가 적음
|
||||||
if (result == 0)
|
if (result == 0)
|
||||||
@@ -134,8 +135,19 @@ namespace Mitria_Minecraft_Launcher.Updater
|
|||||||
{
|
{
|
||||||
CommonLibrary.Log
|
CommonLibrary.Log
|
||||||
.INFO(string.Format("{0}", result == 1 ? "remote is the upper version" : "remote is the lower version"));
|
.INFO(string.Format("{0}", result == 1 ? "remote is the upper version" : "remote is the lower version"));
|
||||||
CommonLibrary.Log.INFO("[Package] delete it for update.");
|
|
||||||
|
|
||||||
|
bool packageInitialization = true;
|
||||||
|
|
||||||
|
if (thisVersion.Major < remoteVersion.Major ||
|
||||||
|
(thisVersion.Major == remoteVersion.Major && thisVersion.Minor < remoteVersion.Minor))
|
||||||
|
{
|
||||||
|
packageInitialization = false;
|
||||||
|
CommonLibrary.Log.INFO("[Package] update.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CommonLibrary.Log.INFO("[Package] delete it for update.");
|
||||||
|
}
|
||||||
var rootDirectoryInfo = new System.IO.DirectoryInfo(System.IO.Path.GetFullPath(CommonLibrary.Extensions.PathCombineW(Settings.UserLauncherConfig.GameDirectory, Settings.NowProfile.ServerName)));
|
var rootDirectoryInfo = new System.IO.DirectoryInfo(System.IO.Path.GetFullPath(CommonLibrary.Extensions.PathCombineW(Settings.UserLauncherConfig.GameDirectory, Settings.NowProfile.ServerName)));
|
||||||
|
|
||||||
if (!rootDirectoryInfo.Exists)
|
if (!rootDirectoryInfo.Exists)
|
||||||
@@ -270,7 +282,6 @@ namespace Mitria_Minecraft_Launcher.Updater
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var directory in dataPatchInformation.ComponentDirectorys)
|
foreach (var directory in dataPatchInformation.ComponentDirectorys)
|
||||||
@@ -284,7 +295,6 @@ namespace Mitria_Minecraft_Launcher.Updater
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var auditFile = new AuditFile();
|
var auditFile = new AuditFile();
|
||||||
var localFiles = auditFile.GetLocalFileList(dataPatchInformation.ComponentDirectorys);
|
var localFiles = auditFile.GetLocalFileList(dataPatchInformation.ComponentDirectorys);
|
||||||
var removeFiles = auditFile.GetRemoveFiles(localFiles, dataPatchInformation.ComponentList);
|
var removeFiles = auditFile.GetRemoveFiles(localFiles, dataPatchInformation.ComponentList);
|
||||||
@@ -322,6 +332,7 @@ namespace Mitria_Minecraft_Launcher.Updater
|
|||||||
// 커스텀 폴더, Config
|
// 커스텀 폴더, Config
|
||||||
|
|
||||||
#region CustomData
|
#region CustomData
|
||||||
|
|
||||||
// 삭제된 파일 찾기
|
// 삭제된 파일 찾기
|
||||||
|
|
||||||
string rootCustomPath = System.IO.Path.GetFullPath(CommonLibrary.Extensions.PathCombineW(Settings.CustomDataDirectory, Settings.NowProfile.ServerName));
|
string rootCustomPath = System.IO.Path.GetFullPath(CommonLibrary.Extensions.PathCombineW(Settings.CustomDataDirectory, Settings.NowProfile.ServerName));
|
||||||
@@ -339,7 +350,6 @@ namespace Mitria_Minecraft_Launcher.Updater
|
|||||||
for (int i = 0; i < files.Count; i++)
|
for (int i = 0; i < files.Count; i++)
|
||||||
{
|
{
|
||||||
files[i] = files[i].Replace(rootCustomPath + '\\', string.Empty);
|
files[i] = files[i].Replace(rootCustomPath + '\\', string.Empty);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var file in files)
|
foreach (var file in files)
|
||||||
@@ -347,7 +357,6 @@ namespace Mitria_Minecraft_Launcher.Updater
|
|||||||
string sourcePath = CommonLibrary.Extensions.PathCombineW(rootCustomPath, file);
|
string sourcePath = CommonLibrary.Extensions.PathCombineW(rootCustomPath, file);
|
||||||
string targetPath = CommonLibrary.Extensions.PathCombineW(Settings.UserLauncherConfig.GameDirectory, Settings.NowProfile.ServerName, file);
|
string targetPath = CommonLibrary.Extensions.PathCombineW(Settings.UserLauncherConfig.GameDirectory, Settings.NowProfile.ServerName, file);
|
||||||
|
|
||||||
|
|
||||||
if (System.IO.File.Exists(targetPath))
|
if (System.IO.File.Exists(targetPath))
|
||||||
{
|
{
|
||||||
System.IO.FileInfo sourceFile = new System.IO.FileInfo(sourcePath);
|
System.IO.FileInfo sourceFile = new System.IO.FileInfo(sourcePath);
|
||||||
@@ -356,7 +365,6 @@ namespace Mitria_Minecraft_Launcher.Updater
|
|||||||
{
|
{
|
||||||
System.IO.File.Copy(sourcePath, targetPath, true);
|
System.IO.File.Copy(sourcePath, targetPath, true);
|
||||||
Log.INFO("[CustomData] +[F] " + targetPath);
|
Log.INFO("[CustomData] +[F] " + targetPath);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -387,8 +395,10 @@ namespace Mitria_Minecraft_Launcher.Updater
|
|||||||
GameUpdateManagerMessage?.Invoke(this, e);
|
GameUpdateManagerMessage?.Invoke(this, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public enum GameUpdateStatus
|
public enum GameUpdateStatus
|
||||||
|
|
||||||
{
|
{
|
||||||
Success,
|
Success,
|
||||||
Fail
|
Fail
|
||||||
|
Reference in New Issue
Block a user