hunting/utils/UpgradeBase/include/UpgradeBase.h
2024-06-15 08:36:44 +08:00

52 lines
1.7 KiB
C++

/*
* Copyright (c) 2023 Fancy Code.
* 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 UPGRADE_BASE_H
#define UPGRADE_BASE_H
#include "StatusCode.h"
constexpr int VERSION_LENGTH = 4;
typedef struct __attribute__((packed)) upgrade_file_header
{
unsigned char packTime[6];
unsigned char version[VERSION_LENGTH];
unsigned char product[2];
unsigned char project[2];
unsigned char upgradeType[1];
unsigned char reserved[15];
unsigned char checkCode[2];
} UpgradeFileHeader;
enum class UpgradeType
{
APPLICATION_ONLY = 0,
END
};
class UpgradeBase
{
public:
UpgradeBase() = default;
virtual ~UpgradeBase() = default;
virtual StatusCode CheckFileHeader(const UpgradeFileHeader &header) = 0;
/**
* @brief Verify if the file belongs to the upgrade file.
*
* @param fileName The file name being verified. Enter the parameter using an absolute path.
* @return StatusCode
*/
StatusCode CheckUpgradeFile(const char *fileName, UpgradeFileHeader &header);
StatusCode MoveUpgradeFile(const char *sourceFile, const char *targetFile);
private:
void PrintfHeader(const UpgradeFileHeader &header);
};
#endif