| OLD | NEW |
| (Empty) |
| 1 // Copyright 2009 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 // ======================================================================== | |
| 15 // | |
| 16 // BCJ encodes a file to increase its compressibility. | |
| 17 | |
| 18 #include <windows.h> | |
| 19 #include <shellapi.h> | |
| 20 | |
| 21 #include "base/basictypes.h" | |
| 22 #include "base/scoped_ptr.h" | |
| 23 #include "third_party/smartany/scoped_any.h" | |
| 24 | |
| 25 extern "C" { | |
| 26 #include "third_party/lzma/v4_65/files/C/Bra.h" | |
| 27 } | |
| 28 | |
| 29 int wmain(int argc, WCHAR* argv[], WCHAR* env[]) { | |
| 30 UNREFERENCED_PARAMETER(env); | |
| 31 | |
| 32 if (argc < 3) { | |
| 33 return 1; | |
| 34 } | |
| 35 | |
| 36 // argv[1] is the input file, argv[2] is the output file. | |
| 37 scoped_hfile file(::CreateFile(argv[1], GENERIC_READ, 0, | |
| 38 NULL, OPEN_EXISTING, 0, NULL)); | |
| 39 if (!valid(file)) { | |
| 40 return 2; | |
| 41 } | |
| 42 | |
| 43 LARGE_INTEGER file_size_data; | |
| 44 if (!::GetFileSizeEx(get(file), &file_size_data)) { | |
| 45 return 3; | |
| 46 } | |
| 47 | |
| 48 DWORD file_size = static_cast<DWORD>(file_size_data.QuadPart); | |
| 49 scoped_array<uint8> buffer(new uint8[file_size]); | |
| 50 DWORD bytes_read = 0; | |
| 51 if (!::ReadFile(get(file), buffer.get(), file_size, &bytes_read, NULL) || | |
| 52 bytes_read != file_size) { | |
| 53 return 4; | |
| 54 } | |
| 55 | |
| 56 uint32 conversion_state; | |
| 57 x86_Convert_Init(conversion_state); | |
| 58 // processed might be less than bytes read. This is apparently OK, although | |
| 59 // I don't understand why! | |
| 60 uint32 processed = x86_Convert(buffer.get(), | |
| 61 bytes_read, | |
| 62 0, | |
| 63 &conversion_state, | |
| 64 1 /* encoding */); | |
| 65 | |
| 66 reset(file, ::CreateFile(argv[2], GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, | |
| 67 NULL)); | |
| 68 if (!valid(file)) { | |
| 69 return 6; | |
| 70 } | |
| 71 | |
| 72 DWORD bytes_written = 0; | |
| 73 if (!::WriteFile(get(file), buffer.get(), bytes_read, &bytes_written, NULL)) { | |
| 74 return 7; | |
| 75 } | |
| 76 | |
| 77 return 0; | |
| 78 } | |
| OLD | NEW |