Permalink
Browse files

Add a preference switch to clear the avatar cache.

Signed-off-by: Dennis Blöte <mail@dennisbloete.de>
  • Loading branch information...
1 parent de2e02f commit c7509537c9522df6073923dcfe012a3cc64d5e5e @priteau priteau committed with dbloete Sep 13, 2009
Showing with 31 additions and 0 deletions.
  1. +1 −0 Classes/AppConstants.h
  2. +14 −0 Classes/iOctocatAppDelegate.m
  3. +16 −0 Settings.bundle/Root.plist
View
@@ -1,4 +1,5 @@
// Settings
+#define kClearAvatarCacheDefaultsKey @"clearAvatarCache"
#define kLaunchDateDefaultsKey @"lastLaunch"
#define kUsernameDefaultsKey @"username"
#define kTokenDefaultsKey @"token"
@@ -33,6 +33,20 @@ - (void)postLaunch {
self.lastLaunchDate = lastLaunch;
// save this launch date
[defaults setValue:nowDate forKey:kLaunchDateDefaultsKey];
+ // Clear avatar cache if it was requested
+ if ([defaults boolForKey:kClearAvatarCacheDefaultsKey]) {
+ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
+ NSString *documentsPath = [paths objectAtIndex:0];
+ NSFileManager *fileManager = [NSFileManager defaultManager];
+ NSArray *documents = [fileManager contentsOfDirectoryAtPath:documentsPath error:NULL];
+ for (NSString *path in documents) {
+ if ([path hasSuffix:@".png"]) {
+ NSString *imagePath = [documentsPath stringByAppendingPathComponent:path];
+ [fileManager removeItemAtPath:imagePath error:NULL];
+ }
+ }
+ [defaults setValue:NO forKey:kClearAvatarCacheDefaultsKey];
+ }
[defaults synchronize];
if (launchDefault) [self authenticate];
}
View
@@ -50,6 +50,22 @@
<key>AutocorrectionType</key>
<string>No</string>
</dict>
+ <dict>
+ <key>Type</key>
+ <string>PSGroupSpecifier</string>
+ <key>Title</key>
+ <string>Avatar cache</string>
+ </dict>
+ <dict>
+ <key>Type</key>
+ <string>PSToggleSwitchSpecifier</string>
+ <key>Title</key>
+ <string>Clear on next launch</string>
+ <key>Key</key>
+ <string>clearAvatarCache</string>
+ <key>DefaultValue</key>
+ <false/>
+ </dict>
</array>
</dict>
</plist>

0 comments on commit c750953

Please sign in to comment.