mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-23 04:34:27 +00:00
Compare commits
662
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
59f9e0ee1b | ||
|
|
ac7fd917d3 | ||
|
|
53f0f4f9ee | ||
|
|
55c57abd2f | ||
|
|
006e71fa89 | ||
|
|
c6d47ed68d | ||
|
|
fd906d9589 | ||
|
|
3e6431f94d | ||
|
|
4a015ada8f | ||
|
|
2c1b3783e4 | ||
|
|
808bde2699 | ||
|
|
fde6b4775e | ||
|
|
92bafa92bf | ||
|
|
7e2d4b019e | ||
|
|
10b8872afb | ||
|
|
d4d984f42c | ||
|
|
bd98b33e25 | ||
|
|
79f447d537 | ||
|
|
a4759c871e | ||
|
|
a3b9a74fe1 | ||
|
|
faba759574 | ||
|
|
91800e3036 | ||
|
|
d7dbbe4bb9 | ||
|
|
2579f2c3a3 | ||
|
|
01e9bd82be | ||
|
|
d34d2853f6 | ||
|
|
fd1ffce3e2 | ||
|
|
6ae7b68659 | ||
|
|
54dc6d0071 | ||
|
|
a773ac5856 | ||
|
|
686c87242c | ||
|
|
f2eaaeb4a3 | ||
|
|
5676acaebc | ||
|
|
0055adcc52 | ||
|
|
ad518eb209 | ||
|
|
20100c283f | ||
|
|
fc88f94d5d | ||
|
|
222ab3edd9 | ||
|
|
4b831a1394 | ||
|
|
bdc45d7e47 | ||
|
|
6ca5c3a337 | ||
|
|
4ab8fd1010 | ||
|
|
3f40f444db | ||
|
|
f1d5103a07 | ||
|
|
890f1fb393 | ||
|
|
d7993257fe | ||
|
|
c99378c170 | ||
|
|
00d8b64b41 | ||
|
|
6a79789d32 | ||
|
|
ec8f46af91 | ||
|
|
2ae8248c35 | ||
|
|
d9d3ff2a8e | ||
|
|
b420ad65be | ||
|
|
5504d6896f | ||
|
|
d888705fd8 | ||
|
|
8d1109b59f | ||
|
|
25aca9f56f | ||
|
|
e75a9b0591 | ||
|
|
5dfc6ab3b2 | ||
|
|
76cca58776 | ||
|
|
7141818b31 | ||
|
|
52bee98867 | ||
|
|
b262c2b581 | ||
|
|
192c3b4c2d | ||
|
|
cfe375b5f3 | ||
|
|
271970697e | ||
|
|
1539c0c077 | ||
|
|
aa25194536 | ||
|
|
6ab4163957 | ||
|
|
dfa27acde2 | ||
|
|
50c3df3a6f | ||
|
|
31a49c83b5 | ||
|
|
a57eb736cb | ||
|
|
52b2d75d63 | ||
|
|
9ea81e21b9 | ||
|
|
eda214a3ec | ||
|
|
d2b7fd6236 | ||
|
|
77ce7c19e9 | ||
|
|
048ce10ed5 | ||
|
|
b23d4a9641 | ||
|
|
843bbe7ece | ||
|
|
a7dbe4184c | ||
|
|
3287299f53 | ||
|
|
1b71d3ebd1 | ||
|
|
ef8edef094 | ||
|
|
c793adf2ed | ||
|
|
5cf229ba41 | ||
|
|
4789ebdec5 | ||
|
|
0ed83cf9f2 | ||
|
|
c37fc01bb1 | ||
|
|
7fae28135e | ||
|
|
82c722ba37 | ||
|
|
aba5567a15 | ||
|
|
1325d3fe40 | ||
|
|
8d2054e62a | ||
|
|
d593a04dda | ||
|
|
8fa758f8aa | ||
|
|
2a0d8afe4e | ||
|
|
3e3a11bd0f | ||
|
|
41b2f054f8 | ||
|
|
93ebf843c2 | ||
|
|
984aac852f | ||
|
|
69c9c70d21 | ||
|
|
478c7fd8cd | ||
|
|
243fdf8f7f | ||
|
|
337002f421 | ||
|
|
a7ba6a7421 | ||
|
|
7b3928db9b | ||
|
|
b86770c39f | ||
|
|
f6622104bf | ||
|
|
860739fce2 | ||
|
|
08065bc05b | ||
|
|
38eb63a7a2 | ||
|
|
f7daf04204 | ||
|
|
2350c59cc8 | ||
|
|
4eebdb82c4 | ||
|
|
066d634ef6 | ||
|
|
9e2e489109 | ||
|
|
f9c428ee06 | ||
|
|
16cdd6bf64 | ||
|
|
e657bcf03a | ||
|
|
d138f64bd6 | ||
|
|
3c37f775fb | ||
|
|
7a283bfaeb | ||
|
|
c1510a5bea | ||
|
|
7a20432b1b | ||
|
|
3d8be2d2da | ||
|
|
a59e8ff958 | ||
|
|
26077f47af | ||
|
|
118f3c5141 | ||
|
|
22b65a3095 | ||
|
|
05c51a1c05 | ||
|
|
21f95465da | ||
|
|
ab74bdca79 | ||
|
|
69d471aefb | ||
|
|
d620dc0b52 | ||
|
|
d3f975816e | ||
|
|
91ac9178f1 | ||
|
|
ae52d2743e | ||
|
|
a4082a0e54 | ||
|
|
9c8e825289 | ||
|
|
9662452c09 | ||
|
|
0a3051349a | ||
|
|
1c258cb690 | ||
|
|
4ba453f337 | ||
|
|
6960045e2b | ||
|
|
803925f2cf | ||
|
|
97c71ef700 | ||
|
|
595c6ce491 | ||
|
|
6b7752792d | ||
|
|
b7dc2438a7 | ||
|
|
12904a5af6 | ||
|
|
7fc9e32ce7 | ||
|
|
9aa3015929 | ||
|
|
09f0c43e7c | ||
|
|
a570191859 | ||
|
|
d7dea30de6 | ||
|
|
409e7e22bf | ||
|
|
ed456740b0 | ||
|
|
8a25500eca | ||
|
|
cdfcd1469e | ||
|
|
4c54349c23 | ||
|
|
4d00e8c569 | ||
|
|
02088e0da6 | ||
|
|
f341d0c3a9 | ||
|
|
833081ffa9 | ||
|
|
faed494d4e | ||
|
|
dbebe4b3b2 | ||
|
|
e27828d248 | ||
|
|
44cf0d0e51 | ||
|
|
320b3aa62a | ||
|
|
1d8adc8fac | ||
|
|
bc458a6ab5 | ||
|
|
6be55685c8 | ||
|
|
29b7321094 | ||
|
|
449b00ed3e | ||
|
|
4c2573702e | ||
|
|
88d4b348d9 | ||
|
|
bf07a9435b | ||
|
|
799b2a381f | ||
|
|
8b4cf14e53 | ||
|
|
515511d5e9 | ||
|
|
aca8cc6fbf | ||
|
|
1bc3834345 | ||
|
|
73e96cdcab | ||
|
|
760e32c5bd | ||
|
|
cf1b167954 | ||
|
|
5ef6c64568 | ||
|
|
7e05e97c95 | ||
|
|
5cd98c5508 | ||
|
|
e6deed9c56 | ||
|
|
290f64f552 | ||
|
|
59caa1f300 | ||
|
|
882b5c9b8a | ||
|
|
7ba0c583af | ||
|
|
b275cab13f | ||
|
|
6a48420e07 | ||
|
|
59f9236009 | ||
|
|
f20c121745 | ||
|
|
25040affc2 | ||
|
|
82e6250250 | ||
|
|
9f2d53a3a2 | ||
|
|
ec4ebbdcfb | ||
|
|
716bb30e7c | ||
|
|
aeeae26d1c | ||
|
|
095d223e70 | ||
|
|
55eed9efd8 | ||
|
|
d092ae9295 | ||
|
|
5457476e4a | ||
|
|
5dce90eafa | ||
|
|
268ea201da | ||
|
|
613b759077 | ||
|
|
02e090c291 | ||
|
|
f6a2e76685 | ||
|
|
8f5b9f03ac | ||
|
|
bb682da743 | ||
|
|
bf38b0c9fd | ||
|
|
e64516c089 | ||
|
|
fc725cce01 | ||
|
|
95398cd26f | ||
|
|
b515c15f9b | ||
|
|
01e8cf90c6 | ||
|
|
7152bd0ffa | ||
|
|
05861e5340 | ||
|
|
aa853a0f0f | ||
|
|
a47151c638 | ||
|
|
06642bba20 | ||
|
|
f04a460d63 | ||
|
|
7d4ce0daeb | ||
|
|
a2bcd53eaa | ||
|
|
5a47fb64c3 | ||
|
|
c96aa2eda8 | ||
|
|
e30a342813 | ||
|
|
320672c1f9 | ||
|
|
0bd27c0cb7 | ||
|
|
436107f20e | ||
|
|
abda56d047 | ||
|
|
950e3894b3 | ||
|
|
2300f2bcb0 | ||
|
|
a6d776ca04 | ||
|
|
76e79d6f92 | ||
|
|
9cc1905f87 | ||
|
|
78e24a6fe6 | ||
|
|
f1a353840a | ||
|
|
0f34252f4a | ||
|
|
000a24c63b | ||
|
|
32d4f249d4 | ||
|
|
96272fce7d | ||
|
|
dc925712dc | ||
|
|
e71915b4fb | ||
|
|
31b9ba8dde | ||
|
|
83708695af | ||
|
|
bb363db7f8 | ||
|
|
ba6c3b6854 | ||
|
|
200da2b1be | ||
|
|
db652744ef | ||
|
|
9f3d4fb524 | ||
|
|
86b6502342 | ||
|
|
fa671073fa | ||
|
|
4f1e5a72a0 | ||
|
|
bca574119b | ||
|
|
acb8f5f076 | ||
|
|
16ff5c6683 | ||
|
|
67d53c04b7 | ||
|
|
910f78b569 | ||
|
|
fdaf26e95d | ||
|
|
a8854375f5 | ||
|
|
9937e5a17b | ||
|
|
67b0860a9f | ||
|
|
5b90432f7e | ||
|
|
7cd8974b7e | ||
|
|
9c042a5767 | ||
|
|
3db00fa137 | ||
|
|
f6710e2379 | ||
|
|
990dee6a8d | ||
|
|
7bfec0f3c0 | ||
|
|
3ea1a9eee4 | ||
|
|
f6e292fad3 | ||
|
|
1cce7890d8 | ||
|
|
61340cab17 | ||
|
|
4a95dbeddc | ||
|
|
45178111b3 | ||
|
|
eef0f5f0dc | ||
|
|
1e1025f17d | ||
|
|
69407123ba | ||
|
|
096d43a7a6 | ||
|
|
00b67269d6 | ||
|
|
5fe0a7cb59 | ||
|
|
7baf50506b | ||
|
|
40616b864a | ||
|
|
561bbbe294 | ||
|
|
fba7231261 | ||
|
|
b3ac18f173 | ||
|
|
e2a59fccb2 | ||
|
|
a8f26b16c2 | ||
|
|
b7a3999da8 | ||
|
|
a5c8e0b1e2 | ||
|
|
2768e60ce1 | ||
|
|
9075d4a037 | ||
|
|
da35ef695b | ||
|
|
394319e1fc | ||
|
|
0c6e6fdd84 | ||
|
|
39bb82bd9a | ||
|
|
25d7faea7b | ||
|
|
a0c2de60d3 | ||
|
|
e8299fd116 | ||
|
|
4548228238 | ||
|
|
fe1372c962 | ||
|
|
a6fcfa61b5 | ||
|
|
c34e9b3c34 | ||
|
|
ea81eeec57 | ||
|
|
19ae8506ab | ||
|
|
803676d56a | ||
|
|
5975703b13 | ||
|
|
ecd2ce227b | ||
|
|
3f502b6151 | ||
|
|
fb43787317 | ||
|
|
f81bfd9f1c | ||
|
|
24ebb7b379 | ||
|
|
2460f2fcf7 | ||
|
|
401e696590 | ||
|
|
29035199f3 | ||
|
|
b4210d8f61 | ||
|
|
c120af6b1f | ||
|
|
96ea09e44f | ||
|
|
f5a1b1c27d | ||
|
|
5cdfffa521 | ||
|
|
a5245accf4 | ||
|
|
9bc63ccf7e | ||
|
|
2e3ed79753 | ||
|
|
da3b5c2570 | ||
|
|
756b37d4a5 | ||
|
|
36b7d434ad | ||
|
|
b21b308203 | ||
|
|
dab8a36a13 | ||
|
|
152e6f9572 | ||
|
|
f8fbf370bc | ||
|
|
61291c77d7 | ||
|
|
b90df8b254 | ||
|
|
4dbc0dd47f | ||
|
|
9d3db1b103 | ||
|
|
b8c8b9e605 | ||
|
|
d7260665d6 | ||
|
|
b96c95066c | ||
|
|
3d352c6fcd | ||
|
|
874572f7bb | ||
|
|
8f0d7d0805 | ||
|
|
65f8d2629a | ||
|
|
c0ca2249a5 | ||
|
|
efe903bc73 | ||
|
|
fd20e0725b | ||
|
|
6c8f094bbe | ||
|
|
50b76d59f7 | ||
|
|
4f76b42bb5 | ||
|
|
d593ab38ad | ||
|
|
a17f974357 | ||
|
|
40dee9958b | ||
|
|
575bdda768 | ||
|
|
9b116929ad | ||
|
|
2e8fa61a5a | ||
|
|
cd93eb9098 | ||
|
|
4c765d86ee | ||
|
|
fa8aaced55 | ||
|
|
1b02ab5f7f | ||
|
|
0e609cc528 | ||
|
|
5ec4c74b0b | ||
|
|
4d7006950a | ||
|
|
e49a69895a | ||
|
|
27f2b9c219 | ||
|
|
db820fbb0f | ||
|
|
ad4e9c74e0 | ||
|
|
4797446f7c | ||
|
|
0ffcde4fbb | ||
|
|
f555e1143f | ||
|
|
bc3fd4542b | ||
|
|
d3fac14586 | ||
|
|
d0425a140a | ||
|
|
64ec0c317e | ||
|
|
5f694f82af | ||
|
|
590122f25a | ||
|
|
9b670b9ea7 | ||
|
|
65e836cba1 | ||
|
|
c634f61f2a | ||
|
|
776e78c459 | ||
|
|
a03235851c | ||
|
|
d2f843f92c | ||
|
|
e9c69673ad | ||
|
|
a453afa29a | ||
|
|
cee669c276 | ||
|
|
2e0c1b0086 | ||
|
|
7686c86792 | ||
|
|
2e0f0211d1 | ||
|
|
4f8d745305 | ||
|
|
9788c6849e | ||
|
|
48dfbac37a | ||
|
|
e4eccce811 | ||
|
|
097c2fea42 | ||
|
|
5a5b171a68 | ||
|
|
343d6866c4 | ||
|
|
2ad144c739 | ||
|
|
983ad61d78 | ||
|
|
27e87143e1 | ||
|
|
d0b802e09b | ||
|
|
8c67631efb | ||
|
|
18df114b70 | ||
|
|
c51bf739cf | ||
|
|
43a0a7db4f | ||
|
|
bbcfe7edf4 | ||
|
|
a11578a863 | ||
|
|
b546304d5d | ||
|
|
d7774c0dc0 | ||
|
|
bd80144c7b | ||
|
|
315cbaab1b | ||
|
|
af37928283 | ||
|
|
6a3df43017 | ||
|
|
c747ffc35b | ||
|
|
7bfbe83d87 | ||
|
|
a871569867 | ||
|
|
65b071eb86 | ||
|
|
0e99d4fa80 | ||
|
|
8f00c3c274 | ||
|
|
4fad53007f | ||
|
|
e7435964a2 | ||
|
|
8ea15468b4 | ||
|
|
9025bef687 | ||
|
|
ffc44bb089 | ||
|
|
6c968489eb | ||
|
|
2fc1b66a79 | ||
|
|
bd99d0451d | ||
|
|
d62e47cd2e | ||
|
|
ab23fedd0c | ||
|
|
43a603c1cc | ||
|
|
9b5b541c82 | ||
|
|
119bac527f | ||
|
|
e9bc6a2915 | ||
|
|
2979338f8a | ||
|
|
830f633a6e | ||
|
|
0d51d12e43 | ||
|
|
2d47989616 | ||
|
|
f259b5e825 | ||
|
|
3800b33c1a | ||
|
|
dfe0eff095 | ||
|
|
8cdec40a03 | ||
|
|
6169234300 | ||
|
|
3ff2d82ecf | ||
|
|
3ef4c09f71 | ||
|
|
79bd7ac090 | ||
|
|
6e648f14f4 | ||
|
|
c3d8254324 | ||
|
|
15095640eb | ||
|
|
6070419761 | ||
|
|
db2f48ad09 | ||
|
|
cfe5206252 | ||
|
|
975f679148 | ||
|
|
b571a3d58d | ||
|
|
5090d4b3a0 | ||
|
|
799b00211d | ||
|
|
afe8afc41f | ||
|
|
090e7c0ecb | ||
|
|
e557b78394 | ||
|
|
c53f961690 | ||
|
|
9e6b51fac9 | ||
|
|
a6f98158a7 | ||
|
|
ca040bdf9a | ||
|
|
f95cf6454d | ||
|
|
827c6adc03 | ||
|
|
59d9ece06b | ||
|
|
1dd1b09e5f | ||
|
|
58296ecaf7 | ||
|
|
3b0674320f | ||
|
|
a8b2b4f962 | ||
|
|
6fc32b6800 | ||
|
|
1e20d43c2a | ||
|
|
52814bcbd0 | ||
|
|
74fccaaab5 | ||
|
|
6813a06455 | ||
|
|
e423cfee35 | ||
|
|
7316a00e9c | ||
|
|
54299d766a | ||
|
|
f2a7b4b349 | ||
|
|
150718ad6f | ||
|
|
0904ec151c | ||
|
|
dff6e0832c | ||
|
|
e983c03232 | ||
|
|
d1c54608f7 | ||
|
|
24b6c88935 | ||
|
|
6397e56c06 | ||
|
|
9785111857 | ||
|
|
522ffb08f0 | ||
|
|
22129e3ec7 | ||
|
|
4431864770 | ||
|
|
23a57f7876 | ||
|
|
05b75aa44c | ||
|
|
e35a1ca231 | ||
|
|
1cc6c2b9ca | ||
|
|
8c092c7453 | ||
|
|
6631fce15f | ||
|
|
7071142aad | ||
|
|
34586bca5a | ||
|
|
516638a6d7 | ||
|
|
d4c39a2ad9 | ||
|
|
d6288c175e | ||
|
|
08b785083a | ||
|
|
a7818f0f64 | ||
|
|
52642aa11a | ||
|
|
27c886f6b9 | ||
|
|
85eb5a7496 | ||
|
|
91c242ac04 | ||
|
|
8ff6c147f2 | ||
|
|
8b4bb5a078 | ||
|
|
9d260f9b0e | ||
|
|
59cd48f3de | ||
|
|
b11db20742 | ||
|
|
f186aa6896 | ||
|
|
2bedf000a8 | ||
|
|
3d6f4544f1 | ||
|
|
13deac9b58 | ||
|
|
21c60ef7ce | ||
|
|
83adbb2979 | ||
|
|
c614b679e1 | ||
|
|
10bcc69c80 | ||
|
|
9eb4368d6f | ||
|
|
783fd4b475 | ||
|
|
00efab8ad2 | ||
|
|
d73b3745bf | ||
|
|
ccd44c0cb2 | ||
|
|
9a0acca849 | ||
|
|
95f9658a7e | ||
|
|
0fa24ce313 | ||
|
|
28ad466aa8 | ||
|
|
7e9fc0f20b | ||
|
|
7f5689835b | ||
|
|
478e0a53d0 | ||
|
|
588cad8d91 | ||
|
|
1d3ab8d6bb | ||
|
|
e086aa1660 | ||
|
|
188a15a948 | ||
|
|
874660f52e | ||
|
|
29bd46d68d | ||
|
|
cb80e0ef51 | ||
|
|
ccef53a3d3 | ||
|
|
d201803259 | ||
|
|
74b206dc77 | ||
|
|
42cda2d2e0 | ||
|
|
c386b704b5 | ||
|
|
84be00b29f | ||
|
|
d064b589ae | ||
|
|
90edd12e43 | ||
|
|
c71bf3ccbe | ||
|
|
724b4de07e | ||
|
|
444b0a928d | ||
|
|
ec8fcbc02f | ||
|
|
68e2cd67d1 | ||
|
|
c21e1aba35 | ||
|
|
ec7f38d157 | ||
|
|
5b38483981 | ||
|
|
46312a2d15 | ||
|
|
8a240f7c46 | ||
|
|
17ca061cda | ||
|
|
4da902b46c | ||
|
|
7b39268171 | ||
|
|
0343569cdc | ||
|
|
32a804e2ea | ||
|
|
7ce078eb16 | ||
|
|
f9dda21088 | ||
|
|
00c5ae4a42 | ||
|
|
d73d8333a1 | ||
|
|
9c720fd6b7 | ||
|
|
7228235ce3 | ||
|
|
5684a1477e | ||
|
|
347dd73269 | ||
|
|
a14850458d | ||
|
|
e249e3cfb6 | ||
|
|
d1c0978ee5 | ||
|
|
e3226d3511 | ||
|
|
ae7c416f16 | ||
|
|
1456fa0f75 | ||
|
|
d6acd07d5c | ||
|
|
d8149e9eb0 | ||
|
|
d6557e21a0 | ||
|
|
3bccef8d22 | ||
|
|
a27e8316fe | ||
|
|
b419948c8d | ||
|
|
211555639d | ||
|
|
46125abdeb | ||
|
|
69e4e7cc49 | ||
|
|
fe9dedb9ad | ||
|
|
47e6a96800 | ||
|
|
f42fb51952 | ||
|
|
1aea1b699a | ||
|
|
e769ba58cc | ||
|
|
f815eec2c0 | ||
|
|
de9be8b481 | ||
|
|
7454b8f2f6 | ||
|
|
b4c7dbe478 | ||
|
|
e14727dcc3 | ||
|
|
ac4e4e405b | ||
|
|
898216ac9f | ||
|
|
c42e3a3f47 | ||
|
|
cec9166956 | ||
|
|
675c66ff9d | ||
|
|
962a110b16 | ||
|
|
405410b8c8 | ||
|
|
32e014af06 | ||
|
|
0af86bbb9d | ||
|
|
a31dc3a102 | ||
|
|
7b212ea7fd | ||
|
|
b3f3944495 | ||
|
|
58a05e2ee7 | ||
|
|
3146ffb8e1 | ||
|
|
b815ce9db4 | ||
|
|
b14aa16a23 | ||
|
|
4397d85727 | ||
|
|
98832c4914 | ||
|
|
720269b118 | ||
|
|
c9bd13213b | ||
|
|
5fdddaeede | ||
|
|
8570539aab | ||
|
|
f4c6738793 | ||
|
|
e018ee98d3 | ||
|
|
95aabd561b | ||
|
|
a1b295c2c9 | ||
|
|
bc7aff3f11 | ||
|
|
dc249c1ec5 | ||
|
|
660228fb0e | ||
|
|
57c1f3e067 | ||
|
|
6ed9ae4bb9 | ||
|
|
752f754bb2 | ||
|
|
44a547341d | ||
|
|
c3f2c693a2 | ||
|
|
918217f6d2 | ||
|
|
bbdc432a20 | ||
|
|
5ba9562b17 | ||
|
|
fabfdcd178 | ||
|
|
33fac1c5af | ||
|
|
d60b87d98e | ||
|
|
c7881dec35 | ||
|
|
df0178e2de | ||
|
|
aaa60d261d | ||
|
|
88ab4b6f52 | ||
|
|
f9d3dbfa61 | ||
|
|
41d05dd922 | ||
|
|
82c2448321 | ||
|
|
a67b546a02 | ||
|
|
842d318277 | ||
|
|
251706d646 | ||
|
|
cbaa635a89 | ||
|
|
0a4bc6576a | ||
|
|
9a266ca52e | ||
|
|
4b6fc55056 | ||
|
|
c9bdb6ef04 | ||
|
|
bc52c0141a | ||
|
|
b2145b6838 | ||
|
|
74337fb65a | ||
|
|
4ffb7ea64a | ||
|
|
3d7e8c6c95 | ||
|
|
50de4d78e5 | ||
|
|
14358a8c37 | ||
|
|
9afa5febc2 | ||
|
|
70e09246ee | ||
|
|
4e8e3b9774 | ||
|
|
32129634ee |
No files matched your search
@@ -1,4 +0,0 @@
|
||||
*.pbxuser
|
||||
.DS_Store
|
||||
*.perspective*
|
||||
.svn
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
# Xcode
|
||||
build/*
|
||||
*.pbxuser
|
||||
!default.pbxuser
|
||||
*.mode1v3
|
||||
!default.mode1v3
|
||||
*.mode2v3
|
||||
!default.mode2v3
|
||||
*.perspectivev3
|
||||
!default.perspectivev3
|
||||
*.xcworkspace
|
||||
!default.xcworkspace
|
||||
xcuserdata/
|
||||
profile
|
||||
*.moved-aside
|
||||
|
||||
## Ignore incredibly annoying .DS_Store files
|
||||
.DS_Store
|
||||
DerivedData/
|
||||
@@ -0,0 +1,4 @@
|
||||
// BinaryDelta tool only
|
||||
|
||||
PRODUCT_NAME = BinaryDelta
|
||||
GCC_PREFIX_HEADER =
|
||||
@@ -0,0 +1,4 @@
|
||||
#include "ConfigCommon.xcconfig"
|
||||
#include "ConfigCommonDebug.xcconfig"
|
||||
#include "ConfigBinaryDelta.xcconfig"
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
#include "ConfigCommon.xcconfig"
|
||||
#include "ConfigCommonRelease.xcconfig"
|
||||
#include "ConfigBinaryDelta.xcconfig"
|
||||
@@ -1,38 +1,29 @@
|
||||
// Common
|
||||
|
||||
PREBINDING = NO
|
||||
ZERO_LINK = NO
|
||||
CURRENT_PROJECT_VERSION = 1.5
|
||||
SDKROOT = $(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk
|
||||
MACOSX_DEPLOYMENT_TARGET[arch=ppc] = 10.3
|
||||
MACOSX_DEPLOYMENT_TARGET[arch=ppc64] = 10.5
|
||||
MACOSX_DEPLOYMENT_TARGET[arch=i386] = 10.4
|
||||
MACOSX_DEPLOYMENT_TARGET[arch=x86_64] = 10.5
|
||||
GCC_C_LANGUAGE_STANDARD = c99
|
||||
GCC_ENABLE_OBJC_EXCEPTIONS = YES
|
||||
FINISH_INSTALL_TOOL_NAME = Autoupdate
|
||||
|
||||
CURRENT_PROJECT_VERSION = 1.6
|
||||
GCC_PRECOMPILE_PREFIX_HEADER = YES
|
||||
GCC_PREFIX_HEADER = $(SDKROOT)/System/Library/Frameworks/Cocoa.framework/Headers/Cocoa.h
|
||||
GCC_FAST_OBJC_DISPATCH = YES
|
||||
GCC_FAST_OBJC_DISPATCH[arch=ppc] = NO // requires 10.4
|
||||
ARCHS = i386 x86_64
|
||||
|
||||
GCC_PREPROCESSOR_DEFINITIONS = FINISH_INSTALL_TOOL_NAME=$(FINISH_INSTALL_TOOL_NAME)
|
||||
|
||||
// Enable warnings
|
||||
GCC_WARN_CHECK_SWITCH_STATEMENTS = YES
|
||||
GCC_WARN_EFFECTIVE_CPLUSPLUS_VIOLATIONS = YES
|
||||
GCC_WARN_FOUR_CHARACTER_CONSTANTS = YES
|
||||
GCC_WARN_SHADOW = YES
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES
|
||||
GCC_WARN_ALLOW_INCOMPLETE_PROTOCOL = YES
|
||||
GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES
|
||||
GCC_WARN_MISSING_PARENTHESES = YES
|
||||
GCC_WARN_ABOUT_MISSING_NEWLINE = YES
|
||||
GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES
|
||||
GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES
|
||||
GCC_WARN_ABOUT_POINTER_SIGNEDNESS = YES
|
||||
GCC_WARN_SIGN_COMPARE = YES
|
||||
GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES
|
||||
GCC_WARN_UNKNOWN_PRAGMAS = YES
|
||||
GCC_WARN_UNUSED_VARIABLE = YES
|
||||
GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS = YES
|
||||
GCC_WARN_ABOUT_INVALID_OFFSETOF_MACRO = YES
|
||||
WARNING_CFLAGS = -Wall
|
||||
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES
|
||||
GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES
|
||||
GCC_WARN_UNUSED_FUNCTION = YES
|
||||
GCC_WARN_UNUSED_LABEL = YES
|
||||
GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES
|
||||
GCC_WARN_UNDECLARED_SELECTOR = YES
|
||||
@@ -3,6 +3,6 @@
|
||||
GCC_OPTIMIZATION_LEVEL = 0
|
||||
DEBUG_INFORMATION_FORMAT = dwarf
|
||||
GCC_GENERATE_DEBUGGING_SYMBOLS = YES
|
||||
SPARKLE_EXTRA_DEBUG = -DDEBUG -fstack-protector -D_FORTIFY_SOURCE=2
|
||||
SPARKLE_EXTRA_DEBUG = -DDEBUG
|
||||
OTHER_CFLAGS = $(SPARKLE_EXTRA_DEBUG)
|
||||
ARCHS = $(NATIVE_ARCH_ACTUAL)
|
||||
|
||||
@@ -4,6 +4,5 @@ GCC_OPTIMIZATION_LEVEL = s
|
||||
DEBUG_INFORMATION_FORMAT = dwarf-with-dsym
|
||||
GCC_GENERATE_DEBUGGING_SYMBOLS = NO
|
||||
DEAD_CODE_STRIPPING = YES
|
||||
GCC_TREAT_WARNINGS_AS_ERRORS = YES
|
||||
GCC_TREAT_WARNINGS_AS_ERRORS = NO
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES
|
||||
ARCHS = ppc i386 x86_64
|
||||
@@ -1,10 +1,10 @@
|
||||
// Framework only
|
||||
|
||||
INSTALL_PATH = @executable_path/../Frameworks
|
||||
INSTALL_PATH = @loader_path/../Frameworks
|
||||
DYLIB_COMPATIBILITY_VERSION = 1.5
|
||||
DYLIB_CURRENT_VERSION = 1.5
|
||||
PRODUCT_NAME = Sparkle
|
||||
WRAPPER_EXTENSION = framework
|
||||
OTHER_LDFLAGS = -lcrypto
|
||||
FRAMEWORK_VERSION = A
|
||||
INFOPLIST_FILE = Info.plist
|
||||
GCC_PREFIX_HEADER = Sparkle.pch
|
||||
@@ -2,4 +2,3 @@
|
||||
#include "ConfigCommonDebug.xcconfig"
|
||||
#include "ConfigFramework.xcconfig"
|
||||
|
||||
OTHER_CFLAGS = -fsingle-precision-constant -DDEBUG
|
||||
@@ -1,3 +1,6 @@
|
||||
#include "ConfigCommon.xcconfig"
|
||||
#include "ConfigCommonRelease.xcconfig"
|
||||
#include "ConfigFramework.xcconfig"
|
||||
|
||||
STRIP_INSTALLED_PRODUCT = YES
|
||||
DEPLOYMENT_POSTPROCESSING = YES
|
||||
@@ -1,3 +0,0 @@
|
||||
#include "ConfigFrameworkRelease.xcconfig"
|
||||
|
||||
GCC_ENABLE_OBJC_GC = supported
|
||||
@@ -1,3 +1,4 @@
|
||||
// Relaunch Tool only
|
||||
|
||||
PRODUCT_NAME = relaunch
|
||||
PRODUCT_NAME = $(FINISH_INSTALL_TOOL_NAME)
|
||||
SKIP_INSTALL = YES
|
||||
@@ -1,5 +1,3 @@
|
||||
#include "ConfigCommon.xcconfig"
|
||||
#include "ConfigCommonDebug.xcconfig"
|
||||
#include "ConfigRelaunch.xcconfig"
|
||||
|
||||
OTHER_CFLAGS = -fsingle-precision-constant -DDEBUG
|
||||
@@ -2,4 +2,3 @@
|
||||
#include "ConfigCommonDebug.xcconfig"
|
||||
#include "ConfigTestApp.xcconfig"
|
||||
|
||||
OTHER_CFLAGS = -fsingle-precision-constant -DDEBUG
|
||||
@@ -0,0 +1,9 @@
|
||||
// Unit Test only
|
||||
|
||||
INFOPLIST_FILE = Tests/Sparkle Unit Tests-Info.plist
|
||||
OTHER_LDFLAGS = -framework Cocoa -framework SenTestingKit
|
||||
PRODUCT_NAME = Sparkle Unit Tests
|
||||
WRAPPER_EXTENSION = octest
|
||||
FRAMEWORK_SEARCH_PATHS = $(DEVELOPER_LIBRARY_DIR)/Frameworks
|
||||
GCC_PREFIX_HEADER = $(SYSTEM_LIBRARY_DIR)/Frameworks/Cocoa.framework/Headers/Cocoa.h
|
||||
GCC_PRECOMPILE_PREFIX_HEADER = YES
|
||||
@@ -0,0 +1,3 @@
|
||||
#include "ConfigCommon.xcconfig"
|
||||
#include "ConfigCommonDebug.xcconfig"
|
||||
#include "ConfigUnitTest.xcconfig"
|
||||
@@ -0,0 +1,3 @@
|
||||
#include "ConfigCommon.xcconfig"
|
||||
#include "ConfigCommonRelease.xcconfig"
|
||||
#include "ConfigUnitTest.xcconfig"
|
||||
+5
-5
@@ -6,22 +6,22 @@
|
||||
<string>en</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>${EXECUTABLE_NAME}</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>${PRODUCT_NAME}</string>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string></string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>org.andymatuschak.Sparkle</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>${PRODUCT_NAME}</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>${CURRENT_PROJECT_VERSION} git</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.5</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.5 Beta (bzr)</string>
|
||||
<string>${CURRENT_PROJECT_VERSION}</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string></string>
|
||||
</dict>
|
||||
|
||||
+32
-1
@@ -4,4 +4,35 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
=================
|
||||
EXTERNAL LICENSES
|
||||
=================
|
||||
|
||||
License for bspatch.c and bsdiff.c, from bsdiff 4.3 (<http://www.daemonology.net/bsdiff/>:
|
||||
/*-
|
||||
* Copyright 2003-2005 Colin Percival
|
||||
* All rights reserved
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted providing that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
@@ -1,59 +0,0 @@
|
||||
//
|
||||
// NSBundle+SUAdditions.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 12/21/07.
|
||||
// Copyright 2007 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef NSBUNDLE_PLUS_ADDITIONS_H
|
||||
#define NSBUNDLE_PLUS_ADDITIONS_H
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@interface NSBundle (SUAdditions)
|
||||
/*!
|
||||
@method
|
||||
@abstract Returns a name for the bundle suitable for display to the user.
|
||||
@discussion This is performed by asking NSFileManager for the display name of the bundle.
|
||||
*/
|
||||
- (NSString *)name;
|
||||
|
||||
/*!
|
||||
@method
|
||||
@abstract Returns the current internal version of the bundle.
|
||||
@discussion This uses the CFBundleVersion info value. This string is not appropriate for display to users: use -displayVersion instead.
|
||||
*/
|
||||
- (NSString *)version;
|
||||
|
||||
/*!
|
||||
@method
|
||||
@abstract Returns the bundle's version, suitable for display to the user.
|
||||
@discussion If the CFBundleShortVersionString is available and different from the CFBundleVersion, this looks like CFBundleShortVersionString (CFBundleVersion). If the version strings are the same or CFBundleShortVersionString is not defined, this is equivalent to -version.
|
||||
*/
|
||||
- (NSString *)displayVersion;
|
||||
|
||||
/*!
|
||||
@method
|
||||
@abstract Returns a suitable icon for this bundle.
|
||||
@discussion Uses the CFBundleIconFile icon if defined; otherwise, uses the default application icon.
|
||||
*/
|
||||
- (NSImage *)icon;
|
||||
|
||||
/*!
|
||||
@method
|
||||
@abstract Returns whether the application is running from a disk image.
|
||||
*/
|
||||
- (BOOL)isRunningFromDiskImage;
|
||||
|
||||
/*!
|
||||
@method
|
||||
@abstract Returns a profile of the users system useful for statistical purposes.
|
||||
@discussion Returns an array of dictionaries; each dictionary represents a piece of data and has keys "key", "visibleKey", "value", and "visibleValue".
|
||||
*/
|
||||
- (NSArray *)systemProfile;
|
||||
|
||||
- (NSString *)publicDSAKey;
|
||||
@end
|
||||
|
||||
#endif
|
||||
@@ -1,89 +0,0 @@
|
||||
//
|
||||
// NSBundle+SUAdditions.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 12/21/07.
|
||||
// Copyright 2007 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#import "Sparkle.h"
|
||||
#import "NSBundle+SUAdditions.h"
|
||||
|
||||
#ifndef NSAppKitVersionNumber10_4
|
||||
#define NSAppKitVersionNumber10_4 824
|
||||
#endif
|
||||
|
||||
@implementation NSBundle (SUAdditions)
|
||||
|
||||
- (NSString *)name
|
||||
{
|
||||
NSString *name = [self objectForInfoDictionaryKey:@"CFBundleDisplayName"];
|
||||
if (name) return name;
|
||||
|
||||
name = [self objectForInfoDictionaryKey:@"CFBundleName"];
|
||||
if (name) return name;
|
||||
|
||||
return [[[NSFileManager defaultManager] displayNameAtPath:[self bundlePath]] stringByDeletingPathExtension];
|
||||
}
|
||||
|
||||
- (NSString *)version
|
||||
{
|
||||
return [self objectForInfoDictionaryKey:@"CFBundleVersion"];
|
||||
}
|
||||
|
||||
- (NSString *)displayVersion
|
||||
{
|
||||
NSString *shortVersionString = [self objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
|
||||
if (shortVersionString)
|
||||
return shortVersionString;
|
||||
else
|
||||
return [self version]; // Fall back on the normal version string.
|
||||
}
|
||||
|
||||
- (NSImage *)icon
|
||||
{
|
||||
// Cache the application icon.
|
||||
NSString *iconPath = [self pathForResource:[self objectForInfoDictionaryKey:@"CFBundleIconFile"] ofType:@"icns"];
|
||||
// According to the OS X docs, "CFBundleIconFile - This key identifies the file containing
|
||||
// the icon for the bundle. The filename you specify does not need to include the .icns
|
||||
// extension, although it may."
|
||||
//
|
||||
// However, if it *does* include the '.icns' the above method fails (tested on OS X 10.3.9) so we'll also try:
|
||||
if (!iconPath)
|
||||
iconPath = [self pathForResource:[self objectForInfoDictionaryKey:@"CFBundleIconFile"] ofType: nil];
|
||||
NSImage *icon = [[[NSImage alloc] initWithContentsOfFile:iconPath] autorelease];
|
||||
// Use a default icon if none is defined.
|
||||
if (!icon) { [[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kGenericApplicationIcon)]; }
|
||||
return icon;
|
||||
}
|
||||
|
||||
- (BOOL)isRunningFromDiskImage
|
||||
{
|
||||
// This check causes crashes on 10.3; for now, we'll just skip it.
|
||||
if (floor(NSAppKitVersionNumber) < NSAppKitVersionNumber10_4)
|
||||
return NO;
|
||||
|
||||
NSDictionary *pathProperties = [[NSWorkspace sharedWorkspace] propertiesForPath:[self bundlePath]];
|
||||
BOOL isDiskImage = [pathProperties objectForKey:NSWorkspace_RBimagefilepath] != nil;
|
||||
BOOL isFileVault = [[pathProperties objectForKey:NSWorkspace_RBmntonname] hasPrefix:@"/Users/"];
|
||||
return isDiskImage && !isFileVault;
|
||||
}
|
||||
|
||||
- (NSString *)publicDSAKey
|
||||
{
|
||||
// Maybe the key is just a string in the Info.plist.
|
||||
NSString *key = [self objectForInfoDictionaryKey:SUPublicDSAKeyKey];
|
||||
if (key) { return key; }
|
||||
|
||||
// More likely, we've got a reference to a Resources file by filename:
|
||||
NSString *keyFilename = [self objectForInfoDictionaryKey:SUPublicDSAKeyFileKey];
|
||||
if (!keyFilename) { return nil; }
|
||||
return [NSString stringWithContentsOfFile:[self pathForResource:keyFilename ofType:nil]];
|
||||
}
|
||||
|
||||
- (NSArray *)systemProfile
|
||||
{
|
||||
return [[SUSystemProfiler sharedSystemProfiler] systemProfileArrayForHostBundle:self];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,18 +0,0 @@
|
||||
//
|
||||
// NSFileManager+Aliases.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 2/4/08.
|
||||
// Copyright 2008 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef NSFILEMANAGER_PLUS_ALIASES_H
|
||||
#define NSFILEMANAGER_PLUS_ALIASES_H
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@interface NSFileManager (SUAliases)
|
||||
- (BOOL)isAliasFolderAtPath:(NSString *)path;
|
||||
@end
|
||||
|
||||
#endif
|
||||
@@ -1,33 +0,0 @@
|
||||
//
|
||||
// NSFileManager+Aliases.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 2/4/08.
|
||||
// Copyright 2008 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#import "NSFileManager+Aliases.h"
|
||||
|
||||
|
||||
@implementation NSFileManager (SUAliases)
|
||||
|
||||
- (BOOL)isAliasFolderAtPath:(NSString *)path
|
||||
{
|
||||
FSRef fileRef;
|
||||
OSStatus err = noErr;
|
||||
Boolean aliasFileFlag, folderFlag;
|
||||
NSURL *fileURL = [NSURL fileURLWithPath:path];
|
||||
|
||||
if (FALSE == CFURLGetFSRef((CFURLRef)fileURL, &fileRef))
|
||||
err = coreFoundationUnknownErr;
|
||||
|
||||
if (noErr == err)
|
||||
err = FSIsAliasFile(&fileRef, &aliasFileFlag, &folderFlag);
|
||||
|
||||
if (noErr == err)
|
||||
return (BOOL)(aliasFileFlag && folderFlag);
|
||||
else
|
||||
return NO;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,16 +0,0 @@
|
||||
//
|
||||
// NSFileManager+Authentication.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 3/9/06.
|
||||
// Copyright 2006 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef NSFILEMANAGER_PLUS_AUTHENTICATION_H
|
||||
#define NSFILEMANAGER_PLUS_AUTHENTICATION_H
|
||||
|
||||
@interface NSFileManager (SUAuthenticationAdditions)
|
||||
- (BOOL)copyPathWithAuthentication:(NSString *)src overPath:(NSString *)dst error:(NSError **)error;
|
||||
@end
|
||||
|
||||
#endif
|
||||
@@ -1,249 +0,0 @@
|
||||
//
|
||||
// NSFileManager+Authentication.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 3/9/06.
|
||||
// Copyright 2006 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
// This code based on generous contribution from Allan Odgaard. Thanks, Allan!
|
||||
|
||||
#import "Sparkle.h"
|
||||
#import "NSFileManager+Authentication.h"
|
||||
|
||||
#import <Security/Security.h>
|
||||
#import <sys/stat.h>
|
||||
#import <sys/wait.h>
|
||||
#import <dirent.h>
|
||||
#import <unistd.h>
|
||||
|
||||
#import "NSFileManager+ExtendedAttributes.h"
|
||||
static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authorization, const char* executablePath, AuthorizationFlags options, const char* const* arguments)
|
||||
{
|
||||
sig_t oldSigChildHandler = signal(SIGCHLD, SIG_DFL);
|
||||
BOOL returnValue = YES;
|
||||
|
||||
if (AuthorizationExecuteWithPrivileges(authorization, executablePath, options, (char* const*)arguments, NULL) == errAuthorizationSuccess)
|
||||
{
|
||||
int status;
|
||||
pid_t pid = wait(&status);
|
||||
if (pid == -1 || !WIFEXITED(status) || WEXITSTATUS(status) != 0)
|
||||
returnValue = NO;
|
||||
}
|
||||
else
|
||||
returnValue = NO;
|
||||
|
||||
signal(SIGCHLD, oldSigChildHandler);
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
@implementation NSFileManager (SUAuthenticationAdditions)
|
||||
|
||||
- (BOOL)currentUserOwnsPath:(NSString *)oPath
|
||||
{
|
||||
const char *path = [oPath fileSystemRepresentation];
|
||||
uid_t uid = getuid();
|
||||
bool res = false;
|
||||
struct stat sb;
|
||||
if(stat(path, &sb) == 0)
|
||||
{
|
||||
if(sb.st_uid == uid)
|
||||
{
|
||||
res = true;
|
||||
if(sb.st_mode & S_IFDIR)
|
||||
{
|
||||
DIR* dir = opendir(path);
|
||||
struct dirent* entry = NULL;
|
||||
while(res && (entry = readdir(dir)))
|
||||
{
|
||||
if(strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
|
||||
continue;
|
||||
|
||||
size_t len = strlen(path) + 1 + entry->d_namlen + 1;
|
||||
char descend[len];
|
||||
strlcpy(descend, path, len);
|
||||
strlcat(descend, "/", len);
|
||||
strlcat(descend, entry->d_name, len);
|
||||
NSString* newPath = [[NSFileManager defaultManager] stringWithFileSystemRepresentation:descend length:strlen(descend)];
|
||||
res = [self currentUserOwnsPath:newPath];
|
||||
}
|
||||
closedir(dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
- (NSString *)_temporaryCopyNameForPath:(NSString *)path
|
||||
{
|
||||
// Let's try to read the version number so the filename will be more meaningful.
|
||||
NSString *postFix;
|
||||
NSBundle *bundle;
|
||||
if ((bundle = [NSBundle bundleWithPath:path]))
|
||||
{
|
||||
// We'll clean it up a little for safety.
|
||||
// The cast is necessary because of a bug in the headers in pre-10.5 SDKs
|
||||
NSMutableCharacterSet *validCharacters = (id)[NSMutableCharacterSet alphanumericCharacterSet];
|
||||
[validCharacters formUnionWithCharacterSet:[NSCharacterSet characterSetWithCharactersInString:@".-()"]];
|
||||
postFix = [[bundle objectForInfoDictionaryKey:@"CFBundleVersion"] stringByTrimmingCharactersInSet:[validCharacters invertedSet]];
|
||||
}
|
||||
else
|
||||
postFix = @"old";
|
||||
NSString *prefix = [[path stringByDeletingPathExtension] stringByAppendingFormat:@" (%@)", postFix];
|
||||
NSString *tempDir = [prefix stringByAppendingPathExtension:[path pathExtension]];
|
||||
// Now let's make sure we get a unique path.
|
||||
int cnt=2;
|
||||
while ([[NSFileManager defaultManager] fileExistsAtPath:tempDir] && cnt <= 999999)
|
||||
tempDir = [NSString stringWithFormat:@"%@ %d.%@", prefix, cnt++, [path pathExtension]];
|
||||
return tempDir;
|
||||
}
|
||||
|
||||
- (BOOL)_copyPathWithForcedAuthentication:(NSString *)src toPath:(NSString *)dst error:(NSError **)error
|
||||
{
|
||||
NSString *tmp = [self _temporaryCopyNameForPath:dst];
|
||||
const char* srcPath = [src fileSystemRepresentation];
|
||||
const char* tmpPath = [tmp fileSystemRepresentation];
|
||||
const char* dstPath = [dst fileSystemRepresentation];
|
||||
|
||||
struct stat dstSB;
|
||||
stat(dstPath, &dstSB);
|
||||
|
||||
AuthorizationRef auth = NULL;
|
||||
OSStatus authStat = errAuthorizationDenied;
|
||||
while (authStat == errAuthorizationDenied) {
|
||||
authStat = AuthorizationCreate(NULL,
|
||||
kAuthorizationEmptyEnvironment,
|
||||
kAuthorizationFlagDefaults,
|
||||
&auth);
|
||||
}
|
||||
|
||||
BOOL res = NO;
|
||||
if (authStat == errAuthorizationSuccess) {
|
||||
res = YES;
|
||||
|
||||
char uidgid[42];
|
||||
snprintf(uidgid, sizeof(uidgid), "%d:%d",
|
||||
dstSB.st_uid, dstSB.st_gid);
|
||||
|
||||
const char* executables[] = {
|
||||
"/bin/rm",
|
||||
"/bin/mv",
|
||||
"/bin/mv",
|
||||
"/bin/rm",
|
||||
NULL, // pause here and do some housekeeping before
|
||||
// continuing
|
||||
"/usr/sbin/chown",
|
||||
NULL // stop here for real
|
||||
};
|
||||
|
||||
// 4 is the maximum number of arguments to any command,
|
||||
// including the NULL that signals the end of an argument
|
||||
// list.
|
||||
const char* const argumentLists[][4] = {
|
||||
{ "-rf", tmpPath, NULL }, // make room for the temporary file... this is kinda unsafe; should probably do something better.
|
||||
{ "-f", dstPath, tmpPath, NULL }, // mv
|
||||
{ "-f", srcPath, dstPath, NULL }, // mv
|
||||
{ "-rf", tmpPath, NULL }, // rm
|
||||
{ NULL }, // pause
|
||||
{ "-R", uidgid, dstPath, NULL }, // chown
|
||||
{ NULL } // stop
|
||||
};
|
||||
|
||||
// Process the commands up until the first NULL
|
||||
int commandIndex = 0;
|
||||
for (; executables[commandIndex] != NULL; ++commandIndex) {
|
||||
if (res)
|
||||
res = AuthorizationExecuteWithPrivilegesAndWait(auth, executables[commandIndex], kAuthorizationFlagDefaults, argumentLists[commandIndex]);
|
||||
}
|
||||
|
||||
// If the currently-running application is trusted, the new
|
||||
// version should be trusted as well. Remove it from the
|
||||
// quarantine to avoid a delay at launch, and to avoid
|
||||
// presenting the user with a confusing trust dialog.
|
||||
//
|
||||
// This needs to be done after the application is moved to its
|
||||
// new home with "mv" in case it's moved across filesystems: if
|
||||
// that happens, "mv" actually performs a copy and may result
|
||||
// in the application being quarantined. It also needs to be
|
||||
// done before "chown" changes ownership, because the ownership
|
||||
// change will almost certainly make it impossible to change
|
||||
// attributes to release the files from the quarantine.
|
||||
if (res) {
|
||||
[self releaseFromQuarantine:dst];
|
||||
}
|
||||
|
||||
// Now move past the NULL we found and continue executing
|
||||
// commands from the list.
|
||||
++commandIndex;
|
||||
|
||||
for (; executables[commandIndex] != NULL; ++commandIndex) {
|
||||
if (res)
|
||||
res = AuthorizationExecuteWithPrivilegesAndWait(auth, executables[commandIndex], kAuthorizationFlagDefaults, argumentLists[commandIndex]);
|
||||
}
|
||||
|
||||
AuthorizationFree(auth, 0);
|
||||
|
||||
if (!res)
|
||||
{
|
||||
// Something went wrong somewhere along the way, but we're not sure exactly where.
|
||||
NSString *errorMessage = [NSString stringWithFormat:@"Authenticated file copy from %@ to %@ failed.", src, dst];
|
||||
if (error != NULL)
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:[NSDictionary dictionaryWithObject:errorMessage forKey:NSLocalizedDescriptionKey]];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (error != NULL)
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:[NSDictionary dictionaryWithObject:@"Couldn't get permission to authenticate." forKey:NSLocalizedDescriptionKey]];
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
- (BOOL)copyPathWithAuthentication:(NSString *)src overPath:(NSString *)dst error:(NSError **)error
|
||||
{
|
||||
if (![[NSFileManager defaultManager] fileExistsAtPath:dst])
|
||||
{
|
||||
NSString *errorMessage = [NSString stringWithFormat:@"Couldn't copy %@ over %@ because there is no file at %@.", src, dst, dst];
|
||||
if (error != NULL)
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUFileCopyFailure userInfo:[NSDictionary dictionaryWithObject:errorMessage forKey:NSLocalizedDescriptionKey]];
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (![[NSFileManager defaultManager] isWritableFileAtPath:dst] || ![[NSFileManager defaultManager] isWritableFileAtPath:[dst stringByDeletingLastPathComponent]])
|
||||
return [self _copyPathWithForcedAuthentication:src toPath:dst error:error];
|
||||
|
||||
NSString *tmpPath = [self _temporaryCopyNameForPath:dst];
|
||||
|
||||
if (![[NSFileManager defaultManager] movePath:dst toPath:tmpPath handler:self])
|
||||
{
|
||||
if (error != NULL)
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUFileCopyFailure userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Couldn't move %@ to %@.", dst, tmpPath] forKey:NSLocalizedDescriptionKey]];
|
||||
return NO;
|
||||
}
|
||||
if (![[NSFileManager defaultManager] copyPath:src toPath:dst handler:self])
|
||||
{
|
||||
if (error != NULL)
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUFileCopyFailure userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Couldn't copy %@ to %@.", src, dst] forKey:NSLocalizedDescriptionKey]];
|
||||
return NO;
|
||||
}
|
||||
|
||||
// Trash the old copy of the app.
|
||||
NSInteger tag = 0;
|
||||
if (![[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation source:[tmpPath stringByDeletingLastPathComponent] destination:@"" files:[NSArray arrayWithObject:[tmpPath lastPathComponent]] tag:&tag])
|
||||
NSLog(@"Sparkle error: couldn't move %@ to the trash. This is often a sign of a permissions error.", tmpPath);
|
||||
|
||||
// If the currently-running application is trusted, the new
|
||||
// version should be trusted as well. Remove it from the
|
||||
// quarantine to avoid a delay at launch, and to avoid
|
||||
// presenting the user with a confusing trust dialog.
|
||||
//
|
||||
// This needs to be done after the application is moved to its
|
||||
// new home in case it's moved across filesystems: if that
|
||||
// happens, the move is actually a copy, and it may result
|
||||
// in the application being quarantined.
|
||||
[self releaseFromQuarantine:dst];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,53 +0,0 @@
|
||||
//
|
||||
// NSFileManager+ExtendedAttributes.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mark Mentovai on 2008-01-22.
|
||||
// Copyright 2008 Mark Mentovai. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef NSFILEMANAGER_PLUS_EXTENDEDATTRIBUTES
|
||||
#define NSFILEMANAGER_PLUS_EXTENDEDATTRIBUTES
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@interface NSFileManager (MMExtendedAttributes)
|
||||
|
||||
// Wraps the removexattr system call, allowing an AppKit-style NSString* to
|
||||
// be used for the pathname argument. Note that the order of the arguments
|
||||
// has changed from what removexattr accepts, so that code reads more
|
||||
// naturally.
|
||||
//
|
||||
// removexattr is only available on Mac OS X 10.4 ("Tiger") and later. If
|
||||
// built with an SDK that includes removexattr, this method will link against
|
||||
// removexattr directly. When using earlier SDKs, this method will dynamically
|
||||
// look up the removexattr symbol at runtime. If the symbol is not present,
|
||||
// as will be the case when running on 10.3, this method returns -1 and sets
|
||||
// errno to ENOSYS.
|
||||
- (int)removeXAttr:(const char*)name
|
||||
fromFile:(NSString*)file
|
||||
options:(int)options;
|
||||
|
||||
// Removes the directory tree rooted at |root| from the file quarantine.
|
||||
// The quarantine was introduced on Mac OS X 10.5 and is described at:
|
||||
//
|
||||
// http://developer.apple.com/releasenotes/Carbon/RN-LaunchServices/index.html
|
||||
//#apple_ref/doc/uid/TP40001369-DontLinkElementID_2
|
||||
//
|
||||
// If |root| is not a directory, then it alone is removed from the quarantine.
|
||||
// Symbolic links, including |root| if it is a symbolic link, will not be
|
||||
// traversed.
|
||||
//
|
||||
// Ordinarily, the quarantine is managed by calling LSSetItemAttribute
|
||||
// to set the kLSItemQuarantineProperties attribute to a dictionary specifying
|
||||
// the quarantine properties to be applied. However, it does not appear to be
|
||||
// possible to remove an item from the quarantine directly through any public
|
||||
// Launch Services calls. Instead, this method takes advantage of the fact
|
||||
// that the quarantine is implemented in part by setting an extended attribute,
|
||||
// "com.apple.quarantine", on affected files. Removing this attribute is
|
||||
// sufficient to remove files from the quarantine.
|
||||
- (void)releaseFromQuarantine:(NSString*)root;
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
@@ -1,98 +0,0 @@
|
||||
//
|
||||
// NSFileManager+ExtendedAttributes.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mark Mentovai on 2008-01-22.
|
||||
// Copyright 2008 Mark Mentovai. All rights reserved.
|
||||
//
|
||||
|
||||
#import "NSFileManager+ExtendedAttributes.h"
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
|
||||
// Extended attribute support was introduced in Mac OS X 10.4 ("Tiger").
|
||||
// If building with an earlier SDK, provide definitions needed to handle
|
||||
// extended attributes at runtime.
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 // SDK >= 10.4
|
||||
#include <sys/xattr.h>
|
||||
#else // SDK >= 10.4
|
||||
#define XATTR_NOFOLLOW 1
|
||||
#endif // SDK >= 10.4
|
||||
|
||||
@implementation NSFileManager (MMExtendedAttributes)
|
||||
|
||||
- (int)removeXAttr:(const char*)name
|
||||
fromFile:(NSString*)file
|
||||
options:(int)options
|
||||
{
|
||||
typedef int (*removexattr_type)(const char*, const char*, int);
|
||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 // SDK >= 10.4
|
||||
// Reference removexattr directly, it's in the SDK.
|
||||
static removexattr_type removexattr_func = removexattr;
|
||||
#else // SDK >= 10.4
|
||||
// removexattr isn't in this SDK, look it up at runtime.
|
||||
static removexattr_type removexattr_func = NULL;
|
||||
static BOOL didSymbolLookup = NO;
|
||||
if (!didSymbolLookup) {
|
||||
didSymbolLookup = YES;
|
||||
removexattr_func = dlsym(RTLD_NEXT, "removexattr");
|
||||
}
|
||||
#endif // SDK >= 10.4
|
||||
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_4 // DT < 10.4
|
||||
// Make sure that the symbol is present. This checks the deployment
|
||||
// target instead of the SDK so that it's able to catch dlsym failures
|
||||
// as well as the null symbol that would result from building with the
|
||||
// 10.4 SDK and a lower deployment target, and running on 10.3.
|
||||
if (!removexattr_func) {
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
#endif // DT < 10.4
|
||||
|
||||
const char* path = NULL;
|
||||
@try {
|
||||
path = [file fileSystemRepresentation];
|
||||
}
|
||||
@catch (id exception) {
|
||||
// -[NSString fileSystemRepresentation] throws an exception if it's
|
||||
// unable to convert the string to something suitable. Map that to
|
||||
// EDOM, "argument out of domain", which sort of conveys that there
|
||||
// was a conversion failure.
|
||||
errno = EDOM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return removexattr_func(path, name, options);
|
||||
}
|
||||
|
||||
- (void)releaseFromQuarantine:(NSString*)root
|
||||
{
|
||||
const char* quarantineAttribute = "com.apple.quarantine";
|
||||
const int removeXAttrOptions = XATTR_NOFOLLOW;
|
||||
|
||||
[self removeXAttr:quarantineAttribute
|
||||
fromFile:root
|
||||
options:removeXAttrOptions];
|
||||
|
||||
// Only recurse if it's actually a directory. Don't recurse into a
|
||||
// root-level symbolic link.
|
||||
NSDictionary* rootAttributes =
|
||||
[self fileAttributesAtPath:root traverseLink:NO];
|
||||
NSString* rootType = [rootAttributes objectForKey:NSFileType];
|
||||
|
||||
if (rootType == NSFileTypeDirectory) {
|
||||
// The NSDirectoryEnumerator will avoid recursing into any contained
|
||||
// symbolic links, so no further type checks are needed.
|
||||
NSDirectoryEnumerator* directoryEnumerator = [self enumeratorAtPath:root];
|
||||
NSString* file = nil;
|
||||
while ((file = [directoryEnumerator nextObject])) {
|
||||
[self removeXAttr:quarantineAttribute
|
||||
fromFile:[root stringByAppendingPathComponent:file]
|
||||
options:removeXAttrOptions];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,17 +0,0 @@
|
||||
//
|
||||
// NSFileManager+Verification.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 3/16/06.
|
||||
// Copyright 2006 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef NSFILEMANAGER_PLUS_VERIFICATION_H
|
||||
#define NSFILEMANAGER_PLUS_VERIFICATION_H
|
||||
|
||||
// For the paranoid folks!
|
||||
@interface NSFileManager (SUVerification)
|
||||
- (BOOL)validatePath:(NSString *)path withEncodedDSASignature:(NSString *)encodedSignature withPublicDSAKey:(NSString *)pkeyString;
|
||||
@end
|
||||
|
||||
#endif
|
||||
@@ -1,151 +0,0 @@
|
||||
//
|
||||
// NSFileManager+Verification.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 3/16/06.
|
||||
// Copyright 2006 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
// DSA stuff adapted from code provided by Allan Odgaard. Thanks, Allan!
|
||||
|
||||
#import "Sparkle.h"
|
||||
#import "NSFileManager+Verification.h"
|
||||
|
||||
#import <stdio.h>
|
||||
#import <openssl/evp.h>
|
||||
#import <openssl/bio.h>
|
||||
#import <openssl/pem.h>
|
||||
#import <openssl/rsa.h>
|
||||
#import <openssl/sha.h>
|
||||
|
||||
long b64decode(unsigned char* str)
|
||||
{
|
||||
unsigned char *cur, *start;
|
||||
int d, dlast, phase;
|
||||
unsigned char c;
|
||||
static int table[256] = {
|
||||
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 00-0F */
|
||||
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 10-1F */
|
||||
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63, /* 20-2F */
|
||||
52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-1,-1,-1, /* 30-3F */
|
||||
-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14, /* 40-4F */
|
||||
15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1, /* 50-5F */
|
||||
-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40, /* 60-6F */
|
||||
41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1, /* 70-7F */
|
||||
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 80-8F */
|
||||
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 90-9F */
|
||||
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* A0-AF */
|
||||
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* B0-BF */
|
||||
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* C0-CF */
|
||||
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* D0-DF */
|
||||
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* E0-EF */
|
||||
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 /* F0-FF */
|
||||
};
|
||||
|
||||
d = dlast = phase = 0;
|
||||
start = str;
|
||||
for (cur = str; *cur != '\0'; ++cur )
|
||||
{
|
||||
if(*cur == '\n' || *cur == '\r'){phase = dlast = 0; continue;}
|
||||
d = table[(int)*cur];
|
||||
if(d != -1)
|
||||
{
|
||||
switch(phase)
|
||||
{
|
||||
case 0:
|
||||
++phase;
|
||||
break;
|
||||
case 1:
|
||||
c = ((dlast << 2) | ((d & 0x30) >> 4));
|
||||
*str++ = c;
|
||||
++phase;
|
||||
break;
|
||||
case 2:
|
||||
c = (((dlast & 0xf) << 4) | ((d & 0x3c) >> 2));
|
||||
*str++ = c;
|
||||
++phase;
|
||||
break;
|
||||
case 3:
|
||||
c = (((dlast & 0x03 ) << 6) | d);
|
||||
*str++ = c;
|
||||
phase = 0;
|
||||
break;
|
||||
}
|
||||
dlast = d;
|
||||
}
|
||||
}
|
||||
*str = '\0';
|
||||
return str - start;
|
||||
}
|
||||
|
||||
EVP_PKEY* load_dsa_key(char *key)
|
||||
{
|
||||
EVP_PKEY* pkey = NULL;
|
||||
BIO *bio;
|
||||
if((bio = BIO_new_mem_buf(key, (int)strlen(key))))
|
||||
{
|
||||
DSA* dsa_key = 0;
|
||||
if(PEM_read_bio_DSA_PUBKEY(bio, &dsa_key, NULL, NULL))
|
||||
{
|
||||
if((pkey = EVP_PKEY_new()))
|
||||
{
|
||||
if(EVP_PKEY_assign_DSA(pkey, dsa_key) != 1)
|
||||
{
|
||||
DSA_free(dsa_key);
|
||||
EVP_PKEY_free(pkey);
|
||||
pkey = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
BIO_free(bio);
|
||||
}
|
||||
return pkey;
|
||||
}
|
||||
|
||||
@implementation NSFileManager (SUVerification)
|
||||
|
||||
- (BOOL)validatePath:(NSString *)path withEncodedDSASignature:(NSString *)encodedSignature withPublicDSAKey:(NSString *)pkeyString
|
||||
{
|
||||
BOOL result = NO;
|
||||
if (!encodedSignature) { return NO; }
|
||||
if (!pkeyString) { return NO; }
|
||||
|
||||
// Remove whitespace around each line of the key.
|
||||
NSMutableArray *pkeyTrimmedLines = [NSMutableArray array];
|
||||
NSEnumerator *pkeyLinesEnumerator = [[pkeyString componentsSeparatedByString:@"\n"] objectEnumerator];
|
||||
NSString *pkeyLine;
|
||||
while ((pkeyLine = [pkeyLinesEnumerator nextObject]) != nil)
|
||||
{
|
||||
[pkeyTrimmedLines addObject:[pkeyLine stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]];
|
||||
}
|
||||
pkeyString = [pkeyTrimmedLines componentsJoinedByString:@"\n"]; // Put them back together.
|
||||
|
||||
EVP_PKEY* pkey = NULL;
|
||||
pkey = load_dsa_key((char *)[pkeyString UTF8String]);
|
||||
if (!pkey) { return NO; }
|
||||
|
||||
// Now, the signature is in base64; we have to decode it into a binary stream.
|
||||
unsigned char *signature = (unsigned char *)[encodedSignature UTF8String];
|
||||
long length = b64decode(signature); // Decode the signature in-place and get the new length of the signature string.
|
||||
|
||||
// We've got the signature, now get the file data.
|
||||
NSData *pathData = [NSData dataWithContentsOfFile:path];
|
||||
if (!pathData) { return NO; }
|
||||
|
||||
// Hash the file with SHA-1.
|
||||
unsigned char md[SHA_DIGEST_LENGTH];
|
||||
SHA1([pathData bytes], [pathData length], md);
|
||||
|
||||
// Actually verify the signature on the file.
|
||||
EVP_MD_CTX ctx;
|
||||
if(EVP_VerifyInit(&ctx, EVP_dss1()) == 1) // We're using DSA keys.
|
||||
{
|
||||
EVP_VerifyUpdate(&ctx, md, SHA_DIGEST_LENGTH);
|
||||
result = (EVP_VerifyFinal(&ctx, signature, (unsigned int)length, pkey) == 1);
|
||||
}
|
||||
|
||||
EVP_PKEY_free(pkey);
|
||||
return result;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,16 +0,0 @@
|
||||
//
|
||||
// NSNumber+Units.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Jonas Witt on 5/18/08.
|
||||
// Copyright 2008 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
|
||||
@interface NSNumber (JWUnits)
|
||||
|
||||
+ (NSString *)humanReadableSizeFromDouble:(double)value;
|
||||
|
||||
@end
|
||||
@@ -1,28 +0,0 @@
|
||||
//
|
||||
// NSNumber+Units.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Jonas Witt on 5/18/08.
|
||||
// Copyright 2008 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import "NSNumber+Units.h"
|
||||
#import "Sparkle.h"
|
||||
|
||||
@implementation NSNumber (JWUnits)
|
||||
|
||||
+ (NSString *)humanReadableSizeFromDouble:(double)value
|
||||
{
|
||||
if (value < 1024)
|
||||
return [NSString stringWithFormat:@"%.0lf %@", value, SULocalizedString(@"B", @"the unit for bytes")];
|
||||
|
||||
if (value < 1024 * 1024)
|
||||
return [NSString stringWithFormat:@"%.0lf %@", value / 1024.0, SULocalizedString(@"KB", @"the unit for kilobytes")];
|
||||
|
||||
if (value < 1024 * 1024 * 1024)
|
||||
return [NSString stringWithFormat:@"%.1lf %@", value / 1024.0 / 1024.0, SULocalizedString(@"MB", @"the unit for megabytes")];
|
||||
|
||||
return [NSString stringWithFormat:@"%.2lf %@", value / 1024.0 / 1024.0 / 1024.0, SULocalizedString(@"GB", @"the unit for gigabytes")];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
|
||||
BSD License
|
||||
|
||||
Copyright (c) 2002, Brent Simmons
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of ranchero.com or Brent Simmons nor the names of its
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#ifndef NSSTRING_PLUS_EXTRAS_H
|
||||
#define NSSTRING_PLUS_EXTRAS_H
|
||||
|
||||
|
||||
/*
|
||||
NSString+extras.h
|
||||
NetNewsWire
|
||||
|
||||
Created by Brent Simmons on Fri Jun 14 2002.
|
||||
Copyright (c) 2002 Brent Simmons. All rights reserved.
|
||||
*/
|
||||
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <CoreFoundation/CoreFoundation.h>
|
||||
#import "SUConstants.h" // for NSInteger
|
||||
|
||||
@interface NSString (BSextras)
|
||||
|
||||
- (NSString *)stringWithSubstitute:(NSString *)subs forCharactersFromSet:(NSCharacterSet *)set;
|
||||
|
||||
- (NSString *) trimWhiteSpace;
|
||||
|
||||
- (NSString *) stripHTML;
|
||||
|
||||
- (NSString *) ellipsizeAfterNWords: (NSInteger) n;
|
||||
|
||||
+ (BOOL) stringIsEmpty: (NSString *) s;
|
||||
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
@@ -1,136 +0,0 @@
|
||||
/*
|
||||
|
||||
BSD License
|
||||
|
||||
Copyright (c) 2002, Brent Simmons
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of ranchero.com or Brent Simmons nor the names of its
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
NSString+extras.m
|
||||
NetNewsWire
|
||||
|
||||
Created by Brent Simmons on Fri Jun 14 2002.
|
||||
Copyright (c) 2002 Brent Simmons. All rights reserved.
|
||||
*/
|
||||
|
||||
#import "Sparkle.h"
|
||||
#import "NSString+extras.h"
|
||||
|
||||
|
||||
@implementation NSString (BSextras)
|
||||
|
||||
- (NSString *)stringWithSubstitute:(NSString *)subs forCharactersFromSet:(NSCharacterSet *)set
|
||||
{
|
||||
NSRange r = [self rangeOfCharacterFromSet:set];
|
||||
if (r.location == NSNotFound) return self;
|
||||
NSMutableString *newString = [self mutableCopy];
|
||||
do
|
||||
{
|
||||
[newString replaceCharactersInRange:r withString:subs];
|
||||
r = [newString rangeOfCharacterFromSet:set];
|
||||
}
|
||||
while (r.location != NSNotFound);
|
||||
return [newString autorelease];
|
||||
}
|
||||
|
||||
- (NSString *) trimWhiteSpace {
|
||||
|
||||
NSMutableString *s = [[self mutableCopy] autorelease];
|
||||
|
||||
CFStringTrimWhitespace ((CFMutableStringRef) s);
|
||||
|
||||
return (NSString *) [[s copy] autorelease];
|
||||
} /*trimWhiteSpace*/
|
||||
|
||||
|
||||
- (NSString *) ellipsizeAfterNWords: (NSInteger) n {
|
||||
|
||||
NSArray *stringComponents = [self componentsSeparatedByString: @" "];
|
||||
NSMutableArray *componentsCopy = [stringComponents mutableCopy];
|
||||
NSInteger ix = n;
|
||||
NSInteger len = [componentsCopy count];
|
||||
|
||||
if (len < n)
|
||||
ix = len;
|
||||
|
||||
[componentsCopy removeObjectsInRange: NSMakeRange (ix, len - ix)];
|
||||
|
||||
return [componentsCopy componentsJoinedByString: @" "];
|
||||
} /*ellipsizeAfterNWords*/
|
||||
|
||||
|
||||
- (NSString *) stripHTML {
|
||||
|
||||
NSUInteger len = [self length];
|
||||
NSMutableString *s = [NSMutableString stringWithCapacity: len];
|
||||
NSUInteger i = 0, level = 0;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
|
||||
NSString *ch = [self substringWithRange: NSMakeRange (i, 1)];
|
||||
|
||||
if ([ch isEqualTo: @"<"])
|
||||
level++;
|
||||
|
||||
else if ([ch isEqualTo: @">"]) {
|
||||
|
||||
level--;
|
||||
|
||||
if (level == 0)
|
||||
[s appendString: @" "];
|
||||
} /*else if*/
|
||||
|
||||
else if (level == 0)
|
||||
[s appendString: ch];
|
||||
} /*for*/
|
||||
|
||||
return (NSString *) [[s copy] autorelease];
|
||||
} /*stripHTML*/
|
||||
|
||||
|
||||
+ (BOOL) stringIsEmpty: (NSString *) s {
|
||||
|
||||
NSString *copy;
|
||||
|
||||
if (s == nil)
|
||||
return (YES);
|
||||
|
||||
if ([s isEqualTo: @""])
|
||||
return (YES);
|
||||
|
||||
copy = [[s copy] autorelease];
|
||||
|
||||
if ([[copy trimWhiteSpace] isEqualTo: @""])
|
||||
return (YES);
|
||||
|
||||
return (NO);
|
||||
} /*stringIsEmpty*/
|
||||
|
||||
@end
|
||||
@@ -1,18 +0,0 @@
|
||||
//
|
||||
// NSURL+Parameters.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 5/6/08.
|
||||
// Copyright 2008 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef NSURL_PLUS_PARAMETERS_H
|
||||
#define NSURL_PLUS_PARAMETERS_H
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@interface NSURL (SUParameterAdditions)
|
||||
- (NSURL *)URLWithParameters:(NSArray *)parameters;
|
||||
@end
|
||||
|
||||
#endif
|
||||
@@ -1,27 +0,0 @@
|
||||
//
|
||||
// NSURL+Parameters.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 5/6/08.
|
||||
// Copyright 2008 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#import "NSURL+Parameters.h"
|
||||
|
||||
@implementation NSURL (SUParameterAdditions)
|
||||
- (NSURL *)URLWithParameters:(NSArray *)parameters;
|
||||
{
|
||||
if (parameters == nil || [parameters count] == 0) { return self; }
|
||||
NSMutableArray *profileInfo = [NSMutableArray array];
|
||||
NSEnumerator *profileInfoEnumerator = [parameters objectEnumerator];
|
||||
NSDictionary *currentProfileInfo;
|
||||
while ((currentProfileInfo = [profileInfoEnumerator nextObject])) {
|
||||
[profileInfo addObject:[NSString stringWithFormat:@"%@=%@", [currentProfileInfo objectForKey:@"key"], [currentProfileInfo objectForKey:@"value"]]];
|
||||
}
|
||||
|
||||
NSString *appcastStringWithProfile = [NSString stringWithFormat:@"%@?%@", [self absoluteString], [profileInfo componentsJoinedByString:@"&"]];
|
||||
|
||||
// Clean it up so it's a valid URL
|
||||
return [NSURL URLWithString:[appcastStringWithProfile stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
|
||||
}
|
||||
@end
|
||||
@@ -1,18 +0,0 @@
|
||||
//
|
||||
// NSWorkspace+SystemVersion.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 5/7/08.
|
||||
// Copyright 2008 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef NSWORKSPACE_PLUS_SYSTEMVERSION_H
|
||||
#define NSWORKSPACE_PLUS_SYSTEMVERSION_H
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@interface NSWorkspace (SUSystemVersion)
|
||||
+ (NSString *)systemVersionString;
|
||||
@end
|
||||
|
||||
#endif
|
||||
@@ -1,36 +0,0 @@
|
||||
//
|
||||
// NSWorkspace+SystemVersion.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 5/7/08.
|
||||
// Copyright 2008 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#import "NSWorkspace+SystemVersion.h"
|
||||
|
||||
|
||||
@implementation NSWorkspace (SUSystemVersion)
|
||||
+ (NSString *)systemVersionString
|
||||
{
|
||||
// This returns a version string of the form X.Y.Z
|
||||
// There may be a better way to deal with the problem that gestaltSystemVersionMajor
|
||||
// et al. are not defined in 10.3, but this is probably good enough.
|
||||
NSString* verStr = nil;
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4
|
||||
SInt32 major, minor, bugfix;
|
||||
OSErr err1 = Gestalt(gestaltSystemVersionMajor, &major);
|
||||
OSErr err2 = Gestalt(gestaltSystemVersionMinor, &minor);
|
||||
OSErr err3 = Gestalt(gestaltSystemVersionBugFix, &bugfix);
|
||||
if (!err1 && !err2 && !err3)
|
||||
{
|
||||
verStr = [NSString stringWithFormat:@"%d.%d.%d", major, minor, bugfix];
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
NSString *versionPlistPath = @"/System/Library/CoreServices/SystemVersion.plist";
|
||||
verStr = [[[NSDictionary dictionaryWithContentsOfFile:versionPlistPath] objectForKey:@"ProductVersion"] retain];
|
||||
}
|
||||
return verStr;
|
||||
}
|
||||
@end
|
||||
@@ -1,41 +0,0 @@
|
||||
//
|
||||
// NSWorkspace_RBAdditions.h
|
||||
// PathProps
|
||||
//
|
||||
// Created by Rainer Brockerhoff on 10/04/2007.
|
||||
// Copyright 2007 Rainer Brockerhoff. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef NSWORKSPACE_RBADDITIONS_H
|
||||
#define NSWORKSPACE_RBADDITIONS_H
|
||||
|
||||
|
||||
extern NSString* NSWorkspace_RBfstypename;
|
||||
extern NSString* NSWorkspace_RBmntonname;
|
||||
extern NSString* NSWorkspace_RBmntfromname;
|
||||
extern NSString* NSWorkspace_RBdeviceinfo;
|
||||
extern NSString* NSWorkspace_RBimagefilepath;
|
||||
extern NSString* NSWorkspace_RBconnectiontype;
|
||||
extern NSString* NSWorkspace_RBpartitionscheme;
|
||||
extern NSString* NSWorkspace_RBserverURL;
|
||||
|
||||
@interface NSWorkspace (NSWorkspace_RBAdditions)
|
||||
|
||||
// This method will return nil if the input path is invalid. Otherwise, the returned NSDictionary may contain
|
||||
// the following keys:
|
||||
//- NSWorkspace_RBfstypename: will always be present.Shows the filesystem type (usually "hfs"), from statfs.
|
||||
//- NSWorkspace_RBmntonname: will always be present. Shows the volume mount point.
|
||||
//- NSWorkspace_RBmntfromname: will always be present. Shows the BSD device path for local volumes; info for
|
||||
// remote volumes depends on the filesystem type.
|
||||
//- NSWorkspace_RBconnectiontype: should always be present for local volumes. Shows the connection type ("SATA", "USB", etc.).
|
||||
//- NSWorkspace_RBpartitionscheme: should always be present for local volumes. Shows the partition scheme.
|
||||
//- NSWorkspace_RBdeviceinfo: should always be present for local volumes. Shows some information about the
|
||||
// physical device; varies widely.
|
||||
//- NSWorkspace_RBimagefilepath: should be present for disk images only. Shows the path of the disk image file.
|
||||
//- NSWorkspace_RBserverURL: should be present for remote volumes only. Shows the server URL.
|
||||
|
||||
- (NSDictionary*)propertiesForPath:(NSString*)path;
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
@@ -1,177 +0,0 @@
|
||||
//
|
||||
// NSWorkspace_RBAdditions.m
|
||||
// PathProps
|
||||
//
|
||||
// Created by Rainer Brockerhoff on 10/04/2007.
|
||||
// Copyright 2007 Rainer Brockerhoff. All rights reserved.
|
||||
//
|
||||
|
||||
#import "Sparkle.h"
|
||||
#import "NSWorkspace_RBAdditions.h"
|
||||
|
||||
#include <IOKit/IOKitLib.h>
|
||||
#include <sys/mount.h>
|
||||
#include <mach/mach.h>
|
||||
|
||||
NSString* NSWorkspace_RBfstypename = @"NSWorkspace_RBfstypename";
|
||||
NSString* NSWorkspace_RBmntonname = @"NSWorkspace_RBmntonname";
|
||||
NSString* NSWorkspace_RBmntfromname = @"NSWorkspace_RBmntfromname";
|
||||
NSString* NSWorkspace_RBdeviceinfo = @"NSWorkspace_RBdeviceinfo";
|
||||
NSString* NSWorkspace_RBimagefilepath = @"NSWorkspace_RBimagefilepath";
|
||||
NSString* NSWorkspace_RBconnectiontype = @"NSWorkspace_RBconnectiontype";
|
||||
NSString* NSWorkspace_RBpartitionscheme = @"NSWorkspace_RBpartitionscheme";
|
||||
NSString* NSWorkspace_RBserverURL = @"NSWorkspace_RBserverURL";
|
||||
|
||||
// This static funtion concatenates two strings, but first checks several possibilities...
|
||||
// like one or the other nil, or one containing the other already.
|
||||
|
||||
static NSString* AddPart(NSString* first,NSString* second) {
|
||||
if (!second) {
|
||||
return first;
|
||||
}
|
||||
second = [second stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
|
||||
if (first) {
|
||||
if ([first rangeOfString:second options:NSCaseInsensitiveSearch].location==NSNotFound) {
|
||||
if ([second rangeOfString:first options:NSCaseInsensitiveSearch].location==NSNotFound) {
|
||||
return [NSString stringWithFormat:@"%@; %@",first,second];
|
||||
}
|
||||
return second;
|
||||
}
|
||||
return first;
|
||||
}
|
||||
return second;
|
||||
}
|
||||
|
||||
// This static functions recurses "upwards" over the IO registry. Returns strings that are concatenated
|
||||
// and ultimately end up under the NSWorkspace_RBdeviceinfo key.
|
||||
// This isn't too robust in that it assumes that objects returned by the objectForKey methods are
|
||||
// either strings or dictionaries. A "standard" implementations would use either only CoreFoundation and
|
||||
// IOKit calls for this, or do more robust type checking on the returned objects.
|
||||
//
|
||||
// Also notice that this works as determined experimentally in 10.4.9, there's no official docs I could find.
|
||||
// YMMV, and it may stop working in any new version of Mac OS X.
|
||||
|
||||
static NSString* CheckParents(io_object_t thing,NSString* part,NSMutableDictionary* dict) {
|
||||
NSString* result = part;
|
||||
io_iterator_t parentsIterator = 0;
|
||||
kern_return_t kernResult = IORegistryEntryGetParentIterator(thing,kIOServicePlane,&parentsIterator);
|
||||
if ((kernResult==KERN_SUCCESS)&&parentsIterator) {
|
||||
io_object_t nextParent = 0;
|
||||
while ((nextParent = IOIteratorNext(parentsIterator))) {
|
||||
NSDictionary* props = nil;
|
||||
NSString* image = nil;
|
||||
NSString* partition = nil;
|
||||
NSString* connection = nil;
|
||||
kernResult = IORegistryEntryCreateCFProperties(nextParent,(CFMutableDictionaryRef*)&props,kCFAllocatorDefault,0);
|
||||
if (IOObjectConformsTo(nextParent,"IOApplePartitionScheme")) {
|
||||
partition = [props objectForKey:@"Content Mask"];
|
||||
} else if (IOObjectConformsTo(nextParent,"IOMedia")) {
|
||||
partition = [props objectForKey:@"Content"];
|
||||
} else if (IOObjectConformsTo(nextParent,"IODiskImageBlockStorageDeviceOutKernel")) {
|
||||
NSData* data = nil;
|
||||
if ((data = [[props objectForKey:@"Protocol Characteristics"] objectForKey:@"Virtual Interface Location Path"])) {
|
||||
image = [[[NSString alloc] initWithBytes:[data bytes] length:[data length] encoding:NSUTF8StringEncoding] autorelease];
|
||||
}
|
||||
} else if (IOObjectConformsTo(nextParent,"IOHDIXHDDriveInKernel")) {
|
||||
image = [props objectForKey:@"KDIURLPath"];
|
||||
}
|
||||
NSDictionary* subdict;
|
||||
if ((subdict = [props objectForKey:@"Protocol Characteristics"])) {
|
||||
connection = [subdict objectForKey:@"Physical Interconnect"];
|
||||
} else {
|
||||
connection = [props objectForKey:@"Physical Interconnect"];
|
||||
}
|
||||
if (connection) {
|
||||
[dict setObject:AddPart([dict objectForKey:NSWorkspace_RBconnectiontype],connection) forKey:NSWorkspace_RBconnectiontype];
|
||||
}
|
||||
if (partition) {
|
||||
[dict setObject:partition forKey:NSWorkspace_RBpartitionscheme];
|
||||
}
|
||||
if (image) {
|
||||
[dict setObject:image forKey:NSWorkspace_RBimagefilepath];
|
||||
}
|
||||
NSString* value;
|
||||
if ((subdict = [props objectForKey:@"Device Characteristics"])) {
|
||||
if ((value = [subdict objectForKey:@"Product Name"])) {
|
||||
result = AddPart(result,value);
|
||||
}
|
||||
if ((value = [subdict objectForKey:@"Product Revision Level"])) {
|
||||
result = AddPart(result,value);
|
||||
}
|
||||
if ((value = [subdict objectForKey:@"Vendor Name"])) {
|
||||
result = AddPart(result,value);
|
||||
}
|
||||
}
|
||||
if ((value = [props objectForKey:@"USB Serial Number"])) {
|
||||
result = AddPart(result,value);
|
||||
}
|
||||
if ((value = [props objectForKey:@"USB Vendor Name"])) {
|
||||
result = AddPart(result,value);
|
||||
}
|
||||
io_name_t ts; // char[128]
|
||||
NSString* cls = ( IOObjectGetClass (nextParent, ts) == KERN_SUCCESS ) ? [NSString stringWithUTF8String:ts ] : nil;
|
||||
if (![cls isEqualToString:@"IOPCIDevice"]) {
|
||||
|
||||
// Uncomment the following line to have the device tree dumped to the console.
|
||||
// NSLog(@"=================================> %@:%@\n",cls,props);
|
||||
|
||||
result = CheckParents(nextParent,result,dict);
|
||||
}
|
||||
if (props) { CFRelease(props); }
|
||||
IOObjectRelease(nextParent);
|
||||
}
|
||||
}
|
||||
if (parentsIterator) {
|
||||
IOObjectRelease(parentsIterator);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@implementation NSWorkspace (NSWorkspace_RBAdditions)
|
||||
|
||||
// Returns a NSDictionary with properties for the path. See details in the .h file.
|
||||
// This assumes that the length of path is less than PATH_MAX (currently 1024 characters).
|
||||
|
||||
- (NSDictionary*)propertiesForPath:(NSString*)path {
|
||||
const char* ccpath = [path fileSystemRepresentation];
|
||||
NSMutableDictionary* result = nil;
|
||||
struct statfs fs = {};
|
||||
if (!statfs(ccpath,&fs)) {
|
||||
NSString* from = [[NSFileManager defaultManager] stringWithFileSystemRepresentation:fs.f_mntfromname length:strlen(fs.f_mntfromname)];
|
||||
result = [NSMutableDictionary dictionaryWithObjectsAndKeys:[NSString stringWithUTF8String:fs.f_fstypename], NSWorkspace_RBfstypename, [[NSFileManager defaultManager] stringWithFileSystemRepresentation:fs.f_mntonname length:strlen(fs.f_mntonname)], NSWorkspace_RBmntonname, nil];
|
||||
const char* devstring = "/dev/";
|
||||
size_t devstringlen = 5;
|
||||
if (strncmp(fs.f_mntfromname,devstring,devstringlen)==0) {
|
||||
// For a local volume,get the IO registry tree and search it for further info.
|
||||
mach_port_t masterPort = 0;
|
||||
io_iterator_t mediaIterator = 0;
|
||||
kern_return_t kernResult = IOMasterPort(bootstrap_port,&masterPort);
|
||||
if (kernResult==KERN_SUCCESS) {
|
||||
CFMutableDictionaryRef classesToMatch = IOBSDNameMatching(masterPort,0,&fs.f_mntfromname[devstringlen]);
|
||||
if (classesToMatch) {
|
||||
kernResult = IOServiceGetMatchingServices(masterPort,classesToMatch,&mediaIterator);
|
||||
if ((kernResult==KERN_SUCCESS)&&mediaIterator) {
|
||||
io_object_t firstMedia = 0;
|
||||
while ((firstMedia = IOIteratorNext(mediaIterator))) {
|
||||
NSString* stuff = CheckParents(firstMedia,nil,result);
|
||||
if (stuff) {
|
||||
[result setObject:stuff forKey:NSWorkspace_RBdeviceinfo];
|
||||
}
|
||||
IOObjectRelease(firstMedia);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (mediaIterator) {
|
||||
IOObjectRelease(mediaIterator);
|
||||
}
|
||||
if (masterPort) {
|
||||
mach_port_deallocate(mach_task_self(),masterPort);
|
||||
}
|
||||
}
|
||||
[result setObject:from forKey:NSWorkspace_RBmntfromname];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@end
|
||||
+8
-1
@@ -11,6 +11,7 @@
|
||||
|
||||
@interface NTSynchronousTask : NSObject
|
||||
{
|
||||
@private
|
||||
NSTask *mv_task;
|
||||
NSPipe *mv_outputPipe;
|
||||
NSPipe *mv_inputPipe;
|
||||
@@ -19,10 +20,16 @@
|
||||
BOOL mv_done;
|
||||
int mv_result;
|
||||
}
|
||||
@property (readonly, retain) NSData *output;
|
||||
@property (readonly) int result;
|
||||
|
||||
// pass nil for directory if not needed
|
||||
// returns the result
|
||||
+ (NSData*)task:(NSString*)toolPath directory:(NSString*)currentDirectory withArgs:(NSArray*)args input:(NSData*)input;
|
||||
+(int) task:(NSString*)toolPath directory:(NSString*)currentDirectory withArgs:(NSArray*)args input:(NSData*)input output: (NSData**)outData;
|
||||
|
||||
+(NSData*)task:(NSString*)toolPath directory:(NSString*)currentDirectory withArgs:(NSArray*)args input:(NSData*)input;
|
||||
|
||||
- (void)run:(NSString*)toolPath directory:(NSString*)currentDirectory withArgs:(NSArray*)args input:(NSData*)input;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
+105
-176
@@ -6,44 +6,54 @@
|
||||
// Copyright 2005 Steve Gehrman. All rights reserved.
|
||||
//
|
||||
|
||||
#import "Sparkle.h"
|
||||
#import "SUUpdater.h"
|
||||
|
||||
#import "SUAppcast.h"
|
||||
#import "SUAppcastItem.h"
|
||||
#import "SUVersionComparisonProtocol.h"
|
||||
#import "NTSynchronousTask.h"
|
||||
|
||||
@interface NTSynchronousTask (Private)
|
||||
- (void)run:(NSString*)toolPath directory:(NSString*)currentDirectory withArgs:(NSArray*)args input:(NSData*)input;
|
||||
|
||||
- (NSTask *)task;
|
||||
- (void)setTask:(NSTask *)theTask;
|
||||
|
||||
- (NSPipe *)outputPipe;
|
||||
- (void)setOutputPipe:(NSPipe *)theOutputPipe;
|
||||
|
||||
- (NSPipe *)inputPipe;
|
||||
- (void)setInputPipe:(NSPipe *)theInputPipe;
|
||||
|
||||
- (NSData *)output;
|
||||
- (void)setOutput:(NSData *)theOutput;
|
||||
|
||||
- (BOOL)done;
|
||||
- (void)setDone:(BOOL)flag;
|
||||
|
||||
- (int)result;
|
||||
- (void)setResult:(int)theResult;
|
||||
@interface NTSynchronousTask ()
|
||||
@property (retain) NSTask *task;
|
||||
@property (retain) NSPipe *outputPipe;
|
||||
@property (retain) NSPipe *inputPipe;
|
||||
@property (readwrite, retain) NSData *output;
|
||||
@property (getter = isDone) BOOL done;
|
||||
@property (readwrite) int result;
|
||||
@end
|
||||
|
||||
@implementation NTSynchronousTask
|
||||
@synthesize output = mv_output;
|
||||
@synthesize result = mv_result;
|
||||
@synthesize task = mv_task;
|
||||
@synthesize outputPipe = mv_outputPipe;
|
||||
@synthesize inputPipe = mv_inputPipe;
|
||||
@synthesize done = mv_done;
|
||||
|
||||
- (void)taskOutputAvailable:(NSNotification*)note
|
||||
{
|
||||
self.output = [[note userInfo] objectForKey:NSFileHandleNotificationDataItem];
|
||||
|
||||
self.done = YES;
|
||||
}
|
||||
|
||||
- (void)taskDidTerminate:(NSNotification*)note
|
||||
{
|
||||
self.result = [self.task terminationStatus];
|
||||
}
|
||||
|
||||
- (id)init;
|
||||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
{
|
||||
[self setTask:[[[NSTask alloc] init] autorelease]];
|
||||
[self setOutputPipe:[[[NSPipe alloc] init] autorelease]];
|
||||
[self setInputPipe:[[[NSPipe alloc] init] autorelease]];
|
||||
self.task = [[[NSTask alloc] init] autorelease];
|
||||
self.outputPipe = [[[NSPipe alloc] init] autorelease];
|
||||
self.inputPipe = [[[NSPipe alloc] init] autorelease];
|
||||
|
||||
[[self task] setStandardInput:[self inputPipe]];
|
||||
[[self task] setStandardOutput:[self outputPipe]];
|
||||
self.task.standardInput = self.inputPipe;
|
||||
self.task.standardOutput = self.outputPipe;
|
||||
self.task.standardError = self.outputPipe;
|
||||
}
|
||||
|
||||
return self;
|
||||
@@ -56,55 +66,23 @@
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
|
||||
[self setTask:nil];
|
||||
[self setOutputPipe:nil];
|
||||
[self setInputPipe:nil];
|
||||
[self setOutput:nil];
|
||||
self.task = nil;
|
||||
self.outputPipe = nil;
|
||||
self.inputPipe = nil;
|
||||
self.output = nil;
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
+ (NSData*)task:(NSString*)toolPath directory:(NSString*)currentDirectory withArgs:(NSArray*)args input:(NSData*)input;
|
||||
{
|
||||
// we need this wacky pool here, otherwise we run out of pipes, the pipes are internally autoreleased
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
NSData* result=nil;
|
||||
|
||||
NS_DURING
|
||||
{
|
||||
NTSynchronousTask* task = [[NTSynchronousTask alloc] init];
|
||||
|
||||
[task run:toolPath directory:currentDirectory withArgs:args input:input];
|
||||
|
||||
if ([task result] == 0)
|
||||
result = [[task output] retain];
|
||||
|
||||
[task release];
|
||||
}
|
||||
NS_HANDLER;
|
||||
NS_ENDHANDLER;
|
||||
|
||||
[pool drain];
|
||||
|
||||
// retained above
|
||||
[result autorelease];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation NTSynchronousTask (Private)
|
||||
|
||||
- (void)run:(NSString*)toolPath directory:(NSString*)currentDirectory withArgs:(NSArray*)args input:(NSData*)input;
|
||||
- (void)run:(NSString*)toolPath directory:(NSString*)currentDirectory withArgs:(NSArray*)args input:(NSData*)input
|
||||
{
|
||||
BOOL success = NO;
|
||||
|
||||
if (currentDirectory)
|
||||
[[self task] setCurrentDirectoryPath: currentDirectory];
|
||||
self.task.currentDirectoryPath = currentDirectory;
|
||||
|
||||
[[self task] setLaunchPath:toolPath];
|
||||
[[self task] setArguments:args];
|
||||
self.task.launchPath = toolPath;
|
||||
self.task.arguments = args;
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(taskOutputAvailable:)
|
||||
@@ -118,24 +96,24 @@
|
||||
|
||||
[[[self outputPipe] fileHandleForReading] readToEndOfFileInBackgroundAndNotifyForModes:[NSArray arrayWithObjects:NSDefaultRunLoopMode, NSModalPanelRunLoopMode, NSEventTrackingRunLoopMode, nil]];
|
||||
|
||||
NS_DURING
|
||||
[[self task] launch];
|
||||
@try
|
||||
{
|
||||
[self.task launch];
|
||||
success = YES;
|
||||
NS_HANDLER
|
||||
;
|
||||
NS_ENDHANDLER
|
||||
}
|
||||
@catch (NSException *localException) { }
|
||||
|
||||
if (success)
|
||||
{
|
||||
if (input)
|
||||
{
|
||||
// feed the running task our input
|
||||
[[[self inputPipe] fileHandleForWriting] writeData:input];
|
||||
[[[self inputPipe] fileHandleForWriting] closeFile];
|
||||
[[self.inputPipe fileHandleForWriting] writeData:input];
|
||||
[[self.inputPipe fileHandleForWriting] closeFile];
|
||||
}
|
||||
|
||||
// loop until we are done receiving the data
|
||||
if (![self done])
|
||||
if (!self.done)
|
||||
{
|
||||
double resolution = 1;
|
||||
BOOL isRunning;
|
||||
@@ -146,117 +124,68 @@
|
||||
|
||||
isRunning = [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
|
||||
beforeDate:next];
|
||||
} while (isRunning && ![self done]);
|
||||
} while (isRunning && !self.done);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------
|
||||
// task
|
||||
//----------------------------------------------------------
|
||||
- (NSTask *)task
|
||||
+ (NSData*)task:(NSString*)toolPath directory:(NSString*)currentDirectory withArgs:(NSArray*)args input:(NSData*)input
|
||||
{
|
||||
return mv_task;
|
||||
}
|
||||
|
||||
- (void)setTask:(NSTask *)theTask
|
||||
{
|
||||
if (mv_task != theTask) {
|
||||
[mv_task release];
|
||||
mv_task = [theTask retain];
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------
|
||||
// outputPipe
|
||||
//----------------------------------------------------------
|
||||
- (NSPipe *)outputPipe
|
||||
{
|
||||
return mv_outputPipe;
|
||||
}
|
||||
|
||||
- (void)setOutputPipe:(NSPipe *)theOutputPipe
|
||||
{
|
||||
if (mv_outputPipe != theOutputPipe) {
|
||||
[mv_outputPipe release];
|
||||
mv_outputPipe = [theOutputPipe retain];
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------
|
||||
// inputPipe
|
||||
//----------------------------------------------------------
|
||||
- (NSPipe *)inputPipe
|
||||
{
|
||||
return mv_inputPipe;
|
||||
}
|
||||
|
||||
- (void)setInputPipe:(NSPipe *)theInputPipe
|
||||
{
|
||||
if (mv_inputPipe != theInputPipe) {
|
||||
[mv_inputPipe release];
|
||||
mv_inputPipe = [theInputPipe retain];
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------
|
||||
// output
|
||||
//----------------------------------------------------------
|
||||
- (NSData *)output
|
||||
{
|
||||
return mv_output;
|
||||
}
|
||||
|
||||
- (void)setOutput:(NSData *)theOutput
|
||||
{
|
||||
if (mv_output != theOutput) {
|
||||
[mv_output release];
|
||||
mv_output = [theOutput retain];
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------
|
||||
// done
|
||||
//----------------------------------------------------------
|
||||
- (BOOL)done
|
||||
{
|
||||
return mv_done;
|
||||
}
|
||||
|
||||
- (void)setDone:(BOOL)flag
|
||||
{
|
||||
mv_done = flag;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------
|
||||
// result
|
||||
//----------------------------------------------------------
|
||||
- (int)result
|
||||
{
|
||||
return mv_result;
|
||||
}
|
||||
|
||||
- (void)setResult:(int)theResult
|
||||
{
|
||||
mv_result = theResult;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation NTSynchronousTask (Notifications)
|
||||
|
||||
- (void)taskOutputAvailable:(NSNotification*)note
|
||||
{
|
||||
[self setOutput:[[note userInfo] objectForKey:NSFileHandleNotificationDataItem]];
|
||||
// we need this wacky pool here, otherwise we run out of pipes, the pipes are internally autoreleased
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
NSData* result = nil;
|
||||
|
||||
[self setDone:YES];
|
||||
@try
|
||||
{
|
||||
NTSynchronousTask* task = [[NTSynchronousTask alloc] init];
|
||||
|
||||
[task run:toolPath directory:currentDirectory withArgs:args input:input];
|
||||
|
||||
if ([task result] == 0)
|
||||
result = [[task output] retain];
|
||||
|
||||
[task release];
|
||||
}
|
||||
@catch (NSException *localException) { }
|
||||
|
||||
[pool drain];
|
||||
|
||||
// retained above
|
||||
[result autorelease];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
- (void)taskDidTerminate:(NSNotification*)note
|
||||
|
||||
+(int) task:(NSString*)toolPath directory:(NSString*)currentDirectory withArgs:(NSArray*)args input:(NSData*)input output: (NSData**)outData
|
||||
{
|
||||
[self setResult:[[self task] terminationStatus]];
|
||||
// we need this wacky pool here, otherwise we run out of pipes, the pipes are internally autoreleased
|
||||
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
||||
int taskResult = 0;
|
||||
if( outData )
|
||||
*outData = nil;
|
||||
|
||||
@try {
|
||||
NTSynchronousTask* task = [[NTSynchronousTask alloc] init];
|
||||
|
||||
[task run:toolPath directory:currentDirectory withArgs:args input:input];
|
||||
|
||||
taskResult = [task result];
|
||||
if( outData )
|
||||
*outData = [[task output] retain];
|
||||
|
||||
[task release];
|
||||
} @catch (NSException *localException) {
|
||||
taskResult = errCppGeneral;
|
||||
}
|
||||
|
||||
[pool drain];
|
||||
|
||||
// retained above
|
||||
if( outData )
|
||||
[*outData autorelease];
|
||||
|
||||
return taskResult;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
# Sparkle <img src="Sparkle.png" width=48 height=48 alt="">
|
||||
is an easy-to-use software update framework for Cocoa developers.
|
||||
|
||||
## This fork
|
||||
|
||||
* Up to date with 10.9 SDK and Xcode 5.1.
|
||||
* Merged bugfixes, security fixes and some features from multiple Sparkle forks.
|
||||
* Merged official Sparkle branch with truly automatic background updates (no UI at all) when user agreed to "Automatically download and install updates in the future."
|
||||
* Ability to mark updates as critical.
|
||||
* Progress and status notifications for the host app.
|
||||
* Name of finish_installation.app can be configured to match your app's name.
|
||||
|
||||
## Features
|
||||
|
||||
* True self-updating—no work required from the user.
|
||||
* Displays release notes to the user via WebKit.
|
||||
* Displays a detailed progress window to the user.
|
||||
* Supports authentication for installing in secure locations.
|
||||
* Really, really easy to install.
|
||||
* Uses appcasts for release information.
|
||||
* The user can choose to automatically download and install all updates.
|
||||
* Seamless integration—there's no mention of Sparkle; your icons and app name are used.
|
||||
* Supports DSA signatures for ultra-secure updates.
|
||||
* Sparkle requires no code in your app, so it's trivial to upgrade or remove the module.
|
||||
* Optionally sends user demographic information to the server when checking for updates.
|
||||
* Sparkle doesn't bug the user until second launch for better first impressions.
|
||||
* Sparkle can install .pkg files for more complicated products.
|
||||
* Supports bundles, preference panes, plugins, and other non-.app software.
|
||||
* Supports branches due to minimum OS version requirements.
|
||||
* Deep delegate support to make Sparkle work exactly as you need.
|
||||
@@ -1,77 +0,0 @@
|
||||
/*
|
||||
|
||||
BSD License
|
||||
|
||||
Copyright (c) 2002, Brent Simmons
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of ranchero.com or Brent Simmons nor the names of its
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#ifndef RSS_H
|
||||
#define RSS_H
|
||||
|
||||
|
||||
/*
|
||||
RSS.h
|
||||
A class for reading RSS feeds.
|
||||
|
||||
Created by Brent Simmons on Wed Apr 17 2002.
|
||||
Copyright (c) 2002 Brent Simmons. All rights reserved.
|
||||
*/
|
||||
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <CoreFoundation/CoreFoundation.h>
|
||||
#import "NSString+extras.h"
|
||||
|
||||
|
||||
@interface RSS : NSObject {
|
||||
NSMutableData *incrementalData;
|
||||
id delegate;
|
||||
|
||||
NSDictionary *headerItems;
|
||||
NSMutableArray *newsItems;
|
||||
NSString *version;
|
||||
|
||||
BOOL flRdf;
|
||||
BOOL normalize;
|
||||
}
|
||||
|
||||
- (RSS *)initWithURL:(NSURL *) url userAgent:(NSString*)userAgent delegate:delegate;
|
||||
- (BOOL)loadData:(NSData *)rssData normalize:(BOOL)fl;
|
||||
|
||||
- (NSMutableArray *)newsItems;
|
||||
- (NSDictionary *)newestItem;
|
||||
|
||||
@end
|
||||
|
||||
@interface NSObject (RSSDelegateProtocol)
|
||||
- (void)feedDidFinishLoading:(RSS *)feed;
|
||||
- (void)feed:(RSS *)feed didFailWithError:(NSError *)error;
|
||||
@end
|
||||
|
||||
#endif
|
||||
@@ -1,727 +0,0 @@
|
||||
/*
|
||||
|
||||
BSD License
|
||||
|
||||
Copyright (c) 2002, Brent Simmons
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of ranchero.com or Brent Simmons nor the names of its
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
||||
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
||||
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
RSS.m
|
||||
A class for reading RSS feeds.
|
||||
|
||||
Created by Brent Simmons on Wed Apr 17 2002.
|
||||
Copyright (c) 2002 Brent Simmons. All rights reserved.
|
||||
*/
|
||||
|
||||
|
||||
#import "Sparkle.h"
|
||||
#import "RSS.h"
|
||||
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_4
|
||||
@interface NSError (TigerPlusMethods)
|
||||
- (NSString *)localizedFailureReason;
|
||||
@end
|
||||
#endif
|
||||
|
||||
@interface RSS (Private)
|
||||
- (void) createheaderdictionary: (CFXMLTreeRef) tree;
|
||||
- (void) createitemsarray: (CFXMLTreeRef) tree;
|
||||
- (void) setversionstring: (CFXMLTreeRef) tree;
|
||||
- (void) flattenimagechildren: (CFXMLTreeRef) tree into: (NSMutableDictionary *) dictionary;
|
||||
- (void) flattensourceattributes: (CFXMLNodeRef) node into: (NSMutableDictionary *) dictionary;
|
||||
- (CFXMLTreeRef) getchanneltree: (CFXMLTreeRef) tree;
|
||||
- (CFXMLTreeRef) getnamedtree: (CFXMLTreeRef) currentTree name: (NSString *) name;
|
||||
- (void) normalizeRSSItem: (NSMutableDictionary *) rssItem;
|
||||
- (NSString *) getelementvalue: (CFXMLTreeRef) tree;
|
||||
@end
|
||||
|
||||
// This comparator function is used to sort the RSS items by their published date.
|
||||
NSComparisonResult compareNewsItems(id item1, id item2, void *context)
|
||||
{
|
||||
// We compare item2 with item1 instead of the other way 'round because we want descending, not ascending. Bit of a hack.
|
||||
return [(NSDate *)[NSDate dateWithNaturalLanguageString:[item2 objectForKey:@"pubDate"]] compare:(NSDate *)[NSDate dateWithNaturalLanguageString:[item1 objectForKey:@"pubDate"]]];
|
||||
}
|
||||
|
||||
@implementation RSS
|
||||
|
||||
|
||||
#define titleKey @"title"
|
||||
#define linkKey @"link"
|
||||
#define descriptionKey @"description"
|
||||
|
||||
|
||||
/*Public interface*/
|
||||
|
||||
- (NSDictionary *)newestItem
|
||||
{
|
||||
// The news items are already sorted by published date, descending.
|
||||
return [[self newsItems] objectAtIndex:0];
|
||||
}
|
||||
|
||||
- (RSS *) initWithTitle: (NSString *) title andDescription: (NSString *) description {
|
||||
|
||||
/*
|
||||
Create an empty feed. Useful for synthetic feeds.
|
||||
*/
|
||||
|
||||
NSMutableDictionary *header;
|
||||
|
||||
flRdf = NO;
|
||||
|
||||
header = [NSMutableDictionary dictionaryWithCapacity: 2];
|
||||
|
||||
[header setObject: title forKey: titleKey];
|
||||
|
||||
[header setObject: description forKey: descriptionKey];
|
||||
|
||||
headerItems = (NSDictionary *) [header copy];
|
||||
|
||||
newsItems = [[NSMutableArray alloc] initWithCapacity: 0];
|
||||
|
||||
version = [[NSString alloc] initWithString: @"synthetic"];
|
||||
|
||||
return (self);
|
||||
} /*initWithTitle*/
|
||||
|
||||
|
||||
- (BOOL)loadData:(NSData *)rssData normalize:(BOOL)fl
|
||||
{
|
||||
CFXMLTreeRef tree;
|
||||
flRdf = NO;
|
||||
normalize = fl;
|
||||
|
||||
NS_DURING
|
||||
tree = CFXMLTreeCreateFromData (kCFAllocatorDefault, (CFDataRef) rssData,
|
||||
NULL, kCFXMLParserSkipWhitespace, kCFXMLNodeCurrentVersion);
|
||||
NS_HANDLER
|
||||
tree = nil;
|
||||
NS_ENDHANDLER
|
||||
|
||||
if (tree == nil)
|
||||
return NO;
|
||||
|
||||
[self createheaderdictionary: tree];
|
||||
[self createitemsarray: tree];
|
||||
[self setversionstring: tree];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
||||
- (RSS *)initWithURL:(NSURL *)url userAgent:(NSString*)userAgent delegate:del
|
||||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
{
|
||||
delegate = del;
|
||||
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: url cachePolicy: NSURLRequestReloadIgnoringCacheData
|
||||
timeoutInterval: 30.0];
|
||||
if (userAgent)
|
||||
[request setValue: userAgent forHTTPHeaderField: @"User-Agent"];
|
||||
|
||||
incrementalData = [[NSMutableData data] retain];
|
||||
NSURLConnection *connection = [NSURLConnection connectionWithRequest:request delegate:self];
|
||||
CFRetain(connection);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
|
||||
{
|
||||
[incrementalData appendData:data];
|
||||
}
|
||||
|
||||
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
|
||||
{
|
||||
CFRelease(connection);
|
||||
|
||||
NSError *error = nil;
|
||||
@try
|
||||
{
|
||||
if (![self loadData:incrementalData normalize:YES])
|
||||
error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAppcastParseError userInfo:[NSDictionary dictionaryWithObject:SULocalizedString(@"An error occurred while parsing the update feed.", nil) forKey:NSLocalizedDescriptionKey]];
|
||||
}
|
||||
@catch (NSException *parseException)
|
||||
{
|
||||
error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAppcastParseError userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:SULocalizedString(@"An error occurred while parsing the update feed: %@", nil), [parseException reason]] forKey:NSLocalizedFailureReasonErrorKey]];
|
||||
}
|
||||
|
||||
if (error)
|
||||
[delegate feed:self didFailWithError:error];
|
||||
else
|
||||
[delegate feedDidFinishLoading:self];
|
||||
}
|
||||
|
||||
- (void)connection:(NSURLConnection*) connection didFailWithError:(NSError *)error
|
||||
{
|
||||
CFRelease(connection);
|
||||
[delegate feed:self didFailWithError:error];
|
||||
}
|
||||
|
||||
- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse
|
||||
{
|
||||
return request;
|
||||
}
|
||||
|
||||
- (NSDictionary *) headerItems {
|
||||
|
||||
return (headerItems);
|
||||
} /*headerItems*/
|
||||
|
||||
|
||||
- (NSMutableArray *) newsItems {
|
||||
|
||||
return (newsItems);
|
||||
} /*newsItems*/
|
||||
|
||||
|
||||
- (NSString *) version {
|
||||
|
||||
return (version);
|
||||
} /*version*/
|
||||
|
||||
|
||||
- (void) dealloc {
|
||||
[incrementalData release];
|
||||
[headerItems release];
|
||||
|
||||
[newsItems release];
|
||||
|
||||
[version release];
|
||||
[super dealloc];
|
||||
} /*dealloc*/
|
||||
|
||||
|
||||
|
||||
/*Private methods. Don't call these: they may change.*/
|
||||
|
||||
|
||||
- (void) createheaderdictionary: (CFXMLTreeRef) tree {
|
||||
|
||||
CFXMLTreeRef channelTree, childTree;
|
||||
CFXMLNodeRef childNode;
|
||||
CFIndex childCount, i;
|
||||
NSString *childName;
|
||||
NSMutableDictionary *headerItemsMutable;
|
||||
|
||||
channelTree = [self getchanneltree: tree];
|
||||
|
||||
if (channelTree == nil) {
|
||||
|
||||
NSException *exception = [NSException exceptionWithName: @"RSSCreateHeaderDictionaryFailed"
|
||||
reason: @"Couldn't find the channel tree." userInfo: nil];
|
||||
|
||||
[exception raise];
|
||||
} /*if*/
|
||||
|
||||
childCount = CFTreeGetChildCount (channelTree);
|
||||
|
||||
headerItemsMutable = [NSMutableDictionary dictionaryWithCapacity: childCount];
|
||||
|
||||
for (i = 0; i < childCount; i++) {
|
||||
|
||||
childTree = CFTreeGetChildAtIndex (channelTree, i);
|
||||
|
||||
childNode = CFXMLTreeGetNode (childTree);
|
||||
|
||||
childName = (NSString *) CFXMLNodeGetString (childNode);
|
||||
|
||||
if ([childName hasPrefix: @"rss:"])
|
||||
childName = [childName substringFromIndex: 4];
|
||||
|
||||
if ([childName isEqualToString: @"item"])
|
||||
break;
|
||||
|
||||
if ([childName isEqualTo: @"image"])
|
||||
[self flattenimagechildren: childTree into: headerItemsMutable];
|
||||
|
||||
[headerItemsMutable setObject: [self getelementvalue: childTree] forKey: childName];
|
||||
} /*for*/
|
||||
|
||||
headerItems = [headerItemsMutable copy];
|
||||
} /*initheaderdictionary*/
|
||||
|
||||
|
||||
- (void) createitemsarray: (CFXMLTreeRef) tree {
|
||||
|
||||
CFXMLTreeRef channelTree, childTree, itemTree;
|
||||
CFXMLNodeRef childNode, itemNode;
|
||||
NSString *childName;
|
||||
NSString *itemName, *itemValue;
|
||||
CFIndex childCount, itemChildCount, i, j;
|
||||
NSMutableDictionary *itemDictionaryMutable;
|
||||
NSMutableArray *itemsArrayMutable;
|
||||
|
||||
if (flRdf)
|
||||
channelTree = [self getnamedtree: tree name: @"rdf:RDF"];
|
||||
else
|
||||
channelTree = [self getchanneltree: tree];
|
||||
|
||||
if (channelTree == nil) {
|
||||
|
||||
NSException *exception = [NSException exceptionWithName: @"RSSCreateItemsArrayFailed"
|
||||
reason: @"Couldn't find the news items." userInfo: nil];
|
||||
|
||||
[exception raise];
|
||||
} /*if*/
|
||||
|
||||
childCount = CFTreeGetChildCount (channelTree);
|
||||
|
||||
itemsArrayMutable = [NSMutableArray arrayWithCapacity: childCount];
|
||||
|
||||
for (i = 0; i < childCount; i++) {
|
||||
|
||||
childTree = CFTreeGetChildAtIndex (channelTree, i);
|
||||
|
||||
childNode = CFXMLTreeGetNode (childTree);
|
||||
|
||||
childName = (NSString *) CFXMLNodeGetString (childNode);
|
||||
|
||||
if ([childName hasPrefix: @"rss:"])
|
||||
childName = [childName substringFromIndex: 4];
|
||||
|
||||
if (![childName isEqualToString: @"item"])
|
||||
continue;
|
||||
|
||||
itemChildCount = CFTreeGetChildCount (childTree);
|
||||
|
||||
itemDictionaryMutable = [NSMutableDictionary dictionaryWithCapacity: itemChildCount];
|
||||
|
||||
for (j = 0; j < itemChildCount; j++) {
|
||||
|
||||
itemTree = CFTreeGetChildAtIndex (childTree, j);
|
||||
|
||||
itemNode = CFXMLTreeGetNode (itemTree);
|
||||
|
||||
itemName = (NSString *) CFXMLNodeGetString (itemNode);
|
||||
|
||||
if ([itemName hasPrefix: @"rss:"])
|
||||
itemName = [itemName substringFromIndex: 4];
|
||||
|
||||
if ([itemName isEqualTo:@"enclosure"])
|
||||
{
|
||||
// Hack to add attributes to the dictionary in addition to children. (AMM)
|
||||
const CFXMLElementInfo *websiteInfo = CFXMLNodeGetInfoPtr(itemNode);
|
||||
NSMutableDictionary *enclosureDictionary = [NSMutableDictionary dictionary];
|
||||
id keyEnumerator = [(NSDictionary *)websiteInfo->attributes keyEnumerator], current;
|
||||
while ((current = [keyEnumerator nextObject]))
|
||||
{
|
||||
NSString *escapedAttributeValue = [(NSDictionary *)websiteInfo->attributes objectForKey:current];
|
||||
CFStringRef attributeValue = CFXMLCreateStringByUnescapingEntities(kCFAllocatorDefault, (CFStringRef)escapedAttributeValue, NULL);
|
||||
if (attributeValue)
|
||||
{
|
||||
// Do a stringWithString dance rather than just casting so that it's GC safe without using the 10.4+ CFMakeCollectable.
|
||||
[enclosureDictionary setObject:[NSString stringWithString:(NSString *)attributeValue] forKey:current];
|
||||
CFRelease(attributeValue);
|
||||
}
|
||||
}
|
||||
[itemDictionaryMutable setObject: enclosureDictionary forKey: itemName];
|
||||
continue;
|
||||
}
|
||||
|
||||
itemValue = [self getelementvalue: itemTree];
|
||||
|
||||
if ([itemName isEqualTo: @"source"])
|
||||
[self flattensourceattributes: itemNode into: itemDictionaryMutable];
|
||||
|
||||
[itemDictionaryMutable setObject: itemValue forKey: itemName];
|
||||
} /*for*/
|
||||
|
||||
if (normalize)
|
||||
[self normalizeRSSItem: itemDictionaryMutable];
|
||||
|
||||
[itemsArrayMutable addObject: itemDictionaryMutable];
|
||||
} /*for*/
|
||||
|
||||
// Sort the news items by published date, descending.
|
||||
newsItems = [[itemsArrayMutable sortedArrayUsingFunction:compareNewsItems context:NULL] retain];
|
||||
} /*createitemsarray*/
|
||||
|
||||
|
||||
- (void) setversionstring: (CFXMLTreeRef) tree {
|
||||
|
||||
CFXMLTreeRef rssTree;
|
||||
const CFXMLElementInfo *elementInfo;
|
||||
CFXMLNodeRef node;
|
||||
|
||||
if (flRdf) {
|
||||
|
||||
version = [[NSString alloc] initWithString: @"rdf"];
|
||||
|
||||
return;
|
||||
} /*if*/
|
||||
|
||||
rssTree = [self getnamedtree: tree name: @"rss"];
|
||||
|
||||
node = CFXMLTreeGetNode (rssTree);
|
||||
|
||||
elementInfo = CFXMLNodeGetInfoPtr (node);
|
||||
|
||||
version = [[NSString alloc] initWithString: [(NSDictionary *) (*elementInfo).attributes objectForKey: @"version"]];
|
||||
} /*setversionstring*/
|
||||
|
||||
|
||||
- (void) flattenimagechildren: (CFXMLTreeRef) tree into: (NSMutableDictionary *) dictionary {
|
||||
|
||||
CFIndex childCount = CFTreeGetChildCount (tree);
|
||||
CFIndex i = 0;
|
||||
CFXMLTreeRef childTree;
|
||||
CFXMLNodeRef childNode;
|
||||
NSString *childName, *childValue, *keyName;
|
||||
|
||||
if (childCount < 1)
|
||||
return;
|
||||
|
||||
for (i = 0; i < childCount; i++) {
|
||||
|
||||
childTree = CFTreeGetChildAtIndex (tree, i);
|
||||
|
||||
childNode = CFXMLTreeGetNode (childTree);
|
||||
|
||||
childName = (NSString *) CFXMLNodeGetString (childNode);
|
||||
|
||||
if ([childName hasPrefix: @"rss:"])
|
||||
childName = [childName substringFromIndex: 4];
|
||||
|
||||
childValue = [self getelementvalue: childTree];
|
||||
|
||||
keyName = [NSString stringWithFormat: @"image%@", childName];
|
||||
|
||||
[dictionary setObject: childValue forKey: keyName];
|
||||
} /*for*/
|
||||
} /*flattenimagechildren*/
|
||||
|
||||
|
||||
- (void) flattensourceattributes: (CFXMLNodeRef) node into: (NSMutableDictionary *) dictionary {
|
||||
|
||||
const CFXMLElementInfo *elementInfo;
|
||||
NSString *sourceHomeUrl, *sourceRssUrl;
|
||||
|
||||
elementInfo = CFXMLNodeGetInfoPtr (node);
|
||||
|
||||
sourceHomeUrl = [(NSDictionary *) (*elementInfo).attributes objectForKey: @"homeUrl"];
|
||||
|
||||
sourceRssUrl = [(NSDictionary *) (*elementInfo).attributes objectForKey: @"url"];
|
||||
|
||||
if (sourceHomeUrl != nil)
|
||||
[dictionary setObject: sourceHomeUrl forKey: @"sourceHomeUrl"];
|
||||
|
||||
if (sourceRssUrl != nil)
|
||||
[dictionary setObject: sourceRssUrl forKey: @"sourceRssUrl"];
|
||||
} /*flattensourceattributes*/
|
||||
|
||||
|
||||
- (CFXMLTreeRef) getchanneltree: (CFXMLTreeRef) tree {
|
||||
|
||||
CFXMLTreeRef rssTree, channelTree;
|
||||
|
||||
rssTree = [self getnamedtree: tree name: @"rss"];
|
||||
|
||||
if (rssTree == nil) { /*It might be "rdf:RDF" instead, a 1.0 or greater feed.*/
|
||||
|
||||
rssTree = [self getnamedtree: tree name: @"rdf:RDF"];
|
||||
|
||||
if (rssTree != nil)
|
||||
flRdf = YES; /*This info will be needed later when creating the items array.*/
|
||||
} /*if*/
|
||||
|
||||
if (rssTree == nil)
|
||||
return (nil);
|
||||
|
||||
channelTree = [self getnamedtree: rssTree name: @"channel"];
|
||||
|
||||
if (channelTree == nil)
|
||||
channelTree = [self getnamedtree: rssTree name: @"rss:channel"];
|
||||
|
||||
return (channelTree);
|
||||
} /*getchanneltree*/
|
||||
|
||||
|
||||
- (CFXMLTreeRef) getnamedtree: (CFXMLTreeRef) currentTree name: (NSString *) name {
|
||||
|
||||
CFIndex childCount, i;
|
||||
CFXMLNodeRef xmlNode;
|
||||
CFXMLTreeRef xmlTreeNode;
|
||||
NSString *itemName;
|
||||
|
||||
childCount = CFTreeGetChildCount (currentTree);
|
||||
|
||||
for (i = childCount - 1; i >= 0; i--) {
|
||||
|
||||
xmlTreeNode = CFTreeGetChildAtIndex (currentTree, i);
|
||||
|
||||
xmlNode = CFXMLTreeGetNode (xmlTreeNode);
|
||||
|
||||
itemName = (NSString *) CFXMLNodeGetString (xmlNode);
|
||||
|
||||
if ([itemName isEqualToString: name])
|
||||
return (xmlTreeNode);
|
||||
} /*for*/
|
||||
|
||||
return (nil);
|
||||
} /*getnamedtree*/
|
||||
|
||||
|
||||
- (void) normalizeRSSItem: (NSMutableDictionary *) rssItem {
|
||||
|
||||
/*
|
||||
Make sure item, link, and description are present and have
|
||||
reasonable values. Description and link may be "".
|
||||
Also trim white space, remove HTML when appropriate.
|
||||
*/
|
||||
|
||||
NSString *description, *normalizedLink, *title;
|
||||
BOOL nilDescription = NO;
|
||||
|
||||
/*Description*/
|
||||
|
||||
description = [rssItem objectForKey: descriptionKey];
|
||||
|
||||
if (description == nil) {
|
||||
|
||||
description = @"";
|
||||
|
||||
nilDescription = YES;
|
||||
} /*if*/
|
||||
|
||||
description = [description trimWhiteSpace];
|
||||
|
||||
if ([description isEqualTo: @""])
|
||||
nilDescription = YES;
|
||||
|
||||
[rssItem setObject: description forKey: descriptionKey];
|
||||
|
||||
/*Link*/
|
||||
|
||||
normalizedLink = [rssItem objectForKey: linkKey];
|
||||
|
||||
if ([NSString stringIsEmpty: normalizedLink]) {
|
||||
|
||||
/*Try to get a URL from the description.*/
|
||||
|
||||
if (!nilDescription) {
|
||||
|
||||
NSArray *stringComponents = [description componentsSeparatedByString: @"href=\""];
|
||||
|
||||
if ([stringComponents count] > 1) {
|
||||
|
||||
normalizedLink = [stringComponents objectAtIndex: 1];
|
||||
|
||||
stringComponents = [normalizedLink componentsSeparatedByString: @"\""];
|
||||
|
||||
normalizedLink = [stringComponents objectAtIndex: 0];
|
||||
} /*if*/
|
||||
} /*if*/
|
||||
} /*if*/
|
||||
|
||||
if (normalizedLink == nil)
|
||||
normalizedLink = @"";
|
||||
|
||||
normalizedLink = [normalizedLink trimWhiteSpace];
|
||||
|
||||
[rssItem setObject: normalizedLink forKey: linkKey];
|
||||
|
||||
/*Title*/
|
||||
|
||||
title = [rssItem objectForKey: titleKey];
|
||||
|
||||
if (title != nil) {
|
||||
|
||||
title = [title stripHTML];
|
||||
|
||||
title = [title trimWhiteSpace];
|
||||
} /*if*/
|
||||
|
||||
if ([NSString stringIsEmpty: title]) {
|
||||
|
||||
/*Grab a title from the description.*/
|
||||
|
||||
if (!nilDescription) {
|
||||
|
||||
NSArray *stringComponents = [description componentsSeparatedByString: @">"];
|
||||
|
||||
if ([stringComponents count] > 1) {
|
||||
|
||||
title = [stringComponents objectAtIndex: 1];
|
||||
|
||||
stringComponents = [title componentsSeparatedByString: @"<"];
|
||||
|
||||
title = [stringComponents objectAtIndex: 0];
|
||||
|
||||
title = [title stripHTML];
|
||||
|
||||
title = [title trimWhiteSpace];
|
||||
} /*if*/
|
||||
|
||||
if ([NSString stringIsEmpty: title]) { /*use first part of description*/
|
||||
|
||||
NSString *shortTitle = [[[description stripHTML] trimWhiteSpace] ellipsizeAfterNWords: 5];
|
||||
|
||||
shortTitle = [shortTitle trimWhiteSpace];
|
||||
|
||||
title = [NSString stringWithFormat: @"%@\u2026", shortTitle];
|
||||
} /*else*/
|
||||
} /*if*/
|
||||
|
||||
title = [title stripHTML];
|
||||
|
||||
title = [title trimWhiteSpace];
|
||||
|
||||
if ([NSString stringIsEmpty: title])
|
||||
title = @"Untitled";
|
||||
} /*if*/
|
||||
|
||||
[rssItem setObject: title forKey: titleKey];
|
||||
|
||||
/*dangerousmeta case: super-long title with no description*/
|
||||
|
||||
if ((nilDescription) && ([title length] > 50)) {
|
||||
|
||||
NSString *shortTitle = [[[title stripHTML] trimWhiteSpace] ellipsizeAfterNWords: 7];
|
||||
|
||||
description = [[title copy] autorelease];
|
||||
|
||||
[rssItem setObject: description forKey: descriptionKey];
|
||||
|
||||
title = [NSString stringWithFormat: @"%@\u2026", shortTitle];
|
||||
|
||||
[rssItem setObject: title forKey: titleKey];
|
||||
} /*if*/
|
||||
|
||||
{ /*deal with entities*/
|
||||
|
||||
const char *tempcstring;
|
||||
NSAttributedString *s = nil;
|
||||
NSString *convertedTitle = nil;
|
||||
NSArray *stringComponents;
|
||||
|
||||
stringComponents = [title componentsSeparatedByString: @"&"];
|
||||
|
||||
if ([stringComponents count] > 1) {
|
||||
|
||||
stringComponents = [title componentsSeparatedByString: @";"];
|
||||
|
||||
if ([stringComponents count] > 1) {
|
||||
|
||||
size_t len;
|
||||
|
||||
tempcstring = [title UTF8String];
|
||||
|
||||
len = strlen (tempcstring);
|
||||
|
||||
if (len > 0) {
|
||||
|
||||
s = [[NSAttributedString alloc]
|
||||
initWithHTML: [NSData dataWithBytes: tempcstring length: strlen (tempcstring)]
|
||||
documentAttributes: (NSDictionary **) NULL];
|
||||
|
||||
convertedTitle = [s string];
|
||||
|
||||
[s autorelease];
|
||||
|
||||
convertedTitle = [convertedTitle stripHTML];
|
||||
|
||||
convertedTitle = [convertedTitle trimWhiteSpace];
|
||||
} /*if*/
|
||||
|
||||
if ([NSString stringIsEmpty: convertedTitle])
|
||||
convertedTitle = @"Untitled";
|
||||
|
||||
[rssItem setObject: convertedTitle forKey: @"convertedTitle"];
|
||||
} /*if*/
|
||||
} /*if*/
|
||||
} /*deal with entities*/
|
||||
} /*normalizeRSSItem*/
|
||||
|
||||
|
||||
- (NSString *) getelementvalue: (CFXMLTreeRef) tree {
|
||||
|
||||
CFXMLNodeRef node;
|
||||
CFXMLTreeRef itemTree;
|
||||
CFIndex childCount, ix;
|
||||
NSMutableString *valueMutable;
|
||||
NSString *value;
|
||||
NSString *name;
|
||||
|
||||
childCount = CFTreeGetChildCount (tree);
|
||||
|
||||
valueMutable = [[NSMutableString alloc] init];
|
||||
|
||||
for (ix = 0; ix < childCount; ix++) {
|
||||
|
||||
itemTree = CFTreeGetChildAtIndex (tree, ix);
|
||||
|
||||
node = CFXMLTreeGetNode (itemTree);
|
||||
|
||||
name = (NSString *) CFXMLNodeGetString (node);
|
||||
|
||||
if (name != nil) {
|
||||
|
||||
if (CFXMLNodeGetTypeCode (node) == kCFXMLNodeTypeEntityReference) {
|
||||
|
||||
if ([name isEqualTo: @"lt"])
|
||||
name = @"<";
|
||||
|
||||
else if ([name isEqualTo: @"gt"])
|
||||
name = @">";
|
||||
|
||||
else if ([name isEqualTo: @"quot"])
|
||||
name = @"\"";
|
||||
|
||||
else if ([name isEqualTo: @"amp"])
|
||||
name = @"&";
|
||||
|
||||
else if ([name isEqualTo: @"rsquo"]) {
|
||||
char rsquo[4] = { 0xe2, 0x80, 0x99, 0x0 };
|
||||
name = [NSString stringWithUTF8String: rsquo];
|
||||
}
|
||||
|
||||
else if ([name isEqualTo: @"lsquo"]) {
|
||||
char lsquo[4] = { 0xe2, 0x80, 0x98, 0x0 };
|
||||
name = [NSString stringWithUTF8String: lsquo];
|
||||
}
|
||||
|
||||
else if ([name isEqualTo: @"apos"])
|
||||
name = @"'";
|
||||
else
|
||||
name = [NSString stringWithFormat: @"&%@;", name];
|
||||
} /*if*/
|
||||
|
||||
[valueMutable appendString: name];
|
||||
} /*if*/
|
||||
} /*for*/
|
||||
|
||||
value = [[valueMutable trimWhiteSpace] retain];
|
||||
|
||||
[valueMutable autorelease];
|
||||
|
||||
return ([value autorelease]);
|
||||
} /*getelementvalue*/
|
||||
|
||||
@end
|
||||
+12
-7
@@ -9,22 +9,27 @@
|
||||
#ifndef SUAPPCAST_H
|
||||
#define SUAPPCAST_H
|
||||
|
||||
@class RSS, SUAppcastItem;
|
||||
@interface SUAppcast : NSObject {
|
||||
@protocol SUAppcastDelegate;
|
||||
|
||||
@class SUAppcastItem;
|
||||
@interface SUAppcast : NSObject<NSURLDownloadDelegate>
|
||||
{
|
||||
@private
|
||||
NSArray *items;
|
||||
NSString *userAgentString;
|
||||
id delegate;
|
||||
id<SUAppcastDelegate> delegate;
|
||||
NSString *downloadFilename;
|
||||
NSURLDownload *download;
|
||||
}
|
||||
@property (assign) id<SUAppcastDelegate> delegate;
|
||||
@property (copy) NSString *userAgentString;
|
||||
|
||||
- (void)fetchAppcastFromURL:(NSURL *)url;
|
||||
- (void)setDelegate:delegate;
|
||||
- (void)setUserAgentString:(NSString *)userAgentString;
|
||||
|
||||
- (NSArray *)items;
|
||||
|
||||
@end
|
||||
|
||||
@interface NSObject (SUAppcastDelegate)
|
||||
@protocol SUAppcastDelegate <NSObject>
|
||||
- (void)appcastDidFinishLoading:(SUAppcast *)appcast;
|
||||
- (void)appcast:(SUAppcast *)appcast failedToLoadWithError:(NSError *)error;
|
||||
@end
|
||||
|
||||
+226
-39
@@ -6,60 +6,239 @@
|
||||
// Copyright 2006 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#import "Sparkle.h"
|
||||
#import "SUAppcast.h"
|
||||
#import "SUUpdater.h"
|
||||
|
||||
@interface SUAppcast (Private)
|
||||
#import "SUAppcast.h"
|
||||
#import "SUAppcastItem.h"
|
||||
#import "SUVersionComparisonProtocol.h"
|
||||
#import "SUAppcast.h"
|
||||
#import "SUConstants.h"
|
||||
#import "SULog.h"
|
||||
|
||||
@interface NSXMLElement (SUAppcastExtensions)
|
||||
- (NSDictionary *)attributesAsDictionary;
|
||||
@end
|
||||
|
||||
@implementation NSXMLElement (SUAppcastExtensions)
|
||||
- (NSDictionary *)attributesAsDictionary
|
||||
{
|
||||
NSEnumerator *attributeEnum = [[self attributes] objectEnumerator];
|
||||
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
|
||||
|
||||
for (NSXMLNode *attribute in attributeEnum) {
|
||||
[dictionary setObject:[attribute stringValue] forKey:[attribute name]];
|
||||
}
|
||||
return dictionary;
|
||||
}
|
||||
@end
|
||||
|
||||
@interface SUAppcast () <NSURLDownloadDelegate>
|
||||
@property (copy) NSString *downloadFilename;
|
||||
@property (retain) NSURLDownload *download;
|
||||
@property (copy) NSArray *items;
|
||||
- (void)reportError:(NSError *)error;
|
||||
- (NSXMLNode *)bestNodeInNodes:(NSArray *)nodes;
|
||||
@end
|
||||
|
||||
@implementation SUAppcast
|
||||
@synthesize downloadFilename;
|
||||
@synthesize delegate;
|
||||
@synthesize userAgentString;
|
||||
@synthesize download;
|
||||
@synthesize items;
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[items release];
|
||||
self.items = nil;
|
||||
self.userAgentString = nil;
|
||||
self.downloadFilename = nil;
|
||||
self.download = nil;
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSArray *)items
|
||||
{
|
||||
return items;
|
||||
}
|
||||
|
||||
- (void)fetchAppcastFromURL:(NSURL *)url
|
||||
{
|
||||
RSS *feed = [[RSS alloc] initWithURL:url userAgent:userAgentString delegate:self];
|
||||
CFRetain(feed); // Manage the RSS feed's memory manually.
|
||||
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30.0];
|
||||
if (userAgentString)
|
||||
[request setValue:userAgentString forHTTPHeaderField:@"User-Agent"];
|
||||
|
||||
self.download = [[[NSURLDownload alloc] initWithRequest:request delegate:self] autorelease];
|
||||
}
|
||||
|
||||
- (void)feedDidFinishLoading:(RSS *)feed
|
||||
- (void)download:(NSURLDownload *)aDownload decideDestinationWithSuggestedFilename:(NSString *)filename
|
||||
{
|
||||
// Set up all the appcast items:
|
||||
NSArray *tempItems = [NSMutableArray array];
|
||||
id enumerator = [[feed newsItems] objectEnumerator], current;
|
||||
@try
|
||||
NSString* destinationFilename = NSTemporaryDirectory();
|
||||
if (destinationFilename)
|
||||
{
|
||||
while ((current = [enumerator nextObject]))
|
||||
{
|
||||
[(NSMutableArray *)tempItems addObject:[[[SUAppcastItem alloc] initWithDictionary:current] autorelease]];
|
||||
}
|
||||
items = [[NSArray arrayWithArray:tempItems] retain]; // Make the items list immutable.
|
||||
destinationFilename = [destinationFilename stringByAppendingPathComponent:filename];
|
||||
[download setDestination:destinationFilename allowOverwrite:NO];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)download:(NSURLDownload *)aDownload didCreateDestination:(NSString *)path
|
||||
{
|
||||
self.downloadFilename = path;
|
||||
}
|
||||
|
||||
- (void)downloadDidFinish:(NSURLDownload *)aDownload
|
||||
{
|
||||
NSError *error = nil;
|
||||
|
||||
NSXMLDocument *document = nil;
|
||||
BOOL failed = NO;
|
||||
NSArray *xmlItems = nil;
|
||||
NSMutableArray *appcastItems = [NSMutableArray array];
|
||||
|
||||
if (downloadFilename)
|
||||
{
|
||||
NSUInteger options = 0;
|
||||
if (NSAppKitVersionNumber < NSAppKitVersionNumber10_7) {
|
||||
// In order to avoid including external entities when parsing the appcast (a potential security vulnerability; see https://github.com/andymatuschak/Sparkle/issues/169), we ask NSXMLDocument to "tidy" the XML first. This happens to remove these external entities; it wouldn't be a future-proof approach, but it worked in these historical versions of OS X, and we have a more rigorous approach for 10.7+.
|
||||
options = NSXMLDocumentTidyXML;
|
||||
} else {
|
||||
// In 10.7 and later, there's a real option for the behavior we desire.
|
||||
options = NSXMLNodeLoadExternalEntitiesSameOriginOnly;
|
||||
}
|
||||
document = [[[NSXMLDocument alloc] initWithContentsOfURL:[NSURL fileURLWithPath:downloadFilename] options:options error:&error] autorelease];
|
||||
|
||||
[[NSFileManager defaultManager] removeItemAtPath:downloadFilename error:nil];
|
||||
self.downloadFilename = nil;
|
||||
}
|
||||
else
|
||||
{
|
||||
failed = YES;
|
||||
}
|
||||
|
||||
if (nil == document)
|
||||
{
|
||||
failed = YES;
|
||||
}
|
||||
else
|
||||
{
|
||||
xmlItems = [document nodesForXPath:@"/rss/channel/item" error:&error];
|
||||
if (nil == xmlItems)
|
||||
{
|
||||
failed = YES;
|
||||
}
|
||||
}
|
||||
|
||||
if (failed == NO)
|
||||
{
|
||||
|
||||
if ([delegate respondsToSelector:@selector(appcastDidFinishLoading:)])
|
||||
[delegate performSelectorOnMainThread:@selector(appcastDidFinishLoading:) withObject:self waitUntilDone:NO];
|
||||
NSEnumerator *nodeEnum = [xmlItems objectEnumerator];
|
||||
NSXMLNode *node;
|
||||
NSMutableDictionary *nodesDict = [NSMutableDictionary dictionary];
|
||||
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
|
||||
|
||||
while (failed == NO && (node = [nodeEnum nextObject]))
|
||||
{
|
||||
// First, we'll "index" all the first-level children of this appcast item so we can pick them out by language later.
|
||||
if ([[node children] count])
|
||||
{
|
||||
node = [node childAtIndex:0];
|
||||
while (nil != node)
|
||||
{
|
||||
NSString *name = [node name];
|
||||
if (name)
|
||||
{
|
||||
NSMutableArray *nodes = [nodesDict objectForKey:name];
|
||||
if (nodes == nil)
|
||||
{
|
||||
nodes = [NSMutableArray array];
|
||||
[nodesDict setObject:nodes forKey:name];
|
||||
}
|
||||
[nodes addObject:node];
|
||||
}
|
||||
node = [node nextSibling];
|
||||
}
|
||||
}
|
||||
|
||||
for (NSString *name in nodesDict)
|
||||
{
|
||||
node = [self bestNodeInNodes:[nodesDict objectForKey:name]];
|
||||
if ([name isEqualToString:@"enclosure"])
|
||||
{
|
||||
// enclosure is flattened as a separate dictionary for some reason
|
||||
NSDictionary *encDict = [(NSXMLElement *)node attributesAsDictionary];
|
||||
[dict setObject:encDict forKey:@"enclosure"];
|
||||
|
||||
}
|
||||
else if ([name isEqualToString:@"pubDate"])
|
||||
{
|
||||
// pubDate is expected to be an NSDate by SUAppcastItem, but the RSS class was returning an NSString
|
||||
NSDate *date = [NSDate dateWithNaturalLanguageString:[node stringValue]];
|
||||
if (date)
|
||||
[dict setObject:date forKey:name];
|
||||
}
|
||||
else if ([name isEqualToString:@"sparkle:deltas"])
|
||||
{
|
||||
NSMutableArray *deltas = [NSMutableArray array];
|
||||
NSEnumerator *childEnum = [[node children] objectEnumerator];
|
||||
for (NSXMLNode *child in childEnum) {
|
||||
if ([[child name] isEqualToString:@"enclosure"])
|
||||
[deltas addObject:[(NSXMLElement *)child attributesAsDictionary]];
|
||||
}
|
||||
[dict setObject:deltas forKey:@"deltas"];
|
||||
}
|
||||
else if (name != nil)
|
||||
{
|
||||
// add all other values as strings
|
||||
NSString *theValue = [[node stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
|
||||
if (theValue != nil) {
|
||||
[dict setObject:theValue forKey:name];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NSString *errString;
|
||||
SUAppcastItem *anItem = [[[SUAppcastItem alloc] initWithDictionary:dict failureReason:&errString] autorelease];
|
||||
if (anItem)
|
||||
{
|
||||
[appcastItems addObject:anItem];
|
||||
}
|
||||
else
|
||||
{
|
||||
SULog(@"Sparkle Updater: Failed to parse appcast item: %@.\nAppcast dictionary was: %@", errString, dict);
|
||||
}
|
||||
[nodesDict removeAllObjects];
|
||||
[dict removeAllObjects];
|
||||
}
|
||||
}
|
||||
@catch (NSException *parseException)
|
||||
{
|
||||
[self reportError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUAppcastParseError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:SULocalizedString(@"An error occurred while parsing the update feed.", nil), NSLocalizedDescriptionKey, [parseException reason], SUTechnicalErrorInformationKey, nil]]];
|
||||
|
||||
if ([appcastItems count])
|
||||
{
|
||||
NSSortDescriptor *sort = [[[NSSortDescriptor alloc] initWithKey:@"date" ascending:NO] autorelease];
|
||||
[appcastItems sortUsingDescriptors:[NSArray arrayWithObject:sort]];
|
||||
self.items = appcastItems;
|
||||
}
|
||||
|
||||
if (failed)
|
||||
{
|
||||
[self reportError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUAppcastParseError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:SULocalizedString(@"An error occurred while parsing the update feed.", nil), NSLocalizedDescriptionKey, nil]]];
|
||||
}
|
||||
else if ([delegate respondsToSelector:@selector(appcastDidFinishLoading:)])
|
||||
{
|
||||
[delegate appcastDidFinishLoading:self];
|
||||
}
|
||||
CFRelease(feed);
|
||||
}
|
||||
|
||||
- (void)feed:(RSS *)feed didFailWithError:(NSError *)error
|
||||
- (void)download:(NSURLDownload *)aDownload didFailWithError:(NSError *)error
|
||||
{
|
||||
if (downloadFilename)
|
||||
{
|
||||
[[NSFileManager defaultManager] removeItemAtPath:downloadFilename error:nil];
|
||||
}
|
||||
self.downloadFilename = nil;
|
||||
|
||||
[self reportError:error];
|
||||
}
|
||||
|
||||
- (NSURLRequest *)download:(NSURLDownload *)aDownload willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse
|
||||
{
|
||||
return request;
|
||||
}
|
||||
|
||||
- (void)reportError:(NSError *)error
|
||||
{
|
||||
if ([delegate respondsToSelector:@selector(appcast:failedToLoadWithError:)])
|
||||
@@ -68,18 +247,26 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setUserAgentString:(NSString *)uas
|
||||
- (NSXMLNode *)bestNodeInNodes:(NSArray *)nodes
|
||||
{
|
||||
if (uas != userAgentString)
|
||||
{
|
||||
[userAgentString release];
|
||||
userAgentString = [uas copy];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setDelegate:del
|
||||
{
|
||||
delegate = del;
|
||||
// We use this method to pick out the localized version of a node when one's available.
|
||||
if ([nodes count] == 1)
|
||||
return [nodes objectAtIndex:0];
|
||||
else if ([nodes count] == 0)
|
||||
return nil;
|
||||
|
||||
NSMutableArray *languages = [NSMutableArray array];
|
||||
NSString *lang;
|
||||
NSUInteger i;
|
||||
for (NSXMLElement *node in nodes) {
|
||||
lang = [[node attributeForName:@"xml:lang"] stringValue];
|
||||
[languages addObject:(lang ? lang : @"")];
|
||||
}
|
||||
lang = [[NSBundle preferredLocalizationsFromArray:languages] objectAtIndex:0];
|
||||
i = [languages indexOfObject:([languages containsObject:lang] ? lang : @"")];
|
||||
if (i == NSNotFound)
|
||||
i = 0;
|
||||
return [nodes objectAtIndex:i];
|
||||
}
|
||||
|
||||
@end
|
||||
+28
-14
@@ -9,40 +9,54 @@
|
||||
#ifndef SUAPPCASTITEM_H
|
||||
#define SUAPPCASTITEM_H
|
||||
|
||||
|
||||
@interface SUAppcastItem : NSObject {
|
||||
@interface SUAppcastItem : NSObject
|
||||
{
|
||||
@private
|
||||
NSString *title;
|
||||
NSDate *date;
|
||||
NSString *description;
|
||||
NSString *itemDescription;
|
||||
|
||||
NSURL *releaseNotesURL;
|
||||
|
||||
NSString *DSASignature;
|
||||
NSString *minimumSystemVersion;
|
||||
NSString *maximumSystemVersion;
|
||||
|
||||
NSURL *fileURL;
|
||||
NSString *versionString;
|
||||
NSString *displayVersionString;
|
||||
|
||||
|
||||
NSDictionary *deltaUpdates;
|
||||
|
||||
NSDictionary *propertiesDictionary;
|
||||
|
||||
NSURL *infoURL; // UK 2007-08-31
|
||||
}
|
||||
@property (copy, readonly) NSString *title;
|
||||
@property (copy, readonly) NSDate *date;
|
||||
@property (copy, readonly) NSString *itemDescription;
|
||||
@property (retain, readonly) NSURL *releaseNotesURL;
|
||||
@property (copy, readonly) NSString *DSASignature;
|
||||
@property (copy, readonly) NSString *minimumSystemVersion;
|
||||
@property (copy, readonly) NSString *maximumSystemVersion;
|
||||
@property (retain, readonly) NSURL *fileURL;
|
||||
@property (copy, readonly) NSString *versionString;
|
||||
@property (copy, readonly) NSString *displayVersionString;
|
||||
@property (copy, readonly) NSDictionary *deltaUpdates;
|
||||
@property (retain, readonly) NSURL *infoURL;
|
||||
|
||||
// Initializes with data from a dictionary provided by the RSS class.
|
||||
- initWithDictionary:(NSDictionary *)dict;
|
||||
- (id)initWithDictionary:(NSDictionary *)dict;
|
||||
- (id)initWithDictionary:(NSDictionary *)dict failureReason:(NSString**)error;
|
||||
|
||||
- (NSString *)title;
|
||||
- (NSString *)versionString;
|
||||
- (NSString *)displayVersionString;
|
||||
- (NSDate *)date;
|
||||
- (NSString *)description;
|
||||
- (NSURL *)releaseNotesURL;
|
||||
- (NSURL *)fileURL;
|
||||
- (NSString *)DSASignature;
|
||||
- (NSString *)minimumSystemVersion;
|
||||
- (BOOL)isDeltaUpdate;
|
||||
- (BOOL)isCriticalUpdate;
|
||||
|
||||
// Returns the dictionary provided in initWithDictionary; this might be useful later for extensions.
|
||||
- (NSDictionary *)propertiesDictionary;
|
||||
|
||||
- (NSURL *)infoURL; // UK 2007-08-31
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
+131
-113
@@ -6,116 +6,64 @@
|
||||
// Copyright 2006 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#import "Sparkle.h"
|
||||
#import "SUUpdater.h"
|
||||
|
||||
#import "SUAppcast.h"
|
||||
#import "SUAppcastItem.h"
|
||||
#import "SUVersionComparisonProtocol.h"
|
||||
#import "SUAppcastItem.h"
|
||||
#import "SULog.h"
|
||||
|
||||
@interface SUAppcastItem ()
|
||||
@property (copy, readwrite) NSString *title;
|
||||
@property (copy, readwrite) NSDate *date;
|
||||
@property (copy, readwrite) NSString *itemDescription;
|
||||
@property (retain, readwrite) NSURL *releaseNotesURL;
|
||||
@property (copy, readwrite) NSString *DSASignature;
|
||||
@property (copy, readwrite) NSString *minimumSystemVersion;
|
||||
@property (copy, readwrite) NSString *maximumSystemVersion;
|
||||
@property (retain, readwrite) NSURL *fileURL;
|
||||
@property (copy, readwrite) NSString *versionString;
|
||||
@property (copy, readwrite) NSString *displayVersionString;
|
||||
@property (copy, readwrite) NSDictionary *deltaUpdates;
|
||||
@property (retain, readwrite) NSURL *infoURL;
|
||||
@end
|
||||
|
||||
@implementation SUAppcastItem
|
||||
@synthesize date;
|
||||
@synthesize deltaUpdates;
|
||||
@synthesize displayVersionString;
|
||||
@synthesize DSASignature;
|
||||
@synthesize fileURL;
|
||||
@synthesize infoURL;
|
||||
@synthesize itemDescription;
|
||||
@synthesize maximumSystemVersion;
|
||||
@synthesize minimumSystemVersion;
|
||||
@synthesize releaseNotesURL;
|
||||
@synthesize title;
|
||||
@synthesize versionString;
|
||||
|
||||
// Attack of accessors!
|
||||
|
||||
- (NSString *)title { return [[title retain] autorelease]; }
|
||||
|
||||
- (void)setTitle:(NSString *)aTitle
|
||||
- (BOOL)isDeltaUpdate
|
||||
{
|
||||
if (title == aTitle) return;
|
||||
[title release];
|
||||
title = [aTitle copy];
|
||||
return [[propertiesDictionary objectForKey:@"enclosure"] objectForKey:@"sparkle:deltaFrom"] != nil;
|
||||
}
|
||||
|
||||
|
||||
- (NSDate *)date { return [[date retain] autorelease]; }
|
||||
|
||||
- (void)setDate:(NSDate *)aDate
|
||||
- (BOOL)isCriticalUpdate
|
||||
{
|
||||
if (date == aDate) return;
|
||||
[date release];
|
||||
date = [aDate copy];
|
||||
}
|
||||
|
||||
|
||||
- (NSString *)description { return [[description retain] autorelease]; }
|
||||
|
||||
- (void)setDescription:(NSString *)aDescription
|
||||
{
|
||||
if (description == aDescription) return;
|
||||
[description release];
|
||||
description = [aDescription copy];
|
||||
}
|
||||
|
||||
|
||||
- (NSURL *)releaseNotesURL { return [[releaseNotesURL retain] autorelease]; }
|
||||
|
||||
- (void)setReleaseNotesURL:(NSURL *)aReleaseNotesURL
|
||||
{
|
||||
if (releaseNotesURL == aReleaseNotesURL) return;
|
||||
[releaseNotesURL release];
|
||||
releaseNotesURL = [aReleaseNotesURL copy];
|
||||
}
|
||||
|
||||
|
||||
- (NSString *)DSASignature { return [[DSASignature retain] autorelease]; }
|
||||
|
||||
- (void)setDSASignature:(NSString *)aDSASignature
|
||||
{
|
||||
if (DSASignature == aDSASignature) return;
|
||||
[DSASignature release];
|
||||
DSASignature = [aDSASignature copy];
|
||||
}
|
||||
|
||||
|
||||
- (NSURL *)fileURL { return [[fileURL retain] autorelease]; }
|
||||
|
||||
- (void)setFileURL:(NSURL *)aFileURL
|
||||
{
|
||||
if (fileURL == aFileURL) return;
|
||||
[fileURL release];
|
||||
fileURL = [aFileURL copy];
|
||||
}
|
||||
|
||||
|
||||
- (NSString *)versionString { return [[versionString retain] autorelease]; }
|
||||
|
||||
- (void)setVersionString:(NSString *)s
|
||||
{
|
||||
if (versionString == s) return;
|
||||
[versionString release];
|
||||
versionString = [s copy];
|
||||
}
|
||||
|
||||
|
||||
- (NSString *)displayVersionString { return [[displayVersionString retain] autorelease]; }
|
||||
|
||||
- (void)setDisplayVersionString:(NSString *)s
|
||||
{
|
||||
if (displayVersionString == s) return;
|
||||
[displayVersionString release];
|
||||
displayVersionString = [s copy];
|
||||
}
|
||||
|
||||
|
||||
- (NSString *)minimumSystemVersion { return [[minimumSystemVersion retain] autorelease]; }
|
||||
- (void)setMinimumSystemVersion:(NSString *)systemVersionString
|
||||
{
|
||||
if (minimumSystemVersion == systemVersionString) return;
|
||||
[minimumSystemVersion release];
|
||||
minimumSystemVersion = [systemVersionString copy];
|
||||
return [[propertiesDictionary objectForKey:@"sparkle:tags"] containsObject:@"sparkle:criticalUpdate"];
|
||||
}
|
||||
|
||||
- initWithDictionary:(NSDictionary *)dict
|
||||
{
|
||||
return [self initWithDictionary:dict failureReason:nil];
|
||||
}
|
||||
|
||||
- initWithDictionary:(NSDictionary *)dict failureReason:(NSString**)error
|
||||
{
|
||||
self = [super init];
|
||||
if (self)
|
||||
{
|
||||
propertiesDictionary = [dict retain];
|
||||
[self setTitle:[dict objectForKey:@"title"]];
|
||||
[self setDate:[dict objectForKey:@"pubDate"]];
|
||||
[self setDescription:[dict objectForKey:@"description"]];
|
||||
|
||||
id enclosure = [dict objectForKey:@"enclosure"];
|
||||
if (enclosure == nil || [enclosure objectForKey:@"url"] == nil)
|
||||
[NSException raise:@"SUAppcastException" format:@"Couldn't find an download URL for feed entry %@!", [self title]];
|
||||
[self setFileURL:[NSURL URLWithString:[[enclosure objectForKey:@"url"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
|
||||
[self setDSASignature:[enclosure objectForKey:@"sparkle:dsaSignature"]];
|
||||
|
||||
// Try to find a version string.
|
||||
// Finding the new version number from the RSS feed is a little bit hacky. There are two ways:
|
||||
@@ -126,46 +74,116 @@
|
||||
// The big caveat with this is that you can't have underscores in your version strings, as that'll confuse Sparkle.
|
||||
// Feel free to change the separator string to a hyphen or something more suited to your needs if you like.
|
||||
NSString *newVersion = [enclosure objectForKey:@"sparkle:version"];
|
||||
if (!newVersion) // no sparkle:version attribute
|
||||
if( newVersion == nil )
|
||||
newVersion = [dict objectForKey:@"sparkle:version"]; // UK 2007-08-31 Get version from the item, in case it's a download-less item (i.e. paid upgrade).
|
||||
if (newVersion == nil) // no sparkle:version attribute anywhere?
|
||||
{
|
||||
// Separate the url by underscores and take the last component, as that'll be closest to the end,
|
||||
// then we remove the extension. Hopefully, this will be the version.
|
||||
NSArray *fileComponents = [[enclosure objectForKey:@"url"] componentsSeparatedByString:@"_"];
|
||||
if ([fileComponents count] > 1)
|
||||
newVersion = [[fileComponents lastObject] stringByDeletingPathExtension];
|
||||
else
|
||||
[NSException raise:@"SUAppcastException" format:@"Couldn't find a version string for %@! You need a sparkle:version attribute.", [enclosure objectForKey:@"url"]];
|
||||
}
|
||||
[self setVersionString:newVersion];
|
||||
[self setMinimumSystemVersion:[dict objectForKey:@"sparkle:minimumSystemVersion"]];
|
||||
|
||||
if(!newVersion )
|
||||
{
|
||||
if (error)
|
||||
*error = @"Feed item lacks sparkle:version attribute, and version couldn't be deduced from file name (would have used last component of a file name like AppName_1.3.4.zip)";
|
||||
[self release];
|
||||
return nil;
|
||||
}
|
||||
|
||||
propertiesDictionary = [[NSMutableDictionary alloc] initWithDictionary:dict];
|
||||
self.title = [dict objectForKey:@"title"];
|
||||
self.date = [dict objectForKey:@"pubDate"];
|
||||
self.itemDescription = [dict objectForKey:@"description"];
|
||||
|
||||
NSString* theInfoURL = [dict objectForKey:@"link"];
|
||||
if( theInfoURL )
|
||||
{
|
||||
if( ![theInfoURL isKindOfClass: [NSString class]] )
|
||||
SULog(@"SUAppcastItem -initWithDictionary: Info URL is not of valid type.");
|
||||
else
|
||||
self.infoURL = [NSURL URLWithString:theInfoURL];
|
||||
}
|
||||
|
||||
// Need an info URL or an enclosure URL. Former to show "More Info"
|
||||
// page, latter to download & install:
|
||||
if( !enclosure && !theInfoURL )
|
||||
{
|
||||
if (error)
|
||||
*error = @"No enclosure in feed item";
|
||||
[self release];
|
||||
return nil;
|
||||
}
|
||||
|
||||
NSString* enclosureURLString = [enclosure objectForKey:@"url"];
|
||||
if( !enclosureURLString && !theInfoURL )
|
||||
{
|
||||
if (error)
|
||||
*error = @"Feed item's enclosure lacks URL";
|
||||
[self release];
|
||||
return nil;
|
||||
}
|
||||
|
||||
if( enclosureURLString )
|
||||
self.fileURL = [NSURL URLWithString: [enclosureURLString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
|
||||
if( enclosure )
|
||||
self.DSASignature = [enclosure objectForKey:@"sparkle:dsaSignature"];
|
||||
|
||||
self.versionString = newVersion;
|
||||
self.minimumSystemVersion = [dict objectForKey:@"sparkle:minimumSystemVersion"];
|
||||
self.maximumSystemVersion = [dict objectForKey:@"sparkle:maximumSystemVersion"];
|
||||
|
||||
NSString *shortVersionString = [enclosure objectForKey:@"sparkle:shortVersionString"];
|
||||
if (nil == shortVersionString)
|
||||
shortVersionString = [dict objectForKey:@"sparkle:shortVersionString"]; // fall back on the <item>
|
||||
|
||||
if (shortVersionString)
|
||||
[self setDisplayVersionString:shortVersionString];
|
||||
self.displayVersionString = shortVersionString;
|
||||
else
|
||||
[self setDisplayVersionString:[self versionString]];
|
||||
self.displayVersionString = [self versionString];
|
||||
|
||||
// Find the appropriate release notes URL.
|
||||
if ([dict objectForKey:@"sparkle:releaseNotesLink"])
|
||||
[self setReleaseNotesURL:[NSURL URLWithString:[dict objectForKey:@"sparkle:releaseNotesLink"]]];
|
||||
else if ([[self description] hasPrefix:@"http://"]) // if the description starts with http://, use that.
|
||||
[self setReleaseNotesURL:[NSURL URLWithString:[self description]]];
|
||||
self.releaseNotesURL = [NSURL URLWithString:[dict objectForKey:@"sparkle:releaseNotesLink"]];
|
||||
else if ([self.itemDescription hasPrefix:@"http://"] || [self.itemDescription hasPrefix:@"https://"]) // if the description starts with http:// or https:// use that.
|
||||
self.releaseNotesURL = [NSURL URLWithString:self.itemDescription];
|
||||
else
|
||||
[self setReleaseNotesURL:nil];
|
||||
self.releaseNotesURL = nil;
|
||||
|
||||
if ([dict objectForKey:@"deltas"])
|
||||
{
|
||||
NSMutableDictionary *deltas = [NSMutableDictionary dictionary];
|
||||
NSArray *deltaDictionaries = [dict objectForKey:@"deltas"];
|
||||
for (NSDictionary *deltaDictionary in [deltaDictionaries objectEnumerator]) {
|
||||
NSMutableDictionary *fakeAppCastDict = [dict mutableCopy];
|
||||
[fakeAppCastDict removeObjectForKey:@"deltas"];
|
||||
[fakeAppCastDict setObject:deltaDictionary forKey:@"enclosure"];
|
||||
SUAppcastItem *deltaItem = [[[self class] alloc] initWithDictionary:fakeAppCastDict];
|
||||
[fakeAppCastDict release];
|
||||
|
||||
[deltas setObject:deltaItem forKey:[deltaDictionary objectForKey:@"sparkle:deltaFrom"]];
|
||||
[deltaItem release];
|
||||
}
|
||||
self.deltaUpdates = deltas;
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[self setTitle:nil];
|
||||
[self setDate:nil];
|
||||
[self setDescription:nil];
|
||||
[self setReleaseNotesURL:nil];
|
||||
[self setDSASignature:nil];
|
||||
[self setFileURL:nil];
|
||||
[self setVersionString:nil];
|
||||
[self setDisplayVersionString:nil];
|
||||
self.title = nil;
|
||||
self.date = nil;
|
||||
self.itemDescription = nil;
|
||||
self.releaseNotesURL = nil;
|
||||
self.DSASignature = nil;
|
||||
self.minimumSystemVersion = nil;
|
||||
self.fileURL = nil;
|
||||
self.versionString = nil;
|
||||
self.displayVersionString = nil;
|
||||
self.infoURL = nil;
|
||||
[propertiesDictionary release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
|
||||
#import "SUWindowController.h"
|
||||
|
||||
@protocol SUAutomaticUpdateAlertDelegateProtocol;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SUInstallNowChoice,
|
||||
@@ -18,21 +20,21 @@ typedef enum
|
||||
SUDoNotInstallChoice
|
||||
} SUAutomaticInstallationChoice;
|
||||
|
||||
@class SUAppcastItem;
|
||||
@class SUAppcastItem, SUHost;
|
||||
@interface SUAutomaticUpdateAlert : SUWindowController {
|
||||
SUAppcastItem *updateItem;
|
||||
id delegate;
|
||||
NSBundle *hostBundle;
|
||||
id<SUAutomaticUpdateAlertDelegateProtocol> delegate;
|
||||
SUHost *host;
|
||||
}
|
||||
|
||||
- (id)initWithAppcastItem:(SUAppcastItem *)item hostBundle:(NSBundle *)hostBundle delegate:delegate;
|
||||
- (id)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)hostBundle delegate:(id<SUAutomaticUpdateAlertDelegateProtocol>)delegate;
|
||||
- (IBAction)installNow:sender;
|
||||
- (IBAction)installLater:sender;
|
||||
- (IBAction)doNotInstall:sender;
|
||||
|
||||
@end
|
||||
|
||||
@interface NSObject (SUAutomaticUpdateAlertDelegateProtocol)
|
||||
@protocol SUAutomaticUpdateAlertDelegateProtocol <NSObject>
|
||||
- (void)automaticUpdateAlert:(SUAutomaticUpdateAlert *)aua finishedWithChoice:(SUAutomaticInstallationChoice)choice;
|
||||
@end
|
||||
|
||||
|
||||
@@ -6,19 +6,20 @@
|
||||
// Copyright 2006 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#import "Sparkle.h"
|
||||
#import "SUAutomaticUpdateAlert.h"
|
||||
|
||||
#import "SUHost.h"
|
||||
|
||||
@implementation SUAutomaticUpdateAlert
|
||||
|
||||
- (id)initWithAppcastItem:(SUAppcastItem *)item hostBundle:(NSBundle *)hb delegate:del;
|
||||
- (id)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost delegate:(id<SUAutomaticUpdateAlertDelegateProtocol>)del
|
||||
{
|
||||
self = [super initWithHostBundle:hb windowNibName:@"SUAutomaticUpdateAlert"];
|
||||
self = [super initWithHost:aHost windowNibName:@"SUAutomaticUpdateAlert"];
|
||||
if (self)
|
||||
{
|
||||
updateItem = [item retain];
|
||||
delegate = del;
|
||||
hostBundle = [hb retain];
|
||||
host = [aHost retain];
|
||||
[self setShouldCascadeWindows:NO];
|
||||
[[self window] center];
|
||||
}
|
||||
@@ -27,11 +28,12 @@
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[hostBundle release];
|
||||
[host release];
|
||||
[updateItem release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@, %@>", [self class], [host bundlePath], [host installationPath]]; }
|
||||
|
||||
- (IBAction)installNow:sender
|
||||
{
|
||||
@@ -53,17 +55,31 @@
|
||||
|
||||
- (NSImage *)applicationIcon
|
||||
{
|
||||
return [hostBundle icon];
|
||||
return [host icon];
|
||||
}
|
||||
|
||||
- (NSString *)titleText
|
||||
{
|
||||
return [NSString stringWithFormat:SULocalizedString(@"A new version of %@ is ready to install!", nil), [hostBundle name]];
|
||||
if ([updateItem isCriticalUpdate])
|
||||
{
|
||||
return [NSString stringWithFormat:SULocalizedString(@"An important update to %@ is ready to install", nil), [host name]];
|
||||
}
|
||||
else
|
||||
{
|
||||
return [NSString stringWithFormat:SULocalizedString(@"A new version of %@ is ready to install!", nil), [host name]];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)descriptionText
|
||||
{
|
||||
return [NSString stringWithFormat:SULocalizedString(@"%1$@ %2$@ has been downloaded and is ready to use! Would you like to install it and relaunch %1$@ now?", nil), [hostBundle name], [hostBundle displayVersion]];
|
||||
if ([updateItem isCriticalUpdate])
|
||||
{
|
||||
return [NSString stringWithFormat:SULocalizedString(@"%1$@ %2$@ has been downloaded and is ready to use! This is an important update; would you like to install it and relaunch %1$@ now?", nil), [host name], [updateItem displayVersionString]];
|
||||
}
|
||||
else
|
||||
{
|
||||
return [NSString stringWithFormat:SULocalizedString(@"%1$@ %2$@ has been downloaded and is ready to use! Would you like to install it and relaunch %1$@ now?", nil), [host name], [updateItem displayVersionString]];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -11,11 +11,15 @@
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "SUBasicUpdateDriver.h"
|
||||
#import "SUAutomaticUpdateAlert.h"
|
||||
|
||||
@class SUAutomaticUpdateAlert;
|
||||
@interface SUAutomaticUpdateDriver : SUBasicUpdateDriver {
|
||||
@interface SUAutomaticUpdateDriver : SUBasicUpdateDriver <SUUnarchiverDelegate, SUAutomaticUpdateAlertDelegateProtocol>
|
||||
{
|
||||
@private
|
||||
BOOL postponingInstallation, showErrors;
|
||||
BOOL willUpdateOnTermination;
|
||||
SUAutomaticUpdateAlert *alert;
|
||||
NSTimer *showUpdateAlertTimer;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
+109
-16
@@ -7,19 +7,113 @@
|
||||
//
|
||||
|
||||
#import "SUAutomaticUpdateDriver.h"
|
||||
#import "Sparkle.h"
|
||||
|
||||
#import "SUAutomaticUpdateAlert.h"
|
||||
#import "SUHost.h"
|
||||
#import "SUConstants.h"
|
||||
|
||||
// If the user hasn't quit in a week, ask them if they want to relaunch to get the latest bits. It doesn't matter that this measure of "one day" is imprecise.
|
||||
static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 24 * 7;
|
||||
|
||||
@implementation SUAutomaticUpdateDriver
|
||||
|
||||
- (void)unarchiverDidFinish:(SUUnarchiver *)ua
|
||||
- (void)showUpdateAlert
|
||||
{
|
||||
alert = [[SUAutomaticUpdateAlert alloc] initWithAppcastItem:updateItem hostBundle:hostBundle delegate:self];
|
||||
isInterruptible = NO;
|
||||
alert = [[SUAutomaticUpdateAlert alloc] initWithAppcastItem:updateItem host:host delegate:self];
|
||||
|
||||
// If the app is a menubar app or the like, we need to focus it first and alter the
|
||||
// update prompt to behave like a normal window. Otherwise if the window were hidden
|
||||
// there may be no way for the application to be activated to make it visible again.
|
||||
if ([host isBackgroundApplication])
|
||||
{
|
||||
[[alert window] setHidesOnDeactivate:NO];
|
||||
[NSApp activateIgnoringOtherApps:YES];
|
||||
}
|
||||
|
||||
if ([NSApp isActive])
|
||||
[[alert window] makeKeyAndOrderFront:self];
|
||||
else
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive:) name:NSApplicationDidBecomeActiveNotification object:NSApp];
|
||||
}
|
||||
|
||||
- (void)unarchiverDidFinish:(SUUnarchiver *)ua
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:NSApplicationWillTerminateNotification object:nil];
|
||||
|
||||
// Sudden termination is available on 10.6+
|
||||
NSProcessInfo *processInfo = [NSProcessInfo processInfo];
|
||||
if ([processInfo respondsToSelector:@selector(disableSuddenTermination)]) {
|
||||
[processInfo disableSuddenTermination];
|
||||
}
|
||||
|
||||
willUpdateOnTermination = YES;
|
||||
|
||||
if ([[updater delegate] respondsToSelector:@selector(updater:willInstallUpdateOnQuit:immediateInstallationInvocation:)])
|
||||
{
|
||||
BOOL relaunch = YES;
|
||||
BOOL showUI = NO;
|
||||
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[self class] instanceMethodSignatureForSelector:@selector(installWithToolAndRelaunch:displayingUserInterface:)]];
|
||||
[invocation setSelector:@selector(installWithToolAndRelaunch:displayingUserInterface:)];
|
||||
[invocation setArgument:&relaunch atIndex:2];
|
||||
[invocation setArgument:&showUI atIndex:3];
|
||||
[invocation setTarget:self];
|
||||
|
||||
[[updater delegate] updater:updater willInstallUpdateOnQuit:updateItem immediateInstallationInvocation:invocation];
|
||||
}
|
||||
|
||||
// If this is marked as a critical update, we'll prompt the user to install it right away.
|
||||
if ([updateItem isCriticalUpdate])
|
||||
{
|
||||
[self showUpdateAlert];
|
||||
}
|
||||
else
|
||||
{
|
||||
showUpdateAlertTimer = [[NSTimer scheduledTimerWithTimeInterval:SUAutomaticUpdatePromptImpatienceTimer target:self selector:@selector(showUpdateAlert) userInfo:nil repeats:NO] retain];
|
||||
|
||||
// At this point the driver is idle, allow it to be interrupted for user-initiated update checks.
|
||||
isInterruptible = YES;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)stopUpdatingOnTermination
|
||||
{
|
||||
if (willUpdateOnTermination)
|
||||
{
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSApplicationWillTerminateNotification object:nil];
|
||||
NSProcessInfo *processInfo = [NSProcessInfo processInfo];
|
||||
if ([processInfo respondsToSelector:@selector(enableSuddenTermination)]) {
|
||||
[processInfo enableSuddenTermination];
|
||||
}
|
||||
willUpdateOnTermination = NO;
|
||||
|
||||
if ([[updater delegate] respondsToSelector:@selector(updater:didCancelInstallUpdateOnQuit:)])
|
||||
[[updater delegate] updater:updater didCancelInstallUpdateOnQuit:updateItem];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)invalidateShowUpdateAlertTimer
|
||||
{
|
||||
[showUpdateAlertTimer invalidate];
|
||||
[showUpdateAlertTimer release];
|
||||
showUpdateAlertTimer = nil;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[self stopUpdatingOnTermination];
|
||||
[self invalidateShowUpdateAlertTimer];
|
||||
[alert release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void)abortUpdate
|
||||
{
|
||||
[self stopUpdatingOnTermination];
|
||||
[self invalidateShowUpdateAlertTimer];
|
||||
[super abortUpdate];
|
||||
}
|
||||
|
||||
- (void)applicationDidBecomeActive:(NSNotification *)aNotification
|
||||
{
|
||||
[[alert window] makeKeyAndOrderFront:self];
|
||||
@@ -31,16 +125,19 @@
|
||||
switch (choice)
|
||||
{
|
||||
case SUInstallNowChoice:
|
||||
[self installUpdate];
|
||||
[self stopUpdatingOnTermination];
|
||||
[self installWithToolAndRelaunch:YES];
|
||||
break;
|
||||
|
||||
case SUInstallLaterChoice:
|
||||
postponingInstallation = YES;
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:NSApplicationWillTerminateNotification object:nil];
|
||||
// We're already waiting on quit, just indicate that we're idle.
|
||||
isInterruptible = YES;
|
||||
break;
|
||||
|
||||
case SUDoNotInstallChoice:
|
||||
[[SUUserDefaults standardUserDefaults] setObject:[updateItem versionString] forKey:SUSkippedVersionKey];
|
||||
[host setObject:[updateItem versionString] forUserDefaultsKey:SUSkippedVersionKey];
|
||||
[self abortUpdate];
|
||||
break;
|
||||
}
|
||||
@@ -48,22 +145,18 @@
|
||||
|
||||
- (BOOL)shouldInstallSynchronously { return postponingInstallation; }
|
||||
|
||||
- (void)installUpdate
|
||||
- (void)installWithToolAndRelaunch:(BOOL)relaunch displayingUserInterface:(BOOL)showUI
|
||||
{
|
||||
showErrors = YES;
|
||||
[super installUpdate];
|
||||
if (relaunch)
|
||||
[self stopUpdatingOnTermination];
|
||||
|
||||
showErrors = YES;
|
||||
[super installWithToolAndRelaunch:relaunch displayingUserInterface:showUI];
|
||||
}
|
||||
|
||||
- (void)applicationWillTerminate:(NSNotification *)note
|
||||
{
|
||||
[self installUpdate];
|
||||
}
|
||||
|
||||
- (void)installerFinishedForHostBundle:(NSBundle *)hb
|
||||
{
|
||||
if (hb != hostBundle) { return; }
|
||||
if (!postponingInstallation)
|
||||
[self relaunchHostApp];
|
||||
[self installWithToolAndRelaunch:NO];
|
||||
}
|
||||
|
||||
- (void)abortUpdateWithError:(NSError *)error
|
||||
|
||||
+12
-12
@@ -11,22 +11,22 @@
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "SUUpdateDriver.h"
|
||||
#import "SUUnarchiver.h"
|
||||
#import "SUAppcast.h"
|
||||
|
||||
@class SUAppcastItem, SUUnarchiver, SUAppcast, SUUnarchiver;
|
||||
@interface SUBasicUpdateDriver : SUUpdateDriver {
|
||||
NSBundle *hostBundle;
|
||||
@class SUAppcastItem, SUHost;
|
||||
@interface SUBasicUpdateDriver : SUUpdateDriver<NSURLDownloadDelegate, SUUnarchiverDelegate, SUAppcastDelegate> {
|
||||
SUAppcastItem *updateItem;
|
||||
SUAppcastItem *nonDeltaUpdateItem;
|
||||
|
||||
NSURLDownload *download;
|
||||
NSString *downloadPath;
|
||||
NSString *tempDir;
|
||||
|
||||
NSString *relaunchPath;
|
||||
}
|
||||
|
||||
- (void)checkForUpdatesAtURL:(NSURL *)appcastURL hostBundle:(NSBundle *)hb;
|
||||
|
||||
- (void)appcastDidFinishLoading:(SUAppcast *)ac;
|
||||
- (void)appcast:(SUAppcast *)ac failedToLoadWithError:(NSError *)error;
|
||||
- (void)checkForUpdatesAtURL:(NSURL *)URL host:(SUHost *)host;
|
||||
|
||||
- (BOOL)isItemNewer:(SUAppcastItem *)ui;
|
||||
- (BOOL)hostSupportsItem:(SUAppcastItem *)ui;
|
||||
@@ -43,13 +43,13 @@
|
||||
- (void)extractUpdate;
|
||||
- (void)unarchiverDidFinish:(SUUnarchiver *)ua;
|
||||
- (void)unarchiverDidFail:(SUUnarchiver *)ua;
|
||||
- (void)failedToApplyDeltaUpdate;
|
||||
|
||||
- (void)installUpdate;
|
||||
- (void)installerFinishedForHostBundle:(NSBundle *)hb;
|
||||
- (void)installerForHostBundle:(NSBundle *)hb failedWithError:(NSError *)error;
|
||||
- (void)installWithToolAndRelaunch:(BOOL)relaunch;
|
||||
- (void)installWithToolAndRelaunch:(BOOL)relaunch displayingUserInterface:(BOOL)showUI;
|
||||
- (void)installerForHost:(SUHost *)host failedWithError:(NSError *)error;
|
||||
|
||||
- (void)relaunchHostApp;
|
||||
- (void)cleanUp;
|
||||
- (void)cleanUpDownload;
|
||||
|
||||
- (void)abortUpdate;
|
||||
- (void)abortUpdateWithError:(NSError *)error;
|
||||
|
||||
+271
-120
@@ -7,17 +7,50 @@
|
||||
//
|
||||
|
||||
#import "SUBasicUpdateDriver.h"
|
||||
#import "Sparkle.h"
|
||||
|
||||
#import "SUHost.h"
|
||||
#import "SUDSAVerifier.h"
|
||||
#import "SUInstaller.h"
|
||||
#import "SUStandardVersionComparator.h"
|
||||
#import "SUUnarchiver.h"
|
||||
#import "SUConstants.h"
|
||||
#import "SULog.h"
|
||||
#import "SUPlainInstaller.h"
|
||||
#import "SUPlainInstallerInternals.h"
|
||||
#import "SUBinaryDeltaCommon.h"
|
||||
#import "SUCodeSigningVerifier.h"
|
||||
#import "SUUpdater_Private.h"
|
||||
|
||||
#ifdef FINISH_INSTALL_TOOL_NAME
|
||||
// FINISH_INSTALL_TOOL_NAME expands to unquoted finish_install
|
||||
#define QUOTE_NS_STRING2(str) @"" #str
|
||||
#define QUOTE_NS_STRING1(str) QUOTE_NS_STRING2(str)
|
||||
#define FINISH_INSTALL_TOOL_NAME_STRING QUOTE_NS_STRING1(FINISH_INSTALL_TOOL_NAME)
|
||||
#else
|
||||
#error FINISH_INSTALL_TOOL_NAME not defined
|
||||
#endif
|
||||
|
||||
@interface SUBasicUpdateDriver () <NSURLDownloadDelegate>; @end
|
||||
|
||||
|
||||
@interface SUBasicUpdateDriver () <NSURLDownloadDelegate>
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@interface SUBasicUpdateDriver () <NSURLDownloadDelegate>
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation SUBasicUpdateDriver
|
||||
|
||||
- (void)checkForUpdatesAtURL:(NSURL *)appcastURL hostBundle:(NSBundle *)hb
|
||||
- (void)checkForUpdatesAtURL:(NSURL *)URL host:(SUHost *)aHost
|
||||
{
|
||||
hostBundle = [hb retain];
|
||||
|
||||
if ([hostBundle isRunningFromDiskImage])
|
||||
[super checkForUpdatesAtURL:URL host:aHost];
|
||||
if ([aHost isRunningOnReadOnlyVolume])
|
||||
{
|
||||
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURunningFromDiskImageError userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:SULocalizedString(@"%1$@ can't be updated when it's running from a disk image. Move %1$@ to your Applications folder, relaunch it from there, and try again.", nil), [hostBundle name]] forKey:NSLocalizedDescriptionKey]]];
|
||||
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURunningFromDiskImageError userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:SULocalizedString(@"%1$@ can't be updated when it's running from a read-only volume like a disk image or an optical drive. Move %1$@ to your Applications folder, relaunch it from there, and try again.", nil), [aHost name]] forKey:NSLocalizedDescriptionKey]]];
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -26,29 +59,54 @@
|
||||
[appcast release];
|
||||
|
||||
[appcast setDelegate:self];
|
||||
[appcast setUserAgentString:[NSString stringWithFormat: @"%@/%@ Sparkle/1.5b2", [hostBundle name], [hostBundle displayVersion]]];
|
||||
[appcast fetchAppcastFromURL:appcastURL];
|
||||
[appcast setUserAgentString:[updater userAgentString]];
|
||||
[appcast fetchAppcastFromURL:URL];
|
||||
}
|
||||
|
||||
- (id <SUVersionComparison>)versionComparator
|
||||
{
|
||||
id <SUVersionComparison> comparator = nil;
|
||||
|
||||
// Give the delegate a chance to provide a custom version comparator
|
||||
if ([[updater delegate] respondsToSelector:@selector(versionComparatorForUpdater:)])
|
||||
comparator = [[updater delegate] versionComparatorForUpdater:updater];
|
||||
|
||||
// If we don't get a comparator from the delegate, use the default comparator
|
||||
if (!comparator)
|
||||
comparator = [SUStandardVersionComparator defaultComparator];
|
||||
|
||||
return comparator;
|
||||
}
|
||||
|
||||
- (BOOL)isItemNewer:(SUAppcastItem *)ui
|
||||
{
|
||||
return [[SUStandardVersionComparator defaultComparator] compareVersion:[hostBundle version]
|
||||
toVersion:[ui versionString]] == NSOrderedAscending;
|
||||
return [[self versionComparator] compareVersion:[host version] toVersion:[ui versionString]] == NSOrderedAscending;
|
||||
}
|
||||
|
||||
- (BOOL)hostSupportsItem:(SUAppcastItem *)ui
|
||||
{
|
||||
if ([ui minimumSystemVersion] == nil || [[ui minimumSystemVersion] isEqualToString:@""]) { return YES; }
|
||||
return [[SUStandardVersionComparator defaultComparator] compareVersion:[ui minimumSystemVersion]
|
||||
toVersion:[NSWorkspace systemVersionString]] != NSOrderedDescending;
|
||||
if (([ui minimumSystemVersion] == nil || [[ui minimumSystemVersion] isEqualToString:@""]) &&
|
||||
([ui maximumSystemVersion] == nil || [[ui maximumSystemVersion] isEqualToString:@""])) { return YES; }
|
||||
|
||||
BOOL minimumVersionOK = TRUE;
|
||||
BOOL maximumVersionOK = TRUE;
|
||||
|
||||
// Check minimum and maximum System Version
|
||||
if ([ui minimumSystemVersion] != nil && ![[ui minimumSystemVersion] isEqualToString:@""]) {
|
||||
minimumVersionOK = [[SUStandardVersionComparator defaultComparator] compareVersion:[ui minimumSystemVersion] toVersion:[SUHost systemVersionString]] != NSOrderedDescending;
|
||||
}
|
||||
if ([ui maximumSystemVersion] != nil && ![[ui maximumSystemVersion] isEqualToString:@""]) {
|
||||
maximumVersionOK = [[SUStandardVersionComparator defaultComparator] compareVersion:[ui maximumSystemVersion] toVersion:[SUHost systemVersionString]] != NSOrderedAscending;
|
||||
}
|
||||
|
||||
return minimumVersionOK && maximumVersionOK;
|
||||
}
|
||||
|
||||
- (BOOL)itemContainsSkippedVersion:(SUAppcastItem *)ui
|
||||
{
|
||||
NSString *skippedVersion = [[SUUserDefaults standardUserDefaults] objectForKey:SUSkippedVersionKey];
|
||||
NSString *skippedVersion = [host objectForUserDefaultsKey:SUSkippedVersionKey];
|
||||
if (skippedVersion == nil) { return NO; }
|
||||
return [[SUStandardVersionComparator defaultComparator] compareVersion:[ui versionString]
|
||||
toVersion:skippedVersion] != NSOrderedDescending;
|
||||
return [[self versionComparator] compareVersion:[ui versionString] toVersion:skippedVersion] != NSOrderedDescending;
|
||||
}
|
||||
|
||||
- (BOOL)itemContainsValidUpdate:(SUAppcastItem *)ui
|
||||
@@ -58,29 +116,38 @@
|
||||
|
||||
- (void)appcastDidFinishLoading:(SUAppcast *)ac
|
||||
{
|
||||
if ([delegate respondsToSelector:@selector(appcastDidFinishLoading:forHostBundle:)])
|
||||
[delegate appcastDidFinishLoading:ac forHostBundle:hostBundle];
|
||||
|
||||
NSArray* updates = [ac items];
|
||||
if ([updates count] > 0)
|
||||
[[SUUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:SULastCheckTimeKey];
|
||||
if ([[updater delegate] respondsToSelector:@selector(updater:didFinishLoadingAppcast:)])
|
||||
[[updater delegate] updater:updater didFinishLoadingAppcast:ac];
|
||||
|
||||
NSDictionary *userInfo = (ac != nil) ? @{SUUpdaterAppcastNotificationKey : ac} : nil;
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidFinishLoadingAppCastNotification object:updater userInfo:userInfo];
|
||||
|
||||
SUAppcastItem *item = nil;
|
||||
|
||||
// Now we have to find the best valid update in the appcast.
|
||||
if ([delegate respondsToSelector:@selector(bestValidUpdateInAppcast:forHostBundle:)]) // Does the delegate want to handle it?
|
||||
if ([[updater delegate] respondsToSelector:@selector(bestValidUpdateInAppcast:forUpdater:)]) // Does the delegate want to handle it?
|
||||
{
|
||||
updateItem = [delegate bestValidUpdateInAppcast:ac forHostBundle:hostBundle];
|
||||
item = [[updater delegate] bestValidUpdateInAppcast:ac forUpdater:updater];
|
||||
}
|
||||
else // If not, we'll take care of it ourselves.
|
||||
{
|
||||
// Find the first update we can actually use.
|
||||
NSEnumerator *updateEnumerator = [updates objectEnumerator];
|
||||
NSEnumerator *updateEnumerator = [[ac items] objectEnumerator];
|
||||
do {
|
||||
updateItem = [updateEnumerator nextObject];
|
||||
} while (updateItem && ![self hostSupportsItem:updateItem]);
|
||||
|
||||
[updateItem retain];
|
||||
item = [updateEnumerator nextObject];
|
||||
} while (item && ![self hostSupportsItem:item]);
|
||||
|
||||
if (binaryDeltaSupported()) {
|
||||
SUAppcastItem *deltaUpdateItem = [[item deltaUpdates] objectForKey:[host version]];
|
||||
if (deltaUpdateItem && [self hostSupportsItem:deltaUpdateItem]) {
|
||||
nonDeltaUpdateItem = [item retain];
|
||||
item = deltaUpdateItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
CFRelease(ac); // Remember that we're explicitly managing the memory of the appcast.
|
||||
|
||||
updateItem = [item retain];
|
||||
if (ac) { CFRelease(ac); } // Remember that we're explicitly managing the memory of the appcast.
|
||||
if (updateItem == nil) { [self didNotFindUpdate]; return; }
|
||||
|
||||
if ([self itemContainsValidUpdate:updateItem])
|
||||
@@ -91,27 +158,33 @@
|
||||
|
||||
- (void)appcast:(SUAppcast *)ac failedToLoadWithError:(NSError *)error
|
||||
{
|
||||
CFRelease(ac); // Remember that we're explicitly managing the memory of the appcast.
|
||||
if (ac) { CFRelease(ac); } // Remember that we're explicitly managing the memory of the appcast.
|
||||
[self abortUpdateWithError:error];
|
||||
}
|
||||
|
||||
- (void)didFindValidUpdate
|
||||
{
|
||||
if ([delegate respondsToSelector:@selector(didFindValidUpdate:toHostBundle:)])
|
||||
[delegate didFindValidUpdate:updateItem toHostBundle:hostBundle];
|
||||
if ([[updater delegate] respondsToSelector:@selector(updater:didFindValidUpdate:)])
|
||||
[[updater delegate] updater:updater didFindValidUpdate:updateItem];
|
||||
NSDictionary *userInfo = (updateItem != nil) ? @{SUUpdaterAppcastItemNotificationKey : updateItem} : nil;
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidFinishLoadingAppCastNotification object:updater userInfo:userInfo];
|
||||
[self downloadUpdate];
|
||||
}
|
||||
|
||||
- (void)didNotFindUpdate
|
||||
{
|
||||
if ([delegate respondsToSelector:@selector(didNotFindUpdateToHostBundle:)])
|
||||
[delegate didNotFindUpdateToHostBundle:hostBundle];
|
||||
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUNoUpdateError userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:SULocalizedString(@"You already have the newest version of %@.", nil), [hostBundle name]] forKey:NSLocalizedDescriptionKey]]];
|
||||
if ([[updater delegate] respondsToSelector:@selector(updaterDidNotFindUpdate:)])
|
||||
[[updater delegate] updaterDidNotFindUpdate:updater];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidNotFindUpdateNotification object:updater];
|
||||
|
||||
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUNoUpdateError userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:SULocalizedString(@"You already have the newest version of %@.", nil), [host name]] forKey:NSLocalizedDescriptionKey]]];
|
||||
}
|
||||
|
||||
- (void)downloadUpdate
|
||||
{
|
||||
download = [[NSURLDownload alloc] initWithRequest:[NSURLRequest requestWithURL:[updateItem fileURL]] delegate:self];
|
||||
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[updateItem fileURL]];
|
||||
[request setValue:[updater userAgentString] forHTTPHeaderField:@"User-Agent"];
|
||||
download = [[NSURLDownload alloc] initWithRequest:request delegate:self];
|
||||
}
|
||||
|
||||
- (void)download:(NSURLDownload *)d decideDestinationWithSuggestedFilename:(NSString *)name
|
||||
@@ -120,17 +193,23 @@
|
||||
if ([[name pathExtension] isEqualToString:@"txt"])
|
||||
name = [name stringByDeletingPathExtension];
|
||||
|
||||
// We create a temporary directory in /tmp and stick the file there.
|
||||
// Not using a GUID here because hdiutil for some reason chokes on GUIDs. Too long? I really have no idea.
|
||||
NSString *prefix = [NSString stringWithFormat:@"%@ %@ Update", [hostBundle name], [hostBundle version]];
|
||||
NSString *tempDir = [NSTemporaryDirectory() stringByAppendingPathComponent:prefix];
|
||||
NSString *downloadFileName = [NSString stringWithFormat:@"%@ %@", [host name], [updateItem versionString]];
|
||||
|
||||
|
||||
[tempDir release];
|
||||
tempDir = [[[host appSupportPath] stringByAppendingPathComponent:downloadFileName] retain];
|
||||
int cnt=1;
|
||||
while ([[NSFileManager defaultManager] fileExistsAtPath:tempDir] && cnt <= 999999)
|
||||
tempDir = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"%@ %d", prefix, cnt++]];
|
||||
BOOL success = [[NSFileManager defaultManager] createDirectoryAtPath:tempDir attributes:nil];
|
||||
while ([[NSFileManager defaultManager] fileExistsAtPath:tempDir] && cnt <= 999)
|
||||
{
|
||||
[tempDir release];
|
||||
tempDir = [[[host appSupportPath] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@ %d", downloadFileName, cnt++]] retain];
|
||||
}
|
||||
|
||||
// Create the temporary directory if necessary.
|
||||
BOOL success = [[NSFileManager defaultManager] createDirectoryAtPath:tempDir withIntermediateDirectories:YES attributes:nil error:NULL];
|
||||
if (!success)
|
||||
{
|
||||
// Okay, something's really broken with /tmp
|
||||
// Okay, something's really broken with this user's file structure.
|
||||
[download cancel];
|
||||
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUTemporaryDirectoryError userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Can't make a temporary directory for the update download at %@.",tempDir] forKey:NSLocalizedDescriptionKey]]];
|
||||
}
|
||||
@@ -139,35 +218,45 @@
|
||||
[download setDestination:downloadPath allowOverwrite:YES];
|
||||
}
|
||||
|
||||
- (void)downloadDidFinish:(NSURLDownload *)d
|
||||
- (BOOL)validateUpdateDownloadedToPath:(NSString *)downloadedPath extractedToPath:(NSString *)extractedPath DSASignature:(NSString *)DSASignature publicDSAKey:(NSString *)publicDSAKey
|
||||
{
|
||||
NSString *newBundlePath = [SUInstaller appPathInUpdateFolder:extractedPath forHost:host];
|
||||
if (newBundlePath)
|
||||
{
|
||||
NSError *error = nil;
|
||||
if ([SUCodeSigningVerifier codeSignatureIsValidAtPath:newBundlePath error:&error]) {
|
||||
return YES;
|
||||
} else {
|
||||
SULog(@"Code signature check on update failed: %@", error);
|
||||
}
|
||||
}
|
||||
|
||||
return [SUDSAVerifier validatePath:downloadedPath withEncodedDSASignature:DSASignature withPublicDSAKey:publicDSAKey];
|
||||
}
|
||||
|
||||
- (void)downloadDidFinish:(NSURLDownload *)d
|
||||
{
|
||||
[self extractUpdate];
|
||||
}
|
||||
|
||||
- (void)download:(NSURLDownload *)download didFailWithError:(NSError *)error
|
||||
{
|
||||
// Get rid of what we've downloaded so far, if anything.
|
||||
if (downloadPath != nil)
|
||||
[[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation source:[downloadPath stringByDeletingLastPathComponent] destination:@"" files:[NSArray arrayWithObject:[downloadPath lastPathComponent]] tag:NULL];
|
||||
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURelaunchError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:SULocalizedString(@"An error occurred while downloading the update. Please try again later.", nil), NSLocalizedDescriptionKey, [error localizedDescription], NSLocalizedFailureReasonErrorKey, nil]]];
|
||||
}
|
||||
|
||||
- (void)extractUpdate
|
||||
- (BOOL)download:(NSURLDownload *)download shouldDecodeSourceDataOfMIMEType:(NSString *)encodingType
|
||||
{
|
||||
// DSA verification, if activated by the developer
|
||||
if ([[hostBundle objectForInfoDictionaryKey:SUExpectsDSASignatureKey] boolValue])
|
||||
{
|
||||
if (![[NSFileManager defaultManager] validatePath:downloadPath withEncodedDSASignature:[updateItem DSASignature] withPublicDSAKey:[hostBundle publicDSAKey]])
|
||||
{
|
||||
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUSignatureError userInfo:[NSDictionary dictionaryWithObject:@"The update is improperly signed." forKey:NSLocalizedDescriptionKey]]];
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
SUUnarchiver *unarchiver = [SUUnarchiver unarchiverForURL:[[[NSURL alloc] initFileURLWithPath:downloadPath] autorelease]];
|
||||
// We don't want the download system to extract our gzips.
|
||||
// Note that we use a substring matching here instead of direct comparison because the docs say "application/gzip" but the system *uses* "application/x-gzip". This is a documentation bug.
|
||||
return ([encodingType rangeOfString:@"gzip"].location == NSNotFound);
|
||||
}
|
||||
|
||||
- (void)extractUpdate
|
||||
{
|
||||
SUUnarchiver *unarchiver = [SUUnarchiver unarchiverForPath:downloadPath updatingHost:host];
|
||||
if (!unarchiver)
|
||||
{
|
||||
NSLog(@"Sparkle Error: No valid unarchiver for %@!", downloadPath);
|
||||
SULog(@"Sparkle Error: No valid unarchiver for %@!", downloadPath);
|
||||
[self unarchiverDidFail:nil];
|
||||
return;
|
||||
}
|
||||
@@ -176,88 +265,145 @@
|
||||
[unarchiver start];
|
||||
}
|
||||
|
||||
- (void)failedToApplyDeltaUpdate
|
||||
{
|
||||
// When a delta update fails to apply we fall back on updating via a full install.
|
||||
[updateItem release];
|
||||
updateItem = nonDeltaUpdateItem;
|
||||
nonDeltaUpdateItem = nil;
|
||||
|
||||
[self downloadUpdate];
|
||||
}
|
||||
|
||||
- (void)unarchiverDidFinish:(SUUnarchiver *)ua
|
||||
{
|
||||
if (ua) { CFRelease(ua); }
|
||||
[self installUpdate];
|
||||
[self installWithToolAndRelaunch:YES];
|
||||
}
|
||||
|
||||
- (void)unarchiverDidFail:(SUUnarchiver *)ua
|
||||
{
|
||||
if (ua) { CFRelease(ua); }
|
||||
|
||||
if ([updateItem isDeltaUpdate]) {
|
||||
[self failedToApplyDeltaUpdate];
|
||||
return;
|
||||
}
|
||||
|
||||
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:[NSDictionary dictionaryWithObject:SULocalizedString(@"An error occurred while extracting the archive. Please try again later.", nil) forKey:NSLocalizedDescriptionKey]]];
|
||||
}
|
||||
|
||||
- (BOOL)shouldInstallSynchronously { return NO; }
|
||||
|
||||
- (void)installUpdate
|
||||
- (void)installWithToolAndRelaunch:(BOOL)relaunch
|
||||
{
|
||||
if ([delegate respondsToSelector:@selector(updateWillInstall:toHostBundle:)])
|
||||
[delegate updateWillInstall:updateItem toHostBundle:hostBundle];
|
||||
// Perhaps a poor assumption but: if we're not relaunching, we assume we shouldn't be showing any UI either. Because non-relaunching installations are kicked off without any user interaction, we shouldn't be interrupting them.
|
||||
[self installWithToolAndRelaunch:relaunch displayingUserInterface:relaunch];
|
||||
}
|
||||
|
||||
- (void)installWithToolAndRelaunch:(BOOL)relaunch displayingUserInterface:(BOOL)showUI
|
||||
{
|
||||
#if !ENDANGER_USERS_WITH_INSECURE_UPDATES
|
||||
if (![self validateUpdateDownloadedToPath:downloadPath extractedToPath:tempDir DSASignature:[updateItem DSASignature] publicDSAKey:[host publicDSAKey]])
|
||||
{
|
||||
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUSignatureError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:SULocalizedString(@"An error occurred while extracting the archive. Please try again later.", nil), NSLocalizedDescriptionKey, @"The update is improperly signed.", NSLocalizedFailureReasonErrorKey, nil]]];
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (![updater mayUpdateAndRestart])
|
||||
{
|
||||
[self abortUpdate];
|
||||
return;
|
||||
}
|
||||
|
||||
// Give the host app an opportunity to postpone the install and relaunch.
|
||||
static BOOL postponedOnce = NO;
|
||||
if (!postponedOnce && [[updater delegate] respondsToSelector:@selector(updater:shouldPostponeRelaunchForUpdate:untilInvoking:)])
|
||||
{
|
||||
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[self class] instanceMethodSignatureForSelector:@selector(installWithToolAndRelaunch:)]];
|
||||
[invocation setSelector:@selector(installWithToolAndRelaunch:)];
|
||||
[invocation setArgument:&relaunch atIndex:2];
|
||||
[invocation setTarget:self];
|
||||
postponedOnce = YES;
|
||||
if ([[updater delegate] updater:updater shouldPostponeRelaunchForUpdate:updateItem untilInvoking:invocation])
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if ([[updater delegate] respondsToSelector:@selector(updater:willInstallUpdate:)])
|
||||
[[updater delegate] updater:updater willInstallUpdate:updateItem];
|
||||
|
||||
NSString *const finishInstallToolName = FINISH_INSTALL_TOOL_NAME_STRING;
|
||||
|
||||
// Copy the relauncher into a temporary directory so we can get to it after the new version's installed.
|
||||
NSString *relaunchPathToCopy = [[NSBundle bundleForClass:[self class]] pathForResource:@"relaunch" ofType:@""];
|
||||
NSString *targetPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[relaunchPathToCopy lastPathComponent]];
|
||||
// Only the paranoid survive: if there's already a stray copy of relaunch there, we would have problems
|
||||
[[NSFileManager defaultManager] removeFileAtPath:targetPath handler:nil];
|
||||
if ([[NSFileManager defaultManager] copyPath:relaunchPathToCopy toPath:targetPath handler:nil])
|
||||
relaunchPath = [targetPath retain];
|
||||
|
||||
[SUInstaller installFromUpdateFolder:[downloadPath stringByDeletingLastPathComponent] overHostBundle:hostBundle delegate:self synchronously:[self shouldInstallSynchronously]];
|
||||
}
|
||||
|
||||
- (void)installerFinishedForHostBundle:(NSBundle *)hb
|
||||
{
|
||||
if (hb != hostBundle) { return; }
|
||||
[self relaunchHostApp];
|
||||
}
|
||||
|
||||
- (void)relaunchHostApp
|
||||
{
|
||||
// Give the host app an opportunity to postpone the relaunch.
|
||||
static BOOL postponedOnce = NO;
|
||||
if (!postponedOnce && [delegate respondsToSelector:@selector(shouldPostponeRelaunchForUpdate:toHostBundle:untilInvoking:)])
|
||||
// Only the paranoid survive: if there's already a stray copy of relaunch there, we would have problems.
|
||||
NSString *relaunchPathToCopy = [SPARKLE_BUNDLE pathForResource:finishInstallToolName ofType:@"app"];
|
||||
if (relaunchPathToCopy != nil)
|
||||
{
|
||||
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[[self class] instanceMethodSignatureForSelector:@selector(relaunchHostApp)] retain]];
|
||||
[invocation setSelector:@selector(relaunchHostApp)];
|
||||
[invocation setTarget:self];
|
||||
postponedOnce = YES;
|
||||
if ([delegate shouldPostponeRelaunchForUpdate:updateItem toHostBundle:hostBundle untilInvoking:invocation])
|
||||
return;
|
||||
NSString *targetPath = [[host appSupportPath] stringByAppendingPathComponent:[relaunchPathToCopy lastPathComponent]];
|
||||
// Only the paranoid survive: if there's already a stray copy of relaunch there, we would have problems.
|
||||
NSError *error = nil;
|
||||
[[NSFileManager defaultManager] createDirectoryAtPath: [targetPath stringByDeletingLastPathComponent] withIntermediateDirectories: YES attributes: [NSDictionary dictionary] error: &error];
|
||||
|
||||
if( [SUPlainInstaller copyPathWithAuthentication: relaunchPathToCopy overPath: targetPath temporaryName: nil error: &error] )
|
||||
relaunchPath = [targetPath retain];
|
||||
else
|
||||
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURelaunchError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:SULocalizedString(@"An error occurred while extracting the archive. Please try again later.", nil), NSLocalizedDescriptionKey, [NSString stringWithFormat:@"Couldn't copy relauncher (%@) to temporary path (%@)! %@", relaunchPathToCopy, targetPath, (error ? [error localizedDescription] : @"")], NSLocalizedFailureReasonErrorKey, nil]]];
|
||||
}
|
||||
|
||||
[self cleanUp]; // Clean up the download and extracted files.
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterWillRestartNotification object:self];
|
||||
if ([delegate respondsToSelector:@selector(updaterWillRelaunchApplication)])
|
||||
[delegate updaterWillRelaunchApplication];
|
||||
|
||||
if(!relaunchPath || ![[NSFileManager defaultManager] fileExistsAtPath:relaunchPath])
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterWillRestartNotification object:self];
|
||||
if ([[updater delegate] respondsToSelector:@selector(updaterWillRelaunchApplication:)])
|
||||
[[updater delegate] updaterWillRelaunchApplication:updater];
|
||||
|
||||
if(!relaunchPath || ![[NSFileManager defaultManager] fileExistsAtPath:relaunchPath])
|
||||
{
|
||||
// Note that we explicitly use the host app's name here, since updating plugin for Mail relaunches Mail, not just the plugin.
|
||||
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURelaunchError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:SULocalizedString(@"An error occurred while relaunching %1$@, but the new version will be available next time you run %1$@.", nil), [host name]], NSLocalizedDescriptionKey, [NSString stringWithFormat:@"Couldn't find the relauncher (expected to find it at %@)", relaunchPath], NSLocalizedFailureReasonErrorKey, nil]]];
|
||||
// We intentionally don't abandon the update here so that the host won't initiate another.
|
||||
return;
|
||||
}
|
||||
|
||||
NSString *pathToRelaunch = [host bundlePath];
|
||||
if ([[updater delegate] respondsToSelector:@selector(pathToRelaunchForUpdater:)])
|
||||
pathToRelaunch = [[updater delegate] pathToRelaunchForUpdater:updater];
|
||||
NSString *relaunchToolPath = [[relaunchPath stringByAppendingPathComponent: @"/Contents/MacOS"] stringByAppendingPathComponent: finishInstallToolName];
|
||||
[NSTask launchedTaskWithLaunchPath: relaunchToolPath arguments:[NSArray arrayWithObjects:
|
||||
[host bundlePath],
|
||||
pathToRelaunch,
|
||||
[NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]],
|
||||
tempDir,
|
||||
relaunch ? @"1" : @"0",
|
||||
showUI ? @"1" : @"0",
|
||||
nil]];
|
||||
|
||||
[NSApp terminate:self];
|
||||
}
|
||||
|
||||
- (void)cleanUpDownload
|
||||
{
|
||||
if (tempDir != nil) // tempDir contains downloadPath, so we implicitly delete both here.
|
||||
{
|
||||
// Note that we explicitly use the host app's name here, since updating plugin for Mail relaunches Mail, not just the plugin.
|
||||
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURelaunchError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:SULocalizedString(@"An error occurred while relaunching %1$@, but the new version will be available next time you run %1$@.", nil), [[NSBundle mainBundle] name]], NSLocalizedDescriptionKey, [NSString stringWithFormat:@"Couldn't find the relauncher (expected to find it at %@)", relaunchPath], NSLocalizedFailureReasonErrorKey, nil]]];
|
||||
// We intentionally don't abandon the update here so that the host won't initiate another.
|
||||
return;
|
||||
}
|
||||
|
||||
[NSTask launchedTaskWithLaunchPath:relaunchPath arguments:[NSArray arrayWithObjects:[hostBundle bundlePath], [NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]], nil]];
|
||||
|
||||
[NSApp terminate:self];
|
||||
BOOL success = NO;
|
||||
NSError * error = nil;
|
||||
success = [[NSFileManager defaultManager] removeItemAtPath: tempDir error: &error]; // Clean up the copied relauncher
|
||||
if( !success )
|
||||
[[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation source:[tempDir stringByDeletingLastPathComponent] destination:@"" files:[NSArray arrayWithObject:[tempDir lastPathComponent]] tag:NULL];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)cleanUp
|
||||
- (void)installerForHost:(SUHost *)aHost failedWithError:(NSError *)error
|
||||
{
|
||||
[[NSFileManager defaultManager] removeFileAtPath:[downloadPath stringByDeletingLastPathComponent] handler:nil];
|
||||
}
|
||||
|
||||
- (void)installerForHostBundle:(NSBundle *)hb failedWithError:(NSError *)error
|
||||
{
|
||||
if (hb != hostBundle) { return; }
|
||||
[[NSFileManager defaultManager] removeFileAtPath:relaunchPath handler:NULL]; // Clean up the copied relauncher.
|
||||
if (aHost != host) { return; }
|
||||
NSError * dontThrow = nil;
|
||||
[[NSFileManager defaultManager] removeItemAtPath: relaunchPath error: &dontThrow]; // Clean up the copied relauncher
|
||||
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:SULocalizedString(@"An error occurred while installing the update. Please try again later.", nil), NSLocalizedDescriptionKey, [error localizedDescription], NSLocalizedFailureReasonErrorKey, nil]]];
|
||||
}
|
||||
|
||||
- (void)abortUpdate
|
||||
{
|
||||
[[self retain] autorelease]; // In case the notification center was the last one holding on to us.
|
||||
[self cleanUpDownload];
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
[super abortUpdate];
|
||||
}
|
||||
@@ -265,16 +411,21 @@
|
||||
- (void)abortUpdateWithError:(NSError *)error
|
||||
{
|
||||
if ([error code] != SUNoUpdateError) // Let's not bother logging this.
|
||||
NSLog(@"Sparkle Error: %@", [error localizedDescription]);
|
||||
SULog(@"Sparkle Error: %@", [error localizedDescription]);
|
||||
if ([error localizedFailureReason])
|
||||
NSLog(@"Sparkle Error (continued): %@", [error localizedFailureReason]);
|
||||
SULog(@"Sparkle Error (continued): %@", [error localizedFailureReason]);
|
||||
if (download)
|
||||
[download cancel];
|
||||
[self abortUpdate];
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[hostBundle release];
|
||||
[updateItem release];
|
||||
[nonDeltaUpdateItem release];
|
||||
[download release];
|
||||
[downloadPath release];
|
||||
[tempDir release];
|
||||
[relaunchPath release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// SUBinaryDeltaApply.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mark Rowe on 2009-06-01.
|
||||
// Copyright 2009 Mark Rowe. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef SUBINARYDELTAAPPLY_H
|
||||
#define SUBINARYDELTAAPPLY_H
|
||||
|
||||
@class NSString;
|
||||
int applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFile);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,101 @@
|
||||
//
|
||||
// SUBinaryDeltaApply.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mark Rowe on 2009-06-01.
|
||||
// Copyright 2009 Mark Rowe. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUBinaryDeltaApply.h"
|
||||
#import "SUBinaryDeltaCommon.h"
|
||||
#import <CommonCrypto/CommonDigest.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <bspatch.h>
|
||||
#import <stdio.h>
|
||||
#import <stdlib.h>
|
||||
#import <xar/xar.h>
|
||||
|
||||
static void applyBinaryDeltaToFile(xar_t x, xar_file_t file, NSString *sourceFilePath, NSString *destinationFilePath)
|
||||
{
|
||||
NSString *patchFile = temporaryFilename(@"apply-binary-delta");
|
||||
xar_extract_tofile(x, file, [patchFile fileSystemRepresentation]);
|
||||
const char *argv[] = {"/usr/bin/bspatch", [sourceFilePath fileSystemRepresentation], [destinationFilePath fileSystemRepresentation], [patchFile fileSystemRepresentation]};
|
||||
bspatch(4, (char **)argv);
|
||||
unlink([patchFile fileSystemRepresentation]);
|
||||
}
|
||||
|
||||
int applyBinaryDelta(NSString *source, NSString *destination, NSString *patchFile)
|
||||
{
|
||||
xar_t x = xar_open([patchFile UTF8String], READ);
|
||||
if (!x) {
|
||||
fprintf(stderr, "Unable to open %s. Giving up.\n", [patchFile UTF8String]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
NSString *expectedBeforeHash = nil;
|
||||
NSString *expectedAfterHash = nil;
|
||||
xar_subdoc_t subdoc;
|
||||
for (subdoc = xar_subdoc_first(x); subdoc; subdoc = xar_subdoc_next(subdoc)) {
|
||||
if (!strcmp(xar_subdoc_name(subdoc), "binary-delta-attributes")) {
|
||||
const char *value = 0;
|
||||
xar_subdoc_prop_get(subdoc, "before-sha1", &value);
|
||||
if (value)
|
||||
expectedBeforeHash = [NSString stringWithUTF8String:value];
|
||||
|
||||
xar_subdoc_prop_get(subdoc, "after-sha1", &value);
|
||||
if (value)
|
||||
expectedAfterHash = [NSString stringWithUTF8String:value];
|
||||
}
|
||||
}
|
||||
|
||||
if (!expectedBeforeHash || !expectedAfterHash) {
|
||||
fprintf(stderr, "Unable to find before-sha1 or after-sha1 metadata in delta. Giving up.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
fprintf(stderr, "Verifying source... ");
|
||||
NSString *beforeHash = hashOfTree(source);
|
||||
|
||||
if (![beforeHash isEqualToString:expectedBeforeHash]) {
|
||||
fprintf(stderr, "Source doesn't have expected hash (%s != %s). Giving up.\n", [expectedBeforeHash UTF8String], [beforeHash UTF8String]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
fprintf(stderr, "\nCopying files... ");
|
||||
removeTree(destination);
|
||||
copyTree(source, destination);
|
||||
|
||||
fprintf(stderr, "\nPatching... ");
|
||||
xar_file_t file;
|
||||
xar_iter_t iter = xar_iter_new();
|
||||
for (file = xar_file_first(x, iter); file; file = xar_file_next(iter)) {
|
||||
NSString *path = [NSString stringWithUTF8String:xar_get_path(file)];
|
||||
NSString *sourceFilePath = [source stringByAppendingPathComponent:path];
|
||||
NSString *destinationFilePath = [destination stringByAppendingPathComponent:path];
|
||||
|
||||
const char *value;
|
||||
if (!xar_prop_get(file, "delete", &value) || !xar_prop_get(file, "delete-then-extract", &value)) {
|
||||
removeTree(destinationFilePath);
|
||||
if (!xar_prop_get(file, "delete", &value))
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!xar_prop_get(file, "binary-delta", &value))
|
||||
applyBinaryDeltaToFile(x, file, sourceFilePath, destinationFilePath);
|
||||
else
|
||||
xar_extract_tofile(x, file, [destinationFilePath fileSystemRepresentation]);
|
||||
}
|
||||
xar_close(x);
|
||||
|
||||
fprintf(stderr, "\nVerifying destination... ");
|
||||
NSString *afterHash = hashOfTree(destination);
|
||||
|
||||
if (![afterHash isEqualToString:expectedAfterHash]) {
|
||||
fprintf(stderr, "Destination doesn't have expected hash (%s != %s). Giving up.\n", [expectedAfterHash UTF8String], [afterHash UTF8String]);
|
||||
removeTree(destination);
|
||||
return 1;
|
||||
}
|
||||
|
||||
fprintf(stderr, "\nDone!\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// SUBinaryDeltaCommon.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mark Rowe on 2009-06-01.
|
||||
// Copyright 2009 Mark Rowe. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef SUBINARYDELTACOMMON_H
|
||||
#define SUBINARYDELTACOMMON_H
|
||||
|
||||
#include <fts.h>
|
||||
|
||||
@class NSString;
|
||||
@class NSData;
|
||||
|
||||
extern int binaryDeltaSupported(void);
|
||||
extern int compareFiles(const FTSENT **a, const FTSENT **b);
|
||||
extern NSData *hashOfFile(FTSENT *ent);
|
||||
extern NSString *hashOfTree(NSString *path);
|
||||
extern void removeTree(NSString *path);
|
||||
extern void copyTree(NSString *source, NSString *dest);
|
||||
extern NSString *pathRelativeToDirectory(NSString *directory, NSString *path);
|
||||
NSString *temporaryFilename(NSString *base);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,157 @@
|
||||
//
|
||||
// SUBinaryDeltaCommon.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mark Rowe on 2009-06-01.
|
||||
// Copyright 2009 Mark Rowe. All rights reserved.
|
||||
//
|
||||
|
||||
#include "SUBinaryDeltaCommon.h"
|
||||
#include <CommonCrypto/CommonDigest.h>
|
||||
#include <Foundation/Foundation.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
extern int xar_close(void*) __attribute__((weak_import));
|
||||
|
||||
int binaryDeltaSupported(void)
|
||||
{
|
||||
// OS X 10.4 didn't include libxar, so we link against it weakly.
|
||||
// This checks whether libxar is available at runtime.
|
||||
return xar_close != 0;
|
||||
}
|
||||
|
||||
int compareFiles(const FTSENT **a, const FTSENT **b)
|
||||
{
|
||||
return strcoll((*a)->fts_name, (*b)->fts_name);
|
||||
}
|
||||
|
||||
NSString *pathRelativeToDirectory(NSString *directory, NSString *path)
|
||||
{
|
||||
NSUInteger directoryLength = [directory length];
|
||||
if ([path hasPrefix:directory])
|
||||
return [path substringFromIndex:directoryLength];
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
NSString *temporaryFilename(NSString *base)
|
||||
{
|
||||
NSString *template = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.XXXXXXXXXX", base]];
|
||||
char buffer[MAXPATHLEN];
|
||||
strcpy(buffer, [template fileSystemRepresentation]);
|
||||
return [NSString stringWithUTF8String:mkstemp(buffer)];
|
||||
}
|
||||
|
||||
static void _hashOfBuffer(unsigned char *hash, const char* buffer, size_t bufferLength)
|
||||
{
|
||||
assert(bufferLength <= UINT32_MAX);
|
||||
CC_SHA1_CTX hashContext;
|
||||
CC_SHA1_Init(&hashContext);
|
||||
CC_SHA1_Update(&hashContext, buffer, (CC_LONG)bufferLength);
|
||||
CC_SHA1_Final(hash, &hashContext);
|
||||
}
|
||||
|
||||
static void _hashOfFile(unsigned char* hash, FTSENT *ent)
|
||||
{
|
||||
if (ent->fts_info == FTS_SL) {
|
||||
char linkDestination[MAXPATHLEN + 1];
|
||||
ssize_t linkDestinationLength = readlink(ent->fts_path, linkDestination, MAXPATHLEN);
|
||||
if (linkDestinationLength < 0) {
|
||||
perror("readlink");
|
||||
return;
|
||||
}
|
||||
|
||||
_hashOfBuffer(hash, linkDestination, linkDestinationLength);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ent->fts_info == FTS_F) {
|
||||
int fileDescriptor = open(ent->fts_path, O_RDONLY);
|
||||
if (fileDescriptor == -1) {
|
||||
perror("open");
|
||||
return;
|
||||
}
|
||||
|
||||
size_t fileSize = (size_t)ent->fts_statp->st_size;
|
||||
if (fileSize == 0) {
|
||||
_hashOfBuffer(hash, NULL, 0);
|
||||
close(fileDescriptor);
|
||||
return;
|
||||
}
|
||||
|
||||
void *buffer = mmap(0, fileSize, PROT_READ, MAP_FILE | MAP_PRIVATE, fileDescriptor, 0);
|
||||
if (buffer == (void*)-1) {
|
||||
close(fileDescriptor);
|
||||
perror("mmap");
|
||||
return;
|
||||
}
|
||||
|
||||
_hashOfBuffer(hash, buffer, fileSize);
|
||||
munmap(buffer, fileSize);
|
||||
close(fileDescriptor);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ent->fts_info == FTS_D)
|
||||
memset(hash, 0xdd, CC_SHA1_DIGEST_LENGTH);
|
||||
}
|
||||
|
||||
NSData *hashOfFile(FTSENT *ent)
|
||||
{
|
||||
unsigned char fileHash[CC_SHA1_DIGEST_LENGTH];
|
||||
_hashOfFile(fileHash, ent);
|
||||
return [NSData dataWithBytes:fileHash length:CC_SHA1_DIGEST_LENGTH];
|
||||
}
|
||||
|
||||
NSString *hashOfTree(NSString *path)
|
||||
{
|
||||
const char *sourcePaths[] = {[path UTF8String], 0};
|
||||
FTS *fts = fts_open((char* const*)sourcePaths, FTS_PHYSICAL | FTS_NOCHDIR, compareFiles);
|
||||
if (!fts) {
|
||||
perror("fts_open");
|
||||
return nil;
|
||||
}
|
||||
|
||||
CC_SHA1_CTX hashContext;
|
||||
CC_SHA1_Init(&hashContext);
|
||||
|
||||
FTSENT *ent = 0;
|
||||
while ((ent = fts_read(fts))) {
|
||||
if (ent->fts_info != FTS_F && ent->fts_info != FTS_SL)
|
||||
continue;
|
||||
|
||||
unsigned char fileHash[CC_SHA1_DIGEST_LENGTH];
|
||||
_hashOfFile(fileHash, ent);
|
||||
CC_SHA1_Update(&hashContext, fileHash, sizeof(fileHash));
|
||||
|
||||
NSString *relativePath = pathRelativeToDirectory(path, [NSString stringWithUTF8String:ent->fts_path]);
|
||||
NSData *relativePathBytes = [relativePath dataUsingEncoding:NSUTF8StringEncoding];
|
||||
CC_SHA1_Update(&hashContext, [relativePathBytes bytes], (uint32_t)[relativePathBytes length]);
|
||||
}
|
||||
fts_close(fts);
|
||||
|
||||
unsigned char hash[CC_SHA1_DIGEST_LENGTH];
|
||||
CC_SHA1_Final(hash, &hashContext);
|
||||
|
||||
char hexHash[CC_SHA1_DIGEST_LENGTH * 2 + 1];
|
||||
size_t i;
|
||||
for (i = 0; i < CC_SHA1_DIGEST_LENGTH; i++)
|
||||
sprintf(hexHash + i * 2, "%02x", hash[i]);
|
||||
|
||||
return [NSString stringWithUTF8String:hexHash];
|
||||
}
|
||||
|
||||
void removeTree(NSString *path)
|
||||
{
|
||||
[[NSFileManager defaultManager] removeItemAtPath:path error:nil];
|
||||
}
|
||||
|
||||
void copyTree(NSString *source, NSString *dest)
|
||||
{
|
||||
[[NSFileManager defaultManager] copyItemAtPath:source toPath:dest error:nil];
|
||||
}
|
||||
@@ -0,0 +1,269 @@
|
||||
//
|
||||
// SUBinaryDeltaTool.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mark Rowe on 2009-06-01.
|
||||
// Copyright 2009 Mark Rowe. All rights reserved.
|
||||
//
|
||||
|
||||
#define _DARWIN_NO_64_BIT_INODE 1
|
||||
|
||||
#include "SUBinaryDeltaCommon.h"
|
||||
#include "SUBinaryDeltaApply.h"
|
||||
#include <CommonCrypto/CommonDigest.h>
|
||||
#include <Foundation/Foundation.h>
|
||||
#include <fcntl.h>
|
||||
#include <fts.h>
|
||||
#include <libgen.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <xar/xar.h>
|
||||
|
||||
extern int bsdiff(int argc, const char **argv);
|
||||
|
||||
@interface CreateBinaryDeltaOperation : NSOperation
|
||||
{
|
||||
NSString *_relativePath;
|
||||
NSString *_fromPath;
|
||||
NSString *_toPath;
|
||||
NSString *_resultPath;
|
||||
}
|
||||
- (id)initWithRelativePath:(NSString *)relativePath oldTree:(NSString *)oldTree newTree:(NSString *)newTree;
|
||||
|
||||
- (NSString *)relativePath;
|
||||
- (NSString *)resultPath;
|
||||
@end
|
||||
|
||||
@implementation CreateBinaryDeltaOperation
|
||||
|
||||
- (id)initWithRelativePath:(NSString *)relativePath oldTree:(NSString *)oldTree newTree:(NSString *)newTree
|
||||
{
|
||||
if ((self = [super init])) {
|
||||
_relativePath = [relativePath copy];
|
||||
_fromPath = [[oldTree stringByAppendingPathComponent:relativePath] retain];
|
||||
_toPath = [[newTree stringByAppendingPathComponent:relativePath] retain];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSString *)relativePath
|
||||
{
|
||||
return [[_relativePath retain] autorelease];
|
||||
}
|
||||
|
||||
- (NSString *)resultPath
|
||||
{
|
||||
return [[_resultPath retain] autorelease];
|
||||
}
|
||||
|
||||
- (void)main
|
||||
{
|
||||
NSString *temporaryFile = temporaryFilename(@"BinaryDelta");
|
||||
const char *argv[] = {"/usr/bin/bsdiff", [_fromPath fileSystemRepresentation], [_toPath fileSystemRepresentation], [temporaryFile fileSystemRepresentation]};
|
||||
int result = bsdiff(4, argv);
|
||||
if (!result)
|
||||
_resultPath = [temporaryFile retain];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
static NSDictionary *infoForFile(FTSENT *ent)
|
||||
{
|
||||
NSData *hash = hashOfFile(ent);
|
||||
NSNumber *size = nil;
|
||||
if (ent->fts_info != FTS_D)
|
||||
size = [NSNumber numberWithUnsignedLongLong:ent->fts_statp->st_size];
|
||||
return [NSDictionary dictionaryWithObjectsAndKeys:hash, @"hash", [NSNumber numberWithUnsignedShort:ent->fts_info], @"type", size, @"size", nil];
|
||||
}
|
||||
|
||||
static NSString *absolutePath(NSString *path)
|
||||
{
|
||||
NSURL *url = [[[NSURL alloc] initFileURLWithPath:path] autorelease];
|
||||
return [[url absoluteURL] path];
|
||||
}
|
||||
|
||||
static NSString *temporaryPatchFile(NSString *patchFile)
|
||||
{
|
||||
NSString *path = absolutePath(patchFile);
|
||||
NSString *directory = [path stringByDeletingLastPathComponent];
|
||||
NSString *file = [path lastPathComponent];
|
||||
return [NSString stringWithFormat:@"%@/.%@.tmp", directory, file];
|
||||
}
|
||||
|
||||
static BOOL shouldSkipDeltaCompression(NSString *key, NSDictionary* originalInfo, NSDictionary *newInfo)
|
||||
{
|
||||
unsigned long long fileSize = [[newInfo objectForKey:@"size"] unsignedLongLongValue];
|
||||
if (fileSize < 4096)
|
||||
return YES;
|
||||
|
||||
if (!originalInfo)
|
||||
return YES;
|
||||
|
||||
if ([[originalInfo objectForKey:@"type"] unsignedShortValue] != [[newInfo objectForKey:@"type"] unsignedShortValue])
|
||||
return YES;
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
static BOOL shouldDeleteThenExtract(NSString *key, NSDictionary* originalInfo, NSDictionary *newInfo)
|
||||
{
|
||||
if (!originalInfo)
|
||||
return NO;
|
||||
|
||||
if ([[originalInfo objectForKey:@"type"] unsignedShortValue] != [[newInfo objectForKey:@"type"] unsignedShortValue])
|
||||
return YES;
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc != 5) {
|
||||
usage:
|
||||
fprintf(stderr, "Usage: BinaryDelta [create | apply] before-tree after-tree patch-file\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
NSString *command = [NSString stringWithUTF8String:argv[1]];
|
||||
NSString *oldPath = [NSString stringWithUTF8String:argv[2]];
|
||||
NSString *newPath = [NSString stringWithUTF8String:argv[3]];
|
||||
NSString *patchFile = [NSString stringWithUTF8String:argv[4]];
|
||||
|
||||
if ([command isEqualToString:@"apply"]) {
|
||||
int result = applyBinaryDelta(oldPath, newPath, patchFile);
|
||||
[pool drain];
|
||||
return result;
|
||||
}
|
||||
if (![command isEqualToString:@"create"]) {
|
||||
[pool drain];
|
||||
goto usage;
|
||||
}
|
||||
|
||||
NSMutableDictionary *originalTreeState = [NSMutableDictionary dictionary];
|
||||
|
||||
const char *sourcePaths[] = {[oldPath fileSystemRepresentation], 0};
|
||||
FTS *fts = fts_open((char* const*)sourcePaths, FTS_PHYSICAL | FTS_NOCHDIR, compareFiles);
|
||||
if (!fts) {
|
||||
[pool drain];
|
||||
perror("fts_open");
|
||||
return 1;
|
||||
}
|
||||
|
||||
fprintf(stderr, "Processing %s...", [oldPath UTF8String]);
|
||||
FTSENT *ent = 0;
|
||||
while ((ent = fts_read(fts))) {
|
||||
if (ent->fts_info != FTS_F && ent->fts_info != FTS_SL && ent->fts_info != FTS_D)
|
||||
continue;
|
||||
|
||||
NSString *key = pathRelativeToDirectory(oldPath, [NSString stringWithUTF8String:ent->fts_path]);
|
||||
if (![key length])
|
||||
continue;
|
||||
|
||||
NSDictionary *info = infoForFile(ent);
|
||||
[originalTreeState setObject:info forKey:key];
|
||||
}
|
||||
fts_close(fts);
|
||||
|
||||
NSString *beforeHash = hashOfTree(oldPath);
|
||||
|
||||
NSMutableDictionary *newTreeState = [NSMutableDictionary dictionary];
|
||||
for (NSString *key in originalTreeState)
|
||||
{
|
||||
[newTreeState setObject:[NSNull null] forKey:key];
|
||||
}
|
||||
|
||||
fprintf(stderr, "\nProcessing %s... ", [newPath UTF8String]);
|
||||
sourcePaths[0] = [newPath fileSystemRepresentation];
|
||||
fts = fts_open((char* const*)sourcePaths, FTS_PHYSICAL | FTS_NOCHDIR, compareFiles);
|
||||
if (!fts) {
|
||||
[pool drain];
|
||||
perror("fts_open");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
while ((ent = fts_read(fts))) {
|
||||
if (ent->fts_info != FTS_F && ent->fts_info != FTS_SL && ent->fts_info != FTS_D)
|
||||
continue;
|
||||
|
||||
NSString *key = pathRelativeToDirectory(newPath, [NSString stringWithUTF8String:ent->fts_path]);
|
||||
if (![key length])
|
||||
continue;
|
||||
|
||||
NSDictionary *info = infoForFile(ent);
|
||||
NSDictionary *oldInfo = [originalTreeState objectForKey:key];
|
||||
|
||||
if ([info isEqual:oldInfo])
|
||||
[newTreeState removeObjectForKey:key];
|
||||
else
|
||||
[newTreeState setObject:info forKey:key];
|
||||
}
|
||||
fts_close(fts);
|
||||
|
||||
NSString *afterHash = hashOfTree(newPath);
|
||||
|
||||
fprintf(stderr, "\nGenerating delta... ");
|
||||
|
||||
NSString *temporaryFile = temporaryPatchFile(patchFile);
|
||||
xar_t x = xar_open([temporaryFile fileSystemRepresentation], WRITE);
|
||||
xar_opt_set(x, XAR_OPT_COMPRESSION, "bzip2");
|
||||
xar_subdoc_t attributes = xar_subdoc_new(x, "binary-delta-attributes");
|
||||
xar_subdoc_prop_set(attributes, "before-sha1", [beforeHash UTF8String]);
|
||||
xar_subdoc_prop_set(attributes, "after-sha1", [afterHash UTF8String]);
|
||||
|
||||
NSOperationQueue *deltaQueue = [[NSOperationQueue alloc] init];
|
||||
NSMutableArray *deltaOperations = [NSMutableArray array];
|
||||
|
||||
NSArray *keys = [[newTreeState allKeys] sortedArrayUsingSelector:@selector(compare:)];
|
||||
for (NSString* key in keys) {
|
||||
id value = [newTreeState valueForKey:key];
|
||||
|
||||
if ([value isEqual:[NSNull null]]) {
|
||||
xar_file_t newFile = xar_add_frombuffer(x, 0, [key fileSystemRepresentation], (char *)"", 1);
|
||||
assert(newFile);
|
||||
xar_prop_set(newFile, "delete", "true");
|
||||
continue;
|
||||
}
|
||||
|
||||
NSDictionary *originalInfo = [originalTreeState objectForKey:key];
|
||||
NSDictionary *newInfo = [newTreeState objectForKey:key];
|
||||
if (shouldSkipDeltaCompression(key, originalInfo, newInfo)) {
|
||||
NSString *path = [newPath stringByAppendingPathComponent:key];
|
||||
xar_file_t newFile = xar_add_frompath(x, 0, [key fileSystemRepresentation], [path fileSystemRepresentation]);
|
||||
assert(newFile);
|
||||
if (shouldDeleteThenExtract(key, originalInfo, newInfo))
|
||||
xar_prop_set(newFile, "delete-then-extract", "true");
|
||||
} else {
|
||||
CreateBinaryDeltaOperation *operation = [[CreateBinaryDeltaOperation alloc] initWithRelativePath:key oldTree:oldPath newTree:newPath];
|
||||
[deltaQueue addOperation:operation];
|
||||
[deltaOperations addObject:operation];
|
||||
[operation release];
|
||||
}
|
||||
}
|
||||
|
||||
[deltaQueue waitUntilAllOperationsAreFinished];
|
||||
[deltaQueue release];
|
||||
|
||||
for (CreateBinaryDeltaOperation *operation in deltaOperations) {
|
||||
NSString *resultPath = [operation resultPath];
|
||||
xar_file_t newFile = xar_add_frompath(x, 0, [[operation relativePath] fileSystemRepresentation], [resultPath fileSystemRepresentation]);
|
||||
assert(newFile);
|
||||
xar_prop_set(newFile, "binary-delta", "true");
|
||||
unlink([resultPath fileSystemRepresentation]);
|
||||
}
|
||||
|
||||
xar_close(x);
|
||||
|
||||
unlink([patchFile fileSystemRepresentation]);
|
||||
link([temporaryFile fileSystemRepresentation], [patchFile fileSystemRepresentation]);
|
||||
unlink([temporaryFile fileSystemRepresentation]);
|
||||
fprintf(stderr, "Done!\n");
|
||||
|
||||
[pool drain];
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// SUBinaryDeltaUnarchiver.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mark Rowe on 2009-06-03.
|
||||
// Copyright 2009 Mark Rowe. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef SUBINARYDELTAUNARCHIVER_H
|
||||
#define SUBINARYDELTAUNARCHIVER_H
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "SUUnarchiver.h"
|
||||
|
||||
@interface SUBinaryDeltaUnarchiver : SUUnarchiver
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,48 @@
|
||||
//
|
||||
// SUBinaryDeltaUnarchiver.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mark Rowe on 2009-06-03.
|
||||
// Copyright 2009 Mark Rowe. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUBinaryDeltaCommon.h"
|
||||
#import "SUBinaryDeltaUnarchiver.h"
|
||||
#import "SUBinaryDeltaApply.h"
|
||||
#import "SUUnarchiver_Private.h"
|
||||
#import "SUHost.h"
|
||||
#import "NTSynchronousTask.h"
|
||||
|
||||
@implementation SUBinaryDeltaUnarchiver
|
||||
|
||||
+ (BOOL)canUnarchivePath:(NSString *)path
|
||||
{
|
||||
return binaryDeltaSupported() && [[path pathExtension] isEqualToString:@"delta"];
|
||||
}
|
||||
|
||||
- (void)applyBinaryDelta
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
NSString *sourcePath = [[updateHost bundle] bundlePath];
|
||||
NSString *targetPath = [[archivePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:[sourcePath lastPathComponent]];
|
||||
|
||||
int result = applyBinaryDelta(sourcePath, targetPath, archivePath);
|
||||
if (!result)
|
||||
[self performSelectorOnMainThread:@selector(notifyDelegateOfSuccess) withObject:nil waitUntilDone:NO];
|
||||
else
|
||||
[self performSelectorOnMainThread:@selector(notifyDelegateOfFailure) withObject:nil waitUntilDone:NO];
|
||||
|
||||
[pool drain];
|
||||
}
|
||||
|
||||
- (void)start
|
||||
{
|
||||
[NSThread detachNewThreadSelector:@selector(applyBinaryDelta) toTarget:self withObject:nil];
|
||||
}
|
||||
|
||||
+ (void)load
|
||||
{
|
||||
[self registerImplementation:self];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// SUCodeSigningVerifier.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 7/5/12.
|
||||
//
|
||||
//
|
||||
|
||||
#ifndef SUCODESIGNINGVERIFIER_H
|
||||
#define SUCODESIGNINGVERIFIER_H
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface SUCodeSigningVerifier : NSObject
|
||||
+ (BOOL)codeSignatureIsValidAtPath:(NSString *)destinationPath error:(NSError **)error;
|
||||
+ (BOOL)hostApplicationIsCodeSigned;
|
||||
@end
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,86 @@
|
||||
//
|
||||
// SUCodeSigningVerifier.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 7/5/12.
|
||||
//
|
||||
//
|
||||
|
||||
#import <Security/CodeSigning.h>
|
||||
#import "SUCodeSigningVerifier.h"
|
||||
#import "SULog.h"
|
||||
|
||||
@implementation SUCodeSigningVerifier
|
||||
|
||||
extern OSStatus SecCodeCopySelf(SecCSFlags flags, SecCodeRef *self) __attribute__((weak_import));
|
||||
|
||||
extern OSStatus SecCodeCopyDesignatedRequirement(SecStaticCodeRef code, SecCSFlags flags, SecRequirementRef *requirement) __attribute__((weak_import));
|
||||
|
||||
extern OSStatus SecStaticCodeCreateWithPath(CFURLRef path, SecCSFlags flags, SecStaticCodeRef *staticCode) __attribute__((weak_import));
|
||||
|
||||
extern OSStatus SecStaticCodeCheckValidityWithErrors(SecStaticCodeRef staticCode, SecCSFlags flags, SecRequirementRef requirement, CFErrorRef *errors) __attribute__((weak_import));
|
||||
|
||||
|
||||
+ (BOOL)codeSignatureIsValidAtPath:(NSString *)destinationPath error:(NSError **)error
|
||||
{
|
||||
// This API didn't exist prior to 10.6.
|
||||
if (SecCodeCopySelf == NULL) return NO;
|
||||
|
||||
OSStatus result;
|
||||
SecRequirementRef requirement = NULL;
|
||||
SecStaticCodeRef staticCode = NULL;
|
||||
SecCodeRef hostCode = NULL;
|
||||
|
||||
result = SecCodeCopySelf(kSecCSDefaultFlags, &hostCode);
|
||||
if (result != 0) {
|
||||
SULog(@"Failed to copy host code %d", result);
|
||||
goto finally;
|
||||
}
|
||||
|
||||
result = SecCodeCopyDesignatedRequirement(hostCode, kSecCSDefaultFlags, &requirement);
|
||||
if (result != 0) {
|
||||
SULog(@"Failed to copy designated requirement %d", result);
|
||||
goto finally;
|
||||
}
|
||||
|
||||
NSBundle *newBundle = [NSBundle bundleWithPath:destinationPath];
|
||||
if (!newBundle) {
|
||||
SULog(@"Failed to load NSBundle for update");
|
||||
result = -1;
|
||||
goto finally;
|
||||
}
|
||||
|
||||
result = SecStaticCodeCreateWithPath((CFURLRef)[newBundle executableURL], kSecCSDefaultFlags, &staticCode);
|
||||
if (result != 0) {
|
||||
SULog(@"Failed to get static code %d", result);
|
||||
goto finally;
|
||||
}
|
||||
|
||||
result = SecStaticCodeCheckValidityWithErrors(staticCode, kSecCSDefaultFlags | kSecCSCheckAllArchitectures, requirement, (CFErrorRef *)error);
|
||||
if (result != 0 && error) [*error autorelease];
|
||||
|
||||
finally:
|
||||
if (hostCode) CFRelease(hostCode);
|
||||
if (staticCode) CFRelease(staticCode);
|
||||
if (requirement) CFRelease(requirement);
|
||||
return (result == 0);
|
||||
}
|
||||
|
||||
+ (BOOL)hostApplicationIsCodeSigned
|
||||
{
|
||||
// This API didn't exist prior to 10.6.
|
||||
if (SecCodeCopySelf == NULL) return NO;
|
||||
|
||||
OSStatus result;
|
||||
SecCodeRef hostCode = NULL;
|
||||
result = SecCodeCopySelf(kSecCSDefaultFlags, &hostCode);
|
||||
if (result != 0) return NO;
|
||||
|
||||
SecRequirementRef requirement = NULL;
|
||||
result = SecCodeCopyDesignatedRequirement(hostCode, kSecCSDefaultFlags, &requirement);
|
||||
if (hostCode) CFRelease(hostCode);
|
||||
if (requirement) CFRelease(requirement);
|
||||
return (result == 0);
|
||||
}
|
||||
|
||||
@end
|
||||
+59
-18
@@ -10,27 +10,62 @@
|
||||
#ifndef SUCONSTANTS_H
|
||||
#define SUCONSTANTS_H
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Preprocessor flags:
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
extern NSString *SUUpdaterWillRestartNotification;
|
||||
extern NSString *SUTechnicalErrorInformationKey;
|
||||
// Turn off DSA signature check (practically invites man-in-the-middle attacks):
|
||||
#define ENDANGER_USERS_WITH_INSECURE_UPDATES 0
|
||||
|
||||
extern NSString *SUFeedURLKey;
|
||||
extern NSString *SUHasLaunchedBeforeKey;
|
||||
extern NSString *SUShowReleaseNotesKey;
|
||||
extern NSString *SUSkippedVersionKey;
|
||||
extern NSString *SUScheduledCheckIntervalKey;
|
||||
extern NSString *SULastCheckTimeKey;
|
||||
extern NSString *SUExpectsDSASignatureKey;
|
||||
extern NSString *SUPublicDSAKeyKey;
|
||||
extern NSString *SUPublicDSAKeyFileKey;
|
||||
extern NSString *SUAutomaticallyUpdateKey;
|
||||
extern NSString *SUAllowsAutomaticUpdatesKey;
|
||||
extern NSString *SUEnableAutomaticChecksKey;
|
||||
extern NSString *SUEnableAutomaticChecksKeyOld;
|
||||
extern NSString *SUEnableSystemProfilingKey;
|
||||
extern NSString *SUSendProfileInfoKey;
|
||||
// Sparkle usually doesn't allow downgrades as they're usually accidental, but
|
||||
// if your app has a downgrade function or URL handler, turn this on:
|
||||
#define PERMIT_AUTOMATED_DOWNGRADES 0
|
||||
|
||||
extern NSString *SUSparkleErrorDomain;
|
||||
// If your app file on disk is named "MyApp 1.1b4", Sparkle usually updates it
|
||||
// in place, giving you an app named 1.1b4 that is actually 1.2. Turn the
|
||||
// following on to always reset the name back to "MyApp":
|
||||
#define NORMALIZE_INSTALLED_APP_NAME 0
|
||||
|
||||
|
||||
#define TRY_TO_APPEND_VERSION_NUMBER 1
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Notifications:
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
extern NSString *const SUUpdaterWillRestartNotification;
|
||||
|
||||
extern NSString *const SUTechnicalErrorInformationKey;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// PList keys::
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
extern NSString *const SUFeedURLKey;
|
||||
extern NSString *const SUHasLaunchedBeforeKey;
|
||||
extern NSString *const SUShowReleaseNotesKey;
|
||||
extern NSString *const SUSkippedVersionKey;
|
||||
extern NSString *const SUScheduledCheckIntervalKey;
|
||||
extern NSString *const SULastCheckTimeKey;
|
||||
extern NSString *const SUPublicDSAKeyKey;
|
||||
extern NSString *const SUPublicDSAKeyFileKey;
|
||||
extern NSString *const SUAutomaticallyUpdateKey;
|
||||
extern NSString *const SUAllowsAutomaticUpdatesKey;
|
||||
extern NSString *const SUEnableAutomaticChecksKey;
|
||||
extern NSString *const SUEnableAutomaticChecksKeyOld;
|
||||
extern NSString *const SUEnableSystemProfilingKey;
|
||||
extern NSString *const SUSendProfileInfoKey;
|
||||
extern NSString *const SULastProfileSubmitDateKey;
|
||||
extern NSString *const SUPromptUserOnFirstLaunchKey;
|
||||
extern NSString *const SUFixedHTMLDisplaySizeKey;
|
||||
extern NSString *const SUKeepDownloadOnFailedInstallKey;
|
||||
extern NSString *const SUDefaultsDomainKey;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Errors:
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
extern NSString *const SUSparkleErrorDomain;
|
||||
// Appcast phase errors.
|
||||
extern OSStatus SUAppcastParseError;
|
||||
extern OSStatus SUNoUpdateError;
|
||||
@@ -51,6 +86,12 @@ extern OSStatus SUMissingUpdateError;
|
||||
extern OSStatus SUMissingInstallerToolError;
|
||||
extern OSStatus SURelaunchError;
|
||||
extern OSStatus SUInstallationError;
|
||||
extern OSStatus SUDowngradeError;
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// NSInteger fixer-upper:
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// NSInteger is a type that was added to Leopard.
|
||||
// Here is some glue to ensure that NSInteger will work with pre-10.5 SDKs:
|
||||
|
||||
+29
-19
@@ -6,29 +6,38 @@
|
||||
// Copyright 2006 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#import "Sparkle.h"
|
||||
#import "SUUpdater.h"
|
||||
|
||||
#import "SUAppcast.h"
|
||||
#import "SUAppcastItem.h"
|
||||
#import "SUVersionComparisonProtocol.h"
|
||||
#import "SUConstants.h"
|
||||
|
||||
NSString *SUUpdaterWillRestartNotification = @"SUUpdaterWillRestartNotificationName";
|
||||
NSString *SUTechnicalErrorInformationKey = @"SUTechnicalErrorInformation";
|
||||
NSString *const SUUpdaterWillRestartNotification = @"SUUpdaterWillRestartNotificationName";
|
||||
NSString *const SUTechnicalErrorInformationKey = @"SUTechnicalErrorInformation";
|
||||
|
||||
NSString *SUHasLaunchedBeforeKey = @"SUHasLaunchedBefore";
|
||||
NSString *SUFeedURLKey = @"SUFeedURL";
|
||||
NSString *SUShowReleaseNotesKey = @"SUShowReleaseNotes";
|
||||
NSString *SUSkippedVersionKey = @"SUSkippedVersion";
|
||||
NSString *SUScheduledCheckIntervalKey = @"SUScheduledCheckInterval";
|
||||
NSString *SULastCheckTimeKey = @"SULastCheckTime";
|
||||
NSString *SUExpectsDSASignatureKey = @"SUExpectsDSASignature";
|
||||
NSString *SUPublicDSAKeyKey = @"SUPublicDSAKey";
|
||||
NSString *SUPublicDSAKeyFileKey = @"SUPublicDSAKeyFile";
|
||||
NSString *SUAutomaticallyUpdateKey = @"SUAutomaticallyUpdate";
|
||||
NSString *SUAllowsAutomaticUpdatesKey = @"SUAllowsAutomaticUpdates";
|
||||
NSString *SUEnableSystemProfilingKey = @"SUEnableSystemProfiling";
|
||||
NSString *SUEnableAutomaticChecksKey = @"SUEnableAutomaticChecks";
|
||||
NSString *SUEnableAutomaticChecksKeyOld = @"SUCheckAtStartup";
|
||||
NSString *SUSendProfileInfoKey = @"SUSendProfileInfo";
|
||||
NSString *const SUHasLaunchedBeforeKey = @"SUHasLaunchedBefore";
|
||||
NSString *const SUFeedURLKey = @"SUFeedURL";
|
||||
NSString *const SUShowReleaseNotesKey = @"SUShowReleaseNotes";
|
||||
NSString *const SUSkippedVersionKey = @"SUSkippedVersion";
|
||||
NSString *const SUScheduledCheckIntervalKey = @"SUScheduledCheckInterval";
|
||||
NSString *const SULastCheckTimeKey = @"SULastCheckTime";
|
||||
NSString *const SUExpectsDSASignatureKey = @"SUExpectsDSASignature";
|
||||
NSString *const SUPublicDSAKeyKey = @"SUPublicDSAKey";
|
||||
NSString *const SUPublicDSAKeyFileKey = @"SUPublicDSAKeyFile";
|
||||
NSString *const SUAutomaticallyUpdateKey = @"SUAutomaticallyUpdate";
|
||||
NSString *const SUAllowsAutomaticUpdatesKey = @"SUAllowsAutomaticUpdates";
|
||||
NSString *const SUEnableSystemProfilingKey = @"SUEnableSystemProfiling";
|
||||
NSString *const SUEnableAutomaticChecksKey = @"SUEnableAutomaticChecks";
|
||||
NSString *const SUEnableAutomaticChecksKeyOld = @"SUCheckAtStartup";
|
||||
NSString *const SUSendProfileInfoKey = @"SUSendProfileInfo";
|
||||
NSString *const SULastProfileSubmitDateKey = @"SULastProfileSubmissionDate";
|
||||
NSString *const SUPromptUserOnFirstLaunchKey = @"SUPromptUserOnFirstLaunch";
|
||||
NSString *const SUFixedHTMLDisplaySizeKey = @"SUFixedHTMLDisplaySize";
|
||||
NSString *const SUKeepDownloadOnFailedInstallKey = @"SUKeepDownloadOnFailedInstall";
|
||||
NSString *const SUDefaultsDomainKey = @"SUDefaultsDomain";
|
||||
|
||||
NSString *SUSparkleErrorDomain = @"SUSparkleErrorDomain";
|
||||
NSString *const SUSparkleErrorDomain = @"SUSparkleErrorDomain";
|
||||
OSStatus SUAppcastParseError = 1000;
|
||||
OSStatus SUNoUpdateError = 1001;
|
||||
OSStatus SUAppcastError = 1002;
|
||||
@@ -45,3 +54,4 @@ OSStatus SUMissingUpdateError = 4002;
|
||||
OSStatus SUMissingInstallerToolError = 4003;
|
||||
OSStatus SURelaunchError = 4004;
|
||||
OSStatus SUInstallationError = 4005;
|
||||
OSStatus SUDowngradeError = 4006;
|
||||
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// SUDSAVerifier.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 3/16/06.
|
||||
// Copyright 2006 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef SUDSAVERIFIER_H
|
||||
#define SUDSAVERIFIER_H
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@interface SUDSAVerifier : NSObject
|
||||
+ (BOOL)validatePath:(NSString *)path withEncodedDSASignature:(NSString *)encodedSignature withPublicDSAKey:(NSString *)pkeyString;
|
||||
@end
|
||||
|
||||
#endif
|
||||
+355
@@ -0,0 +1,355 @@
|
||||
//
|
||||
// SUDSAVerifier.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 3/16/06.
|
||||
// Copyright 2006 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUDSAVerifier.h"
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#import <Security/cssm.h>
|
||||
|
||||
/* CDSA Specific */
|
||||
static CSSM_CSP_HANDLE cdsaInit( void );
|
||||
static void cdsaRelease( CSSM_CSP_HANDLE cspHandle );
|
||||
static CSSM_KEY_PTR cdsaCreateKey( CFDataRef rawKey );
|
||||
static void cdsaReleaseKey( CSSM_KEY_PTR key );
|
||||
static BOOL cdsaVerifyKey( CSSM_CSP_HANDLE cspHandle, const CSSM_KEY_PTR key );
|
||||
static BOOL cdsaVerifySignature( CSSM_CSP_HANDLE cspHandle, const CSSM_KEY_PTR key, const CFDataRef msg, const CFDataRef signature );
|
||||
static CFDataRef cdsaCreateSHA1Digest( CSSM_CSP_HANDLE cspHandle, const CFDataRef bytes );
|
||||
|
||||
/* Helper Functions */
|
||||
static NSData *b64decode( NSString *str );
|
||||
static NSData *rawKeyData( NSString *str );
|
||||
|
||||
@implementation SUDSAVerifier
|
||||
#pragma mark -
|
||||
|
||||
+ (BOOL)validatePath:(NSString *)path withEncodedDSASignature:(NSString *)encodedSignature withPublicDSAKey:(NSString *)pkeyString
|
||||
{
|
||||
if ( !encodedSignature || !pkeyString || !path ) return NO;
|
||||
BOOL result = NO;
|
||||
NSData *pathData = nil, *sigData = nil;
|
||||
CFDataRef hashData = NULL;
|
||||
CSSM_KEY_PTR pubKey = cdsaCreateKey((CFDataRef)rawKeyData(pkeyString)); // Create the DSA key
|
||||
CSSM_CSP_HANDLE cspHandle = CSSM_INVALID_HANDLE;
|
||||
|
||||
if ( !pubKey ) return NO;
|
||||
if ( (cspHandle = cdsaInit()) == CSSM_INVALID_HANDLE ) goto validate_end; // Init CDSA
|
||||
if ( !cdsaVerifyKey(cspHandle, pubKey) ) goto validate_end; // Verify the key is valid
|
||||
if ( (pathData = [NSData dataWithContentsOfFile:path]) == nil ) goto validate_end; // File data
|
||||
if ( (hashData = cdsaCreateSHA1Digest(cspHandle, (CFDataRef)pathData)) == NULL ) goto validate_end; // Hash
|
||||
|
||||
// Remove any line feeds from end of signature
|
||||
// (Not likely needed, but the verify _can_ fail if there is, so...)
|
||||
if ( [encodedSignature characterAtIndex:[encodedSignature length] - 1] == '\n' ) {
|
||||
NSMutableString *sig = [[encodedSignature mutableCopy] autorelease];
|
||||
while ( [sig characterAtIndex:[sig length] - 1] == '\n' )
|
||||
[sig deleteCharactersInRange:NSMakeRange([sig length] - 1, 1)];
|
||||
encodedSignature = sig;
|
||||
}
|
||||
if ( (sigData = b64decode(encodedSignature)) == nil ) goto validate_end; // Decode signature
|
||||
|
||||
// Verify the signature on the file
|
||||
result = cdsaVerifySignature( cspHandle, pubKey, hashData, (CFDataRef)sigData );
|
||||
|
||||
validate_end:
|
||||
cdsaReleaseKey( pubKey );
|
||||
cdsaRelease( cspHandle );
|
||||
if ( hashData ) CFRelease( hashData );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Misc Helper Functions
|
||||
#pragma mark -
|
||||
|
||||
static NSData *b64decode( NSString *str )
|
||||
{
|
||||
if ( !str ) return nil;
|
||||
NSMutableData *retval = nil;
|
||||
NSData *input = [str dataUsingEncoding:NSUTF8StringEncoding];
|
||||
UInt8 *ibuf = (UInt8 *)[input bytes], *buf = NULL, *a = NULL;
|
||||
size_t len = [input length], i = 0, j = 0, size = ((len + 3) / 4) * 3;
|
||||
static UInt8 table[256] = {
|
||||
99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99, /* 00-0F */
|
||||
99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99, /* 10-1F */
|
||||
99,99,99,99,99,99,99,99,99,99,99,62,99,99,99,63, /* 20-2F */
|
||||
52,53,54,55,56,57,58,59,60,61,99,99,99,99,99,99, /* 30-3F */
|
||||
99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14, /* 40-4F */
|
||||
15,16,17,18,19,20,21,22,23,24,25,99,99,99,99,99, /* 50-5F */
|
||||
99,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40, /* 60-6F */
|
||||
41,42,43,44,45,46,47,48,49,50,51,99,99,99,99,99, /* 70-7F */
|
||||
99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99, /* 80-8F */
|
||||
99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99, /* 90-9F */
|
||||
99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99, /* A0-AF */
|
||||
99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99, /* B0-BF */
|
||||
99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99, /* C0-CF */
|
||||
99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99, /* D0-DF */
|
||||
99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99, /* E0-EF */
|
||||
99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99 /* F0-FF */
|
||||
};
|
||||
|
||||
retval = [NSMutableData dataWithLength:size];
|
||||
buf = [retval mutableBytes];
|
||||
|
||||
if ( (a = calloc(4, sizeof(UInt8))) == NULL ) return nil;
|
||||
|
||||
do {
|
||||
size_t ai = 0;
|
||||
a[0] = a[1] = a[2] = a[3] = 0;
|
||||
do {
|
||||
UInt8 d = table[ibuf[i++]];
|
||||
if ( d != 99 ) {
|
||||
a[ai] = d;
|
||||
ai++;
|
||||
if ( ai == 4 ) break;
|
||||
}
|
||||
} while ( i < len );
|
||||
if ( ai >= 2 ) buf[j] = (a[0] << 2) | (a[1] >> 4);
|
||||
if ( ai >= 3 ) buf[j+1] = (a[1] << 4) | (a[2] >> 2);
|
||||
if ( ai >= 4 ) buf[j+2] = (a[2] << 6) | a[3];
|
||||
j += ai-1;
|
||||
} while ( i < len );
|
||||
|
||||
free( a );
|
||||
if ( j < size ) [retval setLength:j];
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
static NSData *rawKeyData( NSString *key )
|
||||
{
|
||||
if ( (key == nil) || ([key length] == 0) ) return nil;
|
||||
NSMutableString *t = [[key mutableCopy] autorelease];
|
||||
|
||||
// Remove the PEM guards (if present)
|
||||
[t replaceOccurrencesOfString:@"-" withString:@"" options:NSLiteralSearch range:NSMakeRange(0, [t length])];
|
||||
[t replaceOccurrencesOfString:@"BEGIN PUBLIC KEY" withString:@"" options:NSLiteralSearch range:NSMakeRange(0, [t length])];
|
||||
[t replaceOccurrencesOfString:@"END PUBLIC KEY" withString:@"" options:NSLiteralSearch range:NSMakeRange(0, [t length])];
|
||||
|
||||
// Remove any line feeds from the beginning of the key
|
||||
while ( [t characterAtIndex:0] == '\n' ) {
|
||||
[t deleteCharactersInRange:NSMakeRange(0, 1)];
|
||||
}
|
||||
|
||||
// Remove any line feeds at the end of the key
|
||||
while ( [t characterAtIndex:[t length] - 1] == '\n' ) {
|
||||
[t deleteCharactersInRange:NSMakeRange([t length] - 1, 1)];
|
||||
}
|
||||
|
||||
// Remove whitespace around each line of the key.
|
||||
NSMutableArray *pkeyTrimmedLines = [NSMutableArray array];
|
||||
NSCharacterSet *whiteSet = [NSCharacterSet whitespaceCharacterSet];
|
||||
for (NSString *pkeyLine in [t componentsSeparatedByString:@"\n"])
|
||||
{
|
||||
[pkeyTrimmedLines addObject:[pkeyLine stringByTrimmingCharactersInSet:whiteSet]];
|
||||
}
|
||||
key = [pkeyTrimmedLines componentsJoinedByString:@"\n"]; // Put them back together.
|
||||
|
||||
// Base64 decode to return the raw key bits (DER format rather than PEM)
|
||||
return b64decode( key );
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark CDSA
|
||||
#pragma mark -
|
||||
|
||||
/* Helper Functions */
|
||||
static CSSM_DATA_PTR su_createData( CFDataRef bytes );
|
||||
static void su_freeData( CSSM_DATA_PTR data, Boolean freeData );
|
||||
static Boolean su_copyBytesToData( CSSM_DATA_PTR data, CSSM_SIZE size, const uint8 *bytes );
|
||||
|
||||
/* Memory functions */
|
||||
static void *su_malloc( CSSM_SIZE size, void *ref );
|
||||
static void su_free( void *ptr, void *ref );
|
||||
static void *su_realloc( void *ptr, CSSM_SIZE size, void *ref );
|
||||
static void *su_calloc( uint32 num, CSSM_SIZE size, void *ref );
|
||||
|
||||
/* Constants & Typedefs */
|
||||
static CSSM_VERSION vers = { 2, 0 };
|
||||
static const CSSM_GUID su_guid = { 'S', 'p', 'a', { 'r', 'k', 'l', 'e', 0, 0, 0, 0 } };
|
||||
static CSSM_BOOL cssmInited = CSSM_FALSE;
|
||||
|
||||
static CSSM_API_MEMORY_FUNCS SU_MemFuncs = {
|
||||
su_malloc,
|
||||
su_free,
|
||||
su_realloc,
|
||||
su_calloc,
|
||||
NULL
|
||||
};
|
||||
|
||||
static CSSM_CSP_HANDLE cdsaInit( void )
|
||||
{
|
||||
CSSM_CSP_HANDLE cspHandle = CSSM_INVALID_HANDLE;
|
||||
CSSM_RETURN crtn;
|
||||
|
||||
if ( !cssmInited ) {
|
||||
CSSM_PVC_MODE pvcPolicy = CSSM_PVC_NONE;
|
||||
crtn = CSSM_Init( &vers, CSSM_PRIVILEGE_SCOPE_NONE, &su_guid, CSSM_KEY_HIERARCHY_NONE, &pvcPolicy, NULL );
|
||||
if ( crtn ) return CSSM_INVALID_HANDLE;
|
||||
cssmInited = CSSM_TRUE;
|
||||
}
|
||||
|
||||
crtn = CSSM_ModuleLoad( &gGuidAppleCSP, CSSM_KEY_HIERARCHY_NONE, NULL, NULL );
|
||||
if ( crtn ) return CSSM_INVALID_HANDLE;
|
||||
|
||||
crtn = CSSM_ModuleAttach( &gGuidAppleCSP, &vers, &SU_MemFuncs, 0, CSSM_SERVICE_CSP, 0, CSSM_KEY_HIERARCHY_NONE, NULL, 0, NULL, &cspHandle );
|
||||
if ( crtn ) return CSSM_INVALID_HANDLE;
|
||||
|
||||
return cspHandle;
|
||||
}
|
||||
|
||||
static void cdsaRelease( CSSM_CSP_HANDLE cspHandle )
|
||||
{
|
||||
if ( CSSM_ModuleDetach(cspHandle) != CSSM_OK ) return;
|
||||
CSSM_ModuleUnload( &gGuidAppleCSP, NULL, NULL );
|
||||
}
|
||||
|
||||
static CSSM_KEY_PTR cdsaCreateKey( CFDataRef rawKey )
|
||||
{
|
||||
CSSM_KEY_PTR retval = NULL;
|
||||
|
||||
if ( !rawKey || (CFDataGetLength(rawKey) == 0) ) return NULL;
|
||||
|
||||
if ( (retval = su_malloc(sizeof(CSSM_KEY), NULL)) == NULL ) return NULL;
|
||||
|
||||
if ( !su_copyBytesToData(&(retval->KeyData), CFDataGetLength(rawKey), CFDataGetBytePtr(rawKey)) ) {
|
||||
su_free( retval, NULL );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CSSM_KEYHEADER_PTR hdr = &(retval->KeyHeader);
|
||||
|
||||
memset( hdr, 0, sizeof(CSSM_KEYHEADER) );
|
||||
|
||||
hdr->HeaderVersion = CSSM_KEYHEADER_VERSION;
|
||||
hdr->CspId = su_guid;
|
||||
hdr->BlobType = CSSM_KEYBLOB_RAW;
|
||||
hdr->Format = CSSM_KEYBLOB_RAW_FORMAT_X509;
|
||||
hdr->AlgorithmId = CSSM_ALGID_DSA;
|
||||
hdr->KeyClass = CSSM_KEYCLASS_PUBLIC_KEY;
|
||||
hdr->KeyAttr = CSSM_KEYATTR_EXTRACTABLE;
|
||||
hdr->KeyUsage = CSSM_KEYUSE_ANY;
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
static void cdsaReleaseKey( CSSM_KEY_PTR key )
|
||||
{
|
||||
if ( key ) {
|
||||
if ( key->KeyData.Data ) su_free( key->KeyData.Data, NULL );
|
||||
su_free( key, NULL );
|
||||
}
|
||||
}
|
||||
|
||||
BOOL cdsaVerifyKey( CSSM_CSP_HANDLE cspHandle, CSSM_KEY_PTR key )
|
||||
{
|
||||
if ( key->KeyHeader.LogicalKeySizeInBits == 0 ) {
|
||||
CSSM_RETURN crtn;
|
||||
CSSM_KEY_SIZE keySize;
|
||||
|
||||
/* This will fail if the key isn't valid */
|
||||
crtn = CSSM_QueryKeySizeInBits( cspHandle, CSSM_INVALID_HANDLE, key, &keySize );
|
||||
if ( crtn ) return NO;
|
||||
key->KeyHeader.LogicalKeySizeInBits = keySize.LogicalKeySizeInBits;
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
||||
static BOOL cdsaVerifySignature( CSSM_CSP_HANDLE cspHandle, const CSSM_KEY_PTR key, const CFDataRef msg, const CFDataRef signature )
|
||||
{
|
||||
CSSM_CC_HANDLE ccHandle = CSSM_INVALID_HANDLE;
|
||||
CSSM_DATA_PTR plain = su_createData( msg ), cipher = su_createData( signature );
|
||||
BOOL retval = NO;
|
||||
|
||||
if ( !plain || !cipher || (CSSM_CSP_CreateSignatureContext(cspHandle, CSSM_ALGID_SHA1WithDSA, NULL, key, &ccHandle) != CSSM_OK) )
|
||||
goto verify_end;
|
||||
|
||||
retval = ( CSSM_VerifyData(ccHandle, plain, 1, CSSM_ALGID_NONE, cipher) == CSSM_OK );
|
||||
|
||||
verify_end:
|
||||
su_freeData( plain, true );
|
||||
su_freeData( cipher, true );
|
||||
if ( ccHandle ) CSSM_DeleteContext( ccHandle );
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
static CFDataRef cdsaCreateSHA1Digest( CSSM_CSP_HANDLE cspHandle, const CFDataRef bytes )
|
||||
{
|
||||
CSSM_CC_HANDLE ccHandle = CSSM_INVALID_HANDLE;
|
||||
CSSM_DATA_PTR data = su_createData( bytes ), dgst = su_createData( NULL );
|
||||
CFDataRef retval = NULL;
|
||||
|
||||
if ( !data || !dgst || (CSSM_CSP_CreateDigestContext(cspHandle, CSSM_ALGID_SHA1, &ccHandle) != CSSM_OK) )
|
||||
goto digest_end;
|
||||
|
||||
if ( CSSM_DigestData(ccHandle, data, 1, dgst) == CSSM_OK )
|
||||
retval = CFDataCreate( kCFAllocatorDefault, (const UInt8 *)dgst->Data, (CFIndex)dgst->Length );
|
||||
|
||||
digest_end:
|
||||
su_freeData( data, true );
|
||||
su_freeData( dgst, true );
|
||||
if ( ccHandle ) CSSM_DeleteContext( ccHandle );
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* Memory Functions */
|
||||
static void *su_malloc( CSSM_SIZE size, void *ref )
|
||||
{
|
||||
return malloc( size );
|
||||
}
|
||||
|
||||
static void su_free( void *ptr, void *ref )
|
||||
{
|
||||
free( ptr );
|
||||
}
|
||||
|
||||
static void *su_realloc( void *ptr, CSSM_SIZE size, void *ref )
|
||||
{
|
||||
return realloc( ptr, size );
|
||||
}
|
||||
|
||||
static void *su_calloc( uint32 num, CSSM_SIZE size, void *ref )
|
||||
{
|
||||
return calloc( num, size );
|
||||
}
|
||||
|
||||
/* Helper Functions */
|
||||
static CSSM_DATA_PTR su_createData( CFDataRef bytes )
|
||||
{
|
||||
CSSM_DATA_PTR data = su_malloc( sizeof(CSSM_DATA), NULL );
|
||||
if ( !data ) return NULL;
|
||||
data->Data = NULL;
|
||||
data->Length = 0;
|
||||
if ( bytes ) su_copyBytesToData( data, CFDataGetLength(bytes), CFDataGetBytePtr(bytes) );
|
||||
return data;
|
||||
}
|
||||
|
||||
static void su_freeData( CSSM_DATA_PTR data, Boolean freeData )
|
||||
{
|
||||
if ( data ) {
|
||||
if ( freeData && data->Data ) su_free( data->Data, NULL );
|
||||
su_free( data, NULL );
|
||||
}
|
||||
}
|
||||
|
||||
static Boolean su_copyBytesToData( CSSM_DATA_PTR data, CSSM_SIZE size, const uint8 *bytes )
|
||||
{
|
||||
Boolean retval = false;
|
||||
if ( size && bytes ) {
|
||||
if ( (data->Data = su_malloc(size, NULL)) ) {
|
||||
memcpy( data->Data, bytes, size );
|
||||
data->Length = size;
|
||||
retval = true;
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
@@ -12,8 +12,7 @@
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "SUUnarchiver.h"
|
||||
|
||||
@interface SUDiskImageUnarchiver : SUUnarchiver {
|
||||
}
|
||||
@interface SUDiskImageUnarchiver : SUUnarchiver
|
||||
|
||||
@end
|
||||
|
||||
|
||||
+179
-53
@@ -9,71 +9,197 @@
|
||||
#import "SUDiskImageUnarchiver.h"
|
||||
#import "SUUnarchiver_Private.h"
|
||||
#import "NTSynchronousTask.h"
|
||||
#import "SULog.h"
|
||||
#import <CoreServices/CoreServices.h>
|
||||
|
||||
@implementation SUDiskImageUnarchiver
|
||||
|
||||
+ (BOOL)_canUnarchiveURL:(NSURL *)URL
|
||||
+ (BOOL)canUnarchivePath:(NSString *)path
|
||||
{
|
||||
return [URL conformsToType:@"public.disk-image"];
|
||||
return [[path pathExtension] isEqualToString:@"dmg"];
|
||||
}
|
||||
|
||||
// Called on a non-main thread.
|
||||
- (void)extractDMG
|
||||
{
|
||||
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
NSData *result = [NTSynchronousTask task:@"/usr/bin/hdiutil" directory:@"/" withArgs:[NSArray arrayWithObjects: @"isencrypted", archivePath, nil] input:NULL];
|
||||
if([self isEncrypted:result] && [delegate respondsToSelector:@selector(unarchiver:requiresPasswordReturnedViaInvocation:)]) {
|
||||
[self performSelectorOnMainThread:@selector(requestPasswordFromDelegate) withObject:nil waitUntilDone:NO];
|
||||
} else {
|
||||
[self extractDMGWithPassword:nil];
|
||||
}
|
||||
|
||||
[pool release];
|
||||
}
|
||||
|
||||
// Called on a non-main thread.
|
||||
- (void)extractDMGWithPassword:(NSString *)password
|
||||
{
|
||||
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
BOOL mountedSuccessfully = NO;
|
||||
|
||||
SULog(@"Extracting %@ as a DMG", archivePath);
|
||||
|
||||
// get a unique mount point path
|
||||
NSString *mountPointName = nil;
|
||||
NSString *mountPoint = nil;
|
||||
FSRef tmpRef;
|
||||
do
|
||||
{
|
||||
CFUUIDRef uuid = CFUUIDCreate(NULL);
|
||||
if (uuid)
|
||||
{
|
||||
CFStringRef uuidString = CFUUIDCreateString(NULL, uuid);
|
||||
if (uuidString)
|
||||
{
|
||||
mountPoint = [@"/Volumes" stringByAppendingPathComponent:(NSString*)uuidString];
|
||||
CFRelease(uuidString);
|
||||
}
|
||||
CFRelease(uuid);
|
||||
}
|
||||
}
|
||||
while (noErr == FSPathMakeRefWithOptions((UInt8 *)[mountPoint fileSystemRepresentation], kFSPathMakeRefDoNotFollowLeafSymlink, &tmpRef, NULL));
|
||||
|
||||
NSData *promptData = nil;
|
||||
if (password) {
|
||||
NSString *data = [NSString stringWithFormat:@"%@\nyes\n", password];
|
||||
const char *bytes = [data cStringUsingEncoding:NSUTF8StringEncoding];
|
||||
NSUInteger length = [data lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
|
||||
promptData = [NSData dataWithBytes:bytes length:length];
|
||||
}
|
||||
else
|
||||
promptData = [NSData dataWithBytes:"yes\n" length:4];
|
||||
|
||||
NSArray* arguments = [NSArray arrayWithObjects:@"attach", archivePath, @"-mountpoint", mountPoint, /*@"-noverify",*/ @"-nobrowse", @"-noautoopen", nil];
|
||||
|
||||
NSData *output = nil;
|
||||
NSInteger taskResult = -1;
|
||||
@try
|
||||
{
|
||||
NTSynchronousTask* task = [[NTSynchronousTask alloc] init];
|
||||
|
||||
[task run:@"/usr/bin/hdiutil" directory:@"/" withArgs:arguments input:promptData];
|
||||
|
||||
taskResult = [task result];
|
||||
output = [[[task output] copy] autorelease];
|
||||
[task release];
|
||||
}
|
||||
@catch (NSException *localException)
|
||||
{
|
||||
goto reportError;
|
||||
}
|
||||
|
||||
if (taskResult != 0)
|
||||
{
|
||||
NSString* resultStr = output ? [[[NSString alloc] initWithData: output encoding: NSUTF8StringEncoding] autorelease] : nil;
|
||||
if (password != nil && [resultStr rangeOfString:@"Authentication error"].location != NSNotFound && [delegate respondsToSelector:@selector(unarchiver:requiresPasswordReturnedViaInvocation:)]) {
|
||||
[self performSelectorOnMainThread:@selector(requestPasswordFromDelegate) withObject:nil waitUntilDone:NO];
|
||||
goto finally;
|
||||
} else {
|
||||
SULog( @"hdiutil failed with code: %d data: <<%@>>", taskResult, resultStr );
|
||||
goto reportError;
|
||||
}
|
||||
}
|
||||
mountedSuccessfully = YES;
|
||||
|
||||
// Now that we've mounted it, we need to copy out its contents.
|
||||
if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_6) {
|
||||
// On 10.7 and later we don't want to use the File Manager API and instead want to use NSFileManager (fixes #827357).
|
||||
NSFileManager *manager = [[[NSFileManager alloc] init] autorelease];
|
||||
NSError *error = nil;
|
||||
NSArray *contents = [manager contentsOfDirectoryAtPath:mountPoint error:&error];
|
||||
if (error)
|
||||
{
|
||||
SULog(@"Couldn't enumerate contents of archive mounted at %@: %@", mountPoint, error);
|
||||
goto reportError;
|
||||
}
|
||||
|
||||
for (NSString *item in contents)
|
||||
{
|
||||
NSString *fromPath = [mountPoint stringByAppendingPathComponent:item];
|
||||
NSString *toPath = [[archivePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:item];
|
||||
|
||||
// We skip any files in the DMG which are not readable.
|
||||
if (![manager isReadableFileAtPath:fromPath])
|
||||
continue;
|
||||
|
||||
SULog(@"copyItemAtPath:%@ toPath:%@", fromPath, toPath);
|
||||
|
||||
if (![manager copyItemAtPath:fromPath toPath:toPath error:&error])
|
||||
{
|
||||
SULog(@"Couldn't copy item: %@ : %@", error, error.userInfo ? error.userInfo : @"");
|
||||
goto reportError;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
FSRef srcRef, dstRef;
|
||||
OSStatus err;
|
||||
err = FSPathMakeRef((UInt8 *)[mountPoint fileSystemRepresentation], &srcRef, NULL);
|
||||
if (err != noErr) goto reportError;
|
||||
err = FSPathMakeRef((UInt8 *)[[archivePath stringByDeletingLastPathComponent] fileSystemRepresentation], &dstRef, NULL);
|
||||
if (err != noErr) goto reportError;
|
||||
|
||||
err = FSCopyObjectSync(&srcRef, &dstRef, (CFStringRef)mountPointName, NULL, kFSFileOperationSkipSourcePermissionErrors);
|
||||
if (err != noErr) goto reportError;
|
||||
}
|
||||
|
||||
[self performSelectorOnMainThread:@selector(notifyDelegateOfSuccess) withObject:nil waitUntilDone:NO];
|
||||
goto finally;
|
||||
|
||||
reportError:
|
||||
[self performSelectorOnMainThread:@selector(notifyDelegateOfFailure) withObject:nil waitUntilDone:NO];
|
||||
|
||||
finally:
|
||||
if (mountedSuccessfully)
|
||||
[NSTask launchedTaskWithLaunchPath:@"/usr/bin/hdiutil" arguments:[NSArray arrayWithObjects:@"detach", mountPoint, @"-force", nil]];
|
||||
else
|
||||
SULog(@"Can't mount DMG %@",archivePath);
|
||||
[pool drain];
|
||||
}
|
||||
|
||||
- (void)start
|
||||
{
|
||||
[NSThread detachNewThreadSelector:@selector(_extractDMG) toTarget:self withObject:nil];
|
||||
}
|
||||
|
||||
- (void)_extractDMG
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
NSString *archivePath = [archiveURL path];
|
||||
BOOL mountedSuccessfully = NO;
|
||||
|
||||
// get a unique mount point path
|
||||
NSString *mountPrefix = [@"/Volumes" stringByAppendingPathComponent:[[archivePath lastPathComponent] stringByDeletingPathExtension]];
|
||||
NSString *mountPoint = [mountPrefix stringByAppendingString:[[NSProcessInfo processInfo] globallyUniqueString]];
|
||||
|
||||
if ([[NSFileManager defaultManager] fileExistsAtPath:mountPoint]) goto reportError;
|
||||
|
||||
// create mount point folder
|
||||
[[NSFileManager defaultManager] createDirectoryAtPath:mountPoint attributes:nil];
|
||||
if (![[NSFileManager defaultManager] fileExistsAtPath:mountPoint]) goto reportError;
|
||||
|
||||
NSArray* arguments = [NSArray arrayWithObjects:@"attach", archivePath, @"-mountpoint", mountPoint, @"-noverify", @"-nobrowse", @"-noautoopen", nil];
|
||||
// set up a pipe and push "yes" (y works too), this will accept any license agreement crap
|
||||
// not every .dmg needs this, but this will make sure it works with everyone
|
||||
NSData* yesData = [[[NSData alloc] initWithBytes:"yes\n" length:4] autorelease];
|
||||
|
||||
NSData *result = [NTSynchronousTask task:@"/usr/bin/hdiutil" directory:@"/" withArgs:arguments input:yesData];
|
||||
if (!result) goto reportError;
|
||||
mountedSuccessfully = YES;
|
||||
|
||||
// Now that we've mounted it, we need to copy out its contents.
|
||||
NSString *targetPath = [[archivePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:[mountPoint lastPathComponent]];
|
||||
if (![[NSFileManager defaultManager] createDirectoryAtPath:targetPath attributes:nil]) goto reportError;
|
||||
|
||||
// We can't just copyPath: from the volume root because that always fails. Seems to be a bug.
|
||||
id subpathEnumerator = [[[NSFileManager defaultManager] directoryContentsAtPath:mountPoint] objectEnumerator], currentSubpath;
|
||||
while ((currentSubpath = [subpathEnumerator nextObject]))
|
||||
{
|
||||
if (![[NSFileManager defaultManager] copyPath:[mountPoint stringByAppendingPathComponent:currentSubpath] toPath:[targetPath stringByAppendingPathComponent:currentSubpath] handler:nil])
|
||||
goto reportError;
|
||||
}
|
||||
|
||||
[self performSelectorOnMainThread:@selector(_notifyDelegateOfSuccess) withObject:nil waitUntilDone:NO];
|
||||
goto finally;
|
||||
|
||||
reportError:
|
||||
[self performSelectorOnMainThread:@selector(_notifyDelegateOfFailure) withObject:nil waitUntilDone:NO];
|
||||
|
||||
finally:
|
||||
if (mountedSuccessfully)
|
||||
[NSTask launchedTaskWithLaunchPath:@"/usr/bin/hdiutil" arguments:[NSArray arrayWithObjects:@"detach", mountPoint, @"-force", nil]];
|
||||
[pool drain];
|
||||
[NSThread detachNewThreadSelector:@selector(extractDMG) toTarget:self withObject:nil];
|
||||
}
|
||||
|
||||
+ (void)load
|
||||
{
|
||||
[self _registerImplementation:self];
|
||||
[self registerImplementation:self];
|
||||
}
|
||||
|
||||
- (BOOL)isEncrypted:(NSData*)resultData
|
||||
{
|
||||
BOOL result = NO;
|
||||
if(resultData)
|
||||
{
|
||||
NSString *data = [[[NSString alloc] initWithData:resultData encoding:NSUTF8StringEncoding] autorelease];
|
||||
|
||||
if ((data != nil) && !NSEqualRanges([data rangeOfString:@"passphrase-count"], NSMakeRange(NSNotFound, 0)))
|
||||
{
|
||||
result = YES;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
- (void)requestPasswordFromDelegate
|
||||
{
|
||||
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[self methodSignatureForSelector:@selector(continueWithPassword:)]];
|
||||
[invocation setSelector:@selector(continueWithPassword:)];
|
||||
[invocation setTarget:self];
|
||||
[invocation retainArguments];
|
||||
[delegate unarchiver:self requiresPasswordReturnedViaInvocation:invocation];
|
||||
}
|
||||
|
||||
- (void)continueWithPassword:(NSString *)password
|
||||
{
|
||||
[NSThread detachNewThreadSelector:@selector(extractDMGWithPassword:) toTarget:self withObject:password];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,45 @@
|
||||
//
|
||||
// SUHost.h
|
||||
// Sparkle
|
||||
//
|
||||
// Copyright 2008 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUUpdater.h"
|
||||
#import "SUAppcast.h"
|
||||
#import "SUAppcastItem.h"
|
||||
#import "SUVersionComparisonProtocol.h"
|
||||
|
||||
@interface SUHost : NSObject
|
||||
{
|
||||
@private
|
||||
NSBundle *bundle;
|
||||
NSString *defaultsDomain;
|
||||
BOOL usesStandardUserDefaults;
|
||||
}
|
||||
@property (retain, readonly) NSBundle *bundle;
|
||||
|
||||
+ (NSString *)systemVersionString;
|
||||
|
||||
- (id)initWithBundle:(NSBundle *)aBundle;
|
||||
- (NSString *)bundlePath;
|
||||
- (NSString *)appSupportPath;
|
||||
- (NSString *)installationPath;
|
||||
- (NSString *)name;
|
||||
- (NSString *)version;
|
||||
- (NSString *)displayVersion;
|
||||
- (NSImage *)icon;
|
||||
- (BOOL)isRunningOnReadOnlyVolume;
|
||||
- (BOOL)isBackgroundApplication;
|
||||
- (NSString *)publicDSAKey;
|
||||
- (NSArray *)systemProfile;
|
||||
|
||||
- (id)objectForInfoDictionaryKey:(NSString *)key;
|
||||
- (BOOL)boolForInfoDictionaryKey:(NSString *)key;
|
||||
- (id)objectForUserDefaultsKey:(NSString *)defaultName;
|
||||
- (void)setObject:(id)value forUserDefaultsKey:(NSString *)defaultName;
|
||||
- (BOOL)boolForUserDefaultsKey:(NSString *)defaultName;
|
||||
- (void)setBool:(BOOL)value forUserDefaultsKey:(NSString *)defaultName;
|
||||
- (id)objectForKey:(NSString *)key;
|
||||
- (BOOL)boolForKey:(NSString *)key;
|
||||
@end
|
||||
@@ -0,0 +1,263 @@
|
||||
//
|
||||
// SUHost.m
|
||||
// Sparkle
|
||||
//
|
||||
// Copyright 2008 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUHost.h"
|
||||
|
||||
#import "SUConstants.h"
|
||||
#import "SUSystemProfiler.h"
|
||||
#import <sys/mount.h> // For statfs for isRunningOnReadOnlyVolume
|
||||
#import "SULog.h"
|
||||
|
||||
@interface SUHost ()
|
||||
@property (retain, readwrite) NSBundle *bundle;
|
||||
@end
|
||||
|
||||
@implementation SUHost
|
||||
@synthesize bundle;
|
||||
|
||||
- (id)initWithBundle:(NSBundle *)aBundle
|
||||
{
|
||||
if ((self = [super init]))
|
||||
{
|
||||
if (aBundle == nil) aBundle = [NSBundle mainBundle];
|
||||
self.bundle = aBundle;
|
||||
if (![bundle bundleIdentifier])
|
||||
SULog(@"Sparkle Error: the bundle being updated at %@ has no CFBundleIdentifier! This will cause preference read/write to not work properly.", bundle);
|
||||
|
||||
defaultsDomain = [[bundle objectForInfoDictionaryKey:SUDefaultsDomainKey] retain];
|
||||
if (!defaultsDomain)
|
||||
defaultsDomain = [[bundle bundleIdentifier] retain];
|
||||
|
||||
// If we're using the main bundle's defaults we'll use the standard user defaults mechanism, otherwise we have to get CF-y.
|
||||
usesStandardUserDefaults = [defaultsDomain isEqualToString:[[NSBundle mainBundle] bundleIdentifier]];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[defaultsDomain release];
|
||||
self.bundle = nil;
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@, %@>", [self class], [self bundlePath], [self installationPath]]; }
|
||||
|
||||
- (NSString *)bundlePath
|
||||
{
|
||||
return [bundle bundlePath];
|
||||
}
|
||||
|
||||
- (NSString *)appSupportPath
|
||||
{
|
||||
NSArray *appSupportPaths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
|
||||
NSString *appSupportPath = nil;
|
||||
if (!appSupportPaths || [appSupportPaths count] == 0)
|
||||
{
|
||||
SULog(@"Failed to find app support directory! Using ~/Library/Application Support...");
|
||||
appSupportPath = [@"~/Library/Application Support" stringByExpandingTildeInPath];
|
||||
}
|
||||
else
|
||||
appSupportPath = [appSupportPaths objectAtIndex:0];
|
||||
appSupportPath = [appSupportPath stringByAppendingPathComponent:[self name]];
|
||||
appSupportPath = [appSupportPath stringByAppendingPathComponent:@".Sparkle"];
|
||||
return appSupportPath;
|
||||
}
|
||||
|
||||
- (NSString *)installationPath
|
||||
{
|
||||
#if NORMALIZE_INSTALLED_APP_NAME
|
||||
// We'll install to "#{CFBundleName}.app", but only if that path doesn't already exist. If we're "Foo 4.2.app," and there's a "Foo.app" in this directory, we don't want to overwrite it! But if there's no "Foo.app," we'll take that name.
|
||||
NSString *normalizedAppPath = [[[bundle bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent: [NSString stringWithFormat: @"%@.%@", [bundle objectForInfoDictionaryKey:@"CFBundleName"], [[bundle bundlePath] pathExtension]]];
|
||||
if (![[NSFileManager defaultManager] fileExistsAtPath:[[[bundle bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent: [NSString stringWithFormat: @"%@.%@", [bundle objectForInfoDictionaryKey:@"CFBundleName"], [[bundle bundlePath] pathExtension]]]])
|
||||
return normalizedAppPath;
|
||||
#endif
|
||||
return [bundle bundlePath];
|
||||
}
|
||||
|
||||
- (NSString *)name
|
||||
{
|
||||
NSString *name = [bundle objectForInfoDictionaryKey:@"CFBundleDisplayName"];
|
||||
if (name) return name;
|
||||
|
||||
name = [self objectForInfoDictionaryKey:@"CFBundleName"];
|
||||
if (name) return name;
|
||||
|
||||
return [[[NSFileManager defaultManager] displayNameAtPath:[bundle bundlePath]] stringByDeletingPathExtension];
|
||||
}
|
||||
|
||||
- (NSString *)version
|
||||
{
|
||||
NSString *version = [bundle objectForInfoDictionaryKey:@"CFBundleVersion"];
|
||||
if (!version || [version isEqualToString:@""])
|
||||
[NSException raise:@"SUNoVersionException" format:@"This host (%@) has no CFBundleVersion! This attribute is required.", [self bundlePath]];
|
||||
return version;
|
||||
}
|
||||
|
||||
- (NSString *)displayVersion
|
||||
{
|
||||
NSString *shortVersionString = [bundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
|
||||
if (shortVersionString)
|
||||
return shortVersionString;
|
||||
else
|
||||
return [self version]; // Fall back on the normal version string.
|
||||
}
|
||||
|
||||
- (NSImage *)icon
|
||||
{
|
||||
// Cache the application icon.
|
||||
NSString *iconPath = [bundle pathForResource:[bundle objectForInfoDictionaryKey:@"CFBundleIconFile"] ofType:@"icns"];
|
||||
// According to the OS X docs, "CFBundleIconFile - This key identifies the file containing
|
||||
// the icon for the bundle. The filename you specify does not need to include the .icns
|
||||
// extension, although it may."
|
||||
//
|
||||
// However, if it *does* include the '.icns' the above method fails (tested on OS X 10.3.9) so we'll also try:
|
||||
if (!iconPath)
|
||||
iconPath = [bundle pathForResource:[bundle objectForInfoDictionaryKey:@"CFBundleIconFile"] ofType: nil];
|
||||
NSImage *icon = [[[NSImage alloc] initWithContentsOfFile:iconPath] autorelease];
|
||||
// Use a default icon if none is defined.
|
||||
if (!icon) {
|
||||
BOOL isMainBundle = (bundle == [NSBundle mainBundle]);
|
||||
|
||||
NSString *fileType = isMainBundle ? (NSString*)kUTTypeApplication : (NSString*)kUTTypeBundle;
|
||||
icon = [[NSWorkspace sharedWorkspace] iconForFileType:fileType];
|
||||
}
|
||||
return icon;
|
||||
}
|
||||
|
||||
- (BOOL)isRunningOnReadOnlyVolume
|
||||
{
|
||||
struct statfs statfs_info;
|
||||
statfs([[bundle bundlePath] fileSystemRepresentation], &statfs_info);
|
||||
return (statfs_info.f_flags & MNT_RDONLY);
|
||||
}
|
||||
|
||||
- (BOOL)isBackgroundApplication
|
||||
{
|
||||
ProcessSerialNumber PSN;
|
||||
GetCurrentProcess(&PSN);
|
||||
CFDictionaryRef processInfo = ProcessInformationCopyDictionary(&PSN, kProcessDictionaryIncludeAllInformationMask);
|
||||
BOOL isElement = [[(NSDictionary *)processInfo objectForKey:@"LSUIElement"] boolValue];
|
||||
if (processInfo)
|
||||
CFRelease(processInfo);
|
||||
return isElement;
|
||||
}
|
||||
|
||||
- (NSString *)publicDSAKey
|
||||
{
|
||||
// Maybe the key is just a string in the Info.plist.
|
||||
NSString *key = [bundle objectForInfoDictionaryKey:SUPublicDSAKeyKey];
|
||||
if (key) { return key; }
|
||||
|
||||
// More likely, we've got a reference to a Resources file by filename:
|
||||
NSString *keyFilename = [self objectForInfoDictionaryKey:SUPublicDSAKeyFileKey];
|
||||
if (!keyFilename) { return nil; }
|
||||
NSError *ignoreErr = nil;
|
||||
return [NSString stringWithContentsOfFile:[bundle pathForResource:keyFilename ofType:nil] encoding:NSASCIIStringEncoding error: &ignoreErr];
|
||||
}
|
||||
|
||||
- (NSArray *)systemProfile
|
||||
{
|
||||
return [[SUSystemProfiler sharedSystemProfiler] systemProfileArrayForHost:self];
|
||||
}
|
||||
|
||||
- (id)objectForInfoDictionaryKey:(NSString *)key
|
||||
{
|
||||
return [bundle objectForInfoDictionaryKey:key];
|
||||
}
|
||||
|
||||
- (BOOL)boolForInfoDictionaryKey:(NSString *)key
|
||||
{
|
||||
return [[self objectForInfoDictionaryKey:key] boolValue];
|
||||
}
|
||||
|
||||
- (id)objectForUserDefaultsKey:(NSString *)defaultName
|
||||
{
|
||||
// Under Tiger, CFPreferencesCopyAppValue doesn't get values from NSRegistrationDomain, so anything
|
||||
// passed into -[NSUserDefaults registerDefaults:] is ignored. The following line falls
|
||||
// back to using NSUserDefaults, but only if the host bundle is the main bundle.
|
||||
if (usesStandardUserDefaults)
|
||||
return [[NSUserDefaults standardUserDefaults] objectForKey:defaultName];
|
||||
|
||||
CFPropertyListRef obj = CFPreferencesCopyAppValue((CFStringRef)defaultName, (CFStringRef)defaultsDomain);
|
||||
return [(id)CFMakeCollectable(obj) autorelease];
|
||||
}
|
||||
|
||||
- (void)setObject:(id)value forUserDefaultsKey:(NSString *)defaultName;
|
||||
{
|
||||
if (usesStandardUserDefaults)
|
||||
{
|
||||
[[NSUserDefaults standardUserDefaults] setObject:value forKey:defaultName];
|
||||
}
|
||||
else
|
||||
{
|
||||
CFPreferencesSetValue((CFStringRef)defaultName, value, (CFStringRef)defaultsDomain, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
|
||||
CFPreferencesSynchronize((CFStringRef)defaultsDomain, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)boolForUserDefaultsKey:(NSString *)defaultName
|
||||
{
|
||||
if (usesStandardUserDefaults)
|
||||
return [[NSUserDefaults standardUserDefaults] boolForKey:defaultName];
|
||||
|
||||
BOOL value;
|
||||
CFPropertyListRef plr = CFPreferencesCopyAppValue((CFStringRef)defaultName, (CFStringRef)defaultsDomain);
|
||||
if (plr == NULL)
|
||||
value = NO;
|
||||
else
|
||||
{
|
||||
value = (BOOL)CFBooleanGetValue((CFBooleanRef)plr);
|
||||
CFRelease(plr);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
- (void)setBool:(BOOL)value forUserDefaultsKey:(NSString *)defaultName
|
||||
{
|
||||
if (usesStandardUserDefaults)
|
||||
{
|
||||
[[NSUserDefaults standardUserDefaults] setBool:value forKey:defaultName];
|
||||
}
|
||||
else
|
||||
{
|
||||
CFPreferencesSetValue((CFStringRef)defaultName, (CFBooleanRef)[NSNumber numberWithBool:value], (CFStringRef)defaultsDomain, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
|
||||
CFPreferencesSynchronize((CFStringRef)defaultsDomain, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
|
||||
}
|
||||
}
|
||||
|
||||
- (id)objectForKey:(NSString *)key {
|
||||
return [self objectForUserDefaultsKey:key] ? [self objectForUserDefaultsKey:key] : [self objectForInfoDictionaryKey:key];
|
||||
}
|
||||
|
||||
- (BOOL)boolForKey:(NSString *)key {
|
||||
return [self objectForUserDefaultsKey:key] ? [self boolForUserDefaultsKey:key] : [self boolForInfoDictionaryKey:key];
|
||||
}
|
||||
|
||||
+ (NSString *)systemVersionString
|
||||
{
|
||||
// This returns a version string of the form X.Y.Z
|
||||
// There may be a better way to deal with the problem that gestaltSystemVersionMajor
|
||||
// et al. are not defined in 10.3, but this is probably good enough.
|
||||
NSString* verStr = nil;
|
||||
SInt32 major, minor, bugfix;
|
||||
OSErr err1 = Gestalt(gestaltSystemVersionMajor, &major);
|
||||
OSErr err2 = Gestalt(gestaltSystemVersionMinor, &minor);
|
||||
OSErr err3 = Gestalt(gestaltSystemVersionBugFix, &bugfix);
|
||||
if (!err1 && !err2 && !err3)
|
||||
{
|
||||
verStr = [NSString stringWithFormat:@"%ld.%ld.%ld", (long)major, (long)minor, (long)bugfix];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSString *versionPlistPath = @"/System/Library/CoreServices/SystemVersion.plist";
|
||||
verStr = [[NSDictionary dictionaryWithContentsOfFile:versionPlistPath] objectForKey:@"ProductVersion"];
|
||||
}
|
||||
return verStr;
|
||||
}
|
||||
|
||||
@end
|
||||
+10
-5
@@ -10,15 +10,20 @@
|
||||
#define SUINSTALLER_H
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "SUVersionComparisonProtocol.h"
|
||||
|
||||
@interface SUInstaller : NSObject { }
|
||||
+ (void)installFromUpdateFolder:(NSString *)updateFolder overHostBundle:(NSBundle *)hostBundle delegate:delegate synchronously:(BOOL)synchronously;
|
||||
+ (void)_finishInstallationWithResult:(BOOL)result hostBundle:(NSBundle *)hostBundle error:(NSError *)error delegate:delegate;
|
||||
@class SUHost;
|
||||
@interface SUInstaller : NSObject
|
||||
+ (NSString *) appPathInUpdateFolder:(NSString *)updateFolder forHost:(SUHost *)host;
|
||||
+ (void) installFromUpdateFolder:(NSString *)updateFolder overHost:(SUHost *)host installationPath:(NSString *)installationPath delegate:delegate synchronously:(BOOL)synchronously versionComparator:(id <SUVersionComparison>)comparator;
|
||||
+ (void) finishInstallationToPath:(NSString *)installationPath withResult:(BOOL)result host:(SUHost *)host error:(NSError *)error delegate:delegate;
|
||||
+ (NSString*) updateFolder;
|
||||
+ (void) notifyDelegateOfFailure: (NSDictionary*)dict;
|
||||
@end
|
||||
|
||||
@interface NSObject (SUInstallerDelegateInformalProtocol)
|
||||
- (void)installerFinishedForHostBundle:(NSBundle *)hostBundle;
|
||||
- (void)installerForHostBundle:(NSBundle *)hostBundle failedWithError:(NSError *)error;
|
||||
- (void)installerFinishedForHost:(SUHost *)host;
|
||||
- (void)installerForHost:(SUHost *)host failedWithError:(NSError *)error;
|
||||
@end
|
||||
|
||||
#endif
|
||||
+128
-32
@@ -9,22 +9,56 @@
|
||||
#import "SUInstaller.h"
|
||||
#import "SUPlainInstaller.h"
|
||||
#import "SUPackageInstaller.h"
|
||||
#import "SUHost.h"
|
||||
#import "SUConstants.h"
|
||||
#import "SULog.h"
|
||||
|
||||
NSString *SUInstallerPathKey = @"SUInstallerPath";
|
||||
NSString *SUInstallerHostBundleKey = @"SUInstallerHostBundle";
|
||||
NSString *SUInstallerDelegateKey = @"SUInstallerDelegate";
|
||||
|
||||
@implementation SUInstaller
|
||||
|
||||
+ (void)installFromUpdateFolder:(NSString *)updateFolder overHostBundle:(NSBundle *)hostBundle delegate:delegate synchronously:(BOOL)synchronously
|
||||
static NSString* sUpdateFolder = nil;
|
||||
|
||||
+(NSString*) updateFolder
|
||||
{
|
||||
// Search subdirectories for the application
|
||||
NSString *currentFile, *newAppDownloadPath = nil, *bundleFileName = [[hostBundle bundlePath] lastPathComponent], *alternateBundleFileName = [[hostBundle name] stringByAppendingPathExtension:[[hostBundle bundlePath] pathExtension]];
|
||||
return sUpdateFolder;
|
||||
}
|
||||
|
||||
+ (BOOL)isAliasFolderAtPath:(NSString *)path
|
||||
{
|
||||
FSRef fileRef;
|
||||
OSStatus err = noErr;
|
||||
Boolean aliasFileFlag, folderFlag;
|
||||
NSURL *fileURL = [NSURL fileURLWithPath:path];
|
||||
|
||||
if (FALSE == CFURLGetFSRef((CFURLRef)fileURL, &fileRef))
|
||||
err = coreFoundationUnknownErr;
|
||||
|
||||
if (noErr == err)
|
||||
err = FSIsAliasFile(&fileRef, &aliasFileFlag, &folderFlag);
|
||||
|
||||
if (noErr == err)
|
||||
return (BOOL)(aliasFileFlag && folderFlag);
|
||||
else
|
||||
return NO;
|
||||
}
|
||||
|
||||
+ (NSString *)installSourcePathInUpdateFolder:(NSString *)inUpdateFolder forHost:(SUHost *)host isPackage:(BOOL *)isPackagePtr
|
||||
{
|
||||
// Search subdirectories for the application
|
||||
NSString *currentFile,
|
||||
*newAppDownloadPath = nil,
|
||||
*bundleFileName = [[host bundlePath] lastPathComponent],
|
||||
*alternateBundleFileName = [[host name] stringByAppendingPathExtension:[[host bundlePath] pathExtension]];
|
||||
BOOL isPackage = NO;
|
||||
NSDirectoryEnumerator *dirEnum = [[NSFileManager defaultManager] enumeratorAtPath:updateFolder];
|
||||
NSString *fallbackPackagePath = nil;
|
||||
NSDirectoryEnumerator *dirEnum = [[NSFileManager defaultManager] enumeratorAtPath: inUpdateFolder];
|
||||
|
||||
[sUpdateFolder release];
|
||||
sUpdateFolder = [inUpdateFolder retain];
|
||||
|
||||
while ((currentFile = [dirEnum nextObject]))
|
||||
{
|
||||
NSString *currentPath = [updateFolder stringByAppendingPathComponent:currentFile];
|
||||
NSString *currentPath = [inUpdateFolder stringByAppendingPathComponent:currentFile];
|
||||
if ([[currentFile lastPathComponent] isEqualToString:bundleFileName] ||
|
||||
[[currentFile lastPathComponent] isEqualToString:alternateBundleFileName]) // We found one!
|
||||
{
|
||||
@@ -32,55 +66,117 @@ NSString *SUInstallerDelegateKey = @"SUInstallerDelegate";
|
||||
newAppDownloadPath = currentPath;
|
||||
break;
|
||||
}
|
||||
else if (([[currentFile pathExtension] isEqualToString:@"pkg"] || [[currentFile pathExtension] isEqualToString:@"mpkg"]) &&
|
||||
[[[currentFile lastPathComponent] stringByDeletingPathExtension] isEqualToString:[bundleFileName stringByDeletingPathExtension]])
|
||||
else if ([[currentFile pathExtension] isEqualToString:@"pkg"] ||
|
||||
[[currentFile pathExtension] isEqualToString:@"mpkg"])
|
||||
{
|
||||
isPackage = YES;
|
||||
newAppDownloadPath = currentPath;
|
||||
break;
|
||||
if ([[[currentFile lastPathComponent] stringByDeletingPathExtension] isEqualToString:[bundleFileName stringByDeletingPathExtension]])
|
||||
{
|
||||
isPackage = YES;
|
||||
newAppDownloadPath = currentPath;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Remember any other non-matching packages we have seen should we need to use one of them as a fallback.
|
||||
fallbackPackagePath = currentPath;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Try matching on bundle identifiers in case the user has changed the name of the host app
|
||||
NSBundle *incomingBundle = [NSBundle bundleWithPath:currentPath];
|
||||
if(incomingBundle && [[incomingBundle bundleIdentifier] isEqualToString:[[host bundle] bundleIdentifier]])
|
||||
{
|
||||
isPackage = NO;
|
||||
newAppDownloadPath = currentPath;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Some DMGs have symlinks into /Applications! That's no good! And there's no point in looking in bundles.
|
||||
if ([[NSFileManager defaultManager] isAliasFolderAtPath:currentPath] ||
|
||||
[[currentFile pathExtension] isEqualToString:[[hostBundle bundlePath] pathExtension]] ||
|
||||
[[currentFile pathExtension] isEqualToString:@"pkg"] ||
|
||||
[[currentFile pathExtension] isEqualToString:@"mpkg"])
|
||||
{
|
||||
// Some DMGs have symlinks into /Applications! That's no good!
|
||||
if ([self isAliasFolderAtPath:currentPath])
|
||||
[dirEnum skipDescendents];
|
||||
}
|
||||
}
|
||||
|
||||
// We don't have a valid path. Try to use the fallback package.
|
||||
|
||||
if (newAppDownloadPath == nil && fallbackPackagePath != nil)
|
||||
{
|
||||
isPackage = YES;
|
||||
newAppDownloadPath = fallbackPackagePath;
|
||||
}
|
||||
|
||||
if (isPackagePtr) *isPackagePtr = isPackage;
|
||||
return newAppDownloadPath;
|
||||
}
|
||||
|
||||
+ (NSString *)appPathInUpdateFolder:(NSString *)updateFolder forHost:(SUHost *)host
|
||||
{
|
||||
BOOL isPackage = NO;
|
||||
NSString *path = [self installSourcePathInUpdateFolder:updateFolder forHost:host isPackage:&isPackage];
|
||||
return isPackage ? nil : path;
|
||||
}
|
||||
|
||||
+ (void)installFromUpdateFolder:(NSString *)inUpdateFolder overHost:(SUHost *)host installationPath:(NSString *)installationPath delegate:delegate synchronously:(BOOL)synchronously versionComparator:(id <SUVersionComparison>)comparator
|
||||
{
|
||||
BOOL isPackage = NO;
|
||||
NSString *newAppDownloadPath = [self installSourcePathInUpdateFolder:inUpdateFolder forHost:host isPackage:&isPackage];
|
||||
|
||||
if (newAppDownloadPath == nil)
|
||||
{
|
||||
[self _finishInstallationWithResult:NO hostBundle:hostBundle error:[NSError errorWithDomain:SUSparkleErrorDomain code:SUMissingUpdateError userInfo:[NSDictionary dictionaryWithObject:@"Couldn't find an appropriate update in the downloaded package." forKey:NSLocalizedDescriptionKey]] delegate:delegate];
|
||||
[self finishInstallationToPath:installationPath withResult:NO host:host error:[NSError errorWithDomain:SUSparkleErrorDomain code:SUMissingUpdateError userInfo:[NSDictionary dictionaryWithObject:@"Couldn't find an appropriate update in the downloaded package." forKey:NSLocalizedDescriptionKey]] delegate:delegate];
|
||||
}
|
||||
else
|
||||
{
|
||||
[(isPackage ? [SUPackageInstaller class] : [SUPlainInstaller class]) performInstallationWithPath:newAppDownloadPath hostBundle:hostBundle delegate:delegate synchronously:synchronously];
|
||||
[(isPackage ? [SUPackageInstaller class] : [SUPlainInstaller class]) performInstallationToPath:installationPath fromPath:newAppDownloadPath host:host delegate:delegate synchronously:synchronously versionComparator:comparator];
|
||||
}
|
||||
}
|
||||
|
||||
+ (void)_mdimportBundle:(NSBundle *)bundle
|
||||
+ (void)mdimportInstallationPath:(NSString *)installationPath
|
||||
{
|
||||
// *** GETS CALLED ON NON-MAIN THREAD!
|
||||
|
||||
SULog( @"mdimporting" );
|
||||
|
||||
NSTask *mdimport = [[[NSTask alloc] init] autorelease];
|
||||
[mdimport setLaunchPath:@"/usr/bin/mdimport"];
|
||||
[mdimport setArguments:[NSArray arrayWithObject:[bundle bundlePath]]];
|
||||
[mdimport launch];
|
||||
[mdimport setArguments:[NSArray arrayWithObject:installationPath]];
|
||||
@try
|
||||
{
|
||||
[mdimport launch];
|
||||
[mdimport waitUntilExit];
|
||||
}
|
||||
@catch (NSException * launchException)
|
||||
{
|
||||
// No big deal.
|
||||
SULog(@"Sparkle Error: %@", [launchException description]);
|
||||
}
|
||||
}
|
||||
|
||||
+ (void)_finishInstallationWithResult:(BOOL)result hostBundle:(NSBundle *)hostBundle error:(NSError *)error delegate:delegate
|
||||
|
||||
#define SUNotifyDictHostKey @"SUNotifyDictHost"
|
||||
#define SUNotifyDictErrorKey @"SUNotifyDictError"
|
||||
#define SUNotifyDictDelegateKey @"SUNotifyDictDelegate"
|
||||
|
||||
+ (void)finishInstallationToPath:(NSString *)installationPath withResult:(BOOL)result host:(SUHost *)host error:(NSError *)error delegate:delegate
|
||||
{
|
||||
if (result == YES)
|
||||
if (result)
|
||||
{
|
||||
[self _mdimportBundle:hostBundle];
|
||||
if ([delegate respondsToSelector:@selector(installerFinishedForHostBundle:)])
|
||||
[delegate installerFinishedForHostBundle:hostBundle];
|
||||
[self mdimportInstallationPath:installationPath];
|
||||
if ([delegate respondsToSelector:@selector(installerFinishedForHost:)])
|
||||
[delegate performSelectorOnMainThread: @selector(installerFinishedForHost:) withObject: host waitUntilDone: NO];
|
||||
}
|
||||
else
|
||||
{
|
||||
if ([delegate respondsToSelector:@selector(installerForHostBundle:failedWithError:)])
|
||||
[delegate installerForHostBundle:hostBundle failedWithError:error];
|
||||
if ([delegate respondsToSelector:@selector(installerForHost:failedWithError:)])
|
||||
[self performSelectorOnMainThread: @selector(notifyDelegateOfFailure:) withObject: [NSDictionary dictionaryWithObjectsAndKeys: host, SUNotifyDictHostKey, error, SUNotifyDictErrorKey, delegate, SUNotifyDictDelegateKey, nil] waitUntilDone: NO];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+(void) notifyDelegateOfFailure: (NSDictionary*)dict
|
||||
{
|
||||
[[dict objectForKey: SUNotifyDictDelegateKey] installerForHost: [dict objectForKey: SUNotifyDictHostKey] failedWithError: [dict objectForKey: SUNotifyDictErrorKey]];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* SULog.h
|
||||
* EyeTV
|
||||
*
|
||||
* Created by Uli Kusterer on 12/03/2009.
|
||||
* Copyright 2008 Elgato Systems GmbH. All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
Log output for troubleshooting Sparkle failures on end-user machines.
|
||||
Your tech support will hug you if you tell them about this.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Headers:
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#include <Foundation/Foundation.h>
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Prototypes:
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void SUClearLog( void );
|
||||
void SULog( NSString* format, ... );
|
||||
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* SULog.m
|
||||
* EyeTV
|
||||
*
|
||||
* Created by Uli Kusterer on 12/03/2009.
|
||||
* Copyright 2009 Elgato Systems GmbH. All rights reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Headers:
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#include "SULog.h"
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Constants:
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#define LOG_FILE_PATH @"~/Library/Logs/SparkleUpdateLog.log"
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// SUClearLog:
|
||||
// Erase the log at the start of an update. We don't want to litter the
|
||||
// user's hard disk with logging data that's mostly unused, so each app
|
||||
// should clear the log before it starts updating, so only the most recent
|
||||
// update is kept around.
|
||||
//
|
||||
// TAKES:
|
||||
// sender - Object that sent this message, typically of type X.
|
||||
//
|
||||
// GIVES:
|
||||
// param - who owns the returned value?
|
||||
// result - same here.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void SUClearLog( void )
|
||||
{
|
||||
FILE* logfile = fopen([[LOG_FILE_PATH stringByExpandingTildeInPath] fileSystemRepresentation],"w");
|
||||
if( logfile )
|
||||
fclose(logfile);
|
||||
else
|
||||
NSLog(@"----- Sparkle Log -----");
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// SULog:
|
||||
// Like NSLog, but logs to one specific log file. Each line is prefixed
|
||||
// with the current date and time, to help in regressing issues.
|
||||
//
|
||||
// TAKES:
|
||||
// format - NSLog/printf-style format string.
|
||||
// ... - More parameters depending on format string's contents.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void SULog( NSString* format, ... )
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
NSString* theStr = [[[NSString alloc] initWithFormat: format arguments: ap] autorelease];
|
||||
FILE* logfile = fopen([[LOG_FILE_PATH stringByExpandingTildeInPath] fileSystemRepresentation],"a");
|
||||
if( !logfile )
|
||||
NSLog( @"%@",theStr );
|
||||
else
|
||||
{
|
||||
theStr = [NSString stringWithFormat: @"%@: %@", [NSDate date], theStr];
|
||||
NSData* theData = [theStr dataUsingEncoding: NSUTF8StringEncoding];
|
||||
char newlineChar = '\n';
|
||||
fwrite( [theData bytes], 1, [theData length], logfile );
|
||||
fwrite( &newlineChar, 1, 1, logfile ); // Append a newline.
|
||||
fclose( logfile );
|
||||
logfile = NULL;
|
||||
}
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
|
||||
+25
-17
@@ -4,6 +4,20 @@
|
||||
<dict>
|
||||
<key>ADP2,1</key>
|
||||
<string>Developer Transition Kit</string>
|
||||
<key>iMac1,1</key>
|
||||
<string>iMac G3 (Rev A-D)</string>
|
||||
<key>iMac4,1</key>
|
||||
<string>iMac (Core Duo)</string>
|
||||
<key>iMac4,2</key>
|
||||
<string>iMac for Education (17-inch, Core Duo)</string>
|
||||
<key>iMac5,1</key>
|
||||
<string>iMac (Core 2 Duo, 17 or 20 inch, SuperDrive)</string>
|
||||
<key>iMac5,2</key>
|
||||
<string>iMac (Core 2 Duo, 17 inch, Combo Drive)</string>
|
||||
<key>iMac6,1</key>
|
||||
<string>iMac (Core 2 Duo, 24 inch, SuperDrive)</string>
|
||||
<key>iMac8,1</key>
|
||||
<string>iMac (April 2008)</string>
|
||||
<key>MacBook1,1</key>
|
||||
<string>MacBook (Core Duo)</string>
|
||||
<key>MacBook2,1</key>
|
||||
@@ -12,6 +26,10 @@
|
||||
<string>MacBook (Core 2 Duo Feb 2008)</string>
|
||||
<key>MacBookAir1,1</key>
|
||||
<string>MacBook Air (January 2008)</string>
|
||||
<key>MacBookAir2,1</key>
|
||||
<string>MacBook Air (June 2009)</string>
|
||||
<key>MacBookAir3,1</key>
|
||||
<string>MacBook Air (October 2010)</string>
|
||||
<key>MacBookPro1,1</key>
|
||||
<string>MacBook Pro Core Duo (15-inch)</string>
|
||||
<key>MacBookPro1,2</key>
|
||||
@@ -26,14 +44,18 @@
|
||||
<string>MacBook Pro Core 2 Duo (17-inch HD, Core 2 Duo)</string>
|
||||
<key>MacBookPro4,1</key>
|
||||
<string>MacBook Pro (Core 2 Duo Feb 2008)</string>
|
||||
<key>Macmini1,1</key>
|
||||
<string>Mac Mini (Core Solo/Duo)</string>
|
||||
<key>MacPro1,1</key>
|
||||
<string>Mac Pro (four-core)</string>
|
||||
<key>MacPro2,1</key>
|
||||
<string>Mac Pro (eight-core)</string>
|
||||
<key>MacPro3,1</key>
|
||||
<string>Mac Pro (January 2008 4- or 8- core "Harpertown")</string>
|
||||
<key>Macmini1,1</key>
|
||||
<string>Mac Mini (Core Solo/Duo)</string>
|
||||
<string>Mac Pro (January 2008 4- or 8- core "Harpertown")</string>
|
||||
<key>MacPro4,1</key>
|
||||
<string>Mac Pro (March 2009)</string>
|
||||
<key>MacPro5,1</key>
|
||||
<string>Mac Pro (August 2010)</string>
|
||||
<key>PowerBook1,1</key>
|
||||
<string>PowerBook G3</string>
|
||||
<key>PowerBook2,1</key>
|
||||
@@ -156,19 +178,5 @@
|
||||
<string>Xserve (Intel Xeon)</string>
|
||||
<key>Xserve2,1</key>
|
||||
<string>Xserve (January 2008 quad-core)</string>
|
||||
<key>iMac1,1</key>
|
||||
<string>iMac G3 (Rev A-D)</string>
|
||||
<key>iMac4,1</key>
|
||||
<string>iMac (Core Duo)</string>
|
||||
<key>iMac4,2</key>
|
||||
<string>iMac for Education (17-inch, Core Duo)</string>
|
||||
<key>iMac5,1</key>
|
||||
<string>iMac (Core 2 Duo, 17 or 20 inch, SuperDrive)</string>
|
||||
<key>iMac5,2</key>
|
||||
<string>iMac (Core 2 Duo, 17 inch, Combo Drive)</string>
|
||||
<key>iMac6,1</key>
|
||||
<string>iMac (Core 2 Duo, 24 inch, SuperDrive)</string>
|
||||
<key>iMac8,1</key>
|
||||
<string>iMac (April 2008)</string>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -9,11 +9,14 @@
|
||||
#ifndef SUPACKAGEINSTALLER_H
|
||||
#define SUPACKAGEINSTALLER_H
|
||||
|
||||
#import "Sparkle.h"
|
||||
#import "SUUpdater.h"
|
||||
|
||||
#import "SUAppcast.h"
|
||||
#import "SUAppcastItem.h"
|
||||
#import "SUVersionComparisonProtocol.h"
|
||||
#import "SUPlainInstaller.h"
|
||||
|
||||
@interface SUPackageInstaller : SUPlainInstaller { }
|
||||
+ (void)installPath:(NSString *)path overHostBundle:(NSBundle *)bundle delegate:delegate;
|
||||
@interface SUPackageInstaller : SUPlainInstaller
|
||||
@end
|
||||
|
||||
#endif
|
||||
+52
-12
@@ -7,26 +7,66 @@
|
||||
//
|
||||
|
||||
#import "SUPackageInstaller.h"
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "SUConstants.h"
|
||||
|
||||
NSString *SUPackageInstallerCommandKey = @"SUPackageInstallerCommand";
|
||||
NSString *SUPackageInstallerArgumentsKey = @"SUPackageInstallerArguments";
|
||||
NSString *SUPackageInstallerHostKey = @"SUPackageInstallerHost";
|
||||
NSString *SUPackageInstallerDelegateKey = @"SUPackageInstallerDelegate";
|
||||
NSString *SUPackageInstallerInstallationPathKey = @"SUPackageInstallerInstallationPathKey";
|
||||
|
||||
@implementation SUPackageInstaller
|
||||
|
||||
+ (void)installPath:(NSString *)path overHostBundle:(NSBundle *)bundle delegate:delegate
|
||||
+ (void)finishInstallationWithInfo:(NSDictionary *)info
|
||||
{
|
||||
NSError *error = nil;
|
||||
BOOL result = YES;
|
||||
[self finishInstallationToPath:[info objectForKey:SUPackageInstallerInstallationPathKey] withResult:YES host:[info objectForKey:SUPackageInstallerHostKey] error:nil delegate:[info objectForKey:SUPackageInstallerDelegateKey]];
|
||||
}
|
||||
|
||||
+ (void)performInstallationWithInfo:(NSDictionary *)info
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
NSString *installerPath = [[NSWorkspace sharedWorkspace] absolutePathForAppBundleWithIdentifier:@"com.apple.installer"];
|
||||
installerPath = [installerPath stringByAppendingString:@"/Contents/MacOS/Installer"];
|
||||
if (![[NSFileManager defaultManager] fileExistsAtPath:installerPath])
|
||||
{
|
||||
error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUMissingInstallerToolError userInfo:[NSDictionary dictionaryWithObject:@"Couldn't find Apple's installer tool!" forKey:NSLocalizedDescriptionKey]];
|
||||
result = NO;
|
||||
}
|
||||
NSTask *installer = [NSTask launchedTaskWithLaunchPath:installerPath arguments:[NSArray arrayWithObjects:path, nil]];
|
||||
NSTask *installer = [NSTask launchedTaskWithLaunchPath:[info objectForKey:SUPackageInstallerCommandKey] arguments:[info objectForKey:SUPackageInstallerArgumentsKey]];
|
||||
[installer waitUntilExit];
|
||||
|
||||
// Known bug: if the installation fails or is canceled, Sparkle goes ahead and restarts, thinking everything is fine.
|
||||
[self _finishInstallationWithResult:result hostBundle:bundle error:error delegate:delegate];
|
||||
[self performSelectorOnMainThread:@selector(finishInstallationWithInfo:) withObject:info waitUntilDone:NO];
|
||||
|
||||
[pool drain];
|
||||
}
|
||||
|
||||
+ (void)performInstallationToPath:(NSString *)installationPath fromPath:(NSString *)path host:(SUHost *)host delegate:delegate synchronously:(BOOL)synchronously versionComparator:(id <SUVersionComparison>)comparator
|
||||
{
|
||||
NSString *command;
|
||||
NSArray *args;
|
||||
|
||||
if (floor(NSAppKitVersionNumber) == NSAppKitVersionNumber10_4) {
|
||||
// 10.4 uses Installer.app because the "open" command in 10.4 doesn't support -W and -n
|
||||
command = [[NSBundle bundleWithIdentifier:@"com.apple.installer"] executablePath];
|
||||
args = [NSArray arrayWithObjects:path, nil];
|
||||
} else {
|
||||
// 10.5 and later. Run installer using the "open" command to ensure it is launched in front of current application.
|
||||
// The -W and -n options were added to the 'open' command in 10.5
|
||||
// -W = wait until the app has quit.
|
||||
// -n = Open another instance if already open.
|
||||
// -b = app bundle identifier
|
||||
command = @"/usr/bin/open";
|
||||
args = [NSArray arrayWithObjects:@"-W", @"-n", @"-b", @"com.apple.installer", path, nil];
|
||||
}
|
||||
if (![[NSFileManager defaultManager] fileExistsAtPath:command])
|
||||
{
|
||||
NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUMissingInstallerToolError userInfo:[NSDictionary dictionaryWithObject:@"Couldn't find Apple's installer tool!" forKey:NSLocalizedDescriptionKey]];
|
||||
[self finishInstallationToPath:installationPath withResult:NO host:host error:error delegate:delegate];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:command, SUPackageInstallerCommandKey, args, SUPackageInstallerArgumentsKey, host, SUPackageInstallerHostKey, delegate, SUPackageInstallerDelegateKey, installationPath, SUPackageInstallerInstallationPathKey, nil];
|
||||
if (synchronously)
|
||||
[self performInstallationWithInfo:info];
|
||||
else
|
||||
[NSThread detachNewThreadSelector:@selector(performInstallationWithInfo:) toTarget:self withObject:info];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// SUPasswordPrompt.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by rudy on 8/18/09.
|
||||
// Copyright 2009 Ambrosia Software, Inc.. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "Sparkle/SUWindowController.h"
|
||||
|
||||
@interface SUPasswordPrompt : SUWindowController
|
||||
{
|
||||
IBOutlet NSImageView *mIconView;
|
||||
IBOutlet NSTextField *mTextDescription;
|
||||
IBOutlet NSSecureTextField *mPasswordField;
|
||||
NSString *mPassword;
|
||||
NSString *mName;
|
||||
NSImage *mIcon;
|
||||
}
|
||||
|
||||
- (id)initWithHost:(SUHost *)aHost;
|
||||
- (NSInteger)run;
|
||||
- (NSString *)password;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,86 @@
|
||||
//
|
||||
// SUPasswordPrompt.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by rudy on 8/18/09.
|
||||
// Copyright 2009 Ambrosia Software, Inc.. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUPasswordPrompt.h"
|
||||
|
||||
|
||||
@implementation SUPasswordPrompt
|
||||
|
||||
- (id)initWithHost:(SUHost *)aHost
|
||||
{
|
||||
self = [super initWithHost:aHost windowNibName:@"SUPasswordPrompt"];
|
||||
if (self)
|
||||
{
|
||||
[self setName:[aHost name]];
|
||||
[self setIcon:[aHost icon]];
|
||||
mPassword = nil;
|
||||
[self setShouldCascadeWindows:NO];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)awakeFromNib
|
||||
{
|
||||
[mIconView setImage:[self icon]];
|
||||
}
|
||||
|
||||
- (void)setName:(NSString*)name
|
||||
{
|
||||
[mName release];
|
||||
mName = [name retain];
|
||||
}
|
||||
|
||||
- (NSString*)name
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
- (void)setIcon:(NSImage*)icon
|
||||
{
|
||||
[mIcon release];
|
||||
mIcon = [icon retain];
|
||||
}
|
||||
|
||||
- (NSImage*)icon
|
||||
{
|
||||
return mIcon;
|
||||
}
|
||||
|
||||
- (NSString *)password
|
||||
{
|
||||
return mPassword;
|
||||
}
|
||||
|
||||
- (void)setPassword:(NSString*)password
|
||||
{
|
||||
[mPassword release];
|
||||
mPassword = [password retain];
|
||||
}
|
||||
|
||||
- (NSInteger)run
|
||||
{
|
||||
//modally run a password prompt
|
||||
NSInteger result = [NSApp runModalForWindow:[self window]];
|
||||
if(result)
|
||||
[self setPassword:[mPasswordField stringValue]];
|
||||
return result;
|
||||
}
|
||||
|
||||
- (IBAction)accept:(id)sender
|
||||
{
|
||||
[[self window] orderOut:self];
|
||||
[NSApp stopModalWithCode:1];
|
||||
}
|
||||
|
||||
- (IBAction)cancel:(id)sender
|
||||
{
|
||||
[[self window] orderOut:self];
|
||||
[NSApp stopModalWithCode:0];
|
||||
}
|
||||
|
||||
@end
|
||||
+1
-3
@@ -12,9 +12,7 @@
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "SUUnarchiver.h"
|
||||
|
||||
@interface SUPipedUnarchiver : SUUnarchiver {
|
||||
|
||||
}
|
||||
@interface SUPipedUnarchiver : SUUnarchiver
|
||||
|
||||
@end
|
||||
|
||||
|
||||
+61
-29
@@ -8,20 +8,24 @@
|
||||
|
||||
#import "SUPipedUnarchiver.h"
|
||||
#import "SUUnarchiver_Private.h"
|
||||
#import "SULog.h"
|
||||
|
||||
|
||||
@implementation SUPipedUnarchiver
|
||||
|
||||
+ (SEL)_selectorConformingToTypeOfURL:(NSURL *)URL
|
||||
+ (SEL)selectorConformingToTypeOfPath:(NSString *)path
|
||||
{
|
||||
static NSDictionary *typeSelectorDictionary;
|
||||
if (!typeSelectorDictionary)
|
||||
typeSelectorDictionary = [[NSDictionary dictionaryWithObjectsAndKeys:@"_extractZIP", @"public.zip-archive", @"_extractTGZ", @"org.gnu.gnu-zip-tar-archive", @"_extractTBZ", @"org.bzip.bzip2-tar-archive", @"_extractTAR", @"public.tar-archive", nil] retain];
|
||||
typeSelectorDictionary = [[NSDictionary dictionaryWithObjectsAndKeys:@"extractZIP", @".zip", @"extractTAR", @".tar",
|
||||
@"extractTGZ", @".tar.gz", @"extractTGZ", @".tgz",
|
||||
@"extractTBZ", @".tar.bz2", @"extractTBZ", @".tbz", nil] retain];
|
||||
|
||||
NSEnumerator *typeEnumerator = [typeSelectorDictionary keyEnumerator];
|
||||
id currentType;
|
||||
while ((currentType = [typeEnumerator nextObject]))
|
||||
NSString *lastPathComponent = [path lastPathComponent];
|
||||
for (id currentType in typeSelectorDictionary)
|
||||
{
|
||||
if ([URL conformsToType:currentType])
|
||||
if ([currentType length] > [lastPathComponent length]) continue;
|
||||
if ([[lastPathComponent substringFromIndex:[lastPathComponent length] - [currentType length]] isEqualToString:currentType])
|
||||
return NSSelectorFromString([typeSelectorDictionary objectForKey:currentType]);
|
||||
}
|
||||
return NULL;
|
||||
@@ -29,23 +33,28 @@
|
||||
|
||||
- (void)start
|
||||
{
|
||||
[NSThread detachNewThreadSelector:[[self class] _selectorConformingToTypeOfURL:archiveURL] toTarget:self withObject:nil];
|
||||
[NSThread detachNewThreadSelector:[[self class] selectorConformingToTypeOfPath:archivePath] toTarget:self withObject:nil];
|
||||
}
|
||||
|
||||
+ (BOOL)_canUnarchiveURL:(NSURL *)URL
|
||||
+ (BOOL)canUnarchivePath:(NSString *)path
|
||||
{
|
||||
return ([self _selectorConformingToTypeOfURL:URL] != nil);
|
||||
return ([self selectorConformingToTypeOfPath:path] != nil);
|
||||
}
|
||||
|
||||
// This method abstracts the types that use a command line tool piping data from stdin.
|
||||
- (void)_extractArchivePipingDataToCommand:(NSString *)command
|
||||
- (void)extractArchivePipingDataToCommand:(NSString *)command
|
||||
{
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
NSString *archivePath = [archiveURL path];
|
||||
FILE *fp = NULL, *cmdFP = NULL;
|
||||
// *** GETS CALLED ON NON-MAIN THREAD!!!
|
||||
|
||||
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
FILE *fp = NULL, *cmdFP = NULL;
|
||||
char *oldDestinationString = NULL;
|
||||
|
||||
SULog(@"Extracting %@ using '%@'",archivePath,command);
|
||||
|
||||
// Get the file size.
|
||||
NSNumber *fs = [[[NSFileManager defaultManager] fileAttributesAtPath:archivePath traverseLink:NO] objectForKey:NSFileSize];
|
||||
NSNumber *fs = [[[NSFileManager defaultManager] attributesOfItemAtPath:archivePath error:nil] objectForKey:NSFileSize];
|
||||
if (fs == nil) goto reportError;
|
||||
|
||||
// Thank you, Allan Odgaard!
|
||||
@@ -53,54 +62,77 @@
|
||||
fp = fopen([archivePath fileSystemRepresentation], "r");
|
||||
if (!fp) goto reportError;
|
||||
|
||||
oldDestinationString = getenv("DESTINATION");
|
||||
setenv("DESTINATION", [[archivePath stringByDeletingLastPathComponent] fileSystemRepresentation], 1);
|
||||
cmdFP = popen([command fileSystemRepresentation], "w");
|
||||
size_t written;
|
||||
if (!cmdFP) goto reportError;
|
||||
|
||||
char buf[32*1024];
|
||||
long len;
|
||||
size_t len;
|
||||
while((len = fread(buf, 1, 32*1024, fp)))
|
||||
{
|
||||
fwrite(buf, 1, len, cmdFP);
|
||||
[self performSelectorOnMainThread:@selector(_notifyDelegateOfExtractedLength:) withObject:[NSNumber numberWithLong:len] waitUntilDone:NO];
|
||||
written = fwrite(buf, 1, len, cmdFP);
|
||||
if( written < len )
|
||||
{
|
||||
pclose(cmdFP);
|
||||
goto reportError;
|
||||
}
|
||||
|
||||
[self performSelectorOnMainThread:@selector(notifyDelegateOfExtractedLength:) withObject:[NSNumber numberWithUnsignedLong:len] waitUntilDone:NO];
|
||||
}
|
||||
pclose(cmdFP);
|
||||
|
||||
[self performSelectorOnMainThread:@selector(_notifyDelegateOfSuccess) withObject:nil waitUntilDone:NO];
|
||||
if( ferror( fp ) )
|
||||
goto reportError;
|
||||
|
||||
[self performSelectorOnMainThread:@selector(notifyDelegateOfSuccess) withObject:nil waitUntilDone:NO];
|
||||
goto finally;
|
||||
|
||||
reportError:
|
||||
[self performSelectorOnMainThread:@selector(_notifyDelegateOfFailure) withObject:nil waitUntilDone:NO];
|
||||
[self performSelectorOnMainThread:@selector(notifyDelegateOfFailure) withObject:nil waitUntilDone:NO];
|
||||
|
||||
finally:
|
||||
if (fp)
|
||||
fclose(fp);
|
||||
[pool drain];
|
||||
if (oldDestinationString)
|
||||
setenv("DESTINATION", oldDestinationString, 1);
|
||||
else
|
||||
unsetenv("DESTINATION");
|
||||
[pool release];
|
||||
}
|
||||
|
||||
- (void)_extractTAR
|
||||
- (void)extractTAR
|
||||
{
|
||||
return [self _extractArchivePipingDataToCommand:@"tar -xC \"$DESTINATION\""];
|
||||
// *** GETS CALLED ON NON-MAIN THREAD!!!
|
||||
|
||||
return [self extractArchivePipingDataToCommand:@"tar -xC \"$DESTINATION\""];
|
||||
}
|
||||
|
||||
- (void)_extractTGZ
|
||||
- (void)extractTGZ
|
||||
{
|
||||
return [self _extractArchivePipingDataToCommand:@"tar -zxC \"$DESTINATION\""];
|
||||
// *** GETS CALLED ON NON-MAIN THREAD!!!
|
||||
|
||||
return [self extractArchivePipingDataToCommand:@"tar -zxC \"$DESTINATION\""];
|
||||
}
|
||||
|
||||
- (void)_extractTBZ
|
||||
- (void)extractTBZ
|
||||
{
|
||||
return [self _extractArchivePipingDataToCommand:@"tar -jxC \"$DESTINATION\""];
|
||||
// *** GETS CALLED ON NON-MAIN THREAD!!!
|
||||
|
||||
return [self extractArchivePipingDataToCommand:@"tar -jxC \"$DESTINATION\""];
|
||||
}
|
||||
|
||||
- (void)_extractZIP
|
||||
- (void)extractZIP
|
||||
{
|
||||
return [self _extractArchivePipingDataToCommand:@"ditto -x -k - \"$DESTINATION\""];
|
||||
// *** GETS CALLED ON NON-MAIN THREAD!!!
|
||||
|
||||
return [self extractArchivePipingDataToCommand:@"ditto -x -k - \"$DESTINATION\""];
|
||||
}
|
||||
|
||||
+ (void)load
|
||||
{
|
||||
[self _registerImplementation:self];
|
||||
[self registerImplementation:self];
|
||||
}
|
||||
|
||||
@end
|
||||
+11
-3
@@ -9,10 +9,18 @@
|
||||
#ifndef SUPLAININSTALLER_H
|
||||
#define SUPLAININSTALLER_H
|
||||
|
||||
#import "Sparkle.h"
|
||||
#import "SUUpdater.h"
|
||||
|
||||
@interface SUPlainInstaller : SUInstaller { }
|
||||
+ (void)performInstallationWithPath:(NSString *)path hostBundle:(NSBundle *)hostBundle delegate:delegate synchronously:(BOOL)synchronously;
|
||||
#import "SUAppcast.h"
|
||||
#import "SUAppcastItem.h"
|
||||
#import "SUVersionComparisonProtocol.h"
|
||||
#import "SUInstaller.h"
|
||||
#import "SUVersionComparisonProtocol.h"
|
||||
|
||||
@class SUHost;
|
||||
|
||||
@interface SUPlainInstaller : SUInstaller
|
||||
+ (void)performInstallationToPath:(NSString *)installationPath fromPath:(NSString *)path host:(SUHost *)host delegate:delegate synchronously:(BOOL)synchronously versionComparator:(id <SUVersionComparison>)comparator;
|
||||
@end
|
||||
|
||||
#endif
|
||||
+54
-13
@@ -7,36 +7,77 @@
|
||||
//
|
||||
|
||||
#import "SUPlainInstaller.h"
|
||||
#import "SUPlainInstallerInternals.h"
|
||||
#import "SUConstants.h"
|
||||
#import "SUHost.h"
|
||||
|
||||
extern NSString *SUInstallerPathKey;
|
||||
extern NSString *SUInstallerHostBundleKey;
|
||||
extern NSString *SUInstallerDelegateKey;
|
||||
static NSString * const SUInstallerPathKey = @"SUInstallerPath";
|
||||
static NSString * const SUInstallerTargetPathKey = @"SUInstallerTargetPath";
|
||||
static NSString * const SUInstallerTempNameKey = @"SUInstallerTempName";
|
||||
static NSString * const SUInstallerHostKey = @"SUInstallerHost";
|
||||
static NSString * const SUInstallerDelegateKey = @"SUInstallerDelegate";
|
||||
static NSString * const SUInstallerResultKey = @"SUInstallerResult";
|
||||
static NSString * const SUInstallerErrorKey = @"SUInstallerError";
|
||||
static NSString * const SUInstallerInstallationPathKey = @"SUInstallerInstallationPath";
|
||||
|
||||
@implementation SUPlainInstaller
|
||||
|
||||
+ (void)installPath:(NSString *)path overHostBundle:(NSBundle *)bundle delegate:delegate
|
||||
+ (void)finishInstallationWithInfo:(NSDictionary *)info
|
||||
{
|
||||
NSError *error;
|
||||
BOOL result = [[NSFileManager defaultManager] copyPathWithAuthentication:path overPath:[bundle bundlePath] error:&error];
|
||||
[self _finishInstallationWithResult:result hostBundle:bundle error:error delegate:delegate];
|
||||
// *** GETS CALLED ON NON-MAIN THREAD!
|
||||
|
||||
[self finishInstallationToPath:[info objectForKey:SUInstallerInstallationPathKey] withResult:[[info objectForKey:SUInstallerResultKey] boolValue] host:[info objectForKey:SUInstallerHostKey] error:[info objectForKey:SUInstallerErrorKey] delegate:[info objectForKey:SUInstallerDelegateKey]];
|
||||
}
|
||||
|
||||
+ (void)_performInstallationWithInfo:(NSDictionary *)info
|
||||
+ (void)performInstallationWithInfo:(NSDictionary *)info
|
||||
{
|
||||
// *** GETS CALLED ON NON-MAIN THREAD!
|
||||
|
||||
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
[self installPath:[info objectForKey:SUInstallerPathKey] overHostBundle:[info objectForKey:SUInstallerHostBundleKey] delegate:[info objectForKey:SUInstallerDelegateKey]];
|
||||
NSError *error = nil;
|
||||
|
||||
NSString * oldPath = [[info objectForKey:SUInstallerHostKey] bundlePath];
|
||||
NSString * installationPath = [info objectForKey:SUInstallerInstallationPathKey];
|
||||
BOOL result = [self copyPathWithAuthentication:[info objectForKey:SUInstallerPathKey] overPath: installationPath temporaryName:[info objectForKey:SUInstallerTempNameKey] error:&error];
|
||||
|
||||
if( result )
|
||||
{
|
||||
BOOL haveOld = [[NSFileManager defaultManager] fileExistsAtPath: oldPath];
|
||||
BOOL differentFromNew = ![oldPath isEqualToString: installationPath];
|
||||
if( haveOld && differentFromNew )
|
||||
[self _movePathToTrash: oldPath]; // On success, trash old copy if there's still one due to renaming.
|
||||
}
|
||||
NSMutableDictionary *mutableInfo = [[info mutableCopy] autorelease];
|
||||
[mutableInfo setObject:[NSNumber numberWithBool:result] forKey:SUInstallerResultKey];
|
||||
[mutableInfo setObject:installationPath forKey:SUInstallerInstallationPathKey];
|
||||
if (!result && error)
|
||||
[mutableInfo setObject:error forKey:SUInstallerErrorKey];
|
||||
[self performSelectorOnMainThread:@selector(finishInstallationWithInfo:) withObject:mutableInfo waitUntilDone:NO];
|
||||
|
||||
[pool drain];
|
||||
}
|
||||
|
||||
+ (void)performInstallationWithPath:(NSString *)path hostBundle:(NSBundle *)hostBundle delegate:delegate synchronously:(BOOL)synchronously;
|
||||
+ (void)performInstallationToPath:(NSString *)installationPath fromPath:(NSString *)path host:(SUHost *)host delegate:delegate synchronously:(BOOL)synchronously versionComparator:(id <SUVersionComparison>)comparator
|
||||
{
|
||||
NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:path, SUInstallerPathKey, hostBundle, SUInstallerHostBundleKey, delegate, SUInstallerDelegateKey, nil];
|
||||
// Prevent malicious downgrades:
|
||||
#if !PERMIT_AUTOMATED_DOWNGRADES
|
||||
if ([comparator compareVersion:[host version] toVersion:[[NSBundle bundleWithPath:path] objectForInfoDictionaryKey:@"CFBundleVersion"]] == NSOrderedDescending)
|
||||
{
|
||||
NSString * errorMessage = [NSString stringWithFormat:@"Sparkle Updater: Possible attack in progress! Attempting to \"upgrade\" from %@ to %@. Aborting update.", [host version], [[NSBundle bundleWithPath:path] objectForInfoDictionaryKey:@"CFBundleVersion"]];
|
||||
NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUDowngradeError userInfo:[NSDictionary dictionaryWithObject:errorMessage forKey:NSLocalizedDescriptionKey]];
|
||||
[self finishInstallationToPath:installationPath withResult:NO host:host error:error delegate:delegate];
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
NSString *targetPath = [host installationPath];
|
||||
NSString *tempName = [self temporaryNameForPath:targetPath];
|
||||
NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:path, SUInstallerPathKey, targetPath, SUInstallerTargetPathKey, tempName, SUInstallerTempNameKey, host, SUInstallerHostKey, delegate, SUInstallerDelegateKey, installationPath, SUInstallerInstallationPathKey, nil];
|
||||
if (synchronously)
|
||||
[self _performInstallationWithInfo:info];
|
||||
[self performInstallationWithInfo:info];
|
||||
else
|
||||
[NSThread detachNewThreadSelector:@selector(_performInstallationWithInfo:) toTarget:self withObject:info];
|
||||
[NSThread detachNewThreadSelector:@selector(performInstallationWithInfo:) toTarget:self withObject:info];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,22 @@
|
||||
//
|
||||
// SUPlainInstallerInternals.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 3/9/06.
|
||||
// Copyright 2006 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef SUPLAININSTALLERINTERNALS_H
|
||||
#define SUPLAININSTALLERINTERNALS_H
|
||||
|
||||
#import "SUPlainInstaller.h"
|
||||
|
||||
@interface SUPlainInstaller (Internals)
|
||||
+ (NSString *)temporaryNameForPath:(NSString *)path;
|
||||
+ (BOOL)copyPathWithAuthentication:(NSString *)src overPath:(NSString *)dst temporaryName:(NSString *)tmp error:(NSError **)error;
|
||||
+ (void)_movePathToTrash:(NSString *)path;
|
||||
+ (BOOL)_removeFileAtPath:(NSString *)path error: (NSError**)error;
|
||||
+ (BOOL)_removeFileAtPathWithForcedAuthentication:(NSString *)src error:(NSError **)error;
|
||||
@end
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,591 @@
|
||||
//
|
||||
// SUPlainInstallerInternals.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Andy Matuschak on 3/9/06.
|
||||
// Copyright 2006 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SUUpdater.h"
|
||||
|
||||
#import "SUAppcast.h"
|
||||
#import "SUAppcastItem.h"
|
||||
#import "SUVersionComparisonProtocol.h"
|
||||
#import "SUPlainInstallerInternals.h"
|
||||
#import "SUConstants.h"
|
||||
#import "SULog.h"
|
||||
|
||||
#import <CoreServices/CoreServices.h>
|
||||
#import <Security/Security.h>
|
||||
#import <sys/stat.h>
|
||||
#import <sys/wait.h>
|
||||
#import <dirent.h>
|
||||
#import <unistd.h>
|
||||
#import <sys/param.h>
|
||||
|
||||
|
||||
@interface SUPlainInstaller (MMExtendedAttributes)
|
||||
// Removes the directory tree rooted at |root| from the file quarantine.
|
||||
// The quarantine was introduced on Mac OS X 10.5 and is described at:
|
||||
//
|
||||
// http://developer.apple.com/releasenotes/Carbon/RN-LaunchServices/index.html
|
||||
//#apple_ref/doc/uid/TP40001369-DontLinkElementID_2
|
||||
//
|
||||
// If |root| is not a directory, then it alone is removed from the quarantine.
|
||||
// Symbolic links, including |root| if it is a symbolic link, will not be
|
||||
// traversed.
|
||||
//
|
||||
// Ordinarily, the quarantine is managed by calling LSSetItemAttribute
|
||||
// to set the kLSItemQuarantineProperties attribute to a dictionary specifying
|
||||
// the quarantine properties to be applied. However, it does not appear to be
|
||||
// possible to remove an item from the quarantine directly through any public
|
||||
// Launch Services calls. Instead, this method takes advantage of the fact
|
||||
// that the quarantine is implemented in part by setting an extended attribute,
|
||||
// "com.apple.quarantine", on affected files. Removing this attribute is
|
||||
// sufficient to remove files from the quarantine.
|
||||
+ (void)releaseFromQuarantine:(NSString*)root;
|
||||
@end
|
||||
|
||||
// Authorization code based on generous contribution from Allan Odgaard. Thanks, Allan!
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations" // this is terrible; will fix later probably
|
||||
static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authorization, const char* executablePath, AuthorizationFlags options, const char* const* arguments)
|
||||
{
|
||||
// *** MUST BE SAFE TO CALL ON NON-MAIN THREAD!
|
||||
|
||||
sig_t oldSigChildHandler = signal(SIGCHLD, SIG_DFL);
|
||||
BOOL returnValue = YES;
|
||||
|
||||
if (AuthorizationExecuteWithPrivileges(authorization, executablePath, options, (char* const*)arguments, NULL) == errAuthorizationSuccess)
|
||||
{
|
||||
int status;
|
||||
pid_t pid = wait(&status);
|
||||
if (pid == -1 || !WIFEXITED(status) || WEXITSTATUS(status) != 0)
|
||||
returnValue = NO;
|
||||
}
|
||||
else
|
||||
returnValue = NO;
|
||||
|
||||
signal(SIGCHLD, oldSigChildHandler);
|
||||
return returnValue;
|
||||
}
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
@implementation SUPlainInstaller (Internals)
|
||||
|
||||
+ (NSString *)temporaryNameForPath:(NSString *)path
|
||||
{
|
||||
// Let's try to read the version number so the filename will be more meaningful.
|
||||
NSString *postFix;
|
||||
NSString *version;
|
||||
if ((version = [[NSBundle bundleWithPath:path] objectForInfoDictionaryKey:@"CFBundleVersion"]) && ![version isEqualToString:@""])
|
||||
{
|
||||
// We'll clean it up a little for safety.
|
||||
// The cast is necessary because of a bug in the headers in pre-10.5 SDKs
|
||||
NSMutableCharacterSet *validCharacters = (id)[NSMutableCharacterSet alphanumericCharacterSet];
|
||||
[validCharacters formUnionWithCharacterSet:[NSCharacterSet characterSetWithCharactersInString:@".-()"]];
|
||||
postFix = [version stringByTrimmingCharactersInSet:[validCharacters invertedSet]];
|
||||
}
|
||||
else
|
||||
postFix = @"old";
|
||||
NSString *prefix = [[path stringByDeletingPathExtension] stringByAppendingFormat:@" (%@)", postFix];
|
||||
NSString *tempDir = [prefix stringByAppendingPathExtension:[path pathExtension]];
|
||||
// Now let's make sure we get a unique path.
|
||||
unsigned int cnt=2;
|
||||
while ([[NSFileManager defaultManager] fileExistsAtPath:tempDir] && cnt <= 999)
|
||||
tempDir = [NSString stringWithFormat:@"%@ %u.%@", prefix, cnt++, [path pathExtension]];
|
||||
return [tempDir lastPathComponent];
|
||||
}
|
||||
|
||||
+ (NSString *)_temporaryCopyNameForPath:(NSString *)path didFindTrash: (BOOL*)outDidFindTrash
|
||||
{
|
||||
// *** MUST BE SAFE TO CALL ON NON-MAIN THREAD!
|
||||
NSString *tempDir = nil;
|
||||
|
||||
UInt8 trashPath[MAXPATHLEN +1] = { 0 };
|
||||
FSRef trashRef, pathRef;
|
||||
FSVolumeRefNum vSrcRefNum = kFSInvalidVolumeRefNum;
|
||||
FSCatalogInfo catInfo;
|
||||
memset( &catInfo, 0, sizeof(catInfo) );
|
||||
OSStatus err = FSPathMakeRef( (UInt8*) [path fileSystemRepresentation], &pathRef, NULL );
|
||||
if( err == noErr )
|
||||
{
|
||||
err = FSGetCatalogInfo( &pathRef, kFSCatInfoVolume, &catInfo, NULL, NULL, NULL );
|
||||
vSrcRefNum = catInfo.volume;
|
||||
}
|
||||
if( err == noErr )
|
||||
err = FSFindFolder( vSrcRefNum, kTrashFolderType, kCreateFolder, &trashRef );
|
||||
if( err == noErr )
|
||||
err = FSGetCatalogInfo( &trashRef, kFSCatInfoVolume, &catInfo, NULL, NULL, NULL );
|
||||
if( err == noErr && vSrcRefNum != catInfo.volume )
|
||||
err = nsvErr; // Couldn't find a trash folder on same volume as given path. Docs say this may happen in the future.
|
||||
if( err == noErr )
|
||||
err = FSRefMakePath( &trashRef, trashPath, MAXPATHLEN );
|
||||
if( err == noErr )
|
||||
tempDir = [[NSFileManager defaultManager] stringWithFileSystemRepresentation: (char*) trashPath length: strlen((char*) trashPath)];
|
||||
if( outDidFindTrash )
|
||||
*outDidFindTrash = (tempDir != nil);
|
||||
if( !tempDir )
|
||||
tempDir = [path stringByDeletingLastPathComponent];
|
||||
|
||||
// Let's try to read the version number so the filename will be more meaningful.
|
||||
#if TRY_TO_APPEND_VERSION_NUMBER
|
||||
NSString *postFix = nil;
|
||||
NSString *version = nil;
|
||||
if ((version = [[NSBundle bundleWithPath: path] objectForInfoDictionaryKey:@"CFBundleVersion"]) && ![version isEqualToString:@""])
|
||||
{
|
||||
// We'll clean it up a little for safety.
|
||||
// The cast is necessary because of a bug in the headers in pre-10.5 SDKs
|
||||
NSMutableCharacterSet *validCharacters = (id)[NSMutableCharacterSet alphanumericCharacterSet];
|
||||
[validCharacters formUnionWithCharacterSet:[NSCharacterSet characterSetWithCharactersInString:@".-()"]];
|
||||
postFix = [version stringByTrimmingCharactersInSet:[validCharacters invertedSet]];
|
||||
}
|
||||
else
|
||||
postFix = @"old";
|
||||
NSString *prefix = [NSString stringWithFormat: @"%@ (%@)", [[path lastPathComponent] stringByDeletingPathExtension], postFix];
|
||||
#else
|
||||
NSString *prefix = [[path lastPathComponent] stringByDeletingPathExtension];
|
||||
#endif
|
||||
NSString *tempName = [prefix stringByAppendingPathExtension: [path pathExtension]];
|
||||
tempDir = [tempDir stringByAppendingPathComponent: tempName];
|
||||
|
||||
// Now let's make sure we get a unique path.
|
||||
int cnt=2;
|
||||
while ([[NSFileManager defaultManager] fileExistsAtPath:tempDir] && cnt <= 9999)
|
||||
tempDir = [[tempDir stringByDeletingLastPathComponent] stringByAppendingPathComponent: [NSString stringWithFormat:@"%@ %d.%@", prefix, cnt++, [path pathExtension]]];
|
||||
|
||||
return tempDir;
|
||||
}
|
||||
|
||||
+ (BOOL)_copyPathWithForcedAuthentication:(NSString *)src toPath:(NSString *)dst temporaryPath:(NSString *)tmp error:(NSError **)error
|
||||
{
|
||||
// *** MUST BE SAFE TO CALL ON NON-MAIN THREAD!
|
||||
|
||||
const char* srcPath = [src fileSystemRepresentation];
|
||||
const char* tmpPath = [tmp fileSystemRepresentation];
|
||||
const char* dstPath = [dst fileSystemRepresentation];
|
||||
|
||||
struct stat dstSB;
|
||||
if( stat(dstPath, &dstSB) != 0 ) // Doesn't exist yet, try containing folder.
|
||||
{
|
||||
const char* dstDirPath = [[dst stringByDeletingLastPathComponent] fileSystemRepresentation];
|
||||
if( stat(dstDirPath, &dstSB) != 0 )
|
||||
{
|
||||
NSString *errorMessage = [NSString stringWithFormat:@"Stat on %@ during authenticated file copy failed.", dst];
|
||||
if (error != NULL)
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUFileCopyFailure userInfo:[NSDictionary dictionaryWithObject:errorMessage forKey:NSLocalizedDescriptionKey]];
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
AuthorizationRef auth = NULL;
|
||||
OSStatus authStat = errAuthorizationDenied;
|
||||
while (authStat == errAuthorizationDenied) {
|
||||
authStat = AuthorizationCreate(NULL,
|
||||
kAuthorizationEmptyEnvironment,
|
||||
kAuthorizationFlagDefaults,
|
||||
&auth);
|
||||
}
|
||||
|
||||
BOOL res = NO;
|
||||
if (authStat == errAuthorizationSuccess) {
|
||||
res = YES;
|
||||
|
||||
char uidgid[42];
|
||||
snprintf(uidgid, sizeof(uidgid), "%u:%u",
|
||||
dstSB.st_uid, dstSB.st_gid);
|
||||
|
||||
// If the currently-running application is trusted, the new
|
||||
// version should be trusted as well. Remove it from the
|
||||
// quarantine to avoid a delay at launch, and to avoid
|
||||
// presenting the user with a confusing trust dialog.
|
||||
//
|
||||
// This needs to be done after the application is moved to its
|
||||
// new home with "mv" in case it's moved across filesystems: if
|
||||
// that happens, "mv" actually performs a copy and may result
|
||||
// in the application being quarantined. It also needs to be
|
||||
// done before "chown" changes ownership, because the ownership
|
||||
// change will almost certainly make it impossible to change
|
||||
// attributes to release the files from the quarantine.
|
||||
if (res)
|
||||
{
|
||||
SULog(@"releaseFromQuarantine");
|
||||
[self performSelectorOnMainThread:@selector(releaseFromQuarantine:) withObject:src waitUntilDone:YES];
|
||||
}
|
||||
|
||||
if( res ) // Set permissions while it's still in source, so we have it with working and correct perms when it arrives at destination.
|
||||
{
|
||||
const char* coParams[] = { "-R", uidgid, srcPath, NULL };
|
||||
res = AuthorizationExecuteWithPrivilegesAndWait( auth, "/usr/sbin/chown", kAuthorizationFlagDefaults, coParams );
|
||||
if( !res )
|
||||
SULog( @"chown -R %s %s failed.", uidgid, srcPath );
|
||||
}
|
||||
|
||||
BOOL haveDst = [[NSFileManager defaultManager] fileExistsAtPath: dst];
|
||||
if( res && haveDst ) // If there's something at our tmp path (previous failed update or whatever) delete that first.
|
||||
{
|
||||
const char* rmParams[] = { "-rf", tmpPath, NULL };
|
||||
res = AuthorizationExecuteWithPrivilegesAndWait( auth, "/bin/rm", kAuthorizationFlagDefaults, rmParams );
|
||||
if( !res )
|
||||
SULog( @"rm failed" );
|
||||
}
|
||||
|
||||
if( res && haveDst ) // Move old exe to tmp path.
|
||||
{
|
||||
const char* mvParams[] = { "-f", dstPath, tmpPath, NULL };
|
||||
res = AuthorizationExecuteWithPrivilegesAndWait( auth, "/bin/mv", kAuthorizationFlagDefaults, mvParams );
|
||||
if( !res )
|
||||
SULog( @"mv 1 failed" );
|
||||
}
|
||||
|
||||
if( res ) // Move new exe to old exe's path.
|
||||
{
|
||||
const char* mvParams2[] = { "-f", srcPath, dstPath, NULL };
|
||||
res = AuthorizationExecuteWithPrivilegesAndWait( auth, "/bin/mv", kAuthorizationFlagDefaults, mvParams2 );
|
||||
if( !res )
|
||||
SULog( @"mv 2 failed" );
|
||||
}
|
||||
|
||||
// if( res && haveDst /*&& !foundTrash*/ ) // If we managed to put the old exe in the trash, leave it there for the user to delete or recover.
|
||||
// { // ... Otherwise we better delete it, wouldn't want dozens of old versions lying around next to the new one.
|
||||
// const char* rmParams2[] = { "-rf", tmpPath, NULL };
|
||||
// res = AuthorizationExecuteWithPrivilegesAndWait( auth, "/bin/rm", kAuthorizationFlagDefaults, rmParams2 );
|
||||
// }
|
||||
|
||||
AuthorizationFree(auth, 0);
|
||||
|
||||
// If the currently-running application is trusted, the new
|
||||
// version should be trusted as well. Remove it from the
|
||||
// quarantine to avoid a delay at launch, and to avoid
|
||||
// presenting the user with a confusing trust dialog.
|
||||
//
|
||||
// This needs to be done after the application is moved to its
|
||||
// new home with "mv" in case it's moved across filesystems: if
|
||||
// that happens, "mv" actually performs a copy and may result
|
||||
// in the application being quarantined.
|
||||
if (res)
|
||||
{
|
||||
SULog(@"releaseFromQuarantine after installing");
|
||||
[self performSelectorOnMainThread:@selector(releaseFromQuarantine:) withObject:dst waitUntilDone:YES];
|
||||
}
|
||||
|
||||
if (!res)
|
||||
{
|
||||
// Something went wrong somewhere along the way, but we're not sure exactly where.
|
||||
NSString *errorMessage = [NSString stringWithFormat:@"Authenticated file copy from %@ to %@ failed.", src, dst];
|
||||
if (error != nil)
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:[NSDictionary dictionaryWithObject:errorMessage forKey:NSLocalizedDescriptionKey]];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (error != nil)
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:[NSDictionary dictionaryWithObject:@"Couldn't get permission to authenticate." forKey:NSLocalizedDescriptionKey]];
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
+ (BOOL)_movePathWithForcedAuthentication:(NSString *)src toPath:(NSString *)dst error:(NSError **)error
|
||||
{
|
||||
// *** MUST BE SAFE TO CALL ON NON-MAIN THREAD!
|
||||
|
||||
const char* srcPath = [src fileSystemRepresentation];
|
||||
const char* dstPath = [dst fileSystemRepresentation];
|
||||
const char* dstContainerPath = [[dst stringByDeletingLastPathComponent] fileSystemRepresentation];
|
||||
|
||||
struct stat dstSB;
|
||||
stat(dstContainerPath, &dstSB);
|
||||
|
||||
AuthorizationRef auth = NULL;
|
||||
OSStatus authStat = errAuthorizationDenied;
|
||||
while( authStat == errAuthorizationDenied )
|
||||
{
|
||||
authStat = AuthorizationCreate(NULL,
|
||||
kAuthorizationEmptyEnvironment,
|
||||
kAuthorizationFlagDefaults,
|
||||
&auth);
|
||||
}
|
||||
|
||||
BOOL res = NO;
|
||||
if (authStat == errAuthorizationSuccess)
|
||||
{
|
||||
res = YES;
|
||||
|
||||
char uidgid[42];
|
||||
snprintf(uidgid, sizeof(uidgid), "%d:%d",
|
||||
dstSB.st_uid, dstSB.st_gid);
|
||||
|
||||
if( res ) // Set permissions while it's still in source, so we have it with working and correct perms when it arrives at destination.
|
||||
{
|
||||
const char* coParams[] = { "-R", uidgid, srcPath, NULL };
|
||||
res = AuthorizationExecuteWithPrivilegesAndWait( auth, "/usr/sbin/chown", kAuthorizationFlagDefaults, coParams );
|
||||
if( !res )
|
||||
SULog(@"Can't set permissions");
|
||||
}
|
||||
|
||||
BOOL haveDst = [[NSFileManager defaultManager] fileExistsAtPath: dst];
|
||||
if( res && haveDst ) // If there's something at our tmp path (previous failed update or whatever) delete that first.
|
||||
{
|
||||
const char* rmParams[] = { "-rf", dstPath, NULL };
|
||||
res = AuthorizationExecuteWithPrivilegesAndWait( auth, "/bin/rm", kAuthorizationFlagDefaults, rmParams );
|
||||
if( !res )
|
||||
SULog(@"Can't remove destination file");
|
||||
}
|
||||
|
||||
if( res ) // Move!.
|
||||
{
|
||||
const char* mvParams[] = { "-f", srcPath, dstPath, NULL };
|
||||
res = AuthorizationExecuteWithPrivilegesAndWait( auth, "/bin/mv", kAuthorizationFlagDefaults, mvParams );
|
||||
if( !res )
|
||||
SULog(@"Can't move source file");
|
||||
}
|
||||
|
||||
AuthorizationFree(auth, 0);
|
||||
|
||||
if (!res)
|
||||
{
|
||||
// Something went wrong somewhere along the way, but we're not sure exactly where.
|
||||
NSString *errorMessage = [NSString stringWithFormat:@"Authenticated file move from %@ to %@ failed.", src, dst];
|
||||
if (error != NULL)
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:[NSDictionary dictionaryWithObject:errorMessage forKey:NSLocalizedDescriptionKey]];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (error != NULL)
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:[NSDictionary dictionaryWithObject:@"Couldn't get permission to authenticate." forKey:NSLocalizedDescriptionKey]];
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
+ (BOOL)_removeFileAtPathWithForcedAuthentication:(NSString *)src error:(NSError **)error
|
||||
{
|
||||
// *** MUST BE SAFE TO CALL ON NON-MAIN THREAD!
|
||||
|
||||
const char* srcPath = [src fileSystemRepresentation];
|
||||
|
||||
AuthorizationRef auth = NULL;
|
||||
OSStatus authStat = errAuthorizationDenied;
|
||||
while( authStat == errAuthorizationDenied )
|
||||
{
|
||||
authStat = AuthorizationCreate(NULL,
|
||||
kAuthorizationEmptyEnvironment,
|
||||
kAuthorizationFlagDefaults,
|
||||
&auth);
|
||||
}
|
||||
|
||||
BOOL res = NO;
|
||||
if (authStat == errAuthorizationSuccess)
|
||||
{
|
||||
res = YES;
|
||||
|
||||
if( res ) // If there's something at our tmp path (previous failed update or whatever) delete that first.
|
||||
{
|
||||
const char* rmParams[] = { "-rf", srcPath, NULL };
|
||||
res = AuthorizationExecuteWithPrivilegesAndWait( auth, "/bin/rm", kAuthorizationFlagDefaults, rmParams );
|
||||
if( !res )
|
||||
SULog(@"Can't remove destination file");
|
||||
}
|
||||
|
||||
AuthorizationFree(auth, 0);
|
||||
|
||||
if (!res)
|
||||
{
|
||||
// Something went wrong somewhere along the way, but we're not sure exactly where.
|
||||
NSString *errorMessage = [NSString stringWithFormat:@"Authenticated file remove from %@ failed.", src];
|
||||
if (error != NULL)
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:[NSDictionary dictionaryWithObject:errorMessage forKey:NSLocalizedDescriptionKey]];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (error != NULL)
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:[NSDictionary dictionaryWithObject:@"Couldn't get permission to authenticate." forKey:NSLocalizedDescriptionKey]];
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
+ (BOOL)_removeFileAtPath:(NSString *)path error: (NSError**)error
|
||||
{
|
||||
BOOL success = YES;
|
||||
if( ![[NSFileManager defaultManager] removeItemAtPath: path error: NULL] )
|
||||
{
|
||||
success = [self _removeFileAtPathWithForcedAuthentication: path error: error];
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
+ (void)_movePathToTrash:(NSString *)path
|
||||
{
|
||||
//SULog(@"Moving %@ to the trash.", path);
|
||||
NSInteger tag = 0;
|
||||
if (![[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation source:[path stringByDeletingLastPathComponent] destination:@"" files:[NSArray arrayWithObject:[path lastPathComponent]] tag:&tag])
|
||||
{
|
||||
BOOL didFindTrash = NO;
|
||||
NSString* trashPath = [self _temporaryCopyNameForPath: path didFindTrash: &didFindTrash];
|
||||
if( didFindTrash )
|
||||
{
|
||||
NSError *err = nil;
|
||||
if( ![self _movePathWithForcedAuthentication: path toPath: trashPath error: &err] )
|
||||
SULog(@"Sparkle error: couldn't move %@ to the trash (%@). %@", path, trashPath, err);
|
||||
}
|
||||
else
|
||||
SULog(@"Sparkle error: couldn't move %@ to the trash. This is often a sign of a permissions error.", path);
|
||||
}
|
||||
else
|
||||
;//SULog(@"Moved %@ to the trash.", path);
|
||||
}
|
||||
|
||||
+ (BOOL)copyPathWithAuthentication:(NSString *)src overPath:(NSString *)dst temporaryName:(NSString *)tmp error:(NSError **)error
|
||||
{
|
||||
FSRef srcRef, dstRef, dstDirRef, tmpDirRef;
|
||||
OSStatus err;
|
||||
BOOL hadFileAtDest = NO, didFindTrash = NO;
|
||||
NSString *tmpPath = [self _temporaryCopyNameForPath: dst didFindTrash: &didFindTrash];
|
||||
|
||||
// Make FSRef for destination:
|
||||
err = FSPathMakeRefWithOptions((UInt8 *)[dst fileSystemRepresentation], kFSPathMakeRefDoNotFollowLeafSymlink, &dstRef, NULL);
|
||||
hadFileAtDest = (err == noErr); // There is a file at the destination, move it aside. If we normalized the name, we might not get here, so don't error.
|
||||
if( hadFileAtDest )
|
||||
{
|
||||
if (0 != access([dst fileSystemRepresentation], W_OK) || 0 != access([[dst stringByDeletingLastPathComponent] fileSystemRepresentation], W_OK))
|
||||
{
|
||||
return [self _copyPathWithForcedAuthentication:src toPath:dst temporaryPath:tmpPath error:error];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (0 != access([[dst stringByDeletingLastPathComponent] fileSystemRepresentation], W_OK)
|
||||
|| 0 != access([[[dst stringByDeletingLastPathComponent] stringByDeletingLastPathComponent] fileSystemRepresentation], W_OK))
|
||||
{
|
||||
return [self _copyPathWithForcedAuthentication:src toPath:dst temporaryPath:tmpPath error:error];
|
||||
}
|
||||
}
|
||||
|
||||
if( hadFileAtDest )
|
||||
{
|
||||
err = FSPathMakeRef((UInt8 *)[[tmpPath stringByDeletingLastPathComponent] fileSystemRepresentation], &tmpDirRef, NULL);
|
||||
if (err != noErr)
|
||||
FSPathMakeRef((UInt8 *)[[dst stringByDeletingLastPathComponent] fileSystemRepresentation], &tmpDirRef, NULL);
|
||||
}
|
||||
|
||||
err = FSPathMakeRef((UInt8 *)[[dst stringByDeletingLastPathComponent] fileSystemRepresentation], &dstDirRef, NULL);
|
||||
|
||||
if (err == noErr && hadFileAtDest)
|
||||
{
|
||||
NSFileManager *manager = [[[NSFileManager alloc] init] autorelease];
|
||||
BOOL success = [manager moveItemAtPath:dst toPath:tmpPath error:error];
|
||||
if (!success && hadFileAtDest)
|
||||
{
|
||||
if (error != NULL)
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUFileCopyFailure userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Couldn't move %@ to %@.", dst, tmpPath] forKey:NSLocalizedDescriptionKey]];
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
err = FSPathMakeRef((UInt8 *)[src fileSystemRepresentation], &srcRef, NULL);
|
||||
if (err == noErr)
|
||||
{
|
||||
NSFileManager *manager = [[[NSFileManager alloc] init] autorelease];
|
||||
BOOL success = [manager copyItemAtPath:src toPath:dst error:error];
|
||||
if (!success)
|
||||
{
|
||||
// We better move the old version back to its old location
|
||||
if( hadFileAtDest )
|
||||
success = [manager moveItemAtPath:tmpPath toPath:dst error:error];
|
||||
if (!success && error != NULL)
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUFileCopyFailure userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Couldn't move %@ to %@.", dst, tmpPath] forKey:NSLocalizedDescriptionKey]];
|
||||
return NO;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// If the currently-running application is trusted, the new
|
||||
// version should be trusted as well. Remove it from the
|
||||
// quarantine to avoid a delay at launch, and to avoid
|
||||
// presenting the user with a confusing trust dialog.
|
||||
//
|
||||
// This needs to be done after the application is moved to its
|
||||
// new home in case it's moved across filesystems: if that
|
||||
// happens, the move is actually a copy, and it may result
|
||||
// in the application being quarantined.
|
||||
[self performSelectorOnMainThread:@selector(releaseFromQuarantine:) withObject:dst waitUntilDone:YES];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#import <dlfcn.h>
|
||||
#import <errno.h>
|
||||
#import <sys/xattr.h>
|
||||
|
||||
@implementation SUPlainInstaller (MMExtendedAttributes)
|
||||
|
||||
+ (int)removeXAttr:(const char*)name
|
||||
fromFile:(NSString*)file
|
||||
options:(int)options
|
||||
{
|
||||
// *** MUST BE SAFE TO CALL ON NON-MAIN THREAD!
|
||||
|
||||
typedef int (*removexattr_type)(const char*, const char*, int);
|
||||
// Reference removexattr directly, it's in the SDK.
|
||||
static removexattr_type removexattr_func = removexattr;
|
||||
|
||||
// Make sure that the symbol is present. This checks the deployment
|
||||
// target instead of the SDK so that it's able to catch dlsym failures
|
||||
// as well as the null symbol that would result from building with the
|
||||
// 10.4 SDK and a lower deployment target, and running on 10.3.
|
||||
if (!removexattr_func) {
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char* path = NULL;
|
||||
@try {
|
||||
path = [file fileSystemRepresentation];
|
||||
}
|
||||
@catch (id exception) {
|
||||
// -[NSString fileSystemRepresentation] throws an exception if it's
|
||||
// unable to convert the string to something suitable. Map that to
|
||||
// EDOM, "argument out of domain", which sort of conveys that there
|
||||
// was a conversion failure.
|
||||
errno = EDOM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return removexattr_func(path, name, options);
|
||||
}
|
||||
|
||||
+ (void)releaseFromQuarantine:(NSString*)root
|
||||
{
|
||||
// *** MUST BE SAFE TO CALL ON NON-MAIN THREAD!
|
||||
|
||||
const char* quarantineAttribute = "com.apple.quarantine";
|
||||
const int removeXAttrOptions = XATTR_NOFOLLOW;
|
||||
|
||||
[self removeXAttr:quarantineAttribute
|
||||
fromFile:root
|
||||
options:removeXAttrOptions];
|
||||
|
||||
// Only recurse if it's actually a directory. Don't recurse into a
|
||||
// root-level symbolic link.
|
||||
NSDictionary* rootAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:root error:nil];
|
||||
NSString* rootType = [rootAttributes objectForKey:NSFileType];
|
||||
|
||||
if (rootType == NSFileTypeDirectory) {
|
||||
// The NSDirectoryEnumerator will avoid recursing into any contained
|
||||
// symbolic links, so no further type checks are needed.
|
||||
NSDirectoryEnumerator* directoryEnumerator = [[NSFileManager defaultManager] enumeratorAtPath:root];
|
||||
NSString* file = nil;
|
||||
while ((file = [directoryEnumerator nextObject])) {
|
||||
[self removeXAttr:quarantineAttribute
|
||||
fromFile:[root stringByAppendingPathComponent:file]
|
||||
options:removeXAttrOptions];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
+10
-2
@@ -7,19 +7,27 @@
|
||||
//
|
||||
|
||||
#import "SUProbingUpdateDriver.h"
|
||||
|
||||
#import "SUUpdater.h"
|
||||
|
||||
@implementation SUProbingUpdateDriver
|
||||
|
||||
// Stop as soon as we have an answer! The superclasses will already have taken care of notifying the delegate.
|
||||
// Stop as soon as we have an answer! Since the superclass implementations are not called, we are responsible for notifying the delegate.
|
||||
|
||||
- (void)didFindValidUpdate
|
||||
{
|
||||
if ([[updater delegate] respondsToSelector:@selector(updater:didFindValidUpdate:)])
|
||||
[[updater delegate] updater:updater didFindValidUpdate:updateItem];
|
||||
NSDictionary *userInfo = (updateItem != nil) ? @{SUUpdaterAppcastItemNotificationKey : updateItem} : nil;
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidFindValidUpdateNotification object:updater userInfo:userInfo];
|
||||
[self abortUpdate];
|
||||
}
|
||||
|
||||
- (void)didNotFindUpdate
|
||||
{
|
||||
if ([[updater delegate] respondsToSelector:@selector(updaterDidNotFindUpdate:)])
|
||||
[[updater delegate] updaterDidNotFindUpdate:updater];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidNotFindUpdateNotification object:updater];
|
||||
|
||||
[self abortUpdate];
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,9 @@
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "SUUIBasedUpdateDriver.h"
|
||||
|
||||
@interface SUScheduledUpdateDriver : SUUIBasedUpdateDriver {
|
||||
@interface SUScheduledUpdateDriver : SUUIBasedUpdateDriver
|
||||
{
|
||||
@private
|
||||
BOOL showErrors;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,11 @@
|
||||
//
|
||||
|
||||
#import "SUScheduledUpdateDriver.h"
|
||||
#import "Sparkle.h"
|
||||
#import "SUUpdater.h"
|
||||
|
||||
#import "SUAppcast.h"
|
||||
#import "SUAppcastItem.h"
|
||||
#import "SUVersionComparisonProtocol.h"
|
||||
|
||||
@implementation SUScheduledUpdateDriver
|
||||
|
||||
@@ -19,6 +23,10 @@
|
||||
|
||||
- (void)didNotFindUpdate
|
||||
{
|
||||
if ([[updater delegate] respondsToSelector:@selector(updaterDidNotFindUpdate:)])
|
||||
[[updater delegate] updaterDidNotFindUpdate:updater];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidNotFindUpdateNotification object:updater];
|
||||
|
||||
[self abortUpdate]; // Don't tell the user that no update was found; this was a scheduled update.
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,11 @@
|
||||
// Copyright 2007 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#import "Sparkle.h"
|
||||
#import "SUUpdater.h"
|
||||
|
||||
#import "SUAppcast.h"
|
||||
#import "SUAppcastItem.h"
|
||||
#import "SUVersionComparisonProtocol.h"
|
||||
#import "SUStandardVersionComparator.h"
|
||||
|
||||
@implementation SUStandardVersionComparator
|
||||
@@ -22,15 +26,19 @@
|
||||
typedef enum {
|
||||
kNumberType,
|
||||
kStringType,
|
||||
kPeriodType
|
||||
kSeparatorType,
|
||||
} SUCharacterType;
|
||||
|
||||
- (SUCharacterType)typeOfCharacter:(NSString *)character
|
||||
{
|
||||
if ([character isEqualToString:@"."]) {
|
||||
return kPeriodType;
|
||||
return kSeparatorType;
|
||||
} else if ([[NSCharacterSet decimalDigitCharacterSet] characterIsMember:[character characterAtIndex:0]]) {
|
||||
return kNumberType;
|
||||
} else if ([[NSCharacterSet whitespaceAndNewlineCharacterSet] characterIsMember:[character characterAtIndex:0]]) {
|
||||
return kSeparatorType;
|
||||
} else if ([[NSCharacterSet punctuationCharacterSet] characterIsMember:[character characterAtIndex:0]]) {
|
||||
return kSeparatorType;
|
||||
} else {
|
||||
return kStringType;
|
||||
}
|
||||
@@ -40,7 +48,8 @@ typedef enum {
|
||||
{
|
||||
NSString *character;
|
||||
NSMutableString *s;
|
||||
NSInteger i, n, oldType, newType;
|
||||
NSUInteger i, n;
|
||||
SUCharacterType oldType, newType;
|
||||
NSMutableArray *parts = [NSMutableArray array];
|
||||
if ([version length] == 0) {
|
||||
// Nothing to do here
|
||||
@@ -52,11 +61,10 @@ typedef enum {
|
||||
for (i = 1; i <= n; ++i) {
|
||||
character = [version substringWithRange:NSMakeRange(i, 1)];
|
||||
newType = [self typeOfCharacter:character];
|
||||
if (oldType != newType || oldType == kPeriodType) {
|
||||
if (oldType != newType || oldType == kSeparatorType) {
|
||||
// We've reached a new segment
|
||||
NSString *aPart = [[NSString alloc] initWithString:s];
|
||||
NSString *aPart = [[[NSString alloc] initWithString:s] autorelease];
|
||||
[parts addObject:aPart];
|
||||
[aPart release];
|
||||
[s setString:character];
|
||||
} else {
|
||||
// Add character to string and continue
|
||||
@@ -76,8 +84,10 @@ typedef enum {
|
||||
NSArray *partsB = [self splitVersionString:versionB];
|
||||
|
||||
NSString *partA, *partB;
|
||||
NSInteger i, n, typeA, typeB, intA, intB;
|
||||
|
||||
NSUInteger i, n;
|
||||
long long valueA, valueB;
|
||||
SUCharacterType typeA, typeB;
|
||||
|
||||
n = MIN([partsA count], [partsB count]);
|
||||
for (i = 0; i < n; ++i) {
|
||||
partA = [partsA objectAtIndex:i];
|
||||
@@ -90,11 +100,11 @@ typedef enum {
|
||||
if (typeA == typeB) {
|
||||
// Same type; we can compare
|
||||
if (typeA == kNumberType) {
|
||||
intA = [partA intValue];
|
||||
intB = [partB intValue];
|
||||
if (intA > intB) {
|
||||
valueA = [partA longLongValue];
|
||||
valueB = [partB longLongValue];
|
||||
if (valueA > valueB) {
|
||||
return NSOrderedDescending;
|
||||
} else if (intA < intB) {
|
||||
} else if (valueA < valueB) {
|
||||
return NSOrderedAscending;
|
||||
}
|
||||
} else if (typeA == kStringType) {
|
||||
|
||||
Generated
-48
@@ -1,48 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>IBClasses</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>CLASS</key>
|
||||
<string>NSApplication</string>
|
||||
<key>LANGUAGE</key>
|
||||
<string>ObjC</string>
|
||||
<key>SUPERCLASS</key>
|
||||
<string>NSResponder</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>CLASS</key>
|
||||
<string>FirstResponder</string>
|
||||
<key>LANGUAGE</key>
|
||||
<string>ObjC</string>
|
||||
<key>SUPERCLASS</key>
|
||||
<string>NSObject</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>CLASS</key>
|
||||
<string>NSObject</string>
|
||||
<key>LANGUAGE</key>
|
||||
<string>ObjC</string>
|
||||
</dict>
|
||||
<dict>
|
||||
<key>CLASS</key>
|
||||
<string>SUStatusController</string>
|
||||
<key>LANGUAGE</key>
|
||||
<string>ObjC</string>
|
||||
<key>OUTLETS</key>
|
||||
<dict>
|
||||
<key>actionButton</key>
|
||||
<string>NSButton</string>
|
||||
<key>progressBar</key>
|
||||
<string>NSProgressIndicator</string>
|
||||
</dict>
|
||||
<key>SUPERCLASS</key>
|
||||
<string>NSWindowController</string>
|
||||
</dict>
|
||||
</array>
|
||||
<key>IBVersion</key>
|
||||
<string>1</string>
|
||||
</dict>
|
||||
</plist>
|
||||
Generated
-20
@@ -1,20 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>IBFramework Version</key>
|
||||
<string>629</string>
|
||||
<key>IBLastKnownRelativeProjectPath</key>
|
||||
<string>../Sparkle.xcodeproj</string>
|
||||
<key>IBOldestOS</key>
|
||||
<integer>5</integer>
|
||||
<key>IBOpenObjects</key>
|
||||
<array>
|
||||
<integer>6</integer>
|
||||
</array>
|
||||
<key>IBSystem Version</key>
|
||||
<string>9C31</string>
|
||||
<key>targetFramework</key>
|
||||
<string>IBCocoaFramework</string>
|
||||
</dict>
|
||||
</plist>
|
||||
Generated
BIN
Binary file not shown.
+589
@@ -0,0 +1,589 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.10">
|
||||
<data>
|
||||
<int key="IBDocument.SystemTarget">1050</int>
|
||||
<string key="IBDocument.SystemVersion">10D573</string>
|
||||
<string key="IBDocument.InterfaceBuilderVersion">762</string>
|
||||
<string key="IBDocument.AppKitVersion">1038.29</string>
|
||||
<string key="IBDocument.HIToolboxVersion">460.00</string>
|
||||
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="NSArray" key="dict.sortedKeys" id="0">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
</object>
|
||||
<object class="NSMutableArray" key="dict.values">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
</object>
|
||||
</object>
|
||||
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<integer value="6"/>
|
||||
</object>
|
||||
<reference key="IBDocument.PluginDependencies" ref="0"/>
|
||||
<object class="NSMutableDictionary" key="IBDocument.Metadata">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<reference key="dict.sortedKeys" ref="0"/>
|
||||
<object class="NSMutableArray" key="dict.values">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
</object>
|
||||
</object>
|
||||
<object class="NSMutableArray" key="IBDocument.RootObjects" id="780577916">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="NSCustomObject" id="245526436">
|
||||
<string key="NSClassName">SUStatusController</string>
|
||||
</object>
|
||||
<object class="NSCustomObject" id="879485556">
|
||||
<string key="NSClassName">FirstResponder</string>
|
||||
</object>
|
||||
<object class="NSCustomObject" id="472338989">
|
||||
<string key="NSClassName">NSApplication</string>
|
||||
</object>
|
||||
<object class="NSWindowTemplate" id="661323156">
|
||||
<int key="NSWindowStyleMask">1</int>
|
||||
<int key="NSWindowBacking">2</int>
|
||||
<string key="NSWindowRect">{{200, 222}, {400, 107}}</string>
|
||||
<int key="NSWTFlags">1886912512</int>
|
||||
<string key="NSWindowTitle">Set in Code</string>
|
||||
<object class="NSMutableString" key="NSWindowClass">
|
||||
<characters key="NS.bytes">NSWindow</characters>
|
||||
</object>
|
||||
<object class="NSMutableString" key="NSViewClass">
|
||||
<characters key="NS.bytes">View</characters>
|
||||
</object>
|
||||
<string key="NSWindowContentMaxSize">{3.40282e+38, 3.40282e+38}</string>
|
||||
<string key="NSWindowContentMinSize">{213, 107}</string>
|
||||
<object class="NSView" key="NSWindowView" id="512815736">
|
||||
<reference key="NSNextResponder"/>
|
||||
<int key="NSvFlags">256</int>
|
||||
<object class="NSMutableArray" key="NSSubviews">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="NSImageView" id="56655866">
|
||||
<reference key="NSNextResponder" ref="512815736"/>
|
||||
<int key="NSvFlags">268</int>
|
||||
<object class="NSMutableSet" key="NSDragTypes">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="NSArray" key="set.sortedObjects">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<string>Apple PDF pasteboard type</string>
|
||||
<string>Apple PICT pasteboard type</string>
|
||||
<string>Apple PNG pasteboard type</string>
|
||||
<string>NSFilenamesPboardType</string>
|
||||
<string>NeXT Encapsulated PostScript v1.2 pasteboard type</string>
|
||||
<string>NeXT TIFF v4.0 pasteboard type</string>
|
||||
</object>
|
||||
</object>
|
||||
<string key="NSFrame">{{24, 28}, {64, 64}}</string>
|
||||
<reference key="NSSuperview" ref="512815736"/>
|
||||
<bool key="NSEnabled">YES</bool>
|
||||
<object class="NSImageCell" key="NSCell" id="381943368">
|
||||
<int key="NSCellFlags">130560</int>
|
||||
<int key="NSCellFlags2">33554432</int>
|
||||
<object class="NSCustomResource" key="NSContents">
|
||||
<string key="NSClassName">NSImage</string>
|
||||
<string key="NSResourceName">NSApplicationIcon</string>
|
||||
</object>
|
||||
<int key="NSAlign">0</int>
|
||||
<int key="NSScale">1</int>
|
||||
<int key="NSStyle">0</int>
|
||||
<bool key="NSAnimates">NO</bool>
|
||||
</object>
|
||||
<bool key="NSEditable">YES</bool>
|
||||
</object>
|
||||
<object class="NSTextField" id="692218720">
|
||||
<reference key="NSNextResponder" ref="512815736"/>
|
||||
<int key="NSvFlags">268</int>
|
||||
<string key="NSFrame">{{106, 75}, {277, 17}}</string>
|
||||
<reference key="NSSuperview" ref="512815736"/>
|
||||
<bool key="NSEnabled">YES</bool>
|
||||
<object class="NSTextFieldCell" key="NSCell" id="597081861">
|
||||
<int key="NSCellFlags">67239424</int>
|
||||
<int key="NSCellFlags2">272629760</int>
|
||||
<string key="NSContents">Status Text (set by loc. string in code)</string>
|
||||
<object class="NSFont" key="NSSupport">
|
||||
<string key="NSName">LucidaGrande-Bold</string>
|
||||
<double key="NSSize">13</double>
|
||||
<int key="NSfFlags">2072</int>
|
||||
</object>
|
||||
<reference key="NSControlView" ref="692218720"/>
|
||||
<object class="NSColor" key="NSBackgroundColor" id="747797151">
|
||||
<int key="NSColorSpace">6</int>
|
||||
<string key="NSCatalogName">System</string>
|
||||
<string key="NSColorName">controlColor</string>
|
||||
<object class="NSColor" key="NSColor">
|
||||
<int key="NSColorSpace">3</int>
|
||||
<bytes key="NSWhite">MC42NjY2NjY2ODY1AA</bytes>
|
||||
</object>
|
||||
</object>
|
||||
<object class="NSColor" key="NSTextColor" id="640273742">
|
||||
<int key="NSColorSpace">6</int>
|
||||
<string key="NSCatalogName">System</string>
|
||||
<string key="NSColorName">controlTextColor</string>
|
||||
<object class="NSColor" key="NSColor">
|
||||
<int key="NSColorSpace">3</int>
|
||||
<bytes key="NSWhite">MAA</bytes>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
<object class="NSProgressIndicator" id="454270533">
|
||||
<reference key="NSNextResponder" ref="512815736"/>
|
||||
<int key="NSvFlags">1280</int>
|
||||
<object class="NSPSMatrix" key="NSDrawMatrix"/>
|
||||
<string key="NSFrame">{{107, 47}, {275, 20}}</string>
|
||||
<reference key="NSSuperview" ref="512815736"/>
|
||||
<int key="NSpiFlags">16394</int>
|
||||
<double key="NSMaxValue">100</double>
|
||||
</object>
|
||||
<object class="NSButton" id="566879706">
|
||||
<reference key="NSNextResponder" ref="512815736"/>
|
||||
<int key="NSvFlags">259</int>
|
||||
<string key="NSFrame">{{272, 12}, {114, 32}}</string>
|
||||
<reference key="NSSuperview" ref="512815736"/>
|
||||
<bool key="NSEnabled">YES</bool>
|
||||
<object class="NSButtonCell" key="NSCell" id="130218013">
|
||||
<int key="NSCellFlags">67239424</int>
|
||||
<int key="NSCellFlags2">134217728</int>
|
||||
<string key="NSContents">Button</string>
|
||||
<object class="NSFont" key="NSSupport" id="531315841">
|
||||
<string key="NSName">LucidaGrande</string>
|
||||
<double key="NSSize">13</double>
|
||||
<int key="NSfFlags">1044</int>
|
||||
</object>
|
||||
<reference key="NSControlView" ref="566879706"/>
|
||||
<int key="NSButtonFlags">-2038284033</int>
|
||||
<int key="NSButtonFlags2">1</int>
|
||||
<reference key="NSAlternateImage" ref="531315841"/>
|
||||
<string key="NSAlternateContents"/>
|
||||
<object class="NSMutableString" key="NSKeyEquivalent">
|
||||
<characters key="NS.bytes"/>
|
||||
</object>
|
||||
<int key="NSPeriodicDelay">200</int>
|
||||
<int key="NSPeriodicInterval">25</int>
|
||||
</object>
|
||||
</object>
|
||||
<object class="NSTextField" id="65200871">
|
||||
<reference key="NSNextResponder" ref="512815736"/>
|
||||
<int key="NSvFlags">256</int>
|
||||
<string key="NSFrame">{{106, 22}, {167, 17}}</string>
|
||||
<reference key="NSSuperview" ref="512815736"/>
|
||||
<bool key="NSEnabled">YES</bool>
|
||||
<object class="NSTextFieldCell" key="NSCell" id="180962568">
|
||||
<int key="NSCellFlags">67239424</int>
|
||||
<int key="NSCellFlags2">272629760</int>
|
||||
<string key="NSContents">Small System Font Text</string>
|
||||
<reference key="NSSupport" ref="531315841"/>
|
||||
<reference key="NSControlView" ref="65200871"/>
|
||||
<reference key="NSBackgroundColor" ref="747797151"/>
|
||||
<reference key="NSTextColor" ref="640273742"/>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
<string key="NSFrameSize">{400, 107}</string>
|
||||
<reference key="NSSuperview"/>
|
||||
</object>
|
||||
<string key="NSScreenRect">{{0, 0}, {1920, 1178}}</string>
|
||||
<string key="NSMinSize">{213, 129}</string>
|
||||
<string key="NSMaxSize">{3.40282e+38, 3.40282e+38}</string>
|
||||
</object>
|
||||
</object>
|
||||
<object class="IBObjectContainer" key="IBDocument.Objects">
|
||||
<object class="NSMutableArray" key="connectionRecords">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBBindingConnection" key="connection">
|
||||
<string key="label">value: applicationIcon</string>
|
||||
<reference key="source" ref="56655866"/>
|
||||
<reference key="destination" ref="245526436"/>
|
||||
<object class="NSNibBindingConnector" key="connector">
|
||||
<reference key="NSSource" ref="56655866"/>
|
||||
<reference key="NSDestination" ref="245526436"/>
|
||||
<string key="NSLabel">value: applicationIcon</string>
|
||||
<string key="NSBinding">value</string>
|
||||
<string key="NSKeyPath">applicationIcon</string>
|
||||
<int key="NSNibBindingConnectorVersion">2</int>
|
||||
</object>
|
||||
</object>
|
||||
<int key="connectionID">9</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBBindingConnection" key="connection">
|
||||
<string key="label">maxValue: maxProgressValue</string>
|
||||
<reference key="source" ref="454270533"/>
|
||||
<reference key="destination" ref="245526436"/>
|
||||
<object class="NSNibBindingConnector" key="connector" id="110266706">
|
||||
<reference key="NSSource" ref="454270533"/>
|
||||
<reference key="NSDestination" ref="245526436"/>
|
||||
<string key="NSLabel">maxValue: maxProgressValue</string>
|
||||
<string key="NSBinding">maxValue</string>
|
||||
<string key="NSKeyPath">maxProgressValue</string>
|
||||
<int key="NSNibBindingConnectorVersion">2</int>
|
||||
</object>
|
||||
</object>
|
||||
<int key="connectionID">13</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBBindingConnection" key="connection">
|
||||
<string key="label">value: statusText</string>
|
||||
<reference key="source" ref="65200871"/>
|
||||
<reference key="destination" ref="245526436"/>
|
||||
<object class="NSNibBindingConnector" key="connector">
|
||||
<reference key="NSSource" ref="65200871"/>
|
||||
<reference key="NSDestination" ref="245526436"/>
|
||||
<string key="NSLabel">value: statusText</string>
|
||||
<string key="NSBinding">value</string>
|
||||
<string key="NSKeyPath">statusText</string>
|
||||
<int key="NSNibBindingConnectorVersion">2</int>
|
||||
</object>
|
||||
</object>
|
||||
<int key="connectionID">17</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBBindingConnection" key="connection">
|
||||
<string key="label">title: buttonTitle</string>
|
||||
<reference key="source" ref="566879706"/>
|
||||
<reference key="destination" ref="245526436"/>
|
||||
<object class="NSNibBindingConnector" key="connector">
|
||||
<reference key="NSSource" ref="566879706"/>
|
||||
<reference key="NSDestination" ref="245526436"/>
|
||||
<string key="NSLabel">title: buttonTitle</string>
|
||||
<string key="NSBinding">title</string>
|
||||
<string key="NSKeyPath">buttonTitle</string>
|
||||
<int key="NSNibBindingConnectorVersion">2</int>
|
||||
</object>
|
||||
</object>
|
||||
<int key="connectionID">21</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBBindingConnection" key="connection">
|
||||
<string key="label">title: windowTitle</string>
|
||||
<reference key="source" ref="661323156"/>
|
||||
<reference key="destination" ref="245526436"/>
|
||||
<object class="NSNibBindingConnector" key="connector">
|
||||
<reference key="NSSource" ref="661323156"/>
|
||||
<reference key="NSDestination" ref="245526436"/>
|
||||
<string key="NSLabel">title: windowTitle</string>
|
||||
<string key="NSBinding">title</string>
|
||||
<string key="NSKeyPath">windowTitle</string>
|
||||
<int key="NSNibBindingConnectorVersion">2</int>
|
||||
</object>
|
||||
</object>
|
||||
<int key="connectionID">24</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBOutletConnection" key="connection">
|
||||
<string key="label">window</string>
|
||||
<reference key="source" ref="245526436"/>
|
||||
<reference key="destination" ref="661323156"/>
|
||||
</object>
|
||||
<int key="connectionID">25</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBBindingConnection" key="connection">
|
||||
<string key="label">value: title</string>
|
||||
<reference key="source" ref="692218720"/>
|
||||
<reference key="destination" ref="245526436"/>
|
||||
<object class="NSNibBindingConnector" key="connector">
|
||||
<reference key="NSSource" ref="692218720"/>
|
||||
<reference key="NSDestination" ref="245526436"/>
|
||||
<string key="NSLabel">value: title</string>
|
||||
<string key="NSBinding">value</string>
|
||||
<string key="NSKeyPath">title</string>
|
||||
<int key="NSNibBindingConnectorVersion">2</int>
|
||||
</object>
|
||||
</object>
|
||||
<int key="connectionID">26</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBBindingConnection" key="connection">
|
||||
<string key="label">value: progressValue</string>
|
||||
<reference key="source" ref="454270533"/>
|
||||
<reference key="destination" ref="245526436"/>
|
||||
<object class="NSNibBindingConnector" key="connector">
|
||||
<reference key="NSSource" ref="454270533"/>
|
||||
<reference key="NSDestination" ref="245526436"/>
|
||||
<string key="NSLabel">value: progressValue</string>
|
||||
<string key="NSBinding">value</string>
|
||||
<string key="NSKeyPath">progressValue</string>
|
||||
<reference key="NSPreviousConnector" ref="110266706"/>
|
||||
<int key="NSNibBindingConnectorVersion">2</int>
|
||||
</object>
|
||||
</object>
|
||||
<int key="connectionID">27</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBBindingConnection" key="connection">
|
||||
<string key="label">hidden: statusText</string>
|
||||
<reference key="source" ref="65200871"/>
|
||||
<reference key="destination" ref="245526436"/>
|
||||
<object class="NSNibBindingConnector" key="connector">
|
||||
<reference key="NSSource" ref="65200871"/>
|
||||
<reference key="NSDestination" ref="245526436"/>
|
||||
<string key="NSLabel">hidden: statusText</string>
|
||||
<string key="NSBinding">hidden</string>
|
||||
<string key="NSKeyPath">statusText</string>
|
||||
<object class="NSDictionary" key="NSOptions">
|
||||
<string key="NS.key.0">NSValueTransformerName</string>
|
||||
<string key="NS.object.0">NSIsNil</string>
|
||||
</object>
|
||||
<int key="NSNibBindingConnectorVersion">2</int>
|
||||
</object>
|
||||
</object>
|
||||
<int key="connectionID">33</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBOutletConnection" key="connection">
|
||||
<string key="label">actionButton</string>
|
||||
<reference key="source" ref="245526436"/>
|
||||
<reference key="destination" ref="566879706"/>
|
||||
</object>
|
||||
<int key="connectionID">34</int>
|
||||
</object>
|
||||
<object class="IBConnectionRecord">
|
||||
<object class="IBOutletConnection" key="connection">
|
||||
<string key="label">progressBar</string>
|
||||
<reference key="source" ref="245526436"/>
|
||||
<reference key="destination" ref="454270533"/>
|
||||
</object>
|
||||
<int key="connectionID">49</int>
|
||||
</object>
|
||||
</object>
|
||||
<object class="IBMutableOrderedSet" key="objectRecords">
|
||||
<object class="NSArray" key="orderedObjects">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">0</int>
|
||||
<reference key="object" ref="0"/>
|
||||
<reference key="children" ref="780577916"/>
|
||||
<nil key="parent"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">-2</int>
|
||||
<reference key="object" ref="245526436"/>
|
||||
<reference key="parent" ref="0"/>
|
||||
<string key="objectName">File's Owner</string>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">-1</int>
|
||||
<reference key="object" ref="879485556"/>
|
||||
<reference key="parent" ref="0"/>
|
||||
<string key="objectName">First Responder</string>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">-3</int>
|
||||
<reference key="object" ref="472338989"/>
|
||||
<reference key="parent" ref="0"/>
|
||||
<string key="objectName">Application</string>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">5</int>
|
||||
<reference key="object" ref="661323156"/>
|
||||
<object class="NSMutableArray" key="children">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<reference ref="512815736"/>
|
||||
</object>
|
||||
<reference key="parent" ref="0"/>
|
||||
<string key="objectName">Window</string>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">6</int>
|
||||
<reference key="object" ref="512815736"/>
|
||||
<object class="NSMutableArray" key="children">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<reference ref="56655866"/>
|
||||
<reference ref="692218720"/>
|
||||
<reference ref="454270533"/>
|
||||
<reference ref="566879706"/>
|
||||
<reference ref="65200871"/>
|
||||
</object>
|
||||
<reference key="parent" ref="661323156"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">7</int>
|
||||
<reference key="object" ref="56655866"/>
|
||||
<object class="NSMutableArray" key="children">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<reference ref="381943368"/>
|
||||
</object>
|
||||
<reference key="parent" ref="512815736"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">8</int>
|
||||
<reference key="object" ref="692218720"/>
|
||||
<object class="NSMutableArray" key="children">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<reference ref="597081861"/>
|
||||
</object>
|
||||
<reference key="parent" ref="512815736"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">11</int>
|
||||
<reference key="object" ref="454270533"/>
|
||||
<reference key="parent" ref="512815736"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">12</int>
|
||||
<reference key="object" ref="566879706"/>
|
||||
<object class="NSMutableArray" key="children">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<reference ref="130218013"/>
|
||||
</object>
|
||||
<reference key="parent" ref="512815736"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">16</int>
|
||||
<reference key="object" ref="65200871"/>
|
||||
<object class="NSMutableArray" key="children">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<reference ref="180962568"/>
|
||||
</object>
|
||||
<reference key="parent" ref="512815736"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">53</int>
|
||||
<reference key="object" ref="381943368"/>
|
||||
<reference key="parent" ref="56655866"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">54</int>
|
||||
<reference key="object" ref="597081861"/>
|
||||
<reference key="parent" ref="692218720"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">55</int>
|
||||
<reference key="object" ref="130218013"/>
|
||||
<reference key="parent" ref="566879706"/>
|
||||
</object>
|
||||
<object class="IBObjectRecord">
|
||||
<int key="objectID">56</int>
|
||||
<reference key="object" ref="180962568"/>
|
||||
<reference key="parent" ref="65200871"/>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
<object class="NSMutableDictionary" key="flattenedProperties">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="NSArray" key="dict.sortedKeys">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<string>-3.ImportedFromIB2</string>
|
||||
<string>11.ImportedFromIB2</string>
|
||||
<string>12.ImportedFromIB2</string>
|
||||
<string>16.ImportedFromIB2</string>
|
||||
<string>5.IBEditorWindowLastContentRect</string>
|
||||
<string>5.IBWindowTemplateEditedContentRect</string>
|
||||
<string>5.ImportedFromIB2</string>
|
||||
<string>5.windowTemplate.hasMinSize</string>
|
||||
<string>5.windowTemplate.minSize</string>
|
||||
<string>6.ImportedFromIB2</string>
|
||||
<string>7.ImportedFromIB2</string>
|
||||
<string>8.ImportedFromIB2</string>
|
||||
</object>
|
||||
<object class="NSMutableArray" key="dict.values">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<boolean value="YES"/>
|
||||
<boolean value="YES"/>
|
||||
<boolean value="YES"/>
|
||||
<boolean value="YES"/>
|
||||
<string>{{294, 716}, {400, 107}}</string>
|
||||
<string>{{294, 716}, {400, 107}}</string>
|
||||
<boolean value="YES"/>
|
||||
<boolean value="YES"/>
|
||||
<string>{213, 107}</string>
|
||||
<boolean value="YES"/>
|
||||
<boolean value="YES"/>
|
||||
<boolean value="YES"/>
|
||||
</object>
|
||||
</object>
|
||||
<object class="NSMutableDictionary" key="unlocalizedProperties">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<reference key="dict.sortedKeys" ref="0"/>
|
||||
<object class="NSMutableArray" key="dict.values">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
</object>
|
||||
</object>
|
||||
<nil key="activeLocalization"/>
|
||||
<object class="NSMutableDictionary" key="localizations">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<reference key="dict.sortedKeys" ref="0"/>
|
||||
<object class="NSMutableArray" key="dict.values">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
</object>
|
||||
</object>
|
||||
<nil key="sourceID"/>
|
||||
<int key="maxID">56</int>
|
||||
</object>
|
||||
<object class="IBClassDescriber" key="IBDocument.Classes">
|
||||
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="IBPartialClassDescription">
|
||||
<string key="className">FirstResponder</string>
|
||||
<string key="superclassName">NSObject</string>
|
||||
<object class="IBClassDescriptionSource" key="sourceIdentifier">
|
||||
<string key="majorKey">IBUserSource</string>
|
||||
<string key="minorKey"/>
|
||||
</object>
|
||||
</object>
|
||||
<object class="IBPartialClassDescription">
|
||||
<string key="className">NSApplication</string>
|
||||
<string key="superclassName">NSResponder</string>
|
||||
<object class="IBClassDescriptionSource" key="sourceIdentifier">
|
||||
<string key="majorKey">IBUserSource</string>
|
||||
<string key="minorKey"/>
|
||||
</object>
|
||||
</object>
|
||||
<object class="IBPartialClassDescription">
|
||||
<string key="className">NSObject</string>
|
||||
<object class="IBClassDescriptionSource" key="sourceIdentifier">
|
||||
<string key="majorKey">IBUserSource</string>
|
||||
<string key="minorKey"/>
|
||||
</object>
|
||||
</object>
|
||||
<object class="IBPartialClassDescription">
|
||||
<string key="className">SUStatusController</string>
|
||||
<string key="superclassName">SUWindowController</string>
|
||||
<object class="NSMutableDictionary" key="outlets">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<object class="NSArray" key="dict.sortedKeys">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<string>actionButton</string>
|
||||
<string>progressBar</string>
|
||||
</object>
|
||||
<object class="NSMutableArray" key="dict.values">
|
||||
<bool key="EncodedWithXMLCoder">YES</bool>
|
||||
<string>NSButton</string>
|
||||
<string>NSProgressIndicator</string>
|
||||
</object>
|
||||
</object>
|
||||
<object class="IBClassDescriptionSource" key="sourceIdentifier">
|
||||
<string key="majorKey">IBUserSource</string>
|
||||
<string key="minorKey"/>
|
||||
</object>
|
||||
</object>
|
||||
<object class="IBPartialClassDescription">
|
||||
<string key="className">SUWindowController</string>
|
||||
<string key="superclassName">NSWindowController</string>
|
||||
<object class="IBClassDescriptionSource" key="sourceIdentifier">
|
||||
<string key="majorKey">IBUserSource</string>
|
||||
<string key="minorKey"/>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
</object>
|
||||
<int key="IBDocument.localizationMode">0</int>
|
||||
<string key="IBDocument.TargetRuntimeIdentifier">IBCocoaFramework</string>
|
||||
<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDependencies">
|
||||
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin.macosx</string>
|
||||
<integer value="1050" key="NS.object.0"/>
|
||||
</object>
|
||||
<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDevelopmentDependencies">
|
||||
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3</string>
|
||||
<integer value="3100" key="NS.object.0"/>
|
||||
</object>
|
||||
<bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
|
||||
<string key="IBDocument.LastKnownRelativeProjectPath">Sparkle.xcodeproj</string>
|
||||
<int key="IBDocument.defaultPropertyAccessControl">3</int>
|
||||
<object class="NSMutableDictionary" key="IBDocument.LastKnownImageSizes">
|
||||
<string key="NS.key.0">NSApplicationIcon</string>
|
||||
<string key="NS.object.0">{128, 128}</string>
|
||||
</object>
|
||||
</data>
|
||||
</archive>
|
||||
@@ -11,15 +11,18 @@
|
||||
|
||||
#import "SUWindowController.h"
|
||||
|
||||
@interface SUStatusController : SUWindowController {
|
||||
@class SUHost;
|
||||
@interface SUStatusController : SUWindowController
|
||||
{
|
||||
@private
|
||||
double progressValue, maxProgressValue;
|
||||
NSString *title, *statusText, *buttonTitle;
|
||||
IBOutlet NSButton *actionButton;
|
||||
IBOutlet NSProgressIndicator* progressBar;
|
||||
NSBundle *hostBundle;
|
||||
SUHost *host;
|
||||
}
|
||||
|
||||
- (id)initWithHostBundle:(NSBundle *)hostBundle;
|
||||
- (id)initWithHost:(SUHost *)host;
|
||||
|
||||
// Pass 0 for the max progress value to get an indeterminate progress bar.
|
||||
// Pass nil for the status text to not show it.
|
||||
|
||||
+33
-10
@@ -6,17 +6,23 @@
|
||||
// Copyright 2006 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#import "Sparkle.h"
|
||||
#import "SUUpdater.h"
|
||||
|
||||
#import "SUAppcast.h"
|
||||
#import "SUAppcastItem.h"
|
||||
#import "SUVersionComparisonProtocol.h"
|
||||
#import "SUStatusController.h"
|
||||
#import "SUHost.h"
|
||||
|
||||
|
||||
@implementation SUStatusController
|
||||
|
||||
- (id)initWithHostBundle:(NSBundle *)hb
|
||||
- (id)initWithHost:(SUHost *)aHost
|
||||
{
|
||||
self = [super initWithHostBundle:hb windowNibName:@"SUStatus"];
|
||||
self = [super initWithHost:aHost windowNibName:@"SUStatus"];
|
||||
if (self)
|
||||
{
|
||||
hostBundle = [hb retain];
|
||||
host = [aHost retain];
|
||||
[self setShouldCascadeWindows:NO];
|
||||
}
|
||||
return self;
|
||||
@@ -24,15 +30,21 @@
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[hostBundle release];
|
||||
[host release];
|
||||
[title release];
|
||||
[statusText release];
|
||||
[buttonTitle release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@, %@>", [self class], [host bundlePath], [host installationPath]]; }
|
||||
|
||||
- (void)awakeFromNib
|
||||
{
|
||||
if ([host isBackgroundApplication]) {
|
||||
[[self window] setLevel:NSFloatingWindowLevel];
|
||||
}
|
||||
|
||||
[[self window] center];
|
||||
[[self window] setFrameAutosaveName:@"SUStatusFrame"];
|
||||
[progressBar setUsesThreadedAnimation:YES];
|
||||
@@ -40,12 +52,12 @@
|
||||
|
||||
- (NSString *)windowTitle
|
||||
{
|
||||
return [NSString stringWithFormat:SULocalizedString(@"Updating %@", nil), [hostBundle name]];
|
||||
return [NSString stringWithFormat:SULocalizedString(@"Updating %@", nil), [host name]];
|
||||
}
|
||||
|
||||
- (NSImage *)applicationIcon
|
||||
{
|
||||
return [hostBundle icon];
|
||||
return [host icon];
|
||||
}
|
||||
|
||||
- (void)beginActionWithTitle:(NSString *)aTitle maxProgressValue:(double)aMaxProgressValue statusText:(NSString *)aStatusText
|
||||
@@ -58,7 +70,7 @@
|
||||
[self setStatusText:aStatusText];
|
||||
}
|
||||
|
||||
- (void)setButtonTitle:(NSString *)aButtonTitle target:target action:(SEL)action isDefault:(BOOL)isDefault
|
||||
- (void)setButtonTitle:(NSString *)aButtonTitle target: (id)target action:(SEL)action isDefault:(BOOL)isDefault
|
||||
{
|
||||
[self willChangeValueForKey:@"buttonTitle"];
|
||||
if (buttonTitle != aButtonTitle)
|
||||
@@ -80,6 +92,14 @@
|
||||
[actionButton setTarget:target];
|
||||
[actionButton setAction:action];
|
||||
[actionButton setKeyEquivalent:isDefault ? @"\r" : @""];
|
||||
|
||||
// 06/05/2008 Alex: Avoid a crash when cancelling during the extraction
|
||||
[self setButtonEnabled: (target != nil)];
|
||||
}
|
||||
|
||||
- (BOOL)progressBarShouldAnimate
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)setButtonEnabled:(BOOL)enabled
|
||||
@@ -104,9 +124,12 @@
|
||||
|
||||
- (void)setMaxProgressValue:(double)value
|
||||
{
|
||||
if (value < 0.0) value = 0.0;
|
||||
maxProgressValue = value;
|
||||
[self setProgressValue:0];
|
||||
[progressBar setIndeterminate:(value == 0)];
|
||||
[self setProgressValue:0.0];
|
||||
[progressBar setIndeterminate:(value == 0.0)];
|
||||
[progressBar startAnimation:self];
|
||||
[progressBar setUsesThreadedAnimation: YES];
|
||||
}
|
||||
|
||||
- (void)setStatusText:(NSString *)aStatusText
|
||||
|
||||
+5
-2
@@ -9,9 +9,12 @@
|
||||
#ifndef SUSYSTEMPROFILER_H
|
||||
#define SUSYSTEMPROFILER_H
|
||||
|
||||
@interface SUSystemProfiler : NSObject {}
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@class SUHost;
|
||||
@interface SUSystemProfiler : NSObject
|
||||
+ (SUSystemProfiler *)sharedSystemProfiler;
|
||||
- (NSMutableArray *)systemProfileArrayForHostBundle:(NSBundle *)hostBundle;
|
||||
- (NSMutableArray *)systemProfileArrayForHost:(SUHost *)host;
|
||||
@end
|
||||
|
||||
#endif
|
||||
+39
-28
@@ -7,9 +7,9 @@
|
||||
// Adapted from Sparkle+, by Tom Harrington.
|
||||
//
|
||||
|
||||
#import "Sparkle.h"
|
||||
#import "SUSystemProfiler.h"
|
||||
|
||||
#import "SUHost.h"
|
||||
#import <sys/sysctl.h>
|
||||
|
||||
@implementation SUSystemProfiler
|
||||
@@ -27,19 +27,19 @@
|
||||
return [[[NSDictionary alloc] initWithContentsOfFile:path] autorelease];
|
||||
}
|
||||
|
||||
- (NSMutableArray *)systemProfileArrayForHostBundle:(NSBundle *)hostBundle
|
||||
- (NSMutableArray *)systemProfileArrayForHost:(SUHost *)host
|
||||
{
|
||||
NSDictionary *modelTranslation = [self modelTranslationTable];
|
||||
|
||||
// Gather profile information and append it to the URL.
|
||||
NSMutableArray *profileArray = [NSMutableArray array];
|
||||
NSArray *profileDictKeys = [NSArray arrayWithObjects:@"key", @"visibleKey", @"value", @"visibleValue", nil];
|
||||
int error = 0 ;
|
||||
int value = 0 ;
|
||||
unsigned long length = sizeof(value) ;
|
||||
NSArray *profileDictKeys = [NSArray arrayWithObjects:@"key", @"displayKey", @"value", @"displayValue", nil];
|
||||
int error = 0;
|
||||
int value = 0;
|
||||
size_t length = sizeof(value);
|
||||
|
||||
// OS version
|
||||
NSString *currentSystemVersion = [NSWorkspace systemVersionString];
|
||||
NSString *currentSystemVersion = [SUHost systemVersionString];
|
||||
if (currentSystemVersion != nil)
|
||||
[profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"osVersion",@"OS Version",currentSystemVersion,currentSystemVersion,nil] forKeys:profileDictKeys]];
|
||||
|
||||
@@ -50,18 +50,30 @@
|
||||
cpuType = value;
|
||||
NSString *visibleCPUType;
|
||||
switch(value) {
|
||||
case 7: visibleCPUType=@"Intel"; break;
|
||||
case 18: visibleCPUType=@"PowerPC"; break;
|
||||
default: visibleCPUType=@"Unknown"; break;
|
||||
case CPU_TYPE_X86: visibleCPUType = @"Intel"; break;
|
||||
case CPU_TYPE_POWERPC: visibleCPUType = @"PowerPC"; break;
|
||||
default: visibleCPUType = @"Unknown"; break;
|
||||
}
|
||||
[profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"cputype",@"CPU Type", [NSNumber numberWithInt:value], visibleCPUType,nil] forKeys:profileDictKeys]];
|
||||
}
|
||||
error = sysctlbyname("hw.cpu64bit_capable", &value, &length, NULL, 0);
|
||||
if(error != 0)
|
||||
error = sysctlbyname("hw.optional.x86_64", &value, &length, NULL, 0); //x86 specific
|
||||
if(error != 0)
|
||||
error = sysctlbyname("hw.optional.64bitops", &value, &length, NULL, 0); //PPC specific
|
||||
|
||||
BOOL is64bit = NO;
|
||||
|
||||
if (error == 0) {
|
||||
is64bit = value == 1;
|
||||
[profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"cpu64bit", @"CPU is 64-Bit?", [NSNumber numberWithBool:is64bit], is64bit ? @"Yes" : @"No", nil] forKeys:profileDictKeys]];
|
||||
}
|
||||
error = sysctlbyname("hw.cpusubtype", &value, &length, NULL, 0);
|
||||
if (error == 0) {
|
||||
NSString *visibleCPUSubType;
|
||||
if (cpuType == 7) {
|
||||
// Intel
|
||||
visibleCPUSubType = @"Intel"; // If anyone knows how to tell a Core Duo from a Core Solo, please email tph@atomicbird.com
|
||||
visibleCPUSubType = is64bit ? @"Intel Core 2" : @"Intel Core"; // If anyone knows how to tell a Core Duo from a Core Solo, please email tph@atomicbird.com
|
||||
} else if (cpuType == 18) {
|
||||
// PowerPC
|
||||
switch(value) {
|
||||
@@ -77,18 +89,18 @@
|
||||
}
|
||||
error = sysctlbyname("hw.model", NULL, &length, NULL, 0);
|
||||
if (error == 0) {
|
||||
char *cpuModel;
|
||||
cpuModel = (char *)malloc(sizeof(char) * length);
|
||||
error = sysctlbyname("hw.model", cpuModel, &length, NULL, 0);
|
||||
if (error == 0) {
|
||||
NSString *rawModelName = [NSString stringWithUTF8String:cpuModel];
|
||||
NSString *visibleModelName = [modelTranslation objectForKey:rawModelName];
|
||||
if (visibleModelName == nil)
|
||||
visibleModelName = rawModelName;
|
||||
[profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"model",@"Mac Model", rawModelName, visibleModelName, nil] forKeys:profileDictKeys]];
|
||||
}
|
||||
if (cpuModel != NULL)
|
||||
char *cpuModel = (char *)malloc(sizeof(char) * length);
|
||||
if (cpuModel != NULL) {
|
||||
error = sysctlbyname("hw.model", cpuModel, &length, NULL, 0);
|
||||
if (error == 0) {
|
||||
NSString *rawModelName = [NSString stringWithUTF8String:cpuModel];
|
||||
NSString *visibleModelName = [modelTranslation objectForKey:rawModelName];
|
||||
if (visibleModelName == nil)
|
||||
visibleModelName = rawModelName;
|
||||
[profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"model",@"Mac Model", rawModelName, visibleModelName, nil] forKeys:profileDictKeys]];
|
||||
}
|
||||
free(cpuModel);
|
||||
}
|
||||
}
|
||||
|
||||
// Number of CPUs
|
||||
@@ -99,24 +111,23 @@
|
||||
// User preferred language
|
||||
NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
|
||||
NSArray *languages = [defs objectForKey:@"AppleLanguages"];
|
||||
if (languages && ([languages count] > 0))
|
||||
if ([languages count] > 0)
|
||||
[profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"lang",@"Preferred Language", [languages objectAtIndex:0], [languages objectAtIndex:0],nil] forKeys:profileDictKeys]];
|
||||
|
||||
// Application sending the request
|
||||
NSString *appName = [hostBundle name];
|
||||
NSString *appName = [host name];
|
||||
if (appName)
|
||||
[profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"appName",@"Application Name", appName, appName,nil] forKeys:profileDictKeys]];
|
||||
NSString *appVersion = [hostBundle version];
|
||||
NSString *appVersion = [host version];
|
||||
if (appVersion)
|
||||
[profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"appVersion",@"Application Version", appVersion, appVersion,nil] forKeys:profileDictKeys]];
|
||||
|
||||
// Number of displays?
|
||||
// CPU speed
|
||||
OSErr err;
|
||||
SInt32 gestaltInfo;
|
||||
err = Gestalt(gestaltProcClkSpeedMHz,&gestaltInfo);
|
||||
OSErr err = Gestalt(gestaltProcClkSpeedMHz,&gestaltInfo);
|
||||
if (err == noErr)
|
||||
[profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"cpuFreqMHz",@"CPU Speed (MHz)", [NSNumber numberWithInt:gestaltInfo], [NSNumber numberWithInt:gestaltInfo],nil] forKeys:profileDictKeys]];
|
||||
[profileArray addObject:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"cpuFreqMHz",@"CPU Speed (GHz)", [NSNumber numberWithInt:gestaltInfo], [NSNumber numberWithDouble:gestaltInfo/1000.0],nil] forKeys:profileDictKeys]];
|
||||
|
||||
// amount of RAM
|
||||
err = Gestalt(gestaltPhysicalRAMSizeInMegabytes,&gestaltInfo);
|
||||
|
||||
@@ -11,13 +11,20 @@
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "SUBasicUpdateDriver.h"
|
||||
#import "SUUpdateAlert.h"
|
||||
|
||||
@class SUStatusController, SUUpdateAlert;
|
||||
@interface SUUIBasedUpdateDriver : SUBasicUpdateDriver {
|
||||
@class SUStatusController;
|
||||
|
||||
@interface SUUIBasedUpdateDriver : SUBasicUpdateDriver <SUUnarchiverDelegate, SUUpdateAlertDelegate>
|
||||
{
|
||||
SUStatusController *statusController;
|
||||
SUUpdateAlert *updateAlert;
|
||||
}
|
||||
|
||||
- (void)showModalAlert:(NSAlert *)alert;
|
||||
- (IBAction)cancelDownload: (id)sender;
|
||||
- (void)installAndRestart: (id)sender;
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
Loaded 100 of 361 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user