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

http://macfuse.googlecode.com/ · Objective C · 74 lines · 36 code · 19 blank · 19 comment · 0 complexity · c91c151a87f64cf46624b076e65541f3 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 "ERAddTicketCommand.h"
  15. #import "KSUpdateEngine.h"
  16. @implementation ERAddTicketCommand
  17. - (NSString *)name {
  18. return @"add";
  19. } // name
  20. - (NSString *)blurb {
  21. return @"Add a new ticket to a ticket store";
  22. } // blurb
  23. - (NSDictionary *)requiredArguments {
  24. return [NSDictionary dictionaryWithObjectsAndKeys:
  25. @"Path to the ticket store to add to", @"store",
  26. @"Product ID for the new ticket", @"productid",
  27. @"Product version for the new ticket", @"version",
  28. @"Existence checker path", @"xcpath",
  29. @"Server URL", @"url",
  30. nil];
  31. } // requiredArguments
  32. - (BOOL)runWithArguments:(NSDictionary *)args {
  33. // Grab the ticket store
  34. NSString *storePath = [args objectForKey:@"store"];
  35. KSTicketStore *ticketStore = [KSTicketStore ticketStoreWithPath:storePath];
  36. // Extract the values for the new ticket.
  37. NSString *productID = [args objectForKey:@"productid"];
  38. NSString *version = [args objectForKey:@"version"];
  39. // Make a path existence checker. Exercise for the reader is to
  40. // add support for the Spotlight / LunchServices existence checkers.
  41. NSString *xcpath = [args objectForKey:@"xcpath"];
  42. KSExistenceChecker *existenceChecker =
  43. [KSPathExistenceChecker checkerWithPath:xcpath];
  44. // Build the server URL.
  45. NSString *urlString = [args objectForKey:@"url"];
  46. NSURL *serverURL = [NSURL URLWithString:urlString];
  47. // Now that all of the pieces are together, make the ticket.
  48. KSTicket *ticket = [KSTicket ticketWithProductID:productID
  49. version:version
  50. existenceChecker:existenceChecker
  51. serverURL:serverURL];
  52. BOOL result = [ticketStore storeTicket:ticket];
  53. return result;
  54. } // runWithArguments
  55. @end // ERAddTicketCommand