| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Helper tool that is built and run during a build to pull strings from | 5 // Helper tool that is built and run during a build to pull strings from |
| 6 // the GRD files and generate the InfoPlist.strings files needed for | 6 // the GRD files and generate the InfoPlist.strings files needed for |
| 7 // Mac OS X app bundles. | 7 // Mac OS X app bundles. |
| 8 | 8 |
| 9 #import <Foundation/Foundation.h> | 9 #import <Foundation/Foundation.h> |
| 10 | 10 |
| 11 #include <stdio.h> | 11 #include <stdio.h> |
| 12 #include <unistd.h> | 12 #include <unistd.h> |
| 13 | 13 |
| 14 #include "base/data_pack.h" | 14 #include "app/data_pack.h" |
| 15 #include "base/file_path.h" | 15 #include "base/file_path.h" |
| 16 #include "base/mac/scoped_nsautorelease_pool.h" | 16 #include "base/mac/scoped_nsautorelease_pool.h" |
| 17 #include "base/scoped_ptr.h" | 17 #include "base/scoped_ptr.h" |
| 18 #include "base/string_piece.h" | 18 #include "base/string_piece.h" |
| 19 #include "base/string_util.h" | 19 #include "base/string_util.h" |
| 20 #include "grit/chromium_strings.h" | 20 #include "grit/chromium_strings.h" |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 NSString* ApplicationVersionString(const char* version_file_path) { | 24 NSString* ApplicationVersionString(const char* version_file_path) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 44 [scanner scanInt:&build] && | 44 [scanner scanInt:&build] && |
| 45 [scanner scanString:@"PATCH=" intoString:nil] && | 45 [scanner scanString:@"PATCH=" intoString:nil] && |
| 46 [scanner scanInt:&patch]) { | 46 [scanner scanInt:&patch]) { |
| 47 return [NSString stringWithFormat:@"%d.%d.%d.%d", | 47 return [NSString stringWithFormat:@"%d.%d.%d.%d", |
| 48 major, minor, build, patch]; | 48 major, minor, build, patch]; |
| 49 } | 49 } |
| 50 fprintf(stderr, "Failed to parse version file\n"); | 50 fprintf(stderr, "Failed to parse version file\n"); |
| 51 return nil; | 51 return nil; |
| 52 } | 52 } |
| 53 | 53 |
| 54 base::DataPack* LoadResourceDataPack(const char* dir_path, | 54 app::DataPack* LoadResourceDataPack(const char* dir_path, |
| 55 const char* branding_strings_name, | 55 const char* branding_strings_name, |
| 56 const char* locale_name) { | 56 const char* locale_name) { |
| 57 base::DataPack* resource_pack = NULL; | 57 ase::DataPack* resource_pack = NULL; |
| 58 | 58 |
| 59 NSString* resource_path = [NSString stringWithFormat:@"%s/%s_%s.pak", | 59 NSString* resource_path = [NSString stringWithFormat:@"%s/%s_%s.pak", |
| 60 dir_path, branding_strings_name, locale_name]; | 60 dir_path, branding_strings_name, locale_name]; |
| 61 if (resource_path) { | 61 if (resource_path) { |
| 62 FilePath resources_pak_path([resource_path fileSystemRepresentation]); | 62 FilePath resources_pak_path([resource_path fileSystemRepresentation]); |
| 63 resource_pack = new base::DataPack; | 63 resource_pack = new ase::DataPack; |
| 64 bool success = resource_pack->Load(resources_pak_path); | 64 bool success = resource_pack->Load(resources_pak_path); |
| 65 if (!success) { | 65 if (!success) { |
| 66 delete resource_pack; | 66 delete resource_pack; |
| 67 resource_pack = NULL; | 67 resource_pack = NULL; |
| 68 } | 68 } |
| 69 } | 69 } |
| 70 | 70 |
| 71 return resource_pack; | 71 return resource_pack; |
| 72 } | 72 } |
| 73 | 73 |
| 74 NSString* LoadStringFromDataPack(base::DataPack* data_pack, | 74 NSString* LoadStringFromDataPack(ase::DataPack* data_pack, |
| 75 const char* data_pack_lang, | 75 const char* data_pack_lang, |
| 76 uint32_t resource_id, | 76 uint32_t resource_id, |
| 77 const char* resource_id_str) { | 77 const char* resource_id_str) { |
| 78 NSString* result = nil; | 78 NSString* result = nil; |
| 79 base::StringPiece data; | 79 base::StringPiece data; |
| 80 if (data_pack->GetStringPiece(resource_id, &data)) { | 80 if (data_pack->GetStringPiece(resource_id, &data)) { |
| 81 // Data pack encodes strings as UTF16. | 81 // Data pack encodes strings as UTF16. |
| 82 result = | 82 result = |
| 83 [[[NSString alloc] initWithBytes:data.data() | 83 [[[NSString alloc] initWithBytes:data.data() |
| 84 length:data.length() | 84 length:data.length() |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 fprintf(stderr, "ERROR: failed to get a version string"); | 197 fprintf(stderr, "ERROR: failed to get a version string"); |
| 198 exit(1); | 198 exit(1); |
| 199 } | 199 } |
| 200 | 200 |
| 201 NSFileManager* fm = [NSFileManager defaultManager]; | 201 NSFileManager* fm = [NSFileManager defaultManager]; |
| 202 | 202 |
| 203 for (int loop = 0; loop < lang_list_count; ++loop) { | 203 for (int loop = 0; loop < lang_list_count; ++loop) { |
| 204 const char* cur_lang = lang_list[loop]; | 204 const char* cur_lang = lang_list[loop]; |
| 205 | 205 |
| 206 // Open the branded string pak file | 206 // Open the branded string pak file |
| 207 scoped_ptr<base::DataPack> branded_data_pack( | 207 scoped_ptr<ase::DataPack> branded_data_pack( |
| 208 LoadResourceDataPack(grit_output_dir, | 208 LoadResourceDataPack(grit_output_dir, |
| 209 branding_strings_name, | 209 branding_strings_name, |
| 210 cur_lang)); | 210 cur_lang)); |
| 211 if (branded_data_pack.get() == NULL) { | 211 if (branded_data_pack.get() == NULL) { |
| 212 fprintf(stderr, "ERROR: Failed to load branded pak for language: %s\n", | 212 fprintf(stderr, "ERROR: Failed to load branded pak for language: %s\n", |
| 213 cur_lang); | 213 cur_lang); |
| 214 exit(1); | 214 exit(1); |
| 215 } | 215 } |
| 216 | 216 |
| 217 uint32_t name_id = IDS_PRODUCT_NAME; | 217 uint32_t name_id = IDS_PRODUCT_NAME; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 [output_path stringByAppendingPathComponent:@"InfoPlist.strings"]; | 296 [output_path stringByAppendingPathComponent:@"InfoPlist.strings"]; |
| 297 if (![strings_file_contents_utf8 writeToFile:output_path | 297 if (![strings_file_contents_utf8 writeToFile:output_path |
| 298 atomically:YES]) { | 298 atomically:YES]) { |
| 299 fprintf(stderr, "ERROR: Failed to write out '%s'\n", | 299 fprintf(stderr, "ERROR: Failed to write out '%s'\n", |
| 300 [output_path UTF8String]); | 300 [output_path UTF8String]); |
| 301 exit(1); | 301 exit(1); |
| 302 } | 302 } |
| 303 } | 303 } |
| 304 return 0; | 304 return 0; |
| 305 } | 305 } |
| OLD | NEW |