From fbcdba4f01db0cfd644fd5514860775074136f67 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Sat, 7 Jun 2008 10:53:00 -0700 Subject: [PATCH 01/22] Fixes several warnings --- NSBundle+SUAdditions.h | 2 ++ NSBundle+SUAdditions.m | 4 ++++ NSFileManager+Authentication.m | 3 ++- relaunch.m | 2 ++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/NSBundle+SUAdditions.h b/NSBundle+SUAdditions.h index 38fc9238..ed2475c4 100644 --- a/NSBundle+SUAdditions.h +++ b/NSBundle+SUAdditions.h @@ -9,6 +9,8 @@ #ifndef NSBUNDLE_PLUS_ADDITIONS_H #define NSBUNDLE_PLUS_ADDITIONS_H +#import + @interface NSBundle (SUAdditions) /*! @method diff --git a/NSBundle+SUAdditions.m b/NSBundle+SUAdditions.m index 948e5d55..983d0f5c 100644 --- a/NSBundle+SUAdditions.m +++ b/NSBundle+SUAdditions.m @@ -9,6 +9,10 @@ #import "Sparkle.h" #import "NSBundle+SUAdditions.h" +#ifndef NSAppKitVersionNumber10_4 +#define NSAppKitVersionNumber10_4 824 +#endif + @implementation NSBundle (SUAdditions) - (NSString *)name diff --git a/NSFileManager+Authentication.m b/NSFileManager+Authentication.m index 2c5d784b..01fc681d 100644 --- a/NSFileManager+Authentication.m +++ b/NSFileManager+Authentication.m @@ -82,7 +82,8 @@ static BOOL AuthorizationExecuteWithPrivilegesAndWait(AuthorizationRef authoriza if ((bundle = [NSBundle bundleWithPath:path])) { // We'll clean it up a little for safety. - NSMutableCharacterSet *validCharacters = [NSMutableCharacterSet alphanumericCharacterSet]; + // 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]]; } diff --git a/relaunch.m b/relaunch.m index be65c539..6d7a5416 100644 --- a/relaunch.m +++ b/relaunch.m @@ -1,6 +1,8 @@ #import +#include + @interface TerminationListener : NSObject { const char *executablePath; From 68c2e6a0551ff5089384576a957edd543a106824 Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Sun, 29 Jun 2008 21:39:24 -0700 Subject: [PATCH 02/22] Let Xcode know about the new localizations we've got for 1.5b2 and removed a bunch of crufty old localizations from the project. --- Sparkle.xcodeproj/project.pbxproj | 62 +++++++++---------------------- 1 file changed, 18 insertions(+), 44 deletions(-) diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 8a54edf2..6ec51f2a 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -224,31 +224,9 @@ 61AAE8230A321A7F00D8810D /* en */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Sparkle.strings; sourceTree = ""; }; 61AAE8250A321A7F00D8810D /* en */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = en; path = en.lproj/SUAutomaticUpdateAlert.nib; sourceTree = ""; }; 61AAE8270A321A7F00D8810D /* en */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = en; path = en.lproj/SUUpdateAlert.nib; sourceTree = ""; }; - 61AAE82D0A321AA200D8810D /* ca */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = ca; path = ca.lproj/Sparkle.strings; sourceTree = ""; }; - 61AAE83F0A321AD200D8810D /* cs */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = cs; path = cs.lproj/Sparkle.strings; sourceTree = ""; }; - 61AAE8420A321ADC00D8810D /* cy */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = cy; path = cy.lproj/Sparkle.strings; sourceTree = ""; }; - 61AAE8450A321AE500D8810D /* da */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = da; path = da.lproj/Sparkle.strings; sourceTree = ""; }; - 61AAE8480A321AED00D8810D /* de */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = de; path = de.lproj/Sparkle.strings; sourceTree = ""; }; 61AAE84F0A321AF700D8810D /* es */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/Sparkle.strings; sourceTree = ""; }; - 61AAE8560A321AFC00D8810D /* fi */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = fi; path = fi.lproj/Sparkle.strings; sourceTree = ""; }; 61AAE8590A321B0400D8810D /* fr */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/Sparkle.strings; sourceTree = ""; }; - 61AAE85C0A321B0C00D8810D /* he */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = he; path = he.lproj/Sparkle.strings; sourceTree = ""; }; - 61AAE85F0A321EF100D8810D /* hu */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = hu; path = hu.lproj/Sparkle.strings; sourceTree = ""; }; - 61AAE8620A321EFA00D8810D /* id */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = id; path = id.lproj/Sparkle.strings; sourceTree = ""; }; - 61AAE8650A321F0100D8810D /* is */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = is; path = is.lproj/Sparkle.strings; sourceTree = ""; }; - 61AAE8680A321F0B00D8810D /* it */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = it; path = it.lproj/Sparkle.strings; sourceTree = ""; }; - 61AAE86B0A321F2D00D8810D /* ja */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = ja; path = ja.lproj/Sparkle.strings; sourceTree = ""; }; - 61AAE86E0A321F3500D8810D /* ko */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = ko; path = ko.lproj/Sparkle.strings; sourceTree = ""; }; 61AAE8710A321F7700D8810D /* nl */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = nl; path = nl.lproj/Sparkle.strings; sourceTree = ""; }; - 61AAE8740A321FA500D8810D /* no */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = no; path = no.lproj/Sparkle.strings; sourceTree = ""; }; - 61AAE8770A321FBE00D8810D /* pl */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = pl; path = pl.lproj/Sparkle.strings; sourceTree = ""; }; - 61AAE87A0A321FC400D8810D /* ru */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = ru; path = ru.lproj/Sparkle.strings; sourceTree = ""; }; - 61AAE87D0A321FCD00D8810D /* sk */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = sk; path = sk.lproj/Sparkle.strings; sourceTree = ""; }; - 61AAE8800A32201100D8810D /* sv */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = sv; path = sv.lproj/Sparkle.strings; sourceTree = ""; }; - 61AAE8830A32202400D8810D /* th */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = th; path = th.lproj/Sparkle.strings; sourceTree = ""; }; - 61AAE8860A32203000D8810D /* tr */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = tr; path = tr.lproj/Sparkle.strings; sourceTree = ""; }; - 61AAE8890A32203800D8810D /* zh_CN */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = zh_CN; path = zh_CN.lproj/Sparkle.strings; sourceTree = ""; }; - 61AAE88C0A32203F00D8810D /* zh_TW */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = zh_TW; path = zh_TW.lproj/Sparkle.strings; sourceTree = ""; }; 61B5F8DF09C4CE3C00B25A18 /* NSString+extras.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = "NSString+extras.h"; sourceTree = ""; }; 61B5F8E009C4CE3C00B25A18 /* NSString+extras.m */ = {isa = PBXFileReference; fileEncoding = 30; includeInIndex = 0; lastKnownFileType = sourcecode.c.objc; path = "NSString+extras.m"; sourceTree = ""; }; 61B5F8E109C4CE3C00B25A18 /* RSS.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = RSS.h; sourceTree = ""; }; @@ -281,6 +259,15 @@ 61C1F2760DA066C2007ACE13 /* NSFileManager+ExtendedAttributes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSFileManager+ExtendedAttributes.h"; sourceTree = ""; }; 61C1F2770DA066C2007ACE13 /* NSFileManager+ExtendedAttributes.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSFileManager+ExtendedAttributes.m"; sourceTree = ""; }; 61C46F350D9C54F300B06326 /* en */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = en; path = en.lproj/SUUpdatePermissionPrompt.nib; sourceTree = ""; }; + 61F3651A0E18987B007ECA02 /* es */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = es; path = es.lproj/SUUpdatePermissionPrompt.nib; sourceTree = ""; }; + 61F3652A0E189883007ECA02 /* es */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = es; path = es.lproj/SUUpdateAlert.nib; sourceTree = ""; }; + 61F3652B0E189883007ECA02 /* es */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = es; path = es.lproj/SUAutomaticUpdateAlert.nib; sourceTree = ""; }; + 61F3652E0E18988F007ECA02 /* fr */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = fr; path = fr.lproj/SUUpdatePermissionPrompt.nib; sourceTree = ""; }; + 61F3652F0E18988F007ECA02 /* fr */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = fr; path = fr.lproj/SUUpdateAlert.nib; sourceTree = ""; }; + 61F365300E18988F007ECA02 /* fr */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = fr; path = fr.lproj/SUAutomaticUpdateAlert.nib; sourceTree = ""; }; + 61F365330E1898A3007ECA02 /* nl */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = nl; path = nl.lproj/SUUpdatePermissionPrompt.nib; sourceTree = ""; }; + 61F365340E1898A3007ECA02 /* nl */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = nl; path = nl.lproj/SUUpdateAlert.nib; sourceTree = ""; }; + 61F365350E1898A3007ECA02 /* nl */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = nl; path = nl.lproj/SUAutomaticUpdateAlert.nib; sourceTree = ""; }; 61F83F6F0DBFE137006FDD30 /* SUBasicUpdateDriver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUBasicUpdateDriver.h; sourceTree = ""; }; 61F83F700DBFE137006FDD30 /* SUBasicUpdateDriver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUBasicUpdateDriver.m; sourceTree = ""; }; 784590BF0DE0429F00D0D64B /* NSNumber+Units.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSNumber+Units.h"; sourceTree = ""; }; @@ -924,31 +911,9 @@ isa = PBXVariantGroup; children = ( 61AAE8230A321A7F00D8810D /* en */, - 61AAE82D0A321AA200D8810D /* ca */, - 61AAE83F0A321AD200D8810D /* cs */, - 61AAE8420A321ADC00D8810D /* cy */, - 61AAE8450A321AE500D8810D /* da */, - 61AAE8480A321AED00D8810D /* de */, 61AAE84F0A321AF700D8810D /* es */, - 61AAE8560A321AFC00D8810D /* fi */, 61AAE8590A321B0400D8810D /* fr */, - 61AAE85C0A321B0C00D8810D /* he */, - 61AAE85F0A321EF100D8810D /* hu */, - 61AAE8620A321EFA00D8810D /* id */, - 61AAE8650A321F0100D8810D /* is */, - 61AAE8680A321F0B00D8810D /* it */, - 61AAE86B0A321F2D00D8810D /* ja */, - 61AAE86E0A321F3500D8810D /* ko */, 61AAE8710A321F7700D8810D /* nl */, - 61AAE8740A321FA500D8810D /* no */, - 61AAE8770A321FBE00D8810D /* pl */, - 61AAE87A0A321FC400D8810D /* ru */, - 61AAE87D0A321FCD00D8810D /* sk */, - 61AAE8800A32201100D8810D /* sv */, - 61AAE8830A32202400D8810D /* th */, - 61AAE8860A32203000D8810D /* tr */, - 61AAE8890A32203800D8810D /* zh_CN */, - 61AAE88C0A32203F00D8810D /* zh_TW */, ); name = Sparkle.strings; sourceTree = ""; @@ -957,6 +922,9 @@ isa = PBXVariantGroup; children = ( 61AAE8250A321A7F00D8810D /* en */, + 61F3652B0E189883007ECA02 /* es */, + 61F365300E18988F007ECA02 /* fr */, + 61F365350E1898A3007ECA02 /* nl */, ); name = SUAutomaticUpdateAlert.nib; sourceTree = ""; @@ -965,6 +933,9 @@ isa = PBXVariantGroup; children = ( 61AAE8270A321A7F00D8810D /* en */, + 61F3652A0E189883007ECA02 /* es */, + 61F3652F0E18988F007ECA02 /* fr */, + 61F365340E1898A3007ECA02 /* nl */, ); name = SUUpdateAlert.nib; sourceTree = ""; @@ -989,6 +960,9 @@ isa = PBXVariantGroup; children = ( 61C46F350D9C54F300B06326 /* en */, + 61F3651A0E18987B007ECA02 /* es */, + 61F3652E0E18988F007ECA02 /* fr */, + 61F365330E1898A3007ECA02 /* nl */, ); name = SUUpdatePermissionPrompt.nib; sourceTree = ""; From 50de4d78e591e0ab340cc97db3bc11cf925ebbf8 Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Mon, 30 Jun 2008 20:44:58 -0700 Subject: [PATCH 03/22] Corrected a stupid commit of a test string. --- Test Application/Test Application-Info.plist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Test Application/Test Application-Info.plist b/Test Application/Test Application-Info.plist index 4845751e..8650c8a6 100644 --- a/Test Application/Test Application-Info.plist +++ b/Test Application/Test Application-Info.plist @@ -25,7 +25,7 @@ NSPrincipalClass NSApplication SUFeedURL - http://www.andymatuschfsfjak.org/files/sparkletestcast.xml + http://www.andymatuschak.org/files/sparkletestcast.xml SUEnableSystemProfiling From 3d7e8c6c9587fe5732ab7ee07168840db6bfeb3f Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Mon, 30 Jun 2008 20:45:54 -0700 Subject: [PATCH 04/22] Fixes 244214 Made Sparkle display sensible data and use an indeterminate progress bar when the server doesn't report an update's file size. --- SUStatus.nib/classes.nib | 10 +++++++++- SUStatus.nib/info.nib | 6 +++--- SUStatus.nib/keyedobjects.nib | Bin 7168 -> 7169 bytes SUStatusController.m | 3 ++- SUUIBasedUpdateDriver.m | 5 ++++- 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/SUStatus.nib/classes.nib b/SUStatus.nib/classes.nib index 3c6ae83f..22f13f8b 100644 --- a/SUStatus.nib/classes.nib +++ b/SUStatus.nib/classes.nib @@ -4,6 +4,14 @@ IBClasses + + CLASS + SUWindowController + LANGUAGE + ObjC + SUPERCLASS + NSWindowController + CLASS NSApplication @@ -39,7 +47,7 @@ NSProgressIndicator SUPERCLASS - NSWindowController + SUWindowController IBVersion diff --git a/SUStatus.nib/info.nib b/SUStatus.nib/info.nib index 4318cb1b..e4c18860 100644 --- a/SUStatus.nib/info.nib +++ b/SUStatus.nib/info.nib @@ -3,9 +3,9 @@ IBFramework Version - 629 + 667 IBLastKnownRelativeProjectPath - ../Sparkle.xcodeproj + Sparkle.xcodeproj IBOldestOS 5 IBOpenObjects @@ -13,7 +13,7 @@ 6 IBSystem Version - 9C31 + 9D34 targetFramework IBCocoaFramework diff --git a/SUStatus.nib/keyedobjects.nib b/SUStatus.nib/keyedobjects.nib index 4bdc9d6712559338935c65ef3ed2f41e5c8dc57f..ba1c0c3d2042ae541c950cbdb2592ce406dec5eb 100644 GIT binary patch delta 1621 zcmZuwc~DhV7(d^U6al$scR_{chPVQyqM3#!i3^|vh&u`@3J>Hx0R`kpZYbGur)9)3 zp~f<6)FC4y_bqeDeM6%$H76TGTeWF9Ji+|KJ9F+mGvEDw+xd=;SQ4?dJq&*rHb4bb z!e;mwK7mhRJA4MaVGrzuuiyxL4aea;T!4%4E!4qH_yKOg&rlC{;ZL{^4=~2fu$Mgz z`gFk>FTo}FWr)B_@iM#|t;8$vN?eLp;nlbdzk=7G6;<0HA6t|4G(AJ7Yp0&C-8!!- z!s`Pcp$ZB@dj*9S^$IEo>mOmZVWHvnJ^%WU3&4`d0C)?dvxA19%WTxcDuG7VkOm5r>DNx>4pvs4)yX zVHY})91|a#?M}~fx;&Dn>QuuvQ>WPh#NjxD{9zv&0{h_r97>9b?=vrLp-a!HfP;Eg z1svA1?Rlg}^P_OA5{}vBq;1cKMw)2K;S`E7L}%gLqeSMJgd_D_onik*`nUa`;4)l! z1bkIz+DWvVyk>0G!Hve=Y-1}*XW2C@@QK;qhBYV|?lk`G(uvwf=h$!1e)3mSsfIrq zE4ii;pcmLzsH5+bA-aN+Q8lW?45gy0s7{9&MFHk$inOoEAj&?(`^To5TA*iDn|G?I_?pRS zSOE?DCcF?`yvc)CXAo0St-%Y#%!3%^`O{$#u`aSli%|Qj7}(m(OWXq2oSx6?E1%W`H9Z{kPV5JH|JEr=w(#6bc`D?&+2(uuU=|2};FCV`}5)oc~jtoU~e ztd3T&)yo=cMOibgOe@cN%X-IJYpt`^TN|uOYm2qrs<94ON3HJ(BA9rQ=ER%$7@iOk zPDYSfq>wBonv{^GWI0($R*?#_g&ZR%$VqaVoF(VUMRJ!mqg`kp8cM_IGqgXApo8dO znn0%%)44QVg)iVFG{QG<7QTgx@I73DcK8vlz;*Z)Zo)0N4gbJ> zc%Xx>>z-yNj1JK%b*V4cSLiGCRr>4tYJH7f2~ql5y-Hi7uhXmbH}v&&`(TM~ERc(& zP3B9xES64LUKjP)j)9a{RD_3F!k2|vD#k`csn5tr^Uk1K(Jk5_Z5FJBDlJV*hfS~! zs1P{&Q>O}WRCe49&bh<>ieJcm+)1u zR&9=avn1g7Ld5th$53R~i zTX!{E7An;O(;J1ldt-yHJM_f1L7T2Re(CO*BWI~O#L1#e#7a98nqcV@*bjZe@8Y-t z8?-C%XE%dGF(k;6OoY4p9nLJL%VAa%V@$7yJ}KUSyQ=?hxYx^2su*0d%$!dx30>pq zfQLO9>6%=kMwRGDw&nki9lgJ@b6FqIO;(}o1j$#;7BnjCyfPoFd+R>Zy;D1=wJ8|Z zabY}jBmixih*v1Ovm>9iMGhIgGK%q%`EwMRBpo2(_NE4`$or)Vk4 z#xyn9L~VvLlcAP0S()y#Q!YK_0%fUKSxQw;&PzSMeCeki-ZHghv!%_v%(F-KM_$MS zd7@wxhz1~x5b{I*h$9~qL?3qjI*>OCKtt*li-dmeyM|^wVT2l^j96omvCzmjN{zRT zcZ^NO`^IKti&10jG3t#5JceSWig7UVRm|g144Q({Q6|blIcO2Gp**w- zZ9wm$&1g3|hpwUP=r?o&{efgjeAP*_fezZUJpq?~ 0) + [statusController setStatusText:[NSString stringWithFormat:SULocalizedString(@"%@ of %@", nil), [NSNumber humanReadableSizeFromDouble:[statusController progressValue]], [NSNumber humanReadableSizeFromDouble:[statusController maxProgressValue]]]]; + else + [statusController setStatusText:[NSString stringWithFormat:SULocalizedString(@"%@ downloaded", nil), [NSNumber humanReadableSizeFromDouble:[statusController progressValue]]]]; } - (IBAction)cancelDownload:sender From 4ffb7ea64a3a8e6b54621f41fae2ae460c24f51c Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Mon, 30 Jun 2008 20:48:14 -0700 Subject: [PATCH 05/22] Added a new string to localize for the case of an unreported download size. --- en.lproj/Sparkle.strings | Bin 8102 -> 8252 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/en.lproj/Sparkle.strings b/en.lproj/Sparkle.strings index 6f7d5648fb283cce475968e4066d823edeb42da5..804915b3cf1335f95820be2d39d23d438d686e70 100644 GIT binary patch delta 46 zcmZ2xzsF%i3;X00HUYs@h7<-R1_cINAXZ{fWpJ3B$R^AT6rHTd7rD8PT|)u@4~Ght delta 12 Tcmdnvu*`l#3;Sj%4kZZyA@Bq& From 74337fb65aac99df8a793c7ea9a8711f54bc43cd Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Mon, 30 Jun 2008 20:55:29 -0700 Subject: [PATCH 06/22] Fixed 243883: Removed the last @try/@catch from my code. Thanks to Christiaan Hofman for the patch. --- SUAppcast.h | 1 + SUAppcast.m | 49 ++++++++++++++++++++++++-------------- SUAppcastItem.m | 62 +++++++++++++++++++++++++++---------------------- 3 files changed, 66 insertions(+), 46 deletions(-) diff --git a/SUAppcast.h b/SUAppcast.h index 624f3f21..6d0a1be9 100644 --- a/SUAppcast.h +++ b/SUAppcast.h @@ -14,6 +14,7 @@ NSArray *items; NSString *userAgentString; id delegate; + RSS *feed; } - (void)fetchAppcastFromURL:(NSURL *)url; diff --git a/SUAppcast.m b/SUAppcast.m index b0d454b5..fcacfe9b 100644 --- a/SUAppcast.m +++ b/SUAppcast.m @@ -17,6 +17,7 @@ - (void)dealloc { + [feed release]; [items release]; [super dealloc]; } @@ -28,36 +29,48 @@ - (void)fetchAppcastFromURL:(NSURL *)url { - RSS *feed = [[RSS alloc] initWithURL:url userAgent:userAgentString delegate:self]; - CFRetain(feed); // Manage the RSS feed's memory manually. + feed = [[RSS alloc] initWithURL:url userAgent:userAgentString delegate:self]; } -- (void)feedDidFinishLoading:(RSS *)feed +- (void)feedDidFinishLoading:(RSS *)aFeed { // Set up all the appcast items: NSArray *tempItems = [NSMutableArray array]; id enumerator = [[feed newsItems] objectEnumerator], current; - @try + BOOL success = YES; + while ((current = [enumerator nextObject])) + { + SUAppcastItem *item = [[[SUAppcastItem alloc] initWithDictionary:current] autorelease]; + if (item) + { + [(NSMutableArray *)tempItems addObject:item]; + } + else + { + success = NO; + break; + } + } + if (success) { - while ((current = [enumerator nextObject])) - { - [(NSMutableArray *)tempItems addObject:[[[SUAppcastItem alloc] initWithDictionary:current] autorelease]]; - } - items = [[NSArray arrayWithArray:tempItems] retain]; // Make the items list immutable. - - if ([delegate respondsToSelector:@selector(appcastDidFinishLoading:)]) - [delegate performSelectorOnMainThread:@selector(appcastDidFinishLoading:) withObject:self waitUntilDone:NO]; + items = [tempItems copy]; // Make the items list immutable. + + if ([delegate respondsToSelector:@selector(appcastDidFinishLoading:)]) + [delegate performSelectorOnMainThread:@selector(appcastDidFinishLoading:) withObject:self waitUntilDone:NO]; + } + else + { + [self reportError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUAppcastParseError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:SULocalizedString(@"An error occurred while parsing the update feed.", nil), NSLocalizedDescriptionKey, nil]]]; } - @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]]]; - } - CFRelease(feed); + [feed release]; + feed = nil; } -- (void)feed:(RSS *)feed didFailWithError:(NSError *)error +- (void)feed:(RSS *)aFeed didFailWithError:(NSError *)error { [self reportError:error]; + [feed release]; + feed = nil; } - (void)reportError:(NSError *)error diff --git a/SUAppcastItem.m b/SUAppcastItem.m index 28efc7c7..2bfc8011 100644 --- a/SUAppcastItem.m +++ b/SUAppcastItem.m @@ -106,16 +106,7 @@ 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,32 +117,47 @@ // 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) // no sparkle:version attribute { // 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"]]; - - NSString *shortVersionString = [enclosure objectForKey:@"sparkle:shortVersionString"]; - if (shortVersionString) - [self setDisplayVersionString:shortVersionString]; - else - [self setDisplayVersionString:[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]]]; - else - [self setReleaseNotesURL:nil]; + + if (enclosure == nil || [enclosure objectForKey:@"url"] == nil || newVersion == nil) + { + [self release]; + self = nil; + } + else + { + propertiesDictionary = [dict retain]; + [self setTitle:[dict objectForKey:@"title"]]; + [self setDate:[dict objectForKey:@"pubDate"]]; + [self setDescription:[dict objectForKey:@"description"]]; + + [self setFileURL:[NSURL URLWithString:[[enclosure objectForKey:@"url"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]; + [self setDSASignature:[enclosure objectForKey:@"sparkle:dsaSignature"]]; + + [self setVersionString:newVersion]; + [self setMinimumSystemVersion:[dict objectForKey:@"sparkle:minimumSystemVersion"]]; + + NSString *shortVersionString = [enclosure objectForKey:@"sparkle:shortVersionString"]; + if (shortVersionString) + [self setDisplayVersionString:shortVersionString]; + else + [self setDisplayVersionString:[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]]]; + else + [self setReleaseNotesURL:nil]; + } } return self; } From b2145b6838b8424046d479fb5b4a1466f1b14610 Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Mon, 30 Jun 2008 21:21:48 -0700 Subject: [PATCH 07/22] Killed NSURL+Parameters and moved the relevant code into SUUpdater. --- NSURL+Parameters.h | 18 ------------- NSURL+Parameters.m | 27 ------------------- SUUpdater.m | 43 ++++++++++++++++++++++--------- Sparkle.h | 1 - Sparkle.xcodeproj/project.pbxproj | 8 ------ 5 files changed, 31 insertions(+), 66 deletions(-) delete mode 100644 NSURL+Parameters.h delete mode 100644 NSURL+Parameters.m diff --git a/NSURL+Parameters.h b/NSURL+Parameters.h deleted file mode 100644 index 40b2f9e8..00000000 --- a/NSURL+Parameters.h +++ /dev/null @@ -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 - -@interface NSURL (SUParameterAdditions) -- (NSURL *)URLWithParameters:(NSArray *)parameters; -@end - -#endif diff --git a/NSURL+Parameters.m b/NSURL+Parameters.m deleted file mode 100644 index 7f9ed958..00000000 --- a/NSURL+Parameters.m +++ /dev/null @@ -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 diff --git a/SUUpdater.m b/SUUpdater.m index c75493c9..0468ed79 100644 --- a/SUUpdater.m +++ b/SUUpdater.m @@ -15,6 +15,7 @@ - (BOOL)shouldScheduleUpdateCheck; - (void)scheduleNextUpdateCheck; - (NSTimeInterval)checkInterval; +- (NSURL *)feedURL; @end @implementation SUUpdater @@ -129,19 +130,10 @@ static SUUpdater *sharedUpdater = nil; if ([self updateInProgress]) { return; } @synchronized (checkTimer) { if (checkTimer) { [checkTimer invalidate]; checkTimer = nil; } } - // A value in the user defaults overrides one in the Info.plist (so preferences panels can be created wherein users choose between beta / release feeds). - NSString *appcastString = [[SUUserDefaults standardUserDefaults] objectForKey:SUFeedURLKey]; - if (!appcastString) - appcastString = [hostBundle objectForInfoDictionaryKey:SUFeedURLKey]; - if (!appcastString) - [NSException raise:@"SUNoFeedURL" format:@"You must specify the URL of the appcast as the SUFeedURLKey in either the Info.plist or the user defaults!"]; - NSCharacterSet* quoteSet = [NSCharacterSet characterSetWithCharactersInString: @"\"\'"]; // Some feed publishers add quotes; strip 'em. - NSURL *feedURL = [[NSURL URLWithString:[appcastString stringByTrimmingCharactersInSet:quoteSet]] URLWithParameters:[self feedParameters]]; - driver = [d retain]; if ([driver delegate] == nil) { [driver setDelegate:delegate]; } [driver addObserver:self forKeyPath:@"finished" options:0 context:NULL]; - [driver checkForUpdatesAtURL:feedURL hostBundle:hostBundle]; + [driver checkForUpdatesAtURL:[self feedURL] hostBundle:hostBundle]; } - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context @@ -198,15 +190,42 @@ static SUUpdater *sharedUpdater = nil; return YES; // Otherwise, we're good to go. } -- (NSArray *)feedParameters +- (NSURL *)_baseFeedURL { + // A value in the user defaults overrides one in the Info.plist (so preferences panels can be created wherein users choose between beta / release feeds). + NSString *appcastString = [[SUUserDefaults standardUserDefaults] objectForKey:SUFeedURLKey]; + if (!appcastString) + appcastString = [hostBundle objectForInfoDictionaryKey:SUFeedURLKey]; + if (!appcastString) // Can't find an appcast string! + [NSException raise:@"SUNoFeedURL" format:@"You must specify the URL of the appcast as the SUFeedURLKey in either the Info.plist or the user defaults!"]; + NSCharacterSet* quoteSet = [NSCharacterSet characterSetWithCharactersInString: @"\"\'"]; // Some feed publishers add quotes; strip 'em. + return [NSURL URLWithString:[appcastString stringByTrimmingCharactersInSet:quoteSet]] ; +} + +- (NSURL *)feedURL +{ + NSURL *baseFeedURL = [self _baseFeedURL]; + + // Determine all the parameters we're attaching to the base feed URL. BOOL sendingSystemProfile = ([[SUUserDefaults standardUserDefaults] boolForKey:SUSendProfileInfoKey] == YES); NSArray *parameters = [NSArray array]; if ([delegate respondsToSelector:@selector(feedParametersForHostBundle:sendingSystemProfile:)]) parameters = [parameters arrayByAddingObjectsFromArray:[delegate feedParametersForHostBundle:hostBundle sendingSystemProfile:sendingSystemProfile]]; if (sendingSystemProfile) parameters = [parameters arrayByAddingObjectsFromArray:[hostBundle systemProfile]]; - return parameters; + if (parameters == nil || [parameters count] == 0) { return baseFeedURL; } + + // Build up the parameterized URL. + NSMutableArray *parameterStrings = [NSMutableArray array]; + NSEnumerator *profileInfoEnumerator = [parameters objectEnumerator]; + NSDictionary *currentProfileInfo; + while ((currentProfileInfo = [profileInfoEnumerator nextObject])) + [parameterStrings addObject:[NSString stringWithFormat:@"%@=%@", [currentProfileInfo objectForKey:@"key"], [currentProfileInfo objectForKey:@"value"]]]; + + NSString *appcastStringWithProfile = [NSString stringWithFormat:@"%@?%@", [baseFeedURL absoluteString], [parameterStrings componentsJoinedByString:@"&"]]; + + // Clean it up so it's a valid URL + return [NSURL URLWithString:[appcastStringWithProfile stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; } - (NSTimeInterval)checkInterval diff --git a/Sparkle.h b/Sparkle.h index cd6013b4..33bd3aa8 100644 --- a/Sparkle.h +++ b/Sparkle.h @@ -30,7 +30,6 @@ #import "NSFileManager+Authentication.h" #import "NSFileManager+Verification.h" #import "NSString+extras.h" -#import "NSURL+Parameters.h" #import "NSWorkspace_RBAdditions.h" #import "NSWorkspace+SystemVersion.h" diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 6ec51f2a..3e33ac22 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -90,8 +90,6 @@ 61B5FCDF09C52A9F00B25A18 /* SUUpdateAlert.h in Headers */ = {isa = PBXBuildFile; fileRef = 61B5FCA009C5228F00B25A18 /* SUUpdateAlert.h */; settings = {ATTRIBUTES = (Public, ); }; }; 61B93A3C0DD02D7000DCD2F8 /* SUUIBasedUpdateDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 61B93A390DD02D6400DCD2F8 /* SUUIBasedUpdateDriver.h */; settings = {ATTRIBUTES = (Public, ); }; }; 61B93A3D0DD02D7000DCD2F8 /* SUUIBasedUpdateDriver.m in Sources */ = {isa = PBXBuildFile; fileRef = 61B93A3A0DD02D6400DCD2F8 /* SUUIBasedUpdateDriver.m */; }; - 61B93AA20DD0E2D300DCD2F8 /* NSURL+Parameters.h in Headers */ = {isa = PBXBuildFile; fileRef = 61B93AA00DD0E2D300DCD2F8 /* NSURL+Parameters.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 61B93AA30DD0E2D300DCD2F8 /* NSURL+Parameters.m in Sources */ = {isa = PBXBuildFile; fileRef = 61B93AA10DD0E2D300DCD2F8 /* NSURL+Parameters.m */; }; 61B93B270DD0FDD300DCD2F8 /* SUAutomaticUpdateDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 61B93B250DD0FDD300DCD2F8 /* SUAutomaticUpdateDriver.h */; settings = {ATTRIBUTES = (Public, ); }; }; 61B93B280DD0FDD300DCD2F8 /* SUAutomaticUpdateDriver.m in Sources */ = {isa = PBXBuildFile; fileRef = 61B93B260DD0FDD300DCD2F8 /* SUAutomaticUpdateDriver.m */; }; 61B93C090DD112FF00DCD2F8 /* SUScheduledUpdateDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 61B93C070DD112FF00DCD2F8 /* SUScheduledUpdateDriver.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -249,8 +247,6 @@ 61B5FCA109C5228F00B25A18 /* SUUpdateAlert.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUUpdateAlert.m; sourceTree = ""; }; 61B93A390DD02D6400DCD2F8 /* SUUIBasedUpdateDriver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUUIBasedUpdateDriver.h; sourceTree = ""; }; 61B93A3A0DD02D6400DCD2F8 /* SUUIBasedUpdateDriver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUUIBasedUpdateDriver.m; sourceTree = ""; }; - 61B93AA00DD0E2D300DCD2F8 /* NSURL+Parameters.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSURL+Parameters.h"; sourceTree = ""; }; - 61B93AA10DD0E2D300DCD2F8 /* NSURL+Parameters.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSURL+Parameters.m"; sourceTree = ""; }; 61B93B250DD0FDD300DCD2F8 /* SUAutomaticUpdateDriver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUAutomaticUpdateDriver.h; sourceTree = ""; }; 61B93B260DD0FDD300DCD2F8 /* SUAutomaticUpdateDriver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUAutomaticUpdateDriver.m; sourceTree = ""; }; 61B93C070DD112FF00DCD2F8 /* SUScheduledUpdateDriver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUScheduledUpdateDriver.h; sourceTree = ""; }; @@ -447,8 +443,6 @@ 61B5F8E209C4CE3C00B25A18 /* RSS.m */, 61B5F8DF09C4CE3C00B25A18 /* NSString+extras.h */, 61B5F8E009C4CE3C00B25A18 /* NSString+extras.m */, - 61B93AA00DD0E2D300DCD2F8 /* NSURL+Parameters.h */, - 61B93AA10DD0E2D300DCD2F8 /* NSURL+Parameters.m */, ); name = "Appcast Support"; sourceTree = ""; @@ -596,7 +590,6 @@ 618FA5220DAE8E8A0026945C /* SUPackageInstaller.h in Headers */, 61F83F740DBFE141006FDD30 /* SUBasicUpdateDriver.h in Headers */, 61B93A3C0DD02D7000DCD2F8 /* SUUIBasedUpdateDriver.h in Headers */, - 61B93AA20DD0E2D300DCD2F8 /* NSURL+Parameters.h in Headers */, 61B93B270DD0FDD300DCD2F8 /* SUAutomaticUpdateDriver.h in Headers */, 61B93C090DD112FF00DCD2F8 /* SUScheduledUpdateDriver.h in Headers */, 610134730DD250470049ACDF /* SUUpdateDriver.h in Headers */, @@ -859,7 +852,6 @@ 618FA5230DAE8E8A0026945C /* SUPackageInstaller.m in Sources */, 61F83F720DBFE140006FDD30 /* SUBasicUpdateDriver.m in Sources */, 61B93A3D0DD02D7000DCD2F8 /* SUUIBasedUpdateDriver.m in Sources */, - 61B93AA30DD0E2D300DCD2F8 /* NSURL+Parameters.m in Sources */, 61B93B280DD0FDD300DCD2F8 /* SUAutomaticUpdateDriver.m in Sources */, 61B93C0A0DD112FF00DCD2F8 /* SUScheduledUpdateDriver.m in Sources */, 610134740DD250470049ACDF /* SUUpdateDriver.m in Sources */, From bc52c0141abcc432fe8cf20452f016e1f7b79220 Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Mon, 30 Jun 2008 21:47:38 -0700 Subject: [PATCH 08/22] Made SUUpdateDriver use notifications instead of KVO to let SUUpdater know it's done. --- SUUpdateDriver.h | 2 ++ SUUpdateDriver.m | 2 ++ SUUpdater.m | 19 +++++++++++-------- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/SUUpdateDriver.h b/SUUpdateDriver.h index f0c4413d..face46e4 100644 --- a/SUUpdateDriver.h +++ b/SUUpdateDriver.h @@ -11,6 +11,8 @@ #import +extern NSString *SUUpdateDriverFinishedNotification; + @interface SUUpdateDriver : NSObject { BOOL finished; diff --git a/SUUpdateDriver.m b/SUUpdateDriver.m index a9978ec7..81e5ce9e 100644 --- a/SUUpdateDriver.m +++ b/SUUpdateDriver.m @@ -8,6 +8,7 @@ #import "SUUpdateDriver.h" +NSString *SUUpdateDriverFinishedNotification = @"SUUpdateDriverFinished"; @implementation SUUpdateDriver - (void)checkForUpdatesAtURL:(NSURL *)appcastURL hostBundle:(NSBundle *)hb @@ -18,6 +19,7 @@ - (void)abortUpdate { [self setValue:[NSNumber numberWithBool:YES] forKey:@"finished"]; + [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdateDriverFinishedNotification object:self]; } - (BOOL)finished { return finished; } diff --git a/SUUpdater.m b/SUUpdater.m index 0468ed79..fd1be205 100644 --- a/SUUpdater.m +++ b/SUUpdater.m @@ -46,6 +46,7 @@ static SUUpdater *sharedUpdater = nil; sharedUpdater = self; [self setHostBundle:[NSBundle mainBundle]]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidFinishLaunching:) name:NSApplicationDidFinishLaunchingNotification object:NSApp]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(driverDidFinish:) name:SUUpdateDriverFinishedNotification object:nil]; [[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[@"values." stringByAppendingString:SUScheduledCheckIntervalKey] options:0 context:NULL]; [[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[@"values." stringByAppendingString:SUEnableAutomaticChecksKey] options:0 context:NULL]; } @@ -132,19 +133,12 @@ static SUUpdater *sharedUpdater = nil; driver = [d retain]; if ([driver delegate] == nil) { [driver setDelegate:delegate]; } - [driver addObserver:self forKeyPath:@"finished" options:0 context:NULL]; [driver checkForUpdatesAtURL:[self feedURL] hostBundle:hostBundle]; } - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { - if (object == driver && [keyPath isEqualToString:@"finished"]) - { - [driver removeObserver:self forKeyPath:@"finished"]; - [driver release]; driver = nil; - [self scheduleNextUpdateCheck]; - } - else if (object == [NSUserDefaultsController sharedUserDefaultsController] && ([keyPath hasSuffix:SUScheduledCheckIntervalKey] || [keyPath hasSuffix:SUEnableAutomaticChecksKey])) + if (object == [NSUserDefaultsController sharedUserDefaultsController] && ([keyPath hasSuffix:SUScheduledCheckIntervalKey] || [keyPath hasSuffix:SUEnableAutomaticChecksKey])) { [self updatePreferencesChanged]; } @@ -247,6 +241,7 @@ static SUUpdater *sharedUpdater = nil; [hostBundle release]; [delegate release]; if (checkTimer) { [checkTimer invalidate]; } + [[NSNotificationCenter defaultCenter] removeObserver:self]; [super dealloc]; } @@ -275,4 +270,12 @@ static SUUpdater *sharedUpdater = nil; return driver && ([driver finished] == NO); } +- (void)driverDidFinish:(NSNotification *)notification +{ + if ([notification object] != driver) return; + [driver release]; + driver = nil; + [self scheduleNextUpdateCheck]; +} + @end From c9bdb6ef04d19194ad49523daa87cfc207d70749 Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Mon, 30 Jun 2008 21:53:15 -0700 Subject: [PATCH 09/22] Tiny refactoring --- SUUpdater.m | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/SUUpdater.m b/SUUpdater.m index fd1be205..d8fb63e5 100644 --- a/SUUpdater.m +++ b/SUUpdater.m @@ -85,8 +85,7 @@ static SUUpdater *sharedUpdater = nil; - (void)updatePermissionPromptFinishedWithResult:(SUPermissionPromptResult)result { - BOOL automaticallyCheck = (result == SUAutomaticallyCheck); - [[SUUserDefaults standardUserDefaults] setBool:automaticallyCheck forKey:SUEnableAutomaticChecksKey]; + [[SUUserDefaults standardUserDefaults] setBool:(result == SUAutomaticallyCheck) forKey:SUEnableAutomaticChecksKey]; [self scheduleNextUpdateCheck]; } From 4b6fc55056945b896f88657336d7b01dbc8a418a Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Mon, 30 Jun 2008 21:55:15 -0700 Subject: [PATCH 10/22] Removed unnecessary @synchronized's. --- SUUpdater.m | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/SUUpdater.m b/SUUpdater.m index d8fb63e5..b490047f 100644 --- a/SUUpdater.m +++ b/SUUpdater.m @@ -91,13 +91,10 @@ static SUUpdater *sharedUpdater = nil; - (void)scheduleNextUpdateCheck { - @synchronized (checkTimer) + if (checkTimer) { - if (checkTimer) - { - [checkTimer invalidate]; - checkTimer = nil; - } + [checkTimer invalidate]; + checkTimer = nil; } if (![self shouldScheduleUpdateCheck]) return; @@ -128,7 +125,7 @@ static SUUpdater *sharedUpdater = nil; - (void)checkForUpdatesWithDriver:(SUUpdateDriver *)d { if ([self updateInProgress]) { return; } - @synchronized (checkTimer) { if (checkTimer) { [checkTimer invalidate]; checkTimer = nil; } } + if (checkTimer) { [checkTimer invalidate]; checkTimer = nil; } driver = [d retain]; if ([driver delegate] == nil) { [driver setDelegate:delegate]; } From 9a266ca52e8e2800b0f301b375841f4d7c2746cb Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Mon, 30 Jun 2008 22:00:47 -0700 Subject: [PATCH 11/22] Added checkForUpdatesInBackground back to SUUpdater.h --- SUUpdater.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/SUUpdater.h b/SUUpdater.h index 645d25a6..aed4ae15 100644 --- a/SUUpdater.h +++ b/SUUpdater.h @@ -28,6 +28,11 @@ // and Sparkle will check for updates and report back its findings verbosely. - (IBAction)checkForUpdates:sender; +// This kicks off an update meant to be programmatically initiated. That is, it will display no UI unless it actually finds an update, +// in which case it proceeds as usual. If the fully automated updating is turned on, however, this will invoke that behavior, and if an +// update is found, it will be downloaded and prepped for installation. +- (void)checkForUpdatesInBackground; + // This forces an update to begin with a particular driver (see SU*UpdateDriver.h) - (void)checkForUpdatesWithDriver:(SUUpdateDriver *)driver; From 0a4bc6576a678b6c86e8112039a43209672b2dea Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Mon, 30 Jun 2008 22:19:07 -0700 Subject: [PATCH 12/22] No longer leaking the NSURLDownload of the update archive. If the update's aborted mid-download through programmatic means, the download will now be canceled. --- SUBasicUpdateDriver.m | 3 +++ 1 file changed, 3 insertions(+) diff --git a/SUBasicUpdateDriver.m b/SUBasicUpdateDriver.m index 733aa021..36c1477f 100644 --- a/SUBasicUpdateDriver.m +++ b/SUBasicUpdateDriver.m @@ -268,12 +268,15 @@ NSLog(@"Sparkle Error: %@", [error localizedDescription]); if ([error localizedFailureReason]) NSLog(@"Sparkle Error (continued): %@", [error localizedFailureReason]); + if (download) + [download cancel]; [self abortUpdate]; } - (void)dealloc { [hostBundle release]; + [download release]; [downloadPath release]; [relaunchPath release]; [super dealloc]; From cbaa635a893e95932ba62e0cb2af4df61bce7fd9 Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Mon, 30 Jun 2008 23:18:45 -0700 Subject: [PATCH 13/22] Fixed a crash that could occur when an appcast failed to parse due to a double-release. --- SUAppcast.m | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/SUAppcast.m b/SUAppcast.m index fcacfe9b..4aab159c 100644 --- a/SUAppcast.m +++ b/SUAppcast.m @@ -40,10 +40,10 @@ BOOL success = YES; while ((current = [enumerator nextObject])) { - SUAppcastItem *item = [[[SUAppcastItem alloc] initWithDictionary:current] autorelease]; + SUAppcastItem *item = [[SUAppcastItem alloc] initWithDictionary:current]; if (item) { - [(NSMutableArray *)tempItems addObject:item]; + [(NSMutableArray *)tempItems addObject:[item autorelease]]; } else { @@ -51,6 +51,8 @@ break; } } + [feed release]; + feed = nil; if (success) { items = [tempItems copy]; // Make the items list immutable. @@ -62,8 +64,6 @@ { [self reportError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUAppcastParseError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:SULocalizedString(@"An error occurred while parsing the update feed.", nil), NSLocalizedDescriptionKey, nil]]]; } - [feed release]; - feed = nil; } - (void)feed:(RSS *)aFeed didFailWithError:(NSError *)error From 251706d646e37d2e68104eec9dfece51963fd36a Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Mon, 30 Jun 2008 23:21:51 -0700 Subject: [PATCH 14/22] Fixed a serious bug which could cause a server to DDoS'd in the case of appcast parse failure. Sparkle now sets the "last checked at" time when it makes the appcast request instead of on successful receipt of an appcast. --- SUBasicUpdateDriver.m | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/SUBasicUpdateDriver.m b/SUBasicUpdateDriver.m index 36c1477f..1bfbaad2 100644 --- a/SUBasicUpdateDriver.m +++ b/SUBasicUpdateDriver.m @@ -28,6 +28,7 @@ [appcast setDelegate:self]; [appcast setUserAgentString:[NSString stringWithFormat: @"%@/%@ Sparkle/1.5b2", [hostBundle name], [hostBundle displayVersion]]]; [appcast fetchAppcastFromURL:appcastURL]; + [[SUUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:SULastCheckTimeKey]; } - (BOOL)isItemNewer:(SUAppcastItem *)ui @@ -60,11 +61,7 @@ { 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]; - + // 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? { @@ -73,7 +70,7 @@ 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]); From a67b546a02af731e8fbf7e7f5db7dc1c716c1b86 Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Wed, 2 Jul 2008 20:05:29 -0700 Subject: [PATCH 15/22] Fixes 244726 Fixed a typo in a respondsToSelector call which caused the shouldPromptForPermissionToCheckForUpdatesToHostBundle: method not to work in 1.5b2. --- SUUpdater.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SUUpdater.m b/SUUpdater.m index b490047f..17077ea6 100644 --- a/SUUpdater.m +++ b/SUUpdater.m @@ -60,7 +60,7 @@ static SUUpdater *sharedUpdater = nil; [[SUUserDefaults standardUserDefaults] boolForKey:SUEnableAutomaticChecksKey] == NO) { return; } // Does the delegate want to take care of the logic for when we should ask permission to update? - if ([delegate respondsToSelector:@selector(shouldPromptForPermissionToCheckForUpdatesToHostBundle)]) + if ([delegate respondsToSelector:@selector(shouldPromptForPermissionToCheckForUpdatesToHostBundle:)]) { if ([delegate shouldPromptForPermissionToCheckForUpdatesToHostBundle:hostBundle]) [SUUpdatePermissionPrompt promptWithHostBundle:hostBundle delegate:self]; From 82c2448321b9a490b6af958a7ceeb1108bd74770 Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Wed, 2 Jul 2008 20:31:18 -0700 Subject: [PATCH 16/22] Fixes 244419 Now removing the RSS class and and NSString+extras to be replaced by a much simpler implementation based on NSXMLDocument directly in SUAppcast! But this will probably break things for certain edge-case appcasts, so please file bugs if things no longer work for you. Thanks to Christiaan Hofman for the patch! --- NSString+extras.h | 66 --- NSString+extras.m | 136 ------ RSS.h | 77 ---- RSS.m | 727 ------------------------------ SUAppcast.h | 2 +- SUAppcast.m | 144 ++++-- Sparkle.h | 3 - Sparkle.xcodeproj/project.pbxproj | 16 - 8 files changed, 114 insertions(+), 1057 deletions(-) delete mode 100644 NSString+extras.h delete mode 100644 NSString+extras.m delete mode 100644 RSS.h delete mode 100644 RSS.m diff --git a/NSString+extras.h b/NSString+extras.h deleted file mode 100644 index 2f53af65..00000000 --- a/NSString+extras.h +++ /dev/null @@ -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 -#import -#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 diff --git a/NSString+extras.m b/NSString+extras.m deleted file mode 100644 index e20718e8..00000000 --- a/NSString+extras.m +++ /dev/null @@ -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 diff --git a/RSS.h b/RSS.h deleted file mode 100644 index 38978b2b..00000000 --- a/RSS.h +++ /dev/null @@ -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 -#import -#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 diff --git a/RSS.m b/RSS.m deleted file mode 100644 index 2920e9c1..00000000 --- a/RSS.m +++ /dev/null @@ -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 diff --git a/SUAppcast.h b/SUAppcast.h index 6d0a1be9..57874c0d 100644 --- a/SUAppcast.h +++ b/SUAppcast.h @@ -14,7 +14,7 @@ NSArray *items; NSString *userAgentString; id delegate; - RSS *feed; + NSMutableData *incrementalData; } - (void)fetchAppcastFromURL:(NSURL *)url; diff --git a/SUAppcast.m b/SUAppcast.m index 4aab159c..3ddb8594 100644 --- a/SUAppcast.m +++ b/SUAppcast.m @@ -17,7 +17,6 @@ - (void)dealloc { - [feed release]; [items release]; [super dealloc]; } @@ -29,48 +28,131 @@ - (void)fetchAppcastFromURL:(NSURL *)url { - feed = [[RSS alloc] initWithURL:url userAgent:userAgentString delegate:self]; + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30.0]; + if (userAgentString) + [request setValue:userAgentString forHTTPHeaderField:@"User-Agent"]; + + incrementalData = [[NSMutableData alloc] init]; + NSURLConnection *connection = [NSURLConnection connectionWithRequest:request delegate:self]; + CFRetain(connection); } -- (void)feedDidFinishLoading:(RSS *)aFeed +- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { - // Set up all the appcast items: - NSArray *tempItems = [NSMutableArray array]; - id enumerator = [[feed newsItems] objectEnumerator], current; - BOOL success = YES; - while ((current = [enumerator nextObject])) + [incrementalData appendData:data]; +} + +- (void)connectionDidFinishLoading:(NSURLConnection *)connection +{ + CFRelease(connection); + + NSError *error = nil; + NSXMLDocument *document = [[NSXMLDocument alloc] initWithData:incrementalData options:0 error:&error]; + BOOL failed = NO; + NSArray *xmlItems = nil; + NSMutableArray *appcastItems = [NSMutableArray array]; + + if (nil == document) { - SUAppcastItem *item = [[SUAppcastItem alloc] initWithDictionary:current]; - if (item) - { - [(NSMutableArray *)tempItems addObject:[item autorelease]]; - } - else - { - success = NO; - break; - } - } - [feed release]; - feed = nil; - if (success) - { - items = [tempItems copy]; // Make the items list immutable. - - if ([delegate respondsToSelector:@selector(appcastDidFinishLoading:)]) - [delegate performSelectorOnMainThread:@selector(appcastDidFinishLoading:) withObject:self waitUntilDone:NO]; + failed = YES; } else { - [self reportError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUAppcastParseError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:SULocalizedString(@"An error occurred while parsing the update feed.", nil), NSLocalizedDescriptionKey, nil]]]; + xmlItems = [document nodesForXPath:@"/rss/channel/item" error:&error]; + if (nil == xmlItems) + { + failed = YES; + } + } + + if (failed == NO) + { + + NSEnumerator *nodeEnum = [xmlItems objectEnumerator]; + NSXMLNode *node; + NSMutableDictionary *dict = [NSMutableDictionary dictionary]; + + while (failed == NO && (node = [nodeEnum nextObject])) + { + // walk the children in reverse + node = [[node children] lastObject]; + while (nil != node) + { + + NSString *name = [node name]; + + if ([name isEqualToString:@"enclosure"]) { + // enclosure is flattened as a separate dictionary for some reason + NSEnumerator *attributeEnum = [[(NSXMLElement *)node attributes] objectEnumerator]; + NSXMLNode *attribute; + NSMutableDictionary *encDict = [NSMutableDictionary dictionary]; + + while ((attribute = [attributeEnum nextObject])) + { + [encDict setObject:[attribute stringValue] forKey:[attribute name]]; + } + [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 + { + // add all other values as strings + [dict setObject:[[node stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] forKey:name]; + } + + // previous sibling; returns nil when exhausted + node = [node previousSibling]; + } + SUAppcastItem *anItem = [[SUAppcastItem alloc] initWithDictionary:dict]; + if (anItem) + { + [appcastItems addObject:anItem]; + [anItem release]; + } + else + { + failed = YES; + } + [dict removeAllObjects]; + } + } + + [document release]; + + if ([appcastItems count]) + { + NSSortDescriptor *sort = [[[NSSortDescriptor alloc] initWithKey:@"date" ascending:NO] autorelease]; + [appcastItems sortUsingDescriptors:[NSArray arrayWithObject:sort]]; + items = [appcastItems copy]; + } + + 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]; } } -- (void)feed:(RSS *)aFeed didFailWithError:(NSError *)error +- (void)connection:(NSURLConnection*)connection didFailWithError:(NSError *)error { + CFRelease(connection); + [self reportError:error]; - [feed release]; - feed = nil; +} + +- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse +{ + return request; } - (void)reportError:(NSError *)error diff --git a/Sparkle.h b/Sparkle.h index 33bd3aa8..db304b09 100644 --- a/Sparkle.h +++ b/Sparkle.h @@ -29,14 +29,11 @@ #import "NSFileManager+Aliases.h" #import "NSFileManager+Authentication.h" #import "NSFileManager+Verification.h" -#import "NSString+extras.h" #import "NSWorkspace_RBAdditions.h" #import "NSWorkspace+SystemVersion.h" #import "NTSynchronousTask.h" -#import "RSS.h" - #import "SUAppcast.h" #import "SUAppcastItem.h" #import "SUAutomaticUpdateAlert.h" diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 3e33ac22..0bacf07e 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -69,10 +69,6 @@ 61AAE8280A321A7F00D8810D /* Sparkle.strings in Resources */ = {isa = PBXBuildFile; fileRef = 61AAE8220A321A7F00D8810D /* Sparkle.strings */; }; 61AAE8290A321A8000D8810D /* SUAutomaticUpdateAlert.nib in Resources */ = {isa = PBXBuildFile; fileRef = 61AAE8240A321A7F00D8810D /* SUAutomaticUpdateAlert.nib */; }; 61AAE82A0A321A8000D8810D /* SUUpdateAlert.nib in Resources */ = {isa = PBXBuildFile; fileRef = 61AAE8260A321A7F00D8810D /* SUUpdateAlert.nib */; }; - 61B5F8E909C4CE3C00B25A18 /* NSString+extras.h in Headers */ = {isa = PBXBuildFile; fileRef = 61B5F8DF09C4CE3C00B25A18 /* NSString+extras.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 61B5F8EA09C4CE3C00B25A18 /* NSString+extras.m in Sources */ = {isa = PBXBuildFile; fileRef = 61B5F8E009C4CE3C00B25A18 /* NSString+extras.m */; }; - 61B5F8EB09C4CE3C00B25A18 /* RSS.h in Headers */ = {isa = PBXBuildFile; fileRef = 61B5F8E109C4CE3C00B25A18 /* RSS.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 61B5F8EC09C4CE3C00B25A18 /* RSS.m in Sources */ = {isa = PBXBuildFile; fileRef = 61B5F8E209C4CE3C00B25A18 /* RSS.m */; }; 61B5F8ED09C4CE3C00B25A18 /* SUUpdater.h in Headers */ = {isa = PBXBuildFile; fileRef = 61B5F8E309C4CE3C00B25A18 /* SUUpdater.h */; settings = {ATTRIBUTES = (Public, ); }; }; 61B5F8EE09C4CE3C00B25A18 /* SUUpdater.m in Sources */ = {isa = PBXBuildFile; fileRef = 61B5F8E409C4CE3C00B25A18 /* SUUpdater.m */; }; 61B5F8EF09C4CE3C00B25A18 /* NSFileManager+Authentication.m in Sources */ = {isa = PBXBuildFile; fileRef = 61B5F8E509C4CE3C00B25A18 /* NSFileManager+Authentication.m */; }; @@ -225,10 +221,6 @@ 61AAE84F0A321AF700D8810D /* es */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/Sparkle.strings; sourceTree = ""; }; 61AAE8590A321B0400D8810D /* fr */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = fr; path = fr.lproj/Sparkle.strings; sourceTree = ""; }; 61AAE8710A321F7700D8810D /* nl */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = nl; path = nl.lproj/Sparkle.strings; sourceTree = ""; }; - 61B5F8DF09C4CE3C00B25A18 /* NSString+extras.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = "NSString+extras.h"; sourceTree = ""; }; - 61B5F8E009C4CE3C00B25A18 /* NSString+extras.m */ = {isa = PBXFileReference; fileEncoding = 30; includeInIndex = 0; lastKnownFileType = sourcecode.c.objc; path = "NSString+extras.m"; sourceTree = ""; }; - 61B5F8E109C4CE3C00B25A18 /* RSS.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = RSS.h; sourceTree = ""; }; - 61B5F8E209C4CE3C00B25A18 /* RSS.m */ = {isa = PBXFileReference; fileEncoding = 30; includeInIndex = 0; lastKnownFileType = sourcecode.c.objc; path = RSS.m; sourceTree = ""; }; 61B5F8E309C4CE3C00B25A18 /* SUUpdater.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = SUUpdater.h; sourceTree = ""; }; 61B5F8E409C4CE3C00B25A18 /* SUUpdater.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = SUUpdater.m; sourceTree = ""; }; 61B5F8E509C4CE3C00B25A18 /* NSFileManager+Authentication.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = "NSFileManager+Authentication.m"; sourceTree = ""; }; @@ -439,10 +431,6 @@ 61A2259C0D1C495D00430CCD /* SUVersionComparisonProtocol.h */, 61A225A20D1C4AC000430CCD /* SUStandardVersionComparator.h */, 61A225A30D1C4AC000430CCD /* SUStandardVersionComparator.m */, - 61B5F8E109C4CE3C00B25A18 /* RSS.h */, - 61B5F8E209C4CE3C00B25A18 /* RSS.m */, - 61B5F8DF09C4CE3C00B25A18 /* NSString+extras.h */, - 61B5F8E009C4CE3C00B25A18 /* NSString+extras.m */, ); name = "Appcast Support"; sourceTree = ""; @@ -561,8 +549,6 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( - 61B5F8E909C4CE3C00B25A18 /* NSString+extras.h in Headers */, - 61B5F8EB09C4CE3C00B25A18 /* RSS.h in Headers */, 61B5F8ED09C4CE3C00B25A18 /* SUUpdater.h in Headers */, 61B5FC0D09C4FC8200B25A18 /* SUAppcast.h in Headers */, 61B5FC7009C51F4A00B25A18 /* SUAppcastItem.h in Headers */, @@ -825,8 +811,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 61B5F8EA09C4CE3C00B25A18 /* NSString+extras.m in Sources */, - 61B5F8EC09C4CE3C00B25A18 /* RSS.m in Sources */, 61B5F8EE09C4CE3C00B25A18 /* SUUpdater.m in Sources */, 61B5F8EF09C4CE3C00B25A18 /* NSFileManager+Authentication.m in Sources */, 61B5FBB709C4FAFF00B25A18 /* SUAppcast.m in Sources */, From 41d05dd922abe3571309a0c0c3d9b2dc62b7e7bc Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Wed, 2 Jul 2008 20:34:05 -0700 Subject: [PATCH 17/22] Fixes 236450 No longer releasing the SUUpdater delegate on dealloc. That was a silly mistake. --- SUUpdater.m | 1 - 1 file changed, 1 deletion(-) diff --git a/SUUpdater.m b/SUUpdater.m index 17077ea6..4db0b093 100644 --- a/SUUpdater.m +++ b/SUUpdater.m @@ -235,7 +235,6 @@ static SUUpdater *sharedUpdater = nil; - (void)dealloc { [hostBundle release]; - [delegate release]; if (checkTimer) { [checkTimer invalidate]; } [[NSNotificationCenter defaultCenter] removeObserver:self]; [super dealloc]; From f9d3dbfa61c9f0d78e2d324e62724b3ac29a150b Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Wed, 2 Jul 2008 23:31:20 -0700 Subject: [PATCH 18/22] Fixes 244692: Sparkle crashes on Tiger due to a double-release in SUUserDefaults. --- SUUserDefaults.m | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/SUUserDefaults.m b/SUUserDefaults.m index d6923f04..26f995ad 100644 --- a/SUUserDefaults.m +++ b/SUUserDefaults.m @@ -44,17 +44,17 @@ { [self verifyIdentifier]; CFPropertyListRef obj = CFPreferencesCopyAppValue((CFStringRef)defaultName, (CFStringRef)identifier); - // Under Tiger, CFPreferencesCopyAppValue doesn't get values from NSRegistratioDomain, so anything + // 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, and no value // is found elsewhere. if (obj == NULL && [identifier isEqualToString:[[NSBundle mainBundle] bundleIdentifier]]) obj = [[NSUserDefaults standardUserDefaults] objectForKey:defaultName]; -#if MAC_OS_X_VERSION_MIN_REQUIRED > 1050 - return [NSMakeCollectable(obj) autorelease]; -#else - return [(id)obj autorelease]; + id result = nil; +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050 + result = [NSMakeCollectable(obj) autorelease]; #endif + return result ?: (id)obj; } - (void)setObject:(id)value forKey:(NSString *)defaultName; From 88ab4b6f52046ac645592eed2de5e1342cbd0459 Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Wed, 2 Jul 2008 23:39:50 -0700 Subject: [PATCH 19/22] Fixes 244675 Arrrgh, Apple changed the .zip UTI between Tiger and Leopard. Now making the unarchiver recognize a UTI which both conform to. --- SUPipedUnarchiver.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SUPipedUnarchiver.m b/SUPipedUnarchiver.m index 9ad911c8..569f8c99 100644 --- a/SUPipedUnarchiver.m +++ b/SUPipedUnarchiver.m @@ -15,7 +15,7 @@ { 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", @"com.pkware.zip-archive", @"_extractTGZ", @"org.gnu.gnu-zip-tar-archive", @"_extractTBZ", @"org.bzip.bzip2-tar-archive", @"_extractTAR", @"public.tar-archive", nil] retain]; NSEnumerator *typeEnumerator = [typeSelectorDictionary keyEnumerator]; id currentType; From aaa60d261db2e2db697de7b5d6deafce9a212c95 Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Wed, 2 Jul 2008 23:54:05 -0700 Subject: [PATCH 20/22] Fixed 244761 Added a delegate method: - (id )versionComparatorForHostBundle:(NSBundle *)hb; Override this to specify a custom SUVersionComparison implementor to be used. --- SUBasicUpdateDriver.m | 24 ++++++++++++++++++------ SUUpdater.h | 6 +++++- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/SUBasicUpdateDriver.m b/SUBasicUpdateDriver.m index 1bfbaad2..512fbf3d 100644 --- a/SUBasicUpdateDriver.m +++ b/SUBasicUpdateDriver.m @@ -31,25 +31,37 @@ [[SUUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:SULastCheckTimeKey]; } +- (id )_versionComparator +{ + id comparator = nil; + + // Give the delegate a chance to provide a custom version comparator + if ([delegate respondsToSelector:@selector(versionComparatorForHostBundle:)]) + comparator = [delegate versionComparatorForHostBundle:hostBundle]; + + // 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:[hostBundle 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; + return [[self _versionComparator] compareVersion:[ui minimumSystemVersion] toVersion:[NSWorkspace systemVersionString]] != NSOrderedDescending; } - (BOOL)itemContainsSkippedVersion:(SUAppcastItem *)ui { NSString *skippedVersion = [[SUUserDefaults standardUserDefaults] objectForKey: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 diff --git a/SUUpdater.h b/SUUpdater.h index aed4ae15..1d633531 100644 --- a/SUUpdater.h +++ b/SUUpdater.h @@ -10,6 +10,7 @@ #define SUUPDATER_H #import "SUUpdateAlert.h" +#import "SUVersionComparisonProtocol.h" @class SUUpdateDriver, SUAppcastItem, SUAppcast; @interface SUUpdater : NSObject { @@ -45,7 +46,6 @@ - (void)updatePreferencesChanged; - (BOOL)updateInProgress; - @end @interface NSObject (SUUpdaterDelegateInformalProtocol) @@ -81,6 +81,10 @@ // Called immediately before relaunching. - (void)updaterWillRelaunchApplication; +// This method allows you to provide a custom version comparator. +// If you don't implement this method or return nil, the standard version comparator will be used. +- (id )versionComparatorForHostBundle:(NSBundle *)hb; + @end // Define some minimum intervals to avoid DOS-like checking attacks. These are in seconds. From df0178e2de2568c8c556fda47c5bf7b9bec2bd34 Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Thu, 3 Jul 2008 00:14:06 -0700 Subject: [PATCH 21/22] Fixed 243533 This should fix the .tar.bz2 and .tar.gz cases. Basically, Launch Services isn't smart enough to see both parts of the extension. When it sees a .bz2 or a .gz, I assume it's a .tar.bz2 or a .tar.gz, because that's what makes sense. Don't use plain .bz2 or .gzs! --- SUPipedUnarchiver.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SUPipedUnarchiver.m b/SUPipedUnarchiver.m index 569f8c99..ab9fd0db 100644 --- a/SUPipedUnarchiver.m +++ b/SUPipedUnarchiver.m @@ -14,8 +14,9 @@ + (SEL)_selectorConformingToTypeOfURL:(NSURL *)URL { static NSDictionary *typeSelectorDictionary; + // HACK: The UTI detector is dumb (not my fault!) and sees .tar.gz files as plain .gz files. If we see something of type .bz2 or .gz, we'll assume it's really a .tar.bz2 or .tar.gz. if (!typeSelectorDictionary) - typeSelectorDictionary = [[NSDictionary dictionaryWithObjectsAndKeys:@"_extractZIP", @"com.pkware.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", @"com.pkware.zip-archive", @"_extractTGZ", @"org.gnu.gnu-zip-tar-archive", @"_extractTGZ", @"org.gnu.gnu-zip-archive", @"_extractTBZ", @"org.bzip.bzip2-tar-archive", @"_extractTBZ", @"org.bzip.bzip2-archive", @"_extractTAR", @"public.tar-archive", nil] retain]; NSEnumerator *typeEnumerator = [typeSelectorDictionary keyEnumerator]; id currentType; From c7881dec3579532db95ce6630ffa98c12af0a790 Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Thu, 3 Jul 2008 22:24:01 -0700 Subject: [PATCH 22/22] Fixes 244767 Simple fix to a dumb mistake which prevented Sparkle from using the default application icon for bundles which didn't have one. --- NSBundle+SUAdditions.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NSBundle+SUAdditions.m b/NSBundle+SUAdditions.m index 983d0f5c..de3c0ce1 100644 --- a/NSBundle+SUAdditions.m +++ b/NSBundle+SUAdditions.m @@ -53,7 +53,7 @@ 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)]; } + if (!icon) { icon = [NSImage imageNamed:@"NSDefaultApplicationIcon"]; } return icon; }