2022-02-15 04:30:27 -05:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
|
|
|
|
#include "UnsyncCmdPatch.h"
|
|
|
|
|
#include "UnsyncFile.h"
|
2023-11-13 19:34:29 -05:00
|
|
|
#include "UnsyncTarget.h"
|
2022-02-15 04:30:27 -05:00
|
|
|
|
|
|
|
|
namespace unsync {
|
|
|
|
|
|
|
|
|
|
int32 // TODO: return a TResult
|
|
|
|
|
CmdPatch(const FCmdPatchOptions& Options)
|
|
|
|
|
{
|
2023-10-31 16:34:04 -04:00
|
|
|
UNSYNC_LOG(L"Patching base file '%ls' using '%ls'", Options.Base.wstring().c_str(), Options.Patch.wstring().c_str());
|
|
|
|
|
UNSYNC_LOG(L"Output file '%ls'", Options.Output.wstring().c_str());
|
2022-02-15 04:30:27 -05:00
|
|
|
|
|
|
|
|
FBuffer BaseFile = ReadFileToBuffer(Options.Base);
|
|
|
|
|
if (BaseFile.Empty())
|
|
|
|
|
{
|
|
|
|
|
UNSYNC_ERROR(L"Failed to open file '%ls'", Options.Base.wstring().c_str());
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FBuffer PatchFile = ReadFileToBuffer(Options.Patch);
|
|
|
|
|
if (PatchFile.Empty())
|
|
|
|
|
{
|
|
|
|
|
UNSYNC_ERROR(L"Failed to open patch file '%ls'", Options.Patch.wstring().c_str());
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FBuffer TargetData = BuildTargetWithPatch(PatchFile.Data(), PatchFile.Size(), BaseFile.Data(), BaseFile.Size());
|
|
|
|
|
|
|
|
|
|
if (TargetData.Empty())
|
|
|
|
|
{
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!GDryRun)
|
|
|
|
|
{
|
2023-10-31 16:34:04 -04:00
|
|
|
UNSYNC_LOG(L"Writing output file to '%ls'", Options.Output.wstring().c_str());
|
2022-02-15 04:30:27 -05:00
|
|
|
return WriteBufferToFile(Options.Output, TargetData) ? 0 : 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace unsync
|