#import <Foundation/Foundation.h>
#import "UICookieMonster.h"

#define kProductID 		@"net.sabi.ICeCoffEE"

// if the first path exists, it and all subsequent paths will be removed

NSString* gGlobalPaths[] = {
    @"/Library/InputManagers/ICeCoffEE",
    @"/Library/Application Enhancers/ICeCoffEE.ape",
    nil
};

NSString* gLocalPaths[] = {
    @"~/Library/InputManagers/ICeCoffEE",
    @"~/Library/Application Enhancers/ICeCoffEE.ape",
    nil
};

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    UICookieMonster* monster = [UICookieMonster monsterWithProductID:kProductID];
    NSArray* files = [monster filesToRemove];
    
    if (!files || ![files count])
    {
        if ([[NSFileManager defaultManager] fileExistsAtPath:[gGlobalPaths[0] stringByExpandingTildeInPath]])
        {
            UICookieMonster* mons = [UICookieMonster monsterWithProductID:kProductID global:YES];
            int i;
            
            for (i=0;gGlobalPaths[i];i++)
            {
                [mons addFile:[gGlobalPaths[i] stringByExpandingTildeInPath]];
            }
            
            [mons flush];
        }
        else if ([[NSFileManager defaultManager] fileExistsAtPath:[gLocalPaths[0] stringByExpandingTildeInPath]])
        {
            UICookieMonster* mons = [UICookieMonster monsterWithProductID:kProductID global:NO];
            int i;
            
            for (i=0;gLocalPaths[i];i++)
            {
                [mons addFile:[gLocalPaths[i] stringByExpandingTildeInPath]];
            }
            
            [mons flush];
        }
    }
    
    [pool release];
    return 0;
}
