mirror of
https://github.com/openharmony/developtools_global_resource_tool.git
synced 2026-07-18 09:14:48 -04:00
@@ -27,8 +27,9 @@ class BinaryFilePacker {
|
||||
public:
|
||||
explicit BinaryFilePacker(const PackageParser &packageParser, const std::string &moduleName);
|
||||
virtual ~BinaryFilePacker();
|
||||
std::future<uint32_t> CopyBinaryFileAsync(const std::vector<std::string> &inputs);
|
||||
void StopCopy();
|
||||
void CopyBinaryFileAsync(const std::vector<std::string> &inputs);
|
||||
void Terminate();
|
||||
uint32_t GetResult();
|
||||
|
||||
protected:
|
||||
virtual uint32_t CopyBinaryFile(const std::vector<std::string> &inputs);
|
||||
@@ -37,14 +38,16 @@ protected:
|
||||
virtual bool IsDuplicated(const std::unique_ptr<FileEntry> &entry, std::string subPath);
|
||||
PackageParser packageParser_;
|
||||
std::string moduleName_;
|
||||
std::vector<std::future<uint32_t>> copyResults_;
|
||||
std::atomic<bool> stopCopy_{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);
|
||||
std::future<uint32_t> copyFuture_;
|
||||
std::vector<std::future<uint32_t>> copyResults_;
|
||||
std::atomic<bool> terminate_{false};
|
||||
uint32_t result_ = RESTOOL_SUCCESS;
|
||||
};
|
||||
} // namespace Restool
|
||||
} // namespace Global
|
||||
|
||||
@@ -32,16 +32,24 @@ BinaryFilePacker::~BinaryFilePacker()
|
||||
{
|
||||
}
|
||||
|
||||
void BinaryFilePacker::StopCopy()
|
||||
void BinaryFilePacker::Terminate()
|
||||
{
|
||||
stopCopy_.store(true);
|
||||
terminate_.store(true);
|
||||
GetResult();
|
||||
}
|
||||
|
||||
std::future<uint32_t> BinaryFilePacker::CopyBinaryFileAsync(const std::vector<std::string> &inputs)
|
||||
uint32_t BinaryFilePacker::GetResult()
|
||||
{
|
||||
if (copyFuture_.valid()) {
|
||||
result_ = copyFuture_.get();
|
||||
}
|
||||
return result_;
|
||||
}
|
||||
|
||||
void BinaryFilePacker::CopyBinaryFileAsync(const std::vector<std::string> &inputs)
|
||||
{
|
||||
auto func = [this](const vector<string> &inputs) { return this->CopyBinaryFile(inputs); };
|
||||
std::future<uint32_t> res = ThreadPool::GetInstance().Enqueue(func, inputs);
|
||||
return res;
|
||||
copyFuture_ = ThreadPool::GetInstance().Enqueue(func, inputs);
|
||||
}
|
||||
|
||||
uint32_t BinaryFilePacker::CopyBinaryFile(const vector<string> &inputs)
|
||||
@@ -118,7 +126,7 @@ uint32_t BinaryFilePacker::CopyBinaryFileImpl(const string &src, const string &d
|
||||
continue;
|
||||
}
|
||||
|
||||
if (stopCopy_.load()) {
|
||||
if (terminate_.load()) {
|
||||
cout << "Info: CopyBinaryFileImpl: stop copy binary file." << endl;
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
@@ -145,6 +153,10 @@ bool BinaryFilePacker::IsDuplicated(const unique_ptr<FileEntry> &entry, string s
|
||||
|
||||
uint32_t BinaryFilePacker::CopySingleFile(const std::string &path, std::string &subPath)
|
||||
{
|
||||
if (terminate_.load()) {
|
||||
cout << "Info: CopySingleFile: stop copy binary file." << endl;
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
if (moduleName_ == "har" || CompressionParser::GetCompressionParser()->GetDefaultCompress()) {
|
||||
if (!ResourceUtil::CopyFileInner(path, subPath)) {
|
||||
return RESTOOL_ERROR;
|
||||
@@ -160,7 +172,7 @@ uint32_t BinaryFilePacker::CopySingleFile(const std::string &path, std::string &
|
||||
uint32_t BinaryFilePacker::CheckCopyResults()
|
||||
{
|
||||
for (auto &res : copyResults_) {
|
||||
if (stopCopy_.load()) {
|
||||
if (terminate_.load()) {
|
||||
cout << "Info: CopyBinaryFile: stop copy binary file." << endl;
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
|
||||
@@ -35,8 +35,8 @@ uint32_t OverlapBinaryFilePacker::CopyBinaryFile(const vector<string> &inputs)
|
||||
|
||||
vector<string> resource(inputs.begin() + 1, inputs.end());
|
||||
BinaryFilePacker rawFilePacker(packageParser_, moduleName_);
|
||||
std::future<uint32_t> copyFuture = rawFilePacker.CopyBinaryFileAsync(resource);
|
||||
if (copyFuture.get() != RESTOOL_SUCCESS) {
|
||||
rawFilePacker.CopyBinaryFileAsync(resource);
|
||||
if (rawFilePacker.GetResult() != RESTOOL_SUCCESS) {
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
return RESTOOL_SUCCESS;
|
||||
|
||||
@@ -43,19 +43,19 @@ uint32_t ResourceOverlap::Pack()
|
||||
}
|
||||
|
||||
OverlapBinaryFilePacker rawFilePacker(packageParser_, moduleName_);
|
||||
future<uint32_t> copyFuture = rawFilePacker.CopyBinaryFileAsync(resourceMerge.GetInputs());
|
||||
rawFilePacker.CopyBinaryFileAsync(resourceMerge.GetInputs());
|
||||
|
||||
if (LoadHapResources() != RESTOOL_SUCCESS) {
|
||||
rawFilePacker.StopCopy();
|
||||
rawFilePacker.Terminate();
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
|
||||
if (PackResources(resourceMerge) != RESTOOL_SUCCESS) {
|
||||
rawFilePacker.StopCopy();
|
||||
rawFilePacker.Terminate();
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
|
||||
if (copyFuture.get() != RESTOOL_SUCCESS) {
|
||||
if (rawFilePacker.GetResult() != RESTOOL_SUCCESS) {
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
return RESTOOL_SUCCESS;
|
||||
|
||||
@@ -316,14 +316,14 @@ uint32_t ResourcePack::Pack()
|
||||
}
|
||||
|
||||
BinaryFilePacker rawFilePacker(packageParser_, moduleName_);
|
||||
std::future<uint32_t> copyFuture = rawFilePacker.CopyBinaryFileAsync(resourceMerge.GetInputs());
|
||||
rawFilePacker.CopyBinaryFileAsync(resourceMerge.GetInputs());
|
||||
|
||||
if (PackResources(resourceMerge) != RESTOOL_SUCCESS) {
|
||||
rawFilePacker.StopCopy();
|
||||
rawFilePacker.Terminate();
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
|
||||
if (copyFuture.get() != RESTOOL_SUCCESS) {
|
||||
if (rawFilePacker.GetResult() != RESTOOL_SUCCESS) {
|
||||
return RESTOOL_ERROR;
|
||||
}
|
||||
return RESTOOL_SUCCESS;
|
||||
|
||||
Reference in New Issue
Block a user