forked from jiakuan/mixing-cocoa-and-qt
-
Notifications
You must be signed in to change notification settings - Fork 2
/
SparkleAutoUpdater.mm
102 lines (82 loc) · 1.96 KB
/
SparkleAutoUpdater.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
* Copyright (C) 2008 Remko Troncon
* Copyright (C) 2017 Vadim Peretokin
*/
#include "SparkleAutoUpdater.h"
#include <Cocoa/Cocoa.h>
#include <Sparkle/Sparkle.h>
#include <syslog.h>
static void SYSLOG(const char* format,...)
{
va_list vaList;
va_start( vaList,format );
vsyslog(LOG_ERR,format,vaList);
va_end(vaList);
}
class SparkleAutoUpdater::Private
{
public:
SUUpdater* updater;
};
@interface SparkleDelegate : NSObject <SUUpdaterDelegate> {
SparkleAutoUpdater* delegateHandler;
}
- (void)updaterDidRelaunchApplication:(SUUpdater *)updater;
@end
@implementation SparkleDelegate
- (id) init:(SparkleAutoUpdater*)handler
{
self = [super init];
if (self) {
delegateHandler = handler;
}
return self;
}
- (void)updaterDidRelaunchApplication:(SUUpdater *)updater
{
delegateHandler->setRelaunchFlag();
}
@end
void SparkleAutoUpdater::setRelaunchFlag()
{
relaunchedFromUpdate = true;
}
bool SparkleAutoUpdater::justUpdated()
{
return relaunchedFromUpdate;
}
SparkleAutoUpdater::SparkleAutoUpdater(const QString& aUrl)
{
d = new Private;
d->updater = [SUUpdater sharedUpdater];
[d->updater retain];
NSURL* url = [NSURL URLWithString:
[NSString stringWithUTF8String: aUrl.toUtf8().data()]];
[d->updater setFeedURL: url];
relaunchedFromUpdate = false;
}
SparkleAutoUpdater::~SparkleAutoUpdater()
{
[d->updater release];
delete d;
}
void SparkleAutoUpdater::checkForUpdates()
{
[d->updater checkForUpdates:nil];
}
void SparkleAutoUpdater::setAutomaticallyChecksForUpdates(bool on)
{
[d->updater setAutomaticallyChecksForUpdates:on];
}
bool SparkleAutoUpdater::automaticallyChecksForUpdates()
{
return [d->updater automaticallyChecksForUpdates];
}
void SparkleAutoUpdater::setAutomaticallyDownloadsUpdates(bool on)
{
[d->updater setAutomaticallyDownloadsUpdates:on];
}
bool SparkleAutoUpdater::automaticallyDownloadsUpdates()
{
return [d->updater automaticallyDownloadsUpdates];
}