PageRenderTime 44ms CodeModel.GetById 11ms app.highlight 30ms RepoModel.GetById 1ms app.codeStats 0ms

/core/externals/update-engine/Core/KSUpdateAction.m

http://macfuse.googlecode.com/
Objective C | 97 lines | 59 code | 16 blank | 22 comment | 9 complexity | e696f202eff40917e707042cb98094a8 MD5 | raw file
 1// Copyright 2008 Google Inc.
 2//
 3// Licensed under the Apache License, Version 2.0 (the "License");
 4// you may not use this file except in compliance with the License.
 5// You may obtain a copy of the License at
 6//
 7//     http://www.apache.org/licenses/LICENSE-2.0
 8//
 9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#import "KSUpdateAction.h"
16#import "KSActionPipe.h"
17#import "KSDownloadAction.h"
18#import "KSInstallAction.h"
19
20
21@implementation KSUpdateAction
22
23+ (id)actionWithUpdateInfo:(KSUpdateInfo *)info
24                    runner:(id<KSCommandRunner>)runner
25             userInitiated:(BOOL)ui {
26  return [[[self alloc] initWithUpdateInfo:info
27                                    runner:runner
28                             userInitiated:ui] autorelease];
29}
30
31// Overriding super's designated initializer
32- (id)initWithActions:(NSArray *)actions {
33  return [self initWithUpdateInfo:nil runner:nil userInitiated:NO];
34}
35
36- (id)initWithUpdateInfo:(KSUpdateInfo *)updateInfo
37                  runner:(id<KSCommandRunner>)runner
38           userInitiated:(BOOL)ui {
39  // Creates a downloader and an installer. We'll get the DMG path for the
40  // installer from the output of the downloader. We stick a ".dmg" extension
41  // on everything downloaded because our installer only knows how to handle
42  // DMG files and we want to help hdiutil identify that the downloaded thing
43  // is indeed a diskimage.
44  NSString *name =
45    [[updateInfo productID] stringByAppendingPathExtension:@"dmg"];
46  KSAction *downloader =
47    [KSDownloadAction actionWithURL:[updateInfo codebaseURL]
48                               size:[[updateInfo codeSize] intValue]
49                               hash:[updateInfo codeHash]
50                               name:name];
51
52  // DMGPath is nil because that will be obtained from the installer's inPipe.
53  KSAction *installer = [KSInstallAction actionWithDMGPath:nil
54                                                    runner:runner
55                                             userInitiated:ui
56                                                updateInfo:updateInfo];
57
58  // Connects the output of the downloader to the input of the installer via
59  // a KSActionPipe.
60  KSActionPipe *pipe = [KSActionPipe pipe];
61  [downloader setOutPipe:pipe];
62  [installer setInPipe:pipe];
63
64  NSArray *actions = [NSArray arrayWithObjects:downloader, installer, nil];
65
66  if ((self = [super initWithActions:actions])) {
67    updateInfo_ = [updateInfo retain];
68    if (updateInfo_ == nil || downloader == nil || installer == nil) {
69      [self release];  // COV_NF_LINE
70      return nil;      // COV_NF_LINE
71    }
72  }
73  return self;
74}
75
76- (void)dealloc {
77  [updateInfo_ release];
78  [super dealloc];
79}
80
81- (KSUpdateInfo *)updateInfo {
82  return updateInfo_;
83}
84
85- (NSNumber *)returnCode {
86  NSArray *actions = [self actions];
87  _GTMDevAssert([actions count] == 2, @"must have exactly 2 actions");
88  KSAction *installer = [actions lastObject];
89  return [[installer outPipe] contents];
90}
91
92- (BOOL)wantsReboot {
93  return [[self returnCode] intValue] == KS_INSTALL_WANTS_REBOOT;
94}
95
96@end
97