Skip to content

Commit

Permalink
Merge pull request #2742 from ktprograms/fix-set-vm-icon
Browse files Browse the repository at this point in the history
Fix crash when setting custom VM icon (#2387)
  • Loading branch information
osy committed Aug 26, 2021
2 parents 4cb8618 + 39d800a commit 94eed42
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions Managers/UTMVirtualMachine.m
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ - (instancetype)initWithConfiguration:(UTMConfiguration *)configuration withDest
if (self) {
self.parentPath = dstUrl;
self.configuration = configuration;
self.configuration.selectedCustomIconPath = configuration.selectedCustomIconPath;
self.viewState = [[UTMViewState alloc] init];
}
return self;
Expand Down Expand Up @@ -195,14 +196,16 @@ - (BOOL)saveUTMWithError:(NSError * _Nullable *)err {
}
// save icon
if (self.configuration.iconCustom && self.configuration.selectedCustomIconPath) {
NSURL *oldIconPath = [url URLByAppendingPathComponent:self.configuration.icon];
if (self.configuration.icon != nil) {
NSURL *oldIconPath = [url URLByAppendingPathComponent:self.configuration.icon];
// delete old icon
if ([fileManager fileExistsAtPath:oldIconPath.path]) {
[fileManager removeItemAtURL:oldIconPath error:&_err]; // Ignore error
}
}
NSString *newIcon = self.configuration.selectedCustomIconPath.lastPathComponent;
NSURL *newIconPath = [url URLByAppendingPathComponent:newIcon];

// delete old icon
if ([fileManager fileExistsAtPath:oldIconPath.path]) {
[fileManager removeItemAtURL:oldIconPath error:&_err]; // ignore error
}
// copy new icon
if (![fileManager copyItemAtURL:self.configuration.selectedCustomIconPath toURL:newIconPath error:&_err]) {
goto error;
Expand Down

0 comments on commit 94eed42

Please sign in to comment.