PageRenderTime 59ms CodeModel.GetById 14ms app.highlight 42ms RepoModel.GetById 1ms app.codeStats 0ms

/core/autoinstaller/UpdateEngineExtensions/UpdatePrinter.m

http://macfuse.googlecode.com/
Objective C | 89 lines | 64 code | 17 blank | 8 comment | 5 complexity | a0204e19acf4040a99617cf57e414604 MD5 | raw file
 1//
 2//  UpdatePrinter.m
 3//  autoinstaller
 4//
 5//  Created by Greg Miller on 7/16/08.
 6//  Copyright 2008 Google Inc. All rights reserved.
 7//
 8
 9#import "UpdatePrinter.h"
10#import "GTMLogger.h"
11
12
13@implementation UpdatePrinter
14
15+ (id)printer {
16  return [[[self alloc] init] autorelease];
17}
18
19- (id)init {
20  GTMLogger *logger = [GTMLogger logger];
21  return [self initWithLogger:logger];
22}
23
24- (id)initWithLogger:(GTMLogger *)logger {
25  if ((self = [super init])) {
26    logger_ = [logger retain];
27  }
28  return self;
29}
30
31- (void)dealloc {
32  [logger_ release];
33  [super dealloc];
34}
35
36- (GTMLogger *)logger {
37  return logger_;
38}
39
40- (void)printUpdates:(NSArray *)productUpdates {
41  NSDictionary *update = nil;
42  NSEnumerator *updateEnumerator = [productUpdates objectEnumerator];
43  while ((update = [updateEnumerator nextObject])) {
44    [[self logger] logInfo:@"###  Update"];
45    NSString *key = nil;
46    NSEnumerator *keyEnumerator = [update keyEnumerator];
47    while ((key = [keyEnumerator nextObject])) {
48      if (![key hasPrefix:@"kServer"])  // Ignore keys created by Update Engine
49        [[self logger] logInfo:@"%@='%@'", key, [update objectForKey:key]];
50    }
51    [[self logger] logInfo:@""];  // Output newline
52  }
53}
54
55@end
56
57
58@implementation PlistUpdatePrinter
59
60- (void)printUpdates:(NSArray *)productUpdates {
61  NSMutableArray *cleanedArray = [NSMutableArray array];
62  
63  NSDictionary *update = nil;
64  NSEnumerator *updateEnumerator = [productUpdates objectEnumerator];
65  while ((update = [updateEnumerator nextObject])) {
66    NSMutableDictionary *mutableUpdate = [[update mutableCopy] autorelease];
67    NSArray *keys = [mutableUpdate allKeys];
68    NSArray *generatedKeys = [keys filteredArrayUsingPredicate:
69                              [NSPredicate predicateWithFormat:
70                               @"SELF beginswith 'kServer'"]];
71    [mutableUpdate removeObjectsForKeys:generatedKeys];
72    [cleanedArray addObject:mutableUpdate];
73  }
74  
75  NSDictionary *dict = [NSDictionary dictionaryWithObject:cleanedArray
76                                                   forKey:@"Updates"];
77    
78  // Now, print the dictionary, which should now be a valid plist
79  NSData *data = [NSPropertyListSerialization
80                  dataFromPropertyList:dict
81                                format:NSPropertyListXMLFormat_v1_0
82                      errorDescription:NULL];
83  NSString *plist = [[[NSString alloc]
84                      initWithData:data
85                          encoding:NSUTF8StringEncoding] autorelease];
86  [[self logger] logInfo:@"%@", plist];
87}
88
89@end