1 /* 2 * Copyright (c) 2021 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_RESOURCE_COMPILER_H 17 #define OHOS_RESTOOL_RESOURCE_COMPILER_H 18 19 #include<vector> 20 #include "increment_manager.h" 21 #include "resource_data.h" 22 #include "resource_item.h" 23 24 namespace OHOS { 25 namespace Global { 26 namespace Restool { 27 class IResourceCompiler { 28 public: 29 IResourceCompiler(ResType type, const std::string &output); 30 virtual ~IResourceCompiler(); 31 uint32_t Compile(const std::vector<DirectoryInfo> &directoryInfos); 32 const std::map<int32_t, std::vector<ResourceItem>> &GetResult() const; 33 uint32_t Compile(const FileInfo &fileInfo); 34 void SetModuleName(const std::string &moduleName); SetPreviewMode(bool enable)35 void SetPreviewMode(bool enable) 36 { 37 previewMode_ = enable; 38 }; 39 uint32_t CompileForAppend(const FileInfo &fileInfo); 40 const std::map<std::pair<ResType, std::string>, std::vector<ResourceItem>> &GetResourceItems() const; 41 42 protected: 43 virtual uint32_t CompileSingleFile(const FileInfo &fileInfo); 44 bool MergeResourceItem(const ResourceItem &resourceItem); 45 bool IsXmlFile(const FileInfo &fileInfo) const; 46 bool HasConvertedToSolidXml(const FileInfo &fileInfo) const; 47 bool NeedIfConvertToSolidXml() const; 48 std::string GetOutputFolder(const DirectoryInfo &directoryInfo) const; 49 ResType type_; 50 std::string output_; 51 std::string moduleName_; 52 bool previewMode_ = false; 53 54 // id, resource items 55 std::map<int32_t, std::vector<ResourceItem>> resourceInfos_; 56 // ResType, name, resourceItems 57 std::map<std::pair<ResType, std::string>, std::vector<ResourceItem>> nameInfos_; 58 59 private: 60 uint32_t ConvertToSolidXml(const std::map<std::string, std::vector<FileInfo>> &setsByDirectory); 61 uint32_t PostCommit(); 62 void ListXmlFile(const std::vector<FileInfo> &fileInfo, std::vector<std::string> &xmlPaths) const; 63 }; 64 } 65 } 66 } 67 #endif