Skip to content

Commit

Permalink
Style cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
colincornaby committed Jul 9, 2024
1 parent f82cf31 commit 3534291
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 27 deletions.
38 changes: 22 additions & 16 deletions Sources/Plasma/Apps/plClient/Mac-Cocoa/PLSPatcher.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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;

Expand All @@ -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);
}
}
Expand All @@ -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;
Expand All @@ -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];
Expand All @@ -272,14 +276,18 @@ 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;
}

ST::string outputPath = [outputURL.path STString];

bool succeeded = true;

struct archive_entry *entry;
struct archive_entry* entry;
while (true) {
r = archive_read_next_header(a, &entry);
if (r == ARCHIVE_EOF)
Expand All @@ -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));
Expand Down Expand Up @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions Sources/Plasma/CoreLib/plFileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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('/');
Expand Down
16 changes: 8 additions & 8 deletions Sources/Plasma/FeatureLib/pfPatcher/plManifests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 3534291

Please sign in to comment.