| 1 | /* |
| 2 | * LegacyClonk |
| 3 | * |
| 4 | * Copyright (c) RedWolf Design |
| 5 | * Copyright (c) 2017-2021, The LegacyClonk Team and contributors |
| 6 | * |
| 7 | * Distributed under the terms of the ISC license; see accompanying file |
| 8 | * "COPYING" for details. |
| 9 | * |
| 10 | * "Clonk" is a registered trademark of Matthes Bender, used with permission. |
| 11 | * See accompanying file "TRADEMARK" for details. |
| 12 | * |
| 13 | * To redistribute this file separately, substitute the full license texts |
| 14 | * for the above references. |
| 15 | */ |
| 16 | |
| 17 | /* Update package support */ |
| 18 | |
| 19 | #pragma once |
| 20 | |
| 21 | #include "C4Constants.h" |
| 22 | #include "C4Group.h" |
| 23 | |
| 24 | const int C4UP_MaxUpGrpCnt = 50; |
| 25 | |
| 26 | class C4UpdatePackageCore |
| 27 | { |
| 28 | public: |
| 29 | C4UpdatePackageCore(); |
| 30 | |
| 31 | public: |
| 32 | int32_t RequireVersion[4]; |
| 33 | char Name[C4MaxName + 1]; |
| 34 | char DestPath[_MAX_PATH + 1]; |
| 35 | int32_t GrpUpdate; |
| 36 | int32_t UpGrpCnt; // number of file versions that can be updated by this package |
| 37 | bool AllowMissingTarget; // if true, missing target files are not considered an error |
| 38 | uint32_t GrpChks1[C4UP_MaxUpGrpCnt], GrpChks2; |
| 39 | uint32_t GrpContentsCRC1[C4UP_MaxUpGrpCnt], GrpContentsCRC2; |
| 40 | |
| 41 | public: |
| 42 | void CompileFunc(StdCompiler *pComp); |
| 43 | bool Load(C4Group &hGroup); |
| 44 | bool Save(C4Group &hGroup); |
| 45 | }; |
| 46 | |
| 47 | class C4UpdatePackage : public C4UpdatePackageCore |
| 48 | { |
| 49 | public: |
| 50 | enum class CheckResult |
| 51 | { |
| 52 | Ok, |
| 53 | NoSource, |
| 54 | BadSource, |
| 55 | AlreadyUpdated, |
| 56 | BadVersion |
| 57 | }; |
| 58 | |
| 59 | bool Load(C4Group *pGroup); |
| 60 | bool Execute(C4Group *pGroup); |
| 61 | static bool Optimize(C4Group *pGrpFrom, const char *strTarget); |
| 62 | CheckResult Check(C4Group *pGroup); |
| 63 | bool MakeUpdate(const char *strFile1, const char *strFile2, const char *strUpdateFile, const char *strName, bool allowMissingTarget); |
| 64 | |
| 65 | protected: |
| 66 | bool DoUpdate(C4Group *pGrpFrom, class C4GroupEx *pGrpTo, const char *strFileName); |
| 67 | bool DoGrpUpdate(C4Group *pUpdateData, class C4GroupEx *pGrpTo); |
| 68 | static bool Optimize(C4Group *pGrpFrom, class C4GroupEx *pGrpTo, const char *strFileName); |
| 69 | |
| 70 | bool MkUp(C4Group *pGrp1, C4Group *pGrp2, C4GroupEx *pUpGr, bool &includeInUpdate); |
| 71 | |
| 72 | CStdFile Log; |
| 73 | |
| 74 | template<typename... Args> |
| 75 | void WriteLog(const std::format_string<Args...> fmt, Args &&... args) |
| 76 | { |
| 77 | const std::string output{std::format(fmt, std::forward<Args>(args)...)}; |
| 78 | Log.Write(pBuffer: output.c_str(), iSize: output.size()); |
| 79 | Log.Flush(); |
| 80 | } |
| 81 | }; |
| 82 | |
| 83 | bool C4Group_ApplyUpdate(C4Group &hGroup); |
| 84 | |