Signed-off-by: HanSY <hansiyuan1@huawei.com>
This commit is contained in:
HanSY
2024-12-09 11:38:19 +08:00
parent 06972263b8
commit ec486b34df
30 changed files with 516 additions and 199 deletions
+10 -9
View File
@@ -29,22 +29,23 @@ public:
~BinaryFilePacker();
std::future<uint32_t> CopyBinaryFileAsync(const std::vector<std::string> &inputs);
void StopCopy();
void SetCopyHap(bool state);
private:
uint32_t CopyBinaryFile(const std::vector<std::string> &inputs);
uint32_t CopyBinaryFile(const std::string &filePath, const std::string &fileType);
uint32_t CopyBinaryFileImpl(const std::string &src, const std::string &dst);
uint32_t CopySingleFile(const std::string &path, std::string &subPath);
uint32_t CopyBinaryFileWithHap(const std::vector<std::string> &inputs);
bool IsDefinedFile(const std::unique_ptr<FileEntry> &entry, std::string subPath);
protected:
virtual uint32_t CopyBinaryFile(const std::vector<std::string> &inputs);
uint32_t CheckCopyResults();
uint32_t CopyBinaryFile(const std::string &input);
virtual bool IsDuplicated(const std::unique_ptr<FileEntry> &entry, std::string subPath);
PackageParser packageParser_;
std::string moduleName_;
ThreadPool threadPool_;
std::vector<std::future<uint32_t>> copyResults_;
std::atomic<bool> stopCopy_{false};
bool copyHap_{false};
std::mutex mutex_;
private:
uint32_t CopyBinaryFile(const std::string &filePath, const std::string &fileType);
uint32_t CopyBinaryFileImpl(const std::string &src, const std::string &dst);
uint32_t CopySingleFile(const std::string &path, std::string &subPath);
};
} // namespace Restool
} // namespace Global
+1 -1
View File
@@ -57,7 +57,7 @@ public:
bool IsTargetConfig() const;
const std::vector<std::string> &GetSysIdDefinedPaths() const;
const std::string &GetCompressionPath() const;
bool ExistHapInput();
bool IsOverlap() const;
private:
void InitCommand();
+1 -1
View File
@@ -24,7 +24,7 @@ namespace Global {
namespace Restool {
class FactoryResourceCompiler {
public:
static std::unique_ptr<IResourceCompiler> CreateCompiler(ResType type, const std::string &output);
static std::unique_ptr<IResourceCompiler> CreateCompiler(ResType type, const std::string &output, bool isHap);
static std::unique_ptr<IResourceCompiler> CreateCompilerForAppend(ResType type, const std::string &output);
};
}
+32
View File
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2021-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_RESTOOL_FACTORY_RESOURCE_PACKER_H
#define OHOS_RESTOOL_FACTORY_RESOURCE_PACKER_H
#include <memory>
#include "resource_pack.h"
namespace OHOS {
namespace Global {
namespace Restool {
class FactoryResourcePacker {
public:
static std::unique_ptr<ResourcePack> CreatePacker(PackType type, const PackageParser &packageParser);
};
}
}
}
#endif
-1
View File
@@ -35,7 +35,6 @@ public:
{
moduleName_ = moduleName;
};
void MarkItemsAsHap();
uint32_t MergeResourceItem(const std::map<int64_t, std::vector<ResourceItem>> &resourceInfos);
bool ScaleIcons(const std::string &output, const std::map<std::string, std::set<uint32_t>> &iconMap);
void SetScanHap(bool state);
+7 -5
View File
@@ -24,17 +24,19 @@ namespace Global {
namespace Restool {
class GenericCompiler : public IResourceCompiler {
public:
GenericCompiler(ResType type, const std::string &output);
GenericCompiler(ResType type, const std::string &output, bool isOverlap = false);
virtual ~GenericCompiler();
protected:
std::string GetOutputFilePath(const FileInfo &fileInfo) const;
virtual bool IsIgnore(const FileInfo &fileInfo);
uint32_t CompileSingleFile(const FileInfo &fileInfo) override;
uint32_t CompileFiles(const std::vector<FileInfo> &fileInfos) override;
bool PostMediaFile(const FileInfo &fileInfo, const std::string &output);
private:
std::string GetOutputFilePath(const FileInfo &fileInfo) const;
bool IsIgnore(const FileInfo &fileInfo);
bool CopyMediaFile(const FileInfo &fileInfo, std::string &output);
std::mutex mutex_;
private:
bool CopyMediaFile(const FileInfo &fileInfo, std::string &output);
};
}
}
+2 -3
View File
@@ -25,7 +25,7 @@ namespace Global {
namespace Restool {
class IResourceCompiler {
public:
IResourceCompiler(ResType type, const std::string &output);
IResourceCompiler(ResType type, const std::string &output, bool isOverlap = false);
virtual ~IResourceCompiler();
uint32_t Compile(const std::vector<DirectoryInfo> &directoryInfos);
const std::map<int64_t, std::vector<ResourceItem>> &GetResult() const;
@@ -33,7 +33,6 @@ public:
void SetModuleName(const std::string &moduleName);
uint32_t CompileForAppend(const FileInfo &fileInfo);
const std::map<std::pair<ResType, std::string>, std::vector<ResourceItem>> &GetResourceItems() const;
void SetHapRes(bool state);
protected:
virtual uint32_t CompileSingleFile(const FileInfo &fileInfo);
@@ -43,7 +42,7 @@ protected:
ResType type_;
std::string output_;
std::string moduleName_;
bool hapRes_ = false;
bool isOverlap_;
// id, resource items
std::map<int64_t, std::vector<ResourceItem>> resourceInfos_;
+1 -1
View File
@@ -26,7 +26,7 @@ namespace Global {
namespace Restool {
class JsonCompiler : public IResourceCompiler {
public:
JsonCompiler(ResType type, const std::string &output);
JsonCompiler(ResType type, const std::string &output, bool isOverlap = false);
virtual ~JsonCompiler();
protected:
uint32_t CompileSingleFile(const FileInfo &fileInfo) override;
+35
View File
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2021-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_RESTOOL_OVERLAP_BINARY_FILE_PACKER_H
#define OHOS_RESTOOL_OVERLAP_BINARY_FILE_PACKER_H
#include "binary_file_packer.h"
namespace OHOS {
namespace Global {
namespace Restool {
class OverlapBinaryFilePacker : public BinaryFilePacker {
public:
OverlapBinaryFilePacker(const PackageParser &packageParser, const std::string &moduleName);
protected:
uint32_t CopyBinaryFile(const std::vector<std::string> &inputs);
bool IsDuplicated(const std::unique_ptr<FileEntry> &entry, std::string subPath);
};
}
}
}
#endif
+34
View File
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2021-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_RESTOOL_OVERLAP_COMPILER_H
#define OHOS_RESTOOL_OVERLAP_COMPILER_H
#include "generic_compiler.h"
namespace OHOS {
namespace Global {
namespace Restool {
class OverlapCompiler : public GenericCompiler {
public:
OverlapCompiler(ResType type, const std::string &output, bool isOverlap = false);
protected:
bool IsIgnore(const FileInfo &fileInfo);
};
}
}
}
#endif
+6 -1
View File
@@ -49,7 +49,7 @@ const static std::string SOLUTIONS_ARROW = "> ";
const static std::string LONG_PATH_HEAD = "\\\\?\\";
const static int32_t VERSION_MAX_LEN = 128;
const static int32_t INT_TO_BYTES = sizeof(uint32_t);
static const int8_t RESTOOL_VERSION[VERSION_MAX_LEN] = { "Restool 5.012" };
static const int8_t RESTOOL_VERSION[VERSION_MAX_LEN] = { "Restool 5.1.0.002" };
const static int32_t TAG_LEN = 4;
static std::set<std::string> g_resourceSet;
static std::set<std::string> g_hapResourceSet;
@@ -93,6 +93,11 @@ enum class ResType {
INVALID_RES_TYPE = -1,
};
enum class PackType {
NORMAL = 1,
OVERLAP
};
enum class OrientationType {
VERTICAL = 0,
HORIZONTAL = 1,
+3 -3
View File
@@ -34,7 +34,7 @@ public:
void SetFilePath(const std::string &filePath);
void SetLimitKey(const std::string &limitKey);
void SetName(const std::string &name);
void MarkHapRes();
void MarkCoverable();
const int8_t *GetData() const;
uint32_t GetDataLength() const;
@@ -43,7 +43,7 @@ public:
const std::vector<KeyParam> &GetKeyParam() const;
const std::string &GetFilePath() const;
const std::string &GetLimitKey() const;
bool IsHapRes() const;
bool IsCoverable() const;
ResourceItem &operator=(const ResourceItem &other);
private:
@@ -56,7 +56,7 @@ private:
ResType type_;
std::string filePath_;
std::string limitKey_;
bool hapRes_ = false;
bool coverable_ = false;
};
}
}
+39
View File
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2021-2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_RESTOOL_RESOURCE_OVERLAP_H
#define OHOS_RESTOOL_RESOURCE_OVERLAP_H
#include "cmd_parser.h"
#include "resource_pack.h"
namespace OHOS {
namespace Global {
namespace Restool {
class ResourceOverlap : public ResourcePack {
public:
ResourceOverlap(const PackageParser &packageParser);
uint32_t Pack();
protected:
uint32_t ScanResources(const std::vector<std::string> &inputs, const std::string &output);
private:
uint32_t LoadHapResources();
};
}
}
}
#endif
+9 -13
View File
@@ -27,19 +27,22 @@
namespace OHOS {
namespace Global {
namespace Restool {
enum class PackType {
NORMAL = 1,
OVERLAP
};
class ResourcePack {
public:
explicit ResourcePack(const PackageParser &packageParser);
virtual ~ResourcePack() = default;
uint32_t Package();
virtual uint32_t Pack();
protected:
uint32_t InitResourcePack();
uint32_t PackResources(const ResourceMerge &resourceMerge);
virtual uint32_t ScanResources(const std::vector<std::string> &inputs, const std::string &output);
PackageParser packageParser_;
std::string moduleName_;
ConfigParser configJson_;
private:
uint32_t InitResourcePack();
uint32_t InitModule();
void InitHeaderCreater();
uint32_t InitOutput() const;
@@ -50,10 +53,6 @@ private:
uint32_t GenerateCplusHeader(const std::string &headerPath) const;
uint32_t GenerateJsHeader(const std::string &headerPath) const;
uint32_t GenerateConfigJson();
uint32_t ScanResources(const std::vector<std::string> &inputs, const std::string &output);
uint32_t Pack();
uint32_t PackResources(const ResourceMerge &resourceMerge);
uint32_t LoadHapResources();
uint32_t PackPreview();
uint32_t PackAppend();
uint32_t PackCombine();
@@ -66,11 +65,8 @@ private:
void CheckConfigJson();
void CheckConfigJsonForCombine(ResourceAppend &resourceAppend);
bool CopyIcon(std::string &dataPath, const std::string &idName, std::string &fileName) const;
PackageParser packageParser_;
std::string moduleName_;
using HeaderCreater = std::function<uint32_t(const std::string&)>;
std::map<std::string, HeaderCreater> headerCreaters_;
ConfigParser configJson_;
PackType packType_ = PackType::NORMAL;
};
}