Skip to content

Commit

Permalink
Fix updater
Browse files Browse the repository at this point in the history
  • Loading branch information
Laeng committed May 24, 2024
1 parent 0a39828 commit b09c555
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
4 changes: 2 additions & 2 deletions SCTools/SCTool_Redesigned/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호를
// 기본값으로 할 수 있습니다.
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.3.4.0")]
[assembly: AssemblyFileVersion("1.3.4.0")]
[assembly: AssemblyVersion("1.3.4.1")]
[assembly: AssemblyFileVersion("1.3.4.1")]
35 changes: 24 additions & 11 deletions SCTools/SCTool_Redesigned/Update/CustomApplicationUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ public CustomApplicationUpdater(IUpdateRepository updateRepository, string execu
_updateScriptPath = Path.Combine(_executableDir, "update.bat");
_updatesStoragePath = Path.Combine(_executableDir, "updates");
_schedInstallArchivePath = Path.Combine(_updatesStoragePath, "latest.zip");
_schedInstallExecutablePath = Path.Combine(_updatesStoragePath, "shatagon.exe");
_schedInstallExecutablePath = Path.Combine(_updatesStoragePath, "Shatagon.exe");
_schedInstallJsonPath = Path.Combine(_updatesStoragePath, "latest.json");
_installUnpackedDir = Path.Combine(_updatesStoragePath, "latest");
_installUnpackedExecutablePath = Path.Combine(_updatesStoragePath, "latest", "shatagon.exe");
_installUnpackedExecutablePath = Path.Combine(_updatesStoragePath, "latest", "Shatagon.exe");
_currentVersion = _updateRepository.CurrentVersion;
}

Expand Down Expand Up @@ -147,11 +147,11 @@ public bool ScheduleInstallUpdate(UpdateInfo updateInfo, string filePath)
{
Directory.CreateDirectory(_updatesStoragePath);
}
if (File.Exists(_schedInstallArchivePath))
if (File.Exists(_schedInstallExecutablePath))
{
File.Delete(_schedInstallArchivePath);
File.Delete(_schedInstallExecutablePath);
}
File.Move(filePath, _schedInstallArchivePath);
File.Move(filePath, _schedInstallExecutablePath);
if (JsonHelper.WriteFile(_schedInstallJsonPath, updateInfo))
{
_updateRepository.SetCurrentVersion(updateInfo.GetVersion());
Expand All @@ -176,8 +176,8 @@ public bool CancelScheduleInstallUpdate()
_updateRepository.SetCurrentVersion(_currentVersion);
if (File.Exists(_schedInstallJsonPath))
FileUtils.DeleteFileNoThrow(_schedInstallJsonPath);
return File.Exists(_schedInstallArchivePath) &&
FileUtils.DeleteFileNoThrow(_schedInstallArchivePath);
return File.Exists(_schedInstallExecutablePath) &&
FileUtils.DeleteFileNoThrow(_schedInstallExecutablePath);
}

public void RemoveUpdateScript()
Expand Down Expand Up @@ -205,7 +205,7 @@ private bool ExtractUpdateScript()
private bool ExtractReadyInstallUpdate()
{
var installUnpackedDir = new DirectoryInfo(_installUnpackedDir);
var extractTempDir = new DirectoryInfo(Path.Combine(_updatesStoragePath, "temp_" + Path.GetRandomFileName()));
//var extractTempDir = new DirectoryInfo(Path.Combine(_updatesStoragePath, "temp_" + Path.GetRandomFileName()));
try
{
if (installUnpackedDir.Exists && !FileUtils.DeleteDirectoryNoThrow(installUnpackedDir, true))
Expand All @@ -214,14 +214,27 @@ private bool ExtractReadyInstallUpdate()
return false;
}

//updates/latest.zip
//updates/temp_random
//updates/lastest
//

//using var archive = ZipFile.OpenRead(_schedInstallArchivePath);

//extractTempDir.Create();
//archive.ExtractToDirectory(extractTempDir.FullName);
//if (!_packageVerifier.VerifyPackage(extractTempDir.FullName))
// throw new NotSupportedException("Not supported upgrade package");
//Directory.Move(extractTempDir.FullName, _installUnpackedDir);

Directory.CreateDirectory(_installUnpackedDir);
File.Move(_schedInstallExecutablePath, _installUnpackedExecutablePath);
File.Copy(_schedInstallExecutablePath, _installUnpackedExecutablePath);
}
catch (Exception e)
{
_logger.Error(e, $"Failed extract update package to: {_installUnpackedDir}");
if (extractTempDir.Exists)
FileUtils.DeleteDirectoryNoThrow(extractTempDir, true);
//if (extractTempDir.Exists)
// FileUtils.DeleteDirectoryNoThrow(extractTempDir, true);
if (installUnpackedDir.Exists)
FileUtils.DeleteDirectoryNoThrow(installUnpackedDir, true);
return false;
Expand Down
3 changes: 1 addition & 2 deletions SCTools/SCTool_Redesigned/Update/CustomPackageVerifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ internal class CustomPackageVerifier : CustomApplicationUpdater.IPackageVerifier

public bool VerifyPackage(string path)
{
if (!File.Exists(Path.Combine(path, $"{ExecutorName}.exe")) ||
!File.Exists(Path.Combine(path, $"{ExecutorName}.exe.config")))
if (!File.Exists(Path.Combine(path, $"{ExecutorName}.exe")))
{
return false;
}
Expand Down

0 comments on commit b09c555

Please sign in to comment.