Fix savePresets.
This commit is contained in:
1 parent
133df13f0d
commit
1e86b6b9cf
1 file changed
+22
-19
+22
-19
@@ -17,7 +17,6 @@ NSString *SBPresetManagerUpdatedNotification = @"SBPresetManagerUpdatedNotificat
|
|||||||
NSMutableArray<MP42Metadata *> *_presets;
|
NSMutableArray<MP42Metadata *> *_presets;
|
||||||
}
|
}
|
||||||
|
|
||||||
@property (nonatomic, readonly) NSString *appSupportPath;
|
|
||||||
- (BOOL)removePresetWithName:(NSString*)name;
|
- (BOOL)removePresetWithName:(NSString*)name;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@@ -102,31 +101,35 @@ NSString *SBPresetManagerUpdatedNotification = @"SBPresetManagerUpdatedNotificat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_presets.count) {
|
return _presets.count > 0;
|
||||||
return NO;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)savePresets
|
- (BOOL)savePresets
|
||||||
{
|
{
|
||||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
NSURL *appSupportURL = [self appSupportURL];
|
||||||
NSString *appSupportPath = [self appSupportPath];
|
|
||||||
BOOL noErr = YES;
|
|
||||||
|
|
||||||
if (!appSupportPath) {
|
if (!appSupportURL) {
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (![fileManager fileExistsAtPath:appSupportPath]) {
|
BOOL noErr = YES;
|
||||||
[fileManager createDirectoryAtPath:appSupportPath withIntermediateDirectories:noErr attributes:nil error:NULL];
|
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||||
|
|
||||||
|
if (![fileManager fileExistsAtPath:appSupportURL.path]) {
|
||||||
|
[fileManager createDirectoryAtURL:appSupportURL withIntermediateDirectories:noErr attributes:nil error:NULL];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (MP42Metadata *object in _presets) {
|
for (MP42Metadata *preset in _presets) {
|
||||||
NSString *saveLocation = [NSString stringWithFormat:@"%@/%@.sbpreset", appSupportPath, object.presetName];
|
NSURL *presetURL = [appSupportURL URLByAppendingPathComponent:[NSString stringWithFormat:@"%@.sbpreset", preset.presetName]];
|
||||||
noErr = [NSKeyedArchiver archiveRootObject:object toFile:saveLocation];
|
|
||||||
|
NSMutableData *data = [[NSMutableData alloc] init];
|
||||||
|
|
||||||
|
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
|
||||||
|
archiver.requiresSecureCoding = YES;
|
||||||
|
[archiver encodeObject:preset forKey:NSKeyedArchiveRootObjectKey];
|
||||||
|
[archiver finishEncoding];
|
||||||
|
|
||||||
|
noErr = [data writeToURL:presetURL atomically:YES];
|
||||||
}
|
}
|
||||||
return noErr;
|
return noErr;
|
||||||
}
|
}
|
||||||
@@ -153,14 +156,14 @@ NSString *SBPresetManagerUpdatedNotification = @"SBPresetManagerUpdatedNotificat
|
|||||||
- (BOOL)removePresetWithName:(NSString *)name
|
- (BOOL)removePresetWithName:(NSString *)name
|
||||||
{
|
{
|
||||||
BOOL err = NO;
|
BOOL err = NO;
|
||||||
NSString *appSupportPath = [self appSupportPath];
|
NSURL *appSupportURL = [self appSupportURL];
|
||||||
|
|
||||||
if (!appSupportPath) {
|
if (!appSupportURL) {
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
NSFileManager *fileManager = [NSFileManager defaultManager];
|
NSFileManager *fileManager = [NSFileManager defaultManager];
|
||||||
err = [fileManager removeItemAtPath:[NSString stringWithFormat:@"%@/%@.sbpreset", appSupportPath, name]
|
err = [fileManager removeItemAtPath:[NSString stringWithFormat:@"%@/%@.sbpreset", appSupportURL.path, name]
|
||||||
error:NULL];
|
error:NULL];
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
|
|||||||
Reference in new issue
Block a user