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.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 32 protected: 33 virtual int32_t ProcessBinFile(Uscript::UScriptEnv &env, Uscript::UScriptContext &context, 34 Hpackage::PkgManager::StreamPtr stream); 35 int32_t ComponentProcess(Uscript::UScriptEnv &env, Hpackage::PkgManager::StreamPtr stream, 36 const std::string &name, const size_t fileSize); 37 bool isStopRun_ = false; 38 39 private: 40 int32_t ExtractBinFile(Uscript::UScriptEnv &env, Uscript::UScriptContext &context, 41 Hpackage::PkgManager::StreamPtr stream); 42 int32_t UnCompressDataProducer(const Hpackage::PkgBuffer &buffer, size_t size, size_t start, 43 bool isFinish, const void* context); 44 size_t GetFileLength(); 45 bool ReadFromBinFile(Hpackage::PkgBuffer &buffer, size_t start, size_t &readLen); 46 47 size_t stashDataSize_ = 0; 48 Hpackage::PkgBuffer stashBuffer_ {}; 49 }; 50 } // namespace Updater 51 #endif // UPDATE_BIN_PROCESS_H