[68] | 1 | //
|
---|
| 2 | // UICookieMonster.m
|
---|
| 3 | // Unsanity Installer
|
---|
| 4 | //
|
---|
| 5 | // Created by Slava Karpenko on Thu Nov 28 2002.
|
---|
| 6 | // Copyright (c) 2002 Unsanity LLC. All rights reserved.
|
---|
| 7 | //
|
---|
| 8 |
|
---|
| 9 | #import "UICookieMonster.h"
|
---|
| 10 |
|
---|
| 11 | #define kCookieID CFSTR("Unsanity Installer Receipts")
|
---|
| 12 |
|
---|
| 13 | @implementation UICookieMonster
|
---|
| 14 | + monsterWithProductID:(NSString*)pid global:(BOOL)global version:(UInt32)inVersion
|
---|
| 15 | {
|
---|
| 16 | if (!pid)
|
---|
| 17 | return nil;
|
---|
| 18 |
|
---|
| 19 | return [[[UICookieMonster alloc] initWithProductID:pid globalVersionValid:YES global:global version:inVersion] autorelease];
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | + monsterWithProductID:(NSString*)pid global:(BOOL)global
|
---|
| 23 | {
|
---|
| 24 | if (!pid)
|
---|
| 25 | return nil;
|
---|
| 26 |
|
---|
| 27 | return [[[UICookieMonster alloc] initWithProductID:pid globalVersionValid:NO global:global version:0] autorelease];
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | + monsterWithProductID:(NSString*)pid
|
---|
| 31 | {
|
---|
| 32 | if (!pid)
|
---|
| 33 | return nil;
|
---|
| 34 |
|
---|
| 35 | return [[[UICookieMonster alloc] initWithProductID:pid globalVersionValid:NO global:NO version:0] autorelease];
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | - initWithProductID:(NSString*)pid globalVersionValid:(BOOL)gvValid global:(BOOL)global version:(UInt32)inVersion
|
---|
| 39 | {
|
---|
| 40 | CFDictionaryRef dict;
|
---|
| 41 |
|
---|
| 42 | productID = [pid retain];
|
---|
| 43 | isGlobal = global;
|
---|
| 44 | version = inVersion;
|
---|
[181] | 45 | cachedVersion = 0;
|
---|
[68] | 46 |
|
---|
| 47 | files = [[NSMutableArray arrayWithCapacity:0] retain];
|
---|
| 48 |
|
---|
| 49 | CFPreferencesSynchronize(kCookieID, kCFPreferencesAnyUser, kCFPreferencesCurrentHost);
|
---|
| 50 | CFPreferencesSynchronize(kCookieID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
|
---|
| 51 |
|
---|
| 52 | dict = CFPreferencesCopyValue((CFStringRef)productID, kCookieID, kCFPreferencesAnyUser, kCFPreferencesCurrentHost);
|
---|
| 53 |
|
---|
| 54 | if (dict)
|
---|
| 55 | {
|
---|
| 56 | NSNumber* vers = (NSNumber*)CFDictionaryGetValue(dict, CFSTR("Version"));
|
---|
| 57 | [files addObjectsFromArray:(NSArray*)CFDictionaryGetValue(dict, CFSTR("Files"))];
|
---|
| 58 | cachedVersion = [vers intValue];
|
---|
| 59 |
|
---|
| 60 | if (!gvValid) isGlobal = YES;
|
---|
| 61 |
|
---|
| 62 | //NSLog(@"Global data read = %@", dict);
|
---|
| 63 | CFRelease(dict);
|
---|
| 64 | }
|
---|
| 65 | else
|
---|
| 66 | {
|
---|
| 67 | dict = CFPreferencesCopyValue((CFStringRef)productID, kCookieID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
|
---|
| 68 |
|
---|
| 69 | if (dict)
|
---|
| 70 | {
|
---|
| 71 | NSNumber* vers = (NSNumber*)CFDictionaryGetValue(dict, CFSTR("Version"));
|
---|
| 72 | [files addObjectsFromArray:(NSArray*)CFDictionaryGetValue(dict, CFSTR("Files"))];
|
---|
| 73 | cachedVersion = [vers intValue];
|
---|
| 74 | if (!gvValid) isGlobal = NO;
|
---|
| 75 |
|
---|
| 76 | //NSLog(@"Local data read = %@", dict);
|
---|
| 77 | CFRelease(dict);
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | if (!cachedVersion) cachedVersion = version;
|
---|
| 83 | if (!gvValid) version = cachedVersion;
|
---|
| 84 |
|
---|
| 85 | dirty = NO;
|
---|
| 86 |
|
---|
| 87 | return self;
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | - (BOOL)isGlobal
|
---|
| 91 | {
|
---|
| 92 | return isGlobal;
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | - (UInt32)productVersion
|
---|
| 96 | {
|
---|
| 97 | return cachedVersion;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | - (void)dealloc
|
---|
| 101 | {
|
---|
| 102 | [self flush];
|
---|
| 103 |
|
---|
| 104 | [productID release];
|
---|
| 105 | [files release];
|
---|
[181] | 106 | [super dealloc];
|
---|
[68] | 107 | }
|
---|
| 108 |
|
---|
| 109 | - (void)addFile:(NSString*)path
|
---|
| 110 | {
|
---|
| 111 | if (![files containsObject:path])
|
---|
| 112 | {
|
---|
| 113 | [files addObject:path];
|
---|
| 114 | dirty = YES;
|
---|
| 115 | }
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | - (void)removeFile:(NSString*)path
|
---|
| 119 | {
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | - (NSArray*)filesToRemove
|
---|
| 123 | {
|
---|
| 124 | return files;
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | - (void)flush
|
---|
| 128 | {
|
---|
| 129 | NSMutableDictionary* dict = [NSMutableDictionary dictionaryWithCapacity:0];
|
---|
| 130 |
|
---|
| 131 | if (!dirty)
|
---|
| 132 | return;
|
---|
| 133 |
|
---|
| 134 | [dict setObject:[NSNumber numberWithInt:version] forKey:@"Version"];
|
---|
| 135 | [dict setObject:files forKey:@"Files"];
|
---|
| 136 |
|
---|
| 137 | CFPreferencesSetValue((CFStringRef)productID, NULL, kCookieID, isGlobal?kCFPreferencesCurrentUser:kCFPreferencesAnyUser, isGlobal?kCFPreferencesAnyHost:kCFPreferencesCurrentHost);
|
---|
| 138 | CFPreferencesSetValue((CFStringRef)productID, (CFPropertyListRef)dict, kCookieID, isGlobal?kCFPreferencesAnyUser:kCFPreferencesCurrentUser, isGlobal?kCFPreferencesCurrentHost:kCFPreferencesAnyHost);
|
---|
| 139 |
|
---|
| 140 | CFPreferencesSynchronize(kCookieID, kCFPreferencesAnyUser, kCFPreferencesCurrentHost);
|
---|
| 141 | CFPreferencesSynchronize(kCookieID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
|
---|
| 142 |
|
---|
| 143 | dirty = NO;
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 | + (void)removeProductID:(NSString*)pid
|
---|
| 147 | {
|
---|
| 148 | CFPreferencesSetValue((CFStringRef)pid, NULL, kCookieID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
|
---|
| 149 | CFPreferencesSetValue((CFStringRef)pid, NULL, kCookieID, kCFPreferencesAnyUser, kCFPreferencesCurrentHost);
|
---|
| 150 |
|
---|
| 151 | CFPreferencesSynchronize(kCookieID, kCFPreferencesAnyUser, kCFPreferencesCurrentHost);
|
---|
| 152 | CFPreferencesSynchronize(kCookieID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 | @end
|
---|