1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 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 #ifndef UPDATER_FILE_PATCH_H 17 #define UPDATER_FILE_PATCH_H 18 19 #include "pkg_manager.h" 20 #include "script_instruction.h" 21 #include "script_manager.h" 22 23 namespace Updater { 24 class USInstrImagePatch : public Uscript::UScriptInstruction { 25 public: 26 struct ImagePatchPara { 27 std::string partName {}; 28 std::string devPath {}; 29 std::string srcSize {}; 30 std::string srcHash {}; 31 std::string destSize {}; 32 std::string destHash {}; 33 std::string patchFile {}; 34 }; USInstrImagePatch()35 USInstrImagePatch() {} ~USInstrImagePatch()36 virtual ~USInstrImagePatch() {} 37 int32_t Execute(Uscript::UScriptEnv &env, Uscript::UScriptContext &context) override; 38 private: 39 int32_t GetParam(Uscript::UScriptContext &context, ImagePatchPara ¶); 40 std::string GetPatchFile(Uscript::UScriptEnv &env, const ImagePatchPara ¶); 41 int32_t ExecuteImagePatch(Uscript::UScriptEnv &env, Uscript::UScriptContext &context); 42 std::string GetSourceFile(const ImagePatchPara ¶); 43 int32_t ApplyPatch(const ImagePatchPara ¶, const std::string &patchFile); 44 std::string GetFileHash(const std::string &file); 45 }; 46 47 class USInstrImageShaCheck : public Uscript::UScriptInstruction { 48 public: 49 struct CheckPara { 50 std::string partName {}; 51 std::string devPath {}; 52 std::string srcSize {}; 53 std::string srcHash {}; 54 std::string destSize {}; 55 std::string destHash {}; 56 }; USInstrImageShaCheck()57 USInstrImageShaCheck() {} ~USInstrImageShaCheck()58 virtual ~USInstrImageShaCheck() {} 59 int32_t Execute(Uscript::UScriptEnv &env, Uscript::UScriptContext &context) override; 60 private: 61 int32_t ExecuteShaCheck(Uscript::UScriptEnv &env, Uscript::UScriptContext &context); 62 int32_t GetParam(Uscript::UScriptContext &context, CheckPara ¶); 63 int32_t CheckHash(const CheckPara ¶); 64 }; 65 } 66 #endif // UPDATER_FILE_PATCH_H 67