| 126 | } |
| 127 | |
| 128 | DiffApplicationResult ApplyDiff(std::string const & oldMwmPath, std::string const & newMwmPath, |
| 129 | std::string const & diffPath, base::Cancellable const & cancellable) |
| 130 | { |
| 131 | try |
| 132 | { |
| 133 | FileReader oldReader(oldMwmPath); |
| 134 | BufferedFileWriter newWriter(newMwmPath); |
| 135 | FileReader diffFileReader(diffPath); |
| 136 | |
| 137 | ReaderSource<FileReader> diffFileSource(diffFileReader); |
| 138 | auto const version = ReadPrimitiveFromSource<uint32_t>(diffFileSource); |
| 139 | |
| 140 | switch (version) |
| 141 | { |
| 142 | case VERSION_V0: return ApplyDiffVersion0(oldReader, newWriter, diffFileSource, cancellable); |
| 143 | default: LOG(LERROR, ("Unknown version format of mwm diff:", version)); return DiffApplicationResult::Failed; |
| 144 | } |
| 145 | } |
| 146 | catch (Reader::Exception const & e) |
| 147 | { |
| 148 | LOG(LERROR, ("Could not open file for reading when applying a patch:", e.Msg())); |
| 149 | } |
| 150 | catch (Writer::Exception const & e) |
| 151 | { |
| 152 | LOG(LERROR, ("Could not open file for writing when applying a patch:", e.Msg())); |
| 153 | } |
| 154 | |
| 155 | return cancellable.IsCancelled() ? DiffApplicationResult::Cancelled : DiffApplicationResult::Failed; |
| 156 | } |
| 157 | |
| 158 | std::string DebugPrint(DiffApplicationResult const & result) |
| 159 | { |