Database options for version migration

This commit is contained in:
relikd
2019-08-09 21:07:54 +02:00
parent dff1594926
commit c717487b0e
10 changed files with 139 additions and 11 deletions

View File

@@ -22,17 +22,20 @@
#import "SettingsAboutView.h"
#import "NSView+Ext.h"
#import "UserPrefs.h"
@implementation SettingsAboutView
- (instancetype)init {
self = [super initWithFrame: NSZeroRect];
NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
NSString *name = infoDict[@"CFBundleName"];
NSString *version = [NSString stringWithFormat:NSLocalizedString(@"Version %@", nil), infoDict[@"CFBundleShortVersionString"]];
NSString *name = [UserPrefs appName];
NSString *version = [NSString stringWithFormat:NSLocalizedString(@"Version %@", nil),
#if DEBUG
version = [version stringByAppendingFormat:@" (%@)", infoDict[@"CFBundleVersion"]];
[UserPrefs appVersionWithBuildNo]
#else
[UserPrefs appVersion]
#endif
];
// Application icon image (top-centered)
NSImageView *logo = [[NSView imageView:NSImageNameApplicationIcon size:64] placeIn:self x:CENTER yTop:PAD_M];

View File

@@ -23,6 +23,7 @@
#import <Foundation/Foundation.h>
@interface UserPrefs : NSObject
// User Preferences Plist
+ (BOOL)defaultYES:(NSString*)key;
+ (BOOL)defaultNO:(NSString*)key;
@@ -30,7 +31,20 @@
+ (void)setHttpApplication:(NSString*)bundleID;
+ (BOOL)openURLsWithPreferredBrowser:(NSArray<NSURL*>*)urls;
// Hidden Plist Properties
+ (NSUInteger)openFewLinksLimit; // Change with: 'defaults write de.relikd.baRSS openFewLinksLimit -int 10'
+ (NSUInteger)shortArticleNamesLimit; // Change with: 'defaults write de.relikd.baRSS shortArticleNamesLimit -int 50'
+ (NSUInteger)articlesInMenuLimit; // Change with: 'defaults write de.relikd.baRSS articlesInMenuLimit -int 40'
// Application Info Plist
+ (NSString*)appName;
+ (NSString*)appVersion;
+ (NSString*)appVersionWithBuildNo;
// Core Data Properties
+ (BOOL)dbIsUnusedInitalState;
+ (BOOL)dbIsCurrentFileVersion;
+ (BOOL)dbIsCurrentAppVersion;
+ (void)dbUpdateFileVersion;
+ (void)dbUpdateAppVersion;
@end

View File

@@ -21,10 +21,14 @@
// SOFTWARE.
#import "UserPrefs.h"
#import "StoreCoordinator.h"
#import <Cocoa/Cocoa.h>
@implementation UserPrefs
#pragma mark - User Preferences Plist
/// @return @c YES if key is not set. Otherwise, return user defaults property from plist.
+ (BOOL)defaultYES:(NSString*)key {
if ([[NSUserDefaults standardUserDefaults] objectForKey:key] == NULL) {
@@ -66,8 +70,10 @@
return [[NSWorkspace sharedWorkspace] openURLs:urls withAppBundleIdentifier:[self getHttpApplication] options:NSWorkspaceLaunchDefault additionalEventParamDescriptor:nil launchIdentifiers:nil];
}
#pragma mark - Hidden Plist Properties -
/// @return The limit on how many links should be opened at the same time, if user holds the option key.
/// Default: @c 10
+ (NSUInteger)openFewLinksLimit {
@@ -86,4 +92,61 @@
return (NSUInteger)[self defaultInt:40 forKey:@"articlesInMenuLimit"];
}
#pragma mark - Application Info Plist
/// @return The application name, e.g., 'baRSS' or 'baRSS Beta'
+ (NSString*)appName {
return [[NSBundle mainBundle] infoDictionary][(NSString*)kCFBundleNameKey];
}
/// @return The application version number, e.g., '0.9.4'
+ (NSString*)appVersion {
return [[NSBundle mainBundle] infoDictionary][@"CFBundleShortVersionString"];
}
/// @return The application version number including build number, e.g., '0.9.4 (9906)'
+ (NSString*)appVersionWithBuildNo {
NSString *buildNo = [[NSBundle mainBundle] infoDictionary][@"CFBundleVersion"];
return [[self appVersion] stringByAppendingFormat:@" (%@)", buildNo];
}
#pragma mark - Core Data Properties -
/// Helper method that retrieves and transforms option value to int
+ (int)dbIntForKey:(NSString*)key defaultsTo:(int)otherwise {
NSString *str = [StoreCoordinator optionForKey:key];
if (!str) return otherwise;
int num = [NSDecimalNumber decimalNumberWithString:str].intValue;
return isnan(num) ? otherwise : num;
}
/// Check whether the database was just initialized (first install)
+ (BOOL)dbIsUnusedInitalState {
return [StoreCoordinator optionForKey:@"db-version"] == nil;
}
/// Check whether the stored database version is up to date
+ (BOOL)dbIsCurrentFileVersion {
return [self dbIntForKey:@"db-version" defaultsTo:-1] == dbFileVersion;
}
/// Write current database version to core data
+ (void)dbUpdateFileVersion {
[StoreCoordinator setOption:@"db-version" value:[NSString stringWithFormat:@"%d", dbFileVersion]];
}
/// Check whether the stored application version is up to date
+ (BOOL)dbIsCurrentAppVersion {
return [[StoreCoordinator optionForKey:@"app-version"] isEqualToString:[self appVersion]];
}
/// Write current application version to core data
+ (void)dbUpdateAppVersion {
[StoreCoordinator setOption:@"app-version" value:[self appVersion]];
}
@end