Skip to content

Commit c3bbc55

Browse files
committed
Delete update source directory after update install
1 parent 16f081e commit c3bbc55

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

Client/loader/Install.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ static int RunInstall()
694694
bool backupExists = FileExists(file.backupFile.absolutePath);
695695
uint64_t backupSize = FileSize(file.backupFile.absolutePath);
696696
AddReportLog(5055, SString("RunInstall: Unable to create backup of '%s' (attempts: %d, checksums: %d, target: %d [size:%llu hash:%08x], backup: %d "
697-
"[size: %llu hash:%08x])",
697+
"[size:%llu hash:%08x])",
698698
file.relativePath.c_str(), attempts, checksums, targetExists, targetSize, file.targetFile.checksum.value_or(0),
699699
backupExists, backupSize, file.backupFile.checksum.value_or(0)));
700700
return 6;
@@ -828,6 +828,13 @@ static int RunInstall()
828828
}
829829

830830
OutputDebugLine(SString("RunInstall: Installation of %zu files complete", files.size()));
831+
832+
// Switch to the source directory's parent to finally delete the source directory.
833+
if (SetCurrentDirectory(ExtractPath(sourceRoot)))
834+
{
835+
DirectoryDeleteScope deleteSourceRoot(sourceRoot);
836+
}
837+
831838
return 0;
832839
}
833840

@@ -903,6 +910,8 @@ SString CheckOnRestartCommand()
903910
if (sourceRoot.empty())
904911
return "FileError1";
905912

913+
DirectoryDeleteScope deleteSourceRoot(sourceRoot);
914+
906915
if (!SetCurrentDirectory(sourceRoot))
907916
return "FileError2";
908917

@@ -911,13 +920,20 @@ SString CheckOnRestartCommand()
911920
StartPseudoProgress(g_hInstance, "MTA: San Andreas", _("Extracting files..."));
912921

913922
// Try to extract the files
914-
if (!ExtractFiles(strFile, true))
923+
bool success = ExtractFiles(strFile, /* withManifest */ true);
924+
925+
if (!success)
915926
{
916927
// If extract failed and update file is an .exe or .msu, try to run it
917928
if (ExtractExtension(strFile).EqualsI("exe") || ExtractExtension(strFile).EqualsI("msu"))
918-
ShellExecuteBlocking("open", strFile, strParameters.SplitRight("###"));
929+
success = ShellExecuteBlocking("open", strFile, strParameters.SplitRight("###"));
919930
}
920931

932+
if (!success)
933+
return "FileError3";
934+
935+
deleteSourceRoot.Release();
936+
921937
// Stop progress bar
922938
StopPseudoProgress();
923939

0 commit comments

Comments
 (0)