/core/externals/update-engine/Samples/EngineRunner/ERChangeTicketCommand.m

http://macfuse.googlecode.com/ · Objective C · 99 lines · 54 code · 25 blank · 20 comment · 8 complexity · 5c489f01d45a6d676cd9d62b35c9ec1a 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. #import "ERChangeTicketCommand.h"
  15. #import "KSUpdateEngine.h"
  16. @implementation ERChangeTicketCommand
  17. - (NSString *)name {
  18. return @"change";
  19. } // name
  20. - (NSString *)blurb {
  21. return @"Change attributes of a ticket";
  22. } // blurb
  23. - (NSDictionary *)requiredArguments {
  24. return [NSDictionary dictionaryWithObjectsAndKeys:
  25. @"Path to the ticket store", @"store",
  26. @"Product ID to change", @"productid",
  27. nil];
  28. } // requiredArguments
  29. - (NSDictionary *)optionalArguments {
  30. return [NSDictionary dictionaryWithObjectsAndKeys:
  31. @"New product version", @"version",
  32. @"New existence checker path", @"xcpath",
  33. @"New server URL", @"url",
  34. nil];
  35. } // optionalArguments
  36. - (BOOL)runWithArguments:(NSDictionary *)args {
  37. // Get ahold of the ticket store.
  38. NSString *storePath = [args objectForKey:@"store"];
  39. KSTicketStore *ticketStore = [KSTicketStore ticketStoreWithPath:storePath];
  40. // Pull the ticket out for the particular product to change.
  41. NSString *productID = [args objectForKey:@"productid"];
  42. KSTicket *ticket = [ticketStore ticketForProductID:productID];
  43. if (ticket == nil) {
  44. fprintf(stderr, "Could not find product '%s' in ticket store '%s'",
  45. [productID UTF8String], [storePath UTF8String]);
  46. return NO;
  47. }
  48. // Tickets are immutable objects, so we will need to create a brand
  49. // new ticket with the changes. Use an old value if the corresponding
  50. // optional parameter has not been provided.
  51. NSString *version = [args objectForKey:@"version"];
  52. if (version == nil) {
  53. version = [ticket version];
  54. }
  55. KSExistenceChecker *existenceChecker = [ticket existenceChecker];
  56. NSString *xcpath = [args objectForKey:@"xcpath"];
  57. if (xcpath != nil) {
  58. existenceChecker = [KSPathExistenceChecker checkerWithPath:xcpath];
  59. }
  60. NSURL *serverURL = [ticket serverURL];
  61. NSString *urlString = [args objectForKey:@"url"];
  62. if (urlString != nil) {
  63. serverURL = [NSURL URLWithString:urlString];
  64. }
  65. // Make the new ticket and put it into the store. This will replace
  66. // the existing ticket, and write it out to disk.
  67. KSTicket *newTicket = [KSTicket ticketWithProductID:productID
  68. version:version
  69. existenceChecker:existenceChecker
  70. serverURL:serverURL];
  71. BOOL result = [ticketStore storeTicket:newTicket];
  72. return result;
  73. } // runWithArguments
  74. @end // ERChangeTicketCommand