• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024-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_PACKAGE_PARSER_H
17 #define OHOS_RESTOOL_PACKAGE_PARSER_H
18 
19 #include <functional>
20 #include <getopt.h>
21 #include <string>
22 #include <iostream>
23 #include "resource_data.h"
24 #include "restool_errors.h"
25 
26 namespace OHOS {
27 namespace Global {
28 namespace Restool {
29 class PackageParser {
30 public:
PackageParser()31     PackageParser(){};
32     virtual ~PackageParser() = default;
33     uint32_t Parse(int argc, char *argv[]);
34     uint32_t ExecCommand();
35     const std::vector<std::string> &GetInputs() const;
36     const std::string &GetPackageName() const;
37     const std::string &GetOutput() const;
38     const std::vector<std::string> &GetResourceHeaders() const;
39     bool GetForceWrite() const;
40     const std::vector<std::string> &GetModuleNames() const;
41     const std::string &GetConfig() const;
42     const std::string &GetRestoolPath() const;
43     uint32_t GetStartId() const;
44     bool IsFileList() const;
45     const std::vector<std::string> &GetAppend() const;
46     bool GetCombine() const;
47     const std::string &GetDependEntry() const;
48     const std::string &GetIdDefinedOutput() const;
49     const std::string &GetIdDefinedInputPath() const;
50     bool GetIconCheck() const;
51     const TargetConfig &GetTargetConfigValues() const;
52     bool IsTargetConfig() const;
53     const std::vector<std::string> &GetSysIdDefinedPaths() const;
54     const std::string &GetCompressionPath() const;
55     bool IsOverlap() const;
56     size_t GetThreadCount() const;
57 
58 private:
59     void InitCommand();
60     uint32_t ParseCommand(int argc, char *argv[]);
61     uint32_t CheckError(int argc, char *argv[], int c, int optIndex);
62     uint32_t AddInput(const std::string &argValue);
63     bool IsOverlapInput(const std::string& inputPath);
64     uint32_t AddPackageName(const std::string &argValue);
65     uint32_t AddOutput(const std::string &argValue);
66     uint32_t AddResourceHeader(const std::string &argValue);
67     uint32_t ForceWrite();
68     uint32_t PrintVersion();
69     uint32_t AddMoudleNames(const std::string &argValue);
70     uint32_t AddConfig(const std::string &argValue);
71     uint32_t AddStartId(const std::string &argValue);
72     void AdaptResourcesDirForInput();
73     uint32_t CheckParam() const;
74     uint32_t HandleProcess(int c, const std::string &argValue);
75     uint32_t ParseFileList(const std::string &fileListPath);
76     uint32_t AddAppend(const std::string &argValue);
77     uint32_t SetCombine();
78     uint32_t AddDependEntry(const std::string &argValue);
79     uint32_t ShowHelp() const;
80     uint32_t SetIdDefinedOutput(const std::string &argValue);
81     uint32_t SetIdDefinedInputPath(const std::string &argValue);
82     uint32_t AddSysIdDefined(const std::string &argValue);
83     bool IsAscii(const std::string &argValue) const;
84     bool IsLongOpt(int argc, char *argv[]) const;
85     uint32_t IconCheck();
86     uint32_t ParseTargetConfig(const std::string &argValue);
87     uint32_t AddCompressionPath(const std::string &argValue);
88     uint32_t ParseThread(const std::string &argValue);
89 
90     static const struct option CMD_OPTS[];
91     static const std::string CMD_PARAMS;
92     using HandleArgValue = std::function<uint32_t(const std::string &)>;
93     std::map<int32_t, HandleArgValue> handles_;
94     std::vector<std::string> inputs_;
95     std::string packageName_;
96     std::string output_;
97     std::vector<std::string> resourceHeaderPaths_;
98     bool forceWrite_ = false;
99     std::vector<std::string> moduleNames_;
100     std::string configPath_;
101     std::string restoolPath_;
102     uint32_t startId_ = 0;
103     bool isFileList_ = false;
104     std::vector<std::string> append_;
105     bool combine_ = false;
106     std::string dependEntry_;
107     std::string idDefinedOutput_;
108     std::string idDefinedInputPath_;
109     bool isIconCheck_ = false;
110     TargetConfig targetConfig_;
111     bool isTargetConfig_ = false;
112     std::string targetConfigValue_;
113     std::vector<std::string> sysIdDefinedPaths_;
114     std::string compressionPath_;
115     size_t threadCount_{ 0 };
116     bool isOverlap_{ false };
117 };
118 } // namespace Restool
119 } // namespace Global
120 } // namespace OHOS
121 #endif