From 353429132c7100b192bebabc1a76efee3e02310c Mon Sep 17 00:00:00 2001 From: Colin Cornaby Date: Mon, 8 Jul 2024 21:05:28 -0700 Subject: [PATCH] Style cleanup --- .../Apps/plClient/Mac-Cocoa/PLSPatcher.mm | 38 +++++++++++-------- .../Mac-Cocoa/PLSPatcherWindowController.mm | 1 - Sources/Plasma/CoreLib/plFileSystem.cpp | 3 +- .../FeatureLib/pfPatcher/plManifests.cpp | 16 ++++---- 4 files changed, 31 insertions(+), 27 deletions(-) diff --git a/Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSPatcher.mm b/Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSPatcher.mm index 812582fbf7..5c65e4e0b6 100644 --- a/Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSPatcher.mm +++ b/Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSPatcher.mm @@ -125,8 +125,7 @@ - (NSURL *)completeSelfPatch:(NSError **)error; if (!self.updatedClientURL) { // uh oh - this implies we weren't able to decompress the client - if (error) - { + if (error) { // Handle as a generic could not read file error. // Bad compression on the server will require correction on the server end. *error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadNoSuchFileError userInfo:nil]; @@ -197,11 +196,11 @@ bool IApproveDownload(const plFileName& file) return extExcludeList.find(file.GetFileExt()) == extExcludeList.end(); } -static la_ssize_t copy_data(struct archive *ar, struct archive *aw) +static la_ssize_t copy_data(struct archive* ar, struct archive* aw) { while (true) { la_ssize_t r; - const void *buff; + const void* buff; size_t size; la_int64_t offset; @@ -212,7 +211,7 @@ static la_ssize_t copy_data(struct archive *ar, struct archive *aw) return (r); r = archive_write_data_block(aw, buff, size, offset); if (r < ARCHIVE_OK) { - fprintf(stderr, "%s\n", archive_error_string(aw)); + plStatusLog::AddLineSF("%s\n", archive_error_string(aw)); return (r); } } @@ -236,8 +235,8 @@ static la_ssize_t copy_data(struct archive *ar, struct archive *aw) /* Select which attributes we want to restore. */ flags = ARCHIVE_EXTRACT_TIME | ARCHIVE_EXTRACT_PERM; - struct archive *a = archive_read_new(); - struct archive *ext = archive_write_disk_new(); + struct archive* a = archive_read_new(); + struct archive* ext = archive_write_disk_new(); { int error; @@ -259,9 +258,14 @@ static la_ssize_t copy_data(struct archive *ar, struct archive *aw) return; } - NSError *error; - patcher.temporaryDirectory = [NSFileManager.defaultManager URLForDirectory:NSItemReplacementDirectory inDomain:NSUserDomainMask appropriateForURL:[NSURL fileURLWithPath:NSFileManager.defaultManager.currentDirectoryPath] create:YES error:&error]; - NSURL *outputURL; + NSError* error; + NSURL* currentDirectory = [NSURL fileURLWithPath:NSFileManager.defaultManager.currentDirectoryPath]; + patcher.temporaryDirectory = [NSFileManager.defaultManager + URLForDirectory:NSItemReplacementDirectory + inDomain:NSUserDomainMask + appropriateForURL:currentDirectory + create:YES error:&error]; + NSURL* outputURL; if (patcher.temporaryDirectory) { outputURL = [patcher.temporaryDirectory URLByAppendingPathComponent:[NSString stringWithSTString:plManifest::PatcherExecutable().GetFileName()]]; [NSFileManager.defaultManager createDirectoryAtURL:outputURL withIntermediateDirectories:false attributes:nil error:&error]; @@ -272,6 +276,10 @@ static la_ssize_t copy_data(struct archive *ar, struct archive *aw) // get a writable temp directory. But if we could not, bail. // Not populating the patched client path will be caught // later. + archive_read_close(a); + archive_read_free(a); + archive_write_close(ext); + archive_write_free(ext); return; } @@ -279,7 +287,7 @@ static la_ssize_t copy_data(struct archive *ar, struct archive *aw) bool succeeded = true; - struct archive_entry *entry; + struct archive_entry* entry; while (true) { r = archive_read_next_header(a, &entry); if (r == ARCHIVE_EOF) @@ -290,9 +298,8 @@ static la_ssize_t copy_data(struct archive *ar, struct archive *aw) succeeded = false; break; } - const char* currentFile = archive_entry_pathname(entry); - auto fullOutputPath = outputPath + "/" + currentFile; - archive_entry_set_pathname(entry, fullOutputPath.c_str()); + auto fullOutputPath = plFileName::Join(plFileName("outputPath"), plFileName("currentFile")); + archive_entry_set_pathname(entry, fullOutputPath.AsString().c_str()); r = archive_write_header(ext, entry); if (r < ARCHIVE_OK) pfPatcher::GetLog()->AddLineF(plStatusLog::kRed, "Failed to extract file while patching app bundle: {}", archive_error_string(ext)); @@ -320,8 +327,7 @@ static la_ssize_t copy_data(struct archive *ar, struct archive *aw) plFileSystem::Unlink(file); - if (succeeded) - { + if (succeeded) { parent.updatedClientURL = outputURL; } } diff --git a/Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSPatcherWindowController.mm b/Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSPatcherWindowController.mm index 95e6382c2f..d6675e06ec 100644 --- a/Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSPatcherWindowController.mm +++ b/Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSPatcherWindowController.mm @@ -91,7 +91,6 @@ - (void)patcherCompleted:(nonnull PLSPatcher *)patcher didSelfPatch:(BOOL)selfPa // intercepted by the application } - - (void)observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object change:(NSDictionary*)change diff --git a/Sources/Plasma/CoreLib/plFileSystem.cpp b/Sources/Plasma/CoreLib/plFileSystem.cpp index d3de746b0d..eb35a60f82 100644 --- a/Sources/Plasma/CoreLib/plFileSystem.cpp +++ b/Sources/Plasma/CoreLib/plFileSystem.cpp @@ -84,8 +84,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com ST::string plFileName::GetFileName() const { - if(fName.ends_with("/")) - { + if (fName.ends_with("/")) return plFileName(fName.before_last('/')).GetFileName(); } ST_ssize_t end = fName.find_last('/'); diff --git a/Sources/Plasma/FeatureLib/pfPatcher/plManifests.cpp b/Sources/Plasma/FeatureLib/pfPatcher/plManifests.cpp index 1b34683b4e..fde7be5e67 100644 --- a/Sources/Plasma/FeatureLib/pfPatcher/plManifests.cpp +++ b/Sources/Plasma/FeatureLib/pfPatcher/plManifests.cpp @@ -52,25 +52,25 @@ Mead, WA 99021 # define MANIFEST(in, ex) in #endif // PLASMA_EXTERNAL_RELEASE -#if HS_BUILD_FOR_APPLE -# define PL_EXECUTABLE_SUFFIX ".app" -#elif HS_BUILD_FOR_WIN32 -# define PL_EXECUTABLE_SUFFIX ".exe" +#if defined(HS_BUILD_FOR_APPLE) +# define EXECUTABLE_SUFFIX ".app" +#elif defined(HS_BUILD_FOR_WIN32) +# define EXECUTABLE_SUFFIX ".exe" #else -# define PL_EXECUTABLE_SUFFIX "" +# define EXECUTABLE_SUFFIX "" #endif plFileName plManifest::ClientExecutable() { - return MANIFEST("plClient" PL_EXECUTABLE_SUFFIX, "UruExplorer" PL_EXECUTABLE_SUFFIX); + return MANIFEST("plClient" EXECUTABLE_SUFFIX, "UruExplorer" EXECUTABLE_SUFFIX); } plFileName plManifest::PatcherExecutable() { #ifdef HS_BUILD_FOR_MACOS - return MANIFEST("plClient" PL_EXECUTABLE_SUFFIX, "UruExplorer" PL_EXECUTABLE_SUFFIX); + return MANIFEST("plClient" EXECUTABLE_SUFFIX, "UruExplorer" EXECUTABLE_SUFFIX); #else - return MANIFEST("plUruLauncher" PL_EXECUTABLE_SUFFIX, "UruLauncher" PL_EXECUTABLE_SUFFIX); + return MANIFEST("plUruLauncher" EXECUTABLE_SUFFIX, "UruLauncher" EXECUTABLE_SUFFIX); #endif }