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 uint32_t ParseIgnoreFileRegex(const std::string &argValue); 90 91 static const struct option CMD_OPTS[]; 92 static const std::string CMD_PARAMS; 93 using HandleArgValue = std::function<uint32_t(const std::string &)>; 94 std::map<int32_t, HandleArgValue> handles_; 95 std::vector<std::string> inputs_; 96 std::string packageName_; 97 std::string output_; 98 std::vector<std::string> resourceHeaderPaths_; 99 bool forceWrite_ = false; 100 std::vector<std::string> moduleNames_; 101 std::string configPath_; 102 std::string restoolPath_; 103 uint32_t startId_ = 0; 104 bool isFileList_ = false; 105 std::vector<std::string> append_; 106 bool combine_ = false; 107 std::string dependEntry_; 108 std::string idDefinedOutput_; 109 std::string idDefinedInputPath_; 110 bool isIconCheck_ = false; 111 TargetConfig targetConfig_; 112 bool isTargetConfig_ = false; 113 std::string targetConfigValue_; 114 std::vector<std::string> sysIdDefinedPaths_; 115 std::string compressionPath_; 116 size_t threadCount_{ 0 }; 117 bool isOverlap_{ false }; 118 }; 119 } // namespace Restool 120 } // namespace Global 121 } // namespace OHOS 122 #endif