mirror of
https://github.com/openharmony/developtools_global_resource_tool.git
synced 2026-07-18 09:14:48 -04:00
+20
-61
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2024 - 2024 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2024-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
|
||||
@@ -21,6 +21,8 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
#include "cmd/package_parser.h"
|
||||
#include "singleton.h"
|
||||
#include "restool_errors.h"
|
||||
|
||||
@@ -28,73 +30,30 @@ namespace OHOS {
|
||||
namespace Global {
|
||||
namespace Restool {
|
||||
|
||||
class ICmdParser {
|
||||
class CmdParserBase {
|
||||
public:
|
||||
virtual uint32_t Parse(int argc, char *argv[]) = 0;
|
||||
CmdParserBase(const std::string &name);
|
||||
virtual ~CmdParserBase() = default;
|
||||
virtual uint32_t Parse(int argc, char *argv[], int currentIndex);
|
||||
virtual uint32_t ParseOption(int argc, char *argv[], int currentIndex);
|
||||
virtual uint32_t ExecCommand() = 0;
|
||||
virtual void ShowUseage() = 0;
|
||||
protected:
|
||||
std::vector<std::unique_ptr<CmdParserBase>> subcommands_;
|
||||
const std::string name_;
|
||||
bool showUseage_{true};
|
||||
};
|
||||
|
||||
template<class T>
|
||||
class CmdParser : public Singleton<CmdParser<T>> {
|
||||
static_assert(std::is_base_of_v<ICmdParser, T>, "Template T must inherit ICmdParser.");
|
||||
class CmdParser : public CmdParserBase, public Singleton<CmdParser> {
|
||||
public:
|
||||
T &GetCmdParser();
|
||||
uint32_t Parse(int argc, char *argv[]);
|
||||
uint32_t ExecCommand();
|
||||
static void ShowUseage();
|
||||
CmdParser();
|
||||
uint32_t ParseOption(int argc, char *argv[], int currentIndex) override;
|
||||
uint32_t ExecCommand() override;
|
||||
void ShowUseage() override;
|
||||
PackageParser &GetPackageParser();
|
||||
|
||||
private:
|
||||
T cmdParser_;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
void CmdParser<T>::ShowUseage()
|
||||
{
|
||||
std::cout << "This is an OHOS Packaging Tool.\n";
|
||||
std::cout << "Usage:\n";
|
||||
std::cout << TOOL_NAME << " [arguments] Package the OHOS resources.\n";
|
||||
std::cout << "[arguments]:\n";
|
||||
std::cout << " -i/--inputPath input resource path, can add more.\n";
|
||||
std::cout << " -p/--packageName package name.\n";
|
||||
std::cout << " -o/--outputPath output path.\n";
|
||||
std::cout << " -r/--resHeader resource header file path(like ./ResourceTable.js, ./ResrouceTable.h).\n";
|
||||
std::cout << " -f/--forceWrite if output path exists,force delete it.\n";
|
||||
std::cout << " -v/--version print tool version.\n";
|
||||
std::cout << " -m/--modules module name, can add more, split by ','(like entry1,entry2,...).\n";
|
||||
std::cout << " -j/--json config.json path.\n";
|
||||
std::cout << " -e/--startId start id mask, e.g 0x01000000,";
|
||||
std::cout << " in [0x01000000, 0x06FFFFFF),[0x08000000, 0xFFFFFFFF)\n";
|
||||
std::cout << " -x/--append resources folder path\n";
|
||||
std::cout << " -z/--combine flag for incremental compilation\n";
|
||||
std::cout << " -h/--help Displays this help menu\n";
|
||||
std::cout << " -l/--fileList input json file of the option set, e.g resConfig.json.";
|
||||
std::cout << " For details, see the developer documentation.\n";
|
||||
std::cout << " --ids save id_defined.json direcory\n";
|
||||
std::cout << " --defined-ids input id_defined.json path\n";
|
||||
std::cout << " --dependEntry Build result directory of the specified entry module when the feature";
|
||||
std::cout << " module resources are independently built in the FA model.\n";
|
||||
std::cout << " --icon-check Enable the PNG image verification function for icons and startwindows.\n";
|
||||
std::cout << " --target-config When used with '-i', selective compilation is supported.\n";
|
||||
std::cout << " --compressed-config opt-compression.json path.\n";
|
||||
std::cout << " dump [config] Dump rsource in hap to json. If with 'config', will only dump limit path.\n";
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T &CmdParser<T>::GetCmdParser()
|
||||
{
|
||||
return cmdParser_;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
uint32_t CmdParser<T>::Parse(int argc, char *argv[])
|
||||
{
|
||||
return cmdParser_.Parse(argc, argv);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
uint32_t CmdParser<T>::ExecCommand()
|
||||
{
|
||||
return cmdParser_.ExecCommand();
|
||||
PackageParser packageParser_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2024 - 2024 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2024-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
|
||||
@@ -16,23 +16,35 @@
|
||||
#ifndef OHOS_RESTOOL_DUMP_PARSER_H
|
||||
#define OHOS_RESTOOL_DUMP_PARSER_H
|
||||
|
||||
#include "cmd_parser.h"
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "cmd_parser.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace Restool {
|
||||
class DumpParser : public ICmdParser {
|
||||
class DumpParserBase : public virtual CmdParserBase {
|
||||
public:
|
||||
virtual ~DumpParser() = default;
|
||||
uint32_t Parse(int argc, char *argv[]) override;
|
||||
uint32_t ExecCommand() override;
|
||||
virtual ~DumpParserBase() = default;
|
||||
uint32_t ParseOption(int argc, char *argv[], int currentIndex) override;
|
||||
void ShowUseage() override;
|
||||
const std::string &GetInputPath() const;
|
||||
|
||||
private:
|
||||
protected:
|
||||
std::string inputPath_;
|
||||
std::string type_;
|
||||
};
|
||||
|
||||
class DumpParser : public virtual DumpParserBase {
|
||||
public:
|
||||
DumpParser();
|
||||
uint32_t ExecCommand() override;
|
||||
};
|
||||
|
||||
class DumpConfigParser : public virtual DumpParserBase {
|
||||
public:
|
||||
DumpConfigParser();
|
||||
virtual ~DumpConfigParser() = default;
|
||||
uint32_t ExecCommand() override;
|
||||
};
|
||||
} // namespace Restool
|
||||
} // namespace Global
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2024 - 2024 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2024-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
|
||||
@@ -18,17 +18,20 @@
|
||||
|
||||
#include <functional>
|
||||
#include <getopt.h>
|
||||
#include "cmd_parser.h"
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include "resource_data.h"
|
||||
#include "restool_errors.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
namespace Restool {
|
||||
class PackageParser : public ICmdParser {
|
||||
class PackageParser {
|
||||
public:
|
||||
PackageParser(){};
|
||||
virtual ~PackageParser() = default;
|
||||
uint32_t Parse(int argc, char *argv[]) override;
|
||||
uint32_t ExecCommand() override;
|
||||
uint32_t Parse(int argc, char *argv[]);
|
||||
uint32_t ExecCommand();
|
||||
const std::vector<std::string> &GetInputs() const;
|
||||
const std::string &GetPackageName() const;
|
||||
const std::string &GetOutput() const;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2024 - 2024 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2024-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
|
||||
@@ -36,7 +36,7 @@ namespace Restool {
|
||||
class ResourceDumper {
|
||||
public:
|
||||
virtual ~ResourceDumper() = default;
|
||||
virtual uint32_t Dump(const DumpParser &parser);
|
||||
virtual uint32_t Dump(const DumpParserBase &parser);
|
||||
protected:
|
||||
virtual uint32_t DumpRes(std::string &out) const = 0;
|
||||
void ReadHapInfo(const std::unique_ptr<char[]> &buffer, size_t len);
|
||||
@@ -69,11 +69,6 @@ private:
|
||||
uint32_t AddItemCommonPropToJson(int32_t resId, const ResourceItem &item, cJSON* json) const;
|
||||
};
|
||||
|
||||
class ResourceDumperFactory {
|
||||
public:
|
||||
static std::unique_ptr<ResourceDumper> CreateResourceDumper(const std::string &type);
|
||||
static const std::set<std::string> GetSupportDumpType();
|
||||
};
|
||||
} // namespace Restool
|
||||
} // namespace Global
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <vector>
|
||||
#include "config_parser.h"
|
||||
#include "restool_errors.h"
|
||||
#include "cmd/package_parser.h"
|
||||
#include "cmd/cmd_parser.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Global {
|
||||
@@ -29,7 +29,7 @@ class ResourceMerge {
|
||||
public:
|
||||
ResourceMerge();
|
||||
virtual ~ResourceMerge();
|
||||
uint32_t Init(const PackageParser &packageParser = CmdParser<PackageParser>::GetInstance().GetCmdParser());
|
||||
uint32_t Init(const PackageParser &packageParser = CmdParser::GetInstance().GetPackageParser());
|
||||
const std::vector<std::string> &GetInputs() const;
|
||||
private:
|
||||
std::vector<std::string> inputsOrder_;
|
||||
|
||||
Reference in New Issue
Block a user