@interface HBPreset : HBTreeNode <NSCopying, NSMutableCopying>
- (instancetype)initWithFolderName:(NSString *)title builtIn:(BOOL)builtIn;
-
- (instancetype)initWithName:(NSString *)title content:(NSDictionary *)content builtIn:(BOOL)builtIn;
- (instancetype)initWithDictionary:(NSDictionary *)dict;
+- (instancetype)initWithPreset:(HBPreset *)preset;
/**
* Initializes a newly allocated preset object initialized with the data found at a given URL.
@interface HBPreset ()
-/**
- * The actual content of the preset.
- */
+/// The actual content of the preset.
@property (nonatomic, strong, nullable) NSMutableDictionary *content;
@end
return self;
}
+- (instancetype)initWithPreset:(HBPreset *)preset
+{
+ self = [super init];
+ if (self)
+ {
+ _name = preset.name;
+ _presetDescription = preset.presetDescription;
+ _content = [preset.content mutableCopy];
+ self.isLeaf = preset.isLeaf;
+
+ for (HBPreset *child in preset.children)
+ {
+ HBPreset *mutableChild = [[[self class] alloc] initWithPreset:child];
+ [self insertObject:mutableChild inChildrenAtIndex:0];
+ }
+ }
+ return self;
+}
+
- (instancetype)initWithName:(NSString *)title content:(NSDictionary *)content builtIn:(BOOL)builtIn;
{
self = [self init];
return success;
}
+- (void)cleanUp
+{
+ // Run the libhb clean function
+ NSString *presetJson = [NSJSONSerialization HB_StringWithJSONObject:self.dictionary options:0 error:NULL];
+
+ if (presetJson.length)
+ {
+ char *cleanedJson = hb_presets_clean_json(presetJson.UTF8String);
+ NSDictionary *cleanedDict = [NSJSONSerialization HB_JSONObjectWithUTF8String:cleanedJson options:0 error:NULL];
+ free(cleanedJson);
+
+ if ([cleanedDict isKindOfClass:[NSDictionary class]])
+ {
+ self.content = [cleanedDict mutableCopy];
+ }
+ }
+}
+
#pragma mark - NSCopying
- (id)copyWithZone:(NSZone *)zone
- (id)mutableCopyWithZone:(NSZone *)zone
{
- return [[HBMutablePreset allocWithZone:zone] initWithDictionary:_content];
+ return [[HBMutablePreset allocWithZone:zone] initWithPreset:self];
}
- (NSUInteger)hash