Upgrade tool.
This commit is contained in:
parent
7c1a8ddd74
commit
9567a6cd66
|
@ -123,6 +123,5 @@ void MainThread::Runing(void)
|
|||
extern bool CreateProtocolHandleImpl(void);
|
||||
void MainThread::CustomizationInit(void)
|
||||
{
|
||||
//
|
||||
CreateProtocolHandleImpl();
|
||||
}
|
|
@ -12,4 +12,10 @@
|
|||
|
||||
## 1.3. 数据丢失还原机制
|
||||
|
||||
  针对可能发生的数据丢失/损坏,提供数据还原机制。
|
||||
|
||||
* 系统配置一份默认的只读配置文件,用于数据丢失/损坏时使用;
|
||||
|
||||
## 1.4. 数据备份还原机制
|
||||
|
||||
  每次修改配置文件,需要备份一份,用于数据丢失/损坏时使用;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# include(${CMAKE_SOURCE_DIR}/build/independent_source.cmake)
|
||||
include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake)
|
||||
# include(${APPLICATION_SOURCE_PATH}/VersionRelease/build/hunting_camera.cmake)
|
||||
set(EXECUTABLE_OUTPUT_PATH ${TEST_OUTPUT_PATH}/bin)
|
||||
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR_IPCSDK}/tools/version_release)
|
||||
|
||||
include_directories(
|
||||
./src
|
||||
|
|
|
@ -24,8 +24,8 @@ int main(int argc, char *argv[])
|
|||
ILogInit(LOG_INSTANCE_TYPE_END);
|
||||
ArgvAnalysis::GetInstance()->Analyze(argc, argv);
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
RUN_ALL_TESTS();
|
||||
int result = RUN_ALL_TESTS();
|
||||
ILogUnInit();
|
||||
DestroyLogModule();
|
||||
return 0;
|
||||
return result;
|
||||
}
|
|
@ -14,6 +14,8 @@
|
|||
*/
|
||||
#include "ArgvAnalysis.h"
|
||||
#include "ILog.h"
|
||||
const char *V_SOURCE_FILE = "v_source_file";
|
||||
const char *V_OUTPUT_FILE = "v_output_file";
|
||||
std::shared_ptr<ArgvAnalysis> &ArgvAnalysis::GetInstance(std::shared_ptr<ArgvAnalysis> *impl)
|
||||
{
|
||||
static auto instance = std::make_shared<ArgvAnalysis>();
|
||||
|
@ -55,4 +57,22 @@ void ArgvAnalysis::Analyze(int argc, char *argv[])
|
|||
for (const auto &pair : mOptions) {
|
||||
LogInfo("Key: %s, Value: %s\n", pair.first.c_str(), pair.second.c_str());
|
||||
}
|
||||
}
|
||||
std::string ArgvAnalysis::GetSourceFile(void)
|
||||
{
|
||||
auto it = mOptions.find(V_SOURCE_FILE);
|
||||
if (it != mOptions.end()) {
|
||||
return it->second;
|
||||
}
|
||||
LogWarning("Can't find the source file.\n");
|
||||
return "";
|
||||
}
|
||||
std::string ArgvAnalysis::GetOutputFile(void)
|
||||
{
|
||||
auto it = mOptions.find(V_OUTPUT_FILE);
|
||||
if (it != mOptions.end()) {
|
||||
return it->second;
|
||||
}
|
||||
LogWarning("Can't find the source file.\n");
|
||||
return "";
|
||||
}
|
|
@ -24,6 +24,8 @@ public:
|
|||
virtual ~ArgvAnalysis() = default;
|
||||
static std::shared_ptr<ArgvAnalysis> &GetInstance(std::shared_ptr<ArgvAnalysis> *impl = nullptr);
|
||||
void Analyze(int argc, char *argv[]);
|
||||
std::string GetSourceFile(void);
|
||||
std::string GetOutputFile(void);
|
||||
|
||||
private:
|
||||
std::map<std::string, std::string> mOptions;
|
||||
|
|
|
@ -12,15 +12,22 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "VersionReleaseTool.h"
|
||||
#include "GtestUsing.h"
|
||||
#include "ILog.h"
|
||||
#include "UpgradeTool.h"
|
||||
#include "VersionReleaseTool.h"
|
||||
#include "ArgvAnalysis.h"
|
||||
#include <thread>
|
||||
namespace VersionReleaseTool
|
||||
{
|
||||
/**
|
||||
* @brief Construct a new TEST object
|
||||
* ../output_files/test/bin/VersionReleaseTool --v_source_file=./test.bin --v_output_file=./test_output.bin
|
||||
*/
|
||||
TEST(VersionReleaseTool, Version)
|
||||
{
|
||||
UpgradeTool::GetInstance()->PackFile("src", "output", "1.0.0", "product", "project", "upgradeType");
|
||||
std::string sourceFile = ArgvAnalysis::GetInstance()->GetSourceFile();
|
||||
std::string outputFile = ArgvAnalysis::GetInstance()->GetOutputFile();
|
||||
UpgradeTool::GetInstance()->PackFile(sourceFile, outputFile, "1.0.0", "product", "project", "upgradeType");
|
||||
}
|
||||
} // namespace VersionReleaseTool
|
BIN
tools/version_release/VersionReleaseTool
Executable file
BIN
tools/version_release/VersionReleaseTool
Executable file
Binary file not shown.
|
@ -82,6 +82,7 @@ void UpgradeTool::FillInTime(unsigned char packTime[6])
|
|||
void UpgradeTool::PackFile(const std::string &fileName, const std::string &outputFile, const std::string &version,
|
||||
const std::string &product, const std::string &project, const std::string &upgradeType)
|
||||
{
|
||||
struct stat fileStat;
|
||||
UpgradeFileHeader header;
|
||||
memset(&header, 0, sizeof(UpgradeFileHeader));
|
||||
StringToVersionBytes(version, header.version);
|
||||
|
@ -91,6 +92,12 @@ void UpgradeTool::PackFile(const std::string &fileName, const std::string &outpu
|
|||
perror("Error opening input file");
|
||||
return;
|
||||
}
|
||||
if (stat(fileName.c_str(), &fileStat) == -1) {
|
||||
LogError("Error getting file size\n");
|
||||
fclose(input_file);
|
||||
return;
|
||||
}
|
||||
LogInfo("File size:%ld\n", fileStat.st_size);
|
||||
|
||||
FILE *output_file = fopen(outputFile.c_str(), "wb");
|
||||
if (!output_file) {
|
||||
|
@ -98,11 +105,28 @@ void UpgradeTool::PackFile(const std::string &fileName, const std::string &outpu
|
|||
fclose(input_file);
|
||||
return;
|
||||
}
|
||||
long writeSize = 0;
|
||||
fwrite(&header, sizeof(header), 1, output_file);
|
||||
char buffer[1024];
|
||||
size_t bytes_read;
|
||||
size_t bytes_read = 0;
|
||||
size_t bytes_write = 0;
|
||||
while ((bytes_read = fread(buffer, 1, sizeof(buffer), input_file)) > 0) {
|
||||
fwrite(buffer, 1, bytes_read, output_file);
|
||||
bytes_write = fwrite(buffer, 1, bytes_read, output_file);
|
||||
if (bytes_write != bytes_read) {
|
||||
LogError("fwrite failed, break;\n");
|
||||
break;
|
||||
}
|
||||
writeSize += bytes_write;
|
||||
}
|
||||
LogInfo("write size:%ld\n", writeSize);
|
||||
if (writeSize != fileStat.st_size) {
|
||||
LogError("write file failed, remove output file.\n");
|
||||
char cmd[1024];
|
||||
snprintf(cmd, sizeof(cmd), "rm -f %s", outputFile.c_str());
|
||||
fx_system(cmd);
|
||||
}
|
||||
else {
|
||||
LogInfo("write file success.\n");
|
||||
}
|
||||
fclose(input_file);
|
||||
fclose(output_file);
|
||||
|
|
Loading…
Reference in New Issue
Block a user