gcapi_example_client.mm revision 5821806d5e7f356e8fa4b058a389a808ea183019
1// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "chrome/installer/gcapi_mac/gcapi.h" 6 7#import <Foundation/Foundation.h> 8#include <getopt.h> 9 10#include <string> 11 12void Usage() { 13 fprintf(stderr, 14"usage: gcapi_example [options]\n" 15"\n" 16"options:\n" 17" --criteria-check exit after criteria check\n" 18" --force-reinstall delete Google Chrome from Applications first\n" 19" --install <path> copy <path> to /Applications/Google Chrome.app, set up\n" 20" --brand <CODE> set brandcode to <CODE> during installation\n" 21" --launch launch Google Chrome when all is done\n" 22" --help print this message\n" 23); 24} 25 26int main(int argc, char* argv[]) { 27 const option kLongOptions[] = { 28 { "criteria-check", no_argument, NULL, 'c' }, 29 { "force-reinstall", no_argument, NULL, 'r' }, 30 { "install", required_argument, NULL, 'i' }, 31 { "brand", required_argument, NULL, 'b' }, 32 { "launch", no_argument, NULL, 'l' }, 33 { "help", no_argument, NULL, 'h' }, 34 { NULL, 0, NULL, 0 } 35 }; 36 37 std::string source_path; 38 std::string brand_code; 39 bool check_only = false; 40 bool reinstall = false; 41 bool launch = false; 42 int opt; 43 while ((opt = getopt_long(argc, argv, "cri:b:lh", kLongOptions, NULL)) 44 != -1) { 45 switch (opt) { 46 case 'c': 47 check_only = true; 48 break; 49 case 'r': 50 reinstall = true; 51 break; 52 case 'i': 53 source_path = optarg; 54 break; 55 case 'b': 56 brand_code = optarg; 57 break; 58 case 'l': 59 launch = true; 60 break; 61 case 'h': 62 default: 63 Usage(); 64 return 1; 65 } 66 } 67 68 if (reinstall) { 69 [[NSFileManager defaultManager] 70 removeItemAtPath:@"/Applications/Google Chrome.app" error:nil]; 71 } 72 73 unsigned reasons; 74 int can_install = GoogleChromeCompatibilityCheck(&reasons); 75 NSLog(@"can_install: %d, reasons %x", can_install, reasons); 76 if (check_only) 77 return 0; 78 79 if (can_install && !source_path.empty()) { 80 int install_result = InstallGoogleChrome( 81 source_path.c_str(), 82 brand_code.empty() ? NULL : brand_code.c_str(), 83 NULL, 0); 84 NSLog(@"install result: %d", install_result); 85 } 86 87 if (launch) 88 LaunchGoogleChrome(); 89} 90