OLD | NEW |
---|---|
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #include <vector> | 5 #include <vector> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/at_exit.h" | 8 #include "base/at_exit.h" |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
45 va_end(args); | 45 va_end(args); |
46 exit(1); | 46 exit(1); |
47 } | 47 } |
48 | 48 |
49 std::string ReadOrFail(const std::wstring& file_name, const char* kind) { | 49 std::string ReadOrFail(const std::wstring& file_name, const char* kind) { |
50 #if defined(OS_WIN) | 50 #if defined(OS_WIN) |
51 FilePath file_path(file_name); | 51 FilePath file_path(file_name); |
52 #else | 52 #else |
53 FilePath file_path(WideToASCII(file_name)); | 53 FilePath file_path(WideToASCII(file_name)); |
54 #endif | 54 #endif |
55 int64 file_size = 0; | |
56 if (!file_util::GetFileSize(file_path, &file_size)) | |
57 Problem("Can't read %s file.", kind); | |
55 std::string buffer; | 58 std::string buffer; |
59 buffer.reserve(static_cast<size_t>(file_size)); | |
56 if (!file_util::ReadFileToString(file_path, &buffer)) | 60 if (!file_util::ReadFileToString(file_path, &buffer)) |
57 Problem("Can't read %s file.", kind); | 61 Problem("Can't read %s file.", kind); |
58 return buffer; | 62 return buffer; |
59 } | 63 } |
60 | 64 |
61 void WriteSinkToFile(const courgette::SinkStream *sink, | 65 void WriteSinkToFile(const courgette::SinkStream *sink, |
62 const std::wstring& output_file) { | 66 const std::wstring& output_file) { |
63 #if defined(OS_WIN) | 67 #if defined(OS_WIN) |
64 FilePath output_path(output_file); | 68 FilePath output_path(output_file); |
65 #else | 69 #else |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
278 courgette::GenerateEnsemblePatch(&old_stream, &new_stream, &patch_stream); | 282 courgette::GenerateEnsemblePatch(&old_stream, &new_stream, &patch_stream); |
279 | 283 |
280 if (status != courgette::C_OK) Problem("-gen failed."); | 284 if (status != courgette::C_OK) Problem("-gen failed."); |
281 | 285 |
282 WriteSinkToFile(&patch_stream, patch_file); | 286 WriteSinkToFile(&patch_stream, patch_file); |
283 } | 287 } |
284 | 288 |
285 void ApplyEnsemblePatch(const std::wstring& old_file, | 289 void ApplyEnsemblePatch(const std::wstring& old_file, |
286 const std::wstring& patch_file, | 290 const std::wstring& patch_file, |
287 const std::wstring& new_file) { | 291 const std::wstring& new_file) { |
292 // We do things a little differently here in order to call the same Courgette | |
293 // entry point as the installer. That entry point point takes file names and | |
294 // returns an status code but does not output any diagnostics. | |
295 #if defined(OS_WIN) | |
296 FilePath old_path(old_file); | |
297 FilePath patch_path(patch_file); | |
298 FilePath new_path(new_file); | |
299 #else | |
300 FilePath old_path(WideToASCII(old_file)); | |
301 FilePath patch_path(WideToASCII(patch_file)); | |
302 FilePath new_path(WideToASCII(new_file)); | |
303 #endif | |
304 | |
305 courgette::Status status = | |
306 courgette::ApplyEnsemblePatch(old_path.value().c_str(), | |
tommi (sloooow) - chröme
2011/02/23 06:35:59
would it be simpler to make all ApplyEnsemplePatch
sra1
2011/02/23 06:51:59
I would like to keep the entry point with as simpl
| |
307 patch_path.value().c_str(), | |
308 new_path.value().c_str()); | |
309 | |
310 if (status == courgette::C_OK) | |
311 return; | |
312 | |
313 // Diagnose the error. | |
288 std::string old_buffer = ReadOrFail(old_file, "'old' input"); | 314 std::string old_buffer = ReadOrFail(old_file, "'old' input"); |
tommi (sloooow) - chröme
2011/02/23 06:35:59
remove these calls?
sra1
2011/02/23 06:51:59
If the file does not exist, this is what gives the
| |
315 old_buffer.clear(); | |
289 std::string patch_buffer = ReadOrFail(patch_file, "'patch' input"); | 316 std::string patch_buffer = ReadOrFail(patch_file, "'patch' input"); |
317 patch_buffer.clear(); | |
290 | 318 |
291 courgette::SourceStream old_stream; | 319 if (status == courgette::C_WRITE_OPEN_ERROR) |
292 courgette::SourceStream patch_stream; | 320 Problem("Can't open output"); |
293 old_stream.Init(old_buffer); | 321 if (status == courgette::C_WRITE_ERROR) |
294 patch_stream.Init(patch_buffer); | 322 Problem("Can't write output"); |
295 courgette::SinkStream new_stream; | |
296 courgette::Status status = | |
297 courgette::ApplyEnsemblePatch(&old_stream, &patch_stream, &new_stream); | |
298 | 323 |
299 if (status != courgette::C_OK) Problem("-apply failed."); | 324 Problem("-apply failed."); |
300 | |
301 WriteSinkToFile(&new_stream, new_file); | |
302 } | 325 } |
303 | 326 |
304 void GenerateBSDiffPatch(const std::wstring& old_file, | 327 void GenerateBSDiffPatch(const std::wstring& old_file, |
305 const std::wstring& new_file, | 328 const std::wstring& new_file, |
306 const std::wstring& patch_file) { | 329 const std::wstring& patch_file) { |
307 std::string old_buffer = ReadOrFail(old_file, "'old' input"); | 330 std::string old_buffer = ReadOrFail(old_file, "'old' input"); |
308 std::string new_buffer = ReadOrFail(new_file, "'new' input"); | 331 std::string new_buffer = ReadOrFail(new_file, "'new' input"); |
309 | 332 |
310 courgette::SourceStream old_stream; | 333 courgette::SourceStream old_stream; |
311 courgette::SourceStream new_stream; | 334 courgette::SourceStream new_stream; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
422 } else if (cmd_spread_1_adjusted || cmd_spread_1_unadjusted) { | 445 } else if (cmd_spread_1_adjusted || cmd_spread_1_unadjusted) { |
423 if (values.size() != 3) | 446 if (values.size() != 3) |
424 UsageProblem("-gen1[au] <old_file> <new_file> <patch_files_root>"); | 447 UsageProblem("-gen1[au] <old_file> <new_file> <patch_files_root>"); |
425 DisassembleAdjustDiff(values[0], values[1], values[2], | 448 DisassembleAdjustDiff(values[0], values[1], values[2], |
426 cmd_spread_1_adjusted); | 449 cmd_spread_1_adjusted); |
427 } else { | 450 } else { |
428 UsageProblem("No operation specified"); | 451 UsageProblem("No operation specified"); |
429 } | 452 } |
430 } | 453 } |
431 } | 454 } |
OLD | NEW |