Author: mlytwyn
Date: Fri Mar 10 15:56:58 2017
New Revision: 40376
URL: http://svn.gna.org/viewcvs/gnustep?rev=40376&view=rev
Log:
Fix user defaults using bundle identifier due to circular nature between
NSBundle and NSUserDefaults, and incorrect behavior on defaults restoration
Modified:
libs/base/branches/gnustep_testplant_branch/Source/NSBundle.m
libs/base/branches/gnustep_testplant_branch/Source/NSUserDefaults.m
Modified: libs/base/branches/gnustep_testplant_branch/Source/NSBundle.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/branches/gnustep_testplant_branch/Source/NSBundle.m?rev=40376&r1=40375&r2=40376&view=diff
==============================================================================
--- libs/base/branches/gnustep_testplant_branch/Source/NSBundle.m
(original)
+++ libs/base/branches/gnustep_testplant_branch/Source/NSBundle.m Fri Mar
10 15:56:58 2017
@@ -172,10 +172,6 @@
static NSLock *pathCacheLock = nil;
static NSMutableDictionary *pathCache = nil;
-
-@interface NSUserDefaults(Private)
-+ (void) _setProcessName: (NSString*) processName;
-@end
@interface NSObject (PrivateFrameworks)
+ (NSString*) frameworkVersion;
@@ -1483,8 +1479,6 @@
/* Please note that _mainBundle should *not* be nil. */
_mainBundle = [_mainBundle initWithPath: path];
NSAssert(_mainBundle != nil, NSInternalInconsistencyException);
- //Testplant:PGL we want to use the bundleIdentifier as the Application
domain
- [NSUserDefaults _setProcessName:[_mainBundle bundleIdentifier]];
}
[load_lock unlock];
Modified: libs/base/branches/gnustep_testplant_branch/Source/NSUserDefaults.m
URL:
http://svn.gna.org/viewcvs/gnustep/libs/base/branches/gnustep_testplant_branch/Source/NSUserDefaults.m?rev=40376&r1=40375&r2=40376&view=diff
==============================================================================
--- libs/base/branches/gnustep_testplant_branch/Source/NSUserDefaults.m
(original)
+++ libs/base/branches/gnustep_testplant_branch/Source/NSUserDefaults.m Fri Mar
10 15:56:58 2017
@@ -56,10 +56,6 @@
#import "GNUstepBase/NSProcessInfo+GNUstepBase.h"
#import "GNUstepBase/NSString+GNUstepBase.h"
-#if defined(__MINGW__)
-@class NSUserDefaultsWin32;
-#endif
-
#ifdef HAVE_LOCALE_H
#include <locale.h>
#endif
@@ -436,7 +432,6 @@
- (BOOL) _readDefaults;
- (BOOL) _readOnly;
- (void) _unlockDefaultsFile;
-+ (void) _setProcessName: (NSString*) processName;
@end
/**
@@ -551,6 +546,51 @@
DESTROY(classLock);
}
+// Testplant-MAL-03102017: Added...
+/* Due to the circular nature between NSBundle and NSUserDefaults we need to
duplicate
+ this code similar to NSBundle in order to properly retrieve the bundle
identifier
+ for use as the process name for the user defaults...
+ */
+// FIXME: The Cocoa info file contains substitution variables that we need to
address and
+// replace during this processing...either here or in some
pre-processing makefile
+// change...
++ (NSString*) _processName
+{
+ NSString *processName = [[NSProcessInfo processInfo] processName];
+ NSString *rootPath = [[[[NSProcessInfo processInfo] arguments]
objectAtIndex: 0] stringByDeletingLastPathComponent];
+ NSString *subPath = nil;
+ NSString *subFile = nil;
+ NSString *infoPath = nil;
+ NSFileManager *filemgr = [NSFileManager defaultManager];
+
+ for (subPath in @[ @"Resources" ])
+ {
+ for (subFile in @[ @"Info-gnustep.plist", @"Info.plist" ])
+ {
+ NSString *fullpath = [rootPath stringByAppendingPathComponent: subPath];
+ fullpath = [fullpath stringByAppendingPathComponent: subFile];
+ if ([filemgr fileExistsAtPath: fullpath])
+ {
+ infoPath = fullpath;
+ break;
+ }
+ }
+
+ if (infoPath)
+ break;
+ }
+
+ if (infoPath)
+ {
+ NSDictionary *infoDict = AUTORELEASE([[NSDictionary alloc]
initWithContentsOfFile: infoPath]);
+
+ if ([infoDict objectForKey: @"CFBundleIdentifier"])
+ processName = [infoDict objectForKey: @"CFBundleIdentifier"];
+ }
+
+ return processName;
+}
+
+ (void) initialize
{
if (self == [NSUserDefaults class])
@@ -769,7 +809,7 @@
if (r.length > 0)
{
- defs = [[NSUserDefaultsWin32 alloc] init];
+ defs = [[NSClassFromString(@"NSUserDefaultsWin32") alloc] init];
}
else
{
@@ -1110,8 +1150,7 @@
*/
if (processName == nil)
{
- NSString *s = [[NSProcessInfo processInfo] processName];
- [NSUserDefaults _setProcessName:s];
+ ASSIGNCOPY(processName, [[self class] _processName]);
}
if (path == nil || [path isEqual: @""] == YES)
@@ -2432,14 +2471,6 @@
isLocked = NO;
}
-
-// Testplant:PGL This is to set the bundleIdentifier after NSBundle loads.
-// Testplant:MAL Fix per GNUstep standards - _setProcessName should be private
-+ (void) _setProcessName:(NSString*)pName
-{
- processName = [pName copy];
-}
-
@end
@implementation GSPersistentDomain
_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs