Skip to content
This repository has been archived by the owner on Oct 1, 2018. It is now read-only.

Commit

Permalink
Small refactoring: all file names are now in one place.
Browse files Browse the repository at this point in the history
  • Loading branch information
nikDemyankov committed Feb 29, 2016
1 parent e6b4ad9 commit 7d4dbdf
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 21 deletions.
9 changes: 8 additions & 1 deletion src/ios/Config/HCPApplicationConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
*/
@property (nonatomic, strong, readonly) HCPContentConfig *contentConfig;

+ (instancetype)configFromBundle;
/**
* Create instance of the application config from the configuration file in assets.
*
* @param configFileName name of the configuration file
*
* @return config instance
*/
+ (instancetype)configFromBundle:(NSString *)configFileName;

@end
38 changes: 19 additions & 19 deletions src/ios/Config/HCPApplicationConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,25 @@ - (NSString *)storeUrl {
return _storeUrl;
}

+ (instancetype)configFromBundle:(NSString *)configFileName {
NSURL *wwwFolderURL = [NSURL fileURLWithPath:[NSBundle pathToWwwFolder] isDirectory:YES];
NSURL *chcpJsonFileURLFromBundle = [wwwFolderURL URLByAppendingPathComponent:configFileName];

NSData *jsonData = [NSData dataWithContentsOfURL:chcpJsonFileURLFromBundle];
if (jsonData == nil) {
return nil;
}

NSError *error = nil;
id json = [NSJSONSerialization JSONObjectWithData:jsonData options:kNilOptions error:&error];
if (error) {
NSLog(@"Can't read application config from bundle. %@", [error underlyingErrorLocalizedDesription]);
return nil;
}

return [HCPApplicationConfig instanceFromJsonObject:json];
}

#pragma mark HCPJsonConvertable implementation

- (id)toJson {
Expand Down Expand Up @@ -77,23 +96,4 @@ + (instancetype)instanceFromJsonObject:(id)json {
return appConfig;
}

+ (instancetype)configFromBundle {
NSURL *wwwFolderURL = [NSURL fileURLWithPath:[NSBundle pathToWwwFolder] isDirectory:YES];
NSURL *chcpJsonFileURLFromBundle = [wwwFolderURL URLByAppendingPathComponent:@"chcp.json"];

NSData *jsonData = [NSData dataWithContentsOfURL:chcpJsonFileURLFromBundle];
if (jsonData == nil) {
return nil;
}

NSError *error = nil;
id json = [NSJSONSerialization JSONObjectWithData:jsonData options:kNilOptions error:&error];
if (error) {
NSLog(@"Can't read chcp.json config from bundle. %@", [error underlyingErrorLocalizedDesription]);
return nil;
}

return [HCPApplicationConfig instanceFromJsonObject:json];
}

@end
3 changes: 2 additions & 1 deletion src/ios/Config/HCPPluginInternalPreferences.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#import "HCPPluginInternalPreferences.h"
#import "NSBundle+HCPExtension.h"
#import "HCPApplicationConfig.h"
#import "HCPFilesStructure.h"

#pragma mark JSON keys for plugin options

Expand All @@ -27,7 +28,7 @@ + (HCPPluginInternalPreferences *)defaultConfig {
pluginConfig.previousReleaseVersionName = @"";
pluginConfig.readyForInstallationReleaseVersionName = @"";

HCPApplicationConfig *config = [HCPApplicationConfig configFromBundle];
HCPApplicationConfig *config = [HCPApplicationConfig configFromBundle:[HCPFilesStructure defaultConfigFileName]];
pluginConfig.currentReleaseVersionName = config.contentConfig.releaseVersion;

return pluginConfig;
Expand Down
16 changes: 16 additions & 0 deletions src/ios/Model/HCPFilesStructure.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,20 @@
*/
+ (NSURL *)pluginRootFolder;

/**
* Default application config file name.
* Should be equal to the config name, that is bundled with the app.
*
* @return default application config file name.
*/
+ (NSString *)defaultConfigFileName;

/**
* Default name of the manifest file.
* Should be equal to the manifest name, that is bundled with the app.
*
* @return default manifest file name.
*/
+ (NSString *)defaultManifestFileName;

@end
8 changes: 8 additions & 0 deletions src/ios/Model/HCPFilesStructure.m
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,12 @@ - (NSString *)manifestFileName {
return CHCP_MANIFEST_FILE_PATH;
}

+ (NSString *)defaultConfigFileName {
return CHCP_JSON_FILE_PATH;
}

+ (NSString *)defaultManifestFileName {
return CHCP_MANIFEST_FILE_PATH;
}

@end

0 comments on commit 7d4dbdf

Please sign in to comment.