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
25namespace Updater {
26class UScriptInstructionBinFlowWrite : public Uscript::UScriptInstruction {
27public:
28    UScriptInstructionBinFlowWrite() {}
29    virtual ~UScriptInstructionBinFlowWrite() {}
30    int32_t Execute(Uscript::UScriptEnv &env, Uscript::UScriptContext &context) override;
31
32protected:
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 Hpackage::FileInfo &fileInfo);
37    bool isStopRun_ = false;
38
39private:
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    bool CheckEsDeviceUpdate(const Hpackage::FileInfo &fileInfo);
47    bool IsMatchedCsEsIamge(const Hpackage::FileInfo &fileInfo);
48    float fullUpdateProportion_ = 1.0f;
49    size_t stashDataSize_ = 0;
50    Hpackage::PkgBuffer stashBuffer_ {};
51};
52} // namespace Updater
53#endif // UPDATE_BIN_PROCESS_H