Browse Source

...

works_for_me
Volker Birk 2 years ago
parent
commit
df036865dd
4 changed files with 35 additions and 29 deletions
  1. +3
    -1
      pEpMacOSAdapter/Makefile
  2. +1
    -1
      pEpMacOSAdapter/pEpUpdater.h
  3. +31
    -27
      pEpMacOSAdapter/pEpUpdater.mm
  4. BIN
      pEpMacOSAdapter/test.der

+ 3
- 1
pEpMacOSAdapter/Makefile View File

@ -81,9 +81,11 @@ unload:
launchctl unload /Library/LaunchAgents/foundation.pEp.adapter.macOS.plist
install: $(TARGET)
sudo install -d "$(INSTALL_TARGET)/Updater"
sudo install -c foundation.pEp.adapter.macOS "$(INSTALL_TARGET)/foundation.pEp.adapter.macOS"
sudo install -c foundation.pEp.adapter.macOS.plist "/Library/LaunchAgents/foundation.pEp.adapter.macOS.plist"
sudo install -c test.plist "/Library/Application Support/pEp/Updater/test.plist"
sudo install -c test.plist "$(INSTALL_TARGET)/Updater/test.plist"
sudo install -c test.der "$(INSTALL_TARGET)/Updater/test.der"
uninstall:
sudo rm -f "$(INSTALL_TARGET)/foundation.pEp.adapter.macOS"


+ 1
- 1
pEpMacOSAdapter/pEpUpdater.h View File

@ -17,7 +17,7 @@
@property (strong) NSTimer* timer;
/// path with config files
@property (strong) NSString* configPath;
@property (retain) NSString* configPath;
/// initializes the pEpUpdater
///


+ 31
- 27
pEpMacOSAdapter/pEpUpdater.mm View File

@ -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());
}
}


BIN
pEpMacOSAdapter/test.der View File


Loading…
Cancel
Save