Merge branch 'development' into cmake/SPEC-2513_w4244

Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com>

# Conflicts:
#	Code/Framework/Crcfix/crcfix.cpp
This commit is contained in:
Esteban Papp
2021-08-18 12:39:24 -07:00
46 changed files with 494 additions and 981 deletions
@@ -366,7 +366,7 @@ bool SpinBoxWatcher::filterSpinBoxEvents(QAbstractSpinBox* spinBox, QEvent* even
{
// To prevent the event being turned into a focus event, be sure to install an
// AzQtComponents::GlobalEventFilter on your QApplication instance.
event->ignore();
event->accept();
return true;
}
@@ -15,6 +15,7 @@
#include <AzToolsFramework/Prefab/Instance/InstanceEntityMapperInterface.h>
#include <AzToolsFramework/Prefab/PrefabLoaderInterface.h>
#include <AzToolsFramework/Prefab/PrefabSystemComponentInterface.h>
#include <Prefab/PrefabDomUtils.h>
namespace AzToolsFramework
{
@@ -81,6 +82,15 @@ namespace AzToolsFramework
result.Combine(resultInstances);
}
PrefabDomUtils::LinkIdMetadata* subPathLinkId = context.GetMetadata().Find<PrefabDomUtils::LinkIdMetadata>();
if (subPathLinkId)
{
AZ::ScopedContextPath subPathSource(context, "m_linkId");
result = ContinueStoringToJsonObjectField(
outputValue, "LinkId", &(instance->m_linkId), &InvalidLinkId, azrtti_typeid<decltype(instance->m_linkId)>(), context);
}
return context.Report(result,
result.GetProcessing() == JSR::Processing::Completed ? "Successfully stored Instance information for Prefab." :
"Failed to store Instance information for Prefab.");
@@ -88,6 +88,11 @@ namespace AzToolsFramework
settings.m_keepDefaults = true;
}
if ((flags & StoreFlags::StoreLinkIds) != StoreFlags::None)
{
settings.m_metadata.Create<LinkIdMetadata>();
}
AZStd::string scratchBuffer;
auto issueReportingCallback = [&scratchBuffer]
(AZStd::string_view message, AZ::JsonSerializationResult::ResultCode result,
@@ -45,7 +45,11 @@ namespace AzToolsFramework
//! By default an instance will be stored with default values. In cases where we want to store less json without defaults
//! such as saving to disk, this flag will control that behavior.
StripDefaultValues = 1 << 0
StripDefaultValues = 1 << 0,
//! We do not save linkIds to file. However when loading a level we want to temporarily save
//! linkIds to instance dom so any nested prefabs will have linkIds correctly set.
StoreLinkIds = 1 << 1
};
AZ_DEFINE_ENUM_BITWISE_OPERATORS(StoreFlags);
@@ -150,6 +154,14 @@ namespace AzToolsFramework
[[maybe_unused]] const AZStd::string_view printMessage,
[[maybe_unused]] const AzToolsFramework::Prefab::PrefabDomValue& prefabDomValue);
//! An empty struct for passing to JsonSerializerSettings.m_metadata that is consumed by InstanceSerializer::Store.
//! If present in metadata, linkIds will be stored to instance dom.
struct LinkIdMetadata
{
AZ_RTTI(LinkIdMetadata, "{8FF7D299-14E3-41D4-90C5-393A240FAE7C}");
virtual ~LinkIdMetadata() {}
};
} // namespace PrefabDomUtils
} // namespace Prefab
} // namespace AzToolsFramework
@@ -300,7 +300,7 @@ namespace AzToolsFramework
}
PrefabDom storedPrefabDom(&loadedTemplateDom->get().GetAllocator());
if (!PrefabDomUtils::StoreInstanceInPrefabDom(loadedPrefabInstance, storedPrefabDom))
if (!PrefabDomUtils::StoreInstanceInPrefabDom(loadedPrefabInstance, storedPrefabDom, PrefabDomUtils::StoreFlags::StoreLinkIds))
{
return false;
}
@@ -61,7 +61,7 @@ namespace AzToolsFramework
m_prefabUndoCache.Destroy();
}
PrefabOperationResult PrefabPublicHandler::CreatePrefabInMemory(const AZStd::vector<AZ::EntityId>& entityIds, AZ::IO::PathView filePath)
PrefabOperationResult PrefabPublicHandler::CreatePrefabInMemory(const EntityIdList& entityIds, AZ::IO::PathView filePath)
{
EntityList inputEntityList, topLevelEntities;
AZ::EntityId commonRootEntityId;
@@ -264,7 +264,7 @@ namespace AzToolsFramework
return AZ::Success();
}
PrefabOperationResult PrefabPublicHandler::CreatePrefabInDisk(const AZStd::vector<AZ::EntityId>& entityIds, AZ::IO::PathView filePath)
PrefabOperationResult PrefabPublicHandler::CreatePrefabInDisk(const EntityIdList& entityIds, AZ::IO::PathView filePath)
{
auto result = CreatePrefabInMemory(entityIds, filePath);
if (result.IsSuccess())
@@ -43,9 +43,9 @@ namespace AzToolsFramework
// PrefabPublicInterface...
PrefabOperationResult CreatePrefabInDisk(
const AZStd::vector<AZ::EntityId>& entityIds, AZ::IO::PathView filePath) override;
const EntityIdList& entityIds, AZ::IO::PathView filePath) override;
PrefabOperationResult CreatePrefabInMemory(
const AZStd::vector<AZ::EntityId>& entityIds, AZ::IO::PathView filePath) override;
const EntityIdList& entityIds, AZ::IO::PathView filePath) override;
InstantiatePrefabResult InstantiatePrefab(AZStd::string_view filePath, AZ::EntityId parent, const AZ::Vector3& position) override;
PrefabOperationResult SavePrefab(AZ::IO::Path filePath) override;
PrefabEntityResult CreateEntity(AZ::EntityId parentId, const AZ::Vector3& position) override;
@@ -47,7 +47,7 @@ namespace AzToolsFramework
* @return An outcome object; on failure, it comes with an error message detailing the cause of the error.
*/
virtual PrefabOperationResult CreatePrefabInDisk(
const AZStd::vector<AZ::EntityId>& entityIds, AZ::IO::PathView filePath) = 0;
const EntityIdList& entityIds, AZ::IO::PathView filePath) = 0;
/**
* Create a prefab out of the entities provided, at the path provided, and keep it in memory.
@@ -57,7 +57,7 @@ namespace AzToolsFramework
* @return An outcome object; on failure, it comes with an error message detailing the cause of the error.
*/
virtual PrefabOperationResult CreatePrefabInMemory(
const AZStd::vector<AZ::EntityId>& entityIds, AZ::IO::PathView filePath) = 0;
const EntityIdList& entityIds, AZ::IO::PathView filePath) = 0;
/**
* Instantiate a prefab from a prefab file.
@@ -11,13 +11,20 @@
#include <AzCore/Component/EntityId.h>
#include <AzCore/EBus/EBus.h>
#include <AzCore/Math/Vector3.h>
#include <AzCore/Outcome/Outcome.h>
#include <AzCore/std/containers/vector.h>
#include <AzCore/std/string/string.h>
#include <AzCore/std/string/string_view.h>
namespace AzToolsFramework
{
using EntityIdList = AZStd::vector<AZ::EntityId>;
namespace Prefab
{
using PrefabOperationResult = AZ::Outcome<void, AZStd::string>;
using InstantiatePrefabResult = AZ::Outcome<AZ::EntityId, AZStd::string>;
/**
* The primary purpose of this bus is to facilitate writing automated tests for prefabs.
* It calls PrefabPublicInterface internally to talk to the prefab system.
@@ -40,14 +47,25 @@ namespace AzToolsFramework
/**
* Create a prefab out of the entities provided, at the path provided, and keep it in memory.
* Automatically detects descendants of entities, and discerns between entities and child instances.
* Return whether the creation succeeded or not.
*/
virtual bool CreatePrefabInMemory(
const AZStd::vector<AZ::EntityId>& entityIds, AZStd::string_view filePath) = 0;
virtual PrefabOperationResult CreatePrefabInMemory(
const EntityIdList& entityIds, AZStd::string_view filePath) = 0;
/**
* Instantiate a prefab from a prefab file.
* Return the container entity id of the prefab instantiated if instantiation succeeded.
*/
virtual AZ::EntityId InstantiatePrefab(AZStd::string_view filePath, AZ::EntityId parent, const AZ::Vector3& position) = 0;
virtual InstantiatePrefabResult InstantiatePrefab(
AZStd::string_view filePath, AZ::EntityId parent, const AZ::Vector3& position) = 0;
/**
* Deletes all entities and their descendants from the owning instance. Bails if the entities don't
* all belong to the same instance.
* Return whether the deletion succeeded or not.
*/
virtual PrefabOperationResult DeleteEntitiesAndAllDescendantsInInstance(const EntityIdList& entityIds) = 0;
};
using PrefabPublicRequestBus = AZ::EBus<PrefabPublicRequests>;
@@ -25,6 +25,7 @@ namespace AzToolsFramework
->Attribute(AZ::Script::Attributes::Module, "prefab")
->Event("CreatePrefabInMemory", &PrefabPublicRequests::CreatePrefabInMemory)
->Event("InstantiatePrefab", &PrefabPublicRequests::InstantiatePrefab)
->Event("DeleteEntitiesAndAllDescendantsInInstance", &PrefabPublicRequests::DeleteEntitiesAndAllDescendantsInInstance)
;
}
}
@@ -44,36 +45,20 @@ namespace AzToolsFramework
m_prefabPublicInterface = nullptr;
}
bool PrefabPublicRequestHandler::CreatePrefabInMemory(const AZStd::vector<AZ::EntityId>& entityIds, AZStd::string_view filePath)
PrefabOperationResult PrefabPublicRequestHandler::CreatePrefabInMemory(const EntityIdList& entityIds, AZStd::string_view filePath)
{
auto createPrefabOutcome = m_prefabPublicInterface->CreatePrefabInMemory(entityIds, filePath);
if (!createPrefabOutcome.IsSuccess())
{
AZ_Error("CreatePrefabInMemory", false,
"Failed to create Prefab on file path '%.*s'. Error message: %s.",
AZ_STRING_ARG(filePath),
createPrefabOutcome.GetError().c_str());
return false;
}
return true;
return m_prefabPublicInterface->CreatePrefabInMemory(entityIds, filePath);
}
AZ::EntityId PrefabPublicRequestHandler::InstantiatePrefab(AZStd::string_view filePath, AZ::EntityId parent, const AZ::Vector3& position)
InstantiatePrefabResult PrefabPublicRequestHandler::InstantiatePrefab(AZStd::string_view filePath, AZ::EntityId parent, const AZ::Vector3& position)
{
auto instantiatePrefabOutcome = m_prefabPublicInterface->InstantiatePrefab(filePath, parent, position);
if (!instantiatePrefabOutcome.IsSuccess())
{
AZ_Error("InstantiatePrefab", false,
"Failed to instantiate Prefab on file path '%.*s'. Error message: %s.",
AZ_STRING_ARG(filePath),
instantiatePrefabOutcome.GetError().c_str());
return AZ::EntityId();
}
return instantiatePrefabOutcome.GetValue();
return m_prefabPublicInterface->InstantiatePrefab(filePath, parent, position);
}
PrefabOperationResult PrefabPublicRequestHandler::DeleteEntitiesAndAllDescendantsInInstance(const EntityIdList& entityIds)
{
return m_prefabPublicInterface->DeleteEntitiesAndAllDescendantsInInstance(entityIds);
}
} // namespace Prefab
} // namespace AzToolsFramework
@@ -31,8 +31,9 @@ namespace AzToolsFramework
void Connect();
void Disconnect();
bool CreatePrefabInMemory(const AZStd::vector<AZ::EntityId>& entityIds, AZStd::string_view filePath) override;
AZ::EntityId InstantiatePrefab(AZStd::string_view filePath, AZ::EntityId parent, const AZ::Vector3& position) override;
PrefabOperationResult CreatePrefabInMemory(const EntityIdList& entityIds, AZStd::string_view filePath) override;
InstantiatePrefabResult InstantiatePrefab(AZStd::string_view filePath, AZ::EntityId parent, const AZ::Vector3& position) override;
PrefabOperationResult DeleteEntitiesAndAllDescendantsInInstance(const EntityIdList& entityIds) override;
private:
PrefabPublicInterface* m_prefabPublicInterface = nullptr;
-1
View File
@@ -15,6 +15,5 @@ add_subdirectory(AzTest)
add_subdirectory(AzToolsFramework)
add_subdirectory(AzManipulatorTestFramework)
add_subdirectory(AzNetworking)
add_subdirectory(Crcfix)
add_subdirectory(GFxFramework)
add_subdirectory(GridMate)
-32
View File
@@ -1,32 +0,0 @@
#
# Copyright (c) Contributors to the Open 3D Engine Project.
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT
#
#
if (NOT PAL_TRAIT_BUILD_HOST_TOOLS)
return()
endif()
include(Platform/${PAL_PLATFORM_NAME}/PAL_${PAL_PLATFORM_NAME_LOWERCASE}.cmake)
if (NOT PAL_TRAIT_BUILD_CRCFIX)
return()
endif()
ly_add_target(
NAME Crcfix EXECUTABLE
NAMESPACE AZ
FILES_CMAKE
crcfix_files.cmake
BUILD_DEPENDENCIES
PRIVATE
AZ::AzCore
)
ly_add_source_properties(
SOURCES crcfix.cpp
PROPERTY COMPILE_DEFINITIONS
VALUES _CRT_SECURE_NO_WARNINGS
)
@@ -1,9 +0,0 @@
#
# Copyright (c) Contributors to the Open 3D Engine Project.
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT
#
#
set(PAL_TRAIT_BUILD_CRCFIX FALSE)
@@ -1,9 +0,0 @@
#
# Copyright (c) Contributors to the Open 3D Engine Project.
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT
#
#
set(PAL_TRAIT_BUILD_CRCFIX FALSE)
@@ -1,9 +0,0 @@
#
# Copyright (c) Contributors to the Open 3D Engine Project.
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT
#
#
set(PAL_TRAIT_BUILD_CRCFIX TRUE)
-538
View File
@@ -1,538 +0,0 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#include <AzCore/PlatformIncl.h>
#include <AzCore/Math/Crc.h>
#include <AzCore/std/string/string.h>
#include <AzCore/std/containers/vector.h>
#include <AzCore/Memory/SystemAllocator.h>
#include <AzCore/Memory/AllocationRecords.h>
#include <AzCore/std/chrono/chrono.h>
#include <AzCore/std/string/conversions.h>
#include <AzCore/Utils/Utils.h>
#include <stdio.h>
#include <stdlib.h>
#include <io.h>
#include <sys/stat.h>
int g_totalFixTimeMs = 0;
int g_longestFixTimeMs = 0;
class Filename
{
wchar_t fullpath[MAX_PATH];
wchar_t drive[_MAX_DRIVE];
wchar_t dir[_MAX_DIR];
wchar_t fname[_MAX_FNAME];
wchar_t ext[_MAX_EXT];
public:
Filename()
{
fullpath[0] = drive[0] = dir[0] = fname[0] = ext[0] = 0;
}
Filename(const AZStd::wstring& filename)
{
_wsplitpath(filename.c_str(), drive, dir, fname, ext);
wcscpy(fullpath, filename.c_str());
}
void SetExt(const wchar_t* pExt) { wcscpy(ext, pExt); _wmakepath(fullpath, drive, dir, fname, pExt); }
const wchar_t* GetFullPath() const { return fullpath; }
bool Exists() const { return _waccess(fullpath, 0) == 0; }
bool IsReadOnly() const { return _waccess(fullpath, 6) == -1; }
bool SetReadOnly() const { return _wchmod(fullpath, _S_IREAD) == 0; }
bool SetWritable() const { return _wchmod(fullpath, _S_IREAD | _S_IWRITE) == 0; }
bool Delete() const { return _wremove(fullpath) == 0; }
bool Rename(const wchar_t* fn2) const{ return MoveFileEx(fullpath, fn2, MOVEFILE_COPY_ALLOWED|MOVEFILE_REPLACE_EXISTING) == 0; }
bool Copy(const wchar_t* dest) const { return ::CopyFile(fullpath, dest, FALSE) == TRUE; }
};
class CRCfix
{
int lastchar;
int linenum;
public:
void SkipToEOL(FILE* infile);
char* GetToken(FILE* infile, FILE* outfile);
void GetPreviousCRC(char* token, FILE* infile);
int Fix(Filename srce);
};
void FixFiles(const AZStd::wstring& dir, const AZStd::wstring& files, FILETIME* pLastRun, bool verbose, int& nFound, int& nProcessed, int& nFixed, int& nFailed)
{
CRCfix fixer;
WIN32_FIND_DATA wfd;
HANDLE hFind;
hFind = FindFirstFile((dir + files).c_str(), &wfd);
if (hFind != INVALID_HANDLE_VALUE)
{
do
{
if ((wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
{
if (verbose)
{
AZ_TracePrintf("CrcFix", "\tProcessing %ls ...", wfd.cFileName);
}
nFound++;
int n = 0;
if ((wfd.dwFileAttributes & FILE_ATTRIBUTE_READONLY) == 0 && (!pLastRun || CompareFileTime(pLastRun, &wfd.ftLastWriteTime) <= 0))
{
n = fixer.Fix(Filename(dir + L"\\" + wfd.cFileName));
nProcessed++;
}
if (n < 0)
{
nFailed++;
if (verbose)
{
AZ_TracePrintf("CrcFix", "Failed\n");
}
}
else
{
if (verbose)
{
AZ_TracePrintf("CrcFix", n > 0 ? "Done\n" : (wfd.dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0 ? "ReadOnly\n" : "Unchanged\n");
}
nFixed += n;
}
}
} while (FindNextFile(hFind, &wfd));
}
FindClose(hFind);
}
void FixDirectories(const AZStd::wstring& dirs, const AZStd::wstring& files, FILETIME* pLastRun, bool verbose, int& nFound, int& nProcessed, int& nFixed, int& nFailed)
{
if (verbose)
{
AZ_TracePrintf("CrcFix", "Processing %ls ...\n", dirs.c_str());
}
// do files
FixFiles(dirs, files, pLastRun, verbose, nFound, nProcessed, nFixed, nFailed);
// do folders
WIN32_FIND_DATA wfd;
HANDLE hFind;
hFind = FindFirstFile((dirs + L"\\*").c_str(), &wfd);
if (hFind != INVALID_HANDLE_VALUE)
{
do
{
if ((wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY)
{
if (wfd.cFileName[0] == '.')
{
continue;
}
FixDirectories(AZStd::wstring(dirs + L"\\" + wfd.cFileName), files, pLastRun, verbose, nFound, nProcessed, nFixed, nFailed);
}
} while (FindNextFile(hFind, &wfd));
}
FindClose(hFind);
}
int main(int argc, char* argv[])
{
AZStd::chrono::system_clock::time_point startTime = AZStd::chrono::system_clock::now();
AZ::SystemAllocator::Descriptor desc;
//desc.m_stackRecordLevels = 15;
AZ::AllocatorInstance<AZ::SystemAllocator>::Create(desc);
//if (AZ::AllocatorInstance<AZ::SystemAllocator>::Get().GetRecords()) {
// AZ::AllocatorInstance<AZ::SystemAllocator>::Get().GetRecords()->SetMode(AZ::Debug::AllocationRecords::RECORD_FULL);
//}
{
if (argc < 2)
{
AZ_TracePrintf("CrcFix", "Usage:\n crcfix [-v(erbose)] [-log:logfile] {path[\\*][\\*.*]}\n");
AZ_TracePrintf("CrcFix", "\n Ex:\n crcfix -v -log:timestamp.log src\\*\\*.cpp src\\*\\*.h ..\\scripts\\*.*\n\n");
}
char root[MAX_PATH];
AZ::Utils::GetExecutableDirectory(root, MAX_PATH);
AZStd::vector<AZStd::wstring> entries;
AZStd::wstring logfilename;
FILETIME lastRun;
FILETIME* pLastRun = NULL;
bool verbose = false;
for (int iArg = 1; iArg < argc; ++iArg)
{
const char* pArg = argv[iArg];
if (!pArg)
{
continue;
}
AZStd::wstring pArgW;
AZStd::to_wstring(pArgW, pArg);
if (_strnicmp(pArg, "-log:", 5) == 0)
{
logfilename.assign(pArgW.begin() + 5, pArgW.end());
HANDLE hFile = CreateFile(logfilename.data(), 0, 0, NULL, OPEN_EXISTING, 0, NULL);
if (hFile != INVALID_HANDLE_VALUE)
{
pLastRun = &lastRun;
GetFileTime(hFile, NULL, NULL, pLastRun);
CloseHandle(hFile);
}
}
else if (_stricmp(pArg, "-v") == 0)
{
verbose = true;
}
else
{
entries.emplace_back(AZStd::move(pArgW));
}
}
// for each entry from the command line...
int nFound = 0;
int nProcessed = 0;
int nFixed = 0;
int nFailed = 0;
for (AZStd::vector<AZStd::wstring>::const_iterator iEntry = entries.begin(); iEntry != entries.end(); ++iEntry)
{
AZStd::wstring entry = (iEntry->at(0) == L'\\' || iEntry->find(L":") != iEntry->npos) ? *iEntry : AZStd::wstring(root) + L"\\" + *iEntry;
AZStd::wstring::size_type split = entry.find(L"*\\");
bool doSubdirs = split != entry.npos;
if (doSubdirs)
{
FixDirectories(entry.substr(0, split), entry.substr(split + 1), pLastRun, verbose, nFound, nProcessed, nFixed, nFailed);
}
else
{
split = entry.rfind(L"\\");
if (split == entry.npos)
{
split = 0;
}
FixFiles(entry.substr(0, split), entry.substr(split), pLastRun, verbose, nFound, nProcessed, nFixed, nFailed);
}
}
// update timestamp
if (!logfilename.empty())
{
HANDLE hFile = CreateFile(logfilename.data(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
GetSystemTimeAsFileTime(&lastRun);
SetFileTime(hFile, NULL, NULL, &lastRun);
char log[1024];
DWORD oCount;
sprintf(log, "Batches processed: %zu\n\tFiles found: %d\n\tFiles processed: %d\n\tFiles fixed: %d\n\tFiles failed: %d\n", entries.size(), nFound, nProcessed, nFixed, nFailed);
WriteFile(hFile, log, static_cast<DWORD>(strlen(log)), &oCount, NULL);
AZStd::chrono::system_clock::time_point endTime = AZStd::chrono::system_clock::now();
sprintf(log, "Total running time: %.2f secs.\n\tTotal processing time: %.2f secs.\n\tLongest processing time: %.2f secs.\n", (float)AZStd::chrono::milliseconds(endTime - startTime).count() / 1000.f, (float)g_totalFixTimeMs / 1000.f, (float)g_longestFixTimeMs / 1000.f);
WriteFile(hFile, log, static_cast<DWORD>(strlen(log)), &oCount, NULL);
CloseHandle(hFile);
}
}
AZ::AllocatorInstance<AZ::SystemAllocator>::Destroy();
return 0;
}
//-----------------------------------------------------------------------------
// CRCfix
//-----------------------------------------------------------------------------
void CRCfix::SkipToEOL(FILE* infile)
{
int c;
for (c = lastchar; c != EOF && c != '\n'; c = fgetc(infile))
{
;
}
lastchar = fgetc(infile);
linenum++;
}
//-----------------------------------------------------------------------------
char* CRCfix::GetToken(FILE* infile, FILE* outfile)
{
static char token[512];
bool commentline = false;
bool commentblock = false;
bool doublequote = false;
bool singlequote = false;
int i = 0;
int c;
if (lastchar == EOF)
{
return NULL;
}
for (c = lastchar; c != EOF; c = fgetc(infile))
{
if (!commentline && !commentblock && !doublequote && !singlequote)
{
if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '#' || c == '_')
{
token[i++] = static_cast<char>(c);
continue;
}
else
{
if (i)
{
lastchar = c;
token[i] = 0;
i = 0;
return token;
}
}
}
if (commentline)
{
if (c == '\n')
{
commentline = false;
}
}
else if (commentblock)
{
while (c == '*')
{
c = fgetc(infile);
if (c == '/')
{
commentblock = false;
}
fputc('*', outfile);
}
}
if (!commentline && !commentblock)
{
if (c == '"' && !singlequote)
{
doublequote = !doublequote;
}
else if (c == '\'' && !doublequote)
{
singlequote = !singlequote;
}
else if (!singlequote && !doublequote)
{
if (c == '/')
{
c = fgetc(infile);
if (c == '/')
{
commentline = true;
}
else if (c == '*')
{
commentblock = true;
}
if (c == '\'')
{
singlequote = true;
}
else if (c == '"')
{
doublequote = true;
}
fputc('/', outfile);
}
}
else if (c == '\\')
{
fputc(c, outfile);
c = fgetc(infile);
}
}
fputc(c, outfile);
if (c == '\n')
{
linenum++;
}
}
lastchar = c;
token[i] = 0;
return i ? token : NULL;
}
//-----------------------------------------------------------------------------
void CRCfix::GetPreviousCRC(char* token, FILE* infile)
{
int c;
while ((c = fgetc(infile)) != ')')
{
*token++ = static_cast<char>(c);
}
*token = 0;
}
//-----------------------------------------------------------------------------
int CRCfix::Fix(Filename srce)
{
AZStd::chrono::system_clock::time_point startTime = AZStd::chrono::system_clock::now();
bool changed = false;
Filename dest(srce);
dest.SetExt(L"xxx");
linenum = 0;
FILE* infile = _wfopen(srce.GetFullPath(), L"r");
FILE* outfile = _wfopen(dest.GetFullPath(), L"w");
if (!infile || !outfile)
{
if (infile)
{
fclose(infile);
infile = nullptr;
}
if (outfile)
{
fclose(outfile);
outfile = nullptr;
}
int dt = static_cast<int>(AZStd::chrono::milliseconds(AZStd::chrono::system_clock::now() - startTime).count());
g_totalFixTimeMs += dt;
if (dt > g_longestFixTimeMs)
{
g_longestFixTimeMs = dt;
}
return -1;
}
lastchar = fgetc(infile);
while (char* token = GetToken(infile, outfile))
{
bool got = false;
if (strcmp(token, "AZ_CRC") == 0 && lastchar == '(')
{
size_t i = strlen(token);
token[i++] = static_cast<char>(lastchar);
int c = fgetc(infile);
if (c == '"')
{
size_t j = i + 1;
do
{
token[i++] = static_cast<char>(c);
c = fgetc(infile);
} while (c != '"');
token[i++] = static_cast<char>(c);
c = fgetc(infile);
int oldcrc = 0, newcrc;
if (c == ',')
{
GetPreviousCRC(token + i, infile);
sscanf(token + i, "%i", &oldcrc);
c = ')';
}
if (c == ')')
{
token[i] = 0;
c = fgetc(infile);
got = true;
newcrc = AZ::Crc32(token + j, i - j - 1, true);
fprintf(outfile, "%s, 0x%08x)", token, newcrc);
if (newcrc != oldcrc)
{
changed = true;
}
}
}
lastchar = c;
token[i] = 0;
}
if (!got)
{
fwrite(token, 1, strlen(token), outfile);
}
}
fclose(infile);
fclose(outfile);
if (changed)
{
Filename backup(srce);
backup.SetExt(L"crcfix_old");
if (backup.Exists())
{
backup.SetWritable();
[[maybe_unused]] bool deleted = backup.Delete();
AZ_Assert(deleted, "failed to delete");
}
if (!srce.Copy(backup.GetFullPath()))
{
AZ_TracePrintf("CrcFix", "Failed to copy %ls to %ls\n", srce, backup);
int dt = static_cast<int>(AZStd::chrono::milliseconds(AZStd::chrono::system_clock::now() - startTime).count());
g_totalFixTimeMs += dt;
if (dt > g_longestFixTimeMs)
{
g_longestFixTimeMs = dt;
}
return -1;
}
if (!dest.Rename(srce.GetFullPath()))
{
AZ_TracePrintf("CrcFix", "Failed to rename %ls to %ls\n", dest, srce);
int dt = static_cast<int>(AZStd::chrono::milliseconds(AZStd::chrono::system_clock::now() - startTime).count());
g_totalFixTimeMs += dt;
if (dt > g_longestFixTimeMs)
{
g_longestFixTimeMs = dt;
}
return -1;
}
if (!backup.Delete())
{
AZ_TracePrintf("CrcFix", "Failed to delete %ls\n", backup);
}
}
else
{
dest.Delete();
}
int dt = static_cast<int>(AZStd::chrono::milliseconds(AZStd::chrono::system_clock::now() - startTime).count());
g_totalFixTimeMs += dt;
if (dt > g_longestFixTimeMs)
{
g_longestFixTimeMs = dt;
}
return changed ? 1 : 0;
}
//-----------------------------------------------------------------------------
-11
View File
@@ -1,11 +0,0 @@
#
# Copyright (c) Contributors to the Open 3D Engine Project.
# For complete copyright and license terms please see the LICENSE at the root of this distribution.
#
# SPDX-License-Identifier: Apache-2.0 OR MIT
#
#
set(FILES crcfix_files.cmake
crcfix.cpp
)