1 /* 2 * Copyright (c) 2023 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 #ifndef UPDATE_BIN_PROCESS_H 16 #define UPDATE_BIN_PROCESS_H 17 18 #include <string> 19 #include "macros_updater.h" 20 #include "component_processor.h" 21 #include "package/pkg_manager.h" 22 #include "script_instruction.h" 23 #include "script_manager.h" 24 25 namespace Updater { 26 class UScriptInstructionBinFlowWrite : public Uscript::UScriptInstruction { 27 public: UScriptInstructionBinFlowWrite()28 UScriptInstructionBinFlowWrite() {} ~UScriptInstructionBinFlowWrite()29 virtual ~UScriptInstructionBinFlowWrite() {} 30 int32_t Execute(Uscript::UScriptEnv &env, Uscript::UScriptContext &context) override; 31 void SetProportion(float proportion); 32 33 protected: 34 virtual int32_t ProcessBinFile(Uscript::UScriptEnv &env, Uscript::UScriptContext &context, 35 Hpackage::PkgManager::StreamPtr stream); 36 int32_t ComponentProcess(Uscript::UScriptEnv &env, Hpackage::PkgManager::StreamPtr stream, 37 const std::string &name, const Hpackage::FileInfo &fileInfo); 38 bool isStopRun_ = false; 39 40 private: 41 int32_t ExtractBinFile(Uscript::UScriptEnv &env, Uscript::UScriptContext &context, 42 Hpackage::PkgManager::StreamPtr stream); 43 int32_t UnCompressDataProducer(const Hpackage::PkgBuffer &buffer, size_t size, size_t start, 44 bool isFinish, const void* context); 45 size_t GetFileLength(); 46 bool ReadFromBinFile(Hpackage::PkgBuffer &buffer, size_t start, size_t &readLen); 47 bool CheckEsDeviceUpdate(const Hpackage::FileInfo &fileInfo); 48 bool IsMatchedCsEsIamge(const Hpackage::FileInfo &fileInfo); 49 float fullUpdateProportion_ = 1.0f; 50 size_t stashDataSize_ = 0; 51 Hpackage::PkgBuffer stashBuffer_ {}; 52 }; 53 } // namespace Updater 54 #endif // UPDATE_BIN_PROCESS_H