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 // This file contains the code to apply a Courgette patch. | 5 // This file contains the code to apply a Courgette patch. |
6 | 6 |
7 #include "courgette/ensemble.h" | 7 #include "courgette/ensemble.h" |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 SourceStream final_patch_prediction; | 344 SourceStream final_patch_prediction; |
345 final_patch_prediction.Init(original_ensemble_and_corrected_base_elements); | 345 final_patch_prediction.Init(original_ensemble_and_corrected_base_elements); |
346 status = patch_process.SubpatchFinalOutput(&final_patch_prediction, | 346 status = patch_process.SubpatchFinalOutput(&final_patch_prediction, |
347 ensemble_correction, output); | 347 ensemble_correction, output); |
348 if (status != C_OK) | 348 if (status != C_OK) |
349 return status; | 349 return status; |
350 | 350 |
351 return C_OK; | 351 return C_OK; |
352 } | 352 } |
353 | 353 |
354 Status ApplyEnsemblePatch(const wchar_t* old_file_name, | 354 Status ApplyEnsemblePatch(const FilePath::CharType* old_file_name, |
355 const wchar_t* patch_file_name, | 355 const FilePath::CharType* patch_file_name, |
356 const wchar_t* new_file_name) { | 356 const FilePath::CharType* new_file_name) { |
357 Status status; | 357 Status status; |
358 | 358 |
359 // First read enough of the patch file to validate the header is well-formed. | 359 // First read enough of the patch file to validate the header is well-formed. |
360 // A few varint32 numbers should fit in 100. | 360 // A few varint32 numbers should fit in 100. |
361 FilePath patch_file_path(patch_file_name); | 361 FilePath patch_file_path(patch_file_name); |
362 const int BIG_ENOUGH_FOR_HEADER = 100; | 362 const int BIG_ENOUGH_FOR_HEADER = 100; |
363 char buffer[BIG_ENOUGH_FOR_HEADER]; | 363 char buffer[BIG_ENOUGH_FOR_HEADER]; |
364 int read_count = | 364 int read_count = |
365 file_util::ReadFile(patch_file_path, buffer, sizeof(buffer)); | 365 file_util::ReadFile(patch_file_path, buffer, sizeof(buffer)); |
366 if (read_count < 0) | 366 if (read_count < 0) |
(...skipping 29 matching lines...) Expand all Loading... |
396 | 396 |
397 // Write the patched data to |new_file_name|. | 397 // Write the patched data to |new_file_name|. |
398 FilePath new_file_path(new_file_name); | 398 FilePath new_file_path(new_file_name); |
399 int written = | 399 int written = |
400 file_util::WriteFile( | 400 file_util::WriteFile( |
401 new_file_path, | 401 new_file_path, |
402 reinterpret_cast<const char*>(new_sink_stream.Buffer()), | 402 reinterpret_cast<const char*>(new_sink_stream.Buffer()), |
403 new_sink_stream.Length()); | 403 new_sink_stream.Length()); |
404 if (written == -1) | 404 if (written == -1) |
405 return C_WRITE_OPEN_ERROR; | 405 return C_WRITE_OPEN_ERROR; |
406 if (written != new_sink_stream.Length()) | 406 if (static_cast<size_t>(written) != new_sink_stream.Length()) |
407 return C_WRITE_ERROR; | 407 return C_WRITE_ERROR; |
408 | 408 |
409 return C_OK; | 409 return C_OK; |
410 } | 410 } |
411 | 411 |
412 } // namespace | 412 } // namespace |
OLD | NEW |