source: trunk/ICeCoffEE/ICeCoffEE/ICFindFilesToRemove/UICookieMonster.m @ 68

Last change on this file since 68 was 68, checked in by Nicholas Riley, 17 years ago

Added ICFindFilesToRemove - automatically uninstalls ICeCoffEE input manager

File size: 4.3 KB
Line 
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;
45    cachedVersion = NULL;
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];
106}
107
108- (void)addFile:(NSString*)path
109{
110    if (![files containsObject:path])
111    {
112        [files addObject:path];
113        dirty = YES;
114    }
115}
116
117- (void)removeFile:(NSString*)path
118{
119}
120
121- (NSArray*)filesToRemove
122{
123    return files;
124}
125
126- (void)flush
127{
128    NSMutableDictionary* dict = [NSMutableDictionary dictionaryWithCapacity:0];
129   
130    if (!dirty)
131        return;
132   
133    [dict setObject:[NSNumber numberWithInt:version] forKey:@"Version"];
134    [dict setObject:files forKey:@"Files"];
135   
136    CFPreferencesSetValue((CFStringRef)productID, NULL, kCookieID, isGlobal?kCFPreferencesCurrentUser:kCFPreferencesAnyUser, isGlobal?kCFPreferencesAnyHost:kCFPreferencesCurrentHost);
137    CFPreferencesSetValue((CFStringRef)productID, (CFPropertyListRef)dict, kCookieID, isGlobal?kCFPreferencesAnyUser:kCFPreferencesCurrentUser, isGlobal?kCFPreferencesCurrentHost:kCFPreferencesAnyHost);
138   
139    CFPreferencesSynchronize(kCookieID, kCFPreferencesAnyUser, kCFPreferencesCurrentHost);
140    CFPreferencesSynchronize(kCookieID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
141   
142    dirty = NO;
143}
144
145+ (void)removeProductID:(NSString*)pid
146{
147    CFPreferencesSetValue((CFStringRef)pid, NULL, kCookieID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
148    CFPreferencesSetValue((CFStringRef)pid, NULL, kCookieID, kCFPreferencesAnyUser, kCFPreferencesCurrentHost);
149   
150    CFPreferencesSynchronize(kCookieID, kCFPreferencesAnyUser, kCFPreferencesCurrentHost);
151    CFPreferencesSynchronize(kCookieID, kCFPreferencesCurrentUser, kCFPreferencesAnyHost);
152}
153
154@end
Note: See TracBrowser for help on using the repository browser.