• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 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 OHOS_RESTOOL_BINARY_FILE_PACKER_H
17 #define OHOS_RESTOOL_BINARY_FILE_PACKER_H
18 
19 #include "cmd/package_parser.h"
20 #include "resource_util.h"
21 #include "thread_pool.h"
22 
23 namespace OHOS {
24 namespace Global {
25 namespace Restool {
26 class BinaryFilePacker {
27 public:
28     explicit BinaryFilePacker(const PackageParser &packageParser, const std::string &moduleName);
29     ~BinaryFilePacker();
30     std::future<uint32_t> CopyBinaryFileAsync(const std::vector<std::string> &inputs);
31     void StopCopy();
32 
33 protected:
34     virtual uint32_t CopyBinaryFile(const std::vector<std::string> &inputs);
35     uint32_t CheckCopyResults();
36     uint32_t CopyBinaryFile(const std::string &input);
37     virtual bool IsDuplicated(const std::unique_ptr<FileEntry> &entry, std::string subPath);
38     PackageParser packageParser_;
39     std::string moduleName_;
40     std::vector<std::future<uint32_t>> copyResults_;
41     std::atomic<bool> stopCopy_{false};
42     std::mutex mutex_;
43 
44 private:
45     uint32_t CopyBinaryFile(const std::string &filePath, const std::string &fileType);
46     uint32_t CopyBinaryFileImpl(const std::string &src, const std::string &dst);
47     uint32_t CopySingleFile(const std::string &path, std::string &subPath);
48 };
49 } // namespace Restool
50 } // namespace Global
51 } // namespace OHOS
52 #endif
53