Skip to content

Commit

Permalink
Added NSUserDefaults hack to cleanup the junk plist files. :(
Browse files Browse the repository at this point in the history
  • Loading branch information
bsneed committed Jan 5, 2011
1 parent f895b39 commit d637d27
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
14 changes: 14 additions & 0 deletions NSUserDefaults+Hack.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// NSUserDefaults+Hack.h
// gitty
//
// Created by brandon on 1/4/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import <Cocoa/Cocoa.h>


@interface NSUserDefaults(Hack)

@end
40 changes: 40 additions & 0 deletions NSUserDefaults+Hack.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// NSUserDefaults+Hack.m
// gitty
//
// Created by brandon on 1/4/11.
// Copyright 2011 redf.net. All rights reserved.
//

#import "NSUserDefaults+Hack.h"


@implementation NSUserDefaults(Hack)

- (BOOL)synchronize
{
BOOL result = CFPreferencesAppSynchronize((CFStringRef)[[NSBundle mainBundle] bundleIdentifier]);
if (!result)
{
// there's probably a temp file lingering around... try again.
result = CFPreferencesAppSynchronize((CFStringRef)[[NSBundle mainBundle] bundleIdentifier]);

// regardless of the result, lets clean up any temp files hanging around..
NSString *prefsDir = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Preferences"];
NSDirectoryEnumerator *dirEnumerator = [[NSFileManager defaultManager] enumeratorAtPath:prefsDir];
NSString *match = [[[NSBundle mainBundle] bundleIdentifier] stringByAppendingString:@".plist."];
NSString *file = nil;
while ((file = [dirEnumerator nextObject]))
{
if ([file rangeOfString:match].location != NSNotFound)
{
NSString *fileToRemove = [prefsDir stringByAppendingPathComponent:file];
[[NSFileManager defaultManager] removeItemAtPath:fileToRemove error:nil];
}
}
}

return result;
}

@end
6 changes: 6 additions & 0 deletions gitty.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@
CABCA82711B6C52D00EB8EEA /* SCEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = CABCA81C11B6C52D00EB8EEA /* SCEvent.m */; };
CABCA82811B6C52D00EB8EEA /* SCEvents.m in Sources */ = {isa = PBXBuildFile; fileRef = CABCA81F11B6C52D00EB8EEA /* SCEvents.m */; };
CABE68591299080C00CCAD60 /* remoteBranches.png in Resources */ = {isa = PBXBuildFile; fileRef = CABE68581299080C00CCAD60 /* remoteBranches.png */; };
CACB1CD212D43A5000038594 /* NSUserDefaults+Hack.m in Sources */ = {isa = PBXBuildFile; fileRef = CACB1CD112D43A5000038594 /* NSUserDefaults+Hack.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -1024,6 +1025,8 @@
CABCA81E11B6C52D00EB8EEA /* SCEvents.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SCEvents.h; sourceTree = "<group>"; };
CABCA81F11B6C52D00EB8EEA /* SCEvents.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SCEvents.m; sourceTree = "<group>"; };
CABE68581299080C00CCAD60 /* remoteBranches.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = remoteBranches.png; sourceTree = "<group>"; };
CACB1CD012D43A5000038594 /* NSUserDefaults+Hack.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSUserDefaults+Hack.h"; sourceTree = "<group>"; };
CACB1CD112D43A5000038594 /* NSUserDefaults+Hack.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSUserDefaults+Hack.m"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -1467,6 +1470,8 @@
isa = PBXGroup;
children = (
07A0549B10708B8200B21AB9 /* GDNSString+Additions.m */,
CACB1CD012D43A5000038594 /* NSUserDefaults+Hack.h */,
CACB1CD112D43A5000038594 /* NSUserDefaults+Hack.m */,
07C971EE1073C86500E7F7DD /* NSFileHandleAdditions.m */,
074E0F5610D498DF00DCE009 /* NSTableView+Additions.m */,
);
Expand Down Expand Up @@ -2693,6 +2698,7 @@
CABCA82711B6C52D00EB8EEA /* SCEvent.m in Sources */,
CABCA82811B6C52D00EB8EEA /* SCEvents.m in Sources */,
CA92314012ACEFE800349047 /* GTQuickLookItem.m in Sources */,
CACB1CD212D43A5000038594 /* NSUserDefaults+Hack.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down

0 comments on commit d637d27

Please sign in to comment.