PageRenderTime 10ms CodeModel.GetById 6ms RepoModel.GetById 0ms 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
Possible License(s): Apache-2.0, BSD-3-Clause, GPL-2.0
  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. #import "KSUpdateAction.h"
  15. #import "KSActionPipe.h"
  16. #import "KSDownloadAction.h"
  17. #import "KSInstallAction.h"
  18. @implementation KSUpdateAction
  19. + (id)actionWithUpdateInfo:(KSUpdateInfo *)info
  20. runner:(id<KSCommandRunner>)runner
  21. userInitiated:(BOOL)ui {
  22. return [[[self alloc] initWithUpdateInfo:info
  23. runner:runner
  24. userInitiated:ui] autorelease];
  25. }
  26. // Overriding super's designated initializer
  27. - (id)initWithActions:(NSArray *)actions {
  28. return [self initWithUpdateInfo:nil runner:nil userInitiated:NO];
  29. }
  30. - (id)initWithUpdateInfo:(KSUpdateInfo *)updateInfo
  31. runner:(id<KSCommandRunner>)runner
  32. userInitiated:(BOOL)ui {
  33. // Creates a downloader and an installer. We'll get the DMG path for the
  34. // installer from the output of the downloader. We stick a ".dmg" extension
  35. // on everything downloaded because our installer only knows how to handle
  36. // DMG files and we want to help hdiutil identify that the downloaded thing
  37. // is indeed a diskimage.
  38. NSString *name =
  39. [[updateInfo productID] stringByAppendingPathExtension:@"dmg"];
  40. KSAction *downloader =
  41. [KSDownloadAction actionWithURL:[updateInfo codebaseURL]
  42. size:[[updateInfo codeSize] intValue]
  43. hash:[updateInfo codeHash]
  44. name:name];
  45. // DMGPath is nil because that will be obtained from the installer's inPipe.
  46. KSAction *installer = [KSInstallAction actionWithDMGPath:nil
  47. runner:runner
  48. userInitiated:ui
  49. updateInfo:updateInfo];
  50. // Connects the output of the downloader to the input of the installer via
  51. // a KSActionPipe.
  52. KSActionPipe *pipe = [KSActionPipe pipe];
  53. [downloader setOutPipe:pipe];
  54. [installer setInPipe:pipe];
  55. NSArray *actions = [NSArray arrayWithObjects:downloader, installer, nil];
  56. if ((self = [super initWithActions:actions])) {
  57. updateInfo_ = [updateInfo retain];
  58. if (updateInfo_ == nil || downloader == nil || installer == nil) {
  59. [self release]; // COV_NF_LINE
  60. return nil; // COV_NF_LINE
  61. }
  62. }
  63. return self;
  64. }
  65. - (void)dealloc {
  66. [updateInfo_ release];
  67. [super dealloc];
  68. }
  69. - (KSUpdateInfo *)updateInfo {
  70. return updateInfo_;
  71. }
  72. - (NSNumber *)returnCode {
  73. NSArray *actions = [self actions];
  74. _GTMDevAssert([actions count] == 2, @"must have exactly 2 actions");
  75. KSAction *installer = [actions lastObject];
  76. return [[installer outPipe] contents];
  77. }
  78. - (BOOL)wantsReboot {
  79. return [[self returnCode] intValue] == KS_INSTALL_WANTS_REBOOT;
  80. }
  81. @end