|
|
|
@ -15,7 +15,7 @@ static const double CYCLE = 7200.0; // 7200 seconds = 2 hours
|
|
|
|
|
|
|
|
|
|
@implementation pEpUpdater
|
|
|
|
|
|
|
|
|
|
pEpNotification *_subscriber = nil;
|
|
|
|
|
pEpNotification* _subscriber = nil;
|
|
|
|
|
|
|
|
|
|
- (id)initWithSubscriber:(pEpNotification*)subscriber
|
|
|
|
|
{
|
|
|
|
@ -32,7 +32,7 @@ pEpNotification *_subscriber = nil;
|
|
|
|
|
|
|
|
|
|
- (void)scheduleUpdates
|
|
|
|
|
{
|
|
|
|
|
NSLog(@"pEpMacOSAdapter: schedule updates");
|
|
|
|
|
NSLog(@"schedule updates");
|
|
|
|
|
|
|
|
|
|
self.timer = [NSTimer scheduledTimerWithTimeInterval:CYCLE target:self
|
|
|
|
|
selector:@selector(updateAll:)
|
|
|
|
@ -41,23 +41,23 @@ pEpNotification *_subscriber = nil;
|
|
|
|
|
|
|
|
|
|
- (void)updateAll:(NSTimer*)timer
|
|
|
|
|
{
|
|
|
|
|
NSLog(@"pEpMacOSAdapter: update all registered products");
|
|
|
|
|
NSLog(@"update all registered products");
|
|
|
|
|
|
|
|
|
|
NSFileManager *localFileManager=[NSFileManager new];
|
|
|
|
|
NSDirectoryEnumerator *dirEnum = [localFileManager enumeratorAtPath:self.configPath];
|
|
|
|
|
NSDirectoryEnumerator *dirEnum = [localFileManager enumeratorAtPath:_configPath];
|
|
|
|
|
|
|
|
|
|
NSString *configFile;
|
|
|
|
|
while (dirEnum && (configFile = [dirEnum nextObject])) {
|
|
|
|
|
if ([[configFile pathExtension] isEqualToString: @"plist"]) {
|
|
|
|
|
NSError *err = nil;
|
|
|
|
|
[self updateWithFile:[NSString stringWithFormat:@"%@/%@", self.configPath, configFile] error:&err];
|
|
|
|
|
[self updateWithFile:[NSString stringWithFormat:@"%@/%@", _configPath, configFile] error:&err];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)updateWithFile:(NSString*)configFile error:(NSError **)err
|
|
|
|
|
{
|
|
|
|
|
NSLog(@"pEpMacOSAdapter: update product with config file %@", configFile);
|
|
|
|
|
NSLog(@"update product with config file %@", configFile);
|
|
|
|
|
|
|
|
|
|
NSInputStream *is = [NSInputStream inputStreamWithFileAtPath:configFile];
|
|
|
|
|
[is open];
|
|
|
|
@ -74,7 +74,7 @@ pEpNotification *_subscriber = nil;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (err) {
|
|
|
|
|
NSLog(@"pEpMacOSAdapter: %@ %@ %@ %@", (*err).localizedDescription,
|
|
|
|
|
NSLog(@"%@ %@ %@ %@", (*err).localizedDescription,
|
|
|
|
|
(*err).localizedFailureReason, (*err).localizedRecoveryOptions,
|
|
|
|
|
(*err).localizedRecoverySuggestion);
|
|
|
|
|
}
|
|
|
|
@ -82,36 +82,39 @@ pEpNotification *_subscriber = nil;
|
|
|
|
|
|
|
|
|
|
- (void)update:(NSString*)name usingUrl:(NSString*)url
|
|
|
|
|
{
|
|
|
|
|
NSLog(@"pEpMacOSAdapter: update %@ using %@", name, url);
|
|
|
|
|
NSLog(@"update %@ using %@", name, url);
|
|
|
|
|
|
|
|
|
|
pEp::UpdateClient::product p = { name.UTF8String, url.UTF8String };
|
|
|
|
|
|
|
|
|
|
std::string keyfile = self.configPath.UTF8String;
|
|
|
|
|
keyfile += "/";
|
|
|
|
|
|
|
|
|
|
std::string keyfile = _configPath.UTF8String;
|
|
|
|
|
keyfile += std::string("/");
|
|
|
|
|
keyfile += p.name;
|
|
|
|
|
keyfile += ".der";
|
|
|
|
|
keyfile += std::string(".der");
|
|
|
|
|
|
|
|
|
|
NSLog(@"using key from %s", keyfile.c_str());
|
|
|
|
|
|
|
|
|
|
NSFileManager *localFileManager=[NSFileManager new];
|
|
|
|
|
NSString* cwd = localFileManager.currentDirectoryPath;
|
|
|
|
|
NSString* tmp = NSTemporaryDirectory();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
NSFileManager *localFileManager=[NSFileManager new];
|
|
|
|
|
NSString* cwd = localFileManager.currentDirectoryPath;
|
|
|
|
|
NSString* tmp = NSTemporaryDirectory();
|
|
|
|
|
|
|
|
|
|
[localFileManager changeCurrentDirectoryPath:tmp];
|
|
|
|
|
std::string _filename;
|
|
|
|
|
|
|
|
|
|
pEp::notifyRead_t notifyRead = [=]()->void{
|
|
|
|
|
if (_subscriber) {
|
|
|
|
|
[_subscriber notifyDownload:downloading withName:name withFilename:nil];
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
[localFileManager changeCurrentDirectoryPath:tmp];
|
|
|
|
|
std::string _filename;
|
|
|
|
|
|
|
|
|
|
pEp::notifyRead_t notifyRead = [=]()->void{
|
|
|
|
|
if (_subscriber) {
|
|
|
|
|
[_subscriber notifyDownload:downloading withName:name withFilename:nil];
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
_filename = pEp::UpdateClient::update(p, keyfile, notifyRead);
|
|
|
|
|
|
|
|
|
|
if (_filename.length()) {
|
|
|
|
|
NSString* filename = [NSString stringWithUTF8String:_filename.c_str()];
|
|
|
|
|
NSString* download = [NSString stringWithFormat:@"%@/%@", tmp, filename];
|
|
|
|
|
[localFileManager changeCurrentDirectoryPath:cwd];
|
|
|
|
|
|
|
|
|
|
NSLog(@"pEpMacOSAdapter: download arrived %@", download);
|
|
|
|
|
NSLog(@"download arrived %@", download);
|
|
|
|
|
|
|
|
|
|
if (_subscriber) {
|
|
|
|
|
[_subscriber notifyDownload:downloadArrived withName:name withFilename:download];
|
|
|
|
@ -124,7 +127,8 @@ pEpNotification *_subscriber = nil;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (std::exception& e) {
|
|
|
|
|
NSLog(@"pEpMacOSAdapter: %s", e.what());
|
|
|
|
|
NSLog(@"pEp::UpdateClient::update({\"%s\", \"%s\"}, \"%s\"): %s",
|
|
|
|
|
p.name.c_str(), p.url.c_str(), keyfile.c_str(), e.what());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|