• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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) { previewMode_ = enable; };
36 
37 protected:
38     virtual uint32_t CompileSingleFile(const FileInfo &fileInfo);
39     bool MergeResourceItem(const ResourceItem &resourceItem);
40     bool IsXmlFile(const FileInfo &fileInfo) const;
41     bool HasConvertedToSolidXml(const FileInfo &fileInfo) const;
42     bool NeedIfConvertToSolidXml() const;
43     std::string GetOutputFolder(const DirectoryInfo &directoryInfo) const;
44     ResType type_;
45     std::string output_;
46     std::string moduleName_;
47     bool previewMode_ = false;
48 
49     // id, resource items
50     std::map<int32_t, std::vector<ResourceItem>> resourceInfos_;
51     // ResType, name, resourceItems
52     std::map<std::pair<ResType, std::string>, std::vector<ResourceItem>> nameInfos_;
53 
54 private:
55     uint32_t ConvertToSolidXml(const std::map<std::string, std::vector<FileInfo>> &setsByDirectory);
56     uint32_t PostCommit();
57     void ListXmlFile(const std::vector<FileInfo> &fileInfo, std::vector<std::string> &xmlPaths) const;
58 };
59 }
60 }
61 }
62 #endif