Keep version of mate (installed) in defaults

This is so that we know when to update the installed version.
This commit is contained in:
Allan Odgaard
2012-08-11 20:49:55 +02:00
parent 512e5fdede
commit 2dcc7ec7b4
3 changed files with 11 additions and 0 deletions

View File

@@ -52,6 +52,7 @@ PUBLIC extern NSString* const kUserDefaultsLastBundleUpdateCheckKey;
// ============
PUBLIC extern NSString* const kUserDefaultsMateInstallPathKey;
PUBLIC extern NSString* const kUserDefaultsMateInstallVersionKey;
PUBLIC extern NSString* const kUserDefaultsDisableRMateServerKey;
PUBLIC extern NSString* const kUserDefaultsRMateServerListenKey;

View File

@@ -119,6 +119,7 @@ NSString* const kUserDefaultsLastBundleUpdateCheckKey = @"lastBundleUpdateChec
// ============
NSString* const kUserDefaultsMateInstallPathKey = @"mateInstallPath";
NSString* const kUserDefaultsMateInstallVersionKey = @"mateInstallVersion";
NSString* const kUserDefaultsDisableRMateServerKey = @"rmateServerDisabled";
NSString* const kUserDefaultsRMateServerListenKey = @"rmateServerListen"; // localhost (default), remote

View File

@@ -7,6 +7,7 @@
#import <OakFoundation/NSString Additions.h>
#import <OakFoundation/OakStringListTransformer.h>
#import <io/path.h>
#import <io/exec.h>
#import <ns/ns.h>
#import <regexp/format_string.h>
#import <bundles/bundles.h>
@@ -218,7 +219,10 @@ static bool uninstall_mate (std::string const& path)
if(NSString* path = self.mateInstallPath)
{
if(access([path fileSystemRepresentation], F_OK) != 0)
{
[[NSUserDefaults standardUserDefaults] removeObjectForKey:kUserDefaultsMateInstallPathKey];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:kUserDefaultsMateInstallVersionKey];
}
}
installPathPopUp.target = self;
@@ -249,7 +253,12 @@ static bool uninstall_mate (std::string const& path)
if(NSString* srcPath = [[NSBundle mainBundle] pathForResource:@"mate" ofType:nil])
{
if(install_mate(to_s(srcPath), to_s(dstPath)))
{
[self setMateInstallPath:dstPath];
std::string res = io::exec(to_s(srcPath), "--version", NULL);
if(regexp::match_t const& m = regexp::search("\\Amate ([\\d.]+)", res.data(), res.data() + res.size()))
[[NSUserDefaults standardUserDefaults] setObject:[NSString stringWithUTF8String:res.data() + m.begin(1) length:m.end(1) - m.begin(1)] forKey:kUserDefaultsMateInstallVersionKey];
}
}
else
{