diff --git a/Code/.p4ignore b/Code/.p4ignore deleted file mode 100644 index f0b9f1ea6b..0000000000 --- a/Code/.p4ignore +++ /dev/null @@ -1,6 +0,0 @@ -#Ignore these directories -SDKs - -#ColinB (8/26)- I know there are depot files that this will ignore... But these files should not be -#here, they should all be in 3rdParty... so we will ignore them until I can move them, it should -#be OK for now because they shouldn't change at all anyway. diff --git a/Code/CryEngine/CryCommon/CMakeLists.txt b/Code/CryEngine/CryCommon/CMakeLists.txt index 5105ff1a5b..3a1eb90d9d 100644 --- a/Code/CryEngine/CryCommon/CMakeLists.txt +++ b/Code/CryEngine/CryCommon/CMakeLists.txt @@ -9,23 +9,15 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # -ly_get_list_relative_pal_filename(pal_dir ${CMAKE_CURRENT_LIST_DIR}/Platform/${PAL_PLATFORM_NAME}) -ly_get_pal_tool_dirs(pal_tool_dirs ${CMAKE_CURRENT_LIST_DIR}/Platform) - ly_add_target( NAME CryCommon STATIC NAMESPACE Legacy FILES_CMAKE crycommon_files.cmake - ${pal_dir}/crycommon_${PAL_PLATFORM_NAME_LOWERCASE}_files.cmake - PLATFORM_INCLUDE_FILES - ${pal_dir}/crycommon_${PAL_PLATFORM_NAME_LOWERCASE}.cmake INCLUDE_DIRECTORIES PUBLIC . # Lots of code without CryCommon/ .. # Dangerous since exports CryEngine's path (client code can do CrySystem/ without depending on that target) - ${pal_dir} - ${pal_tool_dirs} BUILD_DEPENDENCIES PUBLIC AZ::AzCore diff --git a/Code/CryEngine/CryCommon/Mocks/IMemoryManagerMock.h b/Code/CryEngine/CryCommon/Mocks/IMemoryManagerMock.h deleted file mode 100644 index 63df006e14..0000000000 --- a/Code/CryEngine/CryCommon/Mocks/IMemoryManagerMock.h +++ /dev/null @@ -1,43 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#pragma once -#include - -class MemoryManagerMock - : public IMemoryManager -{ -public: - MOCK_METHOD1(GetProcessMemInfo, - bool(SProcessMemInfo& minfo)); - MOCK_METHOD3(TraceDefineHeap, - HeapHandle(const char* heapName, size_t size, const void* pBase)); - MOCK_METHOD6(TraceHeapAlloc, - void(HeapHandle heap, void* mem, size_t size, size_t blockSize, const char* sUsage, const char* sNameHint)); - MOCK_METHOD3(TraceHeapFree, - void(HeapHandle heap, void* mem, size_t blockSize)); - MOCK_METHOD1(TraceHeapSetColor, - void(uint32 color)); - MOCK_METHOD0(TraceHeapGetColor, - uint32()); - MOCK_METHOD1(TraceHeapSetLabel, - void(const char* sLabel)); - MOCK_METHOD1(CreateCustomMemoryHeapInstance, - ICustomMemoryHeap* const (EAllocPolicy const eAllocPolicy)); - MOCK_METHOD3(CreateGeneralExpandingMemoryHeap, - IGeneralMemoryHeap* (size_t upperLimit, size_t reserveSize, const char* sUsage)); - MOCK_METHOD3(CreateGeneralMemoryHeap, - IGeneralMemoryHeap* (void* base, size_t sz, const char* sUsage)); - MOCK_METHOD2(ReserveAddressRange, - IMemoryAddressRange* (size_t capacity, const char* sName)); - MOCK_METHOD2(CreatePageMappingHeap, - IPageMappingHeap* (size_t addressSpace, const char* sName)); -}; diff --git a/Code/CryEngine/CryCommon/Mocks/INetworkMock.h b/Code/CryEngine/CryCommon/Mocks/INetworkMock.h deleted file mode 100644 index b627f927bc..0000000000 --- a/Code/CryEngine/CryCommon/Mocks/INetworkMock.h +++ /dev/null @@ -1,47 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -struct NetworkMock : public INetwork -{ - NetworkMock() : m_gridMate(nullptr) - { - } - GridMate::IGridMate* m_gridMate; - - void Release() override {} - void GetMemoryStatistics([[maybe_unused]] ICrySizer* pSizer) override {} - void GetBandwidthStatistics([[maybe_unused]] SBandwidthStats* const pStats) override {} - void GetPerformanceStatistics([[maybe_unused]] SNetworkPerformance* pSizer) override {} - void GetProfilingStatistics([[maybe_unused]] SNetworkProfilingStats* const pStats) override {} - void SyncWithGame([[maybe_unused]] ENetworkGameSync syncType) override {} - const char* GetHostName() override { return "testhostname"; } - GridMate::IGridMate* GetGridMate() override - { - return m_gridMate; - } - ChannelId GetChannelIdForSessionMember([[maybe_unused]] GridMate::GridMember* member) const override { return ChannelId(); } - ChannelId GetServerChannelId() const override { return ChannelId(); } - ChannelId GetLocalChannelId() const override { return ChannelId(); } - CTimeValue GetSessionTime() override { return CTimeValue(); } - void ChangedAspects([[maybe_unused]] EntityId id, [[maybe_unused]] NetworkAspectType aspectBits) override {} - void SetDelegatableAspectMask([[maybe_unused]] NetworkAspectType aspectBits) override {} - void SetObjectDelegatedAspectMask([[maybe_unused]] EntityId entityId, [[maybe_unused]] NetworkAspectType aspects, [[maybe_unused]] bool set) override {} - void DelegateAuthorityToClient([[maybe_unused]] EntityId entityId, [[maybe_unused]] ChannelId clientChannelId) override {} - void InvokeActorRMI([[maybe_unused]] EntityId entityId, [[maybe_unused]] uint8 actorExtensionId, [[maybe_unused]] ChannelId targetChannelFilter, [[maybe_unused]] IActorRMIRep& rep) override {} - void InvokeScriptRMI([[maybe_unused]] ISerializable* serializable, [[maybe_unused]] bool isServerRMI, [[maybe_unused]] ChannelId toChannelId = kInvalidChannelId, [[maybe_unused]] ChannelId avoidChannelId = kInvalidChannelId) override {} - void RegisterActorRMI([[maybe_unused]] IActorRMIRep* rep) override {} - void UnregisterActorRMI([[maybe_unused]] IActorRMIRep* rep) override {} - EntityId LocalEntityIdToServerEntityId([[maybe_unused]] EntityId localId) const override { return EntityId(); } - EntityId ServerEntityIdToLocalEntityId([[maybe_unused]] EntityId serverId, [[maybe_unused]] bool allowForcedEstablishment = false) const override { return EntityId(); } -}; diff --git a/Code/CryEngine/CryCommon/Mocks/MockCGFContent.h b/Code/CryEngine/CryCommon/Mocks/MockCGFContent.h deleted file mode 100644 index 8047a863f6..0000000000 --- a/Code/CryEngine/CryCommon/Mocks/MockCGFContent.h +++ /dev/null @@ -1,29 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#pragma once - -#include - -#include - -class MockIAssetWriter - : public IAssetWriter -{ -public: - ~MockIAssetWriter() override = default; - MOCK_METHOD1(WriteCGF, - bool(CContentCGF* content)); - MOCK_METHOD2(WriteCHR, - bool(CContentCGF* content, IConvertContext* convertContext)); - MOCK_METHOD3(WriteSKIN, - bool(CContentCGF* content, IConvertContext* convertContext, bool exportMorphTargets)); -}; diff --git a/Code/CryEngine/CryCommon/Platform/Android/crycommon_android.cmake b/Code/CryEngine/CryCommon/Platform/Android/crycommon_android.cmake deleted file mode 100644 index f5b9ea77a2..0000000000 --- a/Code/CryEngine/CryCommon/Platform/Android/crycommon_android.cmake +++ /dev/null @@ -1,11 +0,0 @@ -# -# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -# its licensors. -# -# For complete copyright and license terms please see the LICENSE at the root of this -# distribution (the "License"). All use of this software is governed by the License, -# or, if provided, by the license below or the license accompanying this file. Do not -# remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# - diff --git a/Code/CryEngine/CryCommon/Platform/Android/crycommon_android_files.cmake b/Code/CryEngine/CryCommon/Platform/Android/crycommon_android_files.cmake deleted file mode 100644 index 7b9245ae92..0000000000 --- a/Code/CryEngine/CryCommon/Platform/Android/crycommon_android_files.cmake +++ /dev/null @@ -1,14 +0,0 @@ -# -# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -# its licensors. -# -# For complete copyright and license terms please see the LICENSE at the root of this -# distribution (the "License"). All use of this software is governed by the License, -# or, if provided, by the license below or the license accompanying this file. Do not -# remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# - -set(FILES - ../../WinBase.cpp -) diff --git a/Code/CryEngine/CryCommon/Platform/Android/crycommon_enginesettings_android_files.cmake b/Code/CryEngine/CryCommon/Platform/Android/crycommon_enginesettings_android_files.cmake deleted file mode 100644 index 5714be5dfb..0000000000 --- a/Code/CryEngine/CryCommon/Platform/Android/crycommon_enginesettings_android_files.cmake +++ /dev/null @@ -1,13 +0,0 @@ -# -# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -# its licensors. -# -# For complete copyright and license terms please see the LICENSE at the root of this -# distribution (the "License"). All use of this software is governed by the License, -# or, if provided, by the license below or the license accompanying this file. Do not -# remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# - -set(FILES -) diff --git a/Code/CryEngine/CryCommon/Platform/AppleTV/crycommon_appletv.cmake b/Code/CryEngine/CryCommon/Platform/AppleTV/crycommon_appletv.cmake deleted file mode 100644 index f5b9ea77a2..0000000000 --- a/Code/CryEngine/CryCommon/Platform/AppleTV/crycommon_appletv.cmake +++ /dev/null @@ -1,11 +0,0 @@ -# -# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -# its licensors. -# -# For complete copyright and license terms please see the LICENSE at the root of this -# distribution (the "License"). All use of this software is governed by the License, -# or, if provided, by the license below or the license accompanying this file. Do not -# remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# - diff --git a/Code/CryEngine/CryCommon/Platform/Linux/crycommon_enginesettings_linux_files.cmake b/Code/CryEngine/CryCommon/Platform/Linux/crycommon_enginesettings_linux_files.cmake deleted file mode 100644 index 5714be5dfb..0000000000 --- a/Code/CryEngine/CryCommon/Platform/Linux/crycommon_enginesettings_linux_files.cmake +++ /dev/null @@ -1,13 +0,0 @@ -# -# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -# its licensors. -# -# For complete copyright and license terms please see the LICENSE at the root of this -# distribution (the "License"). All use of this software is governed by the License, -# or, if provided, by the license below or the license accompanying this file. Do not -# remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# - -set(FILES -) diff --git a/Code/CryEngine/CryCommon/Platform/Linux/crycommon_linux.cmake b/Code/CryEngine/CryCommon/Platform/Linux/crycommon_linux.cmake deleted file mode 100644 index f5b9ea77a2..0000000000 --- a/Code/CryEngine/CryCommon/Platform/Linux/crycommon_linux.cmake +++ /dev/null @@ -1,11 +0,0 @@ -# -# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -# its licensors. -# -# For complete copyright and license terms please see the LICENSE at the root of this -# distribution (the "License"). All use of this software is governed by the License, -# or, if provided, by the license below or the license accompanying this file. Do not -# remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# - diff --git a/Code/CryEngine/CryCommon/Platform/Linux/crycommon_linux_files.cmake b/Code/CryEngine/CryCommon/Platform/Linux/crycommon_linux_files.cmake deleted file mode 100644 index 7b9245ae92..0000000000 --- a/Code/CryEngine/CryCommon/Platform/Linux/crycommon_linux_files.cmake +++ /dev/null @@ -1,14 +0,0 @@ -# -# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -# its licensors. -# -# For complete copyright and license terms please see the LICENSE at the root of this -# distribution (the "License"). All use of this software is governed by the License, -# or, if provided, by the license below or the license accompanying this file. Do not -# remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# - -set(FILES - ../../WinBase.cpp -) diff --git a/Code/CryEngine/CryCommon/Platform/Mac/crycommon_mac.cmake b/Code/CryEngine/CryCommon/Platform/Mac/crycommon_mac.cmake deleted file mode 100644 index f5b9ea77a2..0000000000 --- a/Code/CryEngine/CryCommon/Platform/Mac/crycommon_mac.cmake +++ /dev/null @@ -1,11 +0,0 @@ -# -# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -# its licensors. -# -# For complete copyright and license terms please see the LICENSE at the root of this -# distribution (the "License"). All use of this software is governed by the License, -# or, if provided, by the license below or the license accompanying this file. Do not -# remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# - diff --git a/Code/CryEngine/CryCommon/Platform/Mac/crycommon_mac_files.cmake b/Code/CryEngine/CryCommon/Platform/Mac/crycommon_mac_files.cmake deleted file mode 100644 index 7b9245ae92..0000000000 --- a/Code/CryEngine/CryCommon/Platform/Mac/crycommon_mac_files.cmake +++ /dev/null @@ -1,14 +0,0 @@ -# -# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -# its licensors. -# -# For complete copyright and license terms please see the LICENSE at the root of this -# distribution (the "License"). All use of this software is governed by the License, -# or, if provided, by the license below or the license accompanying this file. Do not -# remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# - -set(FILES - ../../WinBase.cpp -) diff --git a/Code/CryEngine/CryCommon/Platform/Windows/crycommon_windows.cmake b/Code/CryEngine/CryCommon/Platform/Windows/crycommon_windows.cmake deleted file mode 100644 index f5b9ea77a2..0000000000 --- a/Code/CryEngine/CryCommon/Platform/Windows/crycommon_windows.cmake +++ /dev/null @@ -1,11 +0,0 @@ -# -# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -# its licensors. -# -# For complete copyright and license terms please see the LICENSE at the root of this -# distribution (the "License"). All use of this software is governed by the License, -# or, if provided, by the license below or the license accompanying this file. Do not -# remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# - diff --git a/Code/CryEngine/CryCommon/Platform/Windows/crycommon_windows_files.cmake b/Code/CryEngine/CryCommon/Platform/Windows/crycommon_windows_files.cmake deleted file mode 100644 index 5714be5dfb..0000000000 --- a/Code/CryEngine/CryCommon/Platform/Windows/crycommon_windows_files.cmake +++ /dev/null @@ -1,13 +0,0 @@ -# -# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -# its licensors. -# -# For complete copyright and license terms please see the LICENSE at the root of this -# distribution (the "License"). All use of this software is governed by the License, -# or, if provided, by the license below or the license accompanying this file. Do not -# remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# - -set(FILES -) diff --git a/Code/CryEngine/CryCommon/Platform/iOS/crycommon_enginesettings_ios_files.cmake b/Code/CryEngine/CryCommon/Platform/iOS/crycommon_enginesettings_ios_files.cmake deleted file mode 100644 index 5714be5dfb..0000000000 --- a/Code/CryEngine/CryCommon/Platform/iOS/crycommon_enginesettings_ios_files.cmake +++ /dev/null @@ -1,13 +0,0 @@ -# -# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -# its licensors. -# -# For complete copyright and license terms please see the LICENSE at the root of this -# distribution (the "License"). All use of this software is governed by the License, -# or, if provided, by the license below or the license accompanying this file. Do not -# remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# - -set(FILES -) diff --git a/Code/CryEngine/CryCommon/Platform/iOS/crycommon_ios.cmake b/Code/CryEngine/CryCommon/Platform/iOS/crycommon_ios.cmake deleted file mode 100644 index f5b9ea77a2..0000000000 --- a/Code/CryEngine/CryCommon/Platform/iOS/crycommon_ios.cmake +++ /dev/null @@ -1,11 +0,0 @@ -# -# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -# its licensors. -# -# For complete copyright and license terms please see the LICENSE at the root of this -# distribution (the "License"). All use of this software is governed by the License, -# or, if provided, by the license below or the license accompanying this file. Do not -# remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# - diff --git a/Code/CryEngine/CryCommon/Platform/iOS/crycommon_ios_files.cmake b/Code/CryEngine/CryCommon/Platform/iOS/crycommon_ios_files.cmake deleted file mode 100644 index 7b9245ae92..0000000000 --- a/Code/CryEngine/CryCommon/Platform/iOS/crycommon_ios_files.cmake +++ /dev/null @@ -1,14 +0,0 @@ -# -# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -# its licensors. -# -# For complete copyright and license terms please see the LICENSE at the root of this -# distribution (the "License"). All use of this software is governed by the License, -# or, if provided, by the license below or the license accompanying this file. Do not -# remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# - -set(FILES - ../../WinBase.cpp -) diff --git a/Code/CryEngine/CryCommon/Terrain/Bus/HeightmapDataBus.h b/Code/CryEngine/CryCommon/Terrain/Bus/HeightmapDataBus.h deleted file mode 100644 index 93065e1196..0000000000 --- a/Code/CryEngine/CryCommon/Terrain/Bus/HeightmapDataBus.h +++ /dev/null @@ -1,102 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include -#include - -namespace Terrain -{ - class Viewport2D - { - public: - int m_topLeftX = 0; - int m_topLeftY = 0; - int m_width = 0; - int m_height = 0; - - Viewport2D() = default; - Viewport2D(const Viewport2D&) = default; - Viewport2D& operator=(const Viewport2D&) = default; - - Viewport2D(int topLeftX, int topLeftY, int width, int height) - : m_topLeftX(topLeftX) - , m_topLeftY(topLeftY) - , m_width(width) - , m_height(height) - { - } - }; - - // External height map data requests - class HeightmapDataRequestInfo - { - public: - HeightmapDataRequestInfo() = default; - HeightmapDataRequestInfo(const HeightmapDataRequestInfo& rhs) = default; - HeightmapDataRequestInfo& operator=(const HeightmapDataRequestInfo& rhs) = default; - - HeightmapDataRequestInfo(int viewportTopLeftX, int viewportTopLeftY, int viewportWidth, int viewportHeight, float metersPerPixel, AZ::Vector2 worldMin, AZ::Vector2 worldMax) - : m_viewport(viewportTopLeftX, viewportTopLeftY, viewportWidth, viewportHeight) - , m_metersPerPixel(metersPerPixel) - , m_worldMin(worldMin) - , m_worldMax(worldMax) - { - } - - float GetMetersPerPixel() const - { - return m_metersPerPixel; - } - - AZ::Vector2 GetWorldMin() const - { - return m_worldMin; - } - - AZ::Vector2 GetWorldMax() const - { - return m_worldMax; - } - - AZ::Vector2 GetWorldWidth() const - { - return (m_worldMax - m_worldMin); - } - - Viewport2D GetViewport() const - { - return m_viewport; - } - - private: - Viewport2D m_viewport; - AZ::Vector2 m_worldMin = AZ::Vector2(0.0f, 0.0f); - AZ::Vector2 m_worldMax = AZ::Vector2(0.0f, 0.0f); - float m_metersPerPixel = 1.0f; - }; - - class HeightmapDataNotifications - : public AZ::EBusTraits - { - public: - ////////////////////////////////////////////////////////////////////////// - // EBusTraits overrides - static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Multiple; - static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; - ////////////////////////////////////////////////////////////////////////// - - virtual void OnTerrainHeightDataChanged(const AZ::Aabb& dirtyRegion) = 0; - }; - using HeightmapDataNotificationBus = AZ::EBus; -} diff --git a/Code/CryEngine/CryCommon/Terrain/Bus/TerrainBus.h b/Code/CryEngine/CryCommon/Terrain/Bus/TerrainBus.h deleted file mode 100644 index 2cfb5134c9..0000000000 --- a/Code/CryEngine/CryCommon/Terrain/Bus/TerrainBus.h +++ /dev/null @@ -1,56 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include -#include - -class CShader; - -namespace Terrain -{ - class TerrainDataRequests - : public AZ::EBusTraits - { - public: - ////////////////////////////////////////////////////////////////////////// - // EBusTraits overrides - static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single; - static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; - using MutexType = AZStd::recursive_mutex; - ////////////////////////////////////////////////////////////////////////// - - virtual float GetHeightSynchronous(float x, float y) = 0; - virtual AZ::Vector3 GetNormalSynchronous(float x, float y) = 0; - - virtual CShader* GetTerrainHeightGeneratorShader() const = 0; - virtual CShader* GetTerrainMaterialCompositingShader() const = 0; - }; - using TerrainDataRequestBus = AZ::EBus; - - class TerrainShaderRequests - : public AZ::EBusTraits - { - public: - ////////////////////////////////////////////////////////////////////////// - // EBusTraits overrides - static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single; - static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; - using MutexType = AZStd::recursive_mutex; - ////////////////////////////////////////////////////////////////////////// - - virtual void RefreshShader(const AZStd::string_view name, CShader* shader) = 0; - virtual void ReleaseShader(CShader* shader) const = 0; - }; - using TerrainShaderRequestBus = AZ::EBus; -} diff --git a/Code/CryEngine/CryCommon/Terrain/Bus/TerrainProviderBus.h b/Code/CryEngine/CryCommon/Terrain/Bus/TerrainProviderBus.h deleted file mode 100644 index 6c1aca6ea7..0000000000 --- a/Code/CryEngine/CryCommon/Terrain/Bus/TerrainProviderBus.h +++ /dev/null @@ -1,82 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include -#include -#include - -#include - -#include "HeightmapDataBus.h" - -class CShader; - -namespace Terrain -{ - // This interface defines how the renderer can access the terrain system to set up state and gather information before rendering height maps - class TerrainProviderRequests - : public AZ::EBusTraits - { - public: - ////////////////////////////////////////////////////////////////////////// - // EBusTraits overrides - static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single; - static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; - //! allows multiple threads to call - using MutexType = AZStd::recursive_mutex; - ////////////////////////////////////////////////////////////////////////// - - // world properties - virtual AZ::Vector3 GetWorldSize() = 0; - virtual AZ::Vector3 GetRegionSize() = 0; - virtual AZ::Vector3 GetWorldOrigin() = 0; - virtual AZ::Vector2 GetHeightRange() = 0; - - // utility - virtual void GetRegionIndex(const AZ::Vector2& worldMin, const AZ::Vector2& worldMax, int& regionIndexX, int& regionIndexY) = 0; - - virtual float GetHeightAtIndexedPosition([[maybe_unused]] int ix, [[maybe_unused]] int iy) { return 64.0f; } - virtual float GetHeightAtWorldPosition([[maybe_unused]] float fx, [[maybe_unused]] float fy) { return 64.0f; } - virtual unsigned char GetSurfaceTypeAtIndexedPosition([[maybe_unused]] int ix, [[maybe_unused]] int iy) { return 0; } - }; - using TerrainProviderRequestBus = AZ::EBus; - - // This class exists for the terrain system to inject data into the renderer for generating the GPU-side terrain height map - struct CRETerrainContext - { - // Tract map - virtual void OnTractVersionUpdate() = 0; - - CShader* m_currentShader = nullptr; - }; - - class TerrainProviderNotifications - : public AZ::EBusTraits - { - public: - ////////////////////////////////////////////////////////////////////////// - // EBusTraits overrides - static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single; - static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; - //! allows multiple threads to call - using MutexType = AZStd::recursive_mutex; - ////////////////////////////////////////////////////////////////////////// - - // interface to be implemented by the game, invoked by the terrain render element - - // pull settings from the world cache, so the next accessors are accurate - virtual void SynchronizeSettings(CRETerrainContext* context) = 0; - }; - using TerrainProviderNotificationBus = AZ::EBus; -} diff --git a/Code/CryEngine/CryCommon/Terrain/Bus/TerrainRendererBus.h b/Code/CryEngine/CryCommon/Terrain/Bus/TerrainRendererBus.h deleted file mode 100644 index ea644f5653..0000000000 --- a/Code/CryEngine/CryCommon/Terrain/Bus/TerrainRendererBus.h +++ /dev/null @@ -1,37 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include - -namespace Terrain -{ - class TerrainRendererRequests - : public AZ::EBusTraits - { - public: - ////////////////////////////////////////////////////////////////////////// - // EBusTraits overrides - static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single; - static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; - ////////////////////////////////////////////////////////////////////////// - - //! allows multiple threads to call - using MutexType = AZStd::recursive_mutex; - - // Query state of the terrain renderer - // Returns true once the terrain renderer has fulfilled most data requests and is ready for rendering - virtual bool IsReady() = 0; - }; - using TerrainRendererRequestBus = AZ::EBus; -} diff --git a/Code/CryEngine/CryCommon/Terrain/Bus/WorldMaterialRequestsBus.h b/Code/CryEngine/CryCommon/Terrain/Bus/WorldMaterialRequestsBus.h deleted file mode 100644 index 3fb80f5f11..0000000000 --- a/Code/CryEngine/CryCommon/Terrain/Bus/WorldMaterialRequestsBus.h +++ /dev/null @@ -1,122 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ - -#pragma once - -#include -#include -#include - -struct IMaterial; -class ITexture; - -namespace Terrain -{ - struct MacroMaterial - { - // Textures - _smart_ptr m_macroColorMap = nullptr; - _smart_ptr m_macroGlossMap = nullptr; - _smart_ptr m_macroNormalMap = nullptr; - - // Material Params - AZ::Color m_macroColorMapColor; - float m_macroGlossMapScale = 1.0f; - float m_macroNormalMapScale = 1.0f; - float m_macroSpecReflectance = 0.03f; - - void Clear() - { - m_macroColorMap = nullptr; - m_macroGlossMap = nullptr; - m_macroNormalMap = nullptr; - - m_macroColorMapColor = AZ::Color(1.0f); - m_macroGlossMapScale = 1.0f; - m_macroNormalMapScale = 1.0f; - m_macroSpecReflectance = 0.03f; - } - }; - - struct TerrainMaterialLayer - { - _smart_ptr m_material = nullptr; - _smart_ptr m_splatTexture = nullptr; - - TerrainMaterialLayer(_smart_ptr material, _smart_ptr splatTexture) - : m_material(material) - , m_splatTexture(splatTexture) - { - } - }; - - struct RegionMaterials - { - MacroMaterial m_macroMaterial; - - AZStd::vector m_materialLayers; - _smart_ptr m_defaultMaterial = nullptr; - - RegionMaterials& operator=(const RegionMaterials& rhs) = default; - - void Clear() - { - m_materialLayers.clear(); - m_defaultMaterial = nullptr; - m_macroMaterial.Clear(); - } - }; - - const AZ::u32 kMaxRegionsPerTerrainMaterialRequest = 16; - typedef AZStd::pair RegionIndex; - typedef AZStd::fixed_vector RegionIndexVector; - typedef AZStd::fixed_vector RegionMaterialVector; - - enum class RequestResult - { - NoAssetsForRegion, - Loading, - Success - }; - - class WorldMaterialRequests - : public AZ::EBusTraits - { - public: - ////////////////////////////////////////////////////////////////////////// - // EBusTraits overrides - static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single; - static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; - ////////////////////////////////////////////////////////////////////////// - - //! allows multiple threads to call - using MutexType = AZStd::recursive_mutex; - - virtual void LoadWorld(const AZStd::string& worldName, int regionSize) = 0; - - virtual RequestResult RequestRegionMaterials(const RegionIndexVector& regions, RegionMaterialVector& outRegionMaterials) = 0; - - // Parameters: - // int tileX, tileY : Region tile indices - // Returns: - // bool : If true, region material data is loaded and exists. outMacroMaterial will be modified with the respective macro material data - // If false, no region material data has been loaded or exists for the given tile (may still have invalid material layers). - virtual RequestResult GetMacroMaterial(int tileX, int tileY, MacroMaterial& outMacroMaterial) = 0; - - virtual void GetTerrainPOMParameters(float& pomHeightBias, float& pomDisplacement, float& selfShadowStrength) = 0; - - //Get the surface type at a given position. If not loaded yet, returns "loadingMaterial". - virtual AZStd::string_view GetSurfaceTypeAtPosition(AZ::Vector2 position) = 0; - }; - using WorldMaterialRequestBus = AZ::EBus; -} // namespace Terrain - diff --git a/Code/CryEngine/CryCommon/WinBase.cpp b/Code/CryEngine/CryCommon/WinBase.cpp index e6ea1cd4a8..47cb943240 100644 --- a/Code/CryEngine/CryCommon/WinBase.cpp +++ b/Code/CryEngine/CryCommon/WinBase.cpp @@ -12,6 +12,7 @@ // Original file Copyright Crytek GMBH or its affiliates, used under license. // Description : Linux/Mac port support for Win32API calls +#if !defined(WIN32) #include "platform.h" // Note: This should be first to get consistent debugging definitions @@ -1667,3 +1668,5 @@ __finddata64_t::~__finddata64_t() } } #endif //defined(APPLE) || defined(LINUX) + +#endif // !defined(WIN32) diff --git a/Code/CryEngine/CryCommon/crycommon_files.cmake b/Code/CryEngine/CryCommon/crycommon_files.cmake index 77b51825f1..dff4ca66e7 100644 --- a/Code/CryEngine/CryCommon/crycommon_files.cmake +++ b/Code/CryEngine/CryCommon/crycommon_files.cmake @@ -249,7 +249,6 @@ set(FILES platform_impl.cpp Win32specific.h Win64specific.h - stl/STLAlignedAlloc.h LyShine/IDraw2d.h LyShine/ILyShine.h LyShine/ISprite.h @@ -341,11 +340,7 @@ set(FILES Maestro/Types/AssetBlendKey.h Maestro/Types/AssetBlends.h Maestro/Types/SequenceType.h - Terrain/Bus/WorldMaterialRequestsBus.h - Terrain/Bus/TerrainBus.h - Terrain/Bus/TerrainRendererBus.h - Terrain/Bus/HeightmapDataBus.h - Terrain/Bus/TerrainProviderBus.h StaticInstance.h Pak/CryPakUtils.h + WinBase.cpp ) diff --git a/Code/CryEngine/CryCommon/crycommon_linux_files.cmake b/Code/CryEngine/CryCommon/crycommon_linux_files.cmake deleted file mode 100644 index 5714be5dfb..0000000000 --- a/Code/CryEngine/CryCommon/crycommon_linux_files.cmake +++ /dev/null @@ -1,13 +0,0 @@ -# -# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -# its licensors. -# -# For complete copyright and license terms please see the LICENSE at the root of this -# distribution (the "License"). All use of this software is governed by the License, -# or, if provided, by the license below or the license accompanying this file. Do not -# remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# - -set(FILES -) diff --git a/Code/CryEngine/CryCommon/crycommon_testing_files.cmake b/Code/CryEngine/CryCommon/crycommon_testing_files.cmake index d20a33f791..b94be27c3b 100644 --- a/Code/CryEngine/CryCommon/crycommon_testing_files.cmake +++ b/Code/CryEngine/CryCommon/crycommon_testing_files.cmake @@ -14,12 +14,10 @@ set(FILES Mocks/IConsoleMock.h Mocks/ICryPakMock.h Mocks/ILogMock.h - Mocks/IMemoryManagerMock.h Mocks/ISystemMock.h Mocks/ITimerMock.h Mocks/ICVarMock.h Mocks/IRendererMock.h Mocks/ITextureMock.h Mocks/IRemoteConsoleMock.h - Mocks/MockCGFContent.h ) diff --git a/Code/CryEngine/CryCommon/stl/STLAlignedAlloc.h b/Code/CryEngine/CryCommon/stl/STLAlignedAlloc.h deleted file mode 100644 index dc21cead81..0000000000 --- a/Code/CryEngine/CryCommon/stl/STLAlignedAlloc.h +++ /dev/null @@ -1,115 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Implements an aligned allocator for STL -// based on the Mallocator (http://blogs.msdn.com/b/vcblog/archive/2008/08/28/the-mallocator.aspx) - -#pragma once - -#include // Required for size_t and ptrdiff_t and NULL - -#include - -namespace stl -{ - template - class AlignedAllocator - : public AZ::SimpleSchemaAllocator> - { - public: - AZ_TYPE_INFO(AlignedAllocator, "{DF152D8A-36ED-4A2A-9FA6-734F212716C6}"); - using Base = AZ::SimpleSchemaAllocator>; - using Descriptor = Base::Descriptor; - using Schema = AZ::ChildAllocatorSchema; - - AlignedAllocator() - : Base("AlignedAllocator", "Legacy Cry Aligned Allocator") - { - } - - pointer_type Allocate(size_type byteSize, size_type /*alignment*/, int flags /* = 0 */, const char* name /* = 0 */, const char* fileName /* = 0 */, int lineNum /* = 0 */, unsigned int suppressStackRecord /* = 0 */) override - { - return Base::Allocate(byteSize, Alignment, flags, name, fileName, lineNum, suppressStackRecord); - } - - void DeAllocate(pointer_type ptr, size_type byteSize, [[maybe_unused]] size_type alignment) override - { - return Base::DeAllocate(ptr, byteSize, Alignment); - } - - pointer_type ReAllocate(pointer_type ptr, size_type newSize, size_type /*newAlignment*/) override - { - return Base::ReAllocate(ptr, newSize, Alignment); - } - }; - - template - using aligned_alloc = AZ::AZStdAlloc>; - - ////////////////////////////////////////////////////////////////////////// - // Defines aligned vector type - ////////////////////////////////////////////////////////////////////////// - template - class aligned_vector - : public AZStd::vector > - { - public: - typedef aligned_alloc MyAlloc; - typedef AZStd::vector MySuperClass; - typedef aligned_vector MySelf; - typedef size_t size_type; - - aligned_vector() {} - explicit aligned_vector(const MyAlloc& _Al) - : MySuperClass(_Al) {} - explicit aligned_vector(size_type _Count) - : MySuperClass(_Count) {}; - aligned_vector(size_type _Count, const T& _Val) - : MySuperClass(_Count, _Val) {} - aligned_vector(size_type _Count, const T& _Val, const MyAlloc& _Al) - : MySuperClass(_Count, _Val) {} - aligned_vector(const MySelf& _Right) - : MySuperClass(_Right) {}; - - - template - aligned_vector(_Iter _First, _Iter _Last) - : MySuperClass(_First, _Last) {}; - - template - aligned_vector(_Iter _First, _Iter _Last, const MyAlloc& _Al) - : MySuperClass(_First, _Last, _Al) {}; - }; - - template - inline size_t size_of_aligned_vector(const Vec& c) - { - if (!c.empty()) - { - // Not really correct as not taking alignment into the account - return c.capacity() * sizeof(typename Vec::value_type); - } - return 0; - } -} // namespace stl - -// Specialize for the AlignedAllocator to provide one per module that does not use the -// environment for its storage. Since this allocator just uses LegacyAllocator -// to do the real work, it's fine if there is one of these per cry module -namespace AZ -{ - template - class AllocatorInstance> : public Internal::AllocatorInstanceBase, AllocatorStorage::ModuleStoragePolicy>> - { - }; -} diff --git a/Code/CryEngine/CrySystem/Tests/Test_CryPrimitives.cpp b/Code/CryEngine/CrySystem/Tests/Test_CryPrimitives.cpp index 2e6e646548..26d12ffd8c 100644 --- a/Code/CryEngine/CrySystem/Tests/Test_CryPrimitives.cpp +++ b/Code/CryEngine/CrySystem/Tests/Test_CryPrimitives.cpp @@ -12,7 +12,6 @@ #include "CrySystem_precompiled.h" #include #include -#include TEST(StringTests, CUT_Strings) { @@ -424,21 +423,6 @@ TEST_F(CryPrimitives, CUT_FixedString) EXPECT_EQ("0123", str5); } -////////////////////////////////////////////////////////////////////////// -// Unit Testing of aligned_vector -////////////////////////////////////////////////////////////////////////// -TEST_F(CryPrimitives, CUT_AlignedVector) -{ - stl::aligned_vector vec; - - vec.push_back(1); - vec.push_back(2); - vec.push_back(3); - - EXPECT_TRUE(vec.size() == 3); - EXPECT_TRUE(((INT_PTR)(&vec[0]) % 16) == 0); -} - TEST_F(CryPrimitives, CUT_DynArray) { LegacyDynArray a; diff --git a/Code/Framework/AtomCore/.p4ignore b/Code/Framework/AtomCore/.p4ignore deleted file mode 100644 index 6722cd96e7..0000000000 --- a/Code/Framework/AtomCore/.p4ignore +++ /dev/null @@ -1 +0,0 @@ -*.xml diff --git a/Code/Framework/AzCore/.p4ignore b/Code/Framework/AzCore/.p4ignore deleted file mode 100644 index 6722cd96e7..0000000000 --- a/Code/Framework/AzCore/.p4ignore +++ /dev/null @@ -1 +0,0 @@ -*.xml diff --git a/Code/Sandbox/.p4ignore b/Code/Sandbox/.p4ignore deleted file mode 100644 index 9c6b6fcd91..0000000000 --- a/Code/Sandbox/.p4ignore +++ /dev/null @@ -1,5 +0,0 @@ -#Ignore these directories -SDKs - -#ignore these files -*.user diff --git a/Code/Tools/CMakeLists.txt b/Code/Tools/CMakeLists.txt index db5476756b..278474819c 100644 --- a/Code/Tools/CMakeLists.txt +++ b/Code/Tools/CMakeLists.txt @@ -15,7 +15,6 @@ add_subdirectory(AWSNativeSDKInit) add_subdirectory(AzTestRunner) add_subdirectory(CrashHandler) add_subdirectory(CryCommonTools) -add_subdirectory(CryXML) add_subdirectory(News) add_subdirectory(PythonBindingsExample) add_subdirectory(RemoteConsole) diff --git a/Code/Tools/CryCommonTools/CMakeLists.txt b/Code/Tools/CryCommonTools/CMakeLists.txt index 0188506e97..63f535b1af 100644 --- a/Code/Tools/CryCommonTools/CMakeLists.txt +++ b/Code/Tools/CryCommonTools/CMakeLists.txt @@ -13,44 +13,18 @@ if (NOT PAL_TRAIT_BUILD_HOST_TOOLS) return() endif() -ly_get_list_relative_pal_filename(pal_dir ${CMAKE_CURRENT_LIST_DIR}/Platform/${PAL_PLATFORM_NAME}) - ly_add_target( NAME CryCommonTools STATIC NAMESPACE Legacy FILES_CMAKE crycommontools_files.cmake - ${pal_dir}/platform_${PAL_PLATFORM_NAME_LOWERCASE}_files.cmake INCLUDE_DIRECTORIES PUBLIC . - ${pal_dir} BUILD_DEPENDENCIES PRIVATE - 3rdParty::lz4 - 3rdParty::zlib - 3rdParty::zstd AZ::AzCore PUBLIC Legacy::CryCommon AZ::AzFramework ) - -if(PAL_TRAIT_BUILD_TESTS_SUPPORTED) - ly_add_target( - NAME CryCommonTools.Tests ${PAL_TRAIT_TEST_TARGET_TYPE} - NAMESPACE Legacy - FILES_CMAKE - crycommontools_tests_files.cmake - INCLUDE_DIRECTORIES - PUBLIC - UnitTests - BUILD_DEPENDENCIES - PRIVATE - Legacy::CryCommonTools - AZ::AzTest - ) - ly_add_googletest( - NAME Legacy::CryCommonTools.Tests - ) -endif() diff --git a/Code/Tools/CryCommonTools/ColladaShared.h b/Code/Tools/CryCommonTools/ColladaShared.h deleted file mode 100644 index edc8341fe1..0000000000 --- a/Code/Tools/CryCommonTools/ColladaShared.h +++ /dev/null @@ -1,18 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#ifndef CRYINCLUDE_CRYCOMMONTOOLS_COLLADASHARED_H -#define CRYINCLUDE_CRYCOMMONTOOLS_COLLADASHARED_H -#pragma once - -static const char* g_LumberyardExportNodeTag = "LumberyardExportNode"; - -#endif // CRYINCLUDE_CRYCOMMONTOOLS_COLLADASHARED_H diff --git a/Code/Tools/CryCommonTools/Decompose.cpp b/Code/Tools/CryCommonTools/Decompose.cpp deleted file mode 100644 index 3cf88db251..0000000000 --- a/Code/Tools/CryCommonTools/Decompose.cpp +++ /dev/null @@ -1,514 +0,0 @@ -// Modifications copyright Amazon.com, Inc. or its affiliates. - -#include - -// Taken from http://tog.acm.org/GraphicsGems/gemsiv/polar_decomp/Decompose.c - -/**** Decompose.c ****/ -/* Ken Shoemake, 1993 */ -#include -#include "Decompose.h" - -#pragma warning(disable:4244) // conversion from 'double' to 'float', possible loss of data -#pragma warning(disable:4305) // 'initializing' : truncation from 'double' to 'float' - -namespace decomp { - - /******* Matrix Preliminaries *******/ - - /** Fill out 3x3 matrix to 4x4 **/ -#define mat_pad(A) (A[W][X]=A[X][W]=A[W][Y]=A[Y][W]=A[W][Z]=A[Z][W]=0,A[W][W]=1) - -/** Copy nxn matrix A to C using "gets" for assignment **/ -#define mat_copy(C,gets,A,n) {int i,j; for(i=0;i= 0.0) { - s = sqrt(tr + mat[W][W]); - qu.w = s * 0.5; - s = 0.5 / s; - qu.x = (mat[Z][Y] - mat[Y][Z]) * s; - qu.y = (mat[X][Z] - mat[Z][X]) * s; - qu.z = (mat[Y][X] - mat[X][Y]) * s; - } else { - int h = X; - if (mat[Y][Y] > mat[X][X]) h = Y; - if (mat[Z][Z] > mat[h][h]) h = Z; - switch (h) { -#define caseMacro(i,j,k,I,J,K) \ - case I:\ - s = sqrt( (mat[I][I] - (mat[J][J]+mat[K][K])) + mat[W][W] );\ - qu.i = s*0.5;\ - s = 0.5 / s;\ - qu.j = (mat[I][J] + mat[J][I]) * s;\ - qu.k = (mat[K][I] + mat[I][K]) * s;\ - qu.w = (mat[K][J] - mat[J][K]) * s;\ - break - caseMacro(x, y, z, X, Y, Z); - caseMacro(y, z, x, Y, Z, X); - caseMacro(z, x, y, Z, X, Y); - } - } - if (mat[W][W] != 1.0) qu = Qt_Scale(qu, 1 / sqrt(mat[W][W])); - return (qu); - } - /******* Decomp Auxiliaries *******/ - - static HMatrix mat_id = { {1,0,0,0},{0,1,0,0},{0,0,1,0},{0,0,0,1} }; - - /** Compute either the 1 or infinity norm of M, depending on tpose **/ - float mat_norm(HMatrix M, int tpose) - { - int i; - float sum, max; - max = 0.0; - for (i = 0; i < 3; i++) { - if (tpose) sum = fabs(M[0][i]) + fabs(M[1][i]) + fabs(M[2][i]); - else sum = fabs(M[i][0]) + fabs(M[i][1]) + fabs(M[i][2]); - if (max < sum) max = sum; - } - return max; - } - - float norm_inf(HMatrix M) { return mat_norm(M, 0); } - float norm_one(HMatrix M) { return mat_norm(M, 1); } - - /** Return index of column of M containing maximum abs entry, or -1 if M=0 **/ - int find_max_col(HMatrix M) - { - float abs, max; - int i, j, col; - max = 0.0; col = -1; - for (i = 0; i < 3; i++) for (j = 0; j < 3; j++) { - abs = M[i][j]; if (abs < 0.0) abs = -abs; - if (abs > max) { max = abs; col = j; } - } - return col; - } - - /** Setup u for Household reflection to zero all v components but first **/ - void make_reflector(float* v, float* u) - { - float s = sqrt(vdot(v, v)); - u[0] = v[0]; u[1] = v[1]; - u[2] = v[2] + ((v[2] < 0.0) ? -s : s); - s = sqrt(2.0 / vdot(u, u)); - u[0] = u[0] * s; u[1] = u[1] * s; u[2] = u[2] * s; - } - - /** Apply Householder reflection represented by u to column vectors of M **/ - void reflect_cols(HMatrix M, float* u) - { - int i, j; - for (i = 0; i < 3; i++) { - float s = u[0] * M[0][i] + u[1] * M[1][i] + u[2] * M[2][i]; - for (j = 0; j < 3; j++) M[j][i] -= u[j] * s; - } - } - /** Apply Householder reflection represented by u to row vectors of M **/ - void reflect_rows(HMatrix M, float* u) - { - int i, j; - for (i = 0; i < 3; i++) { - float s = vdot(u, M[i]); - for (j = 0; j < 3; j++) M[i][j] -= u[j] * s; - } - } - - /** Find orthogonal factor Q of rank 1 (or less) M **/ - void do_rank1(HMatrix M, HMatrix Q) - { - float v1[3], v2[3], s; - int col; - mat_copy(Q, =, mat_id, 4); - /* If rank(M) is 1, we should find a non-zero column in M */ - col = find_max_col(M); - if (col < 0) return; /* Rank is 0 */ - v1[0] = M[0][col]; v1[1] = M[1][col]; v1[2] = M[2][col]; - make_reflector(v1, v1); reflect_cols(M, v1); - v2[0] = M[2][0]; v2[1] = M[2][1]; v2[2] = M[2][2]; - make_reflector(v2, v2); reflect_rows(M, v2); - s = M[2][2]; - if (s < 0.0) Q[2][2] = -1.0; - reflect_cols(Q, v1); reflect_rows(Q, v2); - } - - /** Find orthogonal factor Q of rank 2 (or less) M using adjoint transpose **/ - void do_rank2(HMatrix M, HMatrix MadjT, HMatrix Q) - { - float v1[3], v2[3]; - float w, x, y, z, c, s, d; - int col; - /* If rank(M) is 2, we should find a non-zero column in MadjT */ - col = find_max_col(MadjT); - if (col < 0) { do_rank1(M, Q); return; } /* Rank<2 */ - v1[0] = MadjT[0][col]; v1[1] = MadjT[1][col]; v1[2] = MadjT[2][col]; - make_reflector(v1, v1); reflect_cols(M, v1); - vcross(M[0], M[1], v2); - make_reflector(v2, v2); reflect_rows(M, v2); - w = M[0][0]; x = M[0][1]; y = M[1][0]; z = M[1][1]; - if (w * z > x* y) { - c = z + w; s = y - x; d = sqrt(c * c + s * s); c = c / d; s = s / d; - Q[0][0] = Q[1][1] = c; Q[0][1] = -(Q[1][0] = s); - } else { - c = z - w; s = y + x; d = sqrt(c * c + s * s); c = c / d; s = s / d; - Q[0][0] = -(Q[1][1] = c); Q[0][1] = Q[1][0] = s; - } - Q[0][2] = Q[2][0] = Q[1][2] = Q[2][1] = 0.0; Q[2][2] = 1.0; - reflect_cols(Q, v1); reflect_rows(Q, v2); - } - - - /******* Polar Decomposition *******/ - - /* Polar Decomposition of 3x3 matrix in 4x4, - * M = QS. See Nicholas Higham and Robert S. Schreiber, - * Fast Polar Decomposition of An Arbitrary Matrix, - * Technical Report 88-942, October 1988, - * Department of Computer Science, Cornell University. - */ - float polar_decomp(HMatrix M, HMatrix Q, HMatrix S) - { -#define TOL 1.0e-6 - HMatrix Mk, MadjTk, Ek; - float det, M_one, M_inf, MadjT_one, MadjT_inf, E_one, gamma, g1, g2; - int i, j; - mat_tpose(Mk, =, M, 3); - M_one = norm_one(Mk); M_inf = norm_inf(Mk); - do { - adjoint_transpose(Mk, MadjTk); - det = vdot(Mk[0], MadjTk[0]); - if (det == 0.0) { do_rank2(Mk, MadjTk, Mk); break; } - MadjT_one = norm_one(MadjTk); MadjT_inf = norm_inf(MadjTk); - gamma = sqrt(sqrt((MadjT_one * MadjT_inf) / (M_one * M_inf)) / fabs(det)); - g1 = gamma * 0.5; - g2 = 0.5 / (gamma * det); - mat_copy(Ek, =, Mk, 3); - mat_binop(Mk, =, g1 * Mk, +, g2 * MadjTk, 3); - mat_copy(Ek, -=, Mk, 3); - E_one = norm_one(Ek); - M_one = norm_one(Mk); M_inf = norm_inf(Mk); - } while (E_one > (M_one * TOL)); - mat_tpose(Q, =, Mk, 3); mat_pad(Q); - mat_mult(Mk, M, S); mat_pad(S); - for (i = 0; i < 3; i++) for (j = i; j < 3; j++) - S[i][j] = S[j][i] = 0.5 * (S[i][j] + S[j][i]); - return (det); - } - - - - - - - - - - - - - - - - - - /******* Spectral Decomposition *******/ - - /* Compute the spectral decomposition of symmetric positive semi-definite S. - * Returns rotation in U and scale factors in result, so that if K is a diagonal - * matrix of the scale factors, then S = U K (U transpose). Uses Jacobi method. - * See Gene H. Golub and Charles F. Van Loan. Matrix Computations. Hopkins 1983. - */ - HVect spect_decomp(HMatrix S, HMatrix U) - { - HVect kv; - double Diag[3], OffD[3]; /* OffD is off-diag (by omitted index) */ - double g, h, fabsh, fabsOffDi, t, theta, c, s, tau, ta, OffDq, a, b; - static char nxt[] = { Y,Z,X }; - int sweep, i, j; - mat_copy(U, =, mat_id, 4); - Diag[X] = S[X][X]; Diag[Y] = S[Y][Y]; Diag[Z] = S[Z][Z]; - OffD[X] = S[Y][Z]; OffD[Y] = S[Z][X]; OffD[Z] = S[X][Y]; - for (sweep = 20; sweep > 0; sweep--) { - float sm = fabs(OffD[X]) + fabs(OffD[Y]) + fabs(OffD[Z]); - if (sm == 0.0) break; - for (i = Z; i >= X; i--) { - int p = nxt[i]; int q = nxt[p]; - fabsOffDi = fabs(OffD[i]); - g = 100.0 * fabsOffDi; - if (fabsOffDi > 0.0) { - h = Diag[q] - Diag[p]; - fabsh = fabs(h); - if (fabsh + g == fabsh) { - t = OffD[i] / h; - } else { - theta = 0.5 * h / OffD[i]; - t = 1.0 / (fabs(theta) + sqrt(theta * theta + 1.0)); - if (theta < 0.0) t = -t; - } - c = 1.0 / sqrt(t * t + 1.0); s = t * c; - tau = s / (c + 1.0); - ta = t * OffD[i]; OffD[i] = 0.0; - Diag[p] -= ta; Diag[q] += ta; - OffDq = OffD[q]; - OffD[q] -= s * (OffD[p] + tau * OffD[q]); - OffD[p] += s * (OffDq - tau * OffD[p]); - for (j = Z; j >= X; j--) { - a = U[j][p]; b = U[j][q]; - U[j][p] -= s * (b + tau * a); - U[j][q] += s * (a - tau * b); - } - } - } - } - kv.x = Diag[X]; kv.y = Diag[Y]; kv.z = Diag[Z]; kv.w = 1.0; - return (kv); - } - - /******* Spectral Axis Adjustment *******/ - - /* Given a unit quaternion, q, and a scale vector, k, find a unit quaternion, p, - * which permutes the axes and turns freely in the plane of duplicate scale - * factors, such that q p has the largest possible w component, i.e. the - * smallest possible angle. Permutes k's components to go with q p instead of q. - * See Ken Shoemake and Tom Duff. Matrix Animation and Polar Decomposition. - * Proceedings of Graphics Interface 1992. Details on p. 262-263. - */ - Quat snuggle(Quat q, HVect* k) - { -#define SQRTHALF (0.7071067811865475244f) -#define sgn(n,v) ((n)?-(v):(v)) -#define swap(a,i,j) {a[3]=a[i]; a[i]=a[j]; a[j]=a[3];} -#define cycle(a,p) if (p) {a[3]=a[0]; a[0]=a[1]; a[1]=a[2]; a[2]=a[3];}\ - else {a[3]=a[2]; a[2]=a[1]; a[1]=a[0]; a[0]=a[3];} - Quat p; - float ka[4]; - int i, turn = -1; - ka[X] = k->x; ka[Y] = k->y; ka[Z] = k->z; - if (ka[X] == ka[Y]) { if (ka[X] == ka[Z]) turn = W; else turn = Z; } - else { if (ka[X] == ka[Z]) turn = Y; else if (ka[Y] == ka[Z]) turn = X; } - if (turn >= 0) { - Quat qtoz, qp; - unsigned neg[3], win; - double mag[3], t; - static Quat qxtoz = { 0,SQRTHALF,0,SQRTHALF }; - static Quat qytoz = { SQRTHALF,0,0,SQRTHALF }; - static Quat qppmm = { 0.5, 0.5,-0.5,-0.5 }; - static Quat qpppp = { 0.5, 0.5, 0.5, 0.5 }; - static Quat qmpmm = { -0.5, 0.5,-0.5,-0.5 }; - static Quat qpppm = { 0.5, 0.5, 0.5,-0.5 }; - static Quat q0001 = { 0.0, 0.0, 0.0, 1.0 }; - static Quat q1000 = { 1.0, 0.0, 0.0, 0.0 }; - switch (turn) { - default: return (Qt_Conj(q)); - case X: q = Qt_Mul(q, qtoz = qxtoz); swap(ka, X, Z) break; - case Y: q = Qt_Mul(q, qtoz = qytoz); swap(ka, Y, Z) break; - case Z: qtoz = q0001; break; - } - q = Qt_Conj(q); - mag[0] = (double)q.z * q.z + (double)q.w * q.w - 0.5; - mag[1] = (double)q.x * q.z - (double)q.y * q.w; - mag[2] = (double)q.y * q.z + (double)q.x * q.w; - for (i = 0; i < 3; i++) if (neg[i] = (mag[i] < 0.0)) mag[i] = -mag[i]; - if (mag[0] > mag[1]) { if (mag[0] > mag[2]) win = 0; else win = 2; } - else { if (mag[1] > mag[2]) win = 1; else win = 2; } - switch (win) { - case 0: if (neg[0]) p = q1000; else p = q0001; break; - case 1: if (neg[1]) p = qppmm; else p = qpppp; cycle(ka, 0) break; - case 2: if (neg[2]) p = qmpmm; else p = qpppm; cycle(ka, 1) break; - } - qp = Qt_Mul(q, p); - t = sqrt(mag[win] + 0.5); - p = Qt_Mul(p, Qt_(0.0, 0.0, -qp.z / t, qp.w / t)); - p = Qt_Mul(qtoz, Qt_Conj(p)); - } else { - float qa[4], pa[4]; - unsigned lo, hi, neg[4], par = 0; - double all, big, two; - qa[0] = q.x; qa[1] = q.y; qa[2] = q.z; qa[3] = q.w; - for (i = 0; i < 4; i++) { - pa[i] = 0.0; - if (neg[i] = (qa[i] < 0.0)) qa[i] = -qa[i]; - par ^= neg[i]; - } - /* Find two largest components, indices in hi and lo */ - if (qa[0] > qa[1]) lo = 0; else lo = 1; - if (qa[2] > qa[3]) hi = 2; else hi = 3; - if (qa[lo] > qa[hi]) { - if (qa[lo ^ 1] > qa[hi]) { hi = lo; lo ^= 1; } - else { hi ^= lo; lo ^= hi; hi ^= lo; } - } else {if (qa[hi^1]>qa[lo]) lo = hi^1;} - all = (qa[0] + qa[1] + qa[2] + qa[3]) * 0.5; - two = (qa[hi] + qa[lo]) * SQRTHALF; - big = qa[hi]; - if (all > two) { - if (all > big) {/*all*/ - {int i; for (i = 0; i < 4; i++) pa[i] = sgn(neg[i], 0.5); } - cycle(ka, par) - } else {/*big*/ pa[hi] = sgn(neg[hi],1.0);} - } else { - if (two > big) {/*two*/ - pa[hi] = sgn(neg[hi], SQRTHALF); pa[lo] = sgn(neg[lo], SQRTHALF); - if (lo > hi) { hi ^= lo; lo ^= hi; hi ^= lo; } - if (hi == W) { hi = "\001\002\000"[lo]; lo = 3 - hi - lo; } - swap(ka, hi, lo) - } else {/*big*/ pa[hi] = sgn(neg[hi],1.0);} - } - p.x = -pa[0]; p.y = -pa[1]; p.z = -pa[2]; p.w = pa[3]; - } - k->x = ka[X]; k->y = ka[Y]; k->z = ka[Z]; - return (p); - } - - - - - - - - - - - - /******* Decompose Affine Matrix *******/ - - /* Decompose 4x4 affine matrix A as TFRUK(U transpose), where t contains the - * translation components, q contains the rotation R, u contains U, k contains - * scale factors, and f contains the sign of the determinant. - * Assumes A transforms column vectors in right-handed coordinates. - * See Ken Shoemake and Tom Duff. Matrix Animation and Polar Decomposition. - * Proceedings of Graphics Interface 1992. - */ - void decomp_affine(HMatrix A, AffineParts* parts) - { - HMatrix Q, S, U; - Quat p; - float det; - parts->t = Qt_(A[X][W], A[Y][W], A[Z][W], 0); - det = polar_decomp(A, Q, S); - if (det < 0.0) { - mat_copy(Q, =, -Q, 3); - parts->f = -1; - } else parts->f = 1; - parts->q = Qt_FromMatrix(Q); - parts->k = spect_decomp(S, U); - parts->u = Qt_FromMatrix(U); - p = snuggle(parts->u, &parts->k); - parts->u = Qt_Mul(parts->u, p); - } - - /******* Invert Affine Decomposition *******/ - - /* Compute inverse of affine decomposition. - */ - void invert_affine(AffineParts* parts, AffineParts* inverse) - { - Quat t, p; - inverse->f = parts->f; - inverse->q = Qt_Conj(parts->q); - inverse->u = Qt_Mul(parts->q, parts->u); - inverse->k.x = (parts->k.x == 0.0) ? 0.0 : 1.0 / parts->k.x; - inverse->k.y = (parts->k.y == 0.0) ? 0.0 : 1.0 / parts->k.y; - inverse->k.z = (parts->k.z == 0.0) ? 0.0 : 1.0 / parts->k.z; - inverse->k.w = parts->k.w; - t = Qt_(-parts->t.x, -parts->t.y, -parts->t.z, 0); - t = Qt_Mul(Qt_Conj(inverse->u), Qt_Mul(t, inverse->u)); - t = Qt_(inverse->k.x * t.x, inverse->k.y * t.y, inverse->k.z * t.z, 0); - p = Qt_Mul(inverse->q, inverse->u); - t = Qt_Mul(p, Qt_Mul(t, Qt_Conj(p))); - inverse->t = (inverse->f > 0.0) ? t : Qt_(-t.x, -t.y, -t.z, 0); - } - -} diff --git a/Code/Tools/CryCommonTools/Decompose.h b/Code/Tools/CryCommonTools/Decompose.h deleted file mode 100644 index 88e04737b6..0000000000 --- a/Code/Tools/CryCommonTools/Decompose.h +++ /dev/null @@ -1,30 +0,0 @@ -// Modifications copyright Amazon.com, Inc. or its affiliates. - -namespace decomp { -// Taken from http://tog.acm.org/GraphicsGems/gemsiv/polar_decomp/Decompose.h - -/**** Decompose.h - Basic declarations ****/ -#ifndef CRYINCLUDE_CRYCOMMONTOOLS_DECOMPOSE_H -#define CRYINCLUDE_CRYCOMMONTOOLS_DECOMPOSE_H -#pragma once - -typedef struct {float x, y, z, w;} Quat; /* Quaternion */ -enum QuatPart {X, Y, Z, W}; -typedef Quat HVect; /* Homogeneous 3D vector */ -typedef float HMatrix[4][4]; /* Right-handed, for column vectors */ -typedef struct { - HVect t; /* Translation components */ - Quat q; /* Essential rotation */ - Quat u; /* Stretch rotation */ - HVect k; /* Stretch factors */ - float f; /* Sign of determinant */ -} AffineParts; -float polar_decomp(HMatrix M, HMatrix Q, HMatrix S); -HVect spect_decomp(HMatrix S, HMatrix U); -Quat snuggle(Quat q, HVect *k); -void decomp_affine(HMatrix A, AffineParts *parts); -void invert_affine(AffineParts *parts, AffineParts *inverse); - -#endif // CRYINCLUDE_CRYCOMMONTOOLS_DECOMPOSE_H - -} diff --git a/Code/Tools/CryCommonTools/Exceptions.h b/Code/Tools/CryCommonTools/Exceptions.h deleted file mode 100644 index cc8830f0dd..0000000000 --- a/Code/Tools/CryCommonTools/Exceptions.h +++ /dev/null @@ -1,43 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYCOMMONTOOLS_EXCEPTIONS_H -#define CRYINCLUDE_CRYCOMMONTOOLS_EXCEPTIONS_H -#pragma once - - -#include -#include - -class BaseException - : public std::exception -{ -public: - BaseException(const string& msg) - : msg(msg) {} - virtual const char* what() const throw () {return msg.c_str(); } - -private: - string msg; -}; - -template -class Exception - : public BaseException -{ -public: - Exception(const string& msg) - : BaseException(msg) {} -}; - -#endif // CRYINCLUDE_CRYCOMMONTOOLS_EXCEPTIONS_H diff --git a/Code/Tools/CryCommonTools/FileUtil.cpp b/Code/Tools/CryCommonTools/FileUtil.cpp deleted file mode 100644 index d42a60bcc2..0000000000 --- a/Code/Tools/CryCommonTools/FileUtil.cpp +++ /dev/null @@ -1,175 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include -#include "FileUtil.h" -#include "PathHelpers.h" -#include "StringHelpers.h" - -#include -#include - - -////////////////////////////////////////////////////////////////////////// -// returns true if 'dir' is a subdirectory of 'baseDir' or same directory as 'baseDir' -// note: returns false in case of wrong names passed -static bool IsSubdirOrSameDir(const char* dir, const char* baseDir) -{ - - AZ::IO::LocalFileIO localFileIO; - - char szFullPathDir[AZ_MAX_PATH_LEN]; - if(!localFileIO.ConvertToAbsolutePath(dir, szFullPathDir, sizeof(szFullPathDir))) - { - return false; - } - - char szFullPathBaseDir[2 * 1024]; - if(!localFileIO.ConvertToAbsolutePath(baseDir, szFullPathBaseDir, sizeof(szFullPathBaseDir))) - { - return false; - } - - const char* p = szFullPathDir; - const char* q = szFullPathBaseDir; - for (;; ++p, ++q) - { - if (tolower(*p) == tolower(*q)) - { - if (*p == 0) - { - // dir is exactly same as baseDir - return true; - } - continue; - } - - if ((*p == '/' || *p == '\\') && (*q == '/' || *q == '\\')) - { - continue; - } - - if (*p == 0) - { - // dir length is shorter than baseDir length. so it's not a subdir - return false; - } - - if (*q == 0) - { - // baseDir is shorter than dir. so may be it's a subdir. - const bool isSubdir = (*p == '/' || *p == '\\'); - return isSubdir; - } - - return false; - } -} - -////////////////////////////////////////////////////////////////////////// -// the paths must have trailing slash -static bool ScanDirectoryRecursive(const string& root, const string& path, const string& file, std::vector& files, bool recursive, const string& dirToIgnore) -{ - bool anyFound = false; - if (!dirToIgnore.empty()) - { - if (IsSubdirOrSameDir(root.c_str(), dirToIgnore.c_str())) - { - return anyFound; - } - } - - AZ::IO::LocalFileIO localFileIO; - localFileIO.FindFiles(root.c_str(), file.c_str(), [&](const char* filePath) -> bool - { - bool isDir = localFileIO.IsDirectory(filePath); - if (!isDir) - { - const string foundFilename(filePath); - if (StringHelpers::MatchesWildcardsIgnoreCase(foundFilename, file)) - { - anyFound = true; - files.push_back(PathHelpers::Join(path, PathHelpers::GetFilename(filePath))); - } - } - - return true; // Keep iterating - }); - - if (recursive) - { - localFileIO.FindFiles(root.c_str(), "*", [&](const char* filePath) -> bool - { - bool isDir = localFileIO.IsDirectory(filePath); - // If recursive. - if (isDir && strcmp(filePath, ".") && strcmp(filePath, "..")) - { - if (ScanDirectoryRecursive(filePath, PathHelpers::Join(path, PathHelpers::GetFilename(filePath)), file, files, recursive, dirToIgnore)) - { - anyFound = true; - } - } - return true; // Keep iterating - }); - } - - return anyFound; -} - -////////////////////////////////////////////////////////////////////////// - -bool FileUtil::ScanDirectory(const string& path, const string& file, std::vector& files, bool recursive, const string& dirToIgnore) -{ - return ScanDirectoryRecursive(path, "", file, files, recursive, dirToIgnore); -} - - -bool FileUtil::EnsureDirectoryExists(const char* szPathIn) -{ - if (!szPathIn || !szPathIn[0]) - { - return true; - } - - if (DirectoryExists(szPathIn)) - { - return true; - } - - std::vector path(szPathIn, szPathIn + strlen(szPathIn) + 1); - char* p = &path[0]; - - // Skip '/' and '//' in the beginning - while (*p == '/' || *p == '\\') - { - ++p; - } - - for (;; ) - { - while (*p != '/' && *p != '\\' && *p) - { - ++p; - } - const char saved = *p; - *p = 0; - AZ::IO::LocalFileIO().CreatePath(&path[0]); - *p++ = saved; - if (saved == 0) - { - break; - } - } - - return DirectoryExists(szPathIn); -} diff --git a/Code/Tools/CryCommonTools/FileUtil.h b/Code/Tools/CryCommonTools/FileUtil.h deleted file mode 100644 index cf258c074b..0000000000 --- a/Code/Tools/CryCommonTools/FileUtil.h +++ /dev/null @@ -1,311 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYCOMMONTOOLS_FILEUTIL_H -#define CRYINCLUDE_CRYCOMMONTOOLS_FILEUTIL_H -#pragma once - -#include -#include - -#include - -#if AZ_TRAIT_OS_PLATFORM_APPLE || defined(AZ_PLATFORM_LINUX) -#include -#endif -#if defined(AZ_PLATFORM_LINUX) -#include "Linux64Specific.h" -#endif // defined(AZ_PLATFORM_LINUX) - -#include -#include - -namespace FileUtil -{ - // Magic number explanation: - // Both epochs are Gregorian. 1970 - 1601 = 369. Assuming a leap - // year every four years, 369 / 4 = 92. However, 1700, 1800, and 1900 - // were NOT leap years, so 89 leap years, 280 non-leap years. - // 89 * 366 + 280 * 365 = 134744 days between epochs. Of course - // 60 * 60 * 24 = 86400 seconds per day, so 134744 * 86400 = - // 11644473600 = SECS_BETWEEN_EPOCHS. - // - // This result is also confirmed in the MSDN documentation on how - // to convert a time_t value to a win32 FILETIME. - #define SECS_BETWEEN_EPOCHS 11644473600ll - /* 10^7 */ - #define SECS_TO_100NS 10000000ll - - // Find all files matching filespec. - bool ScanDirectory(const string& path, const string& filespec, std::vector& files, bool recursive, const string& dirToIgnore); - - // Ensures that directory specified by szPathIn exists by creating all needed (sub-)directories. - // Returns false in case of a failure. - // Example: "c:\temp\test" ("c:\temp\test\" also works) - ensures that "c:\temp\test" exists. - bool EnsureDirectoryExists(const char* szPathIn); - - // converts the FILETIME to the C Timestamp (compatible with dbghelp.dll) - inline DWORD FiletimeToUnixTime(const FILETIME& ft) - { - return (DWORD)((((int64&)ft) / SECS_TO_100NS) - SECS_BETWEEN_EPOCHS); - } - - // converts the FILETIME to 64bit C timestamp - inline AZ::u64 FiletimeTo64BitUnixTime(const FILETIME& fileTime) - { - const AZ::u64 time = static_cast(fileTime.dwHighDateTime) << 32 | fileTime.dwLowDateTime; - return ((time / SECS_TO_100NS) - SECS_BETWEEN_EPOCHS); - } - - // converts the C Timestamp (compatible with dbghelp.dll) to FILETIME - inline FILETIME UnixTimeToFiletime(DWORD nCTime) - { - const int64 time = (nCTime + SECS_BETWEEN_EPOCHS) * SECS_TO_100NS; - return (FILETIME&)time; - } - - //converts the 64 bit C Timestamp to FILETIME - inline void UnixTime64BitToFiletime(AZ::u64 nCTime, FILETIME& fileTime) - { - const AZ::u64 time = (nCTime + SECS_BETWEEN_EPOCHS) * SECS_TO_100NS; - fileTime.dwLowDateTime = static_cast(time); - fileTime.dwHighDateTime = static_cast(time >> 32); - } - - inline FILETIME GetInvalidFileTime() - { - FILETIME fileTime; - fileTime.dwLowDateTime = 0; - fileTime.dwHighDateTime = 0; - return fileTime; - } - - // returns file time stamps -#if defined(AZ_PLATFORM_WINDOWS) - inline bool GetFileTimes(const char* filename, FILETIME* ftimeCreate = nullptr, FILETIME* ftimeAccess = nullptr, FILETIME* ftimeModify = nullptr) - { - WIN32_FIND_DATAA FindFileData; - const HANDLE hFind = FindFirstFileA(filename, &FindFileData); - if (hFind == INVALID_HANDLE_VALUE) - { - return false; - } - - if (ftimeModify == nullptr && ftimeCreate == nullptr && ftimeAccess == nullptr) - { - FindClose(hFind); - return true; - } - - FindClose(hFind); - if (ftimeCreate) - { - ftimeCreate->dwLowDateTime = FindFileData.ftCreationTime.dwLowDateTime; - ftimeCreate->dwHighDateTime = FindFileData.ftCreationTime.dwHighDateTime; - } - if (ftimeModify) - { - ftimeModify->dwLowDateTime = FindFileData.ftLastWriteTime.dwLowDateTime; - ftimeModify->dwHighDateTime = FindFileData.ftLastWriteTime.dwHighDateTime; - } - if (ftimeAccess) - { - ftimeAccess->dwLowDateTime = FindFileData.ftLastAccessTime.dwLowDateTime; - ftimeAccess->dwHighDateTime = FindFileData.ftCreationTime.dwHighDateTime; - } - return true; - } -#else - inline bool GetFileTimes(const char* filename, AZ::u64* timeCreate = nullptr, AZ::u64* timeAccess = nullptr, AZ::u64* timeModify = nullptr) - { - - struct stat statResult; - if (stat(filename, &statResult) != 0) - { - return false; - } - - if (timeCreate) - { - *timeCreate =static_cast(statResult.st_ctime); - } - if (timeModify) - { - *timeModify =static_cast(statResult.st_mtime); - } - if (timeAccess) - { - *timeAccess =static_cast(statResult.st_atime); - } - return true; - } -#endif - - - - inline FILETIME GetLastWriteFileTime(const char* filename) - { - FILETIME timeModify = GetInvalidFileTime(); -#if defined(AZ_PLATFORM_WINDOWS) - GetFileTimes(filename, nullptr, nullptr, &timeModify); -#else - AZ::u64 modTime = 0; - GetFileTimes(filename, nullptr, nullptr, &modTime); - if(modTime != 0) - { - UnixTime64BitToFiletime(modTime, timeModify); - } -#endif - return timeModify; - } - - inline bool FileTimesAreEqual(const FILETIME& fileTime0, const FILETIME& fileTime1) - { - return - (fileTime0.dwLowDateTime == fileTime1.dwLowDateTime) && - (fileTime0.dwHighDateTime == fileTime1.dwHighDateTime); - } - - inline bool FileTimesAreEqual(const char* const srcfilename, const char* const targetfilename) - { - FILETIME ftSource = FileUtil::GetLastWriteFileTime(srcfilename); - FILETIME ftTarget = FileUtil::GetLastWriteFileTime(targetfilename); - return FileTimesAreEqual(ftSource, ftTarget); - } - - inline bool FileTimeIsValid(const FILETIME& fileTime) - { - return !FileTimesAreEqual(GetInvalidFileTime(), fileTime); - } - - inline bool SetFileTimes(const char* const filename, const FILETIME& creationFileTime, const FILETIME& accessFileTime, const FILETIME& modifcationFileTime) - { -#if defined(AZ_PLATFORM_WINDOWS) - const HANDLE hf = CreateFileA(filename, FILE_WRITE_ATTRIBUTES, FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0); - if (hf != INVALID_HANDLE_VALUE) - { - if (SetFileTime(hf, &creationFileTime, &accessFileTime, &modifcationFileTime)) - { - if (CloseHandle(hf)) - { - return true; - } - } - - CloseHandle(hf); - } -#else - AZ::u64 creationTime = FiletimeTo64BitUnixTime(creationFileTime); - AZ::u64 modificationTime = FiletimeTo64BitUnixTime(modifcationFileTime); - - struct utimbuf puttime; - puttime.modtime = modificationTime; - puttime.actime = creationTime; - - if (utime(filename, &puttime) == 0) - { - return true; - } - -#endif - return false; - } - - inline bool SetFileTimes(const char* const filename, const FILETIME& fileTime) - { -#if defined(AZ_PLATFORM_WINDOWS) - const HANDLE hf = CreateFileA(filename, FILE_WRITE_ATTRIBUTES, FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0); - if (hf != INVALID_HANDLE_VALUE) - { - if (SetFileTime(hf, &fileTime, &fileTime, &fileTime)) - { - if (CloseHandle(hf)) - { - return true; - } - } - - CloseHandle(hf); - } -#else - - AZ::u64 newTime = FiletimeTo64BitUnixTime(fileTime); - - struct utimbuf puttime; - puttime.modtime = newTime; - puttime.actime = newTime; - - if (utime(filename, &puttime) == 0) - { - return true; - } -#endif - return false; - } - - inline bool SetFileTimes(const char* const srcfilename, const char* const targetfilename) - { -#if defined(AZ_PLATFORM_WINDOWS) - FILETIME creationFileTime, accessFileTime, modifcationFileTime; - if (GetFileTimes(srcfilename, &creationFileTime, &accessFileTime, &modifcationFileTime)) - { - const HANDLE hf = CreateFileA(targetfilename, FILE_WRITE_ATTRIBUTES, FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0); - if (hf != INVALID_HANDLE_VALUE) - { - if (SetFileTime(hf, &creationFileTime, &accessFileTime, &modifcationFileTime)) - { - if (CloseHandle(hf)) - { - return true; - } - } - - CloseHandle(hf); - } - } -#else - AZ::u64 creationFileTime, accessFileTime, modifcationFileTime; - if (GetFileTimes(srcfilename, &creationFileTime, &accessFileTime, &modifcationFileTime)) - { - struct utimbuf puttime; - puttime.modtime = modifcationFileTime; - puttime.actime = accessFileTime; - - if (utime(targetfilename, &puttime) == 0) - { - return true; - } - } -#endif - return false; - } - - inline uint64 GetFileSize(const char* const filename) - { - AZ::u64 fileSize = AZ::IO::SystemFile::Length(filename); - return fileSize >= 0? fileSize : -1; - - } - - inline bool FileExists(const char* szPath) - { - return AZ::IO::LocalFileIO().Exists(szPath); - } - - inline bool DirectoryExists(const char* szPath) - { - return AZ::IO::LocalFileIO().IsDirectory(szPath); - } -}; - -#endif // CRYINCLUDE_CRYCOMMONTOOLS_FILEUTIL_H diff --git a/Code/Tools/CryCommonTools/FileXmlBufferSource.h b/Code/Tools/CryCommonTools/FileXmlBufferSource.h deleted file mode 100644 index de802a3311..0000000000 --- a/Code/Tools/CryCommonTools/FileXmlBufferSource.h +++ /dev/null @@ -1,48 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYCOMMONTOOLS_FILEXMLBUFFERSOURCE_H -#define CRYINCLUDE_CRYCOMMONTOOLS_FILEXMLBUFFERSOURCE_H -#pragma once - - -class FileXmlBufferSource - : public IXmlBufferSource -{ -public: - FileXmlBufferSource(const char* path) - { - file = std::fopen(path, "r"); - } - ~FileXmlBufferSource() - { - if (file) - { - std::fclose(file); - } - } - - virtual int Read(void* buffer, int size) const - { - if (!file) - { - return 0; - } - return std::fread(buffer, 1, size, file); - } - -private: - mutable std::FILE* file; -}; - -#endif // CRYINCLUDE_CRYCOMMONTOOLS_FILEXMLBUFFERSOURCE_H diff --git a/Code/Tools/CryCommonTools/ILogger.h b/Code/Tools/CryCommonTools/ILogger.h deleted file mode 100644 index cbcbae3094..0000000000 --- a/Code/Tools/CryCommonTools/ILogger.h +++ /dev/null @@ -1,53 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYCOMMONTOOLS_ILOGGER_H -#define CRYINCLUDE_CRYCOMMONTOOLS_ILOGGER_H -#pragma once - - -#include -#include - -class ILogger -{ -public: - enum ESeverity - { - eSeverity_Debug, - eSeverity_Info, - eSeverity_Warning, - eSeverity_Error - }; - - virtual ~ILogger() - { - } - - void Log(ESeverity eSeverity, const char* const format, ...) - { - char buffer[2048]; - { - va_list args; - va_start(args, format); - _vsnprintf_s(buffer, sizeof(buffer), sizeof(buffer) - 1, format, args); - va_end(args); - } - LogImpl(eSeverity, buffer); - } - -protected: - virtual void LogImpl(ESeverity eSeverity, const char* text) = 0; -}; - -#endif // CRYINCLUDE_CRYCOMMONTOOLS_ILOGGER_H diff --git a/Code/Tools/CryCommonTools/IPakSystem.h b/Code/Tools/CryCommonTools/IPakSystem.h deleted file mode 100644 index d8646c3a2c..0000000000 --- a/Code/Tools/CryCommonTools/IPakSystem.h +++ /dev/null @@ -1,49 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYCOMMONTOOLS_IPAKSYSTEM_H -#define CRYINCLUDE_CRYCOMMONTOOLS_IPAKSYSTEM_H -#pragma once - -#include - -struct PakSystemFile; -struct PakSystemArchive; -struct IPakSystem -{ - virtual PakSystemFile* Open(const char* filename, const char* mode) = 0; - virtual bool ExtractNoOverwrite(const char* filename, const char* extractToFile = 0) = 0; - virtual void Close(PakSystemFile* file) = 0; - virtual int GetLength(PakSystemFile* file) const = 0; - virtual int Read(PakSystemFile* file, void* buffer, int size) = 0; - virtual bool EoF(PakSystemFile* file) = 0; - - virtual PakSystemArchive* OpenArchive(const char* path, size_t fileAlignment = 1, bool encrypted = false, const uint32 encryptionKey[4] = 0) = 0; - virtual void CloseArchive(PakSystemArchive* archive) = 0; - - // Summary: - // Adds a new file to the pak or update an existing one. - // Adds a directory (creates several nested directories if needed) - // Arguments: - // path - relative path inside archive - // data, size - file content - // modTime - modification timestamp of the file - // compressionLevel - level of compression (correnponds to zlib-levels): - // -1 or [0-9] where -1=default compression, 0=no compression, 9=best compression - virtual void AddToArchive(PakSystemArchive* archive, const char* path, void* data, int size, int64 modTime, int compressionLevel = -1) = 0; - - virtual bool DeleteFromArchive(PakSystemArchive* archive, const char* path) = 0; - virtual bool CheckIfFileExist(PakSystemArchive* archive, const char* path, int64 modTime) = 0; -}; - -#endif // CRYINCLUDE_CRYCOMMONTOOLS_IPAKSYSTEM_H diff --git a/Code/Tools/CryCommonTools/ISettings.h b/Code/Tools/CryCommonTools/ISettings.h deleted file mode 100644 index bba3100215..0000000000 --- a/Code/Tools/CryCommonTools/ISettings.h +++ /dev/null @@ -1,57 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYCOMMONTOOLS_ISETTINGS_H -#define CRYINCLUDE_CRYCOMMONTOOLS_ISETTINGS_H -#pragma once - - -class ISettings -{ -public: - virtual bool GetSettingString(char* buffer, int bufferSizeInBytes, const char* key) = 0; - virtual bool GetSettingInt(int& value, const char* key) = 0; -}; - -inline bool GetSettingByRef(ISettings* settings, const string& key, string& value) -{ - char buffer[1024]; - bool success = false; - if (settings) - { - success = settings->GetSettingString(buffer, sizeof(buffer), key.c_str()); - } - if (success) - { - value = buffer; - } - return success; -} - -inline bool GetSettingByRef(ISettings* settings, const string& key, int& value) -{ - return settings->GetSettingInt(value, key.c_str()); -} - -template -inline T GetSetting(ISettings* settings, const string& key, const T& dflt) -{ - T value; - if (!GetSettingByRef(settings, key, value)) - { - value = dflt; - } - return value; -} - -#endif // CRYINCLUDE_CRYCOMMONTOOLS_ISETTINGS_H diff --git a/Code/Tools/CryCommonTools/LocaleChanger.cpp b/Code/Tools/CryCommonTools/LocaleChanger.cpp deleted file mode 100644 index 3a9edee30a..0000000000 --- a/Code/Tools/CryCommonTools/LocaleChanger.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include -#include "LocaleChanger.h" -#include - -LocaleChanger::LocaleChanger(int category, const char* newLocale) -{ - m_category = category; - m_oldLocale = setlocale(category, newLocale); -} - -LocaleChanger::~LocaleChanger() -{ - setlocale(m_category, m_oldLocale.c_str()); -} diff --git a/Code/Tools/CryCommonTools/LocaleChanger.h b/Code/Tools/CryCommonTools/LocaleChanger.h deleted file mode 100644 index 3b85c462a2..0000000000 --- a/Code/Tools/CryCommonTools/LocaleChanger.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYCOMMONTOOLS_LOCALECHANGER_H -#define CRYINCLUDE_CRYCOMMONTOOLS_LOCALECHANGER_H -#pragma once - - -class LocaleChanger -{ -public: - LocaleChanger(int category, const char* newLocale); - ~LocaleChanger(); - -private: - int m_category; - string m_oldLocale; -}; - -#endif // CRYINCLUDE_CRYCOMMONTOOLS_LOCALECHANGER_H diff --git a/Code/Tools/CryCommonTools/LogFile.cpp b/Code/Tools/CryCommonTools/LogFile.cpp deleted file mode 100644 index ef98be776b..0000000000 --- a/Code/Tools/CryCommonTools/LogFile.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include -#include "LogFile.h" - -LogFile::LogFile(const char* const filename) - : m_file(0) - , m_hasWarnings(false) - , m_hasErrors(false) -{ - m_file = std::fopen(filename, "w"); -} - -LogFile::~LogFile() -{ - if (m_file) - { - fclose(m_file); - } -} - -bool LogFile::IsOpen() const -{ - return m_file != 0; -} - -bool LogFile::HasWarningsOrErrors() const -{ - return m_hasWarnings || m_hasErrors; -} - -void LogFile::LogImpl(ESeverity eSeverity, const char* const text) -{ - const char* severityMessage = 0; - switch (eSeverity) - { - case eSeverity_Debug: - severityMessage = " "; - break; - case eSeverity_Info: - severityMessage = " "; - break; - case eSeverity_Warning: - severityMessage = "W: "; - break; - case eSeverity_Error: - severityMessage = "E: "; - break; - default: - severityMessage = "?: "; - break; - } - - if (eSeverity == eSeverity_Warning) - { - m_hasWarnings = true; - } - if (eSeverity == eSeverity_Error) - { - m_hasErrors = true; - } - - if (m_file) - { - fprintf(m_file, "%s%s\n", severityMessage, text); - fflush(m_file); - } -} diff --git a/Code/Tools/CryCommonTools/LogFile.h b/Code/Tools/CryCommonTools/LogFile.h deleted file mode 100644 index d26c457165..0000000000 --- a/Code/Tools/CryCommonTools/LogFile.h +++ /dev/null @@ -1,40 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYCOMMONTOOLS_LOGFILE_H -#define CRYINCLUDE_CRYCOMMONTOOLS_LOGFILE_H -#pragma once - - -#include "ILogger.h" - -class LogFile - : public ILogger -{ -public: - LogFile(const char* filename); - ~LogFile(); - - bool IsOpen() const; - bool HasWarningsOrErrors() const; - - // ILogger - virtual void LogImpl(ESeverity eSeverity, const char* message); - -private: - std::FILE* m_file; - bool m_hasWarnings; - bool m_hasErrors; -}; - -#endif // CRYINCLUDE_CRYCOMMONTOOLS_LOGFILE_H diff --git a/Code/Tools/CryCommonTools/MathHelpers.h b/Code/Tools/CryCommonTools/MathHelpers.h deleted file mode 100644 index d21c14aa6c..0000000000 --- a/Code/Tools/CryCommonTools/MathHelpers.h +++ /dev/null @@ -1,72 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYCOMMONTOOLS_MATHHELPERS_H -#define CRYINCLUDE_CRYCOMMONTOOLS_MATHHELPERS_H -#pragma once - - -#include -#if (_M_IX86_FP > 0) -#include -#endif - -namespace MathHelpers -{ -#if (_M_IX86_FP > 0) - inline int FastRoundFloatTowardZero(float f) - { - return _mm_cvtt_ss2si(_mm_set_ss(f)); - } -#else - inline int FastRoundFloatTowardZero(float f) - { - return int(f); - } -#endif - -#if defined(AZ_PLATFORM_WINDOWS) - - inline unsigned int EnableFloatingPointExceptions(unsigned int mask) - { - _clearfp(); - unsigned int oldMask; - _controlfp_s(&oldMask, 0, 0); - unsigned int newMask; - _controlfp_s(&newMask, ~mask, _MCW_EM); - return ~oldMask; - } - - class AutoFloatingPointExceptions - { - public: - AutoFloatingPointExceptions(const unsigned int mask) - : m_mask(EnableFloatingPointExceptions(mask)) - { - } - - ~AutoFloatingPointExceptions() - { - EnableFloatingPointExceptions(m_mask); - } - - private: - unsigned int m_mask; - }; - -#endif //AZ_PLATFORM_WINDOWS -} - -#endif // CRYINCLUDE_CRYCOMMONTOOLS_MATHHELPERS_H - - diff --git a/Code/Tools/CryCommonTools/ModuleHelpers.cpp b/Code/Tools/CryCommonTools/ModuleHelpers.cpp deleted file mode 100644 index 2ce5c2639a..0000000000 --- a/Code/Tools/CryCommonTools/ModuleHelpers.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include -#include "ModuleHelpers.h" - -HMODULE ModuleHelpers::GetCurrentModule(CurrentModuleSpecifier moduleSpecifier) -{ - switch (moduleSpecifier) - { - case CurrentModuleSpecifier_Executable: - return GetModuleHandle(0); - - case CurrentModuleSpecifier_Library: - MEMORY_BASIC_INFORMATION mbi; - static int dummy; - VirtualQuery(&dummy, &mbi, sizeof(mbi)); - HMODULE instance = reinterpret_cast(mbi.AllocationBase); - return instance; - } - - return 0; -} - -std::basic_string ModuleHelpers::GetCurrentModulePath(CurrentModuleSpecifier moduleSpecifier) -{ - // Here's a trick that will get you the handle of the module - // you're running in without any a-priori knowledge: - // http://www.dotnet247.com/247reference/msgs/13/65259.aspx - HMODULE instance = GetCurrentModule(moduleSpecifier); - TCHAR moduleNameBuffer[MAX_PATH]; - GetModuleFileName(instance, moduleNameBuffer, sizeof(moduleNameBuffer) / sizeof(moduleNameBuffer[0])); - return moduleNameBuffer; -} diff --git a/Code/Tools/CryCommonTools/ModuleHelpers.h b/Code/Tools/CryCommonTools/ModuleHelpers.h deleted file mode 100644 index cb9049e89b..0000000000 --- a/Code/Tools/CryCommonTools/ModuleHelpers.h +++ /dev/null @@ -1,31 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYCOMMONTOOLS_MODULEHELPERS_H -#define CRYINCLUDE_CRYCOMMONTOOLS_MODULEHELPERS_H -#pragma once - - -namespace ModuleHelpers -{ - enum CurrentModuleSpecifier - { - CurrentModuleSpecifier_Executable, - CurrentModuleSpecifier_Library - }; - - HMODULE GetCurrentModule(CurrentModuleSpecifier moduleSpecifier); - std::basic_string GetCurrentModulePath(CurrentModuleSpecifier moduleSpecifier); -} - -#endif // CRYINCLUDE_CRYCOMMONTOOLS_MODULEHELPERS_H diff --git a/Code/Tools/CryCommonTools/PakSystem.cpp b/Code/Tools/CryCommonTools/PakSystem.cpp deleted file mode 100644 index 42a129c5e6..0000000000 --- a/Code/Tools/CryCommonTools/PakSystem.cpp +++ /dev/null @@ -1,380 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include -#include "PakSystem.h" -#include "PathHelpers.h" -#include "StringHelpers.h" -#include "ZipDir/ZipDir.h" - -#include -#include -#include - - - -PakSystemFile::PakSystemFile() -{ - type = PakSystemFileType_Unknown; - file = NULL; - zip = NULL; - fileEntry = NULL; - data = NULL; - dataPosition = 0; -} - -PakSystem::PakSystem() -{ -} - -PakSystemFile* PakSystem::Open(const char* a_path, const char* a_mode) -{ - string normalPath = a_path; - - string const zipExt = ".zip"; - bool bZip = StringHelpers::EndsWithIgnoreCase(normalPath, zipExt); - - if (bZip) - { - // If it's a .zip file, then we'll try to look for a file without .zip extension inside of the .zip file - normalPath.erase(normalPath.length() - zipExt.length(), zipExt.length()); - } - - string zipPath = normalPath + zipExt; - string filename = PathHelpers::GetFilename(normalPath); - - if (!normalPath.empty() && normalPath[0] == '@') - { - // File is inside pak file. - int splitter = normalPath.find_first_of("|;,"); - if (splitter >= 0) - { - zipPath = normalPath.substr(1, splitter - 1); - filename = StringHelpers::MakeLowerCase(normalPath.substr(splitter + 1)); - bZip = true; - } - else - { - return 0; - } - } - - if (!bZip) - { - // Try to open the file. - FILE* f = nullptr; - azfopen(&f, normalPath.c_str(), a_mode); - if (f) - { - std::unique_ptr file(new PakSystemFile()); - file->type = PakSystemFileType_File; - file->file = f; - - return file.release(); - } - } - - // if it's simple and read-only, it's assumed it's read-only - unsigned const nFactoryFlags = ZipDir::CacheFactory::FLAGS_DONT_COMPACT | ZipDir::CacheFactory::FLAGS_READ_ONLY; - - bool bFileExists = false; - const uint32* decryptionKey = 0; // use default one - - if (bZip) - { - // a caller asked to open a .zip file. check if the .zip file on disk exist - FILE* f = nullptr; - azfopen(&f, zipPath.c_str(), "rb"); - if (f) - { - fclose(f); - bFileExists = true; - } - } - else - { - // a caller specified normal file. we already failed to find it on disk, - // so the file could be within a .pak file. let's find all 'potential' - // pak files and look within these for a matching file - - std::vector foundFileCountainer; // pak files found - - for (string dirToSearch = normalPath;; ) - { - dirToSearch = PathHelpers::GetDirectory(dirToSearch); - - AZ::IO::LocalFileIO localFileIO; - localFileIO.FindFiles(dirToSearch.c_str(), "*.pak", [&](const char* filePath) -> bool - { - const string foundFilename(filePath); - if (StringHelpers::EqualsIgnoreCase(PathHelpers::FindExtension(foundFilename), "pak")) - { - foundFileCountainer.push_back(foundFilename); - } - return true; // continue iterating - }); - - if (PathHelpers::GetFilename(dirToSearch).empty()) - { - // We've reached the top of the path - break; - } - } - - // iterate through found containers and look for relevant files within them - for (int iFile = 0; iFile < foundFileCountainer.size(); ++iFile) - { - zipPath = foundFileCountainer[ iFile ]; - string pathToZip = PathHelpers::GetDirectory(zipPath); - - // construct filename by removing path to zip from path to filename - string pathToFile = PathHelpers::GetDirectory(string(normalPath)); - string pureFileName = PathHelpers::GetFilename(string(normalPath)); - if (pathToFile.length() != pathToZip.length() && pathToZip.length() > 0) - { - pathToFile = pathToFile.substr(pathToZip.length() + 1); - } - filename = pathToFile.empty() - ? pureFileName - : pathToFile + "\\" + pureFileName; - - ZipDir::CacheFactory factory(ZipDir::ZD_INIT_FAST, nFactoryFlags); - ZipDir::CachePtr testZip = factory.New(zipPath.c_str(), decryptionKey); - ZipDir::FileEntry* testFileEntry = (testZip ? testZip->FindFile(filename.c_str()) : 0); - - // break out if we have a testFileEntry, as we've found our first (and best) candidate. - if (testFileEntry) - { - bFileExists = true; - break; - } - } - } - - { - ZipDir::CacheFactory factory(ZipDir::ZD_INIT_FAST, nFactoryFlags); - ZipDir::CachePtr zip = (bFileExists ? factory.New(zipPath.c_str(), decryptionKey) : 0); - ZipDir::FileEntry* fileEntry = (zip ? zip->FindFile(filename.c_str()) : 0); - - if (fileEntry) - { - std::unique_ptr file(new PakSystemFile()); - file->type = PakSystemFileType_PakFile; - file->zip = zip; - file->fileEntry = fileEntry; - file->data = zip->AllocAndReadFile(file->fileEntry); - file->dataPosition = 0; - return file.release(); - } - } - - return 0; -} - - -//Extracts archived file to disk without overwriting any files -//returns true on success, false on failure (due to potential overwrite or no file -//in archive -bool PakSystem::ExtractNoOverwrite(const char* fileToExtract, const char* extractToFile) -{ - if (0 == extractToFile) - { - extractToFile = fileToExtract; - } - - //open file using pak system - PakSystemFile* fileZip = Open(fileToExtract, "r"); - if (!fileZip) - { - return false; - } - - // Try to open a writable file - FILE* fFileOnDisk = nullptr; - azfopen(&fFileOnDisk, extractToFile, "wb"); - if (!fFileOnDisk) - { - Close(fileZip); - return false; - } - - fwrite(fileZip->data, fileZip->fileEntry->desc.lSizeUncompressed, 1, fFileOnDisk); - fclose(fFileOnDisk); - - Close(fileZip); - - return true; -} - - -void PakSystem::Close(PakSystemFile* file) -{ - if (file) - { - switch (file->type) - { - case PakSystemFileType_File: - fclose(file->file); - break; - - case PakSystemFileType_PakFile: - file->zip->Free(file->data); - break; - } - delete file; - } -} - - -int PakSystem::GetLength(PakSystemFile* file) const -{ - if (file) - { - switch (file->type) - { - case PakSystemFileType_File: - { - if (file->file) - { - long pos = ftell(file->file); - fseek(file->file, 0, SEEK_END); - int result = ftell(file->file); - fseek(file->file, pos, SEEK_SET); - return result; - } - break; - } - case PakSystemFileType_PakFile: - { - if (file->fileEntry) - { - return file->fileEntry->desc.lSizeUncompressed; - } - break; - } - default: - { - break; - } - } - } - return 0; -} - - -int PakSystem::Read(PakSystemFile* file, void* buffer, int size) -{ - int readBytes = 0; - - if (file) - { - switch (file->type) - { - case PakSystemFileType_File: - { - readBytes = fread(buffer, 1, size, file->file); - } - break; - - case PakSystemFileType_PakFile: - { - int fileSize = file->fileEntry->desc.lSizeUncompressed; - readBytes = (fileSize - file->dataPosition > size ? size : fileSize - file->dataPosition); - memcpy(buffer, static_cast(file->data) + file->dataPosition, readBytes); - file->dataPosition += readBytes; - } - break; - } - } - - return readBytes; -} - -bool PakSystem::EoF(PakSystemFile* file) -{ - bool EoF = true; - if (file) - { - switch (file->type) - { - case PakSystemFileType_File: - { - EoF = (0 != feof(file->file)); - } - break; - - case PakSystemFileType_PakFile: - { - int fileSize = file->fileEntry->desc.lSizeUncompressed; - EoF = (file->dataPosition >= fileSize); - } - break; - } - } - - return EoF; -} - -PakSystemArchive* PakSystem::OpenArchive(const char* path, size_t fileAlignment, bool encrypted, const uint32 encryptionKey[4]) -{ - //unsigned nFactoryFlags = ZipDir::CacheFactory::FLAGS_DONT_COMPACT | ZipDir::CacheFactory::FLAGS_CREATE_NEW; - unsigned nFactoryFlags = 0; - ZipDir::CacheFactory factory(ZipDir::ZD_INIT_FAST, nFactoryFlags); - ZipDir::CacheRWPtr cache = factory.NewRW(path, fileAlignment, encrypted, encryptionKey); - PakSystemArchive* archive = (cache ? new PakSystemArchive() : 0); - if (archive) - { - archive->zip = cache; - } - return archive; -} - -void PakSystem::CloseArchive(PakSystemArchive* archive) -{ - if (archive) - { - archive->zip->Close(); - delete archive; - } -} - -void PakSystem::AddToArchive(PakSystemArchive* archive, const char* path, void* data, int size, int64 modTime, int compressionLevel) -{ - int compressionMethod = ZipFile::METHOD_DEFLATE; - if (compressionLevel == 0) - { - compressionMethod = ZipFile::METHOD_STORE; - } - archive->zip->UpdateFile(path, data, size, compressionMethod, compressionLevel, modTime); -} - -////////////////////////////////////////////////////////////////////////// -bool PakSystem::CheckIfFileExist(PakSystemArchive* archive, const char* path, int64 modTime) -{ - assert(archive); - - ZipDir::FileEntry* pFileEntry = archive->zip->FindFile(path); - if (pFileEntry) - { - return pFileEntry->CompareFileTimeNTFS(modTime); - } - - return false; -} - -////////////////////////////////////////////////////////////////////////// -bool PakSystem::DeleteFromArchive(PakSystemArchive* archive, const char* path) -{ - ZipDir::ErrorEnum err = archive->zip->RemoveFile(path); - return ZipDir::ZD_ERROR_SUCCESS == err; -} diff --git a/Code/Tools/CryCommonTools/PakSystem.h b/Code/Tools/CryCommonTools/PakSystem.h deleted file mode 100644 index ba57f26d4d..0000000000 --- a/Code/Tools/CryCommonTools/PakSystem.h +++ /dev/null @@ -1,69 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYCOMMONTOOLS_PAKSYSTEM_H -#define CRYINCLUDE_CRYCOMMONTOOLS_PAKSYSTEM_H -#pragma once - - -#include "IPakSystem.h" -#include "ZipDir/ZipDir.h" // TODO: get rid of thid include - -enum PakSystemFileType -{ - PakSystemFileType_Unknown, - PakSystemFileType_File, - PakSystemFileType_PakFile -}; -struct PakSystemFile -{ - PakSystemFile(); - PakSystemFileType type; - - // PakSystemFileType_File - FILE* file; - - // PakSystemFileType_PakFile - ZipDir::CachePtr zip; - ZipDir::FileEntry* fileEntry; - void* data; - int dataPosition; -}; - -struct PakSystemArchive -{ - ZipDir::CacheRWPtr zip; -}; - -class PakSystem - : public IPakSystem -{ -public: - PakSystem(); - - // IPakSystem - virtual PakSystemFile* Open(const char* filename, const char* mode); - virtual bool ExtractNoOverwrite(const char* filename, const char* extractToFile = 0); - virtual void Close(PakSystemFile* file); - virtual int GetLength(PakSystemFile* file) const; - virtual int Read(PakSystemFile* file, void* buffer, int size); - virtual bool EoF(PakSystemFile* file); - - virtual PakSystemArchive* OpenArchive(const char* path, size_t fileAlignment, bool encrypted, const uint32 encryptionKey[4]); - virtual void CloseArchive(PakSystemArchive* archive); - virtual void AddToArchive(PakSystemArchive* archive, const char* path, void* data, int size, int64 modTime, int compressionLevel); - virtual bool DeleteFromArchive(PakSystemArchive* archive, const char* path); - virtual bool CheckIfFileExist(PakSystemArchive* archive, const char* path, int64 modTime); -}; - -#endif // CRYINCLUDE_CRYCOMMONTOOLS_PAKSYSTEM_H diff --git a/Code/Tools/CryCommonTools/PakXmlFileBufferSource.h b/Code/Tools/CryCommonTools/PakXmlFileBufferSource.h deleted file mode 100644 index cd9aa9d211..0000000000 --- a/Code/Tools/CryCommonTools/PakXmlFileBufferSource.h +++ /dev/null @@ -1,74 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYCOMMONTOOLS_PAKXMLFILEBUFFERSOURCE_H -#define CRYINCLUDE_CRYCOMMONTOOLS_PAKXMLFILEBUFFERSOURCE_H -#pragma once - - -#include "../CryXML/IXMLSerializer.h" -#include "IPakSystem.h" - -class PakXmlFileBufferSource - : public IXmlBufferSource -{ -public: - PakXmlFileBufferSource(IPakSystem* pakSystem, const char* path) - : pakSystem(pakSystem) - { - file = pakSystem->Open(path, "r"); - } - ~PakXmlFileBufferSource() - { - if (file) - { - pakSystem->Close(file); - } - } - - virtual int Read(void* buffer, int size) const - { - return pakSystem->Read(file, buffer, size); - }; - - IPakSystem* pakSystem; - PakSystemFile* file; -}; - -class PakXmlBufferSource - : public IXmlBufferSource -{ -public: - PakXmlBufferSource(const char* buffer, size_t length) - : position(buffer) - , end(buffer + length) - { - } - - virtual int Read(void* output, int size) const - { - size_t bytesLeft = end - position; - size_t bytesToCopy = size < bytesLeft ? size : bytesLeft; - if (bytesToCopy > 0) - { - memcpy(output, position, bytesToCopy); - position += bytesToCopy; - } - return bytesToCopy; - }; - - mutable const char* position; - const char* end; -}; - -#endif // CRYINCLUDE_CRYCOMMONTOOLS_PAKXMLFILEBUFFERSOURCE_H diff --git a/Code/Tools/CryCommonTools/PathHelpers.cpp b/Code/Tools/CryCommonTools/PathHelpers.cpp deleted file mode 100644 index 4abd28183e..0000000000 --- a/Code/Tools/CryCommonTools/PathHelpers.cpp +++ /dev/null @@ -1,621 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include -#include "PathHelpers.h" -#include "StringHelpers.h" -#include "Util.h" - -#include -#include -#include -#include -#include - - -// Returns position of last extension in last name (string::npos if not found) -// note: returns string::npos for names starting from '.' and having no -// '.' later (for example 'aaa/.ccc', 'a:.abc', '.rc') -template -static inline size_t findExtensionPosition_Tpl(const TS& path) -{ - const size_t dotPos = path.rfind('.'); - if (dotPos == TS::npos) - { - return TS::npos; - } - - static const typename TS::value_type separators[] = { '\\', '/', ':', 0 }; - const size_t separatorPos = path.find_last_of(separators); - if (separatorPos != TS::npos) - { - if (separatorPos + 1 >= dotPos) - { - return TS::npos; - } - } - else if (dotPos == 0) - { - return TS::npos; - } - - return dotPos + 1; -} - -static size_t findExtensionPosition(const string& path) -{ - return findExtensionPosition_Tpl(path); -} - -static size_t findExtensionPosition(const wstring& path) -{ - return findExtensionPosition_Tpl(path); -} - - -string PathHelpers::FindExtension(const string& path) -{ - const size_t extPos = findExtensionPosition(path); - return (extPos == string::npos) ? string() : path.substr(extPos, string::npos); -} - -wstring PathHelpers::FindExtension(const wstring& path) -{ - const size_t extPos = findExtensionPosition(path); - return (extPos == wstring::npos) ? wstring() : path.substr(extPos, wstring::npos); -} - - -template -static inline TS ReplaceExtension_Tpl(const TS& path, const TS& newExtension) -{ - if (path.empty()) - { - return TS(); - } - - if (newExtension.empty()) - { - return PathHelpers::RemoveExtension(path); - } - - const typename TS::value_type last = path[path.length() - 1]; - if ((last == '\\') || (last == '/') || (last == ':') || (last == '.')) - { - return path; - } - - const size_t extPos = findExtensionPosition(path); - static const typename TS::value_type dot[] = { '.', 0 }; - return ((extPos == TS::npos) ? path + dot : path.substr(0, extPos)) + newExtension; -} - -string PathHelpers::ReplaceExtension(const string& path, const string& newExtension) -{ - return ReplaceExtension_Tpl(path, newExtension); -} - -wstring PathHelpers::ReplaceExtension(const wstring& path, const wstring& newExtension) -{ - return ReplaceExtension_Tpl(path, newExtension); -} - - -string PathHelpers::RemoveExtension(const string& path) -{ - const size_t extPos = findExtensionPosition(path); - return (extPos == string::npos) ? path : path.substr(0, extPos - 1); -} - -wstring PathHelpers::RemoveExtension(const wstring& path) -{ - const size_t extPos = findExtensionPosition(path); - return (extPos == wstring::npos) ? path : path.substr(0, extPos - 1); -} - - -template -static inline TS GetDirectory_Tpl(const TS& path) -{ - static const typename TS::value_type separators[] = { '/', '\\', ':', 0 }; - const size_t pos = path.find_last_of(separators); - - if (pos == TS::npos) - { - return TS(); - } - - if (path[pos] == ':' || pos == 0 || path[pos - 1] == ':') - { - return path.substr(0, pos + 1); - } - - // Handle paths like "\\machine" - if (pos == 1 && (path[0] == '/' || path[0] == '\\')) - { - return path; - } - - return path.substr(0, pos); -} - -string PathHelpers::GetDirectory(const string& path) -{ - return GetDirectory_Tpl(path); -} - -wstring PathHelpers::GetDirectory(const wstring& path) -{ - return GetDirectory_Tpl(path); -} - - -template -static inline TS GetFilename_Tpl(const TS& path) -{ - static const typename TS::value_type separators[] = { '/', '\\', ':', 0 }; - const size_t pos = path.find_last_of(separators); - - if (pos == TS::npos) - { - return path; - } - - // Handle paths like "\\machine" - if (pos == 1 && (path[0] == '/' || path[0] == '\\')) - { - return TS(); - } - - return path.substr(pos + 1, TS::npos); -} - -string PathHelpers::GetFilename(const string& path) -{ - return GetFilename_Tpl(path); -} - -wstring PathHelpers::GetFilename(const wstring& path) -{ - return GetFilename_Tpl(path); -} - - -template -static inline TS AddSeparator_Tpl(const TS& path) -{ - if (path.empty()) - { - return TS(); - } - const typename TS::value_type last = path[path.length() - 1]; - if (last == '/' || last == '\\' || last == ':') - { - return path; - } -#if defined(AZ_PLATFORM_WINDOWS) - static const typename TS::value_type separator[] = { '\\', 0 }; -#else - static const typename TS::value_type separator[] = { '/', 0 }; -#endif - return path + separator; -} - -string PathHelpers::AddSeparator(const string& path) -{ - return AddSeparator_Tpl(path); -} - -wstring PathHelpers::AddSeparator(const wstring& path) -{ - return AddSeparator_Tpl(path); -} - - -template -static inline TS RemoveSeparator_Tpl(const TS& path) -{ - if (path.empty()) - { - return TS(); - } - const typename TS::value_type last = path[path.length() - 1]; - if ((last == '/' || last == '\\') && path.length() > 1 && path[path.length() - 2] != ':') - { - return path.substr(0, path.length() - 1); - } - return path; -} - -string PathHelpers::RemoveSeparator(const string& path) -{ - return RemoveSeparator_Tpl(path); -} - -wstring PathHelpers::RemoveSeparator(const wstring& path) -{ - return RemoveSeparator_Tpl(path); -} - - -template -static inline TS RemoveDuplicateSeparators_Tpl(const TS& path) -{ - if (path.length() <= 1) - { - return path; - } - - TS ret; - ret.reserve(path.length()); - - const typename TS::value_type* p = path.c_str(); - - // We start from the second char just to avoid damaging UNC paths with double backslash at the beginning (e.g. "\\Server04\file.txt") - ret += *p++; - - while (*p) - { - ret += *p++; - if (p[-1] == '\\' || p[-1] == '/') - { - while (*p == '\\' || *p == '/') - { - ++p; - } - } - } - - return ret; -} - -string PathHelpers::RemoveDuplicateSeparators(const string& path) -{ - return RemoveDuplicateSeparators_Tpl(path); -} - -wstring PathHelpers::RemoveDuplicateSeparators(const wstring& path) -{ - return RemoveDuplicateSeparators_Tpl(path); -} - - -template -static inline TS Join_Tpl(const TS& path1, const TS& path2) -{ - if (path1.empty()) - { - return path2; - } - if (path2.empty()) - { - return path1; - } - - if (!PathHelpers::IsRelative(path2)) - { - assert(0 && "Join(): path2 is not relative"); - return TS(); - } - - const typename TS::value_type last = path1[path1.length() - 1]; - if (last == '/' || last == '\\' || last == ':') - { - return path1 + path2; - } -#if defined(AZ_PLATFORM_WINDOWS) - static const typename TS::value_type separator[] = { '\\', 0 }; -#else - static const typename TS::value_type separator[] = { '/', 0 }; -#endif - return path1 + separator + path2; -} - - -string PathHelpers::Join(const string& path1, const string& path2) -{ - return Join_Tpl(path1, path2); -} - -wstring PathHelpers::Join(const wstring& path1, const wstring& path2) -{ - return Join_Tpl(path1, path2); -} - - -template -static inline bool IsRelative_Tpl(const TS& path) -{ - if (path.empty()) - { - return true; - } - return path[0] != '/' && path[0] != '\\' && path.find(':') == TS::npos; -} - -bool PathHelpers::IsRelative(const string& path) -{ - return IsRelative_Tpl(path); -} - -bool PathHelpers::IsRelative(const wstring& path) -{ - return IsRelative_Tpl(path); -} - - -string PathHelpers::ToUnixPath(const string& path) -{ - return StringHelpers::Replace(path, '\\', '/'); -} - -wstring PathHelpers::ToUnixPath(const wstring& path) -{ - wstring s(path); - std::replace(s.begin(), s.end(), L'\\', L'/'); - return s; -} - - -string PathHelpers::ToDosPath(const string& path) -{ - return StringHelpers::Replace(path, '/', '\\'); -} - -wstring PathHelpers::ToDosPath(const wstring& path) -{ - wstring s(path); - std::replace(s.begin(), s.end(), L'/', L'\\'); - return s; -} - -string PathHelpers::ToPlatformPath(const string& path) -{ -#if defined(AZ_PLATFORM_WINDOWS) - return ToDosPath(path); -#else - return ToUnixPath(path); -#endif -} - -wstring PathHelpers::ToPlatformPath(const wstring& path) -{ -#if defined(AZ_PLATFORM_WINDOWS) - return ToDosPath(path); -#else - return ToUnixPath(path); -#endif -} - - -string PathHelpers::GetAsciiPath(const char* pPath) -{ - AZStd::wstring wstr; - AZStd::to_wstring(wstr, pPath); - return GetAsciiPath(wstr.c_str()); -} - -string PathHelpers::GetAsciiPath(const wchar_t* pPath) -{ - if (!pPath[0]) - { - return string(); - } - - wstring w = ToPlatformPath(RemoveSeparator(wstring(pPath))); - - if (StringHelpers::Utf16ContainsAsciiOnly(w.c_str())) - { - return StringHelpers::ConvertAsciiUtf16ToAscii(w.c_str()); - } - - // The path is non-ASCII, so let's resort to using short - // filenames where needed (short names are always ASCII-only) - - // Long names components - std::vector p0; - StringHelpers::Split(w, wstring(L"\\"), true, p0); - - // find last component that is not in ASCII char set - int lastNonAscii; - for (lastNonAscii = (int)p0.size() - 1; lastNonAscii >= 0; --lastNonAscii) - { - if (!StringHelpers::Utf16ContainsAsciiOnly(p0[lastNonAscii].c_str())) - { - break; - } - } - assert(lastNonAscii >= 0); - - string res; - res.reserve(w.length()); - - w.clear(); - for (int i = 0; i <= lastNonAscii; ++i) - { - w.append(p0[i]); - if (i < lastNonAscii) - { - w.push_back('\\'); - } - } - - enum - { - kBufferLen = AZ_MAX_PATH_LEN - }; - wchar_t bufferWchars[kBufferLen]; - -#if defined(AZ_PLATFORM_WINDOWS) - const int charCount = GetShortPathNameW(w.c_str(), bufferWchars, kBufferLen); -#else - const int charCount = w.length(); - wcsncpy(bufferWchars, w.c_str(), kBufferLen); -#endif - if (charCount <= 0 || charCount >= kBufferLen) - { - return string(); - } -#if defined(AZ_PLATFORM_WINDOWS) - // Paranoid - if (!StringHelpers::Utf16ContainsAsciiOnly(bufferWchars)) - { - assert(0); - return string(); - } -#endif - - // Short names components - std::vector p1; - StringHelpers::Split(wstring(bufferWchars), wstring(L"\\"), true, p1); - - for (size_t i = 0; i < (int)p0.size(); ++i) - { - if (!p0[i].empty()) - { - const wstring& p = - (i > lastNonAscii || StringHelpers::Utf16ContainsAsciiOnly(p0[i].c_str())) - ? p0[i] - : p1[i]; - res.append(StringHelpers::ConvertAsciiUtf16ToAscii(p.c_str())); - } - if (i + 1 < (int)p0.size()) - { - res.push_back('\\'); - } - } - - return res; -} - - -string PathHelpers::GetAbsoluteAsciiPath(const char* pPath) -{ - char fullPath[AZ_MAX_PATH_LEN]; - AZ::IO::LocalFileIO localFileIO; - - AZStd::string normalizedPath(pPath); - AzFramework::StringFunc::Path::Normalize(normalizedPath); - - localFileIO.ConvertToAbsolutePath(normalizedPath.c_str(), fullPath, AZ_MAX_PATH_LEN); - fullPath[sizeof(fullPath) - 1] = '\0'; - - AZStd::wstring wstr; - AZStd::to_wstring(wstr, fullPath); - return GetAsciiPath(wstr.c_str()); -} - -string PathHelpers::GetAbsoluteAsciiPath(const wchar_t* pPath) -{ - AZStd::string str; - AZStd::to_string(str, pPath); - - AzFramework::StringFunc::Path::Normalize(str); - - char fullPath[AZ_MAX_PATH_LEN]; - AZ::IO::LocalFileIO localFileIO; - localFileIO.ConvertToAbsolutePath(str.c_str(), fullPath, AZ_MAX_PATH_LEN); - fullPath[sizeof(fullPath) - 1] = '\0'; - - AZStd::wstring wstr; - AZStd::to_wstring(wstr, fullPath); - return GetAsciiPath(wstr.c_str()); -} - - -string PathHelpers::GetShortestRelativeAsciiPath(const string& baseFolder, const string& dependentPath) -{ - const string d = GetAbsoluteAsciiPath(dependentPath.c_str()); - if (d.empty()) - { - return PathHelpers::CanonicalizePath(dependentPath); - } - - const string b = GetAbsoluteAsciiPath(baseFolder.c_str()); - if (b.empty()) - { - return PathHelpers::CanonicalizePath(dependentPath); - } - - const string b2 = AddSeparator(b); - if (StringHelpers::StartsWithIgnoreCase(d, b2)) - { - const size_t len = d.length() - b2.length(); - // note: len == 0 is possible in case of "C:\" and "C:\". - return (len == 0) ? string(".") : d.substr(b2.length(), len); - } - - std::vector p0; - StringHelpers::Split(b2, string("\\"), true, p0); - std::vector p1; - StringHelpers::Split(d, string("\\"), true, p1); - - if (!StringHelpers::EqualsIgnoreCase(p0[0], p1[0])) - { - // got different drive letters - return PathHelpers::CanonicalizePath(dependentPath); - } - - if (StringHelpers::EqualsIgnoreCase(d, b)) - { - // exactly same path - return string("."); - } - - // Search for first non-matching component - for (int i = 1; i < (int)p0.size(); ++i) - { - if (StringHelpers::EqualsIgnoreCase(p0[i], p1[i])) - { - continue; - } - - string s; - s.reserve(Util::getMax(d.length(), b.length())); - for (int j = i; j < (int)p0.size(); ++j) - { - if (!p0[j].empty()) - { - s.append("..\\"); - } - } - for (int j = i; j < (int)p1.size(); ++j) - { - s.append(p1[j]); - if (j + 1 < (int)p1.size()) - { - s.push_back('\\'); - } - } - return s; - } - - assert(0); - return string(); -} - - -string PathHelpers::CanonicalizePath(const string& path) -{ - string result = RemoveSeparator(path); - // remove .\ or ./ at the path beginning. - if (result.length() > 2) - { - if (result[0] == '.' && (result[1] == '\\' || result[1] == '/')) - { - result = result.substr(2); - } - } - - return result; -} diff --git a/Code/Tools/CryCommonTools/PathHelpers.h b/Code/Tools/CryCommonTools/PathHelpers.h deleted file mode 100644 index 4cf509d876..0000000000 --- a/Code/Tools/CryCommonTools/PathHelpers.h +++ /dev/null @@ -1,110 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYCOMMONTOOLS_PATHHELPERS_H -#define CRYINCLUDE_CRYCOMMONTOOLS_PATHHELPERS_H -#pragma once - -#include - -namespace PathHelpers -{ - // checks to see what the extension is in a string path - // returns the extension if found or an empty string if not found - string FindExtension(const string& path); - wstring FindExtension(const wstring& path); - - // replace an extension of a string path with a new specified extension - // returns a string with the replaced extension or the original string if unable to replace the extension - string ReplaceExtension(const string& path, const string& newExtension); - wstring ReplaceExtension(const wstring& path, const wstring& newExtension); - - // removes the extension of a specified string path - // returns a string with the extension removed or the original string if no extension was found - string RemoveExtension(const string& path); - wstring RemoveExtension(const wstring& path); - - // "abc/def/ghi" -> "abc/def" - // "abc/def/ghi/" -> "abc/def/ghi" - // "/" -> "/" - // gets the directory path out of a specified string path - // returns a string of the directory path - string GetDirectory(const string& path); - wstring GetDirectory(const wstring& path); - - // gets the file name out of a specified string path - // returns a string of the file name - string GetFilename(const string& path); - wstring GetFilename(const wstring& path); - - // add a backslash to a specified path if it doesn't already have a separator - // returns a path with the appended backslash unless there was already a separator - string AddSeparator(const string& path); - wstring AddSeparator(const wstring& path); - - // removes a forward slash or backslash from the end of a specified string path if found - // returns a string with the separator removed - string RemoveSeparator(const string& path); - wstring RemoveSeparator(const wstring& path); - - // removes extra forward slashes and backslashes if they're contained within the string path - // returns a string with the extra forward slashes and backslashes removed - string RemoveDuplicateSeparators(const string& path); - wstring RemoveDuplicateSeparators(const wstring& path); - - // It's not allowed to pass an absolute path in path2. - // Join(GetDirectory(fname), GetFilename(fname)) returns fname. - // merges two string paths together into one - // returns the merged string paths - string Join(const string& path1, const string& path2); - wstring Join(const wstring& path1, const wstring& path2); - - // checks to see if the path is a relative path - // returns true if it is or false if it is not - bool IsRelative(const string& path); - bool IsRelative(const wstring& path); - - // converts a string path to a unix path format - // returns the path in unix format - string ToUnixPath(const string& path); - wstring ToUnixPath(const wstring& path); - - // converts a string path to a dos path format - // returns the path in dos format - string ToDosPath(const string& path); - wstring ToDosPath(const wstring& path); - - // converts a string to the platform's path format. - // returns the path in the platform's path format. - string ToPlatformPath(const string& path); - wstring ToPlatformPath(const wstring& path); - - // char* pPath: in ASCII or UTF-8 encoding - // wchar_t* pPath: in UTF-16 encoding - // Non-ASCII components of pPath (everything from &pPath[0] to last non-ASCII - // part, inclusively) should exist on disk, otherwise an empty string is returned. - string GetAsciiPath(const char* pPath); - string GetAsciiPath(const wchar_t* pPath); - - // pPath passed should be in ASCII or UTF-8 encoding - string GetAbsoluteAsciiPath(const char* pPath); - // pPath passed should be in UTF-16 encoding - string GetAbsoluteAsciiPath(const wchar_t* pPath); - - // baseFolder and dependentPath passed should be in ASCII or UTF-8 encoding - string GetShortestRelativeAsciiPath(const string& baseFolder, const string& dependentPath); - - string CanonicalizePath(const string& path); -} - -#endif // CRYINCLUDE_CRYCOMMONTOOLS_PATHHELPERS_H diff --git a/Code/Tools/CryCommonTools/Platform/Common/UnixLike/ZipDir/ZipDir_Traits_UnixLike.h b/Code/Tools/CryCommonTools/Platform/Common/UnixLike/ZipDir/ZipDir_Traits_UnixLike.h deleted file mode 100644 index 03a0b4ff38..0000000000 --- a/Code/Tools/CryCommonTools/Platform/Common/UnixLike/ZipDir/ZipDir_Traits_UnixLike.h +++ /dev/null @@ -1,15 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#pragma once - -#define AZ_TRAIT_CRYCOMMONTOOLS_FSEEK(file, offset, s) fseek(file, offset, s) -#define AZ_TRAIT_CRYCOMMONTOOLS_FTELL(file) ftell(file) diff --git a/Code/Tools/CryCommonTools/Platform/Linux/ZipDir/ZipDir_Traits_Linux.h b/Code/Tools/CryCommonTools/Platform/Linux/ZipDir/ZipDir_Traits_Linux.h deleted file mode 100644 index 81a38177c2..0000000000 --- a/Code/Tools/CryCommonTools/Platform/Linux/ZipDir/ZipDir_Traits_Linux.h +++ /dev/null @@ -1,16 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#pragma once - -#include <../Common/UnixLike/ZipDir/ZipDir_Traits_UnixLike.h> - -#define AZ_TRAIT_CRYCOMMONTOOLS_PACK_1 0 diff --git a/Code/Tools/CryCommonTools/Platform/Linux/ZipDir/ZipDir_Traits_Platform.h b/Code/Tools/CryCommonTools/Platform/Linux/ZipDir/ZipDir_Traits_Platform.h deleted file mode 100644 index 6232c6462b..0000000000 --- a/Code/Tools/CryCommonTools/Platform/Linux/ZipDir/ZipDir_Traits_Platform.h +++ /dev/null @@ -1,15 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#pragma once - -#include <../Common/UnixLike/ZipDir/ZipDir_Traits_UnixLike.h> -#include diff --git a/Code/Tools/CryCommonTools/Platform/Linux/platform_linux_files.cmake b/Code/Tools/CryCommonTools/Platform/Linux/platform_linux_files.cmake deleted file mode 100644 index 9c71b39bf1..0000000000 --- a/Code/Tools/CryCommonTools/Platform/Linux/platform_linux_files.cmake +++ /dev/null @@ -1,16 +0,0 @@ -# -# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -# its licensors. -# -# For complete copyright and license terms please see the LICENSE at the root of this -# distribution (the "License"). All use of this software is governed by the License, -# or, if provided, by the license below or the license accompanying this file. Do not -# remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# - -set(FILES - ZipDir/ZipDir_Traits_Platform.h - ZipDir/ZipDir_Traits_Linux.h - ../Common/UnixLike/ZipDir/ZipDir_Traits_UnixLike.h -) diff --git a/Code/Tools/CryCommonTools/Platform/Mac/ZipDir/ZipDir_Traits_Mac.h b/Code/Tools/CryCommonTools/Platform/Mac/ZipDir/ZipDir_Traits_Mac.h deleted file mode 100644 index 111a31dc55..0000000000 --- a/Code/Tools/CryCommonTools/Platform/Mac/ZipDir/ZipDir_Traits_Mac.h +++ /dev/null @@ -1,16 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#pragma once - -#include <../Common/UnixLike/ZipDir/ZipDir_Traits_UnixLike.h> - -#define AZ_TRAIT_CRYCOMMONTOOLS_PACK_1 1 diff --git a/Code/Tools/CryCommonTools/Platform/Mac/ZipDir/ZipDir_Traits_Platform.h b/Code/Tools/CryCommonTools/Platform/Mac/ZipDir/ZipDir_Traits_Platform.h deleted file mode 100644 index e601614c59..0000000000 --- a/Code/Tools/CryCommonTools/Platform/Mac/ZipDir/ZipDir_Traits_Platform.h +++ /dev/null @@ -1,14 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#pragma once - -#include diff --git a/Code/Tools/CryCommonTools/Platform/Mac/platform_mac_files.cmake b/Code/Tools/CryCommonTools/Platform/Mac/platform_mac_files.cmake deleted file mode 100644 index b1fb3fa9a1..0000000000 --- a/Code/Tools/CryCommonTools/Platform/Mac/platform_mac_files.cmake +++ /dev/null @@ -1,16 +0,0 @@ -# -# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -# its licensors. -# -# For complete copyright and license terms please see the LICENSE at the root of this -# distribution (the "License"). All use of this software is governed by the License, -# or, if provided, by the license below or the license accompanying this file. Do not -# remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# - -set(FILES - ZipDir/ZipDir_Traits_Platform.h - ZipDir/ZipDir_Traits_Mac.h - ../Common/UnixLike/ZipDir/ZipDir_Traits_UnixLike.h -) diff --git a/Code/Tools/CryCommonTools/Platform/Windows/ZipDir/ZipDir_Traits_Platform.h b/Code/Tools/CryCommonTools/Platform/Windows/ZipDir/ZipDir_Traits_Platform.h deleted file mode 100644 index 1d177a5c8c..0000000000 --- a/Code/Tools/CryCommonTools/Platform/Windows/ZipDir/ZipDir_Traits_Platform.h +++ /dev/null @@ -1,14 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#pragma once - -#include diff --git a/Code/Tools/CryCommonTools/Platform/Windows/ZipDir/ZipDir_Traits_Windows.h b/Code/Tools/CryCommonTools/Platform/Windows/ZipDir/ZipDir_Traits_Windows.h deleted file mode 100644 index 6d9c5314e4..0000000000 --- a/Code/Tools/CryCommonTools/Platform/Windows/ZipDir/ZipDir_Traits_Windows.h +++ /dev/null @@ -1,16 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -#pragma once - -#define AZ_TRAIT_CRYCOMMONTOOLS_FSEEK(file, offset, s) _fseeki64(file, (__int64)offset, s) -#define AZ_TRAIT_CRYCOMMONTOOLS_FTELL(file) (size_t)_ftelli64(file) -#define AZ_TRAIT_CRYCOMMONTOOLS_PACK_1 1 diff --git a/Code/Tools/CryCommonTools/Platform/Windows/platform_windows_files.cmake b/Code/Tools/CryCommonTools/Platform/Windows/platform_windows_files.cmake deleted file mode 100644 index 252842e917..0000000000 --- a/Code/Tools/CryCommonTools/Platform/Windows/platform_windows_files.cmake +++ /dev/null @@ -1,15 +0,0 @@ -# -# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -# its licensors. -# -# For complete copyright and license terms please see the LICENSE at the root of this -# distribution (the "License"). All use of this software is governed by the License, -# or, if provided, by the license below or the license accompanying this file. Do not -# remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# - -set(FILES - ZipDir/ZipDir_Traits_Platform.h - ZipDir/ZipDir_Traits_Windows.h -) diff --git a/Code/Tools/CryCommonTools/ProgressRange.h b/Code/Tools/CryCommonTools/ProgressRange.h deleted file mode 100644 index 297d862980..0000000000 --- a/Code/Tools/CryCommonTools/ProgressRange.h +++ /dev/null @@ -1,89 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYCOMMONTOOLS_PROGRESSRANGE_H -#define CRYINCLUDE_CRYCOMMONTOOLS_PROGRESSRANGE_H -#pragma once - - -class ProgressRange -{ -public: - template - ProgressRange(T* object, void (T::* setter)(float progress)) - : m_target(new MethodTarget(object, setter)) - , m_progress(0.0f) - , m_start(0.0f) - , m_scale(1.0f) - { - m_target->Set(m_start); - } - - ProgressRange(ProgressRange& parent, float scale) - : m_target(new ParentRangeTarget(parent)) - , m_progress(0.0f) - , m_start(parent.m_progress) - , m_scale(scale) - { - m_target->Set(m_start); - } - - ~ProgressRange() - { - m_target->Set(m_start + m_scale); - delete m_target; - } - - void SetProgress(float progress) - { - assert(progress > -0.01f && progress < 1.1f); - m_progress = progress; - m_target->Set(m_start + m_scale * progress); - } - -private: - struct ITarget - { - virtual ~ITarget() {} - virtual void Set(float progress) = 0; - }; - - struct ParentRangeTarget - : public ITarget - { - ParentRangeTarget(ProgressRange& range) - : range(range) {} - virtual void Set(float progress) {range.SetProgress(progress); } - ProgressRange& range; - }; - - template - struct MethodTarget - : public ITarget - { - typedef void (T::* Setter)(float progress); - MethodTarget(T* object, Setter setter) - : object(object) - , setter(setter) {} - virtual void Set(float progress) {(object->*setter)(progress); } - T* object; - Setter setter; - }; - - ITarget* m_target; - float m_progress; - float m_start; - float m_scale; -}; - -#endif // CRYINCLUDE_CRYCOMMONTOOLS_PROGRESSRANGE_H diff --git a/Code/Tools/CryCommonTools/PropertyHelpers.cpp b/Code/Tools/CryCommonTools/PropertyHelpers.cpp deleted file mode 100644 index aaaa1df309..0000000000 --- a/Code/Tools/CryCommonTools/PropertyHelpers.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include -#include "PropertyHelpers.h" -#include "StringHelpers.h" - - -bool PropertyHelpers::GetPropertyValue(const string& a_propertiesString, const char* a_propertyName, string& a_value) -{ - if ((a_propertyName == 0) || (a_propertyName[0] == 0)) - { - return false; - } - - const char* lineStart = a_propertiesString.c_str(); - - while (*lineStart) - { - string key; - string value; - - const size_t lineEndPosition = strcspn(lineStart, "\n"); - const size_t equalPosition = strcspn(lineStart, "="); - - if (equalPosition < lineEndPosition) - { - key = string(lineStart, equalPosition); - value = string(lineStart + equalPosition + 1, lineEndPosition - equalPosition - 1); - } - else - { - key = string(lineStart, lineEndPosition); - value = ""; - } - - key = StringHelpers::Trim(key); - - if (_stricmp(key.c_str(), a_propertyName) == 0) - { - a_value = StringHelpers::Trim(value); - return true; - } - - lineStart += lineEndPosition; - if (*lineStart) - { - ++lineStart; - } - } - - return false; -} - -void PropertyHelpers::SetPropertyValue(string& a_propertiesString, const char* a_propertyName, const char* a_value) -{ - if ((a_propertyName == 0) || (a_propertyName[0] == 0)) - { - return; - } - - const string newValue = StringHelpers::Trim(string(a_value)); - - const char* lineStart = a_propertiesString.c_str(); - - while (*lineStart) - { - const size_t lineEndPosition = strcspn(lineStart, "\n"); - const size_t equalPosition = strcspn(lineStart, "="); - - const string key = StringHelpers::Trim(string(lineStart, ((equalPosition < lineEndPosition) ? equalPosition : lineEndPosition))); - - if (_stricmp(key.c_str(), a_propertyName) == 0) - { - const size_t prefixSz = lineStart - a_propertiesString.c_str(); - const size_t expressionSz = lineEndPosition; - - if (newValue.empty()) - { - a_propertiesString = a_propertiesString.substr(0, prefixSz) + string(a_propertyName) + a_propertiesString.substr(prefixSz + expressionSz, string::npos); - } - else - { - a_propertiesString = a_propertiesString.substr(0, prefixSz) + string(a_propertyName) + string("=") + newValue + a_propertiesString.substr(prefixSz + expressionSz, string::npos); - } - return; - } - - lineStart += lineEndPosition; - if (*lineStart) - { - ++lineStart; - } - } - - if (a_propertiesString.empty() || (a_propertiesString[a_propertiesString.size() - 1] != '\n')) - { - a_propertiesString += string("\r\n"); - } - - if (newValue.empty()) - { - a_propertiesString += string(a_propertyName); - } - else - { - a_propertiesString += string(a_propertyName) + string("=") + newValue; - } -} - -bool PropertyHelpers::HasProperty(const string& a_propertiesString, const char* a_propertyName) -{ - string value; - return PropertyHelpers::GetPropertyValue(a_propertiesString, a_propertyName, value); -} diff --git a/Code/Tools/CryCommonTools/PropertyHelpers.h b/Code/Tools/CryCommonTools/PropertyHelpers.h deleted file mode 100644 index 0a2f428cc8..0000000000 --- a/Code/Tools/CryCommonTools/PropertyHelpers.h +++ /dev/null @@ -1,28 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYCOMMONTOOLS_PROPERTYHELPERS_H -#define CRYINCLUDE_CRYCOMMONTOOLS_PROPERTYHELPERS_H -#pragma once - - -namespace PropertyHelpers -{ - bool GetPropertyValue(const string& propertiesString, const char* propertyName, string& value); - void SetPropertyValue(string& a_propertiesString, const char* propertyName, const char* value); - bool HasProperty(const string& propertiesString, const char* propertyName); -} - -#endif // CRYINCLUDE_CRYCOMMONTOOLS_PROPERTYHELPERS_H - - diff --git a/Code/Tools/CryCommonTools/STLHelpers.cpp b/Code/Tools/CryCommonTools/STLHelpers.cpp deleted file mode 100644 index c1b65f25b2..0000000000 --- a/Code/Tools/CryCommonTools/STLHelpers.cpp +++ /dev/null @@ -1,14 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include diff --git a/Code/Tools/CryCommonTools/STLHelpers.h b/Code/Tools/CryCommonTools/STLHelpers.h deleted file mode 100644 index 6fbf0c7d11..0000000000 --- a/Code/Tools/CryCommonTools/STLHelpers.h +++ /dev/null @@ -1,54 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYCOMMONTOOLS_STLHELPERS_H -#define CRYINCLUDE_CRYCOMMONTOOLS_STLHELPERS_H -#pragma once - - -#include - -namespace STLHelpers -{ - template - inline const char* constchar_cast(const Type& type) - { - return type; - } - - template <> - inline const char* constchar_cast(const std::string& type) - { - return type.c_str(); - } - - template - struct less_strcmp - { - bool operator()(const Type& left, const Type& right) const - { - return strcmp(constchar_cast(left), constchar_cast(right)) < 0; - } - }; - - template - struct less_stricmp - { - bool operator()(const Type& left, const Type& right) const - { - return _stricmp(constchar_cast(left), constchar_cast(right)) < 0; - } - }; -} - -#endif // CRYINCLUDE_CRYCOMMONTOOLS_STLHELPERS_H diff --git a/Code/Tools/CryCommonTools/SimpleBitmap.h b/Code/Tools/CryCommonTools/SimpleBitmap.h deleted file mode 100644 index ce4e93c626..0000000000 --- a/Code/Tools/CryCommonTools/SimpleBitmap.h +++ /dev/null @@ -1,508 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#pragma once -#ifndef CRYINCLUDE_CRYCOMMONTOOLS_SIMPLEBITMAP_H -#define CRYINCLUDE_CRYCOMMONTOOLS_SIMPLEBITMAP_H - -#include -#include // STL vector -#include "platform.h" // uint32 -#include "Cry_Math.h" // uint32 -#include "Util.h" // getMin() - -enum EImageFilteringMode -{ - eifm2DBorder = 0, - eifmCubemapFilter = 1, -}; - -namespace -{ - enum ECubeFace - { - ecfPosX = 0, - ecfNegX = 1, - ecfPosY = 2, - ecfNegY = 3, - ecfPosZ = 4, - ecfNegZ = 5, - ecfUnknown = -1, - }; - - struct JumpEntry - { - ECubeFace face; - int rot; - }; - - static const JumpEntry XJmpTable[] = - { - {ecfNegZ, 0}, {ecfPosZ, 2}, // ecfPosXa - {ecfPosZ, 0}, {ecfNegZ, 2}, // ecfNegXa - {ecfPosX, 1}, {ecfNegX, 3}, // ecfPosYa - {ecfPosX, 3}, {ecfNegX, 1}, // ecfNegYa - {ecfPosX, 0}, {ecfNegX, 0}, // ecfPosZa - {ecfPosX, 2}, {ecfNegX, 2} // ecfNegZa - }; - - static const JumpEntry YJmpTable[] = - { - {ecfPosY, 3}, {ecfNegY, 1}, // ecfPosXa - {ecfPosY, 1}, {ecfNegY, 3}, // ecfNegXa - {ecfNegZ, 2}, {ecfPosZ, 0}, // ecfPosYa - {ecfPosZ, 0}, {ecfNegZ, 2}, // ecfNegYa - {ecfNegY, 0}, {ecfPosY, 2}, // ecfPosZa - {ecfNegY, 2}, {ecfPosY, 0} // ecfNegZa - }; -} - -//! memory block used as bitmap -//! if you might need mipmaps please consider using ImageObject instead -template -class CSimpleBitmap -{ -public: - - CSimpleBitmap() - : m_dwWidth(0) - , m_dwHeight(0) - { - } - - ~CSimpleBitmap() - { - } - - // copy constructor - CSimpleBitmap(const CSimpleBitmap& rhs) - : m_dwWidth(0) - , m_dwHeight(0) - { - *this = rhs; // call assignment operator - } - - // assignment operator - CSimpleBitmap& operator=(const CSimpleBitmap& rhs) - { - if (&rhs != this) - { - m_data = rhs.m_data; - m_dwWidth = rhs.m_dwWidth; - m_dwHeight = rhs.m_dwHeight; - } - return *this; - } - - //! free all the memory resources - void FreeData() - { - m_data = std::vector(); - m_dwWidth = 0; - m_dwHeight = 0; - } - - //! /return true=success, false=failed because of low memory - bool SetSize(const uint32 indwWidth, const uint32 indwHeight) - { - if (m_dwWidth * m_dwHeight != indwWidth * indwHeight) - { - FreeData(); - m_data.resize(indwWidth * indwHeight); - m_dwWidth = indwWidth; - m_dwHeight = indwHeight; - } - return true; - } - -private: - ECubeFace JumpX(const ECubeFace srcFace, const bool isdXPos, int* rotCoords) const - { - int index = (int)srcFace * 2 + (isdXPos ? 0 : 1); - assert(index < sizeof(XJmpTable)); - const JumpEntry& jmp = XJmpTable[index]; - (*rotCoords) += jmp.rot; - return jmp.face; - } - - ECubeFace JumpY(const ECubeFace srcFace, const bool isdYPos, int* rotCoords) const - { - int index = (int)srcFace * 2 + (isdYPos ? 0 : 1); - assert(index < sizeof(YJmpTable)); - const JumpEntry& jmp = YJmpTable[index]; - (*rotCoords) += jmp.rot; - return jmp.face; - } - - // table that shows to which face we jump - ECubeFace JumpTable(const ECubeFace srcFace, int isdXPos, int isdYPos, int* rotCoords) const - { - if (isdXPos != 0) // recursive jump until dx==0 - { - int newSwap = 0; - ECubeFace newFace = JumpX(srcFace, isdXPos > 0, &newSwap); - (*rotCoords) += newSwap; - isdXPos -= ((isdXPos > 0) ? 1 : -1); - RotateCoord(&isdXPos, &isdYPos, newSwap); - return JumpTable(newFace, isdXPos, isdYPos, rotCoords); - } - if (isdYPos != 0) // recursive jump until dy==0 - { - int newSwap = 0; - ECubeFace newFace = JumpY(srcFace, isdYPos > 0, &newSwap); - (*rotCoords) += newSwap; - isdYPos -= ((isdYPos > 0) ? 1 : -1); - RotateCoord(&isdXPos, &isdYPos, newSwap); - return JumpTable(newFace, isdXPos, isdYPos, rotCoords); - } - assert(isdXPos == 0 && isdYPos == 0); - return srcFace; - } - - void RotateCoord(int* x, int* y, int mode) const - { - if (mode != 0) - { - if (mode == 2) // 180 degrees - { - (*x) = -(*x); - (*y) = -(*y); - } - else - { - if (mode == 1) // 90 dergees - { - int tmp = (*y); - (*y) = (*x); - (*x) = -tmp; - } - else // 270 degrees - { - assert(mode == 3); - int tmp = (*y); - (*y) = -(*x); - (*x) = tmp; - } - } - } - } - -public: - //! works only within the Bitmap for filter kernels - //! /param inX 0..m_dwWidth-1 or the method returns false - //! /param inY 0..m_dwHeight-1 or the method returns false - //! /param outValue - //! /return pointer to the raster element value if position was in the bitmap, NULL otherwise - const RasterElement* GetForFiltering_2D(const int inX, const int inY) const - { - return Get(inX, inY); - } - - //! works only within the Bitmap for filter kernels - //! /param inX 0..m_dwWidth-1 or the method returns false - //! /param inY 0..m_dwHeight-1 or the method returns false - //! /param outValue - //! /return pointer to the raster element value if position was in the bitmap, NULL otherwise - const RasterElement* GetForFiltering_Cubemap(const int inX, const int inY, const int srcX, const int srcY) const - { - if (m_data.empty()) - { - return false; - } - - assert(m_dwWidth == m_dwHeight * 6); - assert(srcX >= 0 && srcX < m_dwWidth); - assert(srcY >= 0 && srcY < m_dwHeight); - - const int sideSize = m_dwHeight; - - ECubeFace srcFace = (ECubeFace)(srcX / sideSize); - - if (inX >= 0 && inX < m_dwWidth && inY >= 0 && inY < m_dwHeight) // if we're inside the cubemap - { - ECubeFace destFace = (ECubeFace)(inX / sideSize); - if (destFace == srcFace) // we have the same face as src texel - { - return &m_data[inY * m_dwWidth + inX]; - } - } - const int halfSideSize = Util::getMax(1, sideSize / 2); - - // ternary logic - const int isdXPositive = int(floorf((float)inX / sideSize) - floorf((float)srcX / sideSize)); - const int isdYPositive = int(floorf((float)inY / sideSize) - floorf((float)srcY / sideSize)); - //if(isdXPositive==0&&isdYPositive<0&&srcFace==ecfPosY) - //{ - // int tmp = 0; - //} - assert(isdXPositive != 0 || isdYPositive != 0); - int rotCoords = 0; // quadrants to rotate coords - ECubeFace destFace = JumpTable(srcFace, isdXPositive, isdYPositive, &rotCoords); - rotCoords = ((rotCoords % 4) + 4) % 4; - int destX = inX - srcFace * sideSize; - int destY = inY; - - // rotate coords - destX -= halfSideSize; // center coords - destY -= halfSideSize; - RotateCoord(&destX, &destY, rotCoords); - destX += halfSideSize; // shift back - destY += halfSideSize; - - destX = ((destX + sideSize) % sideSize + sideSize) % sideSize; // tile in the face - destY = ((destY + sideSize) % sideSize + sideSize) % sideSize; - - destX = Util::getMin(destX, sideSize - 1); - destY = Util::getMin(destY, sideSize - 1); - destX += sideSize * destFace; - - assert(destX < m_dwWidth); - assert((ECubeFace)(destX / sideSize) == destFace); - - return &m_data[destY * m_dwWidth + destX]; - } - - const RasterElement* GetForFiltering(const Vec3& inDir) const - { - Vec3 vcAbsDir(fabsf(inDir.x), fabsf(inDir.y), fabsf(inDir.z)); - ECubeFace face; - int rotQuadrant = 0; - Vec2 texCoord; - if (vcAbsDir.x > vcAbsDir.y && vcAbsDir.x > vcAbsDir.z) - { - if (inDir.x > 0) - { - rotQuadrant = 3; - face = ecfPosX; - } - else - { - rotQuadrant = 1; - face = ecfNegX; - } - texCoord = Vec2(inDir.y, inDir.z) / vcAbsDir.x; - } - else if (vcAbsDir.y > vcAbsDir.x && vcAbsDir.y > vcAbsDir.z) - { - if (inDir.y > 0) - { - rotQuadrant = 2; - face = ecfPosY; - } - else - { - rotQuadrant = 0; - face = ecfNegY; - } - texCoord = Vec2(inDir.x, inDir.z) / vcAbsDir.y; - } - else - { - assert(vcAbsDir.z >= vcAbsDir.x && vcAbsDir.z >= vcAbsDir.y); - if (inDir.z > 0) - { - rotQuadrant = 1; - face = ecfPosZ; - } - else - { - rotQuadrant = 3; - face = ecfNegZ; - } - texCoord = Vec2(inDir.x, inDir.y) / vcAbsDir.z; - } - - texCoord = texCoord * .5f + Vec2(.5f, .5f); - assert(texCoord.x <= 1.f && texCoord.x >= 0); - assert(texCoord.y <= 1.f && texCoord.y >= 0); - - Vec2i texelPos(texCoord.x * (m_dwHeight - 1), texCoord.y * (m_dwHeight - 1)); - - texelPos.x += face * m_dwHeight; // plus face - return &m_data[texelPos.y * m_dwWidth + texelPos.x]; - } - - //! works only within the Bitmap - //! /param inX 0..m_dwWidth-1 or the method returns false - //! /param inY 0..m_dwHeight-1 or the method returns false - //! /param outValue - //! /return pointer to raster element value if position was in the bitmap, NULL otherwise - const RasterElement* Get(const uint32 inX, const uint32 inY) const - { - if (m_data.empty()) - { - return 0; - } - if (inX >= m_dwWidth || inY >= m_dwHeight) - { - return 0; - } - return &m_data[inY * m_dwWidth + inX]; - } - - - //! bilinear, works only well within 0..1 - bool GetFiltered(const float infX, const float infY, RasterElement& outValue) const - { - float fIX = floorf(infX), fIY = floorf(infY); - float fFX = infX - fIX, fFY = infY - fIY; - int iXa = (int)fIX, iYa = (int)fIY; - int iXb = iXa + 1, iYb = iYa + 1; - - if (iXb == m_dwWidth) - { - iXb = 0; - } - - if (iYb == m_dwHeight) - { - iYb = 0; - } - - const RasterElement* p[4]; - - if ((p[0] = Get(iXa, iYa)) && (p[1] = Get(iXb, iYa)) && (p[2] = Get(iXa, iYb)) && (p[3] = Get(iXb, iYb))) - { - outValue = - (*p[0]) * ((1.0f - fFX) * (1.0f - fFY)) + // left top - (*p[1]) * ((fFX) * (1.0f - fFY)) + // right top - (*p[2]) * ((1.0f - fFX) * (fFY)) + // left bottom - (*p[3]) * ((fFX) * (fFY)); // right bottom - - return true; - } - - return false; - } - - //! works only within the Bitmap - //! /param inX 0..m_dwWidth-1 or the method returns false - //! /param inY 0..m_dwHeight-1 or the method returns false - const RasterElement& GetRef(const uint32 inX, const uint32 inY) const - { - assert(!m_data.empty()); - assert(inX < m_dwWidth && inY < m_dwHeight); - return m_data[inY * m_dwWidth + inX]; - } - - //! works only within the Bitmap - //! /param inX 0..m_dwWidth-1 or the method returns false - //! /param inY 0..m_dwHeight-1 or the method returns false - RasterElement& GetRef(const uint32 inX, const uint32 inY) - { - assert(!m_data.empty()); - assert(inX < m_dwWidth && inY < m_dwHeight); - return m_data[inY * m_dwWidth + inX]; - } - - //! works even outside of the Bitmap (tiled) - //! /param inX 0..m_dwWidth-1 or the method returns false - //! /param inY 0..m_dwHeight-1 or the method returns false - RasterElement& GetTiledRef(const uint32 inX, const uint32 inY) - { - assert(!m_data.empty()); - const uint32 x = inX % m_dwWidth; - const uint32 y = inY % m_dwHeight; - return m_data[y * m_dwWidth + x]; - } - - //! works only within the Bitmap - //! /param inX 0..m_dwWidth-1 or the method returns false - //! /param inY 0..m_dwHeight-1 or the method returns false - //! /param inValue - bool Set(const uint32 inX, const uint32 inY, const RasterElement& inValue) - { - if (m_data.empty()) - { - assert(!m_data.empty()); - return false; - } - - if (inX >= m_dwWidth || inY >= m_dwHeight) - { - return false; - } - - m_data[inY * m_dwWidth + inX] = inValue; - - return true; - } - - uint32 GetWidth() const - { - return m_dwWidth; - } - - uint32 GetHeight() const - { - return m_dwHeight; - } - - // Returns size of one line in bytes - size_t GetPitch() const - { - return m_dwWidth * sizeof(RasterElement); - } - - uint32 GetBitmapSizeInBytes() const - { - return m_dwWidth * m_dwHeight * sizeof(RasterElement); - } - - //! /return could be 0 if the pixel is outside the bitmap - const RasterElement* GetPointer(const uint32 inX = 0, const uint32 inY = 0) const - { - if (inX >= m_dwWidth || inY >= m_dwHeight) - { - return 0; - } - return &m_data[inY * m_dwWidth + inX]; - } - - //! /return could be 0 if the pixel is outside the bitmap - RasterElement* GetPointer(const uint32 inX = 0, const uint32 inY = 0) - { - if (inX >= m_dwWidth || inY >= m_dwHeight) - { - return 0; - } - return &m_data[inY * m_dwWidth + inX]; - } - - void Fill(const RasterElement& inValue) - { - const uint32 n = m_dwHeight * m_dwWidth; - for (uint32 i = 0; i < n; ++i) - { - m_data[i] = inValue; - } - } - - bool IsValid() const - { - return !m_data.empty(); - } - -protected: // ------------------------------------------------------ - - std::vector m_data; //!< [m_dwWidth * m_dwHeight] - - uint32 m_dwWidth; - uint32 m_dwHeight; -}; - - - - - -#endif // CRYINCLUDE_CRYCOMMONTOOLS_SIMPLEBITMAP_H diff --git a/Code/Tools/CryCommonTools/SimpleStringPool.h b/Code/Tools/CryCommonTools/SimpleStringPool.h deleted file mode 100644 index 4e65ce1be6..0000000000 --- a/Code/Tools/CryCommonTools/SimpleStringPool.h +++ /dev/null @@ -1,249 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYCOMMONTOOLS_SIMPLESTRINGPOOL_H -#define CRYINCLUDE_CRYCOMMONTOOLS_SIMPLESTRINGPOOL_H -#pragma once - -#include - -///////////////////////////////////////////////////////////////////// -// String pool implementation. -// Inspired by expat implementation. -///////////////////////////////////////////////////////////////////// -class CSimpleStringPool -{ -public: - enum - { - STD_BLOCK_SIZE = 4096 - }; - struct BLOCK - { - BLOCK* next; - int size; - char s[1]; - }; - unsigned int m_blockSize; - BLOCK* m_blocks; - BLOCK* m_free_blocks; - const char* m_end; - char* m_ptr; - char* m_start; - int nUsedSpace; - int nUsedBlocks; - - CSimpleStringPool() - { - m_blockSize = STD_BLOCK_SIZE; - m_blocks = 0; - m_start = 0; - m_ptr = 0; - m_end = 0; - nUsedSpace = 0; - nUsedBlocks = 0; - m_free_blocks = 0; - } - ~CSimpleStringPool() - { - BLOCK* pBlock = m_blocks; - while (pBlock) - { - BLOCK* temp = pBlock->next; - //nFree++; - free(pBlock); - pBlock = temp; - } - pBlock = m_free_blocks; - while (pBlock) - { - BLOCK* temp = pBlock->next; - //nFree++; - free(pBlock); - pBlock = temp; - } - m_blocks = 0; - m_ptr = 0; - m_start = 0; - m_end = 0; - } - void SetBlockSize(unsigned int nBlockSize) - { - if (nBlockSize > 1024 * 1024) - { - nBlockSize = 1024 * 1024; - } - unsigned int size = 512; - while (size < nBlockSize) - { - size *= 2; - } - - m_blockSize = size - offsetof(BLOCK, s); - } - void Clear() - { - if (m_free_blocks) - { - BLOCK* pLast = m_blocks; - while (pLast) - { - BLOCK* temp = pLast->next; - if (!temp) - { - break; - } - pLast = temp; - } - if (pLast) - { - pLast->next = m_free_blocks; - } - } - m_free_blocks = m_blocks; - m_blocks = 0; - m_start = 0; - m_ptr = 0; - m_end = 0; - nUsedSpace = 0; - } - char* Append(const char* ptr, int nStrLen) - { - char* ret = m_ptr; - if (m_ptr && nStrLen + 1 < (m_end - m_ptr)) - { - memcpy(m_ptr, ptr, nStrLen); - m_ptr = m_ptr + nStrLen; - *m_ptr++ = 0; // add null termination. - } - else - { - int nNewBlockSize = (std::max)(nStrLen + 1, (int)m_blockSize); - AllocBlock(nNewBlockSize, nStrLen + 1); - memcpy(m_ptr, ptr, nStrLen); - m_ptr = m_ptr + nStrLen; - *m_ptr++ = 0; // add null termination. - ret = m_start; - } - nUsedSpace += nStrLen; - return ret; - } - char* ReplaceString(const char* str1, const char* str2) - { - int nStrLen1 = check_cast(strlen(str1)); - int nStrLen2 = check_cast(strlen(str2)); - - // undo ptr1 add. - if (m_ptr != m_start) - { - m_ptr = m_ptr - nStrLen1 - 1; - } - - assert(m_ptr == str1); - - int nStrLen = nStrLen1 + nStrLen2; - - char* ret = m_ptr; - if (m_ptr && nStrLen + 1 < (m_end - m_ptr)) - { - memcpy(m_ptr, str1, nStrLen1); - memcpy(m_ptr + nStrLen1, str2, nStrLen2); - m_ptr = m_ptr + nStrLen; - *m_ptr++ = 0; // add null termination. - } - else - { - int nNewBlockSize = (std::max)(nStrLen + 1, check_cast(m_blockSize)); - if (m_ptr == m_start) - { - ReallocBlock(nNewBlockSize * 2); // Reallocate current block. - memcpy(m_ptr + nStrLen1, str2, nStrLen2); - } - else - { - AllocBlock(nNewBlockSize, nStrLen + 1); - memcpy(m_ptr, str1, nStrLen1); - memcpy(m_ptr + nStrLen1, str2, nStrLen2); - } - - m_ptr = m_ptr + nStrLen; - *m_ptr++ = 0; // add null termination. - ret = m_start; - } - nUsedSpace += nStrLen; - return ret; - } -private: - void AllocBlock(int blockSize, int nMinBlockSize) - { - if (m_free_blocks) - { - BLOCK* pBlock = m_free_blocks; - BLOCK* pPrev = 0; - while (pBlock) - { - if (pBlock->size >= nMinBlockSize) - { - // Reuse free block - if (pPrev) - { - pPrev->next = pBlock->next; - } - else - { - m_free_blocks = pBlock->next; - } - - pBlock->next = m_blocks; - m_blocks = pBlock; - m_ptr = pBlock->s; - m_start = pBlock->s; - m_end = pBlock->s + pBlock->size; - return; - } - pPrev = pBlock; - pBlock = pBlock->next; - } - } - size_t nMallocSize = offsetof(BLOCK, s) + blockSize * sizeof(char); - //nMallocs++; - BLOCK* pBlock = (BLOCK*)malloc(nMallocSize); - pBlock->size = blockSize; - pBlock->next = m_blocks; - m_blocks = pBlock; - m_ptr = pBlock->s; - m_start = pBlock->s; - m_end = pBlock->s + blockSize; - nUsedBlocks++; - } - void ReallocBlock(int blockSize) - { - BLOCK* pThisBlock = m_blocks; - BLOCK* pPrevBlock = m_blocks->next; - m_blocks = pPrevBlock; - - size_t nMallocSize = offsetof(BLOCK, s) + blockSize * sizeof(char); - - //nMallocs++; - BLOCK* pBlock = (BLOCK*)realloc(pThisBlock, nMallocSize); - pBlock->size = blockSize; - pBlock->next = m_blocks; - m_blocks = pBlock; - m_ptr = pBlock->s; - m_start = pBlock->s; - m_end = pBlock->s + blockSize; - } -}; - - -#endif // CRYINCLUDE_CRYCOMMONTOOLS_SIMPLESTRINGPOOL_H diff --git a/Code/Tools/CryCommonTools/StealingThreadPool.cpp b/Code/Tools/CryCommonTools/StealingThreadPool.cpp deleted file mode 100644 index e4a6f87243..0000000000 --- a/Code/Tools/CryCommonTools/StealingThreadPool.cpp +++ /dev/null @@ -1,580 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include -#include "StealingThreadPool.h" -#include "ThreadUtils.h" -#include -#include -#include - -namespace ThreadUtils { - class StealingWorker - { - public: - StealingWorker(StealingThreadPool* pool, int index, bool trace, AZStd::condition_variable& jobsCV) - : m_pool(pool) - , m_index(index) - , m_tracingEnabled(trace) - , m_lastStartTime(0) - , m_exitFlag(0) - , m_jobsCV(jobsCV) - { - } - - static unsigned int __stdcall ThreadFunc(void* param) - { - StealingWorker* self = (StealingWorker*)(param); - self->Work(); - return 0; - } - - void Start(int startTime) - { - m_lastStartTime = startTime; - - string threadName; - threadName.Format("StealingWorker %d", m_index); - - AZStd::thread_desc threadDesc; - threadDesc.m_name = threadName.c_str(); - m_thread = AZStd::thread(AZStd::bind(StealingWorker::ThreadFunc, (void*)this), &threadDesc); - - } - - bool GetJobLockless(Job& job) - { - if (m_jobs.empty()) - { - return false; - } - job = m_jobs.front(); - m_jobs.pop_front(); - - return true; - } - - bool GetJob(Job& job) - { - AZStd::lock_guard lock(m_lockJobs); - return GetJobLockless(job); - } - - void ExecuteJob(Job& job) - { - --m_pool->m_numJobsWaitingForExecution; - job.Run(); - - if (m_tracingEnabled) - { - int time = (int)GetTickCount(); - - JobTrace trace; - trace.m_job = job; - trace.m_duration = time - m_lastStartTime; - m_traces.push_back(trace); - - m_lastStartTime = time; - } - - --m_pool->m_numJobs; - m_pool->m_jobFinishedCV.notify_all(); - } - - bool TryToStealJob(Job& job) - { - while (true) - { - StealingWorker* victim = m_pool->FindBestVictim(m_index); - if (!victim) - { - return false; - } - if (StealJobs(job, victim)) - { - return true; - } - } - } - - void Work() - { - Job job; - - while (true) - { - AZStd::mutex loadMutex; - AZStd::unique_lock loadLock(loadMutex, AZStd::defer_lock_t()); - - while (m_pool->m_numJobsWaitingForExecution == 0) - { - - m_jobsCV.wait(loadLock); - - if (m_exitFlag == 1) - { - return; - } - } - - if (GetJob(job)) - { - ExecuteJob(job); - } - else if (TryToStealJob(job)) - { - ExecuteJob(job); - } - } - } - - // Called from different worker thread - bool StealJobs(Job& job, StealingWorker* victim) - { - if (victim == this) - { - assert(0 && "Trying to steal own jobs"); - return false; - } - - bool order = m_index < victim->m_index; - AZStd::lock_guard lock1(order ? m_lockJobs : victim->m_lockJobs); - AZStd::lock_guard lock2(order ? victim->m_lockJobs : m_lockJobs); - - if (victim->m_jobs.empty()) - { - return false; - } - - int numJobs = (int)victim->m_jobs.size(); - size_t stealUntil = numJobs - numJobs / 2; - Jobs::iterator begin = victim->m_jobs.begin(); - Jobs::iterator end = victim->m_jobs.begin() + stealUntil; - - m_jobs.insert(m_jobs.end(), begin, end); - victim->m_jobs.erase(begin, end); - - return GetJobLockless(job); - } - - // Called from any thread - void Submit(const Job& job) - { - AZStd::lock_guard lock(m_lockJobs); - - m_jobs.push_back(job); - m_jobs.back().m_debugInitialThread = m_index; - - m_jobsCV.notify_one(); - } - - // Called from any thread - void Submit(const Jobs& jobs) - { - const size_t numJobs = jobs.size(); - - AZStd::lock_guard lock(m_lockJobs); - - m_jobs.insert(m_jobs.begin(), jobs.begin(), jobs.end()); - for (size_t i = 0; i < numJobs; ++i) - { - m_jobs[i].m_debugInitialThread = m_index; - } - - m_jobsCV.notify_one(); - } - - long NumJobsPending() const - { - AZStd::lock_guard lock(m_lockJobs); - return m_jobs.size(); - } - - // Called from main thread - void SignalExit() - { - CryInterlockedCompareExchange(&m_exitFlag, 1, 0); - } - - void GetTraces(JobTraces& traces) - { - if (m_tracingEnabled) - { - m_traces.swap(traces); - } - } - - private: - StealingThreadPool* m_pool; - AZStd::thread m_thread; - int m_index; - bool m_tracingEnabled; - int m_lastStartTime; - JobTraces m_traces; - - Jobs m_jobs; - mutable AZStd::mutex m_lockJobs; - AZStd::condition_variable& m_jobsCV; - - LONG m_exitFlag; - friend class StealingThreadPool; - }; - - // --------------------------------------------------------------------------- - - StealingThreadPool::StealingThreadPool(int numThreads, bool enableTracing) - : m_numThreads(numThreads) - , m_numJobs(0) - , m_numJobsWaitingForExecution(0) - , m_enableTracing(enableTracing) - { - m_workers.resize(numThreads); - for (int i = 0; i < numThreads; ++i) - { - m_workers[i] = new StealingWorker(this, i, m_enableTracing, m_jobsCV); - } - } - - StealingThreadPool::~StealingThreadPool() - { - WaitAllJobs(); - - size_t numThreads = m_workers.size(); - for (size_t i = 0; i < numThreads; ++i) - { - m_workers[i]->SignalExit(); - } - m_jobsCV.notify_all(); - - m_threadTraces.resize(numThreads); - for (size_t i = 0; i < numThreads; ++i) - { - m_workers[i]->GetTraces(m_threadTraces[i]); - } - } - - void StealingThreadPool::Start() - { - int startTime = (int)GetTickCount(); - size_t numThreads = m_workers.size(); - for (int i = 0; i < numThreads; ++i) - { - m_workers[i]->Start(startTime); - } - } - - void StealingThreadPool::WaitAllJobs() - { - AZStd::mutex loadMutex; - AZStd::unique_lock loadLock(loadMutex, AZStd::defer_lock_t()); - - while (m_numJobs > 0) - { - m_jobsCV.wait(loadLock); - } - } - - // Called from any thread - void StealingThreadPool::Submit(const Job& job) - { - ++m_numJobs; - ++m_numJobsWaitingForExecution; - - if (StealingWorker* worker = FindWorstWorker()) - { - worker->Submit(job); - } - } - - // Called from any thread - void StealingThreadPool::Submit(const Jobs& jobs) - { - m_numJobs += jobs.size(); - m_numJobsWaitingForExecution += jobs.size(); - if (StealingWorker* worker = FindWorstWorker()) - { - worker->Submit(jobs); - } - } - - JobGroup* StealingThreadPool::CreateJobGroup(JobFunc func, void* data) - { - return new JobGroup(this, func, data); - } - - StealingWorker* StealingThreadPool::FindBestVictim(int exceptFor) const - { - int maxJobs = 0; - StealingWorker* bestVictim = 0; - for (size_t i = 0; i < m_workers.size(); ++i) - { - if (i == exceptFor) - { - continue; - } - StealingWorker* worker = m_workers[i]; - long numJobs = worker->NumJobsPending(); - if (numJobs > maxJobs) - { - maxJobs = numJobs; - bestVictim = worker; - } - } - return bestVictim; - } - - StealingWorker* StealingThreadPool::FindWorstWorker() const - { - if (m_workers.empty()) - { - return 0; - } - - int minJobs = INT_MAX; - StealingWorker* worstWorker = m_workers[0]; - for (size_t i = 0; i < m_workers.size(); ++i) - { - StealingWorker* worker = m_workers[i]; - long numJobs = worker->NumJobsPending(); - if (numJobs < minJobs) - { - minJobs = numJobs; - worstWorker = worker; - } - } - return worstWorker; - } - - static bool WriteString(FILE* f, const char* str) - { - return fwrite(str, strlen(str), 1, f) == 1; - } - - static int Interpolate(int a, int b, float phase) - { - return int(float(a) + float(b - a) * phase); - } - - static int InterpolateColor(int c1, int c2, float phase) - { - const int r1 = (c1 & 0x0000ff); - const int g1 = (c1 & 0x00ff00) >> 8; - const int b1 = (c1 & 0xff0000) >> 16; - const int r2 = (c2 & 0x0000ff); - const int g2 = (c2 & 0x00ff00) >> 8; - const int b2 = (c2 & 0xff0000) >> 16; - - const int r = min(255, max(0, Interpolate(r1, r2, phase))); - const int g = min(255, max(0, Interpolate(g1, g2, phase))); - const int b = min(255, max(0, Interpolate(b1, b2, phase))); - - return r + (g << 8) + (b << 16); - } - - static const int g_animColors[] = { - 0xff0000, 0x0000ff, 0x00ff00, - 0xffff00, 0xff00ff, 0x00ffff, - 0xff8080, 0x8080ff, 0x80ff80, - 0xffff80, 0xff80ff, 0x80ffff - }; - - static int ColorizeJobTrace(const ThreadUtils::JobTrace& trace) - { - const int numColors = sizeof(g_animColors) / sizeof(g_animColors[0]); - const int initialThread = trace.m_job.m_debugInitialThread; - const int index = initialThread % numColors; - const float brightness = aznumeric_cast(pow(0.5f, initialThread / numColors)); - return InterpolateColor(0, InterpolateColor(g_animColors[index], 0xffffff, 0.5f), brightness); - } - - bool StealingThreadPool::SaveTracesGraph(const char* filename) - { - if (!m_enableTracing) - { - return false; - } - - const float screenWidth = 1240.0f; - - float duration = 0; - for (size_t t = 0; t < m_threadTraces.size(); ++t) - { - float threadDuration = 0; - const JobTraces& traces = m_threadTraces[t]; - for (int i = 0; i < traces.size(); ++i) - { - threadDuration += traces[i].m_duration; - } - duration = max(threadDuration, duration); - } - - const float padding = 10.0f; - const float rowHeight = 60.0f; - const float xScale = fabsf(duration) > FLT_EPSILON ? (screenWidth - padding * 2.0f) / duration : 1.0f; - - const float width = screenWidth; - const float height = (m_threadTraces.size() + 0.5f) * rowHeight; - - FILE* f = nullptr; - azfopen(&f, filename, "wt"); - if (!f) - { - return false; - } - - char buf[4096]; - azsnprintf(buf, sizeof(buf), - "\n" - "\n", - width, height - ); - - if (!WriteString(f, buf)) - { - return false; - } - - for (size_t t = 0; t < m_threadTraces.size(); ++t) - { - float x = padding; - float y = rowHeight * 0.5f + rowHeight * t; - - azsnprintf(buf, sizeof(buf), - " Thread %i\n", - x, y, x, y, static_cast(t + 1)); - - if (!WriteString(f, buf)) - { - return false; - } - - - y += padding; - - const ThreadUtils::JobTraces& traces = m_threadTraces[t]; - for (int i = 0; i < traces.size(); ++i) - { - const float width2 = traces[i].m_duration * xScale; - const float height2 = rowHeight * 0.5f; - - const int color = ColorizeJobTrace(traces[i]); - const int strokeColor = 0; - azsnprintf(buf, sizeof(buf), - " \n", - color, strokeColor, width2, height2, x, y); - - if (!WriteString(f, buf)) - { - return false; - } - - x += width2; - } - - y += rowHeight; - } - - if (!WriteString(f, "\n\n")) - { - return false; - } - - fclose(f); - return true; - } - - // --------------------------------------------------------------------------- - - void JobGroup::Process(JobGroup::GroupInfo* info) - { - info->m_job.Run(); - - long jobsLeft = --info->m_group->m_numJobsRunning; - assert(jobsLeft >= 0); - if (jobsLeft == 0) - { - info->m_group->m_finishJob.Run(); - delete info->m_group; - } - } - - JobGroup::JobGroup(StealingThreadPool* pool, JobFunc func, void* data) - : m_pool(pool) - , m_numJobsRunning(0) - , m_finishJob(func, data) - , m_submited(false) - { - } - - void JobGroup::Submit() - { - if (m_submited) - { - assert(0); - return; - } - - if (m_numJobsRunning == 0) - { - m_pool->Submit(m_finishJob); - return; - } - - Jobs jobs; - jobs.resize(m_infos.size()); - for (size_t i = 0; i < m_infos.size(); ++i) - { - jobs[i] = Job((JobFunc) & JobGroup::Process, &m_infos[i]); - } - - m_pool->Submit(jobs); - } - - void JobGroup::Add(JobFunc func, void* data) - { - if (m_submited) - { - assert(0); - return; - } - - GroupInfo info; - info.m_job = Job(func, data); - info.m_group = this; - - m_infos.push_back(info); - ++m_numJobsRunning; - } -} diff --git a/Code/Tools/CryCommonTools/StealingThreadPool.h b/Code/Tools/CryCommonTools/StealingThreadPool.h deleted file mode 100644 index 8576ed0416..0000000000 --- a/Code/Tools/CryCommonTools/StealingThreadPool.h +++ /dev/null @@ -1,123 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYCOMMONTOOLS_STEALINGTHREADPOOL_H -#define CRYINCLUDE_CRYCOMMONTOOLS_STEALINGTHREADPOOL_H -#pragma once - - -#include "ThreadUtils.h" -#include -#include -#include -#include -#if AZ_TRAIT_OS_PLATFORM_APPLE -#include "AppleSpecific.h" -#endif - -namespace ThreadUtils { - class StealingWorker; - class JobGroup; - - // Simple stealing thread pool - class StealingThreadPool - { - public: - explicit StealingThreadPool(int numThreads, bool enableTracing = false); - ~StealingThreadPool(); - - void Start(); - void WaitAllJobs(); - - const std::vector& Traces() const{ return m_threadTraces; } - bool SaveTracesGraph(const char* filename); - - // Submits single independent job - template - void Submit(void(* jobFunc)(T*), T* data) - { - Submit(Job((JobFunc)jobFunc, data)); - } - - // Create a group of jobs. A group of jobs can be followed by one "finishing" job. - // It is a way to express dependencies between jobs. - template - JobGroup* CreateJobGroup(void(* jobFunc)(T*), T* data) - { - return CreateJobGroup((JobFunc)jobFunc, (void*)data); - } - - uint GetNumThreads() const { return aznumeric_cast(m_numThreads); } - - private: - StealingWorker* FindBestVictim(int exceptFor) const; - StealingWorker* FindWorstWorker() const; - - void Submit(const Job& job); - void Submit(const Jobs& jobs); - JobGroup* CreateJobGroup(JobFunc, void* data); - - size_t m_numThreads; - typedef std::vector ThreadWorkers; - ThreadWorkers m_workers; - - bool m_enableTracing; - std::vector m_threadTraces; - - AZStd::atomic_long m_numJobsWaitingForExecution; - AZStd::atomic_long m_numJobs; - AZStd::condition_variable m_jobsCV; - AZStd::condition_variable m_jobFinishedCV; - - - friend class JobGroup; - friend class StealingWorker; - }; - - - // JobGroup represents a group of jobs that can be followed by one "finishing" - // job. This is a way to express dependencies between jobs. - class JobGroup - { - public: - template - void Add(void(* jobFunc)(T*), T* data) - { - Add((JobFunc)jobFunc, data); - } - - // Submits group to thread pool - void Submit(); - private: - struct GroupInfo - { - Job m_job; - JobGroup* m_group; - }; - typedef std::vector GroupInfos; - - JobGroup(StealingThreadPool* pool, JobFunc func, void* data); - - static void Process(JobGroup::GroupInfo* job); - void Add(JobFunc func, void* data); - - volatile LONG m_numJobsRunning; - StealingThreadPool* m_pool; - GroupInfos m_infos; - Job m_finishJob; - bool m_submited; - friend class StealingThreadPool; - }; -} - -#endif // CRYINCLUDE_CRYCOMMONTOOLS_STEALINGTHREADPOOL_H diff --git a/Code/Tools/CryCommonTools/SuffixUtil.h b/Code/Tools/CryCommonTools/SuffixUtil.h deleted file mode 100644 index 632e86525f..0000000000 --- a/Code/Tools/CryCommonTools/SuffixUtil.h +++ /dev/null @@ -1,59 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYCOMMONTOOLS_SUFFIXUTIL_H -#define CRYINCLUDE_CRYCOMMONTOOLS_SUFFIXUTIL_H -#pragma once - - -// convenience class to work with suffixes in filenames, like in like dirt_ddn.dds -class SuffixUtil -{ -public: - - // filename allowed to have many suffixes (e.g. "test_ddn_bump.dds" has "bump" and "ddn" - // as suffixes (assuming that suffixSeparator is '_'). - // suffixes in file extension are also considered (e.g. "test_abc.my_data" has "abc" and "data" as suffixes) - // suffixes in path part are also considered. if it's not what you want - remove path before calling this function. - // comparison is case insensitive - static bool HasSuffix(const char* const filename, const char suffixSeparator, const char* const suffix) - { - assert(filename); - assert(suffix && suffix[0]); - - const size_t suffixLen = strlen(suffix); - - for (const char* p = filename; *p; ++p) - { - if (p[0] != suffixSeparator) - { - continue; - } - - if (azmemicmp(&p[1], suffix, suffixLen) != 0) - { - continue; - } - - const char c = p[1 + suffixLen]; - if ((c == 0) || (c == suffixSeparator) || (c == '.')) - { - return true; - } - } - - return false; - } -}; - -#endif // CRYINCLUDE_CRYCOMMONTOOLS_SUFFIXUTIL_H diff --git a/Code/Tools/CryCommonTools/SummedAreaFilterKernel.cpp b/Code/Tools/CryCommonTools/SummedAreaFilterKernel.cpp deleted file mode 100644 index 3ee26df3bd..0000000000 --- a/Code/Tools/CryCommonTools/SummedAreaFilterKernel.cpp +++ /dev/null @@ -1,442 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include -#include -#include // assert() -#include // floorf() -#include "SummedAreaFilterKernel.h" // CSummedAreaFilterKernel - -CSummedAreaFilterKernel::CSummedAreaFilterKernel() -{ - m_eFilterType = eEmpty; - m_fCorrectionFactor = 0.0f; -} - -// http://www.sixsigma.de/english/sixsigma/6s_e_gauss.htm -bool CSummedAreaFilterKernel::CreateFromGauss(const unsigned long indwSize) -{ - assert(indwSize > 2); - - int iInit = 0; - - if (!Alloc(indwSize, indwSize, &iInit)) - { - return false; - } - - for (unsigned long y = 0; y < indwSize; y++) - { - for (unsigned long x = 0; x < indwSize; x++) - { - float fX = (float)(x) - (float)(indwSize) * 0.5f; - float fY = (float)(y) - (float)(indwSize) * 0.5f; - - double r1 = sqrt(fX * fX + fY * fY) / (indwSize * 0.5 - 2.0); - - if (r1 > 1) - { - m_pData[y * indwSize + x] = 0; - } - else - { - double fSigma = 1.0 / 3.0; // we aim for 6*sigma = 99,99996 of all values - - double fWeight = exp(-r1 * r1 / (2 * fSigma * fSigma)); - - fWeight -= (1.0 - 0.9999996); - - m_pData[y * indwSize + x] = (int)(255.0f * fWeight); - } - } - } - - m_eFilterType = eGaussBlur; - _SumUpTableAndNormalize(); - return true; -} - - -// create summed area table -void CSummedAreaFilterKernel::_SumUpTableAndNormalize() -{ - for (unsigned long y = 0; y < m_dwHeight; y++) - { - int iFromLeft = 0; - - for (unsigned long x = 0; x < m_dwWidth; x++) - { - iFromLeft += m_pData[y * m_dwWidth + x]; - - if (y != 0) - { - m_pData[y * m_dwWidth + x] = iFromLeft + m_pData[(y - 1) * m_dwWidth + x]; - } - else - { - m_pData[y * m_dwWidth + x] = iFromLeft; - } - } - } - - m_fCorrectionFactor = 1.0f / ((float)m_pData[m_dwHeight * m_dwWidth - 1]); -} - - -// windows size 16x16 = radius 8 -bool CSummedAreaFilterKernel::CreateFromSincCalc(const unsigned long indwSize) -{ - assert(indwSize > 2); - - int iInit = 0; - - if (!Alloc(indwSize, indwSize, &iInit)) - { - return false; - } - - for (unsigned long y = 0; y < indwSize; y++) - { - for (unsigned long x = 0; x < indwSize; x++) - { - float fX = (float)(x - indwSize * 0.5f); - float fY = (float)(y - indwSize * 0.5f); - - float r1 = sqrtf(fX * fX + fY * fY) / (indwSize * 0.5f - 2.0f); - - if (r1 > 1.0f) - { - m_pData[y * indwSize + x] = 0; - } - else - { - r1 *= 3.1415926535897932384626433832795f; - - float r2 = r1 * 8.0f; - - // http://home.no.net/dmaurer/~dersch/interpolator/interpolator.html - // weight = [ sin(x*pi) / (x*pi) ] * [ sin(x*pi / 8) / (x*pi/8) ] - - // http://www.binbooks.com/books/photo/i/l/57186AF8DE - // sinc(x) = sin(pi * x) / (pi * x) - // L8interp(x) = sinc(x) * sinc(x/8) if abs(x) <= 8 - // = 0 if abs(x) > 8 - - float fWeight = (sinf(r1) * sinf(r2)) / (r1 * r2); - - m_pData[y * indwSize + x] = (int)(255.0f * fWeight); - } - } - } - - m_eFilterType = eSinc; - _SumUpTableAndNormalize(); - - return true; -} - - - - - -bool CSummedAreaFilterKernel::CreateFromRAWFile(const char* filename, const unsigned long indwSize, const int iniMidValue) -{ - assert(iniMidValue >= 0 && iniMidValue < 255); - - int iInit = 0; - - if (!Alloc(indwSize, indwSize, &iInit)) - { - return false; - } - - FILE* in = fopen(filename, "rb"); - if (!in) - { - return false; - } - - for (unsigned long y = 0; y < m_dwHeight; y++) - { - for (unsigned long x = 0; x < m_dwWidth; x++) - { - unsigned char val; - - if (fread(&val, 1, 1, in) != 1) - { - fclose(in); - return false; - } - - m_pData[y * m_dwWidth + x] = (int)val - iniMidValue; - } - } - - fclose(in); - - m_eFilterType = eRAW; - _SumUpTableAndNormalize(); - - return true; -} - - -std::string CSummedAreaFilterKernel::GetInfoString(void) const -{ - std::string sRet = "FilterKernel("; - - switch (m_eFilterType) - { - case eEmpty: - sRet += "Empty"; - break; - case eSinc: - sRet += "Sinc16x16"; - break; - case eRAW: - sRet += "RAW"; - break; - case eGaussBlur: - sRet += "GaussBlur"; - break; - case eGaussSharp: - sRet += "GaussSharp"; - break; - default: - assert(0); - } - - sRet += ")"; - - return(sRet); -} - -float CSummedAreaFilterKernel::GetAreaNonAA(float infAx, float infAy, float infDx, float infDy) const -{ - assert(m_eFilterType != eEmpty); - - int ax = (int)floorf(infAx * 127.5f + 127.5f); - int ay = (int)floorf(infAy * 127.5f + 127.5f); - int dx = (int)floorf(infDx * 127.5f + 127.5f); - int dy = (int)floorf(infDy * 127.5f + 127.5f); - - if (ax < 0) - { - ax = 0; - } - else if (ax > 255) - { - ax = 255; - } - if (dx < 0) - { - dx = 0; - } - else if (dx > 255) - { - dx = 255; - } - if (ay < 0) - { - ay = 0; - } - else if (ay > 255) - { - ay = 255; - } - if (dy < 0) - { - dy = 0; - } - else if (dy > 255) - { - dy = 255; - } - - unsigned long area = m_pData[dy * m_dwWidth + dx] - m_pData[dy * m_dwWidth + ax] - m_pData[ay * m_dwWidth + dx] + m_pData[ay * m_dwWidth + ax]; - - return(m_fCorrectionFactor * (float)area); -} - - - -// optimizable -float CSummedAreaFilterKernel::GetAreaAA(float infAx, float infAy, float infDx, float infDy) const -{ - assert(m_eFilterType != eEmpty); - - infAx = infAx * 127.5f + 127.5f; - infAy = infAy * 127.5f + 127.5f; - infDx = infDx * 127.5f + 127.5f; - infDy = infDy * 127.5f + 127.5f; - - float fSum = _GetBilinearFiltered(infDx, infDy) - - _GetBilinearFiltered(infAx, infDy) - - _GetBilinearFiltered(infDx, infAy) - + _GetBilinearFiltered(infAx, infAy); - - return(fSum * m_fCorrectionFactor); -} - - -float CSummedAreaFilterKernel::_GetBilinearFiltered(const float infX, const float infY) const -{ - float fIX = floorf(infX), fIY = floorf(infY); - float fFX = infX - fIX, fFY = infY - fIY; - int iX = (int)fIX, iY = (int)fIY; - - if (iX < 0) - { - iX = 0; - } - else if (iX > 254) - { - iX = 254; - } - if (iY < 0) - { - iY = 0; - } - else if (iY > 254) - { - iY = 254; - } - - float fArea = m_pData[ iY * m_dwWidth + iX ] * ((1.0f - fFX) * (1.0f - fFY)) // left top - + m_pData[ iY * m_dwWidth + iX + 1 ] * ((fFX) * (1.0f - fFY)) // right top - + m_pData[(iY + 1) * m_dwWidth + iX ] * ((1.0f - fFX) * (fFY)) // left bottom - + m_pData[ iY * m_dwWidth + iX + 257] * ((fFX) * (fFY)); // right bottom - - return(fArea); -} - - - -bool CSummedAreaFilterKernel::CreateWeightFilter(CSimpleBitmap& outFilter, const float infX, const float infY, - const float infWeight, const float infR) const -{ - assert(infX >= 0.0f); - assert(infX < 1.0f); - assert(infY >= 0.0f); - assert(infY < 1.0f); - assert(infWeight >= 0.0f); - assert(infR > 0.0f); - - float fLeftTop = ceilf(infR); - int iSide = 2 * (int)fLeftTop + 1; - - float fInit = 0.0f; - - if (!outFilter.Alloc(iSide, iSide, &fInit)) - { - return false; - } - - AddWeights(outFilter, infX + fLeftTop, infY + fLeftTop, infWeight, infR); - - return true; -} - - -bool CSummedAreaFilterKernel::CreateWeightFilterBlock(CSimpleBitmap& outFilter, const unsigned long indwSideLength, - const float infR) const -{ - assert(indwSideLength >= 0); - assert(infR > 0.0f); - - float fLeftTop = ceilf(infR); - int iSide = 2 * (int)fLeftTop + 1; - - float fInit = 0.0f; - - if (!outFilter.Alloc(iSide, iSide, &fInit)) - { - return false; - } - - float fStep = 1.0f / (float)indwSideLength; - float fHalf = fStep * 0.5f; - - float fWeight = fStep * fStep; - - for (float y = fHalf; y < 1.0f; y += fStep) - { - for (float x = fHalf; x < 1.0f; x += fStep) - { - AddWeights(outFilter, x + fLeftTop, y + fLeftTop, fWeight, infR); - } - } - - // check -#ifdef _DEBUG - float fSum = 0.0f; - for (int y = 0; y < iSide; y++) - { - for (int x = 0; x < iSide; x++) - { - float f; - - outFilter.Get(x, y, f); - fSum += f; - } - } - assert(fSum >= 0.98f); - assert(fSum <= 1.02f); -#endif - - return true; -} - - -void CSummedAreaFilterKernel::AddWeights(CSimpleBitmap& inoutFilter, const float infX, const float infY, - const float infWeight, const float infR) const -{ - assert(infWeight >= 0.0f); - assert(infR > 0.0f); - - if (infWeight <= 0.0f) - { - return; - } - - float fInvR = 1.0f / infR; - float sx = floorf(infX - infR); - float sy = floorf(infY - infR); - - int iax = (int)sx; - int iay = (int)sy; - int iex = (int)ceilf(infX + infR); - int iey = (int)ceilf(infY + infR); - - float x, y; - int ix, iy; - - for (iy = iay, y = (sy - infY) * fInvR; iy <= iey; iy++, y += fInvR) - { - for (ix = iax, x = (sx - infX) * fInvR; ix <= iex; ix++, x += fInvR) - { - float fArea = GetAreaAA(x, y, x + fInvR, y + fInvR); // better quality - // float fArea=m_Filter.GetAreaNonAA(x,y,x+fInvR,y+fInvR); // faster - - // assert(fArea<=1.0f); // may be wrong if we use sharpening filter - - float fOldVal; - - inoutFilter.Get(ix, iy, fOldVal); - inoutFilter.Set(ix, iy, fOldVal + fArea * infWeight); - } - } -} - - - diff --git a/Code/Tools/CryCommonTools/SummedAreaFilterKernel.h b/Code/Tools/CryCommonTools/SummedAreaFilterKernel.h deleted file mode 100644 index 55af94f12c..0000000000 --- a/Code/Tools/CryCommonTools/SummedAreaFilterKernel.h +++ /dev/null @@ -1,112 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#pragma once -#ifndef CRYINCLUDE_CRYCOMMONTOOLS_SUMMEDAREAFILTERKERNEL_H -#define CRYINCLUDE_CRYCOMMONTOOLS_SUMMEDAREAFILTERKERNEL_H - -#include // STL string -#include "SimpleBitmap.h" // SimpleBitmap<> - -// squared of any size (summed area tables limit the size and/or values) -// normalized(sum=1) - -// optimized for high quality, not speed -// for faster filter kernels extract the neccessary size and use this 1:1 - -// based on summed area tables - -class CSummedAreaFilterKernel - : public CSimpleBitmap -{ -public: - - //! constructor init is eEmpty - CSummedAreaFilterKernel(); - - //! load 8 bit photoshop 256x256 raw image - slow - //! typical filtersize for a gaussian filter kernel is 1.44 - //! /param iniMidValue [0..255[ this enables sharpening - sharpening may expand the result range - bool CreateFromRAWFile(const char* filename, const unsigned long indwSize = 256, const int iniMidValue = 0); - - //! sharpest possible result - filter diameter size has to be 16*pixelsize (256 samples per pixel) - //! theory: http://home.no.net/dmaurer/~dersch/interpolator/interpolator.html - //! /param indwSize >2 - bool CreateFromSincCalc(const unsigned long indwSize = 256); - - //! shttp://www.sixsigma.de/english/sixsigma/6s_e_gauss.htm - //! /param indwSize >2 - bool CreateFromGauss(const unsigned long indwSize = 256); - - //! optimizable O(k*1) with high k - //! bokeh is in the range ([-1..1],[-1..1]) - //! return normalized result - float GetAreaAA(float infAx, float infAy, float infDx, float infDy) const; - - //! O(k*1) with low k - //! bokeh is in the range ([-1..1],[-1..1]) - //! return normalized result - float GetAreaNonAA(float infAx, float infAy, float infDx, float infDy) const; - - //! - //! /return e.g. "FilterKernel(Sinc16x16)" - std::string GetInfoString(void) const; - - //! /param infX [0..1[ - //! /param infY [0..1[ - //! /param infWeight [0..[ - //! /param infR >0, radius - bool CreateWeightFilter(CSimpleBitmap& outFilter, const float infX, const float infY, - const float infWeight, const float infR) const; - - //! weight for the whole block is 1.0 - //! /param indwSideLength [1,..[ e.g. 3 for 3x3 block - //! /param infR >0, radius - bool CreateWeightFilterBlock(CSimpleBitmap& outFilter, const unsigned long indwSideLength, const float infR) const; - - //! with user filter kernel - //! /param infX - //! /param infY - //! /param infWeight [0..[ - //! /param infR >0, radius - void AddWeights(CSimpleBitmap& inoutFilter, const float infX, const float infY, - const float infWeight, const float infR) const; - -private: // -------------------------------------------------------------------- - - enum EFilterState - { - eEmpty, //!< after calling constructor - eSinc, //!< from CreateFromSincCalc - eRAW, //!< from CreateFromRAWFile - eGaussBlur, //!< from CreateFromGauss - eDisc, //!< not implemented - eGaussSharp //!< not implemented - }; - - EFilterState m_eFilterType; //!< for error checks and GetInfoString() - float m_fCorrectionFactor; //!< to get the normalized (whole kernel has sum of 1) result - - //! optimizable - //! bokeh is in the range ([0..255],[0..255]) - //! /param infX - //! /param infY - //! /return not normalized result - float _GetBilinearFiltered(const float infX, const float infY) const; - - //! sum the stored values in the bitmap together - //! calculate m_fCorrectionFactor - void _SumUpTableAndNormalize(void); -}; - -#endif // CRYINCLUDE_CRYCOMMONTOOLS_SUMMEDAREAFILTERKERNEL_H diff --git a/Code/Tools/CryCommonTools/TempFilePakExtraction.cpp b/Code/Tools/CryCommonTools/TempFilePakExtraction.cpp deleted file mode 100644 index 52aa6896d6..0000000000 --- a/Code/Tools/CryCommonTools/TempFilePakExtraction.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Opens a temporary file for read only access, where the file could be -// located in a zip or pak file. Note that if the file specified -// already exists it does not delete it when finished. - - -#include "TempFilePakExtraction.h" -#include "FileUtil.h" -#include "PathHelpers.h" -#include "IPakSystem.h" - - -TempFilePakExtraction::TempFilePakExtraction(const char* filename, const char* tempPath, IPakSystem* pPakSystem) - : m_strOriginalFileName(filename) - , m_strTempFileName(filename) -{ - if (!pPakSystem || !tempPath) - { - return; - } - - { - FILE* fileOnDisk = nullptr; - azfopen(&fileOnDisk, m_strOriginalFileName.c_str(), "rb"); - if (fileOnDisk) - { - fclose(fileOnDisk); - return; - } - } - - // Choose the name for the temporary file. - string tempFullFileName; - { - uint32 tempNumber = 0; - { - LARGE_INTEGER performanceCount; - if (QueryPerformanceCounter(&performanceCount)) - { - tempNumber = performanceCount.u.LowPart; - } - } - - string tempName; - { - // CryEngine's pak system supports filenames in format "@pakFilename|fileInPak", - // so let's handle such cases by using fileInPak part of the filename. - const size_t pos = m_strOriginalFileName.find_last_of('|'); - if (pos != string::npos) - { - tempName = m_strOriginalFileName.substr(pos + 1, string::npos); - if (tempName.empty()) - { - tempName = "BadFilenameSyntax"; - } - } - else - { - tempName = m_strOriginalFileName; - } - tempName = PathHelpers::GetFilename(tempName); - } - - int tryCount = 2000; - while (--tryCount >= 0) - { - tempFullFileName.Format("%sRC%04x_%s", tempPath, (tempNumber & 0xFFFF), tempName.c_str()); - - if (!FileUtil::FileExists(tempFullFileName.c_str())) - { - FILE* f = nullptr; - azfopen(&f, tempFullFileName.c_str(), "wb"); - if (f) - { - fclose(f); - break; - } - } - - tempFullFileName.clear(); - ++tempNumber; - } - - if (tempFullFileName.empty()) - { - return; - } - } - - if (pPakSystem->ExtractNoOverwrite(m_strOriginalFileName.c_str(), tempFullFileName.c_str())) - { - m_strTempFileName = tempFullFileName; - AZ::IO::SystemFile::SetWritable(m_strTempFileName.c_str(), false); - } - else - { - AZ::IO::LocalFileIO().Remove(tempFullFileName.c_str()); - } -} - - -TempFilePakExtraction::~TempFilePakExtraction() -{ - if (HasTempFile()) - { -#if defined(AZ_PLATFORM_WINDOWS) - SetFileAttributesA(m_strTempFileName.c_str(), FILE_ATTRIBUTE_ARCHIVE); -#endif - AZ::IO::LocalFileIO().Remove(m_strTempFileName.c_str()); - } -} - - -bool TempFilePakExtraction::HasTempFile() const -{ - return (m_strOriginalFileName != m_strTempFileName); -} diff --git a/Code/Tools/CryCommonTools/TempFilePakExtraction.h b/Code/Tools/CryCommonTools/TempFilePakExtraction.h deleted file mode 100644 index c0fbb44b8a..0000000000 --- a/Code/Tools/CryCommonTools/TempFilePakExtraction.h +++ /dev/null @@ -1,50 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Opens a temporary file for read only access, where the file could be -// located in a zip or pak file. Note that if the file specified -// already exists it does not delete it when finished. - - -#ifndef CRYINCLUDE_CRYCOMMONTOOLS_TEMPFILEPAKEXTRACTION_H -#define CRYINCLUDE_CRYCOMMONTOOLS_TEMPFILEPAKEXTRACTION_H -#pragma once - -#include - -struct IPakSystem; - -class TempFilePakExtraction -{ -public: - TempFilePakExtraction(const char* filename, const char* tempPath, IPakSystem* pPakSystem); - ~TempFilePakExtraction(); - - const string& GetTempName() const - { - return m_strTempFileName; - } - - const string& GetOriginalName() const - { - return m_strOriginalFileName; - } - - bool HasTempFile() const; - -private: - string m_strTempFileName; - string m_strOriginalFileName; -}; - -#endif // CRYINCLUDE_CRYCOMMONTOOLS_TEMPFILEPAKEXTRACTION_H diff --git a/Code/Tools/CryCommonTools/ThreadUtils.cpp b/Code/Tools/CryCommonTools/ThreadUtils.cpp deleted file mode 100644 index b3dfcd6117..0000000000 --- a/Code/Tools/CryCommonTools/ThreadUtils.cpp +++ /dev/null @@ -1,171 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include -#include "ThreadUtils.h" -#include -#include -#include -#include - -namespace ThreadUtils -{ - class SimpleWorker - { - public: - SimpleWorker(SimpleThreadPool* pool, int index, bool trace) - : m_pool(pool) - , m_index(index) - , m_trace(trace) - { - } - - void Start(int startTime) - { - m_lastStartTime = startTime; - m_handle = AZStd::thread(AZStd::bind(SimpleWorker::ThreadFunc, (void*)this)); - } - - static unsigned int __stdcall ThreadFunc(void* param) - { - SimpleWorker* self = (SimpleWorker*)(param); - self->Work(); - return 0; - } - - void ExecuteJob(Job& job) - { - job.Run(); - if (m_trace) - { - int time = (int)GetTickCount(); - - JobTrace trace; - trace.m_job = job; - trace.m_duration = time - m_lastStartTime; - m_traces.push_back(trace); - - m_lastStartTime = time; - } - } - - void Work() - { - Job job; - for (;; ) - { - if (m_pool->GetJob(job, m_index)) - { - ExecuteJob(job); - } - else - { - return; - } - } - } - - // Called from main thread - void Join(JobTraces& traces) - { - if(m_handle.joinable()) - { - m_handle.join(); - } - - if (m_trace) - { - m_traces.swap(traces); - } - } - - private: - SimpleThreadPool* m_pool; - AZStd::thread m_handle; - int m_index; - bool m_trace; - int m_lastStartTime; - JobTraces m_traces; - friend SimpleThreadPool; - }; - - // --------------------------------------------------------------------------- - - SimpleThreadPool::SimpleThreadPool(bool trace) - : m_trace(trace) - , m_started(false) - , m_numProcessedJobs(0) - { - } - - SimpleThreadPool::~SimpleThreadPool() - { - WaitAllJobs(); - } - - void SimpleThreadPool::Start(int numThreads) - { - m_workers.resize(numThreads); - for (int i = 0; i < numThreads; ++i) - { - m_workers[i] = new SimpleWorker(this, i, m_trace); - } - - m_started = true; - - int startTime = (int)GetTickCount(); - for (int i = 0; i < numThreads; ++i) - { - m_workers[i]->Start(startTime); - } - } - - - void SimpleThreadPool::WaitAllJobs() - { - size_t numThreads = m_workers.size(); - m_threadTraces.resize(numThreads); - for (size_t i = 0; i < numThreads; ++i) - { - m_workers[i]->Join(m_threadTraces[i]); - } - - for (size_t i = 0; i < numThreads; ++i) - { - delete m_workers[i]; - } - m_workers.clear(); - - m_started = false; - } - - void SimpleThreadPool::Submit(const Job& job) - { - assert(!m_started); - m_jobs.push_back(job); - } - - bool SimpleThreadPool::GetJob(Job& job, [[maybe_unused]] int threadIndex) - { - AZStd::lock_guard lock(m_lockJobs); - - if (m_numProcessedJobs >= m_jobs.size()) - { - return false; - } - - job = m_jobs[m_numProcessedJobs]; - ++m_numProcessedJobs; - return true; - } -} diff --git a/Code/Tools/CryCommonTools/ThreadUtils.h b/Code/Tools/CryCommonTools/ThreadUtils.h deleted file mode 100644 index ac60a8420e..0000000000 --- a/Code/Tools/CryCommonTools/ThreadUtils.h +++ /dev/null @@ -1,288 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYCOMMONTOOLS_THREADUTILS_H -#define CRYINCLUDE_CRYCOMMONTOOLS_THREADUTILS_H -#pragma once - -#include - -#if defined(AZ_PLATFORM_WINDOWS) -#define WIN32_LEAN_AND_MEAN -#include // CRITICAL_SECTION -#endif - -#include -#include - -namespace ThreadUtils -{ -#if defined(AZ_PLATFORM_WINDOWS) - class CriticalSection - { - friend class ConditionVariable; - - public: - CriticalSection() - { - memset(&m_cs, 0, sizeof(m_cs)); - InitializeCriticalSection(&m_cs); - } - - ~CriticalSection() - { - DeleteCriticalSection(&m_cs); - } - - void Lock() - { - EnterCriticalSection(&m_cs); - } - void Unlock() - { - LeaveCriticalSection(&m_cs); - } - bool TryLock() - { - return TryEnterCriticalSection(&m_cs) != FALSE; - } - -#if defined(AZ_DEBUG_BUILD) - bool IsLocked() - { - return m_cs.RecursionCount > 0 && m_cs.OwningThread == GetCurrentThread(); - } -#endif - - private: - // You are not allowed to copy or move a CRITICAL_SECTION - // handle, so make this class non-copyable - CriticalSection(const CriticalSection& cs); - CriticalSection& operator=(const CriticalSection& cs); - - CRITICAL_SECTION m_cs; - }; - - class ConditionVariable - { - public: - ConditionVariable() - { - InitializeConditionVariable(&m_cv); - } - - void Wake() - { - WakeConditionVariable(&m_cv); - } - - void WakeAll() - { - WakeAllConditionVariable(&m_cv); - } - - void Sleep(CriticalSection& cs, DWORD milliseconds = INFINITE) - { - SleepConditionVariableCS(&m_cv, &cs.m_cs, milliseconds); - } - - private: - // You are not allowed to copy or move a CONDITION_VARIABLE - // handle, so make this class non-copyable - ConditionVariable(const ConditionVariable& cs); - ConditionVariable& operator=(const ConditionVariable& cs); - - CONDITION_VARIABLE m_cv; - }; -#elif AZ_TRAIT_OS_PLATFORM_APPLE || defined(AZ_PLATFORM_LINUX) - class CriticalSection - { - public: - CriticalSection() - : m_locked(false) - { - } - - ~CriticalSection() - { - } - - void Lock() - { - m_cs.lock(); - m_locked = true; - } - void Unlock() - { - m_cs.unlock(); - m_locked = false; - } - bool TryLock() - { - m_locked = m_cs.try_lock(); - return m_locked; - } - -#if defined (AZ_DEBUG_BUILD) - bool IsLocked() - { - return m_locked; - } -#endif - - private: - // You are not allowed to copy or move a CRITICAL_SECTION - // handle, so make this class non-copyable - CriticalSection(const CriticalSection& cs); - CriticalSection& operator=(const CriticalSection& cs); - - bool m_locked; - AZStd::recursive_mutex m_cs; - }; -#endif - - class AutoLock - { - private: - CriticalSection& m_lock; - - AutoLock(); - AutoLock(const AutoLock&); - AutoLock& operator = (const AutoLock&); - - public: - AutoLock(CriticalSection& lock) - : m_lock(lock) - { - m_lock.Lock(); - } - ~AutoLock() - { - m_lock.Unlock(); - } - }; - - typedef void(* JobFunc)(void*); - - struct Job - { - JobFunc m_func; - void* m_data; - int m_debugInitialThread; - - Job() - : m_func(0) - , m_data(0) - , m_debugInitialThread(0) - { - } - - Job(JobFunc func, void* data) - : m_func(func) - , m_data(data) - , m_debugInitialThread(0) - { - } - - void Run() - { - m_func(m_data); - } - }; - typedef std::deque Jobs; - - struct JobTrace - { - Job m_job; - bool m_stolen; - int m_duration; - - JobTrace() - : m_duration(0) - , m_stolen(false) - { - } - }; - typedef std::vector JobTraces; - - class SimpleWorker; - - class SimpleThreadPool - { - public: - SimpleThreadPool(bool trace); - ~SimpleThreadPool(); - - bool GetJob(Job& job, int threadIndex); - - // Submits single independent job - template - void Submit(void(* jobFunc)(T*), T* data) - { - Submit(Job((JobFunc)jobFunc, data)); - } - - void Start(int numThreads); - void WaitAllJobs(); - - private: - void Submit(const Job& job); - - bool m_started; - bool m_trace; - - std::vector m_workers; - - std::vector m_threadTraces; - - int m_numProcessedJobs; - AZStd::mutex m_lockJobs; - std::vector m_jobs; - }; - -#if defined(AZ_PLATFORM_WINDOWS) -#pragma pack(push, 8) - struct ThreadNameInfo - { - DWORD dwType; // Must be 0x1000. - LPCSTR szName; // Pointer to name (in user addr space). - DWORD dwThreadID; // Thread ID (-1=caller thread). - DWORD dwFlags; // Reserved for future use, must be zero. - }; -#pragma pack(pop) - - // Usage: SetThreadName (-1, "MainThread"); - // From http://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx - inline void SetThreadName([[maybe_unused]] DWORD dwThreadID, [[maybe_unused]] const char* threadName) - { -#ifdef _DEBUG - ThreadNameInfo info; - info.dwType = 0x1000; - info.szName = threadName; - info.dwThreadID = dwThreadID; - info.dwFlags = 0; - - __try - { - const DWORD exceptionCode = 0x406D1388; - RaiseException(exceptionCode, 0, sizeof(info) / sizeof(ULONG_PTR), (ULONG_PTR*)&info); - } - __except (EXCEPTION_EXECUTE_HANDLER) - { - } -#endif - } -#endif -} - -#endif // CRYINCLUDE_CRYCOMMONTOOLS_THREADUTILS_H diff --git a/Code/Tools/CryCommonTools/UI/log_icons.bmp b/Code/Tools/CryCommonTools/UI/log_icons.bmp deleted file mode 100644 index 4080bb98ea..0000000000 --- a/Code/Tools/CryCommonTools/UI/log_icons.bmp +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:1fb280a5c873225c5f2b0518964c9b7947e81c6fdb4ec19374e02043a12dd295 -size 2358 diff --git a/Code/Tools/CryCommonTools/UnitTests/PathHelpersUnitTests.cpp b/Code/Tools/CryCommonTools/UnitTests/PathHelpersUnitTests.cpp deleted file mode 100644 index 0c44aabb86..0000000000 --- a/Code/Tools/CryCommonTools/UnitTests/PathHelpersUnitTests.cpp +++ /dev/null @@ -1,807 +0,0 @@ -/* - * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or - * its licensors. - * - * For complete copyright and license terms please see the LICENSE at the root of this - * distribution (the "License"). All use of this software is governed by the License, - * or, if provided, by the license below or the license accompanying this file. Do not - * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * - */ - - -#include -#include "PathHelpers.h" -#include -#include -#include - -namespace PathHelpersTest -{ - class CryCommonToolsPathHelpersTest - : public UnitTest::AllocatorsTestFixture - { - public: - void SetUp() override - { - UnitTest::AllocatorsTestFixture::SetUp(); - AZ::AllocatorInstance::Create(); - AZ::AllocatorInstance::Create(); - } - - void TearDown() - { - AZ::AllocatorInstance::Destroy(); - AZ::AllocatorInstance::Destroy(); - UnitTest::AllocatorsTestFixture::TearDown(); - } - }; - - TEST_F(CryCommonToolsPathHelpersTest, FindExtension_StringPathNoExtension_ReturnsEmptyString) - { - const char* filePath = "ext"; - string result = PathHelpers::FindExtension(filePath); - EXPECT_STREQ("", result); - } - - TEST_F(CryCommonToolsPathHelpersTest, FindExtension_StringPath_ReturnsStringExtension) - { - const char* extension = "ext"; - const char* filePath = "foo.ext"; - string result = PathHelpers::FindExtension(filePath); - EXPECT_STREQ(extension, result); - } - - TEST_F(CryCommonToolsPathHelpersTest, FindExtension_WStringPathNoExtension_ReturnsEmptyString) - { - const wchar_t filePath[] = L"ext"; - const wchar_t expectedResult[] = L""; - const wstring result = PathHelpers::FindExtension(filePath); - EXPECT_TRUE(result == expectedResult); - } - - TEST_F(CryCommonToolsPathHelpersTest, FindExtension_WStringPath_ReturnsStringExtension) - { - const wchar_t extension[] = L"ext"; - const wchar_t filePath[] = L"foo.ext"; - const wstring result = PathHelpers::FindExtension(filePath); - EXPECT_TRUE(result == extension); - } - - TEST_F(CryCommonToolsPathHelpersTest, ReplaceExtension_EmptyStringPath_ReturnsEmptyString) - { - const char* filePath = ""; - const char* newExtension = "new"; - string result = PathHelpers::ReplaceExtension(filePath, newExtension); - EXPECT_STREQ(filePath, result); - } - - TEST_F(CryCommonToolsPathHelpersTest, ReplaceExtension_StringNoExtension_ReturnsStringNoExtension) - { - const char* filePath = "foo.ext"; - const char* newExtension = ""; - string result = PathHelpers::ReplaceExtension(filePath, newExtension); - EXPECT_STREQ("foo", result); - } - -#if AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS - TEST_F(CryCommonToolsPathHelpersTest, ReplaceExtension_StringPathWithDoubleBackSlash_ReturnsUnalteredString) - { - const char* filePath = "foo.ext\\"; - const char* newExtension = "new"; - string result = PathHelpers::ReplaceExtension(filePath, newExtension); - EXPECT_STREQ(filePath, result); - } -#endif // AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS - - TEST_F(CryCommonToolsPathHelpersTest, ReplaceExtension_StringPathWithForwardSlash_ReturnsUnalteredString) - { - const char* filePath = "foo.ext/"; - const char* newExtension = "new"; - string result = PathHelpers::ReplaceExtension(filePath, newExtension); - EXPECT_STREQ(filePath, result); - } - - TEST_F(CryCommonToolsPathHelpersTest, ReplaceExtension_StringPathWithColon_ReturnsUnalteredString) - { - const char* filePath = "foo.ext:"; - const char* newExtension = "new"; - string result = PathHelpers::ReplaceExtension(filePath, newExtension); - EXPECT_STREQ(filePath, result); - } - - TEST_F(CryCommonToolsPathHelpersTest, ReplaceExtension_StringPathEndsWithPeriod_ReturnsUnalteredString) - { - const char* filePath = "foo.ext."; - const char* newExtension = "new"; - string result = PathHelpers::ReplaceExtension(filePath, newExtension); - EXPECT_STREQ(filePath, result); - } - - TEST_F(CryCommonToolsPathHelpersTest, ReplaceExtension_StringNewExtension_ReturnsStringWithNewExtension) - { - const char* filePath = "foo.ext"; - const char* newExtension = "new"; - string result = PathHelpers::ReplaceExtension(filePath, newExtension); - EXPECT_STREQ("foo.new", result); - } - - TEST_F(CryCommonToolsPathHelpersTest, ReplaceExtension_EmptyWStringPath_ReturnsEmptyWString) - { - const wchar_t filePath[] = L""; - const wchar_t newExtension[] = L"new"; - wstring result = PathHelpers::ReplaceExtension(filePath, newExtension); - EXPECT_TRUE(result == filePath); - } - - TEST_F(CryCommonToolsPathHelpersTest, ReplaceExtension_WStringNoExtension_ReturnsWStringNoExtension) - { - const wchar_t filePath[] = L"foo.ext"; - const wchar_t newExtension[] = L""; - const wchar_t expectedResult[] = L"foo"; - wstring result = PathHelpers::ReplaceExtension(filePath, newExtension); - EXPECT_TRUE(result == expectedResult); - } - -#if AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS - TEST_F(CryCommonToolsPathHelpersTest, ReplaceExtension_WStringPathWithDoubleBackSlash_ReturnsUnalteredWString) - { - const wchar_t filePath[] = L"foo.ext\\"; - const wchar_t newExtension[] = L"new"; - wstring result = PathHelpers::ReplaceExtension(filePath, newExtension); - EXPECT_TRUE(result == filePath); - } -#endif // AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS - - TEST_F(CryCommonToolsPathHelpersTest, ReplaceExtension_WStringPathWithForwardSlash_ReturnsUnalteredWString) - { - const wchar_t filePath[] = L"foo.ext/"; - const wchar_t newExtension[] = L"new"; - wstring result = PathHelpers::ReplaceExtension(filePath, newExtension); - EXPECT_TRUE(result == filePath); - } - - TEST_F(CryCommonToolsPathHelpersTest, ReplaceExtension_WStringPathWithColon_ReturnsUnalteredWString) - { - const wchar_t filePath[] = L"foo.ext:"; - const wchar_t newExtension[] = L"new"; - wstring result = PathHelpers::ReplaceExtension(filePath, newExtension); - EXPECT_TRUE(result == filePath); - } - - TEST_F(CryCommonToolsPathHelpersTest, ReplaceExtension_WStringPathEndsWithPeriod_ReturnsUnalteredWString) - { - const wchar_t filePath[] = L"foo.ext."; - const wchar_t newExtension[] = L"new"; - wstring result = PathHelpers::ReplaceExtension(filePath, newExtension); - EXPECT_TRUE(result == filePath); - } - - TEST_F(CryCommonToolsPathHelpersTest, ReplaceExtension_WStringNewExtension_ReturnsWStringWithNewExtension) - { - const wchar_t filePath[] = L"foo.ext"; - const wchar_t newExtension[] = L"new"; - const wchar_t expectedResult[] = L"foo.new"; - wstring result = PathHelpers::ReplaceExtension(filePath, newExtension); - EXPECT_TRUE(result == expectedResult); - } - - TEST_F(CryCommonToolsPathHelpersTest, RemoveExtension_StringPathNoExtension_ReturnsUnalteredString) - { - const char* filePath = "foo"; - string result = PathHelpers::RemoveExtension(filePath); - EXPECT_STREQ(filePath, result); - } - - TEST_F(CryCommonToolsPathHelpersTest, RemoveExtension_StringPath_ReturnsStringWithoutExtension) - { - const char* filePath = "foo.bar"; - string result = PathHelpers::RemoveExtension(filePath); - EXPECT_STREQ("foo", result); - } - - TEST_F(CryCommonToolsPathHelpersTest, RemoveExtension_WStringPathNoExtension_ReturnsUnalteredWString) - { - const wchar_t filePath[] = L"foo"; - wstring result = PathHelpers::RemoveExtension(filePath); - EXPECT_TRUE(result == filePath); - } - - TEST_F(CryCommonToolsPathHelpersTest, RemoveExtension_WStringPath_ReturnsWStringWithoutExtension) - { - const wchar_t filePath[] = L"foo.bar"; - const wchar_t expectedResult[] = L"foo"; - wstring result = PathHelpers::RemoveExtension(filePath); - EXPECT_TRUE(result == expectedResult); - } - - TEST_F(CryCommonToolsPathHelpersTest, GetDirectory_StringPathWithColon_RemovesCharactersAfterColon) - { - const char* filePath = "foo:bar"; - string result = PathHelpers::GetDirectory(filePath); - EXPECT_STREQ("foo:", result); - } - - TEST_F(CryCommonToolsPathHelpersTest, GetDirectory_StringPathWithColonAsCharacterBeforeLastSeparator_RemovesCharactersAfterLastSeparator) - { - const char* filePath = "foo:/bar"; - string result = PathHelpers::GetDirectory(filePath); - EXPECT_STREQ("foo:/", result); - } - - TEST_F(CryCommonToolsPathHelpersTest, GetDirectory_StringPathWithLastSeparatorAsFirstCharacter_ReturnsStringColon) - { - const char* filePath = ":foo"; - string result = PathHelpers::GetDirectory(filePath); - EXPECT_STREQ(":", result); - } - - TEST_F(CryCommonToolsPathHelpersTest, GetDirectory_StringPathStartsWithForwardSlash_ReturnsFullString) - { - const char* filePath = "//foo"; - string result = PathHelpers::GetDirectory(filePath); - EXPECT_STREQ(filePath, result); - } - -#if AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS - TEST_F(CryCommonToolsPathHelpersTest, GetDirectory_StringPathStartsWithDoubleBackSlash_ReturnsFullString) - { - const char* filePath = "\\\\foo"; - string result = PathHelpers::GetDirectory(filePath); - EXPECT_STREQ(filePath, result); - } -#endif // AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS - - TEST_F(CryCommonToolsPathHelpersTest, GetDirectory_StringPath_ReturnsOnlyStringPath) - { - const char* filePath = "foobar/"; - string result = PathHelpers::GetDirectory(filePath); - EXPECT_STREQ("foobar", result); - } - - TEST_F(CryCommonToolsPathHelpersTest, GetDirectory_WStringPathWithColon_RemovesCharactersAfterColon) - { - const wchar_t filePath[] = L"foo:bar"; - const wchar_t expectedResult[] = L"foo:"; - wstring result = PathHelpers::GetDirectory(filePath); - EXPECT_TRUE(result == expectedResult); - } - - TEST_F(CryCommonToolsPathHelpersTest, GetDirectory_WStringPathWithColonAsCharacterBeforeLastSeparator_RemovesCharactersAfterLastSeparator) - { - const wchar_t filePath[] = L"foo:/bar"; - const wchar_t expectedResult[] = L"foo:/"; - wstring result = PathHelpers::GetDirectory(filePath); - EXPECT_TRUE(result == expectedResult); - } - - TEST_F(CryCommonToolsPathHelpersTest, GetDirectory_WStringPathWithLastSeparatorAsFirstCharacter_ReturnsWStringColon) - { - const wchar_t filePath[] = L":foo"; - const wchar_t expectedResult[] = L":"; - wstring result = PathHelpers::GetDirectory(filePath); - EXPECT_TRUE(result == expectedResult); - } - - TEST_F(CryCommonToolsPathHelpersTest, GetDirectory_WStringPathStartsWithForwardSlash_ReturnsFullWString) - { - const wchar_t filePath[] = L"//foo"; - wstring result = PathHelpers::GetDirectory(filePath); - EXPECT_TRUE(result == filePath); - } - -#if AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS - TEST_F(CryCommonToolsPathHelpersTest, GetDirectory_WStringPathStartsWithDoubleBackSlash_ReturnsFullWString) - { - const wchar_t filePath[] = L"\\\\foo"; - wstring result = PathHelpers::GetDirectory(filePath); - EXPECT_TRUE(result == filePath); - } -#endif // AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS - - TEST_F(CryCommonToolsPathHelpersTest, GetDirectory_WStringPath_ReturnsOnlyWStringPath) - { - const wchar_t filePath[] = L"foobar/"; - const wchar_t expectedResult[] = L"foobar"; - wstring result = PathHelpers::GetDirectory(filePath); - EXPECT_TRUE(result == expectedResult); - } - - TEST_F(CryCommonToolsPathHelpersTest, GetFilename_StringPathStartsWithForwardSlash_ReturnsEmptyString) - { - const char* filePath = "/:foobar"; - string result = PathHelpers::GetFilename(filePath); - EXPECT_STREQ("", result); - } - - TEST_F(CryCommonToolsPathHelpersTest, GetFilename_StringPathStartsWithDoubleBackSlash_ReturnsEmptyString) - { - const char* filePath = "\\:foobar"; - string result = PathHelpers::GetFilename(filePath); - EXPECT_STREQ("", result); - } - - TEST_F(CryCommonToolsPathHelpersTest, GetFilename_StringPath_ReturnsStringFilename) - { - const char* filePath = "/foo/foo/foobar"; - string result = PathHelpers::GetFilename(filePath); - EXPECT_STREQ("foobar", result); - } - - TEST_F(CryCommonToolsPathHelpersTest, GetFilename_WStringPathStartsWithForwardSlash_ReturnsEmptyWString) - { - const wchar_t filePath[] = L"/:foobar"; - const wchar_t expectedResult[] = L""; - wstring result = PathHelpers::GetFilename(filePath); - EXPECT_TRUE(result == expectedResult); - } - -#if AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS - TEST_F(CryCommonToolsPathHelpersTest, GetFilename_WStringPathStartsWithDoubleBackSlash_ReturnsEmptyWString) - { - const wchar_t filePath[] = L"\\:foobar"; - const wchar_t expectedResult[] = L""; - wstring result = PathHelpers::GetFilename(filePath); - EXPECT_TRUE(result == expectedResult); - } -#endif // AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS - - TEST_F(CryCommonToolsPathHelpersTest, GetFilename_WStringPath_ReturnsWStringFilename) - { - const wchar_t filePath[] = L"/foo/foo/foobar"; - const wchar_t expectedResult[] = L"foobar"; - wstring result = PathHelpers::GetFilename(filePath); - EXPECT_TRUE(result == expectedResult); - } - - TEST_F(CryCommonToolsPathHelpersTest, AddSeparator_EmptyPath_ReturnsEmptyString) - { - const char* filePath = ""; - string result = PathHelpers::AddSeparator(filePath); - EXPECT_STREQ(filePath, result); - } - - TEST_F(CryCommonToolsPathHelpersTest, AddSeparator_StringPathEndsWithForwardSlash_ReturnsStringPath) - { - const char* filePath = "foo/"; - string result = PathHelpers::AddSeparator(filePath); - EXPECT_STREQ(filePath, result); - } - -#if AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS - TEST_F(CryCommonToolsPathHelpersTest, AddSeparator_StringPathEndsWithDoubleBackSlash_ReturnsStringPath) - { - const char* filePath = "foo\\"; - string result = PathHelpers::AddSeparator(filePath); - EXPECT_STREQ(filePath, result); - } -#endif // AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS - - TEST_F(CryCommonToolsPathHelpersTest, AddSeparator_StringPathEndsWithColon_ReturnsStringPath) - { - const char* filePath = "foo:"; - string result = PathHelpers::AddSeparator(filePath); - EXPECT_STREQ(filePath, result); - } - -#if AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS - TEST_F(CryCommonToolsPathHelpersTest, AddSeparator_StringPath_ReturnsStringWithDoubleBackSlashAdded) - { - const char* filePath = "foo"; - string result = PathHelpers::AddSeparator(filePath); - EXPECT_STREQ("foo\\", result); - } -#endif // AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS - - TEST_F(CryCommonToolsPathHelpersTest, AddSeparator_EmptyPath_ReturnsEmptyWString) - { - const wchar_t filePath[] = L""; - wstring result = PathHelpers::AddSeparator(filePath); - EXPECT_TRUE(result == filePath); - } - - TEST_F(CryCommonToolsPathHelpersTest, AddSeparator_WStringPathEndsWithForwardSlash_ReturnsWStringPath) - { - const wchar_t filePath[] = L"foo/"; - wstring result = PathHelpers::AddSeparator(filePath); - EXPECT_TRUE(result == filePath); - } - -#if AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS - TEST_F(CryCommonToolsPathHelpersTest, AddSeparator_WStringPathEndsWithDoubleBackSlash_ReturnsWStringPath) - { - const wchar_t filePath[] = L"foo\\"; - wstring result = PathHelpers::AddSeparator(filePath); - EXPECT_TRUE(result == filePath); - } -#endif // AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS - - TEST_F(CryCommonToolsPathHelpersTest, AddSeparator_WStringPathEndsWithColon_ReturnsWStringPath) - { - const wchar_t filePath[] = L"foo:"; - wstring result = PathHelpers::AddSeparator(filePath); - EXPECT_TRUE(result == filePath); - } - -#if AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS - TEST_F(CryCommonToolsPathHelpersTest, AddSeparator_WStringPath_ReturnsWStringWithDoubleBackSlashAdded) - { - const wchar_t filePath[] = L"foo"; - const wchar_t expectedResult[] = L"foo\\"; - wstring result = PathHelpers::AddSeparator(filePath); - EXPECT_TRUE(result == expectedResult); - } -#endif // AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS - - TEST_F(CryCommonToolsPathHelpersTest, RemoveSeparator_EmptyStringPath_ReturnsEmptyString) - { - const char* filePath = ""; - string result = PathHelpers::RemoveSeparator(filePath); - EXPECT_STREQ(filePath, result); - } - - TEST_F(CryCommonToolsPathHelpersTest, RemoveSeparator_StringPathEndsWithForwardSlash_ReturnsStringWithoutForwardSlash) - { - const char* filePath = "foo/"; - string result = PathHelpers::RemoveSeparator(filePath); - EXPECT_STREQ("foo", result); - } - -#if AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS - TEST_F(CryCommonToolsPathHelpersTest, RemoveSeparator_StringPathEndsWithDoubleBackSlash_ReturnsStringWithoutDoubleBackSlash) - { - const char* filePath = "foo\\"; - string result = PathHelpers::RemoveSeparator(filePath); - EXPECT_STREQ("foo", result); - } -#endif // AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS - - TEST_F(CryCommonToolsPathHelpersTest, RemoveSeparator_StringPath_ReturnsStringPath) - { - const char* filePath = "foo"; - string result = PathHelpers::RemoveSeparator(filePath); - EXPECT_STREQ(filePath, result); - } - - TEST_F(CryCommonToolsPathHelpersTest, RemoveSeparator_EmptyWStringPath_ReturnsEmptyWString) - { - const wchar_t filePath[] = L""; - wstring result = PathHelpers::RemoveSeparator(filePath); - EXPECT_TRUE(result == filePath); - } - - TEST_F(CryCommonToolsPathHelpersTest, RemoveSeparator_WStringPathEndsWithForwardSlash_ReturnsWStringWithoutForwardSlash) - { - const wchar_t filePath[] = L"foo/"; - const wchar_t expectedResult[] = L"foo"; - wstring result = PathHelpers::RemoveSeparator(filePath); - EXPECT_TRUE(result == expectedResult); - } - -#if AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS - TEST_F(CryCommonToolsPathHelpersTest, RemoveSeparator_WStringPathEndsWithDoubleBackSlash_ReturnsWStringWithoutDoubleBackSlash) - { - const wchar_t filePath[] = L"foo\\"; - const wchar_t expectedResult[] = L"foo"; - wstring result = PathHelpers::RemoveSeparator(filePath); - EXPECT_TRUE(result == expectedResult); - } -#endif // AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS - - TEST_F(CryCommonToolsPathHelpersTest, RemoveSeparator_WStringPath_ReturnsWStringPath) - { - const wchar_t filePath[] = L"foo"; - wstring result = PathHelpers::RemoveSeparator(filePath); - EXPECT_TRUE(result == filePath); - } - - TEST_F(CryCommonToolsPathHelpersTest, RemoveDuplicateSeparators_StringPathLengthEqualOne_ReturnsStringPath) - { - const char* filePath = "f"; - string result = PathHelpers::RemoveDuplicateSeparators(filePath); - EXPECT_STREQ(filePath, result); - } - -#if AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS - TEST_F(CryCommonToolsPathHelpersTest, RemoveDuplicateSeparators_StringPathWithDuplicateBackSlashes_ReturnsStringWithoutDoubleBackSlashes) - { - const char* filePath = "foo\\\\bar"; - string result = PathHelpers::RemoveDuplicateSeparators(filePath); - EXPECT_STREQ("foo\\bar", result); - } -#endif // AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS - - TEST_F(CryCommonToolsPathHelpersTest, RemoveDuplicateSeparators_StringPathWithDuplicateForwardSlashes_ReturnsStringWithoutForwardSlashes) - { - const char* filePath = "foo//bar"; - string result = PathHelpers::RemoveDuplicateSeparators(filePath); - EXPECT_STREQ("foo/bar", result); - } - - TEST_F(CryCommonToolsPathHelpersTest, RemoveDuplicateSeparators_WStringPathLengthEqualOne_ReturnsWStringPath) - { - const wchar_t filePath[] = L"f"; - wstring result = PathHelpers::RemoveDuplicateSeparators(filePath); - EXPECT_TRUE(result == filePath); - } - -#if AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS - TEST_F(CryCommonToolsPathHelpersTest, RemoveDuplicateSeparators_WStringPathWithDuplicateBackSlashes_ReturnsWStringWithoutDoubleBackSlashes) - { - const wchar_t filePath[] = L"foo\\\\bar"; - const wchar_t expectedResult[] = L"foo\\bar"; - wstring result = PathHelpers::RemoveDuplicateSeparators(filePath); - EXPECT_TRUE(result == expectedResult); - } -#endif // AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS - - TEST_F(CryCommonToolsPathHelpersTest, RemoveDuplicateSeparators_WStringPathWithDuplicateForwardSlashes_ReturnsWStringWithoutForwardSlashes) - { - const wchar_t filePath[] = L"foo//bar"; - const wchar_t expectedResult[] = L"foo/bar"; - wstring result = PathHelpers::RemoveDuplicateSeparators(filePath); - EXPECT_TRUE(result == expectedResult); - } - - TEST_F(CryCommonToolsPathHelpersTest, Join_EmptySecondStringPath_ReturnsFirstString) - { - const char* filePath1 = "foo"; - const char* filePath2 = ""; - string result = PathHelpers::Join(filePath1, filePath2); - EXPECT_STREQ(filePath1, result); - } - - TEST_F(CryCommonToolsPathHelpersTest, Join_EmptyFirstStringPath_ReturnsSecondString) - { - const char* filePath1 = ""; - const char* filePath2 = "bar"; - string result = PathHelpers::Join(filePath1, filePath2); - EXPECT_STREQ(filePath2, result); - } - -#if AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS - TEST_F(CryCommonToolsPathHelpersTest, Join_StringPath_ReturnsStringAppendedWithDoubleBackSlashDivider) - { - const char* filePath1 = "foo"; - const char* filePath2 = "bar"; - string result = PathHelpers::Join(filePath1, filePath2); - EXPECT_STREQ("foo\\bar", result); - } -#endif // AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS - - TEST_F(CryCommonToolsPathHelpersTest, Join_FirstStringPathEndsWithForwardSlash_ReturnsAppendedString) - { - const char* filePath1 = "foo/"; - const char* filePath2 = "bar"; - string result = PathHelpers::Join(filePath1, filePath2); - EXPECT_STREQ("foo/bar", result); - } - -#if AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS - TEST_F(CryCommonToolsPathHelpersTest, Join_FirstStringPathEndsWithDoubleBackSlash_ReturnsAppendedString) - { - const char* filePath1 = "foo\\"; - const char* filePath2 = "bar"; - string result = PathHelpers::Join(filePath1, filePath2); - EXPECT_STREQ("foo\\bar", result); - } -#endif // AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS - - TEST_F(CryCommonToolsPathHelpersTest, Join_FirstStringPathEndsWithColon_ReturnsAppendedString) - { - const char* filePath1 = "foo:"; - const char* filePath2 = "bar"; - string result = PathHelpers::Join(filePath1, filePath2); - EXPECT_STREQ("foo:bar", result); - } - - TEST_F(CryCommonToolsPathHelpersTest, Join_EmptySecondWStringPath_ReturnsFirstWString) - { - const wchar_t filePath1[] = L"foo"; - const wchar_t filePath2[] = L""; - wstring result = PathHelpers::Join(filePath1, filePath2); - EXPECT_TRUE(result == filePath1); - } - - TEST_F(CryCommonToolsPathHelpersTest, Join_EmptyFirstWStringPath_ReturnsSecondWString) - { - const wchar_t filePath1[] = L""; - const wchar_t filePath2[] = L"bar"; - wstring result = PathHelpers::Join(filePath1, filePath2); - EXPECT_TRUE(result == filePath2); - } - -#if AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS - TEST_F(CryCommonToolsPathHelpersTest, Join_WStringPath_ReturnsWStringAppendedWithDoubleBackSlashDivider) - { - const wchar_t filePath1[] = L"foo"; - const wchar_t filePath2[] = L"bar"; - const wchar_t expectedResult[] = L"foo\\bar"; - wstring result = PathHelpers::Join(filePath1, filePath2); - EXPECT_TRUE(result == expectedResult); - } -#endif // AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS - - TEST_F(CryCommonToolsPathHelpersTest, Join_FirstWStringPathEndsWithForwardSlash_ReturnsAppendedWString) - { - const wchar_t filePath1[] = L"foo/"; - const wchar_t filePath2[] = L"bar"; - const wchar_t expectedResult[] = L"foo/bar"; - wstring result = PathHelpers::Join(filePath1, filePath2); - EXPECT_TRUE(result == expectedResult); - } - -#if AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS - TEST_F(CryCommonToolsPathHelpersTest, Join_FirstWStringPathEndsWithDoubleBackSlash_ReturnsAppendedWString) - { - const wchar_t filePath1[] = L"foo\\"; - const wchar_t filePath2[] = L"bar"; - const wchar_t expectedResult[] = L"foo\\bar"; - wstring result = PathHelpers::Join(filePath1, filePath2); - EXPECT_TRUE(result == expectedResult); - } -#endif // AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS - - TEST_F(CryCommonToolsPathHelpersTest, Join_FirstWStringPathEndsWithColon_ReturnsAppendedWString) - { - const wchar_t filePath1[] = L"foo:"; - const wchar_t filePath2[] = L"bar"; - const wchar_t expectedResult[] = L"foo:bar"; - wstring result = PathHelpers::Join(filePath1, filePath2); - EXPECT_TRUE(result == expectedResult); - } - - TEST_F(CryCommonToolsPathHelpersTest, IsRelative_EmptyStringPath_ReturnsTrue) - { - const char* filePath = ""; - bool result = PathHelpers::IsRelative(filePath); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsPathHelpersTest, IsRelative_StringPath_ReturnsTrue) - { - const char* filePath = "foo"; - bool result = PathHelpers::IsRelative(filePath); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsPathHelpersTest, IsRelative_StringPathBeginsWithForwardSlash_ReturnsFalse) - { - const char* filePath = "/foo"; - bool result = PathHelpers::IsRelative(filePath); - EXPECT_FALSE(result); - } - -#if AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS - TEST_F(CryCommonToolsPathHelpersTest, IsRelative_StringPathBeginsWithDoubleBackSlash_ReturnsFalse) - { - const char* filePath = "\\foo"; - bool result = PathHelpers::IsRelative(filePath); - EXPECT_FALSE (result); - } -#endif // AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS - - TEST_F(CryCommonToolsPathHelpersTest, IsRelative_StringPathBeginsWithColon_ReturnsFalse) - { - const char* filePath = ":foo"; - bool result = PathHelpers::IsRelative(filePath); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsPathHelpersTest, IsRelative_EmptyWStringPath_ReturnsTrue) - { - const wchar_t filePath[] = L""; - bool result = PathHelpers::IsRelative(filePath); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsPathHelpersTest, IsRelative_WStringPath_ReturnsTrue) - { - const wchar_t filePath[] = L"foo"; - bool result = PathHelpers::IsRelative(filePath); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsPathHelpersTest, IsRelative_WStringPathBeginsWithForwardSlash_ReturnsFalse) - { - const wchar_t filePath[] = L"/foo"; - bool result = PathHelpers::IsRelative(filePath); - EXPECT_FALSE(result); - } - -#if AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS - TEST_F(CryCommonToolsPathHelpersTest, IsRelative_WStringPathBeginsWithDoubleBackSlash_ReturnsFalse) - { - const wchar_t filePath[] = L"\\foo"; - bool result = PathHelpers::IsRelative(filePath); - EXPECT_FALSE(result); - } -#endif // AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS - - TEST_F(CryCommonToolsPathHelpersTest, IsRelative_WStringPathBeginsWithColon_ReturnsFalse) - { - const wchar_t filePath[] = L":foo"; - bool result = PathHelpers::IsRelative(filePath); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsPathHelpersTest, ToUnixPath_StringPath_ReturnsStringWithForwardSlashes) - { - const char* filePath = "foo\\foo\\foo"; - string result = PathHelpers::ToUnixPath(filePath); - EXPECT_STREQ("foo/foo/foo", result); - } - - TEST_F(CryCommonToolsPathHelpersTest, ToUnixPath_WStringPath_ReturnsWStringWithForwardSlashes) - { - const wchar_t filePath[] = L"foo\\foo\\foo"; - const wchar_t expectedResult[] = L"foo/foo/foo"; - wstring result = PathHelpers::ToUnixPath(filePath); - EXPECT_TRUE(result == expectedResult); - } - - TEST_F(CryCommonToolsPathHelpersTest, ToDosPath_StringPath_ReturnsStringWithDoubleBackSlashes) - { - const char* filePath = "foo/foo/foo"; - string result = PathHelpers::ToDosPath(filePath); - EXPECT_STREQ("foo\\foo\\foo", result); - } - - TEST_F(CryCommonToolsPathHelpersTest, ToDosPath_WStringPath_ReturnsStringWithDoubleBackSlashes) - { - const wchar_t filePath[] = L"foo/foo/foo"; - const wchar_t expectedResult[] = L"foo\\foo\\foo"; - wstring result = PathHelpers::ToDosPath(filePath); - EXPECT_TRUE(result == expectedResult); - } - - TEST_F(CryCommonToolsPathHelpersTest, GetAsciiPath_EmptyStringPath_ReturnsEmpty) - { - const char* filePath = ""; - string result = PathHelpers::GetAsciiPath(filePath); - EXPECT_STREQ(filePath, result); - } - -#if AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS - TEST_F(CryCommonToolsPathHelpersTest, GetAsciiPath_StringPath_ReturnsStringWithoutForwardSlash) - { - const char* filePath = "foo/bar/"; - string result = PathHelpers::GetAsciiPath(filePath); - EXPECT_STREQ("foo\\bar", result); - } -#endif // AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS - - TEST_F(CryCommonToolsPathHelpersTest, GetAsciiPath_EmptyWStringPath_ReturnsEmpty) - { - const wchar_t filePath[] = L""; - string expectedResult = ""; - string result = PathHelpers::GetAsciiPath(filePath); - EXPECT_STREQ(expectedResult, result); - } - - TEST_F(CryCommonToolsPathHelpersTest, CanonicalizePath_StringPathLengthLessThanThree_ReturnsStringWithoutForwardSlash) - { - const char* filePath = "./"; - string result = PathHelpers::CanonicalizePath(filePath); - EXPECT_STREQ(".", result); - } - - TEST_F(CryCommonToolsPathHelpersTest, CanonicalizePath_StringPathStartsWithPeriodForwardSlash_ReturnsStringWithoutPeriodAndForwardSlash) - { - const char* filePath = "./foo"; - string result = PathHelpers::CanonicalizePath(filePath); - EXPECT_STREQ("foo", result); - } - -#if AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS - TEST_F(CryCommonToolsPathHelpersTest, CanonicalizePath_StringPathStartsWithPeriodDoubleBackSlash_ReturnsStringWithoutPeriodAndDoubleBackSlash) - { - const char* filePath = ".\\foo"; - string result = PathHelpers::CanonicalizePath(filePath); - EXPECT_STREQ("foo", result); - } -#endif // AZ_TRAIT_OS_USE_WINDOWS_FILE_PATHS -} - -AZ_UNIT_TEST_HOOK(DEFAULT_UNIT_TEST_ENV); diff --git a/Code/Tools/CryCommonTools/UnitTests/StringHelpersUnitTests.cpp b/Code/Tools/CryCommonTools/UnitTests/StringHelpersUnitTests.cpp deleted file mode 100644 index 013f077528..0000000000 --- a/Code/Tools/CryCommonTools/UnitTests/StringHelpersUnitTests.cpp +++ /dev/null @@ -1,1056 +0,0 @@ -/* - * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or - * its licensors. - * - * For complete copyright and license terms please see the LICENSE at the root of this - * distribution (the "License"). All use of this software is governed by the License, - * or, if provided, by the license below or the license accompanying this file. Do not - * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * - */ - -#include -#include "StringHelpers.h" -#include -#include -#include - -namespace StringHelpersTest -{ - class CryCommonToolsStringHelpersTest - : public UnitTest::AllocatorsTestFixture - { - public: - void SetUp() override - { - UnitTest::AllocatorsTestFixture::SetUp(); - AZ::AllocatorInstance::Create(); - AZ::AllocatorInstance::Create(); - } - - void TearDown() - { - AZ::AllocatorInstance::Destroy(); - AZ::AllocatorInstance::Destroy(); - UnitTest::AllocatorsTestFixture::TearDown(); - } - }; - - TEST_F(CryCommonToolsStringHelpersTest, Compare_TwoMatchingStrings_ReturnsZero) - { - const char* string1 = "foo"; - const char* string2 = "foo"; - int result = StringHelpers::Compare(string1, string2); - EXPECT_EQ(0, result); - } - - TEST_F(CryCommonToolsStringHelpersTest, Compare_SecondStringLonger_ReturnsGreaterThanZero) - { - const char* string1 = "foo"; - const char* string2 = "foobar"; - int result = StringHelpers::Compare(string1, string2); - EXPECT_GT(0, result); - } - - TEST_F(CryCommonToolsStringHelpersTest, Compare_FirstStringLonger_ReturnsLessThanZero) - { - const char* string1 = "foobar"; - const char* string2 = "foo"; - int result = StringHelpers::Compare(string1, string2); - EXPECT_LT(0, result); - } - - TEST_F(CryCommonToolsStringHelpersTest, Compare_FirstStringCapitalized_ReturnsGreaterThanZero) - { - const char* string1 = "FOO"; - const char* string2 = "foo"; - int result = StringHelpers::Compare(string1, string2); - EXPECT_GT(0, result); - } - - TEST_F(CryCommonToolsStringHelpersTest, Compare_SecondStringCapitalized_ReturnsLessThanZero) - { - const char* string1 = "foo"; - const char* string2 = "FOO"; - int result = StringHelpers::Compare(string1, string2); - EXPECT_LT(0, result); - } - - TEST_F(CryCommonToolsStringHelpersTest, Compare_TwoMatchingWStrings_ReturnsZero) - { - const wchar_t string1[] = L"foo"; - const wchar_t string2[] = L"foo"; - int result = StringHelpers::Compare(string1, string2); - EXPECT_EQ(0, result); - } - - TEST_F(CryCommonToolsStringHelpersTest, Compare_SecondWStringLonger_ReturnsGreaterThanZero) - { - const wchar_t string1[] = L"foo"; - const wchar_t string2[] = L"foobar"; - int result = StringHelpers::Compare(string1, string2); - EXPECT_GT(0, result); - } - - TEST_F(CryCommonToolsStringHelpersTest, Compare_FirstWStringLonger_ReturnsLessThanZero) - { - const wchar_t string1[] = L"foobar"; - const wchar_t string2[] = L"foo"; - int result = StringHelpers::Compare(string1, string2); - EXPECT_LT(0, result); - } - - TEST_F(CryCommonToolsStringHelpersTest, Compare_FirstWStringCapitalized_ReturnsGreaterThanZero) - { - const wchar_t string1[] = L"FOO"; - const wchar_t string2[] = L"foo"; - int result = StringHelpers::Compare(string1, string2); - EXPECT_GT(0, result); - } - - TEST_F(CryCommonToolsStringHelpersTest, Compare_SecondWStringCapitalized_ReturnsLessThanZero) - { - const wchar_t string1[] = L"foo"; - const wchar_t string2[] = L"FOO"; - int result = StringHelpers::Compare(string1, string2); - EXPECT_LT(0, result); - } - - TEST_F(CryCommonToolsStringHelpersTest, CompareIgnoreCase_TwoMatchingStrings_ReturnsZero) - { - const char* string1 = "foo"; - const char* string2 = "foo"; - int result = StringHelpers::CompareIgnoreCase(string1, string2); - EXPECT_EQ(0, result); - } - - TEST_F(CryCommonToolsStringHelpersTest, CompareIgnoreCase_FirstStringCapitalized_ReturnsZero) - { - const char* string1 = "FOO"; - const char* string2 = "foo"; - int result = StringHelpers::CompareIgnoreCase(string1, string2); - EXPECT_EQ(0, result); - } - - TEST_F(CryCommonToolsStringHelpersTest, CompareIgnoreCase_SecondStringCapitalized_ReturnsZero) - { - const char* string1 = "foo"; - const char* string2 = "FOO"; - int result = StringHelpers::CompareIgnoreCase(string1, string2); - EXPECT_EQ(0, result); - } - - TEST_F(CryCommonToolsStringHelpersTest, CompareIgnoreCase_SecondStringLonger_ReturnsGreaterThanZero) - { - const char* string1 = "foo"; - const char* string2 = "foobar"; - int result = StringHelpers::CompareIgnoreCase(string1, string2); - EXPECT_GT(0, result); - } - - TEST_F(CryCommonToolsStringHelpersTest, CompareIgnoreCase_FirstStringLonger_ReturnsLessThanZero) - { - const char* string1 = "foobar"; - const char* string2 = "foo"; - int result = StringHelpers::CompareIgnoreCase(string1, string2); - EXPECT_LT(0, result); - } - - TEST_F(CryCommonToolsStringHelpersTest, CompareIgnoreCase_TwoMatchingWStrings_ReturnsZero) - { - const wchar_t string1[] = L"foo"; - const wchar_t string2[] = L"foo"; - int result = StringHelpers::CompareIgnoreCase(string1, string2); - EXPECT_EQ(0, result); - } - - TEST_F(CryCommonToolsStringHelpersTest, CompareIgnoreCase_FirstWStringCapitalized_ReturnsZero) - { - const wchar_t string1[] = L"FOO"; - const wchar_t string2[] = L"foo"; - int result = StringHelpers::CompareIgnoreCase(string1, string2); - EXPECT_EQ(0, result); - } - - TEST_F(CryCommonToolsStringHelpersTest, CompareIgnoreCase_SecondWStringCapitalized_ReturnsZero) - { - const wchar_t string1[] = L"foo"; - const wchar_t string2[] = L"FOO"; - int result = StringHelpers::CompareIgnoreCase(string1, string2); - EXPECT_EQ(0, result); - } - - TEST_F(CryCommonToolsStringHelpersTest, CompareIgnoreCase_SecondWStringLonger_ReturnsGreaterThanZero) - { - const wchar_t string1[] = L"foo"; - const wchar_t string2[] = L"foobar"; - int result = StringHelpers::CompareIgnoreCase(string1, string2); - EXPECT_GT(0, result); - } - - TEST_F(CryCommonToolsStringHelpersTest, CompareIgnoreCase_FirstWStringLonger_ReturnsLessThanZero) - { - const wchar_t string1[] = L"foobar"; - const wchar_t string2[] = L"foo"; - int result = StringHelpers::CompareIgnoreCase(string1, string2); - EXPECT_LT(0, result); - } - - TEST_F(CryCommonToolsStringHelpersTest, Equals_SameTwoStrings_ReturnsTrue) - { - const char* string1 = "foo"; - const char* string2 = "foo"; - bool result = StringHelpers::Equals(string1, string2); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, Equals_SecondStringUpperCase_ReturnsFalse) - { - const char* string1 = "foo"; - const char* string2 = "FOO"; - bool result = StringHelpers::Equals(string1, string2); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, Equals_FirstStringUpperCase_ReturnsFalse) - { - const char* string1 = "FOO"; - const char* string2 = "foo"; - bool result = StringHelpers::Equals(string1, string2); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, Equals_DifferentStrings_ReturnsFalse) - { - const char* string1 = "foo"; - const char* string2 = "foobar"; - bool result = StringHelpers::Equals(string1, string2); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, Equals_SameTwoWStrings_ReturnsTrue) - { - const wchar_t string1[] = L"foo"; - const wchar_t string2[] = L"foo"; - bool result = StringHelpers::Equals(string1, string2); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, Equals_SecondWStringUpperCase_ReturnsFalse) - { - const wchar_t string1[] = L"foo"; - const wchar_t string2[] = L"FOO"; - bool result = StringHelpers::Equals(string1, string2); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, Equals_FirstWStringUpperCase_ReturnsFalse) - { - const wchar_t string1[] = L"FOO"; - const wchar_t string2[] = L"foo"; - bool result = StringHelpers::Equals(string1, string2); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, Equals_DifferentWStrings_ReturnsFalse) - { - const wchar_t string1[] = L"foo"; - const wchar_t string2[] = L"foobar"; - bool result = StringHelpers::Equals(string1, string2); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, EqualsIgnoreCase_SameTwoStrings_ReturnsTrue) - { - const char* string1 = "foo"; - const char* string2 = "foo"; - bool result = StringHelpers::EqualsIgnoreCase(string1, string2); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, EqualsIgnoreCase_SecondStringUpperCase_ReturnsFalse) - { - const char* string1 = "foo"; - const char* string2 = "FOO"; - bool result = StringHelpers::EqualsIgnoreCase(string1, string2); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, EqualsIgnoreCase_FirstStringUpperCase_ReturnsFalse) - { - const char* string1 = "FOO"; - const char* string2 = "foo"; - bool result = StringHelpers::EqualsIgnoreCase(string1, string2); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, EqualsIgnoreCase_DifferentStrings_ReturnsFalse) - { - const char* string1 = "foo"; - const char* string2 = "foobar"; - bool result = StringHelpers::EqualsIgnoreCase(string1, string2); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, EqualsIgnoreCase_SameTwoWStrings_ReturnsTrue) - { - const wchar_t string1[] = L"foo"; - const wchar_t string2[] = L"foo"; - bool result = StringHelpers::EqualsIgnoreCase(string1, string2); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, EqualsIgnoreCase_SecondWStringUpperCase_ReturnsFalse) - { - const wchar_t string1[] = L"foo"; - const wchar_t string2[] = L"FOO"; - bool result = StringHelpers::EqualsIgnoreCase(string1, string2); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, EqualsIgnoreCase_FirstWStringUpperCase_ReturnsFalse) - { - const wchar_t string1[] = L"FOO"; - const wchar_t string2[] = L"foo"; - bool result = StringHelpers::EqualsIgnoreCase(string1, string2); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, EqualsIgnoreCase_DifferentWStrings_ReturnsFalse) - { - const wchar_t string1[] = L"foo"; - const wchar_t string2[] = L"foobar"; - bool result = StringHelpers::EqualsIgnoreCase(string1, string2); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, StartsWith_StringPathsWithLongerPattern_ReturnsFalse) - { - const char* string = "foo"; - const char* pattern = "foobar"; - bool result = StringHelpers::StartsWith(string, pattern); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, StartsWith_StringPathAndPattern_ReturnsTrue) - { - const char* string = "foobar"; - const char* pattern = "foo"; - bool result = StringHelpers::StartsWith(string, pattern); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, StartsWith_StringPathCapitalized_ReturnsFalse) - { - const char* string = "FOOBAR"; - const char* pattern = "foo"; - bool result = StringHelpers::StartsWith(string, pattern); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, StartsWith_PatternStringCapitalized_ReturnsFalse) - { - const char* string = "foobar"; - const char* pattern = "FOO"; - bool result = StringHelpers::StartsWith(string, pattern); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, StartsWith_StringPathAndNoMatchingPattern_ReturnsFalse) - { - const char* string = "foo"; - const char* pattern = "bar"; - bool result = StringHelpers::StartsWith(string, pattern); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, StartsWith_WStringPathsWithLongerPattern_ReturnsFalse) - { - const wchar_t string[] = L"foo"; - const wchar_t pattern[] = L"foobar"; - bool result = StringHelpers::StartsWith(string, pattern); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, StartsWith_WStringPathAndPattern_ReturnsTrue) - { - const wchar_t string[] = L"foobar"; - const wchar_t pattern[] = L"foo"; - bool result = StringHelpers::StartsWith(string, pattern); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, StartsWith_WStringPathCapitalized_ReturnsFalse) - { - const wchar_t string[] = L"FOOBAR"; - const wchar_t pattern[] = L"foo"; - bool result = StringHelpers::StartsWith(string, pattern); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, StartsWith_PatternWstringCapitalized_ReturnsFalse) - { - const wchar_t string[] = L"foobar"; - const wchar_t pattern[] = L"FOO"; - bool result = StringHelpers::StartsWith(string, pattern); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, StartsWith_WStringPathAndNoMatchingPattern_ReturnsFalse) - { - const wchar_t string[] = L"foo"; - const wchar_t pattern[] = L"bar"; - bool result = StringHelpers::StartsWith(string, pattern); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, StartsWithIgnoreCase_StringPathsWithLongerPattern_ReturnsFalse) - { - const char* string = "foo"; - const char* pattern = "foobar"; - bool result = StringHelpers::StartsWithIgnoreCase(string, pattern); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, StartsWithIgnoreCase_StringPathAndPattern_ReturnsTrue) - { - const char* string = "foobar"; - const char* pattern = "foo"; - bool result = StringHelpers::StartsWithIgnoreCase(string, pattern); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, StartsWithIgnoreCase_StringPathCapitalized_ReturnsFalse) - { - const char* string = "FOOBAR"; - const char* pattern = "foo"; - bool result = StringHelpers::StartsWithIgnoreCase(string, pattern); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, StartsWithIgnoreCase_PatternStringCapitalized_ReturnsFalse) - { - const char* string = "foobar"; - const char* pattern = "FOO"; - bool result = StringHelpers::StartsWithIgnoreCase(string, pattern); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, StartsWithIgnoreCase_StringPathAndNoMatchingPattern_ReturnsFalse) - { - const char* string = "foo"; - const char* pattern = "bar"; - bool result = StringHelpers::StartsWithIgnoreCase(string, pattern); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, StartsWithIgnoreCase_WStringPathsWithLongerPattern_ReturnsFalse) - { - const wchar_t string[] = L"foo"; - const wchar_t pattern[] = L"foobar"; - bool result = StringHelpers::StartsWithIgnoreCase(string, pattern); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, StartsWithIgnoreCase_WStringPathAndPattern_ReturnsTrue) - { - const wchar_t string[] = L"foobar"; - const wchar_t pattern[] = L"foo"; - bool result = StringHelpers::StartsWithIgnoreCase(string, pattern); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, StartsWithIgnoreCase_WStringPathCapitalized_ReturnsFalse) - { - const wchar_t string[] = L"FOOBAR"; - const wchar_t pattern[] = L"foo"; - bool result = StringHelpers::StartsWithIgnoreCase(string, pattern); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, StartsWithIgnoreCase_PatternWStringCapitalized_ReturnsFalse) - { - const wchar_t string[] = L"foobar"; - const wchar_t pattern[] = L"FOO"; - bool result = StringHelpers::StartsWithIgnoreCase(string, pattern); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, StartsWithIgnoreCase_WStringPathAndNoMatchingPattern_ReturnsFalse) - { - const wchar_t string[] = L"foo"; - const wchar_t pattern[] = L"bar"; - bool result = StringHelpers::StartsWithIgnoreCase(string, pattern); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, EndsWith_StringPathWithLongerPattern_ReturnsFalse) - { - const char* string = "foo"; - const char* pattern = "foobar"; - bool result = StringHelpers::EndsWith(string, pattern); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, EndsWith_StringPathAndPattern_ReturnsTrue) - { - const char* string = "foobar"; - const char* pattern = "bar"; - bool result = StringHelpers::EndsWith(string, pattern); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, EndsWith_StringPathCapitalized_ReturnsFalse) - { - const char* string = "FOOBAR"; - const char* pattern = "bar"; - bool result = StringHelpers::EndsWith(string, pattern); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, EndsWith_PatternStringCapitalized_ReturnsFalse) - { - const char* string = "foobar"; - const char* pattern = "BAR"; - bool result = StringHelpers::EndsWith(string, pattern); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, EndsWith_StringPathAndNoMatchingPattern_ReturnsFalse) - { - const char* string = "foo"; - const char* pattern = "bar"; - bool result = StringHelpers::EndsWithIgnoreCase(string, pattern); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, EndsWith_WStringPathWithLongerPattern_ReturnsFalse) - { - const wchar_t string[] = L"foo"; - const wchar_t pattern[] = L"foobar"; - bool result = StringHelpers::EndsWith(string, pattern); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, EndsWith_WStringPathAndPattern_ReturnsTrue) - { - const wchar_t string[] = L"foobar"; - const wchar_t pattern[] = L"bar"; - bool result = StringHelpers::EndsWith(string, pattern); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, EndsWith_WStringPathCapitalized_ReturnsFalse) - { - const wchar_t string[] = L"FOOBAR"; - const wchar_t pattern[] = L"bar"; - bool result = StringHelpers::EndsWith(string, pattern); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, EndsWith_PatternWStringCapitalized_ReturnsFalse) - { - const wchar_t string[] = L"foobar"; - const wchar_t pattern[] = L"BAR"; - bool result = StringHelpers::EndsWith(string, pattern); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, EndsWith_WStringPathAndNoMatchingPattern_ReturnsFalse) - { - const wchar_t string[] = L"foo"; - const wchar_t pattern[] = L"bar"; - bool result = StringHelpers::EndsWithIgnoreCase(string, pattern); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, EndsWithIgnoreCase_StringPathWithLongerPattern_ReturnsFalse) - { - const char* string = "foo"; - const char* pattern = "foobar"; - bool result = StringHelpers::EndsWithIgnoreCase(string, pattern); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, EndsWithIgnoreCase_StringPathAndPattern_ReturnsTrue) - { - const char* string = "foobar"; - const char* pattern = "bar"; - bool result = StringHelpers::EndsWithIgnoreCase(string, pattern); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, EndsWithIgnoreCase_StringPathCapitalized_ReturnsTrue) - { - const char* string = "FOOBAR"; - const char* pattern = "bar"; - bool result = StringHelpers::EndsWithIgnoreCase(string, pattern); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, EndsWithIgnoreCase_PatternStringCapitalized_ReturnsTrue) - { - const char* string = "foobar"; - const char* pattern = "BAR"; - bool result = StringHelpers::EndsWithIgnoreCase(string, pattern); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, EndsWithIgnoreCase_StringPathAndNoMatchingPattern_ReturnsFalse) - { - const char* string = "foo"; - const char* pattern = "bar"; - bool result = StringHelpers::EndsWithIgnoreCase(string, pattern); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, EndsWithIgnoreCase_WStringPathWithLongerPattern_ReturnsFalse) - { - const wchar_t string[] = L"foo"; - const wchar_t pattern[] = L"foobar"; - bool result = StringHelpers::EndsWithIgnoreCase(string, pattern); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, EndsWithIgnoreCase_WStringPathAndPattern_ReturnsTrue) - { - const wchar_t string[] = L"foobar"; - const wchar_t pattern[] = L"bar"; - bool result = StringHelpers::EndsWithIgnoreCase(string, pattern); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, EndsWithIgnoreCase_WStringPathCapitalized_ReturnsTrue) - { - const wchar_t string[] = L"FOOBAR"; - const wchar_t pattern[] = L"bar"; - bool result = StringHelpers::EndsWithIgnoreCase(string, pattern); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, EndsWithIgnoreCase_PatternWStringCapitalized_ReturnsTrue) - { - const wchar_t string[] = L"foobar"; - const wchar_t pattern[] = L"BAR"; - bool result = StringHelpers::EndsWithIgnoreCase(string, pattern); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, EndsWithIgnoreCase_WStringPathAndNoMatchingPattern_ReturnsFalse) - { - const wchar_t string[] = L"foo"; - const wchar_t pattern[] = L"bar"; - bool result = StringHelpers::EndsWithIgnoreCase(string, pattern); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, Contains_StringPathWithLongerPattern_ReturnsFalse) - { - const char* string = "foo"; - const char* pattern = "barbar"; - bool result = StringHelpers::Contains(string, pattern); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, Contains_StringPathAndPattern_ReturnsTrue) - { - const char* string = "foobarfoo"; - const char* pattern = "bar"; - bool result = StringHelpers::Contains(string, pattern); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, Contains_PatternStringCapitalized_ReturnsFalse) - { - const char* string = "foobarfoo"; - const char* pattern = "BAR"; - bool result = StringHelpers::Contains(string, pattern); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, Contains_StringPathCapitalized_ReturnsFalse) - { - const char* string = "FOOBARFOO"; - const char* pattern = "bar"; - bool result = StringHelpers::Contains(string, pattern); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, Contains_StringPathNoMatchingPattern_ReturnsFalse) - { - const char* string = "foofoofoo"; - const char* pattern = "bar"; - bool result = StringHelpers::Contains(string, pattern); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, Contains_WStringPathWithLongerPattern_ReturnsFalse) - { - const wchar_t string[] = L"foo"; - const wchar_t pattern[] = L"barbar"; - bool result = StringHelpers::Contains(string, pattern); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, Contains_WStringPathAndPattern_ReturnsTrue) - { - const wchar_t string[] = L"foobarfoo"; - const wchar_t pattern[] = L"bar"; - bool result = StringHelpers::Contains(string, pattern); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, Contains_PatternWStringCapitalized_ReturnsFalse) - { - const wchar_t string[] = L"foobarfoo"; - const wchar_t pattern[] = L"BAR"; - bool result = StringHelpers::Contains(string, pattern); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, Contains_WStringPathCapitalized_ReturnsFalse) - { - const wchar_t string[] = L"FOOBARFOO"; - const wchar_t pattern[] = L"bar"; - bool result = StringHelpers::Contains(string, pattern); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, Contains_WStringPathNoMatchingPattern_ReturnsFalse) - { - const wchar_t string[] = L"foofoofoo"; - const wchar_t pattern[] = L"bar"; - bool result = StringHelpers::Contains(string, pattern); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, ContainsIgnoreCase_StringPathWithLongerPattern_ReturnsFalse) - { - const char* string = "foo"; - const char* pattern = "barbar"; - bool result = StringHelpers::ContainsIgnoreCase(string, pattern); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, ContainsIgnoreCase_StringPathAndPattern_ReturnsTrue) - { - const char* string = "foobarfoo"; - const char* pattern = "bar"; - bool result = StringHelpers::ContainsIgnoreCase(string, pattern); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, ContainsIgnoreCase_PatternStringCapitalized_ReturnsTrue) - { - const char* string = "foobarfoo"; - const char* pattern = "BAR"; - bool result = StringHelpers::ContainsIgnoreCase(string, pattern); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, ContainsIgnoreCase_StringPathCapitalized_ReturnsTrue) - { - const char* string = "FOOBARFOO"; - const char* pattern = "bar"; - bool result = StringHelpers::ContainsIgnoreCase(string, pattern); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, ContainsIgnoreCase_StringPathNoMatchingPattern_ReturnsFalse) - { - const char* string = "foofoofoo"; - const char* pattern = "bar"; - bool result = StringHelpers::ContainsIgnoreCase(string, pattern); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, ContainsIgnoreCase_WStringPathWithLongerPattern_ReturnsFalse) - { - const wchar_t string[] = L"foo"; - const wchar_t pattern[] = L"barbar"; - bool result = StringHelpers::ContainsIgnoreCase(string, pattern); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, ContainsIgnoreCase_WStringPathAndPattern_ReturnsTrue) - { - const wchar_t string[] = L"foobarfoo"; - const wchar_t pattern[] = L"bar"; - bool result = StringHelpers::ContainsIgnoreCase(string, pattern); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, ContainsIgnoreCase_WStringPathAndPattern2_ReturnsTrue) - { - const wchar_t string[] = L"foobfobaro"; - const wchar_t pattern[] = L"bar"; - bool result = StringHelpers::ContainsIgnoreCase(string, pattern); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, ContainsIgnoreCase_PatternWStringCapitalized_ReturnsTrue) - { - const wchar_t string[] = L"foobarfoo"; - const wchar_t pattern[] = L"BAR"; - bool result = StringHelpers::ContainsIgnoreCase(string, pattern); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, ContainsIgnoreCase_WStringPathCapitalized_ReturnsTrue) - { - const wchar_t string[] = L"FOOBARFOO"; - const wchar_t pattern[] = L"bar"; - bool result = StringHelpers::ContainsIgnoreCase(string, pattern); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, ContainsIgnoreCase_WStringPathNoMatchingPattern_ReturnsFalse) - { - const wchar_t string[] = L"foofoofoo"; - const wchar_t pattern[] = L"bar"; - bool result = StringHelpers::ContainsIgnoreCase(string, pattern); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, MatchesWildcards_StringMatchingPattern_ReturnsTrue) - { - const char* string = "foo"; - const char* wildcard = "f*o"; - bool result = StringHelpers::MatchesWildcards(string, wildcard); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, MatchesWildcards_PatternStringCapitalized_ReturnsFalse) - { - const char* string = "foo"; - const char* wildcard = "F*O"; - bool result = StringHelpers::MatchesWildcards(string, wildcard); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, MatchesWildcards_StringCapitalized_ReturnsFalse) - { - const char* string = "FOO"; - const char* wildcard = "f*o"; - bool result = StringHelpers::MatchesWildcards(string, wildcard); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, MatchesWildcards_StringNoMatchingPatternWithAsterisk_ReturnsFalse) - { - const char* string = "foo"; - const char* wildcard = "f*r"; - bool result = StringHelpers::MatchesWildcards(string, wildcard); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, MatchesWildcards_StringNoMatchingPattern_ReturnsFalse) - { - const char* string = "foobar"; - const char* wildcard = "foo"; - bool result = StringHelpers::MatchesWildcards(string, wildcard); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, MatchesWildcards_WStringMatchingPattern_ReturnsTrue) - { - const wchar_t string[] = L"foo"; - const wchar_t wildcard[] = L"f*o"; - bool result = StringHelpers::MatchesWildcards(string, wildcard); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, MatchesWildcards_WPatternStringCapitalized_ReturnsFalse) - { - const wchar_t string[] = L"foo"; - const wchar_t wildcard[] = L"F*O"; - bool result = StringHelpers::MatchesWildcards(string, wildcard); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, MatchesWildcards_WStringCapitalized_ReturnsFalse) - { - const wchar_t string[] = L"FOO"; - const wchar_t wildcard[] = L"f*o"; - bool result = StringHelpers::MatchesWildcards(string, wildcard); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, MatchesWildcards_WStringNoMatchingPatternWithAsterisk_ReturnsFalse) - { - const wchar_t string[] = L"foo"; - const wchar_t wildcard[] = L"f*r"; - bool result = StringHelpers::MatchesWildcards(string, wildcard); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, MatchesWildcards_WStringNoMatchingPattern_ReturnsFalse) - { - const wchar_t string[] = L"foobar"; - const wchar_t wildcard[] = L"foo"; - bool result = StringHelpers::MatchesWildcards(string, wildcard); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, MatchesWildcardsIgnoreCase_StringMatchingPattern_ReturnsTrue) - { - const char* string = "foo"; - const char* wildcard = "f*o"; - bool result = StringHelpers::MatchesWildcardsIgnoreCase(string, wildcard); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, MatchesWildcardsIgnoreCase_PatternStringCapitalized_ReturnsTrue) - { - const char* string = "foo"; - const char* wildcard = "F*O"; - bool result = StringHelpers::MatchesWildcardsIgnoreCase(string, wildcard); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, MatchesWildcardsIgnoreCase_StringCapitalized_ReturnsTrue) - { - const char* string = "FOO"; - const char* wildcard = "f*o"; - bool result = StringHelpers::MatchesWildcardsIgnoreCase(string, wildcard); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, MatchesWildcardsIgnoreCase_StringNoMatchingPatternWithAsterisk_ReturnsFalse) - { - const char* string = "foo"; - const char* wildcard = "f*r"; - bool result = StringHelpers::MatchesWildcardsIgnoreCase(string, wildcard); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, MatchesWildcardsIgnoreCase_StringNoMatchingPattern_ReturnsFalse) - { - const char* string = "foobar"; - const char* wildcard = "foo"; - bool result = StringHelpers::MatchesWildcardsIgnoreCase(string, wildcard); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, MatchesWildcardsIgnoreCase_WStringMatchingPattern_ReturnsTrue) - { - const wchar_t string[] = L"foo"; - const wchar_t wildcard[] = L"f*o"; - bool result = StringHelpers::MatchesWildcardsIgnoreCase(string, wildcard); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, MatchesWildcardsIgnoreCase_PatternWStringCapitalized_ReturnsTrue) - { - const wchar_t string[] = L"foo"; - const wchar_t wildcard[] = L"F*O"; - bool result = StringHelpers::MatchesWildcardsIgnoreCase(string, wildcard); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, MatchesWildcardsIgnoreCase_WStringCapitalized_ReturnsTrue) - { - const wchar_t string[] = L"FOO"; - const wchar_t wildcard[] = L"f*o"; - bool result = StringHelpers::MatchesWildcardsIgnoreCase(string, wildcard); - EXPECT_TRUE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, MatchesWildcardsIgnoreCase_WStringNoMatchingPatternWithAsterisk_ReturnsFalse) - { - const wchar_t string[] = L"foo"; - const wchar_t wildcard[] = L"f*r"; - bool result = StringHelpers::MatchesWildcardsIgnoreCase(string, wildcard); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, MatchesWildcardsIgnoreCase_WStringNoMatchingPattern_ReturnsFalse) - { - const wchar_t string[] = L"foobar"; - const wchar_t wildcard[] = L"foo"; - bool result = StringHelpers::MatchesWildcardsIgnoreCase(string, wildcard); - EXPECT_FALSE(result); - } - - TEST_F(CryCommonToolsStringHelpersTest, TrimLeft_StringWithoutReturnOrTab_ReturnsString) - { - const char* stringInput = "foo"; - string result = StringHelpers::TrimLeft(stringInput); - EXPECT_STREQ(stringInput, result); - } - - TEST_F(CryCommonToolsStringHelpersTest, TrimRight_StringWithoutReturnOrTab_ReturnsString) - { - const char* stringInput = "foo"; - string result = StringHelpers::TrimRight(stringInput); - EXPECT_STREQ(stringInput, result); - } - - TEST_F(CryCommonToolsStringHelpersTest, MakeLowerCase_UpperCaseString_ReturnsLowerCaseString) - { - const char* stringInput = "FOO"; - string result = StringHelpers::MakeLowerCase(stringInput); - EXPECT_STREQ("foo", result); - } - - TEST_F(CryCommonToolsStringHelpersTest, MakeLowerCase_UpperCaseWString_ReturnsLowerCaseString) - { - const wchar_t stringInput[] = L"FOO"; - const wchar_t expectedString[] = L"foo"; - wstring result = StringHelpers::MakeLowerCase(stringInput); - EXPECT_TRUE(result == expectedString); - } - - TEST_F(CryCommonToolsStringHelpersTest, MakeUpperCase_LowerCaseString_ReturnsUpperCaseString) - { - const char* stringInput = "foo"; - string result = StringHelpers::MakeUpperCase(stringInput); - EXPECT_STREQ("FOO", result); - } - - TEST_F(CryCommonToolsStringHelpersTest, MakeUpperCase_LowerCaseWString_ReturnsUpperCaseString) - { - const wchar_t stringInput[] = L"foo"; - const wchar_t expectedString[] = L"FOO"; - wstring result = StringHelpers::MakeUpperCase(stringInput); - EXPECT_TRUE(result == expectedString); - } - - TEST_F(CryCommonToolsStringHelpersTest, Replace_CharacterToReplace_ReturnsStringWithReplacedCharacters) - { - const char* stringInput = "foo"; - char oldChar = 'o'; - char newChar = 'i'; - string result = StringHelpers::Replace(stringInput, oldChar, newChar); - EXPECT_STREQ("fii", result); - } - - TEST_F(CryCommonToolsStringHelpersTest, Replace_CharacterToReplace_ReturnsWStringWithReplacedCharacters) - { - const wchar_t stringInput[] = L"foo"; - wchar_t oldChar = 'o'; - wchar_t newChar = 'i'; - const wchar_t expectedString[] = L"fii"; - wstring result = StringHelpers::Replace(stringInput, oldChar, newChar); - EXPECT_TRUE(result == expectedString); - } - - TEST_F(CryCommonToolsStringHelpersTest, Replace_CharacterToReplaceNotInString_ReturnsOriginalString) - { - const char* stringInput = "foo"; - char oldChar = 'a'; - char newChar = 'i'; - string result = StringHelpers::Replace(stringInput, oldChar, newChar); - EXPECT_STREQ(stringInput, result); - } - - TEST_F(CryCommonToolsStringHelpersTest, Replace_CharacterToReplaceNotInWString_ReturnsOriginalWString) - { - const wchar_t stringInput[] = L"foo"; - wchar_t oldChar = 'a'; - wchar_t newChar = 'i'; - wstring result = StringHelpers::Replace(stringInput, oldChar, newChar); - EXPECT_TRUE(result == stringInput); - } -} diff --git a/Code/Tools/CryCommonTools/WeightFilterSet.cpp b/Code/Tools/CryCommonTools/WeightFilterSet.cpp deleted file mode 100644 index dfc5ff24d0..0000000000 --- a/Code/Tools/CryCommonTools/WeightFilterSet.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include -#include // assert() -#include "WeightFilterSet.h" // CWeightFilterSet - - - -void CWeightFilterSet::FreeData() -{ - m_FilterKernelBlock.FreeData(); -} - - -bool CWeightFilterSet::Create(const unsigned long indwSideLength, const CSummedAreaFilterKernel& inFilter, const float infR) -{ - assert(indwSideLength >= 1); - - FreeData(); - - // 32 Baustelle - inFilter.CreateWeightFilterBlock(m_FilterKernelBlock, 1, infR * indwSideLength); - return(true); -} - diff --git a/Code/Tools/CryCommonTools/WeightFilterSet.h b/Code/Tools/CryCommonTools/WeightFilterSet.h deleted file mode 100644 index 16c8c79acd..0000000000 --- a/Code/Tools/CryCommonTools/WeightFilterSet.h +++ /dev/null @@ -1,96 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#pragma once -#ifndef CRYINCLUDE_CRYCOMMONTOOLS_WEIGHTFILTERSET_H -#define CRYINCLUDE_CRYCOMMONTOOLS_WEIGHTFILTERSET_H - - -#include "SimpleBitmap.h" // SimpleBitmap<> -#include // STL vector<> -#include "SummedAreaFilterKernel.h" // CSummedAreaFilterKernel - -class CWeightFilterSet -{ -public: - - //! /param indwSideLength [1,..[ e.g. 3 for 3x3 block - bool Create(const unsigned long indwSideLength, const CSummedAreaFilterKernel& inFilter, const float infR); - - //! - void FreeData(); - - //! optimizable - //! weight is 1.0 - //! /param iniX x position in inoutDest - //! /param iniY y position in inoutDest - //! /param TInputImage typically CSimpleBitmap - //! /return weight - template - float GetBlockWithFilter(const TInputImage& inSrc, const int iniX, const int iniY, TElement& outResult) - { - float fWeightSum = 0.0f; - CSimpleBitmap& rBitmap = m_FilterKernelBlock; - - int W = (int)rBitmap.GetWidth(); - int H = (int)rBitmap.GetHeight(); - - int iSrcW = (int)inSrc.GetWidth(); - int iSrcH = (int)inSrc.GetHeight(); - - float* pfWeights = rBitmap.GetPointer(0, 0); - - for (int y = 0; y < H; y++) - { - int iDestY = y + iniY - H / 2; - - // optimizable (don't use the bottom border) - // if(iDestY==iSrcH){ pfWeights+=H;continue; } - - for (int x = 0; x < W; x++, pfWeights++) - { - int iDestX = x + iniX - W / 2; - - // optimizable (don't use the right border) - // if(iDestX==iSrcW) - // continue; - - TElement Value; - - // if(inSrc.Get(iDestX,iDestY,Value)) - if (inSrc.Get((iDestX + iSrcW * 2) % iSrcW, (iDestY + iSrcH * 2) % iSrcH, Value)) // tiled - { - float fWeight = *pfWeights; - - outResult += Value * fWeight; - fWeightSum += fWeight; - } - } - } - - return fWeightSum; - } - - int GetBorderSize() - { - int W = (int)m_FilterKernelBlock.GetWidth(); - - return (W - 1) / 2; - } - -private: // ------------------------------------------------------------- - - CSimpleBitmap m_FilterKernelBlock; //!< weight = 1 -}; - -#endif // CRYINCLUDE_CRYCOMMONTOOLS_WEIGHTFILTERSET_H diff --git a/Code/Tools/CryCommonTools/XMLPakFileSink.cpp b/Code/Tools/CryCommonTools/XMLPakFileSink.cpp deleted file mode 100644 index 9a9590687f..0000000000 --- a/Code/Tools/CryCommonTools/XMLPakFileSink.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include -#include "XMLPakFileSink.h" -#include "StringHelpers.h" - -XMLPakFileSink::XMLPakFileSink(IPakSystem* pakSystem, const string& archivePath, const string& filePath) - : pakSystem(pakSystem) - , filePath(filePath) -{ - archive = pakSystem->OpenArchive(archivePath.c_str()); -} - -XMLPakFileSink::~XMLPakFileSink() -{ - if (archive && pakSystem) - { - SYSTEMTIME st; - GetSystemTime(&st); - - FILETIME ft; - ZeroStruct(ft); - const BOOL ok = SystemTimeToFileTime(&st, &ft); - - LARGE_INTEGER lt; - lt.HighPart = ft.dwHighDateTime; - lt.LowPart = ft.dwLowDateTime; - - const __int64 modTime = lt.QuadPart; - ; - - pakSystem->AddToArchive(archive, filePath.c_str(), &data[0], int(data.size()), modTime); - pakSystem->CloseArchive(archive); - } -} - -void XMLPakFileSink::Write(const char* text) -{ - string asciiText = text; - int len = int(asciiText.size()); - int start = int(data.size()); - data.resize(data.size() + len); - memcpy(&data[start], asciiText.c_str(), len); -} diff --git a/Code/Tools/CryCommonTools/XMLPakFileSink.h b/Code/Tools/CryCommonTools/XMLPakFileSink.h deleted file mode 100644 index 973f9a05ca..0000000000 --- a/Code/Tools/CryCommonTools/XMLPakFileSink.h +++ /dev/null @@ -1,39 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYCOMMONTOOLS_XMLPAKFILESINK_H -#define CRYINCLUDE_CRYCOMMONTOOLS_XMLPAKFILESINK_H -#pragma once - - -#include "XMLWriter.h" -#include "IPakSystem.h" - -class XMLPakFileSink - : public IXMLSink -{ -public: - XMLPakFileSink(IPakSystem* pakSystem, const string& archivePath, const string& filePath); - ~XMLPakFileSink(); - - // IXMLSink - virtual void Write(const char* text); - -private: - IPakSystem* pakSystem; - PakSystemArchive* archive; - string filePath; - std::vector data; -}; - -#endif // CRYINCLUDE_CRYCOMMONTOOLS_XMLPAKFILESINK_H diff --git a/Code/Tools/CryCommonTools/XMLWriter.cpp b/Code/Tools/CryCommonTools/XMLWriter.cpp deleted file mode 100644 index bfaf9df429..0000000000 --- a/Code/Tools/CryCommonTools/XMLWriter.cpp +++ /dev/null @@ -1,261 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include -#include "XMLWriter.h" -#include "StringHelpers.h" -#include - -XMLWriter::XMLWriter(IXMLSink* sink) -{ - m_indentationSize = -1; - m_sink = sink; - - WriteText("\n"); -} - -void XMLWriter::BeginElement(const string& name) -{ - // Write the indentation. - if (m_newLine) - { - for (int i = 0; i < m_indentationSize; ++i) - { - WriteText(" "); - } - } - - WriteText("<%s", name.c_str()); - m_newLine = false; -} - -void XMLWriter::EndElement(const string& name) -{ - // Write the indentation. - if (m_newLine) - { - for (int i = 0; i < m_indentationSize; ++i) - { - WriteText(" "); - } - } - - WriteText("\n", name.c_str()); - m_newLine = true; -} - -void XMLWriter::CloseElement(const string& name, bool newLine) -{ - if (newLine) - { - WriteText(">\n"); - } - else - { - WriteText(">"); - } - m_newLine = newLine; -} - -void XMLWriter::CloseLeafElement(const string& name) -{ - WriteText(" />\n"); - m_newLine = true; -} - -void XMLWriter::IncreaseIndentation() -{ - ++m_indentationSize; -} - -void XMLWriter::DecreaseIndentation() -{ - --m_indentationSize; -} - -void XMLWriter::WriteAttribute(const string& name, const string& value) -{ - WriteText(" %s=\"%s\"", name.c_str(), value.c_str()); -} - -void XMLWriter::SerializeAttribute(char* buffer, size_t bufferSize, const string& value) -{ - // TODO: Escape string. - strcpy_s(buffer, bufferSize, value.c_str()); -} - -void XMLWriter::SerializeAttribute(char* buffer, size_t bufferSize, float value) -{ - sprintf_s(buffer, bufferSize, "%.10e", value); -} - -void XMLWriter::SerializeAttribute(char* buffer, size_t bufferSize, int value) -{ - sprintf_s(buffer, bufferSize, "%d", value); -} - -void XMLWriter::SerializeArrayElement(char* buffer, size_t bufferSize, float value) -{ - sprintf_s(buffer, bufferSize, "%.10e", value); -} - -void XMLWriter::SerializeArrayElement(char* buffer, size_t bufferSize, const string& value) -{ - strcpy(buffer, value.c_str()); -} - -void XMLWriter::SerializeArrayElement(char* buffer, size_t bufferSize, int value) -{ - sprintf_s(buffer, bufferSize, "%d", value); -} - -void XMLWriter::WriteContent(const string& text) -{ - WriteText("%s", text.c_str()); -} - -void XMLWriter::WriteContentLine(const string& text) -{ - // Write the indentation. - if (m_newLine) - { - for (int i = 0; i < m_indentationSize; ++i) - { - WriteText(" "); - } - } - - WriteText("%s\n", text.c_str()); - m_newLine = true; -} - -void XMLWriter::WriteText(const char* format, ...) -{ - va_list args; - va_start(args, format); - char buffer[40000]; - azvsnprintf(buffer, sizeof(buffer), format, args); - m_sink->Write(buffer); - va_end(args); -} - -XMLWriter::Element::Element(XMLWriter& writer, const string& name, bool output) - : m_writer(writer) - , m_name(name) - , m_output(output) - , isParent(false) -{ - if (!m_writer.m_elements.empty()) - { - Element* parent = m_writer.m_elements.back(); - if (!parent->isParent) - { - parent->isParent = true; - if (parent->m_output) - { - m_writer.CloseElement(m_name, true); - } - } - } - m_writer.m_elements.push_back(this); - if (m_output) - { - m_writer.IncreaseIndentation(); - } - if (m_output) - { - m_writer.BeginElement(m_name); - } -} - -XMLWriter::Element::~Element() -{ - if (m_output) - { - if (isParent) - { - m_writer.EndElement(m_name); - } - else - { - m_writer.CloseLeafElement(m_name); - } - } - m_writer.m_elements.pop_back(); - if (m_output) - { - m_writer.DecreaseIndentation(); - } -} - -void XMLWriter::Element::Child(const string& name, const string& value) -{ - Element child(m_writer, name); - child.Content(value); -} - -void XMLWriter::Element::Content(const string& text) -{ - if (m_output) - { - assert(!isParent); - if (!isParent) - { - isParent = true; - m_writer.CloseElement(m_name, false); - } - m_writer.WriteContent(text); - } -} - -void XMLWriter::Element::ContentLine(const string& text) -{ - if (!isParent) - { - isParent = true; - if (m_output) - { - m_writer.CloseElement(m_name, true); - } - } - if (m_output) - { - m_writer.WriteContentLine(text); - } -} - -XMLFileSink::XMLFileSink(const string& filename) -{ - m_file = std::fopen(filename.c_str(), "w"); - if (!m_file) - { - throw OpenFailedError("Unable to open file."); - } -} - -XMLFileSink::~XMLFileSink() -{ - if (m_file) - { - fclose(m_file); - } -} - -void XMLFileSink::Write(const char* text) -{ - if (m_file) - { - string asciiText = StringHelpers::ConvertString(text); - fwrite(asciiText.c_str(), 1, asciiText.size(), m_file); - } -} diff --git a/Code/Tools/CryCommonTools/XMLWriter.h b/Code/Tools/CryCommonTools/XMLWriter.h deleted file mode 100644 index d98b9f3d56..0000000000 --- a/Code/Tools/CryCommonTools/XMLWriter.h +++ /dev/null @@ -1,185 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYCOMMONTOOLS_XMLWRITER_H -#define CRYINCLUDE_CRYCOMMONTOOLS_XMLWRITER_H -#pragma once - - -#include "Exceptions.h" - -#include -#include -#include - -class IXMLSink -{ -public: - // Define an exception type to throw when file opening fails. - struct OpenFailedErrorTag {}; - typedef Exception OpenFailedError; - - virtual void Write(const char* text) = 0; -}; - -class XMLFileSink - : public IXMLSink -{ -public: - XMLFileSink(const string& name); - ~XMLFileSink(); - - virtual void Write(const char* text); - -private: - FILE* m_file; -}; - -class XMLWriter -{ -public: - XMLWriter(IXMLSink* sink); - - class Element - { - public: - Element(XMLWriter& writer, const string& name, bool output = true); - ~Element(); - - template - void Attribute(const string& name, const T& value); - void Child(const string& name, const string& value); - void Content(const string& text); - void ContentLine(const string& text); - template - void ContentArrayElement(const T& value); - void ContentArrayFloat24(const float floatBuffer[24], const int entryCount); - - void WriteDirectText(const char* text) - { - if (!isParent) - { - isParent = true; - if (m_output) - { - m_writer.CloseElement(m_name, false); - } - } - m_writer.WriteDirectText(text); - } - - private: - XMLWriter& m_writer; - string m_name; - bool isParent; - bool m_output; - }; - - void WriteDirectText(const char* text) - { - m_sink->Write(text); - } - -private: - void IncreaseIndentation(); - void DecreaseIndentation(); - - void BeginElement(const string& name); - void EndElement(const string& name); - void CloseElement(const string& name, bool newLine); - void CloseLeafElement(const string& name); - - void WriteAttribute(const string& name, const string& value); - static void SerializeAttribute(char* buffer, size_t bufferSize, const string& value); - static void SerializeAttribute(char* buffer, size_t bufferSize, float value); - static void SerializeAttribute(char* buffer, size_t bufferSize, int value); - static void SerializeArrayElement(char* buffer, size_t bufferSize, float value); - static void SerializeArrayElement(char* buffer, size_t bufferSize, const string& value); - static void SerializeArrayElement(char* buffer, size_t bufferSize, int value); - void WriteContent(const string& text); - void WriteContentLine(const string& text); - - void WriteText(const char* format, ...); - - IXMLSink* m_sink; - int m_indentationSize; - - std::vector m_elements; - bool m_newLine; -}; - -template -void XMLWriter::Element::Attribute(const string& name, const T& value) -{ - assert(!isParent); - char buffer[1024]; - XMLWriter::SerializeAttribute(buffer, sizeof(buffer), value); - if (m_output) - { - m_writer.WriteAttribute(name, buffer); - } -} - -template -void XMLWriter::Element::ContentArrayElement(const T& value) -{ - if (!m_output) - { - return; - } - - if (!isParent) - { - isParent = true; - m_writer.CloseElement(m_name, false); - } - - char buffer[1024] = {' ', 0}; - XMLWriter::SerializeArrayElement(buffer + 1, sizeof(buffer) - 1, value); - - m_writer.WriteDirectText(buffer); -} - -inline void XMLWriter::Element::ContentArrayFloat24(const float floatBuffer[24], const int entryCount) -{ - if (!m_output) - { - return; - } - if (!isParent) - { - isParent = true; - m_writer.CloseElement(m_name, false); - } - - char buffer[2048]; - if (entryCount == 24) - { - sprintf_s(buffer, " %.10e %.10e %.10e %.10e %.10e %.10e %.10e %.10e %.10e %.10e %.10e %.10e %.10e %.10e %.10e %.10e %.10e %.10e %.10e %.10e %.10e %.10e %.10e %.10e", - floatBuffer[0], floatBuffer[1], floatBuffer[2], floatBuffer[3], floatBuffer[4], floatBuffer[5], floatBuffer[6], floatBuffer[7], - floatBuffer[8], floatBuffer[9], floatBuffer[10], floatBuffer[11], floatBuffer[12], floatBuffer[13], floatBuffer[14], floatBuffer[15], - floatBuffer[16], floatBuffer[17], floatBuffer[18], floatBuffer[19], floatBuffer[20], floatBuffer[21], floatBuffer[22], floatBuffer[23]); - m_writer.WriteDirectText(buffer); - } - else - { - for (int i = 0; i < entryCount; i++) - { - char buffer[1024]; - sprintf_s(buffer, " %.10e", floatBuffer[i]); - m_writer.WriteDirectText(buffer); - } - } -} - -#endif // CRYINCLUDE_CRYCOMMONTOOLS_XMLWRITER_H diff --git a/Code/Tools/CryCommonTools/ZipDir/ZipDir.h b/Code/Tools/CryCommonTools/ZipDir/ZipDir.h deleted file mode 100644 index c9954ce5dc..0000000000 --- a/Code/Tools/CryCommonTools/ZipDir/ZipDir.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYCOMMONTOOLS_ZIPDIR_ZIPDIR_H -#define CRYINCLUDE_CRYCOMMONTOOLS_ZIPDIR_ZIPDIR_H -#pragma once - -#include "smartptr.h" -#include "ZipFileFormat.h" -#include "zipdirstructures.h" -#include "smartptr.h" -#include "ZipDirTree.h" -#include "ZipDirList.h" -#include "ZipDirCache.h" -#include "ZipDirCacheRW.h" -#include "ZipDirCacheFactory.h" -#include "ZipDirFind.h" -#include "ZipDirFindRW.h" - -#endif // CRYINCLUDE_CRYCOMMONTOOLS_ZIPDIR_ZIPDIR_H diff --git a/Code/Tools/CryCommonTools/ZipDir/ZipDirCache.cpp b/Code/Tools/CryCommonTools/ZipDir/ZipDirCache.cpp deleted file mode 100644 index 1f5d4a9286..0000000000 --- a/Code/Tools/CryCommonTools/ZipDir/ZipDirCache.cpp +++ /dev/null @@ -1,298 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - - -#include -#include "FileUtil.h" -#include "ZipFileFormat.h" -#include "zipdirstructures.h" -#include "ZipDirTree.h" -#include "ZipDirCache.h" -#include "ZipDirFind.h" -#include "ZipDirCacheFactory.h" -#include -#include -#include "PathHelpers.h" -#include - -using namespace ZipFile; - -// initializes the instance structure -void ZipDir::Cache::Construct(FILE* fNew, size_t nDataSizeIn, const EncryptionKey& key) -{ - m_nRefCount = 0; - m_pFile = fNew; - m_nDataSize = nDataSizeIn; - m_nZipPathOffset = nDataSizeIn; - m_bEncryptHeaders = false; - m_encryptionKey = key; -} - -// self-destruct when ref count drops to 0 -void ZipDir::Cache::Delete() -{ - if (m_pFile) - { - fclose (m_pFile); - } - free(this); -} - -// looks for the given file record in the Central Directory. If there's none, returns NULL. -// if there is some, returns the pointer to it. -// the Path must be the relative path to the file inside the Zip -// if the file handle is passed, it will be used to find the file data offset, if one hasn't been initialized yet -ZipDir::FileEntry* ZipDir::Cache::FindFile (const char* szPath, [[maybe_unused]] bool bRefresh) -{ - ZipDir::FindFile fd (this); - if (!fd.FindExact(szPath)) - { - assert (!fd.GetFileEntry()); - return NULL; - } - assert (fd.GetFileEntry()); - return fd.GetFileEntry(); -} - -// loads the given file into the pCompressed buffer (the actual compressed data) -// if the pUncompressed buffer is supplied, uncompresses the data there -// buffers must have enough memory allocated, according to the info in the FileEntry -// NOTE: there's no need to decompress if the method is 0 (store) -// returns 0 if successful or error code if couldn't do something -ZipDir::ErrorEnum ZipDir::Cache::ReadFile (FileEntry* pFileEntry, void* pCompressed, void* pUncompressed) -{ - if (!pFileEntry) - { - return ZD_ERROR_INVALID_CALL; - } - - if (pFileEntry->desc.lSizeUncompressed == 0) - { - assert (pFileEntry->desc.lSizeCompressed == 0); - return ZD_ERROR_SUCCESS; - } - - assert (pFileEntry->desc.lSizeCompressed > 0); - - ErrorEnum nError = Refresh(pFileEntry); - if (nError != ZD_ERROR_SUCCESS) - { - return nError; - } - - if (AZ_TRAIT_CRYCOMMONTOOLS_FSEEK(m_pFile, pFileEntry->nFileDataOffset, SEEK_SET)) - { - return ZD_ERROR_IO_FAILED; - } - - SmartPtr pBufferDestroyer; - - void* pBuffer = pCompressed; // the buffer where the compressed data will go - - if (pFileEntry->nMethod == 0 && pUncompressed) - { - // we can directly read into the uncompress buffer - pBuffer = pUncompressed; - } - - if (!pBuffer) - { - if (!pUncompressed) - { - // what's the sense of it - no buffers at all? - return ZD_ERROR_INVALID_CALL; - } - - pBuffer = malloc(pFileEntry->desc.lSizeCompressed); - pBufferDestroyer.Attach(pBuffer); // we want it auto-freed once we return - } - - - if (fread (pBuffer, pFileEntry->desc.lSizeCompressed, 1, m_pFile) != 1) - { - return ZD_ERROR_IO_FAILED; - } - - if (pFileEntry->nMethod == METHOD_DEFLATE_AND_ENCRYPT) - { - ZipDir::Decrypt((char*)pBuffer, pFileEntry->desc.lSizeCompressed, m_encryptionKey); - } - - // if there's a buffer for uncompressed data, uncompress it to that buffer - if (pUncompressed) - { - if (pFileEntry->nMethod == 0) - { - assert (pBuffer == pUncompressed); - //assert (pFileEntry->desc.lSizeCompressed == pFileEntry->nSizeUncompressed); - //memcpy (pUncompressed, pBuffer, pFileEntry->desc.lSizeCompressed); - } - else - { - unsigned long nSizeUncompressed = pFileEntry->desc.lSizeUncompressed; - if (Z_OK != ZipRawUncompress(pUncompressed, &nSizeUncompressed, pBuffer, pFileEntry->desc.lSizeCompressed)) - { - return ZD_ERROR_CORRUPTED_DATA; - } - } - } - - return ZD_ERROR_SUCCESS; -} - -// loads and unpacks the file into a newly created buffer (that must be subsequently freed with -// Free()) Returns NULL if failed -void* ZipDir::Cache::AllocAndReadFile (FileEntry* pFileEntry) -{ - if (!pFileEntry) - { - return NULL; - } - - void* pData = malloc(pFileEntry->desc.lSizeUncompressed); - if (pData) - { - if (ZD_ERROR_SUCCESS != ReadFile (pFileEntry, NULL, pData)) - { - free(pData); - pData = NULL; - } - } - return pData; -} - -// frees the memory block that was previously allocated by AllocAndReadFile -void ZipDir::Cache::Free (void* pData) -{ - free(pData); -} - -// refreshes information about the given file entry into this file entry -ZipDir::ErrorEnum ZipDir::Cache::Refresh (FileEntry* pFileEntry) -{ - if (!pFileEntry) - { - return ZD_ERROR_INVALID_CALL; - } - - if (pFileEntry->nFileDataOffset != pFileEntry->INVALID_DATA_OFFSET) - { - return ZD_ERROR_SUCCESS; // the data offset has been successfully read.. - } - - return ZipDir::Refresh(m_pFile, pFileEntry, m_bEncryptHeaders); -} - -////////////////////////////////////////////////////////////////////////// -uint32 ZipDir::Cache::GetFileDataOffset(FileEntry* pFileEntry) -{ - if (pFileEntry->nFileDataOffset == pFileEntry->INVALID_DATA_OFFSET) - { - ZipDir::Refresh (m_pFile, pFileEntry, m_bEncryptHeaders); - } - return pFileEntry->nFileDataOffset; -} - -// returns the size of memory occupied by the instance referred to by this cache -// must be exact, because it's used by CacheRW to reallocate this cache -size_t ZipDir::Cache::GetSize() const -{ - return m_nDataSize + sizeof(Cache) + strlen(GetFilePath()); -} - - -// QUICK check to determine whether the file entry belongs to this object -bool ZipDir::Cache::IsOwnerOf (const FileEntry* pFileEntry) const -{ - // just check whether the pointer is within the memory block of this cache instance - return ((ULONG_PTR)pFileEntry >= (ULONG_PTR)(GetRoot() + 1) - && (ULONG_PTR)pFileEntry <= ((ULONG_PTR)GetRoot()) + m_nDataSize - sizeof(FileEntry)); -} - -bool ZipDir::Cache::UnpakToDisk(const string& destFolder) -{ - return UnpakToDiskInternal(GetRoot(), destFolder); -} - -bool ZipDir::Cache::UnpakToDiskInternal(ZipDir::DirHeader* folder, const string& destFolder) -{ - if (!folder) - { - return false; - } - - if (!FileUtil::EnsureDirectoryExists(destFolder.c_str())) - { - return false; - } - - bool result = true; - for (ZipFile::ushort fileNum = 0; fileNum < folder->numFiles; ++fileNum) - { - ZipDir::FileEntry* fileEntry = folder->GetFileEntry(fileNum); - if (!fileEntry) - { - result = false; - continue; - } - - string filePath = PathHelpers::Join(destFolder, fileEntry->GetName(folder->GetNamePool())); - AZ::IO::SystemFile file; - if (!file.Open(filePath.c_str(), AZ::IO::SystemFile::SF_OPEN_READ_WRITE | AZ::IO::SystemFile::SF_OPEN_CREATE)) - { - result = false; - continue; - } - - if (!fileEntry->desc.lSizeUncompressed) - { - // Nothing to write. Just close the file. - file.Close(); - continue; - } - - AZStd::vector buffer(fileEntry->desc.lSizeUncompressed); - if (ReadFile(fileEntry, nullptr, buffer.data()) == ZD_ERROR_SUCCESS) - { - file.Write(buffer.data(), buffer.size()); - file.Close(); - } - else - { - file.Close(); - AZ::IO::SystemFile::Delete(filePath.c_str()); - result = false; - continue; - } - } - - for (ZipFile::ushort dirNum = 0; dirNum < folder->numDirs; ++dirNum) - { - ZipDir::DirEntry* entry = folder->GetSubdirEntry(dirNum); - if (!entry) - { - result = false; - continue; - } - - string newPath = PathHelpers::Join(destFolder, entry->GetName(folder->GetNamePool())); - if (!UnpakToDiskInternal(entry->GetDirectory(), newPath)) - { - result = false; - continue; - } - } - - return result; -} - diff --git a/Code/Tools/CryCommonTools/ZipDir/ZipDirCache.h b/Code/Tools/CryCommonTools/ZipDir/ZipDirCache.h deleted file mode 100644 index 958c77efc3..0000000000 --- a/Code/Tools/CryCommonTools/ZipDir/ZipDirCache.h +++ /dev/null @@ -1,140 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Declarations of the class used to parse and cache Zipped directory. -// This class is actually an auto-pointer to the instance of the cache, so it can -// be easily passed by value. -// The cache instance contains the optimized for memory usage and fast search tree -// of the files/directories inside the zip; each file has a descriptor with the -// info about where its compressed data lies within the file - -#ifndef CRYINCLUDE_CRYCOMMONTOOLS_ZIPDIR_ZIPDIRCACHE_H -#define CRYINCLUDE_CRYCOMMONTOOLS_ZIPDIR_ZIPDIRCACHE_H -#pragma once - - - -///////////////////////////////////////////////////////////// -// THe Zip Dir uses a special memory layout for keeping the structure of zip file. -// This layout is optimized for small memory footprint (for big zip files) -// and quick binary-search access to the individual files. -// -// The serialized layout consists of a number of directory records. -// Each directory record starts with the DirHeader structure, then -// it has an array of DirEntry structures (sorted by name), -// array of FileEntry structures (sorted by name) and then -// the pool of names, followed by pad bytes to align the whole directory -// record on 4-byte boundray. - -namespace ZipDir -{ - // this is the header of the instance data allocated dynamically - // it contains the FILE* : it owns it and closes upon destruction - struct Cache - { - void AddRef() { ++m_nRefCount; } - void Release() - { - if (--m_nRefCount <= 0) - { - Delete(); - } - } - int NumRefs() const { return m_nRefCount; } - - // looks for the given file record in the Central Directory. If there's none, returns NULL. - // if there is some, returns the pointer to it. - // the Path must be the relative path to the file inside the Zip - // if the file handle is passed, it will be used to find the file data offset, if one hasn't been initialized yet - // if bFull is true, then the full information about the file is returned (the offset to the data may be unknown at this point)- - // if needed, the file is accessed and the information is loaded - FileEntry* FindFile (const char* szPath, bool bFullInfo = false); - - // loads the given file into the pCompressed buffer (the actual compressed data) - // if the pUncompressed buffer is supplied, uncompresses the data there - // buffers must have enough memory allocated, according to the info in the FileEntry - // NOTE: there's no need to decompress if the method is 0 (store) - // returns 0 if successful or error code if couldn't do something - ErrorEnum ReadFile (FileEntry* pFileEntry, void* pCompressed, void* pUncompressed); - - // loads and unpacks the file into a newly created buffer (that must be subsequently freed with - // Free()) Returns NULL if failed - void* AllocAndReadFile (FileEntry* pFileEntry); - - // frees the memory block that was previously allocated by AllocAndReadFile - void Free (void*); - - // refreshes information about the given file entry into this file entry - ErrorEnum Refresh (FileEntry* pFileEntry); - - // Return FileEntity data offset inside zip file. - uint32 GetFileDataOffset(FileEntry* pFileEntry); - - - // returns the root directory record; - // through this directory record, user can traverse the whole tree - DirHeader* GetRoot() const - { - return (DirHeader*)(this + 1); - } - - // returns the size of memory occupied by the instance referred to by this cache - // must be exact, because it's used by CacheRW to reallocate this cache - size_t GetSize() const; - - // QUICK check to determine whether the file entry belongs to this object - bool IsOwnerOf (const FileEntry* pFileEntry) const; - - // returns the string - path to the zip file from which this object was constructed. - // this will be "" if the object was constructed with a factory that wasn't created with FLAGS_MEMORIZE_ZIP_PATH - const char* GetFilePath() const - { - return ((const char*)(this + 1)) + m_nZipPathOffset; - } - - // Unpak the file into a destination folder - bool UnpakToDisk(const string& destFolder); - - friend class CacheFactory; // the factory class creates instances of this class - friend class CacheRW; // the Read-Write 2-way cache can modify this cache directly during write operations - protected: - volatile signed int m_nRefCount; // the reference count - FILE* m_pFile; // the opened file - - // the size of the serialized data following this instance (not including the extra fields after the serialized tree data) - size_t m_nDataSize; - // the offset to the path/name of the zip file relative to (char*)(this+1) pointer in bytes - size_t m_nZipPathOffset; - - // tells if encryption used for zip-file - EncryptionKey m_encryptionKey; - bool m_bEncryptHeaders; - public: - // initializes the instance structure - void Construct(FILE* fNew, size_t nDataSize, const EncryptionKey& key); - void Delete(); - private: - bool ReadCompressedData(char* data, size_t size); - bool UnpakToDiskInternal(ZipDir::DirHeader* dirHeader, const string& destFolder); - - // the constructor/destructor cannot be called at all - everything will go through the factory class - Cache() { m_nRefCount = 0; } - ~Cache(){} - }; - - TYPEDEF_AUTOPTR(Cache); - - typedef Cache_AutoPtr CachePtr; -} - -#endif // CRYINCLUDE_CRYCOMMONTOOLS_ZIPDIR_ZIPDIRCACHE_H diff --git a/Code/Tools/CryCommonTools/ZipDir/ZipDirCacheFactory.cpp b/Code/Tools/CryCommonTools/ZipDir/ZipDirCacheFactory.cpp deleted file mode 100644 index 9d64f60b63..0000000000 --- a/Code/Tools/CryCommonTools/ZipDir/ZipDirCacheFactory.cpp +++ /dev/null @@ -1,804 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include -#include "smartptr.h" -#include "ZipFileFormat.h" -#include "zipdirstructures.h" -#include "ZipDirTree.h" -#include "ZipDirCache.h" -#include "ZipDirCacheRW.h" -#include "ZipDirCacheFactory.h" -#include "ZipDirList.h" -#include - -static uint32 g_defaultEncryptionKey[4] = { 0xc968fb67, 0x8f9b4267, 0x85399e84, 0xf9b99dc4 }; - -ZipDir::CacheFactory::CacheFactory (InitMethodEnum nInitMethod, unsigned nFlags) -{ - m_nCDREndPos = 0; - m_f = NULL; - m_bBuildFileEntryMap = false; // we only need it for validation/debugging - m_bBuildFileEntryTree = true; // we need it to actually build the optimized structure of directories - m_bEncryptedHeaders = false; - - m_nInitMethod = nInitMethod; - m_nFlags = nFlags; -} - -ZipDir::CacheFactory::~CacheFactory() -{ - Clear(); -} - -ZipDir::CachePtr ZipDir::CacheFactory::New (const char* szFile, const uint32 key[4]) -{ - m_encryptionKey = EncryptionKey(g_defaultEncryptionKey); - if (key) - { - m_encryptionKey = EncryptionKey(key); - } - - Clear(); - m_f = nullptr; - azfopen(&m_f, szFile, "rb"); - if (m_f) - { - return MakeCache (szFile); - } - Clear(); - THROW_ZIPDIR_ERROR(ZD_ERROR_IO_FAILED, "Cannot open file in binary mode for reading, probably missing file"); - return 0; - /* - if (!m_f) - THROW_ZIPDIR_ERROR(ZD_ERROR_IO_FAILED,"Cannot open file in binary mode for reading, probably missing file"); - try - { - return MakeCache (szFile); - } - catch(Error) - { - Clear(); - throw; - } - */ -} - - -ZipDir::CacheRWPtr ZipDir::CacheFactory::NewRW(const char* szFileName, size_t fileAlignment, bool encrypted, const uint32* key) -{ - m_encryptionKey = EncryptionKey(g_defaultEncryptionKey); - if (key) - { - m_encryptionKey = EncryptionKey(key); - } - - CacheRWPtr pCache = new CacheRW(encrypted, m_encryptionKey); - - // opens the given zip file and connects to it. Creates a new file if no such file exists - // if successful, returns true. - if (!(m_nFlags & FLAGS_DONT_MEMORIZE_ZIP_PATH)) - { - pCache->m_strFilePath = szFileName; - } - - if (m_nFlags & FLAGS_DONT_COMPACT) - { - pCache->m_nFlags |= CacheRW::FLAGS_DONT_COMPACT; - } - - // first, try to open the file for reading or reading/writing - if (m_nFlags & FLAGS_READ_ONLY) - { - m_f = nullptr; - azfopen(&m_f, szFileName, "rb"); - pCache->m_nFlags |= CacheRW::FLAGS_CDR_DIRTY | CacheRW::FLAGS_READ_ONLY; - - if (!m_f) - { - THROW_ZIPDIR_ERROR(ZD_ERROR_IO_FAILED, "Could not open file in binary mode for reading"); - return 0; - } - } - else - { - m_f = NULL; - if (!(m_nFlags & FLAGS_CREATE_NEW)) - { - m_f = nullptr; - azfopen(&m_f, szFileName, "r+b"); - } - - bool bOpenForWriting = true; - - if (m_f) - { - // get file size - fseek(m_f, 0, SEEK_END); - size_t nFileSize = AZ_TRAIT_CRYCOMMONTOOLS_FTELL(m_f); - fseek(m_f, 0, SEEK_SET); - - if (nFileSize) - { - if (!ReadCacheRW(*pCache)) - { - fclose(m_f); - m_f = NULL; - - THROW_ZIPDIR_ERROR(ZD_ERROR_IO_FAILED, "Could not read archive"); - return 0; - } - bOpenForWriting = false; - } - else - { - // if file has 0 bytes (e.g. crash during saving) we don't want to open it - assert(0); // you can ignore, the system shold handle this gracefully - } - } - - if (bOpenForWriting) - { - m_f = nullptr; - azfopen(&m_f, szFileName, "w+b"); - if (m_f) - { - // there's no such file, but we'll create one. We'll need to write out the CDR here - pCache->m_lCDROffset = 0; - pCache->m_nFlags |= CacheRW::FLAGS_CDR_DIRTY; - } - pCache->m_fileAlignment = fileAlignment; - } - - if (!m_f) - { - THROW_ZIPDIR_ERROR(ZD_ERROR_IO_FAILED, "Could not open file in binary mode for appending (read/write)"); - return 0; - } - } - - - // give the cache the file handle: - pCache->m_pFile = m_f; - // the factory doesn't own it after that - m_f = NULL; - - return pCache; -} - -bool ZipDir::CacheFactory::ReadCacheRW (CacheRW& rwCache) -{ - m_bBuildFileEntryTree = true; - if (!Prepare()) - { - return false; - } - - // since it's open for R/W, we need to know exactly how much space - // we have for each file to use the gaps efficiently - FileEntryList Adjuster (&m_treeFileEntries, m_CDREnd.lCDROffset); - Adjuster.RefreshEOFOffsets(); - - m_treeFileEntries.Swap(rwCache.m_treeDir); - m_CDR_buffer.swap(rwCache.m_CDR_buffer); // CDR Buffer contain actually the string pool for the tree directory. - m_unifiedNameBuffer.swap(rwCache.m_unifiedNameBuffer); // string pool for unified names - - // very important: we need this offset to be able to add to the zip file - rwCache.m_lCDROffset = m_CDREnd.lCDROffset; - - if (m_bEncryptedHeaders != rwCache.m_bEncryptedHeaders) - { - // force to relink and update all headers on close - rwCache.m_nFlags |= ZipDir::CacheRW::FLAGS_UNCOMPACTED; - rwCache.m_bHeadersEncryptedOnClose = rwCache.m_bEncryptedHeaders; - rwCache.m_bEncryptedHeaders = m_bEncryptedHeaders; - } - return true; -} - -// reads everything and prepares the maps -bool ZipDir::CacheFactory::Prepare () -{ - if (!FindCDREnd()) - { - return false; - } - - m_bEncryptedHeaders = (m_CDREnd.nDisk & (1 << 15)) != 0; - m_CDREnd.nDisk = m_CDREnd.nDisk & 0x7fff; - - // we don't support multivolume archives - if (m_CDREnd.nDisk != 0 - || m_CDREnd.nCDRStartDisk != 0 - || m_CDREnd.numEntriesOnDisk != m_CDREnd.numEntriesTotal) - { - THROW_ZIPDIR_ERROR(ZD_ERROR_UNSUPPORTED, "Multivolume archive detected. Current version of ZipDir does not support multivolume archives"); - return false; - } - - // if the central directory offset or size are out of range, - // the CDREnd record is probably corrupt - if (m_CDREnd.lCDROffset > m_nCDREndPos - || m_CDREnd.lCDRSize > m_nCDREndPos - || m_CDREnd.lCDROffset + m_CDREnd.lCDRSize > m_nCDREndPos) - { - THROW_ZIPDIR_ERROR (ZD_ERROR_DATA_IS_CORRUPT, "The central directory offset or size are out of range, the pak is probably corrupt, try to repair or delete the file"); - return false; - } - - if (!BuildFileEntryMap()) - { - return false; - } - - // the number of parsed files MUST be the declared number of entries - // in the central directory - if (m_bBuildFileEntryMap && m_CDREnd.numEntriesTotal != m_mapFileEntries.size()) - { - THROW_ZIPDIR_ERROR (ZD_ERROR_CDR_IS_CORRUPT, "The number of parsed files does not match the declared number of entries in the central directory, the pak is probably corrupt, try to repair or delete the file"); - } - - const size_t numFilesFound = m_treeFileEntries.NumFilesTotal(); - if (m_bBuildFileEntryTree && m_CDREnd.numEntriesTotal != numFilesFound) - { - const size_t numDirsFound = m_treeFileEntries.NumDirsTotal(); - - // Other zip tools create entries for directories. - // These entires don't have representation in our tree. - // FIXME: Proper calculation of entry count should be implemented. - if (m_CDREnd.numEntriesTotal != numFilesFound + numDirsFound) - { - THROW_ZIPDIR_ERROR (ZD_ERROR_CDR_IS_CORRUPT, "The number of parsed files does not match the declared number of entries in the central directory. The pak does not appear to be corrupt, but perhaps there are some duplicated or missing file entries, try to repair the file"); - } - } - - return true; -} - -ZipDir::CachePtr ZipDir::CacheFactory::MakeCache (const char* szFile) -{ - if (!Prepare()) - { - return CachePtr(); - } - - // initializes this object from the given tree, which is a convenient representation of the file tree - size_t nSizeRequired = m_treeFileEntries.GetSizeSerialized(); - size_t nSizeZipPath = 1; // we need to remember the terminating 0 - if (!(m_nFlags & FLAGS_DONT_MEMORIZE_ZIP_PATH)) - { - nSizeZipPath += strlen(szFile); - } - // allocate and initialize the memory that'll be the root now - size_t nCacheInstanceSize = sizeof(Cache) + nSizeRequired + nSizeZipPath; - - Cache* pCacheInstance = (Cache*)malloc(nCacheInstanceSize); // Do not use pools for this allocation - pCacheInstance->Construct(m_f, nSizeRequired, m_encryptionKey); - CachePtr cache = pCacheInstance; - m_f = NULL; // we don't own the file anymore - it's in possession of the cache instance - - // try to serialize into the memory -#if !defined(NDEBUG) - size_t nSizeSerialized = -#endif - m_treeFileEntries.Serialize (cache->GetRoot()); - - assert (nSizeSerialized == nSizeRequired); - - char* pZipPath = ((char*)(pCacheInstance + 1)) + nSizeRequired; - - if (!(m_nFlags & FLAGS_DONT_MEMORIZE_ZIP_PATH)) - { - memcpy (pZipPath, szFile, nSizeZipPath); - } - else - { - pZipPath[0] = '\0'; - } - - Clear(); - - return cache; -} - -void ZipDir::CacheFactory::Clear() -{ - if (m_f) - { - fclose (m_f); - } - m_nCDREndPos = 0; - memset (&m_CDREnd, 0, sizeof(m_CDREnd)); - m_mapFileEntries.clear(); - m_treeFileEntries.Clear(); - m_bEncryptedHeaders = false; -} - - -////////////////////////////////////////////////////////////////////////// -// searches for CDREnd record in the given file -bool ZipDir::CacheFactory::FindCDREnd() -{ - // this buffer will be used to find the CDR End record - // the additional bytes are required to store the potential tail of the CDREnd structure - // when moving the window to the next position in the file - char pReservedBuffer[g_nCDRSearchWindowSize + sizeof(ZipFile::CDREnd) - 1]; - - Seek (0, SEEK_END); - unsigned long nFileSize = Tell(); - - if (nFileSize < sizeof(ZipFile::CDREnd)) - { - THROW_ZIPDIR_ERROR (ZD_ERROR_NO_CDR, "The file is too small, it doesn't even contain the CDREnd structure. Please check and delete the file. Truncated files are not deleted automatically"); - return false; - } - - // this will point to the place where the buffer was loaded - unsigned int nOldBufPos = nFileSize; - // start scanning well before the end of the file to avoid reading beyond the end - - unsigned int nScanPos = nFileSize - sizeof(ZipFile::CDREnd); - - m_CDREnd.lSignature = 0; // invalid signature as the flag of not-found CDR End structure - while (true) - { - unsigned int nNewBufPos; // the new buf pos - char* pWindow = pReservedBuffer; // the window pointer into which data will be read (takes into account the possible tail-of-CDREnd) - if (nOldBufPos <= g_nCDRSearchWindowSize) - { - // the old buffer position doesn't let us read the full search window size - // therefore the new buffer pos will be 0 (instead of negative beyond the start of the file) - // and the window pointer will be closer tot he end of the buffer because the end of the buffer - // contains the data from the previous iteration (possibly) - nNewBufPos = 0; - pWindow = pReservedBuffer + g_nCDRSearchWindowSize - (nOldBufPos - nNewBufPos); - } - else - { - nNewBufPos = nOldBufPos - g_nCDRSearchWindowSize; - assert (nNewBufPos > 0); - } - - // since dealing with 32bit unsigned, check that filesize is bigger than - // CDREnd plus comment before the following check occurs. - if (nFileSize > (sizeof(ZipFile::CDREnd) + 0xFFFF)) - { - // if the new buffer pos is beyond 64k limit for the comment size - if (nNewBufPos < (unsigned int)(nFileSize - sizeof(ZipFile::CDREnd) - 0xFFFF)) - { - nNewBufPos = nFileSize - sizeof(ZipFile::CDREnd) - 0xFFFF; - } - } - - // if there's nothing to search - if (nNewBufPos >= nOldBufPos) - { - THROW_ZIPDIR_ERROR (ZD_ERROR_NO_CDR, "Cannot find Central Directory Record in pak. This is either not a pak file, or a pak file without Central Directory. It does not mean that the data is permanently lost, but it may be severely damaged. Please repair the file with external tools, there may be enough information left to recover the file completely"); // we didn't find anything - return false; - } - - // seek to the start of the new window and read it - Seek (nNewBufPos); - Read (pWindow, nOldBufPos - nNewBufPos); - - while (nScanPos >= nNewBufPos) - { - ZipFile::CDREnd* pEnd = (ZipFile::CDREnd*)(pWindow + nScanPos - nNewBufPos); - if (pEnd->lSignature == pEnd->SIGNATURE) - { - if (pEnd->nCommentLength == nFileSize - nScanPos - sizeof(ZipFile::CDREnd)) - { - // the comment length is exactly what we expected - m_CDREnd = *pEnd; - m_nCDREndPos = nScanPos; - break; - } - else - { - THROW_ZIPDIR_ERROR (ZD_ERROR_DATA_IS_CORRUPT, "Central Directory Record is followed by a comment of inconsistent length. This might be a minor misconsistency, please try to repair the file. However, it is dangerous to open the file because I will have to guess some structure offsets, which can lead to permanent unrecoverable damage of the archive content"); - return false; - } - } - if (nScanPos == 0) - { - break; - } - --nScanPos; - } - - if (m_CDREnd.lSignature == m_CDREnd.SIGNATURE) - { - return true; // we've found it - } - - nOldBufPos = nNewBufPos; - memmove (pReservedBuffer + g_nCDRSearchWindowSize, pWindow, sizeof(ZipFile::CDREnd) - 1); - } - THROW_ZIPDIR_ERROR (ZD_ERROR_UNEXPECTED, "The program flow may not have possibly lead here. This error is unexplainable"); // we shouldn't be here - return false; -} - - -////////////////////////////////////////////////////////////////////////// -// uses the found CDREnd to scan the CDR and probably the Zip file itself -// builds up the m_mapFileEntries -bool ZipDir::CacheFactory::BuildFileEntryMap() -{ - Seek (m_CDREnd.lCDROffset); - - if (m_CDREnd.lCDRSize == 0) - { - return true; - } - - DynArray& pBuffer = m_CDR_buffer; // Use persistent buffer. - - pBuffer.resize(m_CDREnd.lCDRSize + 1); // Allocate one more because we use this memory as a strings pool. - - if (pBuffer.empty()) // couldn't allocate enough memory for temporary copy of CDR - { - THROW_ZIPDIR_ERROR (ZD_ERROR_NO_MEMORY, "Not enough memory to cache Central Directory record for fast initialization. This error may not happen on non-console systems"); - return false; - } - - // Calculate buffer size for unified filenames - const size_t headersSize = sizeof(ZipFile::CDRFileHeader) * m_CDREnd.numEntriesTotal; - const size_t terminatingZeros = m_CDREnd.numEntriesTotal; - if (headersSize > m_CDREnd.lCDRSize + terminatingZeros) - { - THROW_ZIPDIR_ERROR (ZD_ERROR_CORRUPTED_DATA, "Number of entries in Central Directory seems to be wrong"); - return false; - } - const size_t nameBufferSize = m_CDREnd.lCDRSize + terminatingZeros - headersSize; // numEntriesTotal for terminating zeroes - - // Allocate buffer for unified filenames - m_unifiedNameBuffer.resize(nameBufferSize); - if (m_unifiedNameBuffer.empty() && nameBufferSize != 0) - { - THROW_ZIPDIR_ERROR (ZD_ERROR_NO_MEMORY, "Not enough memory to allocate unified names buffer"); - return false; - } - char* pUnifiedName = m_unifiedNameBuffer.empty() ? 0 : &m_unifiedNameBuffer[0]; - const char* const pUnifiedNameEnd = pUnifiedName + m_unifiedNameBuffer.size(); - - ReadHeaderData(&pBuffer[0], m_CDREnd.lCDRSize); - - // now we've read the complete CDR - parse it. - ZipFile::CDRFileHeader* pFile = (ZipFile::CDRFileHeader*)(&pBuffer[0]); - const char* const pEndOfData = &pBuffer[0] + m_CDREnd.lCDRSize; - const char* const pEndOfBuffer = &pBuffer[0] + pBuffer.size(); - char* pFileName; - - // check signature of first entry - if ((const char*)(pFile + 1) <= pEndOfData) - { - if (pFile->lSignature != pFile->SIGNATURE) - { - THROW_ZIPDIR_ERROR (ZD_ERROR_CDR_IS_CORRUPT, m_bEncryptedHeaders - ? "Signature of CDR entry is corrupt. Wrong decryption key was used or archive is corrupt." - : "Signature of CDR entry is corrupt. Archive is corrupt."); - return false; - } - } - - while ((pFileName = (char*)(pFile + 1)) <= pEndOfData) - { - // Hacky way to use CDR memory block as a string pool. - pFile->lSignature = 0; // Force signature to always be 0 (First byte of signature maybe a zero termination of the previous file filename). - - if (pFile->nVersionNeeded > 20) - { - THROW_ZIPDIR_ERROR (ZD_ERROR_UNSUPPORTED, "Reading file header with unsupported version (nVersionNeeded > 20)."); - return false; - } - //if (pFile->lSignature != pFile->SIGNATURE) // Timur, Dont compare signatures as signatue in memory can be overwritten by the code below - //break; - // the end of this file record - const char* pEndOfRecord = (pFileName + pFile->nFileNameLength + pFile->nExtraFieldLength + pFile->nFileCommentLength); - // if the record overlaps with the End Of CDR structure, something is wrong - if (pEndOfRecord > pEndOfData) - { - THROW_ZIPDIR_ERROR (ZD_ERROR_CDR_IS_CORRUPT, "Central Directory record is either corrupt, or truncated, or missing. Cannot read the archive directory"); - return false; - } - - ////////////////////////////////////////////////////////////////////////// - // Analyze advanced section. - ////////////////////////////////////////////////////////////////////////// - SExtraZipFileData extra; - const char* pExtraField = (pFileName + pFile->nFileNameLength); - const char* pExtraEnd = pExtraField + pFile->nExtraFieldLength; - while (pExtraField < pExtraEnd) - { - const char* pAttrData = pExtraField + sizeof(ZipFile::ExtraFieldHeader); - ZipFile::ExtraFieldHeader& hdr = *(ZipFile::ExtraFieldHeader*)pExtraField; - switch (hdr.headerID) - { - case ZipFile::EXTRA_NTFS: - { - extra.nLastModifyTime = *(uint64*)(pAttrData + sizeof(ZipFile::ExtraNTFSHeader)); - //uint64 accTime = *(uint64*)(pAttrData + sizeof(ZipFile::ExtraNTFSHeader) + 8); - //uint64 crtTime = *(uint64*)(pAttrData + sizeof(ZipFile::ExtraNTFSHeader) + 16); - } - break; - } - pExtraField += sizeof(ZipFile::ExtraFieldHeader) + hdr.dataSize; - } - - bool bDirectory = false; - if (pFile->nFileNameLength > 0 && (pFileName[pFile->nFileNameLength - 1] == '/' || pFileName[pFile->nFileNameLength - 1] == '\\')) - { - bDirectory = true; - } - - if (!bDirectory) - { - const size_t fileNameLen = pFile->nFileNameLength; - pFileName[fileNameLen] = 0; // Not standard!, may overwrite signature of the next memory record data in zip. - - // generate unified name - if (pFileName + fileNameLen + 1 > pEndOfBuffer || - pUnifiedName + fileNameLen + 1 > pUnifiedNameEnd) - { - THROW_ZIPDIR_ERROR (ZD_ERROR_CORRUPTED_DATA, "Filename length exceeds estimated size. Try to repair the archive."); - return false; - } - - for (int i = 0; i < fileNameLen + 1; i++) - { - pUnifiedName[i] = ::tolower(pFileName[i]); - } - - // put this entry into the map - AddFileEntry (pFileName, pUnifiedName, pFile, extra); - - pUnifiedName += fileNameLen + 1; - } - - // move to the next file - pFile = (ZipFile::CDRFileHeader*)pEndOfRecord; - } - - // finished reading CDR - return true; -} - - -////////////////////////////////////////////////////////////////////////// -// give the CDR File Header entry, reads the local file header to validate -// and determine where the actual file lies -void ZipDir::CacheFactory::AddFileEntry (char* strFilePath, char* strUnifiedPath, const ZipFile::CDRFileHeader* pFileHeader, const SExtraZipFileData& extra) -{ - if (pFileHeader->lLocalHeaderOffset > m_CDREnd.lCDROffset) - { - THROW_ZIPDIR_ERROR (ZD_ERROR_CDR_IS_CORRUPT, "Central Directory contains file descriptors pointing outside the archive file boundaries. The archive file is either truncated or damaged. Please try to repair the file"); // the file offset is beyond the CDR: impossible - return; - } - - if (pFileHeader->nMethod == ZipFile::METHOD_STORE && pFileHeader->desc.lSizeUncompressed != pFileHeader->desc.lSizeCompressed) - { - THROW_ZIPDIR_ERROR (ZD_ERROR_VALIDATION_FAILED, "File with STORE compression method declares its compressed size not matching its uncompressed size. File descriptor is inconsistent, archive content may be damaged, please try to repair the archive"); - return; - } - - FileEntry fileEntry (*pFileHeader, extra); - - if ((m_bEncryptedHeaders || m_nInitMethod >= ZD_INIT_FULL) && pFileHeader->desc.lSizeCompressed) - { - InitDataOffset(fileEntry, pFileHeader); - } - - if (m_bBuildFileEntryMap) - { - m_mapFileEntries.insert (FileEntryMap::value_type(strFilePath, fileEntry)); - } - - if (m_bBuildFileEntryTree) - { - m_treeFileEntries.Add(strFilePath, strUnifiedPath, fileEntry); - } -} - - -////////////////////////////////////////////////////////////////////////// -// initializes the actual data offset in the file in the fileEntry structure -// searches to the local file header, reads it and calculates the actual offset in the file -void ZipDir::CacheFactory::InitDataOffset (FileEntry& fileEntry, const ZipFile::CDRFileHeader* pFileHeader) -{ - // make sure it's the same file and the fileEntry structure is properly initialized - assert (fileEntry.nFileHeaderOffset == pFileHeader->lLocalHeaderOffset); - - /* - // without validation, it would be like this: - ErrorEnum nError = Refresh(&fileEntry); - if (nError != ZD_ERROR_SUCCESS) - THROW_ZIPDIR_ERROR(nError,"Cannot refresh file entry. Probably corrupted file header inside zip file"); - */ - - - if (m_bEncryptedHeaders) - { - // ignore local header - fileEntry.nFileDataOffset = pFileHeader->lLocalHeaderOffset + sizeof(ZipFile::LocalFileHeader) + pFileHeader->nFileNameLength + pFileHeader->nExtraFieldLength; - } - else - { - Seek(pFileHeader->lLocalHeaderOffset); - // read the local file header and the name (for validation) into the buffer - DynArraypBuffer; - unsigned nBufferLength = sizeof(ZipFile::LocalFileHeader) + pFileHeader->nFileNameLength; - pBuffer.resize(nBufferLength); - Read (&pBuffer[0], nBufferLength); - - // validate the local file header (compare with the CDR file header - they should contain basically the same information) - const ZipFile::LocalFileHeader* pLocalFileHeader = (const ZipFile::LocalFileHeader*)&pBuffer[0]; - if (pFileHeader->desc != pLocalFileHeader->desc - || pFileHeader->nMethod != pLocalFileHeader->nMethod - || pFileHeader->nFileNameLength != pLocalFileHeader->nFileNameLength - // for a tough validation, we can compare the timestamps of the local and central directory entries - // but we won't do that for backward compatibility with ZipDir - //|| pFileHeader->nLastModDate != pLocalFileHeader->nLastModDate - //|| pFileHeader->nLastModTime != pLocalFileHeader->nLastModTime - ) - { - THROW_ZIPDIR_ERROR (ZD_ERROR_VALIDATION_FAILED, "The local file header descriptor doesn't match the basic parameters declared in the global file header in the file. The archive content is misconsistent and may be damaged. Please try to repair the archive"); - return; - } - - // now compare the local file name with the one recorded in CDR: they must match. - if (azmemicmp((const char*)&pBuffer[sizeof(ZipFile::LocalFileHeader)], (const char*)pFileHeader + 1, pFileHeader->nFileNameLength)) - { - // either file name, or the extra field do not match - THROW_ZIPDIR_ERROR(ZD_ERROR_VALIDATION_FAILED, "The local file header contains file name which does not match the file name of the global file header. The archive content is misconsistent with its directory. Please repair the archive"); - return; - } - - fileEntry.nFileDataOffset = pFileHeader->lLocalHeaderOffset + sizeof(ZipFile::LocalFileHeader) + pLocalFileHeader->nFileNameLength + pLocalFileHeader->nExtraFieldLength; - } - - if (fileEntry.nFileDataOffset >= m_nCDREndPos) - { - THROW_ZIPDIR_ERROR(ZD_ERROR_VALIDATION_FAILED, "The global file header declares the file which crosses the boundaries of the archive. The archive is either corrupted or truncated, please try to repair it"); - return; - } - - if (m_nInitMethod >= ZD_INIT_VALIDATE) - { - Validate (fileEntry); - } -} - -////////////////////////////////////////////////////////////////////////// -// reads the file pointed by the given header and entry (they must be coherent) -// and decompresses it; then calculates and validates its CRC32 -void ZipDir::CacheFactory::Validate(const FileEntry& fileEntry) -{ - DynArray pBuffer; - // validate the file contents - // allocate memory for both the compressed data and uncompressed data - pBuffer.resize(fileEntry.desc.lSizeCompressed + fileEntry.desc.lSizeUncompressed); - char* pUncompressed = &pBuffer[fileEntry.desc.lSizeCompressed]; - char* pCompressed = &pBuffer[0]; - - assert (fileEntry.nFileDataOffset != FileEntry::INVALID_DATA_OFFSET); - Seek(fileEntry.nFileDataOffset); - - Read(pCompressed, fileEntry.desc.lSizeCompressed); - - if (fileEntry.nMethod == ZipFile::METHOD_DEFLATE_AND_ENCRYPT) - { - ZipDir::Decrypt(pCompressed, fileEntry.desc.lSizeCompressed, m_encryptionKey); - } - - unsigned long nDestSize = fileEntry.desc.lSizeUncompressed; - int nError = Z_OK; - if (fileEntry.nMethod) - { - nError = ZipRawUncompress (pUncompressed, &nDestSize, pCompressed, fileEntry.desc.lSizeCompressed); - } - else - { - assert (fileEntry.desc.lSizeCompressed == fileEntry.desc.lSizeUncompressed); - memcpy (pUncompressed, pCompressed, fileEntry.desc.lSizeUncompressed); - } - switch (nError) - { - case Z_OK: - break; - case Z_MEM_ERROR: - THROW_ZIPDIR_ERROR(ZD_ERROR_ZLIB_NO_MEMORY, "ZLib reported out-of-memory error"); - return; - case Z_BUF_ERROR: - THROW_ZIPDIR_ERROR(ZD_ERROR_ZLIB_CORRUPTED_DATA, "ZLib reported compressed stream buffer error"); - return; - case Z_DATA_ERROR: - THROW_ZIPDIR_ERROR(ZD_ERROR_ZLIB_CORRUPTED_DATA, "ZLib reported compressed stream data error"); - return; - default: - THROW_ZIPDIR_ERROR(ZD_ERROR_ZLIB_FAILED, "ZLib reported an unexpected unknown error"); - return; - } - - if (nDestSize != fileEntry.desc.lSizeUncompressed) - { - THROW_ZIPDIR_ERROR(ZD_ERROR_CORRUPTED_DATA, "Uncompressed stream doesn't match the size of uncompressed file stored in the archive file headers"); - return; - } - - uLong uCRC32 = crc32(0L, Z_NULL, 0); - uCRC32 = crc32(uCRC32, (Bytef*)pUncompressed, nDestSize); - if (uCRC32 != fileEntry.desc.lCRC32) - { - THROW_ZIPDIR_ERROR(ZD_ERROR_CRC32_CHECK, "Uncompressed stream CRC32 check failed"); - return; - } -} - - -////////////////////////////////////////////////////////////////////////// -// extracts the file path from the file header with subsequent information -// may, or may not, put all letters to lower-case (depending on whether the system is to be case-sensitive or not) -// it's the responsibility of the caller to ensure that the file name is in readable valid memory -char* ZipDir::CacheFactory::GetFilePath (const char* pFileName, ZipFile::ushort nFileNameLength) -{ - static char strResult[_MAX_PATH]; - assert(nFileNameLength < _MAX_PATH); - memcpy(strResult, pFileName, nFileNameLength); - strResult[nFileNameLength] = 0; - for (int i = 0; i < nFileNameLength; i++) - { - strResult[i] = ::tolower(strResult[i]); - } - - return strResult; -} - -// seeks in the file relative to the starting position -void ZipDir::CacheFactory::Seek (ZipFile::ulong nPos, int nOrigin) // throw -{ - if (AZ_TRAIT_CRYCOMMONTOOLS_FSEEK(m_f, nPos, nOrigin)) - { - THROW_ZIPDIR_ERROR(ZD_ERROR_IO_FAILED, "Cannot fseek() to the new position in the file. This is unexpected error and should not happen under any circumstances. Perhaps some network or disk failure error has caused this"); - return; - } -} - -unsigned long ZipDir::CacheFactory::Tell () // throw -{ - AZ::s64 nPos = AZ_TRAIT_CRYCOMMONTOOLS_FTELL(m_f); - if (nPos == -1) - { - THROW_ZIPDIR_ERROR(ZD_ERROR_IO_FAILED, "Cannot ftell() position in the archive. This is unexpected error and should not happen under any circumstances. Perhaps some network or disk failure error has caused this"); - return 0; - } - return (unsigned long)nPos; -} - -void ZipDir::CacheFactory::Read (void* pDest, unsigned nSize) // throw -{ - if (fread (pDest, nSize, 1, m_f) != 1) - { - THROW_ZIPDIR_ERROR(ZD_ERROR_IO_FAILED, "Cannot fread() a portion of data from archive"); - } -} - -void ZipDir::CacheFactory::ReadHeaderData (void* pDest, unsigned nSize) // throw -{ - Read(pDest, nSize); - - if (m_bEncryptedHeaders) - { - ZipDir::Decrypt((char*)pDest, nSize, m_encryptionKey); - } -} - diff --git a/Code/Tools/CryCommonTools/ZipDir/ZipDirCacheFactory.h b/Code/Tools/CryCommonTools/ZipDir/ZipDirCacheFactory.h deleted file mode 100644 index caf947e1af..0000000000 --- a/Code/Tools/CryCommonTools/ZipDir/ZipDirCacheFactory.h +++ /dev/null @@ -1,143 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// This is the class that can read the directory from Zip file, -// and store it into the directory cache - -#ifndef CRYINCLUDE_CRYCOMMONTOOLS_ZIPDIR_ZIPDIRCACHEFACTORY_H -#define CRYINCLUDE_CRYCOMMONTOOLS_ZIPDIR_ZIPDIRCACHEFACTORY_H -#pragma once - - -namespace ZipDir -{ - class CacheRW; - TYPEDEF_AUTOPTR(CacheRW); - typedef CacheRW_AutoPtr CacheRWPtr; - - // an instance of this class is temporarily created on stack to initialize the CZipFile instance - class CacheFactory - { - public: - enum - { - // open RW cache in read-only mode - FLAGS_READ_ONLY = 1, - // do not compact RW-cached zip upon destruction - FLAGS_DONT_COMPACT = 1 << 1, - // if this is set, then the zip paths won't be memorized in the cache objects - FLAGS_DONT_MEMORIZE_ZIP_PATH = 1 << 2, - // if this is set, the archive will be created anew (the existing file will be overwritten) - FLAGS_CREATE_NEW = 1 << 3 - }; - - // initializes the internal structures - // nFlags can have FLAGS_READ_ONLY flag, in this case the object will be opened only for reading - CacheFactory (InitMethodEnum nInitMethod, unsigned nFlags = 0); - ~CacheFactory(); - - // the new function creates a new cache - CachePtr New(const char* szFileName, const uint32 decryptionKey[4]);// throw (ErrorEnum); - - CacheRWPtr NewRW(const char* szFileName, size_t fileAlignment, bool encrypted, const uint32 encryptionKey[4]); - - protected: - // reads the zip file into the file entry tree. - bool ReadCacheRW (CacheRW& rwCache); - - // creates from the m_f file - // reserves the given number of bytes for future expansion of the object - // upon return, pReserve contains the actual number of bytes that were allocated (more might have been allocated) - CachePtr MakeCache (const char* szFile); - - // this sets the window size of the blocks of data read from the end of the file to find the Central Directory Record - // since normally there are no - enum - { - g_nCDRSearchWindowSize = 0x100 - }; - - void Clear(); - - // reads everything and prepares the maps - bool Prepare(); - - // searches for CDREnd record in the given file - bool FindCDREnd();// throw(ErrorEnum); - - // uses the found CDREnd to scan the CDR and probably the Zip file itself - // builds up the m_mapFileEntries - bool BuildFileEntryMap();// throw (ErrorEnum); - - // give the CDR File Header entry, reads the local file header to validate and determine where - // the actual file lies - // This function can actually modify strFilePath and strUnifiedPath variables, make sure you use copies of real paths. - void AddFileEntry (char* strFilePath, char* strUnifiedPath, const ZipFile::CDRFileHeader* pFileHeader, const SExtraZipFileData& extra);// throw (ErrorEnum); - - // extracts the file path from the file header with subsequent information - // may, or may not, put all letters to lower-case (depending on whether the system is to be case-sensitive or not) - // it's the responsibility of the caller to ensure that the file name is in readable valid memory - char* GetFilePath (const ZipFile::CDRFileHeader* pFileHeader) - { - return GetFilePath((const char*)(pFileHeader + 1), pFileHeader->nFileNameLength); - } - // extracts the file path from the file header with subsequent information - // may, or may not, put all letters to lower-case (depending on whether the system is to be case-sensitive or not) - // it's the responsibility of the caller to ensure that the file name is in readable valid memory - char* GetFilePath (const ZipFile::LocalFileHeader* pFileHeader) - { - return GetFilePath((const char*)(pFileHeader + 1), pFileHeader->nFileNameLength); - } - // extracts the file path from the file header with subsequent information - // may, or may not, put all letters to lower-case (depending on whether the system is to be case-sensitive or not) - // it's the responsibility of the caller to ensure that the file name is in readable valid memory - char* GetFilePath (const char* pFileName, ZipFile::ushort nFileNameLength); - - // validates (if the init method has the corresponding value) the given file/header - void Validate(const FileEntry& fileEntry); - - // initializes the actual data offset in the file in the fileEntry structure - // searches to the local file header, reads it and calculates the actual offset in the file - void InitDataOffset (FileEntry& fileEntry, const ZipFile::CDRFileHeader* pFileHeader); - - // seeks in the file relative to the starting position - void Seek (ZipFile::ulong nPos, int nOrigin = SEEK_SET); // throw - unsigned long Tell (); // throw - void Read (void* pDest, unsigned nSize); // throw - void ReadHeaderData (void* pDest, unsigned nSize);// throw - protected: - - FILE* m_f; - InitMethodEnum m_nInitMethod; - unsigned m_nFlags; - ZipFile::CDREnd m_CDREnd; - - unsigned m_nCDREndPos; // position of the CDR End in the file - - // Map: Relative file path => file entry info - typedef std::map FileEntryMap; - FileEntryMap m_mapFileEntries; - - FileEntryTree m_treeFileEntries; - - DynArray m_CDR_buffer; - DynArray m_unifiedNameBuffer; - - EncryptionKey m_encryptionKey; - bool m_bEncryptedHeaders; - bool m_bBuildFileEntryMap; - bool m_bBuildFileEntryTree; - }; -} - -#endif // CRYINCLUDE_CRYCOMMONTOOLS_ZIPDIR_ZIPDIRCACHEFACTORY_H diff --git a/Code/Tools/CryCommonTools/ZipDir/ZipDirCacheRW.cpp b/Code/Tools/CryCommonTools/ZipDir/ZipDirCacheRW.cpp deleted file mode 100644 index 6e47aec5d4..0000000000 --- a/Code/Tools/CryCommonTools/ZipDir/ZipDirCacheRW.cpp +++ /dev/null @@ -1,2100 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include -#include "Util.h" -#include "ZipFileFormat.h" -#include "zipdirstructures.h" -#include "ZipDirTree.h" -#include "ZipDirList.h" -#include "ZipDirCache.h" -#include "ZipDirCacheRW.h" -#include "ZipDirCacheFactory.h" -#include "ZipDirFindRW.h" - -#include "ThreadUtils.h" - -#include // declaration of Z_OK for ZipRawDecompress -#include -#include -#include -#include -#include -#include -#include -#include -#include - -enum PackFileStatus -{ - PACKFILE_COMPRESSED, - - PACKFILE_ADDED, - PACKFILE_UPTODATE, - PACKFILE_SKIPPED, - PACKFILE_MISSING, - PACKFILE_FAILED -}; - -enum PackFileCompressionPolicy -{ - PACKFILE_USE_REQUESTED_COMPRESSOR, - PACKFILE_USE_FASTEST_DECOMPRESSING_CODEC -}; - -class PackFilePool; -struct PackFileBatch -{ - PackFilePool* pool; - - int zipMaxSize; - int sourceMinSize; - int sourceMaxSize; - int compressionMethod; - int compressionLevel; - - PackFileBatch() - : pool(0) - , sourceMinSize(0) - , sourceMaxSize(0) - , zipMaxSize(0) - , compressionMethod(0) - , compressionLevel(0) - { - } -}; - -class PackFilePool; -struct PackFileJob -{ - int index; - int key; - PackFileBatch* batch; - const char* relativePathSrc; - const char* realFilename; - - unsigned int existingCRC; - - void* compressedData; - unsigned long compressedSize; - unsigned long compressedSizePreviously; - - void* uncompressedData; - unsigned long uncompressedSize; - unsigned long uncompressedSizePreviously; - - int64 modTime; - ZipDir::ErrorEnum zdError; - PackFileStatus status; - PackFileCompressionPolicy compressionPolicy; - - PackFileJob() - : index(0) - , key(0) - , batch(0) - , realFilename(0) - , relativePathSrc(0) - , existingCRC(0) - , compressedData(0) - , compressedSize(0) - , compressedSizePreviously(0) - , uncompressedData(0) - , uncompressedSize(0) - , uncompressedSizePreviously(0) - , modTime(0) - , zdError(ZipDir::ZD_ERROR_NOT_IMPLEMENTED) - , status(PACKFILE_FAILED) - , compressionPolicy(PACKFILE_USE_REQUESTED_COMPRESSOR) - { - } - - void DetachUncompressedData() - { - if (uncompressedData && uncompressedData == compressedData) - { - compressedData = 0; - compressedSize = 0; - } - - uncompressedData = 0; - uncompressedSize = 0; - } - - ~PackFileJob() - { - if (compressedData && compressedData != uncompressedData) - { - azfree(compressedData); - compressedData = 0; - } - - if (uncompressedData) - { - azfree(uncompressedData); - uncompressedData = 0; - } - } -}; - - -// --------------------------------------------------------------------------- -static void PackFileFromDisc(PackFileJob* job); -class PackFilePool -{ -public: - PackFilePool(int numFiles, size_t memoryLimit) - : m_pool(false) - , m_skip(false) - , m_awaitedFile(0) - , m_memoryLimit(memoryLimit) - , m_allocatedMemory(0) - { - m_files.reserve(numFiles); - } - - ~PackFilePool() - { - } - - void Submit(int key, const PackFileJob& job) - { - PackFileJob* newJob = new PackFileJob(job); - - // index in queue, and custom key for identification - newJob->index = int(m_files.size()); - newJob->key = key; - - m_files.push_back(newJob); - } - - PackFileJob* WaitForFile(int index) - { - while (true) - { - { - AZStd::lock_guard lock(m_filesLock); - m_awaitedFile = index; - if (size_t(index) >= m_files.size()) - { - return 0; - } - if (m_files[index]) - { - return m_files[index]; - } - } - Sleep(0); - } - - assert(0); - return 0; - } - - void Start(unsigned numExtraThreads) - { - if (numExtraThreads == 0) - { - for (PackFileJob* job : m_files) - { - PackFileFromDisc(job); - } - } - else - { - for (size_t i = 0; i < m_files.size(); ++i) - { - PackFileJob* job = m_files[i]; - m_files[i] = 0; - m_pool.Submit(&ProcessFile, job); - } - - m_pool.Start(numExtraThreads); - } - } - - size_t GetJobCount() const - { - return m_files.size(); - } - - void SkipPendingFiles() - { - m_skip = true; - } - - void ReleaseFile(int index) - { - assert(m_files[index] != 0); - if (m_files[index]) - { - if (m_memoryLimit != 0) - { - AZStd::lock_guard lock(m_filesLock); - - m_allocatedMemory -= m_files[index]->uncompressedSize; - m_allocatedMemory -= m_files[index]->compressedSize; - } - - delete m_files[index]; - m_files[index] = 0; - } - } - -private: - - // called from non-main thread - static void ProcessFile(PackFileJob* job) - { - PackFilePool* self = job->batch->pool; - - if (!self->m_skip) - { - if (self->m_memoryLimit != 0) - { - while (true) - { - size_t allocatedMemory = 0; - int awaitedFile = 0; - { - AZStd::lock_guard lock(self->m_filesLock); - allocatedMemory = self->m_allocatedMemory; - awaitedFile = self->m_awaitedFile; - } - - if (allocatedMemory > self->m_memoryLimit && job->index > awaitedFile + 1) - { - Sleep(10); // give time to main thread to write data to file - } - else - { - break; - } - } - } - - PackFileFromDisc(job); - } - - self->FileCompleted(job); - } - - // called from non-main thread - void FileCompleted(PackFileJob* job) - { - AZStd::lock_guard lock(m_filesLock); - - assert(job); - assert(job->index < m_files.size()); - assert(m_files[job->index] == 0); - m_files[job->index] = job; - - if (m_memoryLimit != 0) - { - m_allocatedMemory += job->uncompressedSize; - m_allocatedMemory += job->compressedSize; - } - } - - size_t m_memoryLimit; - - AZStd::mutex m_filesLock; - std::vector m_files; - int m_awaitedFile; - size_t m_allocatedMemory; - bool m_skip; - - ThreadUtils::SimpleThreadPool m_pool; -}; - -////////////////////////////////////////////////////////////////////////// -static size_t AlignTo(size_t offset, size_t alignment) -{ - const size_t remainder = offset % alignment; - return remainder ? offset + alignment - remainder : offset; -} -////////////////////////////////////////////////////////////////////////// -// Calculates new offset of the header to make sure that following data are -// aligned properly -static size_t CalculateAlignedHeaderOffset(const char* fileName, size_t currentOffset, size_t alignment) -{ - // Since file should start from header - if (currentOffset == 0) - { - return 0; - } - - // Local header is followed by filename - const size_t totalHeaderSize = sizeof(ZipFile::LocalFileHeader) + strlen(fileName); - - // Align end of the header - const size_t dataOffset = AlignTo(currentOffset + totalHeaderSize, alignment); - - return dataOffset - totalHeaderSize; -} - -////////////////////////////////////////////////////////////////////////// -ZipDir::CacheRW::CacheRW(bool encryptHeaders, const EncryptionKey& encryptionKey) - : m_pFile (NULL) - , m_nFlags (0) - , m_lCDROffset (0) - , m_fileAlignment (1) - , m_bEncryptedHeaders(encryptHeaders) - , m_bHeadersEncryptedOnClose(encryptHeaders) - , m_encryptionKey(encryptionKey) -{ - m_nRefCount = 0; -} -////////////////////////////////////////////////////////////////////////// -ZipDir::CacheRW::~CacheRW() -{ - Close(); -} -////////////////////////////////////////////////////////////////////////// -void ZipDir::CacheRW::AddRef() -{ - ++m_nRefCount; -} - -////////////////////////////////////////////////////////////////////////// -void ZipDir::CacheRW::Release() -{ - if (--m_nRefCount <= 0) - { - delete this; - } -} - -void ZipDir::CacheRW::Close() -{ - if (m_pFile) - { - if (!(m_nFlags & FLAGS_READ_ONLY)) - { - if ((m_nFlags & FLAGS_UNCOMPACTED) && !(m_nFlags & FLAGS_DONT_COMPACT)) - { - if (!RelinkZip()) - { - WriteCDR(); - } - } - else - if (m_nFlags & FLAGS_CDR_DIRTY) - { - WriteCDR(); - } - } - - if (m_pFile) // RelinkZip() might have closed the file - { - fclose (m_pFile); - } - - m_pFile = NULL; - } - m_treeDir.Clear(); -} - -////////////////////////////////////////////////////////////////////////// -char* ZipDir::CacheRW::UnifyPath(char* const str, const char* pPath) -{ - assert(str); - const char* src = pPath; - char* trg = str; - while (*src) - { - if (*src != '/') - { - *trg++ = ::tolower(*src++); - } - else - { - *trg++ = '\\'; - src++; - } - } - *trg = 0; - return str; -} - -////////////////////////////////////////////////////////////////////////// -char* ZipDir::CacheRW::ToUnixPath(char* const str, const char* pPath) -{ - assert(str); - const char* src = pPath; - char* trg = str; - while (*src) - { - if (*src != '/') - { - *trg++ = *src++; - } - else - { - *trg++ = '\\'; - src++; - } - } - *trg = 0; - return str; -} - -////////////////////////////////////////////////////////////////////////// -char* ZipDir::CacheRW::AllocPath(const char* pPath) -{ - char str[_MAX_PATH]; - char* temp = ToUnixPath(str, pPath); - temp = m_tempStringPool.Append(temp, strlen(temp)); - return temp; -} - -static bool UseZlibForFileType(const char* filename) -{ - AZStd::string f(filename); - - //some files types are forced to use zlib - bool found = AzFramework::StringFunc::Path::IsExtension(filename, ".dds") || f.find("cover.ctc") != string::npos || AzFramework::StringFunc::Path::IsExtension(filename, ".uicanvas"); - - return found; -} - -#ifdef AZ_DEBUG_BUILD -static const char* CodecAsString(CompressionCodec::Codec codec) -{ - switch (codec) - { - case CompressionCodec::Codec::ZLIB: - return "ZLIB"; - case CompressionCodec::Codec::ZSTD: - return "ZSTD"; - case CompressionCodec::Codec::LZ4: - return "LZ4"; - } - return "ERROR"; -} -#endif - -static bool CompressData(PackFileJob *job) -{ - bool bUseZlib = UseZlibForFileType(job->relativePathSrc) || (job->compressionPolicy == PACKFILE_USE_REQUESTED_COMPRESSOR); - - bool compressionSuccessful = true; - - if (bUseZlib) - { - job->compressedSize = ZipDir::GetCompressedSizeEstimate(job->uncompressedSize,CompressionCodec::Codec::ZLIB); - job->compressedData = azmalloc(job->compressedSize); - int error = ZipDir::ZipRawCompress(job->uncompressedData, &job->compressedSize, job->compressedData, job->uncompressedSize, job->batch->compressionLevel); - if (error == Z_OK) - { - job->status = PACKFILE_COMPRESSED; - job->zdError = ZipDir::ZD_ERROR_SUCCESS; - } - else - { - compressionSuccessful = false; - } - } - else - { - unsigned long compressedSize[static_cast(CompressionCodec::Codec::NUM_CODECS)]; - void* compressedData[static_cast(CompressionCodec::Codec::NUM_CODECS)]; - std::chrono::milliseconds decompressionTime[static_cast(CompressionCodec::Codec::NUM_CODECS)]; - bool compressionCodecWasSuccessful[static_cast(CompressionCodec::Codec::NUM_CODECS)]; - - std::chrono::time_point start; - - //do compression - for (CompressionCodec::Codec codec : CompressionCodec::s_AllCodecs) - { - unsigned int index = static_cast(codec); - compressedSize[index] = ZipDir::GetCompressedSizeEstimate(job->uncompressedSize, codec); - compressedData[index] = azmalloc(compressedSize[index]); - AZStd::unique_ptr tempBuffer; - unsigned long tempSize = 0; - - //some files decompress so fast they are beyond our ability to measure so we need to do it a few times to get a reading - int numTimesToDecompress = 1 + ZipDir::TARGET_MIN_TEST_COMPRESS_BYTES / job->uncompressedSize; - - auto testDecompressionTime = [&tempSize, job, &tempBuffer, &start, &compressionCodecWasSuccessful, index, numTimesToDecompress, &compressedData, &compressedSize, &decompressionTime]() { - tempSize = job->uncompressedSize; - tempBuffer = AZStd::make_unique(tempSize); - start = std::chrono::high_resolution_clock::now(); - - //start by assuming the decompression test is never going to result in an error - compressionCodecWasSuccessful[index] = true; - - for (int i = 0; i < numTimesToDecompress; i++) - { - int zerror = ZipDir::ZipRawUncompress(tempBuffer.get(), &tempSize, compressedData[index], compressedSize[index]); - if (zerror != Z_OK) - { - compressionCodecWasSuccessful[index] = false; - break; - } - } - decompressionTime[index] = std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - start); - }; - - switch (codec) - { - case CompressionCodec::Codec::ZLIB: - if (ZipDir::ZipRawCompress(job->uncompressedData, &compressedSize[index], compressedData[index], job->uncompressedSize, job->batch->compressionLevel) == Z_OK) - { - testDecompressionTime(); - } - else - { - compressionCodecWasSuccessful[index] = false; - } - break; - - case CompressionCodec::Codec::ZSTD: - if (ZipDir::ZipRawCompressZSTD(job->uncompressedData, &compressedSize[index], compressedData[index], job->uncompressedSize, 1) == Z_OK) - { - testDecompressionTime(); - } - else - { - compressionCodecWasSuccessful[index] = false; - } - break; - - case CompressionCodec::Codec::LZ4: - if (ZipDir::ZipRawCompressLZ4(job->uncompressedData, &compressedSize[index], compressedData[index], job->uncompressedSize, job->batch->compressionLevel) == Z_OK) - { - testDecompressionTime(); - } - else - { - compressionCodecWasSuccessful[index] = false; - } - - break; - - default: - break; - } - } - - //check decompression speed - int bestTimeIndex = -1; - int numberOfSuccessfulCodecs = 0; - for (CompressionCodec::Codec codec : CompressionCodec::s_AllCodecs) - { - int index = static_cast(codec); - if (compressionCodecWasSuccessful[index]) - { - numberOfSuccessfulCodecs++; - if (bestTimeIndex == -1) - { - bestTimeIndex = index; - continue; - } - if ((decompressionTime[index] < decompressionTime[bestTimeIndex])) - { - bestTimeIndex = index; - } - } - } - - if (!numberOfSuccessfulCodecs) - { - AZ_Error("ZipDirCacheRW", false, "None of the available codecs were able to compress the file: %s", job->relativePathSrc); - compressionSuccessful = false; - } - else - { -#ifdef AZ_DEBUG_BUILD - AZ_Printf("ZipDirCacheRW", "Winner for %s is %s with: %d ms ", job->realFilename, CodecAsString(static_cast(bestTimeIndex)), decompressionTime[bestTimeIndex]); -#endif - } - - //get rid of losing data - for (CompressionCodec::Codec codec : CompressionCodec::s_AllCodecs) - { - int index = static_cast(codec); - if (index != bestTimeIndex) - { - azfree(compressedData[index]); - compressedData[index] = nullptr; - } - } - - if (compressionSuccessful) - { - job->compressedSize = compressedSize[bestTimeIndex]; - job->compressedData = compressedData[bestTimeIndex]; - } - } - - //if there was a problem with the compression so just store the file - if (!compressionSuccessful) - { - azfree(job->compressedData); - job->compressedData = job->uncompressedData; - job->compressedSize = job->uncompressedSize; - } - job->status = PACKFILE_COMPRESSED; - job->zdError = ZipDir::ZD_ERROR_SUCCESS; - return true; -} - -static void PackFileFromMemory(PackFileJob* job) -{ - if (job->existingCRC != 0) - { - unsigned int crcCode = (unsigned int)crc32(0, (unsigned char*)job->uncompressedData, job->uncompressedSize); - if (crcCode == job->existingCRC) - { - job->compressedData = 0; - job->compressedSize = 0; - job->status = PACKFILE_UPTODATE; - job->zdError = ZipDir::ZD_ERROR_SUCCESS; - // This file with same data already in pak, skip it. - return; - } - } - - switch (job->batch->compressionMethod) - { - case ZipFile::METHOD_DEFLATE_AND_ENCRYPT: - case ZipFile::METHOD_DEFLATE: - { - // allocate memory for compression. Min is nSize * 1.001 + 12 - if (job->uncompressedSize > 0) - { - CompressData(job); - } - else - { - job->status = PACKFILE_COMPRESSED; - job->zdError = ZipDir::ZD_ERROR_SUCCESS; - - job->compressedSize = 0; - job->compressedData = 0; - } - break; - } - case ZipFile::METHOD_STORE: - job->compressedData = job->uncompressedData; - job->compressedSize = job->uncompressedSize; - job->status = PACKFILE_COMPRESSED; - job->zdError = ZipDir::ZD_ERROR_SUCCESS; - break; - - default: - job->status = PACKFILE_FAILED; - job->zdError = ZipDir::ZD_ERROR_UNSUPPORTED; - break; - } -} - -bool ZipDir::CacheRW::WriteCompressedData(const char* data, size_t size, bool encrypt, FILE* file) -{ - if (size <= 0) - { - return true; - } - - std::vector buffer; - if (encrypt) - { - buffer.resize(size); - memcpy(&buffer[0], data, size); - ZipDir::Encrypt(&buffer[0], size, m_encryptionKey); - data = &buffer[0]; - } - - // Danny - writing a single large chunk (more than 6MB?) causes - // Windows fwrite to (silently?!) fail. So we're writing data - // in small chunks. - while (size > 0) - { - const size_t sizeToWrite = Util::getMin(size, size_t(1024 * 1024)); - if (fwrite(data, sizeToWrite, 1, file) != 1) - { - return false; - } - data += sizeToWrite; - size -= sizeToWrite; - } - - return true; -} - -static bool WriteRandomData(FILE* file, size_t size) -{ - if (size <= 0) - { - return true; - } - - const size_t bufferSize = Util::getMin(size, size_t(1024 * 1024)); - std::vector buffer(bufferSize); - - while (size > 0) - { - const size_t sizeToWrite = Util::getMin(size, bufferSize); - - for (size_t i = 0; i < sizeToWrite; ++i) - { - buffer[i] = rand() & 0xff; - } - - if (fwrite(&buffer[0], sizeToWrite, 1, file) != 1) - { - return false; - } - - size -= sizeToWrite; - } - - return true; -} - -bool ZipDir::CacheRW::WriteNullData(size_t size) -{ - if (size <= 0) - { - return true; - } - - const size_t bufferSize = Util::getMin(size, size_t(1024 * 1024)); - std::vector buffer(bufferSize, 0); - - while (size > 0) - { - const size_t sizeToWrite = Util::getMin(size, bufferSize); - - if (fwrite(&buffer[0], sizeToWrite, 1, m_pFile) != 1) - { - return false; - } - - size -= sizeToWrite; - } - - return true; -} - -void ZipDir::CacheRW::StorePackedFile(PackFileJob* job) -{ - if (job->batch->zipMaxSize > 0 && GetTotalFileSize() > job->batch->zipMaxSize) - { - job->status = PACKFILE_SKIPPED; - job->zdError = ZipDir::ZD_ERROR_SUCCESS; - return; - } - - job->status = PACKFILE_FAILED; - - char str[_MAX_PATH]; - char* relativePath = UnifyPath(str, job->relativePathSrc); - - // create or find the file entry.. this object will rollback (delete the object - // if the operation fails) if needed. - FileEntryTransactionAdd pFileEntry(this, AllocPath(job->relativePathSrc), AllocPath(relativePath)); - - if (!pFileEntry) - { - job->zdError = ZipDir::ZD_ERROR_INVALID_PATH; - return; - } - - pFileEntry->OnNewFileData(job->uncompressedData, job->uncompressedSize, - job->compressedSize, job->batch->compressionMethod, false); - pFileEntry->SetFromFileTimeNTFS(job->modTime); - - // since we changed the time, we'll have to update CDR - m_nFlags |= FLAGS_CDR_DIRTY; - - // the new CDR position, if the operation completes successfully - unsigned lNewCDROffset = m_lCDROffset; - - if (pFileEntry->IsInitialized()) - { - // this file entry is already allocated in CDR - - // check if the new compressed data fits into the old place - unsigned nFreeSpace = pFileEntry->nEOFOffset - pFileEntry->nFileHeaderOffset - (unsigned)sizeof(ZipFile::LocalFileHeader) - (unsigned)strlen(relativePath); - - if (nFreeSpace != job->compressedSize) - { - m_nFlags |= FLAGS_UNCOMPACTED; - } - - if (nFreeSpace >= job->compressedSize) - { - // and we can just override the compressed data in the file - ErrorEnum e = WriteLocalHeader(m_pFile, pFileEntry, job->relativePathSrc, m_bEncryptedHeaders); - if (e != ZipDir::ZD_ERROR_SUCCESS) - { - job->zdError = e; - return; - } - } - else - { - // we need to write the file anew - in place of current CDR - pFileEntry->nFileHeaderOffset = CalculateAlignedHeaderOffset(job->relativePathSrc, m_lCDROffset, m_fileAlignment); - ErrorEnum e = WriteLocalHeader(m_pFile, pFileEntry, job->relativePathSrc, m_bEncryptedHeaders); - lNewCDROffset = pFileEntry->nEOFOffset; - if (e != ZipDir::ZD_ERROR_SUCCESS) - { - job->zdError = e; - return; - } - } - } - else - { - pFileEntry->nFileHeaderOffset = CalculateAlignedHeaderOffset(job->relativePathSrc, m_lCDROffset, m_fileAlignment); - ErrorEnum e = WriteLocalHeader(m_pFile, pFileEntry, job->relativePathSrc, m_bEncryptedHeaders); - if (e != ZipDir::ZD_ERROR_SUCCESS) - { - job->zdError = e; - return; - } - - lNewCDROffset = pFileEntry->nFileDataOffset + job->compressedSize; - - m_nFlags |= FLAGS_CDR_DIRTY; - } - - // now we have the fresh local header and data offset - -#ifdef WIN32 - if (_fseeki64 (m_pFile, (__int64)pFileEntry->nFileDataOffset, SEEK_SET) != 0) -#else - if (fseek (m_pFile, pFileEntry->nFileDataOffset, SEEK_SET) != 0) -#endif - { - job->zdError = ZD_ERROR_IO_FAILED; - return; - } - - const bool encrypt = pFileEntry->nMethod == ZipFile::METHOD_DEFLATE_AND_ENCRYPT; - - if (!WriteCompressedData((char*)job->compressedData, job->compressedSize, encrypt, m_pFile)) - { - job->zdError = ZD_ERROR_IO_FAILED; - return; - } - - // since we wrote the file successfully, update the new CDR position - m_lCDROffset = lNewCDROffset; - pFileEntry.Commit(); - - job->status = PACKFILE_ADDED; - job->zdError = ZD_ERROR_SUCCESS; -} - -// Adds a new file to the zip or update an existing one -// adds a directory (creates several nested directories if needed) -ZipDir::ErrorEnum ZipDir::CacheRW::UpdateFile (const char* szRelativePathSrc, void* pUncompressed, unsigned nSize, - unsigned nCompressionMethod, int nCompressionLevel, int64 modTime) -{ - char str[_MAX_PATH]; - char* szRelativePath = UnifyPath(str, szRelativePathSrc); - - - PackFileBatch batch; - batch.compressionMethod = nCompressionMethod; - batch.compressionLevel = nCompressionLevel; - - PackFileJob job; - job.relativePathSrc = szRelativePathSrc; - job.modTime = modTime; - job.uncompressedData = pUncompressed; - job.uncompressedSize = nSize; - job.batch = &batch; - - // crc will be used to check if this file need to be updated at all - ZipDir::FileEntry* entry = FindFile(szRelativePath); - if (entry) - { - job.existingCRC = entry->desc.lCRC32; - } - - PackFileFromMemory(&job); - - switch (job.status) - { - case PACKFILE_SKIPPED: - case PACKFILE_MISSING: - case PACKFILE_FAILED: - return ZD_ERROR_IO_FAILED; - } - - StorePackedFile(&job); - job.DetachUncompressedData(); - return job.zdError; -} - -static FILETIME GetFileWriteTimeAndSize(uint64* fileSize, const char* filename) -{ - // Warning: FindFirstFile on NTFS may report file size that - // is not up-to-date with the actual file content. - // http://blogs.msdn.com/b/oldnewthing/archive/2011/12/26/10251026.aspx - - FILETIME fileTime; - -#if defined(AZ_PLATFORM_WINDOWS) - WIN32_FIND_DATAA FindFileData; - HANDLE hFind = FindFirstFileA(filename, &FindFileData); - - if (hFind == INVALID_HANDLE_VALUE) - { - fileTime.dwLowDateTime = 0; - fileTime.dwHighDateTime = 0; - if (fileSize) - { - *fileSize = 0; - } - } - else - { - fileTime.dwLowDateTime = FindFileData.ftLastWriteTime.dwLowDateTime; - fileTime.dwHighDateTime = FindFileData.ftLastWriteTime.dwHighDateTime; - if (fileSize) - { - *fileSize = (uint64(FindFileData.nFileSizeHigh) << 32) + FindFileData.nFileSizeLow; - } - FindClose(hFind); - } -#elif AZ_TRAIT_OS_PLATFORM_APPLE || defined(AZ_PLATFORM_LINUX) - //We cant use this implmentation for the windows version because ModificationTime - //returns the time filename was changed(ChangeTime) not last written into(LastWriteTime). - //If LocalFileIO ever adds support for LastWriteTime we can have a common implementation. - AZ::IO::LocalFileIO localFileIO; - AZ::u64 modTime = 0; - modTime = localFileIO.ModificationTime(filename); - if(modTime != 0) - { - fileTime.dwHighDateTime = modTime >> 32; - fileTime.dwLowDateTime = modTime & 0xFFFFFFFF; - if (fileSize) - { - localFileIO.Size(filename, *fileSize); - } - } -#else -#error Needs implmentation! -#endif - return fileTime; -} -static void PackFileFromDisc(PackFileJob* job) -{ - const FILETIME ft = GetFileWriteTimeAndSize(0, job->realFilename); - LARGE_INTEGER lt; - lt.HighPart = ft.dwHighDateTime; - lt.LowPart = ft.dwLowDateTime; - job->modTime = lt.QuadPart; - - FILE* f = nullptr; - azfopen(&f, job->realFilename, "rb"); - if (!f) - { - job->status = PACKFILE_FAILED; - job->zdError = ZipDir::ZD_ERROR_FILE_NOT_FOUND; - return; - } - - fseek(f, 0, SEEK_END); - size_t fileSize = (size_t)ftell(f); - - if ((fileSize < job->batch->sourceMinSize) || (job->batch->sourceMaxSize > 0 && fileSize > job->batch->sourceMaxSize)) - { - fclose(f); - - job->status = PACKFILE_SKIPPED; - job->zdError = ZipDir::ZD_ERROR_SUCCESS; - return; - } - - if (!fileSize) - { - //Allow 0-Bytes long files. - job->uncompressedData = nullptr; - } - else - { - job->uncompressedData = azmalloc(fileSize); - - fseek(f, 0, SEEK_SET); - if (fread(job->uncompressedData, 1, fileSize, f) != fileSize) - { - azfree(job->uncompressedData); - job->uncompressedData = 0; - fclose(f); - - job->status = PACKFILE_FAILED; - job->zdError = ZipDir::ZD_ERROR_IO_FAILED; - return; - } - } - fclose(f); - job->uncompressedSize = fileSize; - - PackFileFromMemory(job); -} - -bool ZipDir::CacheRW::UpdateMultipleFiles(const char** realFilenames, const char** filenamesInZip, size_t fileCount, - int compressionLevel, bool encryptContent, size_t zipMaxSize, int sourceMinSize, int sourceMaxSize, - unsigned numExtraThreads, ZipDir::IReporter* reporter, ZipDir::ISplitter* splitter, bool useFastestDecompressionCodec) -{ - int compressionMethod = ZipFile::METHOD_DEFLATE; - if (encryptContent) - { - compressionMethod = ZipFile::METHOD_DEFLATE_AND_ENCRYPT; - } - else if (compressionLevel == 0) - { - compressionMethod = ZipFile::METHOD_STORE; - } - - uint64 totalSize = 0; - - clock_t startTime = clock(); - - PackFileBatch batch; - batch.compressionLevel = compressionLevel; - batch.compressionMethod = compressionMethod; - batch.sourceMinSize = sourceMinSize; - batch.sourceMaxSize = sourceMaxSize; - batch.zipMaxSize = zipMaxSize; - - const size_t memoryLimit = 1024 * 1024 * 1024; // prevents threads from generating more than 1GB of data - PackFilePool pool(fileCount, memoryLimit); - batch.pool = &pool; - - for (int i = 0; i < fileCount; ++i) - { - const char* realFilename = realFilenames[i]; - const char* filenameInZip = filenamesInZip[i]; - - PackFileJob job; - - job.relativePathSrc = filenameInZip; - job.realFilename = realFilename; - job.batch = &batch; - job.compressionPolicy = useFastestDecompressionCodec ? PACKFILE_USE_FASTEST_DECOMPRESSING_CODEC : PACKFILE_USE_REQUESTED_COMPRESSOR; - - { - // crc will be used to check if this file need to be updated at all - ZipDir::FileEntry* entry = FindFile(filenameInZip); - if (entry) - { - uint64 fileSize = 0; - - const FILETIME ft = GetFileWriteTimeAndSize(&fileSize, realFilename); - LARGE_INTEGER lt; - - lt.HighPart = ft.dwHighDateTime; - lt.LowPart = ft.dwLowDateTime; - job.modTime = lt.QuadPart; - job.existingCRC = entry->desc.lCRC32; - job.compressedSizePreviously = entry->desc.lSizeCompressed; - job.uncompressedSizePreviously = entry->desc.lSizeUncompressed; - - // Check if file with the same name, timestamp and size already exists in pak. - if (entry->CompareFileTimeNTFS(job.modTime) && fileSize == entry->desc.lSizeUncompressed) - { - if (reporter) - { - reporter->ReportUpToDate(filenameInZip); - } - continue; - } - } - } - - pool.Submit(i, job); - } - - // Get the number of submitted jobs, which is at most - // as large as the largest successfully submitted file-index. - // Any number of files can be skipped for submission. - const int jobCount = pool.GetJobCount(); - if (jobCount == 0) - { - return true; - } - - pool.Start(numExtraThreads); - - for (int i = 0; i < jobCount; ++i) - { - PackFileJob* job = pool.WaitForFile(i); - if (!job) - { - assert(job); - continue; - } - - if (job->status == PACKFILE_COMPRESSED) - { - if (splitter) - { - size_t dsk = GetTotalFileSizeOnDiskSoFar(); - size_t bse = 0; - size_t add = 0; - size_t sub = 0; - - bse += sizeof(ZipFile::CDRFileHeader) + strlen(job->relativePathSrc); - bse += sizeof(ZipFile::LocalFileHeader) + strlen(job->relativePathSrc); - - if (job->compressedSize) - { - add += bse + job->compressedSize; - } - if (job->compressedSizePreviously) - { - sub += bse + job->compressedSizePreviously; - } - - if (splitter->CheckWriteLimit(dsk, add, sub)) - { - splitter->SetLastFile(dsk, add, sub, job->key - 1); - - // deplete the pool before leaving the loop - pool.SkipPendingFiles(); - for (; i < jobCount; ++i) - { - pool.WaitForFile(i); - pool.ReleaseFile(i); - } - - break; - } - } - - StorePackedFile(job); - } - - switch (job->status) - { - case PACKFILE_ADDED: - if (reporter) - { - reporter->ReportAdded(job->relativePathSrc); - } - - totalSize += job->uncompressedSize; - break; - case PACKFILE_MISSING: - if (reporter) - { - reporter->ReportMissing(job->realFilename); - } - break; - case PACKFILE_UPTODATE: - if (reporter) - { - reporter->ReportUpToDate(job->realFilename); - } - break; - case PACKFILE_SKIPPED: - if (reporter) - { - reporter->ReportSkipped(job->realFilename); - } - break; - default: - if (reporter) - { - reporter->ReportFailed(job->realFilename, ""); // TODO reason - } - break; - } - - pool.ReleaseFile(i); - } - - clock_t endTime = clock(); - double timeSeconds = double(endTime - startTime) / CLOCKS_PER_SEC; - double speed = (endTime - startTime) == 0 ? 0.0 : double(totalSize) / timeSeconds; - - if (reporter) - { - reporter->ReportSpeed(speed); - } - - return true; -} - - -// Adds a new file to the zip or update an existing one if it is not compressed - just stored - start a big file -ZipDir::ErrorEnum ZipDir::CacheRW::StartContinuousFileUpdate(const char* szRelativePathSrc, unsigned nSize) -{ - char str[_MAX_PATH]; - char* szRelativePath = UnifyPath(str, szRelativePathSrc); - - SmartPtr pBufferDestroyer; - - // create or find the file entry.. this object will rollback (delete the object - // if the operation fails) if needed. - FileEntryTransactionAdd pFileEntry(this, AllocPath(szRelativePathSrc), AllocPath(szRelativePath)); - - if (!pFileEntry) - { - return ZD_ERROR_INVALID_PATH; - } - - pFileEntry->OnNewFileData (NULL, nSize, nSize, ZipFile::METHOD_STORE, false); - // since we changed the time, we'll have to update CDR - m_nFlags |= FLAGS_CDR_DIRTY; - - // the new CDR position, if the operation completes successfully - unsigned lNewCDROffset = m_lCDROffset; - if (pFileEntry->IsInitialized()) - { - // check if the new compressed data fits into the old place - unsigned nFreeSpace = pFileEntry->nEOFOffset - pFileEntry->nFileHeaderOffset - (unsigned)sizeof(ZipFile::LocalFileHeader) - (unsigned)strlen(szRelativePath); - - if (nFreeSpace != nSize) - { - m_nFlags |= FLAGS_UNCOMPACTED; - } - - if (nFreeSpace >= nSize) - { - // and we can just override the compressed data in the file - ErrorEnum e = WriteLocalHeader(m_pFile, pFileEntry, szRelativePathSrc, m_bEncryptedHeaders); - if (e != ZD_ERROR_SUCCESS) - { - return e; - } - } - else - { - // we need to write the file anew - in place of current CDR - pFileEntry->nFileHeaderOffset = CalculateAlignedHeaderOffset(szRelativePathSrc, m_lCDROffset, m_fileAlignment); - ErrorEnum e = WriteLocalHeader(m_pFile, pFileEntry, szRelativePathSrc, m_bEncryptedHeaders); - lNewCDROffset = pFileEntry->nEOFOffset; - if (e != ZD_ERROR_SUCCESS) - { - return e; - } - } - } - else - { - pFileEntry->nFileHeaderOffset = CalculateAlignedHeaderOffset(szRelativePathSrc, m_lCDROffset, m_fileAlignment); - ErrorEnum e = WriteLocalHeader(m_pFile, pFileEntry, szRelativePathSrc, m_bEncryptedHeaders); - if (e != ZD_ERROR_SUCCESS) - { - return e; - } - - lNewCDROffset = pFileEntry->nFileDataOffset + nSize; - - m_nFlags |= FLAGS_CDR_DIRTY; - } - -#ifdef WIN32 - if (_fseeki64 (m_pFile, (__int64)pFileEntry->nFileDataOffset, SEEK_SET) != 0) -#else - if (fseek (m_pFile, pFileEntry->nFileDataOffset, SEEK_SET) != 0) -#endif - { - return ZD_ERROR_IO_FAILED; - } - - if (!WriteNullData(nSize)) - { - return ZD_ERROR_IO_FAILED; - } - - pFileEntry->nEOFOffset = pFileEntry->nFileDataOffset; - - // since we wrote the file successfully, update the new CDR position - m_lCDROffset = lNewCDROffset; - pFileEntry.Commit(); - - return ZD_ERROR_SUCCESS; -} - -// Adds a new file to the zip or update an existing's segment if it is not compressed - just stored -// adds a directory (creates several nested directories if needed) -ZipDir::ErrorEnum ZipDir::CacheRW::UpdateFileContinuousSegment (const char* szRelativePathSrc, [[maybe_unused]] unsigned nSize, void* pUncompressed, unsigned nSegmentSize, unsigned nOverwriteSeekPos) -{ - char str[_MAX_PATH]; - char* szRelativePath = UnifyPath(str, szRelativePathSrc); - - SmartPtr pBufferDestroyer; - - // create or find the file entry.. this object will rollback (delete the object - // if the operation fails) if needed. - FileEntryTransactionAdd pFileEntry(this, AllocPath(szRelativePathSrc), AllocPath(szRelativePath)); - - if (!pFileEntry) - { - return ZD_ERROR_INVALID_PATH; - } - - pFileEntry->OnNewFileData (pUncompressed, nSegmentSize, nSegmentSize, ZipFile::METHOD_STORE, true); - // since we changed the time, we'll have to update CDR - m_nFlags |= FLAGS_CDR_DIRTY; - - // this file entry is already allocated in CDR - unsigned lSegmentOffset = pFileEntry->nEOFOffset; - -#ifdef WIN32 - if (_fseeki64 (m_pFile, (__int64)pFileEntry->nFileHeaderOffset, SEEK_SET) != 0) -#else - if (fseek (m_pFile, pFileEntry->nFileHeaderOffset, SEEK_SET) != 0) -#endif - { - return ZD_ERROR_IO_FAILED; - } - - // and we can just override the compressed data in the file - ErrorEnum e = WriteLocalHeader(m_pFile, pFileEntry, szRelativePath, m_bEncryptedHeaders); - if (e != ZD_ERROR_SUCCESS) - { - return e; - } - - if (nOverwriteSeekPos != 0xffffffff) - { - lSegmentOffset = pFileEntry->nFileDataOffset + nOverwriteSeekPos; - } - - // now we have the fresh local header and data offset -#ifdef WIN32 - if (_fseeki64 (m_pFile, (__int64)lSegmentOffset, SEEK_SET) != 0) -#else - if (fseek (m_pFile, lSegmentOffset, SEEK_SET) != 0) -#endif - { - return ZD_ERROR_IO_FAILED; - } - - const bool encrypt = false; // encryption is not supported for continous updates - if (!WriteCompressedData((char*)pUncompressed, nSegmentSize, encrypt, m_pFile)) - { - return ZD_ERROR_IO_FAILED; - } - - if (nOverwriteSeekPos == 0xffffffff) - { - pFileEntry->nEOFOffset = lSegmentOffset + nSegmentSize; - } - - // since we wrote the file successfully, update CDR - pFileEntry.Commit(); - return ZD_ERROR_SUCCESS; -} - - -ZipDir::ErrorEnum ZipDir::CacheRW::UpdateFileCRC (const char* szRelativePathSrc, unsigned dwCRC32) -{ - char str[_MAX_PATH]; - char* szRelativePath = UnifyPath(str, szRelativePathSrc); - - SmartPtr pBufferDestroyer; - - // create or find the file entry.. this object will rollback (delete the object - // if the operation fails) if needed. - FileEntryTransactionAdd pFileEntry(this, AllocPath(szRelativePathSrc), AllocPath(szRelativePath)); - - if (!pFileEntry) - { - return ZD_ERROR_INVALID_PATH; - } - - // since we changed the time, we'll have to update CDR - m_nFlags |= FLAGS_CDR_DIRTY; - - pFileEntry->desc.lCRC32 = dwCRC32; - -#ifdef WIN32 - if (_fseeki64 (m_pFile, (__int64)pFileEntry->nFileHeaderOffset, SEEK_SET) != 0) -#else - if (fseek (m_pFile, pFileEntry->nFileHeaderOffset, SEEK_SET) != 0) -#endif - { - return ZD_ERROR_IO_FAILED; - } - - // and we can just override the compressed data in the file - ErrorEnum e = WriteLocalHeader(m_pFile, pFileEntry, szRelativePath, m_bEncryptedHeaders); - if (e != ZD_ERROR_SUCCESS) - { - return e; - } - - // since we wrote the file successfully, update - pFileEntry.Commit(); - return ZD_ERROR_SUCCESS; -} - - -// deletes the file from the archive -ZipDir::ErrorEnum ZipDir::CacheRW::RemoveFile (const char* szRelativePathSrc) -{ - char str[_MAX_PATH]; - char* szRelativePath = UnifyPath(str, szRelativePathSrc); - - // find the last slash in the path - const char* pSlash = (std::max)(strrchr(szRelativePath, '/'), strrchr(szRelativePath, '\\')); - - const char* pFileName; // the name of the file to delete - - FileEntryTree* pDir; // the dir from which the subdir will be deleted - - if (pSlash) - { - FindDirRW fd (GetRoot()); - // the directory to remove - pDir = fd.FindExact(string (szRelativePath, pSlash - szRelativePath).c_str()); - if (!pDir) - { - return ZD_ERROR_DIR_NOT_FOUND;// there is no such directory - } - pFileName = pSlash + 1; - } - else - { - pDir = GetRoot(); - pFileName = szRelativePath; - } - - ErrorEnum e = pDir->RemoveFile (pFileName); - if (e == ZD_ERROR_SUCCESS) - { - m_nFlags |= FLAGS_UNCOMPACTED | FLAGS_CDR_DIRTY; - } - return e; -} - - -// deletes the directory, with all its descendants (files and subdirs) -ZipDir::ErrorEnum ZipDir::CacheRW::RemoveDir (const char* szRelativePathSrc) -{ - char str[_MAX_PATH]; - char* szRelativePath = UnifyPath(str, szRelativePathSrc); - - // find the last slash in the path - const char* pSlash = (std::max)(strrchr(szRelativePath, '/'), strrchr(szRelativePath, '\\')); - - const char* pDirName; // the name of the dir to delete - - FileEntryTree* pDir; // the dir from which the subdir will be deleted - - if (pSlash) - { - FindDirRW fd (GetRoot()); - // the directory to remove - pDir = fd.FindExact(string (szRelativePath, pSlash - szRelativePath).c_str()); - if (!pDir) - { - return ZD_ERROR_DIR_NOT_FOUND;// there is no such directory - } - pDirName = pSlash + 1; - } - else - { - pDir = GetRoot(); - pDirName = szRelativePath; - } - - ErrorEnum e = pDir->RemoveDir (pDirName); - if (e == ZD_ERROR_SUCCESS) - { - m_nFlags |= FLAGS_UNCOMPACTED | FLAGS_CDR_DIRTY; - } - return e; -} - -// deletes all files and directories in this archive -ZipDir::ErrorEnum ZipDir::CacheRW::RemoveAll() -{ - ErrorEnum e = m_treeDir.RemoveAll(); - if (e == ZD_ERROR_SUCCESS) - { - m_nFlags |= FLAGS_UNCOMPACTED | FLAGS_CDR_DIRTY; - } - return e; -} - -ZipDir::ErrorEnum ZipDir::CacheRW::ReadFile (FileEntry* pFileEntry, void* pCompressed, void* pUncompressed) -{ - if (!pFileEntry) - { - return ZD_ERROR_INVALID_CALL; - } - - if (pFileEntry->desc.lSizeUncompressed == 0) - { - assert (pFileEntry->desc.lSizeCompressed == 0); - return ZD_ERROR_SUCCESS; - } - - assert (pFileEntry->desc.lSizeCompressed > 0); - - ErrorEnum nError = Refresh(pFileEntry); - if (nError != ZD_ERROR_SUCCESS) - { - return nError; - } - -#ifdef WIN32 - if (_fseeki64 (m_pFile, (__int64)pFileEntry->nFileDataOffset, SEEK_SET)) -#else - if (fseek (m_pFile, pFileEntry->nFileDataOffset, SEEK_SET)) -#endif - { - return ZD_ERROR_IO_FAILED; - } - - SmartPtr pBufferDestroyer; - - void* pBuffer = pCompressed; // the buffer where the compressed data will go - - if (pFileEntry->nMethod == 0 && pUncompressed) - { - // we can directly read into the uncompress buffer - pBuffer = pUncompressed; - } - - if (!pBuffer) - { - if (!pUncompressed) - { - // what's the sense of it - no buffers at all? - return ZD_ERROR_INVALID_CALL; - } - - pBuffer = azmalloc(pFileEntry->desc.lSizeCompressed); - pBufferDestroyer.Attach(pBuffer); // we want it auto-freed once we return - } - - if (fread((char*)pBuffer, pFileEntry->desc.lSizeCompressed, 1, m_pFile) != 1) - { - return ZD_ERROR_IO_FAILED; - } - - if (pFileEntry->nMethod == ZipFile::METHOD_DEFLATE_AND_ENCRYPT) - { - ZipDir::Decrypt((char*)pBuffer, pFileEntry->desc.lSizeCompressed, m_encryptionKey); - } - - // if there's a buffer for uncompressed data, uncompress it to that buffer - if (pUncompressed) - { - if (pFileEntry->nMethod == 0) - { - assert (pBuffer == pUncompressed); - //assert (pFileEntry->nSizeCompressed == pFileEntry->nSizeUncompressed); - //memcpy (pUncompressed, pBuffer, pFileEntry->nSizeCompressed); - } - else - { - unsigned long nSizeUncompressed = pFileEntry->desc.lSizeUncompressed; - if (nSizeUncompressed > 0) - { - if (Z_OK != ZipRawUncompress(pUncompressed, &nSizeUncompressed, pBuffer, pFileEntry->desc.lSizeCompressed)) - { - return ZD_ERROR_CORRUPTED_DATA; - } - } - } - } - - return ZD_ERROR_SUCCESS; -} - - -////////////////////////////////////////////////////////////////////////// -// finds the file by exact path -ZipDir::FileEntry* ZipDir::CacheRW::FindFile (const char* szPathSrc, [[maybe_unused]] bool bFullInfo) -{ - char str[_MAX_PATH]; - char* szPath = UnifyPath(str, szPathSrc); - - ZipDir::FindFileRW fd (GetRoot()); - if (!fd.FindExact(szPath)) - { - assert (!fd.GetFileEntry()); - return NULL; - } - assert (fd.GetFileEntry()); - return fd.GetFileEntry(); -} - -// returns the size of memory occupied by the instance referred to by this cache -size_t ZipDir::CacheRW::GetSize() const -{ - return sizeof(*this) + m_strFilePath.capacity() + m_treeDir.GetSize() - sizeof(m_treeDir); -} - -// returns the compressed size of all the entries -size_t ZipDir::CacheRW::GetCompressedSize() const -{ - return m_treeDir.GetCompressedFileSize(); -} - -// returns the total size of memory occupied by the instance of this cache and all the compressed files -size_t ZipDir::CacheRW::GetTotalFileSize() const -{ - return GetSize() + GetCompressedSize(); -} - -// returns the total size of space occupied on disk by the instance of this cache and all the compressed files -size_t ZipDir::CacheRW::GetTotalFileSizeOnDiskSoFar() -{ - FileRecordList arrFiles(GetRoot()); - FileRecordList::ZipStats statFiles = arrFiles.GetStats(); - - return m_lCDROffset + statFiles.nSizeCDR; -} - -// refreshes information about the given file entry into this file entry -ZipDir::ErrorEnum ZipDir::CacheRW::Refresh (FileEntry* pFileEntry) -{ - if (!pFileEntry) - { - return ZD_ERROR_INVALID_CALL; - } - - if (pFileEntry->nFileDataOffset != pFileEntry->INVALID_DATA_OFFSET) - { - return ZD_ERROR_SUCCESS; // the data offset has been successfully read.. - } - - return ZipDir::Refresh(m_pFile, pFileEntry, m_bEncryptedHeaders); -} - - -// writes the CDR to the disk -bool ZipDir::CacheRW::WriteCDR(FILE* fTarget, bool encryptCDR) -{ - if (!fTarget) - { - return false; - } - -#ifdef WIN32 - if (_fseeki64(fTarget, (__int64)m_lCDROffset, SEEK_SET)) -#else - if (fseek(fTarget, m_lCDROffset, SEEK_SET)) -#endif - { - return false; - } - - FileRecordList arrFiles(GetRoot()); - //arrFiles.SortByFileOffset(); - size_t nSizeCDR = arrFiles.GetStats().nSizeCDR; - void* pCDR = malloc(nSizeCDR); -#if !defined(NDEBUG) - size_t nSizeCDRSerialized = -#endif - arrFiles.MakeZipCDR(m_lCDROffset, pCDR, encryptCDR); - assert (nSizeCDRSerialized == nSizeCDR); - - if (encryptCDR) - { - // We do not encrypt CDREnd, so we could find it by signature - ZipDir::Encrypt((char*)pCDR, nSizeCDR - sizeof(ZipFile::CDREnd), m_encryptionKey); - } - - size_t nWriteRes = fwrite (pCDR, nSizeCDR, 1, fTarget); - free(pCDR); - return nWriteRes == 1; -} - -// generates random file name -string ZipDir::CacheRW::GetRandomName(int nAttempt) -{ - if (nAttempt) - { - char szBuf[8]; - int i; - for (i = 0; i < sizeof(szBuf) - 1; ++i) - { - int r = rand() % (10 + 'z' - 'a' + 1); - szBuf[i] = r > 9 ? (r - 10) + 'a' : '0' + r; - } - szBuf[i] = '\0'; - return szBuf; - } - else - { - return string(); - } -} - -bool ZipDir::CacheRW::RelinkZip() -{ - AZ::IO::LocalFileIO localFileIO; - for (int nAttempt = 0; nAttempt < 32; ++nAttempt) - { - string strNewFilePath = m_strFilePath + "$" + GetRandomName(nAttempt); - - FILE* f = nullptr; - azfopen(&f, strNewFilePath.c_str(), "wb"); - if (f) - { - bool bOk = RelinkZip(f); - fclose (f); // we don't need the temporary file handle anyway - - if (!bOk) - { - // we don't need the temporary file - localFileIO.Remove(strNewFilePath.c_str()); - return false; - } - - // we successfully relinked, now copy the temporary file to the original file - fclose (m_pFile); - m_pFile = NULL; - - localFileIO.Remove(m_strFilePath.c_str()); - if (localFileIO.Rename(strNewFilePath.c_str(), m_strFilePath.c_str()) == 0) - { - // successfully renamed - reopen - m_pFile = nullptr; - azfopen(&m_pFile, m_strFilePath.c_str(), "r+b"); - return m_pFile == NULL; - } - else - { - // could not rename - - //m_pFile = fopen (strNewFilePath.c_str(), "r+b"); - return false; - } - } - } - - // couldn't open temp file - return false; -} - -bool ZipDir::CacheRW::RelinkZip(FILE* fTmp) -{ - FileRecordList arrFiles(GetRoot()); - arrFiles.SortByFileOffset(); - FileRecordList::ZipStats Stats = arrFiles.GetStats(); - - // we back up our file entries, because we'll need to restore them - // in case the operation fails - std::vector arrFileEntryBackup; - arrFiles.Backup (arrFileEntryBackup); - - // this is the set of files that are to be written out - compressed data and the file record iterator - std::vector queFiles; - queFiles.reserve (g_nMaxItemsRelinkBuffer); - - // the total size of data in the queue - unsigned nQueueSize = 0; - - for (FileRecordList::iterator it = arrFiles.begin(); it != arrFiles.end(); ++it) - { - FileEntry* entry = it->pFileEntry; - // find the file data offset - if (ZD_ERROR_SUCCESS != Refresh(entry)) - { - return false; - } - - // go to the file data -#ifdef WIN32 - if (_fseeki64 (m_pFile, (__int64)entry->nFileDataOffset, SEEK_SET) != 0) -#else - if (fseek (m_pFile, entry->nFileDataOffset, SEEK_SET) != 0) -#endif - { - return false; - } - - // allocate memory for the file compressed data - FileDataRecordPtr pFile = FileDataRecord::New (*it); - - if (!pFile) - { - return false; - } - - // read the compressed data - if (entry->desc.lSizeCompressed && fread (pFile->GetData(), entry->desc.lSizeCompressed, 1, m_pFile) != 1) - { - return false; - } - - if (entry->nMethod == ZipFile::METHOD_DEFLATE_AND_ENCRYPT) - { - ZipDir::Decrypt((char*)pFile->GetData(), entry->desc.lSizeCompressed, m_encryptionKey); - } - - // put the file into the queue for copying (writing) - queFiles.push_back(pFile); - nQueueSize += entry->desc.lSizeCompressed; - - // if the queue is big enough, write it out - if (nQueueSize > g_nSizeRelinkBuffer || queFiles.size() >= g_nMaxItemsRelinkBuffer) - { - nQueueSize = 0; - if (!WriteZipFiles(queFiles, fTmp)) - { - return false; - } - } - } - - if (!WriteZipFiles(queFiles, fTmp)) - { - return false; - } - - ZipFile::ulong lOldCDROffset = m_lCDROffset; - // the file data has now been written out. Now write the CDR -#ifdef WIN32 - m_lCDROffset = (ZipFile::ulong)_ftelli64(fTmp); -#else - m_lCDROffset = ftell(fTmp); -#endif - if (m_lCDROffset >= 0 && WriteCDR(fTmp, m_bHeadersEncryptedOnClose) && 0 == fflush (fTmp)) - { - // the new file positions are already there - just discard the backup and return - return true; - } - // recover from backup - arrFiles.Restore (arrFileEntryBackup); - m_lCDROffset = lOldCDROffset; - m_bEncryptedHeaders = m_bHeadersEncryptedOnClose; - return false; -} - -// writes out the file data in the queue into the given file. Empties the queue -bool ZipDir::CacheRW::WriteZipFiles(std::vector& queFiles, FILE* fTmp) -{ - for (std::vector::iterator it = queFiles.begin(); it != queFiles.end(); ++it) - { - // set the new header offset to the file entry - we won't need it -#ifdef WIN32 - const unsigned long currentPos = (unsigned long)_ftelli64 (fTmp); -#else - const unsigned long currentPos = ftell (fTmp); -#endif - (*it)->pFileEntry->nFileHeaderOffset = CalculateAlignedHeaderOffset((*it)->strPath.c_str(), currentPos, m_fileAlignment); - - // while writing the local header, the data offset will also be calculated - if (ZD_ERROR_SUCCESS != WriteLocalHeader(fTmp, (*it)->pFileEntry, (*it)->strPath.c_str(), m_bHeadersEncryptedOnClose)) - { - return false; - } - ; - - // write the compressed file data - const bool encrypt = (*it)->pFileEntry->nMethod == ZipFile::METHOD_DEFLATE_AND_ENCRYPT; - if (!WriteCompressedData((char*)(*it)->GetData(), (*it)->pFileEntry->desc.lSizeCompressed, encrypt, fTmp)) - { - return false; - } - -#ifdef WIN32 - assert ((*it)->pFileEntry->nEOFOffset == (unsigned long)_ftelli64 (fTmp)); -#else - assert ((*it)->pFileEntry->nEOFOffset == ftell (fTmp)); -#endif - } - queFiles.clear(); - queFiles.reserve (g_nMaxItemsRelinkBuffer); - return true; -} - -void TruncateFile(FILE* file, size_t newLength) -{ -#if defined(AZ_PLATFORM_WINDOWS) - int filedes = _fileno(file); - _chsize_s(filedes, newLength); -#elif AZ_TRAIT_OS_PLATFORM_APPLE || defined(AZ_PLATFORM_LINUX) - ftruncate(fileno(file), newLength); -#else -#error Not implemented! -#endif -} - -bool ZipDir::CacheRW::EncryptArchive(EncryptionChange change, IEncryptPredicate* encryptContentPredicate, int* numChanged, int* numSkipped) -{ - FileRecordList arrFiles(GetRoot()); - arrFiles.SortByFileOffset(); - - size_t unusedSpace = 0; - size_t lastDataEnd = 0; - - for (FileRecordList::iterator it = arrFiles.begin(); it != arrFiles.end(); ++it) - { - FileEntry* entry = it->pFileEntry; - - if (entry->nFileHeaderOffset > lastDataEnd) - { - fseek(m_pFile, lastDataEnd, SEEK_SET); - size_t gapLength = entry->nFileHeaderOffset - lastDataEnd; - unusedSpace += gapLength; - if (change == ENCRYPT) - { - if (!WriteRandomData(m_pFile, gapLength)) - { - return false; - } - } - else - { - if (!WriteNullData(gapLength)) - { - return false; - } - } - } - lastDataEnd = entry->nEOFOffset; - - if (numSkipped) - { - ++(*numSkipped); - } - - // find the file data offset - if (ZD_ERROR_SUCCESS != Refresh (entry)) - { - return false; - } - - ZipFile::ushort oldMethod = entry->nMethod; - ZipFile::ushort newMethod = oldMethod; - if (change == ENCRYPT) - { - if (entry->nMethod == ZipFile::METHOD_DEFLATE) - { - newMethod = ZipFile::METHOD_DEFLATE_AND_ENCRYPT; - } - } - else - { - if (entry->nMethod == ZipFile::METHOD_DEFLATE_AND_ENCRYPT) - { - newMethod = ZipFile::METHOD_DEFLATE; - } - } - - // allow encryption only for matching files - if (newMethod == ZipFile::METHOD_DEFLATE_AND_ENCRYPT && - (!encryptContentPredicate || !encryptContentPredicate->Match(it->strPath.c_str()))) - { - newMethod = ZipFile::METHOD_DEFLATE; - } - - entry->nMethod = newMethod; - - const bool encryptHeaders = change == ENCRYPT; - // encryption is toggled or compression method changed... - if (newMethod != oldMethod || encryptHeaders != m_bEncryptedHeaders) - { - // ... update header - if (ZipDir::WriteLocalHeader(m_pFile, entry, it->strPath.c_str(), encryptHeaders) != ZD_ERROR_SUCCESS) - { - return false; - } - } - - if (newMethod == oldMethod) - { - // no need to update file content - continue; - } - - // go to the file data -#ifdef WIN32 - if (_fseeki64 (m_pFile, (__int64)entry->nFileDataOffset, SEEK_SET) != 0) -#else - if (fseek (m_pFile, entry->nFileDataOffset, SEEK_SET) != 0) -#endif - { - return false; - } - - // allocate memory for the file compressed data - FileDataRecordPtr pFile = FileDataRecord::New(*it); - if (!pFile) - { - return false; - } - - // read the compressed data - if (entry->desc.lSizeCompressed && fread (pFile->GetData(), entry->desc.lSizeCompressed, 1, m_pFile) != 1) - { - return false; - } - - if (oldMethod == ZipFile::METHOD_DEFLATE_AND_ENCRYPT) - { - ZipDir::Decrypt((char*)pFile->GetData(), entry->desc.lSizeCompressed, m_encryptionKey); - } - -#ifdef WIN32 - if (_fseeki64 (m_pFile, (__int64)entry->nFileDataOffset, SEEK_SET) != 0) -#else - if (fseek (m_pFile, entry->nFileDataOffset, SEEK_SET) != 0) -#endif - { - return false; - } - - const bool encryptContent = newMethod == ZipFile::METHOD_DEFLATE_AND_ENCRYPT; - if (!WriteCompressedData((const char*)pFile->GetData(), entry->desc.lSizeCompressed, encryptContent, m_pFile)) - { - return false; - } - - if (numSkipped) - { - --(*numSkipped); - } - if (numChanged) - { - ++(*numChanged); - } - } - - m_bEncryptedHeaders = change == ENCRYPT; - m_bHeadersEncryptedOnClose = m_bEncryptedHeaders; - - if (!WriteCDR(m_pFile, m_bEncryptedHeaders)) - { - return false; - } - - if (fflush (m_pFile) != 0) - { - return false; - } - - size_t endOfCDR = (size_t)ftell(m_pFile); - - fseek(m_pFile, 0, SEEK_END); - size_t fileSize = (size_t)ftell(m_pFile); - - if (fileSize != endOfCDR) - { - TruncateFile(m_pFile, endOfCDR); - } - - fclose(m_pFile); - m_pFile = 0; - m_treeDir.Clear(); - return true; -} diff --git a/Code/Tools/CryCommonTools/ZipDir/ZipDirCacheRW.h b/Code/Tools/CryCommonTools/ZipDir/ZipDirCacheRW.h deleted file mode 100644 index 6c02d34bf3..0000000000 --- a/Code/Tools/CryCommonTools/ZipDir/ZipDirCacheRW.h +++ /dev/null @@ -1,283 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -////////////////////////////////////////////////////////////////////////// -// Declaration of the class that will keep the ZipDir Cache object -// and will provide all its services to access Zip file, plus it will -// provide services to write to the zip file efficiently -// Time to time, the contained Cache object will be recreated during -// an archive add operation - -#pragma once - -#include "SimpleStringPool.h" -#include "StringUtils.h" - -struct PackFileJob; -namespace ZipDir -{ - struct FileDataRecord; - TYPEDEF_AUTOPTR(FileDataRecord); - typedef FileDataRecord_AutoPtr FileDataRecordPtr; - - static constexpr int TARGET_MIN_TEST_COMPRESS_BYTES = 128 * 1024; - - struct IReporter - { - virtual void ReportAdded(const char* filename) = 0; - virtual void ReportMissing(const char* filename) = 0; - virtual void ReportUpToDate(const char* filename) = 0; - virtual void ReportSkipped(const char* filename) = 0; - virtual void ReportFailed(const char* filename, const char* error) = 0; - virtual void ReportSpeed(double bytesPerSecond) = 0; - }; - - struct ISplitter - { - // Arguments: - // total - the current size of the pak - // add - the size of the file to add - // sub - the size of the old version of the file which will be removed from the pak - // Return: - // true if adding the current file to the current pak is still permitted. - virtual bool CheckWriteLimit(size_t total, size_t add, size_t sub) const = 0; - - // Arguments: - // total - the current size of the pak - // add - the size of the file to add - // sub - the size of the old version of the file which will be removed from the pak - // offset - the position of the first file which has not been added to the pak - // in the array passed to "UpdateMultipleFiles()" - virtual void SetLastFile(size_t total, size_t add, size_t sub, int offset) = 0; - }; - - struct IEncryptPredicate - { - virtual ~IEncryptPredicate() = default; - virtual bool Match(const char* filename) = 0; - }; - - class CacheRW - { - public: - enum EncryptionChange - { - ENCRYPT, - DECRYPT - }; - // the size of the buffer that's using during re-linking the zip file - enum - { - g_nSizeRelinkBuffer = 128 * 1024 * 1024, // 128 Mbytes - g_nMaxItemsRelinkBuffer = 1024 // max number of files to read before (without) writing - }; - - void AddRef(); - void Release(); - - - CacheRW(bool encryptHeaders, const EncryptionKey& encryptionKey); - ~CacheRW(); - - bool IsValid () const - { - return m_pFile != NULL; - } - - static char* UnifyPath(char* const str, const char* pPath); - static char* ToUnixPath(char* const str, const char* pPath); - char* AllocPath(const char* pPath); - - // opens the given zip file and connects to it. Creates a new file if no such file exists - // if successful, returns true. - //ErrorEnum Open (CMTSafeHeap* pHeap, InitMethodEnum nInitMethod, unsigned nFlags, const char* szFile); - - // Adds a new file to the zip or update an existing one - // adds a directory (creates several nested directories if needed) - ErrorEnum UpdateFile(const char* szRelativePath, void* pUncompressed, unsigned nSize, unsigned nCompressionMethod, int nCompressionLevel, int64 modTime); - - // Sets if Archive should be encrypted or decrypted on close. - bool EncryptArchive(EncryptionChange change, IEncryptPredicate* encryptContentPredicate, int* numChanged, int* numSkipped); - - // Adds or updates a bunch of files. Creates directories if needed. Multithreaded when numExtraThreads > 0 - bool UpdateMultipleFiles(const char** realFilenames, const char** filenamesInZip, size_t fileCount, - int compressionLevel, bool encryptContent, size_t zipMaxSize, int sourceMinSize, int sourceMaxSize, - unsigned numExtraThreads, ZipDir::IReporter* reporter, ZipDir::ISplitter* splitter = nullptr, bool useFastestDecompressionCodec = false); - - // Adds a new file to the zip or update an existing one if it is not compressed - just stored - start a big file - ErrorEnum StartContinuousFileUpdate(const char* szRelativePath, unsigned nSize); - - // Adds a new file to the zip or update an existing's segment if it is not compressed - just stored - // adds a directory (creates several nested directories if needed) - // Arguments: - // nOverwriteSeekPos - 0xffffffff means the seek pos should not be overwritten - ErrorEnum UpdateFileContinuousSegment (const char* szRelativePath, unsigned nSize, void* pUncompressed, unsigned nSegmentSize, unsigned nOverwriteSeekPos); - - ErrorEnum UpdateFileCRC(const char* szRelativePath, unsigned dwCRC32); - - // deletes the file from the archive - ErrorEnum RemoveFile(const char* szRelativePath); - - // deletes the directory, with all its descendants (files and subdirs) - ErrorEnum RemoveDir(const char* szRelativePath); - - // deletes all files and directories in this archive - ErrorEnum RemoveAll(); - - // closes the current zip file - void Close(); - - FileEntry* FindFile(const char* szPath, bool bFullInfo = false); - - ErrorEnum ReadFile(FileEntry* pFileEntry, void* pCompressed, void* pUncompressed); - - void* AllocAndReadFile (FileEntry* pFileEntry); - - void Free (void* p) - { - free(p); - } - - // refreshes information about the given file entry into this file entry - ErrorEnum Refresh (FileEntry* pFileEntry); - - // returns the size of memory occupied by the instance of this cache - size_t GetSize() const; - - // returns the compressed size of all the entries - size_t GetCompressedSize() const; - - // returns the total size of memory occupied by the instance of this cache and all the compressed files - size_t GetTotalFileSize() const; - - // returns the total size of space occupied on disk by the instance of this cache and all the compressed files - size_t GetTotalFileSizeOnDiskSoFar(); - - // QUICK check to determine whether the file entry belongs to this object - bool IsOwnerOf (const FileEntry* pFileEntry) const - { - return m_treeDir.IsOwnerOf(pFileEntry); - } - - // returns the string - path to the zip file from which this object was constructed. - // this will be "" if the object was constructed with a factory that wasn't created with FLAGS_MEMORIZE_ZIP_PATH - const char* GetFilePath() const - { - return m_strFilePath.c_str(); - } - - FileEntryTree* GetRoot() - { - return &m_treeDir; - } - - const FileEntryTree* GetRoot() const - { - return &m_treeDir; - } - - // writes the CDR to the disk - bool WriteCDR() {return WriteCDR(m_pFile, m_bEncryptedHeaders); } - bool WriteCDR(FILE* fTarget, bool encryptHeaders); - - bool RelinkZip(); - protected: - bool RelinkZip(FILE* fTmp); - // writes out the file data in the queue into the given file. Empties the queue - bool WriteZipFiles(std::vector& queFiles, FILE* fTmp); - // generates random file name - string GetRandomName(int nAttempt); - - bool ReadCompressedData(char* data, size_t size); - bool WriteCompressedData(const char* data, size_t size, bool encrypt, FILE* file); - bool WriteNullData(size_t size); - - void StorePackedFile(PackFileJob* job); - protected: - - friend class CacheFactory; - volatile signed int m_nRefCount; // the reference count - FileEntryTree m_treeDir; - FILE* m_pFile; - string m_strFilePath; - - // offset to the start of CDR in the file,even if there's no CDR there currently - // when a new file is added, it can start from here, but this value will need to be updated then - ZipFile::ulong m_lCDROffset; - - CSimpleStringPool m_tempStringPool; - - enum - { - // if this is set, the file needs to be compacted before it can be used by - // all standard zip tools, because gaps between file datas can be present - FLAGS_UNCOMPACTED = 1 << 0, - // if this is set, the CDR needs to be written to the file - FLAGS_CDR_DIRTY = 1 << 1, - // if this is set, the file is opened in read-only mode. no write operations are to be performed - FLAGS_READ_ONLY = 1 << 2, - // when this is set, compact operation is not performed - FLAGS_DONT_COMPACT = 1 << 3 - }; - unsigned m_nFlags; - size_t m_fileAlignment; - - // CDR buffer. - DynArray m_CDR_buffer; - // unified names buffer - DynArray m_unifiedNameBuffer; - - EncryptionKey m_encryptionKey; - bool m_bEncryptedHeaders; - bool m_bHeadersEncryptedOnClose; - }; - - TYPEDEF_AUTOPTR(CacheRW); - typedef CacheRW_AutoPtr CacheRWPtr; - - // creates and if needed automatically destroys the file entry - class FileEntryTransactionAdd - { - class CacheRW* m_pCache; - char m_szPath[_MAX_PATH]; - FileEntry* m_pFileEntry; - bool m_bComitted; - public: - operator FileEntry* () { - return m_pFileEntry; - } - operator bool() const{ - return m_pFileEntry != NULL; - } - FileEntry* operator -> () {return m_pFileEntry; } - FileEntryTransactionAdd(class CacheRW* pCache, char* szPath, char* szUnifiedPath) - : m_pCache(pCache) - , m_bComitted (false) - { - // we need to copy path, because original one will be destroyed by FileEntryTree::Add call - cry_strcpy(m_szPath, szUnifiedPath); - m_pFileEntry = m_pCache->GetRoot()->Add(szPath, szUnifiedPath); - } - ~FileEntryTransactionAdd() - { - if (m_pFileEntry && !m_bComitted) - { - m_pCache->RemoveFile(m_szPath); - } - } - void Commit() - { - m_bComitted = true; - } - }; -} diff --git a/Code/Tools/CryCommonTools/ZipDir/ZipDirFind.cpp b/Code/Tools/CryCommonTools/ZipDir/ZipDirFind.cpp deleted file mode 100644 index c62428f0b1..0000000000 --- a/Code/Tools/CryCommonTools/ZipDir/ZipDirFind.cpp +++ /dev/null @@ -1,246 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - - -#include "smartptr.h" -#include "ZipFileFormat.h" -#include "zipdirstructures.h" -#include "ZipDirCache.h" -#include "ZipDirFind.h" -#include "StringHelpers.h" - -bool ZipDir::FindFile::FindFirst (const char* szWildcard) -{ - if (!PreFind (szWildcard)) - { - return false; - } - - // finally, this is the name of the file - m_nFileEntry = 0; - return SkipNonMatchingFiles(); -} - -bool ZipDir::FindDir::FindFirst (const char* szWildcard) -{ - if (!PreFind (szWildcard)) - { - return false; - } - - // finally, this is the name of the file - m_nDirEntry = 0; - return SkipNonMatchingDirs(); -} - -// matches the file wilcard in the m_szWildcard to the given file/dir name -// this takes into account the fact that xxx. is the alias name for xxx -bool ZipDir::FindData::MatchWildcard(const char* szName) -{ - if (StringHelpers::MatchesWildcards(szName, m_szWildcard)) - { - return true; - } - - // check if the file object name contains extension sign (.) - const char* p; - for (p = szName; *p && *p != '.'; ++p) - { - continue; - } - - if (*p) - { - // there's an extension sign in the object, but it wasn't matched.. - assert (*p == '.'); - return false; - } - - // no extension sign - add it - char szAlias[_MAX_PATH + 2]; - size_t nLength = p - szName; - if (nLength > _MAX_PATH) - { - nLength = _MAX_PATH; - } - memcpy (szAlias, szName, nLength); - szAlias[nLength] = '.'; // add the alias - szAlias[nLength + 1] = '\0'; // terminate the string - return StringHelpers::MatchesWildcards(szAlias, m_szWildcard); -} - - -ZipDir::FileEntry* ZipDir::FindFile::FindExact (const char* szPath) -{ - if (!PreFind (szPath)) - { - return NULL; - } - - FileEntry* pFileEntry = m_pDirHeader->FindFileEntry(m_szWildcard); - if (pFileEntry) - { - m_nFileEntry = (unsigned)(pFileEntry - m_pDirHeader->GetFileEntry(0)); - } - else - { - m_pDirHeader = NULL; // we didn't find it, fail the search - } - return pFileEntry; -} - -////////////////////////////////////////////////////////////////////////// -// after this call returns successfully (with true returned), the m_szWildcard -// contains the file name/wildcard and m_pDirHeader contains the directory where -// the file (s) are to be found -bool ZipDir::FindData::PreFind (const char* szWildcard) -{ - if (!m_pRoot) - { - return false; - } - - // start the search from the root - m_pDirHeader = m_pRoot; - - // for each path dir name, copy it into the buffer and try to find the subdirectory - const char* pPath = szWildcard; - for (;; ) - { - char* pName = m_szWildcard; - - // at first we'll use the wildcard memory to save the directory names - for (; *pPath && *pPath != '/' && *pPath != '\\' && pName < m_szWildcard + sizeof(m_szWildcard) - 1; ++pPath, ++pName) - { - *pName = ::tolower(*pPath); - } - *pName = '\0'; - - if (*pPath) - { - if (*pPath != '/' && *pPath != '\\') - { - return false;//ZD_ERROR_NAME_TOO_LONG; - } - // this is the name of the directory - DirEntry* pDirEntry = m_pDirHeader->FindSubdirEntry(m_szWildcard); - if (!pDirEntry) - { - m_pDirHeader = NULL; // finish the search - return false; - } - m_pDirHeader = pDirEntry->GetDirectory(); - ++pPath; - assert(m_pDirHeader); - } - else - { - // finally, this is the name of the file (or directory) - return true; - } - } -} - -// goes on to the next entry -bool ZipDir::FindFile::FindNext () -{ - if (m_pDirHeader && m_nFileEntry < m_pDirHeader->numFiles) - { - ++m_nFileEntry; - return SkipNonMatchingFiles(); - } - else - { - return false; - } -} - -// goes on to the next entry -bool ZipDir::FindDir::FindNext () -{ - if (m_pDirHeader && m_nDirEntry < m_pDirHeader->numDirs) - { - ++m_nDirEntry; - return SkipNonMatchingDirs(); - } - else - { - return false; - } -} - -bool ZipDir::FindFile::SkipNonMatchingFiles() -{ - assert(m_pDirHeader && m_nFileEntry <= m_pDirHeader->numFiles); - - for (; m_nFileEntry < m_pDirHeader->numFiles; ++m_nFileEntry) - { - if (MatchWildcard(GetFileName())) - { - return true; - } - } - // we didn't find anything other file else - return false; -} - -bool ZipDir::FindDir::SkipNonMatchingDirs() -{ - assert(m_pDirHeader && m_nDirEntry <= m_pDirHeader->numDirs); - - for (; m_nDirEntry < m_pDirHeader->numDirs; ++m_nDirEntry) - { - if (MatchWildcard(GetDirName())) - { - return true; - } - } - // we didn't find anything other file else - return false; -} - - -ZipDir::FileEntry* ZipDir::FindFile::GetFileEntry() -{ - return m_pDirHeader && m_nFileEntry < m_pDirHeader->numFiles ? m_pDirHeader->GetFileEntry(m_nFileEntry) : NULL; -} -ZipDir::DirEntry* ZipDir::FindDir::GetDirEntry() -{ - return m_pDirHeader && m_nDirEntry < m_pDirHeader->numDirs ? m_pDirHeader->GetSubdirEntry(m_nDirEntry) : NULL; -} - -const char* ZipDir::FindFile::GetFileName () -{ - if (m_pDirHeader && m_nFileEntry < m_pDirHeader->numFiles) - { - const char* pNamePool = m_pDirHeader->GetNamePool(); - return m_pDirHeader->GetFileEntry(m_nFileEntry)->GetName(pNamePool); - } - else - { - return ""; // default name - } -} - -const char* ZipDir::FindDir::GetDirName () -{ - if (m_pDirHeader && m_nDirEntry < m_pDirHeader->numDirs) - { - const char* pNamePool = m_pDirHeader->GetNamePool(); - return m_pDirHeader->GetSubdirEntry(m_nDirEntry)->GetName(pNamePool); - } - else - { - return ""; // default name - } -} diff --git a/Code/Tools/CryCommonTools/ZipDir/ZipDirFind.h b/Code/Tools/CryCommonTools/ZipDir/ZipDirFind.h deleted file mode 100644 index 99e95607c1..0000000000 --- a/Code/Tools/CryCommonTools/ZipDir/ZipDirFind.h +++ /dev/null @@ -1,109 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYCOMMONTOOLS_ZIPDIR_ZIPDIRFIND_H -#define CRYINCLUDE_CRYCOMMONTOOLS_ZIPDIR_ZIPDIRFIND_H -#pragma once - - -namespace ZipDir -{ - // create this structure and loop: - // FindData fd (pZip); - // for (fd.FindFirst("*.cgf"); fd.GetFileEntry(); fd.FindNext()) - // {} // inside the loop, use GetFileEntry() and GetFileName() to get the file entry and name records - class FindData - { - public: - - FindData (DirHeader* pRoot) - : m_pRoot (pRoot) - , m_pDirHeader (NULL) - { - } - - protected: - // initializes everything until the point where the file must be searched for - // after this call returns successfully (with true returned), the m_szWildcard - // contains the file name/wildcard and m_pDirHeader contains the directory where - // the file (s) are to be found - bool PreFind (const char* szWildcard); - - // matches the file wilcard in the m_szWildcard to the given file/dir name - // this takes into account the fact that xxx. is the alias name for xxx - bool MatchWildcard(const char* szName); - - DirHeader* m_pRoot; // the zip file inwhich the search is performed - DirHeader* m_pDirHeader; // the header of the directory in which the files reside - //unsigned m_nDirEntry; // the current directory entry inside the parent directory - - // the actual wildcard being used in the current scan - the file name wildcard only! - char m_szWildcard[_MAX_PATH]; - }; - - class FindFile - : public FindData - { - public: - FindFile (Cache* pCache) - : FindData(pCache->GetRoot()) - { - } - FindFile (DirHeader* pRoot) - : FindData(pRoot) - { - } - // if bExactFile is passed, only the file is searched, and besides with the exact name as passed (no wildcards) - bool FindFirst (const char* szWildcard); - - FileEntry* FindExact (const char* szPath); - - // goes on to the next file entry - bool FindNext (); - - FileEntry* GetFileEntry(); - const char* GetFileName (); - - protected: - bool SkipNonMatchingFiles(); - unsigned m_nFileEntry; // the current file index inside the parent directory - }; - - class FindDir - : public FindData - { - public: - FindDir (Cache* pCache) - : FindData(pCache->GetRoot()) - { - } - FindDir (DirHeader* pRoot) - : FindData(pRoot) - { - } - // if bExactFile is passed, only the file is searched, and besides with the exact name as passed (no wildcards) - bool FindFirst (const char* szWildcard); - - // goes on to the next file entry - bool FindNext (); - - DirEntry* GetDirEntry(); - const char* GetDirName (); - - protected: - bool SkipNonMatchingDirs(); - unsigned m_nDirEntry; // the current dir index inside the parent directory - }; -} - -#endif // CRYINCLUDE_CRYCOMMONTOOLS_ZIPDIR_ZIPDIRFIND_H diff --git a/Code/Tools/CryCommonTools/ZipDir/ZipDirFindRW.cpp b/Code/Tools/CryCommonTools/ZipDir/ZipDirFindRW.cpp deleted file mode 100644 index a44f8dd45e..0000000000 --- a/Code/Tools/CryCommonTools/ZipDir/ZipDirFindRW.cpp +++ /dev/null @@ -1,253 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - - -#include "smartptr.h" -#include "ZipFileFormat.h" -#include "zipdirstructures.h" -#include "ZipDirTree.h" -#include "ZipDirCacheRW.h" -#include "ZipDirFindRW.h" -#include "StringHelpers.h" - -bool ZipDir::FindFileRW::FindFirst (const char* szWildcard) -{ - if (!PreFind (szWildcard)) - { - return false; - } - - // finally, this is the name of the file - m_itFile = m_pDirHeader->GetFileBegin(); - return SkipNonMatchingFiles(); -} - -bool ZipDir::FindDirRW::FindFirst (const char* szWildcard) -{ - if (!PreFind (szWildcard)) - { - return false; - } - - // finally, this is the name of the file - m_itDir = m_pDirHeader->GetDirBegin(); - return SkipNonMatchingDirs(); -} - -// matches the file wilcard in the m_szWildcard to the given file/dir name -// this takes into account the fact that xxx. is the alias name for xxx -bool ZipDir::FindDataRW::MatchWildcard(const char* szName) -{ - if (StringHelpers::MatchesWildcards(szName, m_szWildcard)) - { - return true; - } - - // check if the file object name contains extension sign (.) - const char* p; - for (p = szName; *p && *p != '.'; ++p) - { - continue; - } - - if (*p) - { - // there's an extension sign in the object, but it wasn't matched.. - assert (*p == '.'); - return false; - } - - // no extension sign - add it - char szAlias[_MAX_PATH + 2]; - size_t nLength = p - szName; - if (nLength > _MAX_PATH) - { - nLength = _MAX_PATH; - } - memcpy (szAlias, szName, nLength); - szAlias[nLength] = '.'; // add the alias - szAlias[nLength + 1] = '\0'; // terminate the string - return StringHelpers::MatchesWildcards(szAlias, m_szWildcard); -} - - -ZipDir::FileEntry* ZipDir::FindFileRW::FindExact (const char* szPath) -{ - if (!PreFind (szPath)) - { - return NULL; - } - - FileEntryTree::FileMap::iterator itFile = m_pDirHeader->FindFile(m_szWildcard); - if (itFile != m_pDirHeader->GetFileEnd()) - { - m_itFile = itFile; - } - else - { - m_pDirHeader = NULL; // we didn't find it, fail the search - } - return m_pDirHeader ? m_pDirHeader->GetFileEntry(itFile) : NULL; -} - -ZipDir::FileEntryTree* ZipDir::FindDirRW::FindExact (const char* szPath) -{ - if (!PreFind(szPath)) - { - return NULL; - } - - // the wildcard will contain the target directory name - return m_pDirHeader->FindDir(m_szWildcard); -} - -////////////////////////////////////////////////////////////////////////// -// initializes everything until the point where the file must be searched for -// after this call returns successfully (with true returned), the m_szWildcard -// contains the file name/wildcard and m_pDirHeader contains the directory where -// the file (s) are to be found -bool ZipDir::FindDataRW::PreFind (const char* szWildcard) -{ - if (!m_pRoot) - { - return false; - } - - // start the search from the root - m_pDirHeader = m_pRoot; - - // for each path dir name, copy it into the buffer and try to find the subdirectory - const char* pPath = szWildcard; - for (;; ) - { - char* pName = m_szWildcard; - - // at first we'll use the wildcard memory to save the directory names - for (; *pPath && *pPath != '/' && *pPath != '\\' && pName < m_szWildcard + sizeof(m_szWildcard) - 1; ++pPath, ++pName) - { - *pName = ::tolower(*pPath); - } - *pName = '\0'; - - if (*pPath) - { - // this is the name of the directory - FileEntryTree* pDirEntry = m_pDirHeader->FindDir(m_szWildcard); - if (!pDirEntry) - { - m_pDirHeader = NULL; // finish the search - return false; - } - m_pDirHeader = pDirEntry->GetDirectory(); - ++pPath; - assert(m_pDirHeader); - } - else - { - // finally, this is the name of the file (or directory) - return true; - } - } -} - -// goes on to the next entry -bool ZipDir::FindFileRW::FindNext () -{ - if (m_pDirHeader && m_itFile != m_pDirHeader->GetFileEnd()) - { - ++m_itFile; - return SkipNonMatchingFiles(); - } - else - { - return false; - } -} - -// goes on to the next entry -bool ZipDir::FindDirRW::FindNext () -{ - if (m_pDirHeader && m_itDir != m_pDirHeader->GetDirEnd()) - { - ++m_itDir; - return SkipNonMatchingDirs(); - } - else - { - return false; - } -} - -bool ZipDir::FindFileRW::SkipNonMatchingFiles() -{ - assert(m_pDirHeader); - - for (; m_itFile != m_pDirHeader->GetFileEnd(); ++m_itFile) - { - if (MatchWildcard(GetFileName())) - { - return true; - } - } - // we didn't find anything other file else - return false; -} - -bool ZipDir::FindDirRW::SkipNonMatchingDirs() -{ - assert(m_pDirHeader); - - for (; m_itDir != m_pDirHeader->GetDirEnd(); ++m_itDir) - { - if (MatchWildcard(GetDirName())) - { - return true; - } - } - // we didn't find anything other file else - return false; -} - - -ZipDir::FileEntry* ZipDir::FindFileRW::GetFileEntry() -{ - return m_pDirHeader && m_itFile != m_pDirHeader->GetFileEnd() ? m_pDirHeader->GetFileEntry(m_itFile) : NULL; -} -ZipDir::FileEntryTree* ZipDir::FindDirRW::GetDirEntry() -{ - return m_pDirHeader && m_itDir != m_pDirHeader->GetDirEnd() ? m_pDirHeader->GetDirEntry(m_itDir) : NULL; -} - -const char* ZipDir::FindFileRW::GetFileName () -{ - if (m_pDirHeader && m_itFile != m_pDirHeader->GetFileEnd()) - { - return m_pDirHeader->GetFileName(m_itFile); - } - else - { - return ""; // default name - } -} - -const char* ZipDir::FindDirRW::GetDirName () -{ - if (m_pDirHeader && m_itDir != m_pDirHeader->GetDirEnd()) - { - return m_pDirHeader->GetDirName(m_itDir); - } - else - { - return ""; // default name - } -} diff --git a/Code/Tools/CryCommonTools/ZipDir/ZipDirFindRW.h b/Code/Tools/CryCommonTools/ZipDir/ZipDirFindRW.h deleted file mode 100644 index 3085b5f8ba..0000000000 --- a/Code/Tools/CryCommonTools/ZipDir/ZipDirFindRW.h +++ /dev/null @@ -1,110 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Declaration of the class that can be used to search for the entries -// in a zip dir cache - - -#ifndef CRYINCLUDE_CRYCOMMONTOOLS_ZIPDIR_ZIPDIRFINDRW_H -#define CRYINCLUDE_CRYCOMMONTOOLS_ZIPDIR_ZIPDIRFINDRW_H -#pragma once - - -namespace ZipDir -{ - // create this structure and loop: - // FindData fd (pZip); - // for (fd.FindFirst("*.cgf"); fd.GetFileEntry(); fd.FindNext()) - // {} // inside the loop, use GetFileEntry() and GetFileName() to get the file entry and name records - class FindDataRW - { - public: - FindDataRW (FileEntryTree* pRoot) - : m_pRoot (pRoot) - , m_pDirHeader (NULL) - { - } - - // returns the directory to which the current object belongs - FileEntryTree* GetParentDir() {return m_pDirHeader; } - protected: - // initializes everything until the point where the file must be searched for - // after this call returns successfully (with true returned), the m_szWildcard - // contains the file name/wildcard and m_pDirHeader contains the directory where - // the file (s) are to be found - bool PreFind (const char* szWildcard); - - // matches the file wilcard in the m_szWildcard to the given file/dir name - // this takes into account the fact that xxx. is the alias name for xxx - bool MatchWildcard(const char* szName); - - // the directory inside which the current object (file or directory) is being searched - FileEntryTree* m_pDirHeader; - - FileEntryTree* m_pRoot; // the root of the zip file in which to search - - // the actual wildcard being used in the current scan - the file name wildcard only! - char m_szWildcard[_MAX_PATH]; - }; - - - class FindFileRW - : public FindDataRW - { - public: - FindFileRW (FileEntryTree* pRoot) - : FindDataRW(pRoot) - { - } - // if bExactFile is passed, only the file is searched, and besides with the exact name as passed (no wildcards) - bool FindFirst (const char* szWildcard); - - FileEntry* FindExact (const char* szPath); - - // goes on to the next file entry - bool FindNext (); - - FileEntry* GetFileEntry(); - const char* GetFileName (); - - protected: - bool SkipNonMatchingFiles(); - FileEntryTree::FileMap::iterator m_itFile; // the current file iterator inside the parent directory - }; - - class FindDirRW - : public FindDataRW - { - public: - FindDirRW (FileEntryTree* pRoot) - : FindDataRW(pRoot) - { - } - // if bExactFile is passed, only the file is searched, and besides with the exact name as passed (no wildcards) - bool FindFirst (const char* szWildcard); - - FileEntryTree* FindExact (const char* szPath); - - // goes on to the next file entry - bool FindNext (); - - FileEntryTree* GetDirEntry(); - const char* GetDirName (); - - protected: - bool SkipNonMatchingDirs(); - FileEntryTree::SubdirMap::iterator m_itDir; // the current dir index inside the parent directory - }; -} - -#endif // CRYINCLUDE_CRYCOMMONTOOLS_ZIPDIR_ZIPDIRFINDRW_H diff --git a/Code/Tools/CryCommonTools/ZipDir/ZipDirList.cpp b/Code/Tools/CryCommonTools/ZipDir/ZipDirList.cpp deleted file mode 100644 index 36b0dd6ba8..0000000000 --- a/Code/Tools/CryCommonTools/ZipDir/ZipDirList.cpp +++ /dev/null @@ -1,174 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - - -#undef max -#include -#include "ZipFileFormat.h" -#include "zipdirstructures.h" -#include "ZipDirList.h" -#include "ZipDirTree.h" - -ZipDir::FileRecordList::FileRecordList(FileEntryTree* pTree) -{ - clear(); - reserve(pTree->NumFilesTotal()); - AddAllFiles(pTree); -} - -//recursively adds the files from this directory and subdirectories -// the strRoot contains the trailing slash -void ZipDir::FileRecordList::AddAllFiles(FileEntryTree* pTree, string strRoot) -{ - for (FileEntryTree::SubdirMap::iterator it = pTree->GetDirBegin(); it != pTree->GetDirEnd(); ++it) - { - AddAllFiles (it->second, strRoot + it->second->GetOriginalName() + "/"); - } - - for (FileEntryTree::FileMap::iterator it = pTree->GetFileBegin(); it != pTree->GetFileEnd(); ++it) - { - FileRecord rec; - rec.pFileEntry = pTree->GetFileEntry(it); - const char* filename = rec.pFileEntry->szOriginalFileName ? rec.pFileEntry->szOriginalFileName : it->first; - rec.strPath = strRoot + filename; - push_back(rec); - } -} - - -// sorts the files by the physical offset in the zip file -void ZipDir::FileRecordList::SortByFileOffset() -{ - std::sort (begin(), end(), FileRecordFileOffsetOrder()); -} - -// returns the size of CDR in the zip file -ZipDir::FileRecordList::ZipStats ZipDir::FileRecordList::GetStats() const -{ - ZipStats Stats; - Stats.nSizeCDR = sizeof(ZipFile::CDREnd); - Stats.nSizeCompactData = 0; - // for each file, we'll need to store only its CDR header and the name - for (const_iterator it = begin(); it != end(); ++it) - { - Stats.nSizeCDR += sizeof(ZipFile::CDRFileHeader) + it->strPath.length(); - Stats.nSizeCompactData += sizeof(ZipFile::LocalFileHeader) + it->strPath.length() + it->pFileEntry->desc.lSizeCompressed; - } - - return Stats; -} - -// puts the CDR into the given block of mem -size_t ZipDir::FileRecordList::MakeZipCDR(ZipFile::ulong lCDROffset, void* pBuffer, bool encryptedFlag) const -{ - const ZipFile::ushort nBaseVersion = std::max(encryptedFlag ? ZipFile::VERSION_ENCRYPTION_PKWARE : ZipFile::VERSION_DEFAULT, ZipFile::VERSION_COMPRESSION_DEFLATE); - - char* pCur = (char*)pBuffer; - for (const_iterator it = begin(); it != end(); ++it) - { - ZipFile::CDRFileHeader& h = *(ZipFile::CDRFileHeader*)pCur; - pCur = (char*)(&h + 1); - h.lSignature = h.SIGNATURE; - h.nVersionMadeBy = nBaseVersion + (ZipFile::CREATOR_MSDOS << 8); - h.nVersionNeeded = nBaseVersion; - h.nFlags = 0; - h.nMethod = it->pFileEntry->nMethod; - h.nLastModTime = it->pFileEntry->nLastModTime; - h.nLastModDate = it->pFileEntry->nLastModDate; - h.desc = it->pFileEntry->desc; - h.nFileNameLength = (ZipFile::ushort)it->strPath.length(); - h.nExtraFieldLength = 0; - h.nFileCommentLength = 0; - h.nDiskNumberStart = 0; - h.nAttrInternal = 0; - h.lAttrExternal = 0; - h.lLocalHeaderOffset = it->pFileEntry->nFileHeaderOffset; - - memcpy (pCur, it->strPath.c_str(), it->strPath.length()); - pCur += it->strPath.length(); - } - - ZipFile::CDREnd& e = *(ZipFile::CDREnd*)pCur; - e.lSignature = e.SIGNATURE; - e.nDisk = encryptedFlag ? (1 << 15) : 0; - e.nCDRStartDisk = 0; - e.numEntriesOnDisk = (ZipFile::ushort)this->size(); - e.numEntriesTotal = (ZipFile::ushort)this->size(); - e.lCDRSize = (ZipFile::ulong)(pCur - (char*)pBuffer); - e.lCDROffset = lCDROffset; - e.nCommentLength = 0; - - pCur = (char*)(&e + 1); - - return pCur - (char*)pBuffer; -} - - -ZipDir::FileEntryList::FileEntryList (FileEntryTree* pTree, unsigned lCDROffset) - : m_lCDROffset (lCDROffset) -{ - Add (pTree); -} - -void ZipDir::FileEntryList::Add(FileEntryTree* pTree) -{ - for (FileEntryTree::SubdirMap::iterator itDir = pTree->GetDirBegin(); itDir != pTree->GetDirEnd(); ++itDir) - { - Add(pTree->GetDirEntry(itDir)); - } - for (FileEntryTree::FileMap::iterator itFile = pTree->GetFileBegin(); itFile != pTree->GetFileEnd(); ++itFile) - { - insert(pTree->GetFileEntry(itFile)); - } -} - -// updates each file entry's info about the next file entry -void ZipDir::FileEntryList::RefreshEOFOffsets() -{ - iterator it, itNext = begin(); - - if (itNext != end()) - { - while ((it = itNext, ++itNext) != end()) - { - // start scan - (*it)->nEOFOffset = (*itNext)->nFileHeaderOffset; - } - // it is the last one.. - (*it)->nEOFOffset = m_lCDROffset; - } -} - - -void ZipDir::FileRecordList::Backup(std::vector& arrFiles) const -{ - arrFiles.resize (size()); - std::vector::iterator itTgt = arrFiles.begin(); - - for (const_iterator it = begin(); it != end(); ++it, ++itTgt) - { - *itTgt = *it->pFileEntry; - } -} - -void ZipDir::FileRecordList::Restore(const std::vector& arrFiles) -{ - if (arrFiles.size() == size()) - { - std::vector::const_iterator itTgt = arrFiles.begin(); - for (iterator it = begin(); it != end(); ++it, ++itTgt) - { - *it->pFileEntry = *itTgt; - } - } -} diff --git a/Code/Tools/CryCommonTools/ZipDir/ZipDirList.h b/Code/Tools/CryCommonTools/ZipDir/ZipDirList.h deleted file mode 100644 index 58ce7312ae..0000000000 --- a/Code/Tools/CryCommonTools/ZipDir/ZipDirList.h +++ /dev/null @@ -1,138 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYCOMMONTOOLS_ZIPDIR_ZIPDIRLIST_H -#define CRYINCLUDE_CRYCOMMONTOOLS_ZIPDIR_ZIPDIRLIST_H -#pragma once - -#include - -namespace ZipDir -{ - // this is the array of file entries that's convenient to use to construct CDR - struct FileRecord - { - string strPath; // relative path to the file inside zip - FileEntry* pFileEntry; // the file entry itself - - void ConstructFileRecord() - { - new (&strPath)string(); - } - }; - - struct FileDataRecord - : public FileRecord - { - FileDataRecord() { m_nRefCount = 0; } - void AddRef() { ++m_nRefCount; } - void Release() - { - if (--m_nRefCount <= 0) - { - Delete(); - } - } - - void Delete() - { - free (this); - } - - static FileDataRecord* New(const FileRecord& rThat) - { - FileDataRecord* pThis = (FileDataRecord*)malloc(sizeof(FileDataRecord) + rThat.pFileEntry->desc.lSizeCompressed); - - if (pThis) - { - pThis->m_nRefCount = 0; - pThis->ConstructFileRecord(); - *static_cast(pThis) = rThat; - } - return pThis; - } - - void* GetData() {return this + 1; } - - volatile signed int m_nRefCount; // the reference count - }; - - TYPEDEF_AUTOPTR(FileDataRecord); - typedef FileDataRecord_AutoPtr FileDataRecordPtr; - - struct FileRecordFileOffsetOrder - { - bool operator () (const FileRecord& left, const FileRecord& right) - { - return left.pFileEntry->nFileHeaderOffset < right.pFileEntry->nFileHeaderOffset; - } - }; - - // this is used for construction of CDR - class FileRecordList - : public std::vector - { - public: - FileRecordList(class FileEntryTree* pTree); - - struct ZipStats - { - // the size of the CDR in the file - size_t nSizeCDR; - // the size of the file data part (local file descriptors and file datas) - // if it's compacted - size_t nSizeCompactData; - }; - - // sorts the files by the physical offset in the zip file - void SortByFileOffset (); - - // returns the size of CDR in the zip file - ZipStats GetStats() const; - - // puts the CDR into the given block of mem - size_t MakeZipCDR(ZipFile::ulong lCDROffset, void* p, bool encryptedFlag) const; - - void Backup(std::vector& arrFiles) const; - void Restore(const std::vector& arrFiles); - - protected: - // recursively adds the files from this directory and subdirectories - // the strRoot contains the trailing slash - void AddAllFiles(class FileEntryTree* pTree, string strRoot = string()); - }; - - - struct FileEntryFileOffsetOrder - { - bool operator () (FileEntry* pLeft, FileEntry* pRight) const - { - return pLeft->nFileHeaderOffset < pRight->nFileHeaderOffset; - } - }; - - // this is used for refreshing EOFOffsets - class FileEntryList - : public std::set - { - public: - FileEntryList (class FileEntryTree* pTree, unsigned lCDROffset); - // updates each file entry's info about the next file entry - void RefreshEOFOffsets(); - protected: - void Add (class FileEntryTree* pTree); - unsigned m_lCDROffset; - }; -} - -#endif // CRYINCLUDE_CRYCOMMONTOOLS_ZIPDIR_ZIPDIRLIST_H diff --git a/Code/Tools/CryCommonTools/ZipDir/ZipDirStructures.cpp b/Code/Tools/CryCommonTools/ZipDir/ZipDirStructures.cpp deleted file mode 100644 index 3d404ad62b..0000000000 --- a/Code/Tools/CryCommonTools/ZipDir/ZipDirStructures.cpp +++ /dev/null @@ -1,670 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "smartptr.h" -#include -#include -#include -#include "ZipFileFormat.h" -#include "zipdirstructures.h" -#include -#include -#include -#include - -using namespace ZipFile; - -ZipDir::FileEntry::FileEntry(const CDRFileHeader& header, const SExtraZipFileData& extra) -{ - this->desc = header.desc; - this->nFileHeaderOffset = header.lLocalHeaderOffset; - this->nFileDataOffset = INVALID_DATA_OFFSET; // we don't know yet - this->nMethod = header.nMethod; - this->nNameOffset = 0; // we don't know yet -#if defined(AZ_PLATFORM_WINDOWS) - this->nLastModTime = header.nLastModTime; - this->nLastModDate = header.nLastModDate; -#endif - this->nNTFS_LastModifyTime = extra.nLastModifyTime; - this->szOriginalFileName = 0; - - // make an estimation (at least this offset should be there), but we don't actually know yet - this->nEOFOffset = header.lLocalHeaderOffset + sizeof (ZipFile::LocalFileHeader) + header.nFileNameLength + header.desc.lSizeCompressed; -} - - - -// Uncompresses raw (without wrapping) data that is compressed with method 8 (deflated) in the Zip file -// returns one of the Z_* errors (Z_OK upon success) -// This function just mimics the standard uncompress (with modification taken from unzReadCurrentFile) -// with 2 differences: there are no 16-bit checks, and -// it initializes the inflation to start without waiting for compression method byte, as this is the -// way it's stored into zip file -int ZipDir::ZipRawUncompress (void* pUncompressed, unsigned long* pDestSize, const void* pCompressed, unsigned long nSrcSize) -{ - int nReturnCode = Z_OK; - - //check first 4 bytes to see what compression codec was used - if (CompressionCodec::TestForZSTDMagic(pCompressed)) - { - - size_t result = ZSTD_decompress(pUncompressed, *pDestSize, pCompressed, nSrcSize); - - if (ZSTD_isError(result)) - { - AZ_Error("ZipDirStructures", false, "Error decompressing using zstd: %s", ZSTD_getErrorName(result)); - nReturnCode = Z_BUF_ERROR; - } - else - { - *pDestSize = result; - } - return nReturnCode; - } - else if (CompressionCodec::TestForLZ4Magic(pCompressed)) - { - size_t result; - LZ4F_decompressionContext_t dctx; - result = LZ4F_createDecompressionContext(&dctx, LZ4F_VERSION); - if (LZ4F_isError(result)) - { - AZ_Error("ZipDirStructures", false, "Error creating lz4 decompression context: %s", LZ4F_getErrorName(result)); - return Z_BUF_ERROR; - } - - size_t dstSize = (size_t)*pDestSize; - size_t srcSize = (size_t)nSrcSize; - result = LZ4F_decompress(dctx, pUncompressed, &dstSize, pCompressed, &srcSize, nullptr); - if (LZ4F_isError(result)) - { - AZ_Error("ZipDirStructures", false, "Error decompressing using lz4: %s", LZ4F_getErrorName(result)); - nReturnCode = Z_BUF_ERROR; - } - else - { - *pDestSize = (long)dstSize; - } - - size_t freeCode = LZ4F_freeDecompressionContext(dctx); - if (LZ4F_isError(freeCode)) - { - //We are not changing the return code in this case, but it is good to record that releasing the - //decompression context failed. - AZ_Error("ZipDirStructures", false, "Error releasing lz4 decompression context: %s", LZ4F_getErrorName(freeCode)); - } - - return nReturnCode; - } - - - //Default to Zlib - z_stream stream; - stream.next_in = (Bytef*)pCompressed; - stream.avail_in = (uInt)nSrcSize; - - int err; - - stream.next_out = (Bytef*)pUncompressed; - stream.avail_out = (uInt) * pDestSize; - - stream.zalloc = Z_NULL; - stream.zfree = Z_NULL; - stream.opaque = Z_NULL; - - err = inflateInit2(&stream, -MAX_WBITS); - if (err != Z_OK) - { - return err; - } - - // for some strange reason, passing Z_FINISH doesn't work - - // it seems the stream isn't finished for some files and - // inflate returns an error due to stream-end-not-reached (though expected) problem - err = inflate(&stream, Z_SYNC_FLUSH); - if (err != Z_STREAM_END && err != Z_OK) - { - inflateEnd(&stream); - return err == Z_OK ? Z_BUF_ERROR : err; - } - - *pDestSize = stream.total_out; - - err = inflateEnd(&stream); - return err; - -} - -// compresses the raw data into raw data. The buffer for compressed data itself with the heap passed. Uses method 8 (deflate) -// returns one of the Z_* errors (Z_OK upon success) -int ZipDir::ZipRawCompress(const void* pUncompressed, unsigned long* pDestSize, void* pCompressed, unsigned long nSrcSize, int nLevel) -{ - z_stream stream; - int err; - - stream.next_out = reinterpret_cast(pCompressed); - - stream.next_in = const_cast(static_cast(pUncompressed)); - stream.avail_in = static_cast(nSrcSize); - - stream.avail_out = static_cast(*pDestSize); - - stream.zalloc = Z_NULL; - stream.zfree = Z_NULL; - stream.opaque = Z_NULL; - - err = deflateInit2 (&stream, nLevel, Z_DEFLATED, -MAX_WBITS, 9, Z_DEFAULT_STRATEGY); - if (err != Z_OK) - { - return err; - } - - err = deflate (&stream, Z_FINISH); - if (err != Z_STREAM_END) - { - deflateEnd(&stream); - return err == Z_OK ? Z_BUF_ERROR : err; - } - *pDestSize = stream.total_out; - - err = deflateEnd(&stream); - return err; -} - -int ZipDir::ZipRawCompressZSTD(const void* pUncompressed, unsigned long* pDestSize, void* pCompressed, unsigned long nSrcSize, int nLevel) -{ - size_t result = ZSTD_compress(pCompressed, *pDestSize, pUncompressed, nSrcSize, nLevel); - - int err = Z_OK; - - if (ZSTD_isError(result)) - { - err = Z_BUF_ERROR; - } - else - { - *pDestSize = static_cast(result); - } - return err; -} - -int ZipDir::ZipRawCompressLZ4(const void* pUncompressed, unsigned long* pDestSize, void* pCompressed, unsigned long nSrcSize, [[maybe_unused]] int nLevel) -{ - int returnCode = Z_OK; - const size_t compressedBufferMaxSize = aznumeric_caster(*pDestSize); - size_t lz4_code = LZ4F_compressFrame(pCompressed, compressedBufferMaxSize, pUncompressed, aznumeric_caster(nSrcSize), nullptr); - - if (LZ4F_isError(lz4_code)) - { - returnCode = Z_BUF_ERROR; - } - else - { - *pDestSize = aznumeric_caster(lz4_code); - } - - return returnCode; -} - -int ZipDir::GetCompressedSizeEstimate(unsigned long uncompressedSize, CompressionCodec::Codec codec) -{ - switch (codec) - { - case CompressionCodec::Codec::ZLIB: - return (uncompressedSize + (uncompressedSize >> 3) + 32); - case CompressionCodec::Codec::ZSTD: - return ZSTD_compressBound(uncompressedSize); - case CompressionCodec::Codec::LZ4: - return LZ4F_compressFrameBound(uncompressedSize, nullptr); - default: - break; - } - return 0; -} - -ZipDir::ValidationResult ZipDir::ValidateZSTDCompressedDataWithOriginalData(const void* pUncompressed, unsigned long uncompressedSize, const void* pCompressed, unsigned long compressedSize) -{ - auto decompressedSize = ZSTD_getDecompressedSize(pCompressed, compressedSize); - ZipDir::ValidationResult testResult = ValidationResult::OK; - - if (decompressedSize != uncompressedSize) - { - testResult = ValidationResult::SIZE_MISMATCH; - } - else - { - void* decompressionBuffer = azmalloc(decompressedSize); - - size_t result = ZSTD_decompress(decompressionBuffer, decompressedSize, pCompressed, compressedSize); - - if (ZSTD_isError(result)) - { - AZ_Warning("Debug", false, "Error decompressing data with zstd: %s", ZSTD_getErrorName(result)); - testResult = ValidationResult::DATA_CORRUPTED; - } - else - { - if (memcmp(decompressionBuffer, pUncompressed, decompressedSize) != 0) - { - testResult = ValidationResult::DATA_NO_MATCH; - } - } - azfree(decompressionBuffer); - } - return testResult; -} - -// finds the subdirectory entry by the name, using the names from the name pool -// assumes: all directories are sorted in alphabetical order. -// case-sensitive (must be lower-case if case-insensitive search in Win32 is performed) -ZipDir::DirEntry* ZipDir::DirHeader::FindSubdirEntry(const char* szName) -{ - if (this->numDirs) - { - const char* pNamePool = GetNamePool(); - DirEntrySortPred pred(pNamePool); - DirEntry* pBegin = GetSubdirEntry(0); - DirEntry* pEnd = pBegin + this->numDirs; - DirEntry* pEntry = std::lower_bound(pBegin, pEnd, szName, pred); -#if defined(LINUX) - if (pEntry != pEnd && !strcasecmp(szName, pEntry->GetName(pNamePool))) -#else - if (pEntry != pEnd && !strcmp(szName, pEntry->GetName(pNamePool))) -#endif - { - return pEntry; - } - } - return NULL; -} - -// finds the file entry by the name, using the names from the name pool -// assumes: all directories are sorted in alphabetical order. -// case-sensitive (must be lower-case if case-insensitive search in Win32 is performed) -ZipDir::FileEntry* ZipDir::DirHeader::FindFileEntry(const char* szName) -{ - if (this->numFiles) - { - const char* pNamePool = GetNamePool(); - DirEntrySortPred pred(pNamePool); - FileEntry* pBegin = GetFileEntry(0); - FileEntry* pEnd = pBegin + this->numFiles; - FileEntry* pEntry = std::lower_bound(pBegin, pEnd, szName, pred); -#if defined(LINUX) - if (pEntry != pEnd && !strcasecmp(szName, pEntry->GetName(pNamePool))) -#else - if (pEntry != pEnd && !strcmp(szName, pEntry->GetName(pNamePool))) -#endif - { - return pEntry; - } - } - return NULL; -} - - -// tries to refresh the file entry from the given file (reads fromthere if needed) -// returns the error code if the operation was impossible to complete -ZipDir::ErrorEnum ZipDir::Refresh(FILE* f, FileEntry* pFileEntry, bool encryptedHeaders) -{ - if (pFileEntry->nFileDataOffset != pFileEntry->INVALID_DATA_OFFSET) - { - return ZD_ERROR_SUCCESS; - } - - if (pFileEntry->desc.lSizeCompressed == 0) - { - return ZD_ERROR_SUCCESS; - } - -#ifdef WIN32 - if (_fseeki64(f, (__int64)pFileEntry->nFileHeaderOffset, SEEK_SET)) -#else - if (fseek(f, pFileEntry->nFileHeaderOffset, SEEK_SET)) -#endif - { - return ZD_ERROR_IO_FAILED; - } - - if (encryptedHeaders) - { - // with encrypted headers FileEntries should always be initialized from CDR. - return ZD_ERROR_IO_FAILED; - } - - // read the local file header and the name (for validation) into the buffer - LocalFileHeader fileHeader; - if (1 != fread (&fileHeader, sizeof(fileHeader), 1, f)) - { - return ZD_ERROR_IO_FAILED; - } - - if (fileHeader.desc != pFileEntry->desc - || fileHeader.nMethod != pFileEntry->nMethod) - { - return ZD_ERROR_IO_FAILED; - } - - pFileEntry->nFileDataOffset = pFileEntry->nFileHeaderOffset + sizeof(LocalFileHeader) + fileHeader.nFileNameLength + fileHeader.nExtraFieldLength; - pFileEntry->nEOFOffset = pFileEntry->nFileDataOffset + pFileEntry->desc.lSizeCompressed; - return ZD_ERROR_SUCCESS; -} - -// writes into the file local header - without Extra data -// puts the new offset to the file data to the file entry -// in case of error can put INVALID_DATA_OFFSET into the data offset field of file entry -ZipDir::ErrorEnum ZipDir::WriteLocalHeader (FILE* f, FileEntry* pFileEntry, const char* szRelativePath, bool encrypt) -{ - size_t nFileNameLength = strlen(szRelativePath); - size_t nHeaderSize = sizeof(LocalFileHeader) + nFileNameLength; - - pFileEntry->nFileDataOffset = pFileEntry->nFileHeaderOffset + nHeaderSize; - pFileEntry->nEOFOffset = pFileEntry->nFileDataOffset + pFileEntry->desc.lSizeCompressed; - -#ifdef WIN32 - if (_fseeki64 (f, (__int64)pFileEntry->nFileHeaderOffset, SEEK_SET)) -#else - if (fseek (f, pFileEntry->nFileHeaderOffset, SEEK_SET)) -#endif - { - return ZD_ERROR_IO_FAILED; - } - - if (encrypt) - { - std::vector garbage; - garbage.resize(nHeaderSize); - for (size_t i = 0; i < nHeaderSize; ++i) - { - garbage[i] = rand() & 0xff; - } - - if (fwrite(&garbage[0], nHeaderSize, 1, f) != 1) - { - return ZD_ERROR_IO_FAILED; - } - } - else - { - LocalFileHeader h; - memset(&h, 0, sizeof(h)); - - h.lSignature = h.SIGNATURE; - h.nVersionNeeded = 10; - h.nFlags = 0; - h.nMethod = pFileEntry->nMethod; -#if defined(AZ_PLATFORM_WINDOWS) - h.nLastModDate = pFileEntry->nLastModDate; - h.nLastModTime = pFileEntry->nLastModTime; -#endif - h.desc = pFileEntry->desc; - h.nFileNameLength = (unsigned short)nFileNameLength; - h.nExtraFieldLength = 0; - - if (1 != fwrite(&h, sizeof(h), 1, f)) - { - return ZD_ERROR_IO_FAILED; - } - - if (nFileNameLength > 0) - { - if (1 != fwrite (szRelativePath, nFileNameLength, 1, f)) - { - return ZD_ERROR_IO_FAILED; - } - } - } - - return ZD_ERROR_SUCCESS; -} - - -// conversion routines for the date/time fields used in Zip -ZipFile::ushort ZipDir::DOSDate(tm* t) -{ - return - ((t->tm_year - 80) << 9) - | (t->tm_mon << 5) - | t->tm_mday; -} - -ZipFile::ushort ZipDir::DOSTime(tm* t) -{ - return - ((t->tm_hour) << 11) - | ((t->tm_min) << 5) - | ((t->tm_sec) >> 1); -} - - - -// sets the current time to modification time -// calculates CRC32 for the new data -void ZipDir::FileEntry::OnNewFileData(void* pUncompressed, unsigned nSize, unsigned nCompressedSize, unsigned nCompressionMethod, bool bContinuous) -{ - time_t nTime; - time(&nTime); -#if defined(AZ_PLATFORM_WINDOWS) - tm t; - localtime_s(&t, &nTime); - this->nLastModTime = DOSTime(&t); - this->nLastModDate = DOSDate(&t); -#else - -#endif - this->nNTFS_LastModifyTime = AZStd::GetTimeUTCMilliSecond(); - - if (!bContinuous) - { - this->desc.lCRC32 = crc32(0L, Z_NULL, 0); - this->desc.lSizeCompressed = nCompressedSize; - this->desc.lSizeUncompressed = nSize; - } - - // we'll need CRC32 of the file to pack it - this->desc.lCRC32 = crc32(this->desc.lCRC32, (Bytef*)pUncompressed, nSize); - - this->nMethod = nCompressionMethod; -} - - -const char* ZipDir::DOSTimeCStr(ZipFile::ushort nTime) -{ - static char szBuf[16]; - azsprintf(szBuf, "%02d:%02d.%02d", (nTime >> 11), ((nTime & ((1 << 11) - 1)) >> 5), ((nTime & ((1 << 5) - 1)) << 1)); - return szBuf; -} - -const char* ZipDir::DOSDateCStr(ZipFile::ushort nTime) -{ - static char szBuf[32]; - azsprintf(szBuf, "%02d.%02d.%04d", (nTime & 0x1F), (nTime >> 5) & 0xF, (nTime >> 9) + 1980); - return szBuf; -} - -uint64 ZipDir::FileEntry::GetModificationTime() -{ - if (nNTFS_LastModifyTime != 0) - { - return nNTFS_LastModifyTime; - } - -#if defined(AZ_PLATFORM_WINDOWS) - // TODO/TIME: check and test - SYSTEMTIME st; - st.wYear = (nLastModDate >> 9) + 1980; - st.wMonth = ((nLastModDate >> 5) & 0xF); - st.wDay = (nLastModDate & 0x1F); - st.wHour = (nLastModTime >> 11); - st.wMinute = (nLastModTime >> 5) & 0x3F; - st.wSecond = (nLastModTime << 1) & 0x3F; - st.wMilliseconds = 0; - FILETIME ft; - SystemTimeToFileTime(&st, &ft); - LARGE_INTEGER lt; - lt.HighPart = ft.dwHighDateTime; - lt.LowPart = ft.dwLowDateTime; - return lt.QuadPart; -#else - return 0; -#endif -} - - -void ZipDir::FileEntry::SetFromFileTimeNTFS(int64 timestamp) -{ -#if defined(AZ_PLATFORM_WINDOWS) - FILETIME ft; - ft.dwHighDateTime = timestamp >> 32; - ft.dwLowDateTime = timestamp & 0xFFFFFFFF; - - WORD dosTime, dosDate; - FileTimeToDosDateTime(&ft, &dosDate, &dosTime); - - nLastModDate = dosDate; - nLastModTime = dosTime; -#endif - nNTFS_LastModifyTime = timestamp; -} - -bool ZipDir::FileEntry::CompareFileTimeNTFS(int64 timestamp) -{ -#if defined(AZ_PLATFORM_WINDOWS) - FILETIME ft; - ft.dwHighDateTime = timestamp >> 32; - ft.dwLowDateTime = timestamp & 0xFFFFFFFF; - - WORD dosTime, dosDate; - FileTimeToDosDateTime(&ft, &dosDate, &dosTime); - - return (nLastModTime == dosTime && nLastModDate == dosDate); -#else - return (nNTFS_LastModifyTime == timestamp); -#endif -} - -const char* ZipDir::Error::getError() -{ - switch (this->nError) - { -#define DECLARE_ERROR(x) case ZD_ERROR_##x: \ - return #x; - DECLARE_ERROR(SUCCESS); - DECLARE_ERROR(IO_FAILED); - DECLARE_ERROR(UNEXPECTED); - DECLARE_ERROR(UNSUPPORTED); - DECLARE_ERROR(INVALID_SIGNATURE); - DECLARE_ERROR(ZIP_FILE_IS_CORRUPT); - DECLARE_ERROR(DATA_IS_CORRUPT); - DECLARE_ERROR(NO_CDR); - DECLARE_ERROR(CDR_IS_CORRUPT); - DECLARE_ERROR(NO_MEMORY); - DECLARE_ERROR(VALIDATION_FAILED); - DECLARE_ERROR(CRC32_CHECK); - DECLARE_ERROR(ZLIB_FAILED); - DECLARE_ERROR(ZLIB_CORRUPTED_DATA); - DECLARE_ERROR(ZLIB_NO_MEMORY); - DECLARE_ERROR(CORRUPTED_DATA); - DECLARE_ERROR(INVALID_CALL); - DECLARE_ERROR(NOT_IMPLEMENTED); - DECLARE_ERROR(FILE_NOT_FOUND); - DECLARE_ERROR(DIR_NOT_FOUND); - DECLARE_ERROR(NAME_TOO_LONG); - DECLARE_ERROR(INVALID_PATH); - DECLARE_ERROR(FILE_ALREADY_EXISTS); -#undef DECLARE_ERROR - default: - return "Unknown ZD_ERROR code"; - } -} - - -inline void btea(uint32* v, int n, uint32 const k[4]) -{ -#define TEA_DELTA 0x9e3779b9 -#define TEA_MX (((z >> 5 ^ y << 2) + (y >> 3 ^ z << 4)) ^ ((sum ^ y) + (k[(p & 3) ^ e] ^ z))) - uint32 y, z, sum; - unsigned p, rounds, e; - if (n > 1) /* Coding Part */ - { - rounds = 6 + 52 / n; - sum = 0; - z = v[n - 1]; - do - { - sum += TEA_DELTA; - e = (sum >> 2) & 3; - for (p = 0; p < n - 1; p++) - { - y = v[p + 1]; - z = v[p] += TEA_MX; - } - y = v[0]; - z = v[n - 1] += TEA_MX; - } while (--rounds); - } - else if (n < -1) /* Decoding Part */ - { - n = -n; - rounds = 6 + 52 / n; - sum = rounds * TEA_DELTA; - y = v[0]; - do - { - e = (sum >> 2) & 3; - for (p = n - 1; p > 0; p--) - { - z = v[p - 1]; - y = v[p] -= TEA_MX; - } - z = v[n - 1]; - y = v[0] -= TEA_MX; - } while ((sum -= TEA_DELTA) != 0); - } -#undef TEA_DELTA -#undef TEA_MX -} - -static inline void SwapByteOrder(uint32* values, size_t count) -{ - for (uint32* w = values, * e = values + count; w != e; ++w) - { - *w = (*w >> 24) + ((*w >> 8) & 0xff00) + ((*w & 0xff00) << 8) + (*w << 24); - } -} - -////////////////////////////////////////////////////////////////////////// -void ZipDir::Encrypt(char* buffer, size_t size, const EncryptionKey& key) -{ - uint32* intBuffer = (uint32*)buffer; - const int encryptedLen = size >> 2; - - SwapByteOrder(intBuffer, encryptedLen); - - btea(intBuffer, encryptedLen, key.key); - - SwapByteOrder(intBuffer, encryptedLen); -} - -////////////////////////////////////////////////////////////////////////// -void ZipDir::Decrypt(char* buffer, size_t size, const EncryptionKey& key) -{ - uint32* intBuffer = (uint32*)buffer; - const int encryptedLen = size >> 2; - - SwapByteOrder(intBuffer, encryptedLen); - - btea(intBuffer, -encryptedLen, key.key); - - SwapByteOrder(intBuffer, encryptedLen); -} - diff --git a/Code/Tools/CryCommonTools/ZipDir/ZipDirTree.cpp b/Code/Tools/CryCommonTools/ZipDir/ZipDirTree.cpp deleted file mode 100644 index b35ae48b2a..0000000000 --- a/Code/Tools/CryCommonTools/ZipDir/ZipDirTree.cpp +++ /dev/null @@ -1,356 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "ZipFileFormat.h" -#include "zipdirstructures.h" -#include "ZipDirTree.h" - - -// Adds or finds the file. Returns non-initialized structure if it was added, -// or an IsInitialized() structure if it was found -ZipDir::FileEntry* ZipDir::FileEntryTree::Add(char* szPath, char* szUnifiedPath) -{ - // find the slash; if we found it, it's a subdirectory - add a subdirectory and - // add the file to it. - // if we didn't find it, it's a file - add the file to this dir - - char* pSlash; - for (pSlash = szPath; *pSlash && *pSlash != '/' && *pSlash != '\\'; ++pSlash) - { - continue; // find the next slash - } - char* pUnifiedSlash = szUnifiedPath + (pSlash - szPath); - assert(*pUnifiedSlash == '\0' || *pUnifiedSlash == '\\' || *pUnifiedSlash == '/'); - - if (*pUnifiedSlash) - { - FileEntryTree* pSubdir; - // we have a subdirectory here - create the file in it - { - char* unifiedDir = szUnifiedPath; - *pUnifiedSlash = '\0'; - - char* dir = szPath; - *pSlash = '\0'; - - SubdirMap::iterator it = m_mapDirs.find (unifiedDir); - if (it == m_mapDirs.end()) - { - pSubdir = new FileEntryTree(dir); - m_mapDirs.insert (SubdirMap::value_type(unifiedDir, pSubdir)); - } - else - { - pSubdir = it->second; - } - } - - return pSubdir->Add(pSlash + 1, pUnifiedSlash + 1); - } - else - { - ZipDir::FileEntry* result = &m_mapFiles[szUnifiedPath]; - result->szOriginalFileName = szPath; - return result; - } -} - -// adds a file to this directory -ZipDir::ErrorEnum ZipDir::FileEntryTree::Add (char* szPath, char* szUnifiedPath, const FileEntry& file) -{ - FileEntry* pFile = Add (szPath, szUnifiedPath); - if (!pFile) - { - return ZD_ERROR_INVALID_PATH; - } - if (pFile->IsInitialized()) - { - return ZD_ERROR_FILE_ALREADY_EXISTS; - } - // preserve original filename - const char* szOriginalFileName = pFile->szOriginalFileName; - *pFile = file; - pFile->szOriginalFileName = szOriginalFileName; - return ZD_ERROR_SUCCESS; -} - -// returns the number of files in this tree, including this and sublevels -unsigned ZipDir::FileEntryTree::NumFilesTotal() const -{ - unsigned numFiles = (unsigned)m_mapFiles.size(); - for (SubdirMap::const_iterator it = m_mapDirs.begin(); it != m_mapDirs.end(); ++it) - { - numFiles += it->second->NumFilesTotal(); - } - return numFiles; -} - -#ifdef _TEST_ -size_t g_nSF = 0, g_nSS = 0, g_nSN = 0, g_nSNa = 0, g_nSH; -size_t g_nGF = 0, g_nGS = 0, g_nGN = 0, g_nGNa = 0, g_nGH; -#endif - -// returns the size required to serialize the tree -size_t ZipDir::FileEntryTree::GetSizeSerialized() const -{ - // the total size of name pool gets aligned on 4-byte boundary - size_t nSizeOfNamePool = 0; - size_t nSizeOfFileEntries = 0, nSizeOfDirEntries = 0; - size_t nSizeOfSubdirs = 0; - - for (SubdirMap::const_iterator itDir = m_mapDirs.begin(); itDir != m_mapDirs.end(); ++itDir) - { - nSizeOfDirEntries += sizeof(DirEntry); - const char* dirname = itDir->first; - nSizeOfNamePool += strlen(dirname) + 1; - nSizeOfSubdirs += itDir->second->GetSizeSerialized(); - } - - // for each file, we need to have an entry in the name pool and in the file list - for (FileMap::const_iterator itFile = m_mapFiles.begin(); itFile != m_mapFiles.end(); ++itFile) - { - nSizeOfFileEntries += sizeof(FileEntry); - const char* fname = itFile->first; - nSizeOfNamePool += strlen(fname) + 1; - } - - if (nSizeOfNamePool > 0xFFFF) - { - // we don't support so long names/directories - THROW_ZIPDIR_ERROR(ZD_ERROR_UNSUPPORTED, "Name pool larger then 65536 bytes"); - } - -#ifdef _TEST_ - g_nGF += nSizeOfFileEntries; - g_nGS += nSizeOfDirEntries; - g_nGN += nSizeOfNamePool; - g_nGNa += ((nSizeOfNamePool + 3) & ~3); - g_nGH += sizeof(DirHeader); -#endif - - return sizeof(DirHeader) + ((nSizeOfNamePool + 3) & ~3) + nSizeOfDirEntries + nSizeOfFileEntries + nSizeOfSubdirs; -} - -// serializes into the memory -size_t ZipDir::FileEntryTree::Serialize (DirHeader* pDirHeader) const -{ - pDirHeader->numDirs = (ZipFile::ushort)m_mapDirs.size(); - pDirHeader->numFiles = (ZipFile::ushort)m_mapFiles.size(); - DirEntry* pDirEntries = (DirEntry*)(pDirHeader + 1); - FileEntry* pFileEntries = (FileEntry*)(pDirEntries + pDirHeader->numDirs); - char* pNamePool = (char*)(pFileEntries + pDirHeader->numFiles); - - char* pName = pNamePool; - DirEntry* pDirEntry = pDirEntries; - FileEntry* pFileEntry = pFileEntries; - - SubdirMap::const_iterator itDir; - for (itDir = m_mapDirs.begin(); itDir != m_mapDirs.end(); ++itDir) - { - pDirEntry->nNameOffset = (ZipFile::ulong)(pName - pNamePool); - size_t nNameLen = strlen(itDir->first); - memcpy (pName, itDir->first, nNameLen + 1); - pName += nNameLen + 1; - ++pDirEntry; - } - - assert ((FileEntry*)pDirEntry == pFileEntry); - - // for each file, we need to have an entry in the name pool and in the file list - for (FileMap::const_iterator itFile = m_mapFiles.begin(); itFile != m_mapFiles.end(); ++itFile) - { - *pFileEntry = itFile->second; - const char* filename = itFile->first; - pFileEntry->nNameOffset = (ZipFile::ushort)(pName - pNamePool); - size_t nNameLen = strlen(filename); - memcpy (pName, filename, nNameLen + 1); - pName += nNameLen + 1; - ++pFileEntry; - } - assert ((const char*)pFileEntry == pNamePool); - - // now the name pool is full. Go on and fill the other directories - const char* pSubdirHeader = (const char*)(((UINT_PTR)(pName + 3)) & ~3); - -#ifdef _TEST_ - g_nSF += pDirHeader->numFiles * sizeof(FileEntry); - g_nSS += pDirHeader->numDirs * sizeof(DirEntry); - g_nSN += pName - pNamePool; - g_nSNa += pSubdirHeader - pNamePool; - g_nSH += sizeof(DirHeader); -#endif - - pDirEntry = pDirEntries; - for (itDir = m_mapDirs.begin(); itDir != m_mapDirs.end(); ++itDir) - { - pDirEntry->nDirHeaderOffset = (ZipFile::ulong)(pSubdirHeader - (const char*)pDirEntry); - pSubdirHeader += itDir->second->Serialize ((DirHeader*)pSubdirHeader); - ++pDirEntry; - } - - - return pSubdirHeader - (const char*)pDirHeader; -} - - - -void ZipDir::FileEntryTree::Clear() -{ - for (SubdirMap::iterator it = m_mapDirs.begin(); it != m_mapDirs.end(); ++it) - { - delete it->second; - } - m_mapDirs.clear(); - m_mapFiles.clear(); -} - - -size_t ZipDir::FileEntryTree::GetSize() const -{ - size_t nSize = sizeof(*this); - for (SubdirMap::const_iterator itDir = m_mapDirs.begin(); itDir != m_mapDirs.end(); ++itDir) - { - nSize += strlen(itDir->first) + sizeof(*itDir) + itDir->second->GetSize(); - } - - for (FileMap::const_iterator itFile = m_mapFiles.begin(); itFile != m_mapFiles.end(); ++itFile) - { - nSize += strlen(itFile->first) + sizeof(*itFile); - } - return nSize; -} - -size_t ZipDir::FileEntryTree::GetCompressedFileSize() const -{ - size_t nSize = 0; - for (SubdirMap::const_iterator itDir = m_mapDirs.begin(); itDir != m_mapDirs.end(); ++itDir) - { - nSize += itDir->second->GetCompressedFileSize(); - } - - for (FileMap::const_iterator itFile = m_mapFiles.begin(); itFile != m_mapFiles.end(); ++itFile) - { - nSize += itFile->second.desc.lSizeCompressed; - } - return nSize; -} - -size_t ZipDir::FileEntryTree::GetUncompressedFileSize() const -{ - size_t nSize = 0; - for (SubdirMap::const_iterator itDir = m_mapDirs.begin(); itDir != m_mapDirs.end(); ++itDir) - { - nSize += itDir->second->GetUncompressedFileSize(); - } - - for (FileMap::const_iterator itFile = m_mapFiles.begin(); itFile != m_mapFiles.end(); ++itFile) - { - nSize += itFile->second.desc.lSizeUncompressed; - } - return nSize; -} - -bool ZipDir::FileEntryTree::IsOwnerOf (const FileEntry* pFileEntry) const -{ - for (FileMap::const_iterator itFile = m_mapFiles.begin(); itFile != m_mapFiles.end(); ++itFile) - { - if (pFileEntry == &itFile->second) - { - return true; - } - } - - for (SubdirMap::const_iterator itDir = m_mapDirs.begin(); itDir != m_mapDirs.end(); ++itDir) - { - if (itDir->second->IsOwnerOf (pFileEntry)) - { - return true; - } - } - - return false; -} - -ZipDir::FileEntryTree* ZipDir::FileEntryTree::FindDir(const char* szDirName) -{ - SubdirMap::iterator it = m_mapDirs.find (szDirName); - if (it == m_mapDirs.end()) - { - return NULL; - } - else - { - return it->second; - } -} - -ZipDir::FileEntryTree::FileMap::iterator ZipDir::FileEntryTree::FindFile (const char* szFileName) -{ - return m_mapFiles.find (szFileName); -} - -ZipDir::FileEntry* ZipDir::FileEntryTree::GetFileEntry(FileMap::iterator it) -{ - return it == GetFileEnd() ? NULL : &it->second; -} - -ZipDir::FileEntryTree* ZipDir::FileEntryTree::GetDirEntry(SubdirMap::iterator it) -{ - return it == GetDirEnd() ? NULL : it->second; -} - -const ZipDir::FileEntry* ZipDir::FileEntryTree::GetFileEntry(FileMap::const_iterator it) const -{ - return it == GetFileEnd() ? NULL : &it->second; -} - -const ZipDir::FileEntryTree* ZipDir::FileEntryTree::GetDirEntry(SubdirMap::const_iterator it) const -{ - return it == GetDirEnd() ? NULL : it->second; -} - -ZipDir::ErrorEnum ZipDir::FileEntryTree::RemoveDir (const char* szDirName) -{ - SubdirMap::iterator itRemove = m_mapDirs.find (szDirName); - if (itRemove == m_mapDirs.end()) - { - return ZD_ERROR_FILE_NOT_FOUND; - } - - delete itRemove->second; - m_mapDirs.erase (itRemove); - return ZD_ERROR_SUCCESS; -} - -ZipDir::ErrorEnum ZipDir::FileEntryTree::RemoveFile (const char* szFileName) -{ - FileMap::iterator itRemove = m_mapFiles.find (szFileName); - if (itRemove == m_mapFiles.end()) - { - return ZD_ERROR_FILE_NOT_FOUND; - } - - m_mapFiles.erase (itRemove); - return ZD_ERROR_SUCCESS; -} - -size_t ZipDir::FileEntryTree::NumDirsTotal() const -{ - size_t result = m_mapDirs.size(); - SubdirMap::const_iterator it; - for (it = m_mapDirs.begin(); it != m_mapDirs.end(); ++it) - { - result += it->second->NumDirsTotal(); - } - return result; -} diff --git a/Code/Tools/CryCommonTools/ZipDir/ZipDirTree.h b/Code/Tools/CryCommonTools/ZipDir/ZipDirTree.h deleted file mode 100644 index 0e8af76142..0000000000 --- a/Code/Tools/CryCommonTools/ZipDir/ZipDirTree.h +++ /dev/null @@ -1,103 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYCOMMONTOOLS_ZIPDIR_ZIPDIRTREE_H -#define CRYINCLUDE_CRYCOMMONTOOLS_ZIPDIR_ZIPDIRTREE_H -#pragma once - - -namespace ZipDir -{ - class FileEntryTree - { - public: - FileEntryTree() - : m_originalName(0) {} - FileEntryTree(const char* originalName) - : m_originalName(originalName) {} - ~FileEntryTree () {Clear(); } - - // adds a file to this directory - // Function can modify szPath input - ErrorEnum Add (char* szPath, char* szUnifiedPath, const FileEntry& file); - - // Adds or finds the file. Returns non-initialized structure if it was added, - // or an IsInitialized() structure if it was found - // Function can modify szPath input - FileEntry* Add (char* szPath, char* szUnifiedPath); - - // returns the number of files in this tree, including this and sublevels - unsigned NumFilesTotal() const; - - // returns the size required to serialize the tree - size_t GetSizeSerialized() const; - - // serializes into the memory - size_t Serialize (DirHeader* pDir) const; - - void Clear(); - - void Swap (FileEntryTree& rThat) - { - m_mapDirs.swap (rThat.m_mapDirs); - m_mapFiles.swap (rThat.m_mapFiles); - } - - size_t GetSize() const; - - size_t GetCompressedFileSize() const; - size_t GetUncompressedFileSize() const; - - bool IsOwnerOf (const FileEntry* pFileEntry) const; - - // subdirectories - typedef std::map > SubdirMap; - // file entries - typedef std::map > FileMap; - - FileEntryTree* FindDir(const char* szDirName); - ErrorEnum RemoveDir (const char* szDirName); - ErrorEnum RemoveAll (){Clear(); return ZD_ERROR_SUCCESS; } - FileEntry* FindFileEntry (const char* szFileName); - FileMap::iterator FindFile (const char* szFileName); - ErrorEnum RemoveFile (const char* szFileName); - FileEntryTree* GetDirectory(){return this; } // the FileENtryTree is simultaneously an entry in the dir list AND the directory header - - FileMap::iterator GetFileBegin() {return m_mapFiles.begin(); } - FileMap::iterator GetFileEnd() {return m_mapFiles.end(); } - FileMap::const_iterator GetFileBegin() const {return m_mapFiles.begin(); } - FileMap::const_iterator GetFileEnd() const {return m_mapFiles.end(); } - unsigned NumFiles() const {return (unsigned)m_mapFiles.size(); } - - SubdirMap::iterator GetDirBegin() {return m_mapDirs.begin(); } - SubdirMap::iterator GetDirEnd() {return m_mapDirs.end(); } - SubdirMap::const_iterator GetDirBegin() const {return m_mapDirs.begin(); } - SubdirMap::const_iterator GetDirEnd() const {return m_mapDirs.end(); } - size_t NumDirsTotal() const; - - const char* GetFileName(FileMap::iterator it) {return it->first; } - const char* GetDirName(SubdirMap::iterator it) {return it->first; } - const char* GetOriginalName() const{ return m_originalName; } - - FileEntry* GetFileEntry(FileMap::iterator it); - FileEntryTree* GetDirEntry(SubdirMap::iterator it); - const FileEntry* GetFileEntry(FileMap::const_iterator it) const; - const FileEntryTree* GetDirEntry(SubdirMap::const_iterator it) const; - - protected: - SubdirMap m_mapDirs; - FileMap m_mapFiles; - const char* m_originalName; - }; -} -#endif // CRYINCLUDE_CRYCOMMONTOOLS_ZIPDIR_ZIPDIRTREE_H diff --git a/Code/Tools/CryCommonTools/ZipDir/ZipFile.h b/Code/Tools/CryCommonTools/ZipDir/ZipFile.h deleted file mode 100644 index 5e1f78050c..0000000000 --- a/Code/Tools/CryCommonTools/ZipDir/ZipFile.h +++ /dev/null @@ -1,19 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYCOMMONTOOLS_ZIPDIR_ZIPFILE_H -#define CRYINCLUDE_CRYCOMMONTOOLS_ZIPDIR_ZIPFILE_H -#pragma once - - -#endif // CRYINCLUDE_CRYCOMMONTOOLS_ZIPDIR_ZIPFILE_H diff --git a/Code/Tools/CryCommonTools/ZipDir/ZipFileFormat.h b/Code/Tools/CryCommonTools/ZipDir/ZipFileFormat.h deleted file mode 100644 index 3f2083de0f..0000000000 --- a/Code/Tools/CryCommonTools/ZipDir/ZipFileFormat.h +++ /dev/null @@ -1,388 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYCOMMONTOOLS_ZIPDIR_ZIPFILEFORMAT_H -#define CRYINCLUDE_CRYCOMMONTOOLS_ZIPDIR_ZIPFILEFORMAT_H -#pragma once - -#include -#include - -#if AZ_TRAIT_CRYCOMMONTOOLS_PACK_1 -#pragma pack(push) -#pragma pack(1) -#define PACK_GCC -#else -#define PACK_GCC __PACKED -#endif - -namespace ZipFile -{ - typedef unsigned int ulong; - typedef unsigned short ushort; - - // General-purpose bit field flags - enum - { - GPF_ENCRYPTED = 1 << 0, // If set, indicates that the file is encrypted. - GPF_DATA_DESCRIPTOR = 1 << 3, // if set, the CRC32 and sizes aren't set in the file header, but only in the data descriptor following compressed data - GPF_RESERVED_8_ENHANCED_DEFLATING = 1 << 4, // Reserved for use with method 8, for enhanced deflating. - GPF_COMPRESSED_PATCHED = 1 << 5, // the file is compressed patched data - }; - - // compression methods - enum - { - METHOD_STORE = 0, // The file is stored (no compression) - METHOD_SHRINK = 1, // The file is Shrunk - METHOD_REDUCE_1 = 2, // The file is Reduced with compression factor 1 - METHOD_REDUCE_2 = 3, // The file is Reduced with compression factor 2 - METHOD_REDUCE_3 = 4, // The file is Reduced with compression factor 3 - METHOD_REDUCE_4 = 5, // The file is Reduced with compression factor 4 - METHOD_IMPLODE = 6, // The file is Imploded - METHOD_TOKENIZE = 7, // Reserved for Tokenizing compression algorithm - METHOD_DEFLATE = 8, // The file is Deflated - METHOD_DEFLATE64 = 9, // Enhanced Deflating using Deflate64(tm) - METHOD_IMPLODE_PKWARE = 10, // PKWARE Date Compression Library Imploding - METHOD_DEFLATE_AND_ENCRYPT = 11 // Deflate + Custom encryption - }; - - // version numbers - enum - { - VERSION_DEFAULT = 10, // Default value - - VERSION_TYPE_VOLUMELABEL = 11, // File is a volume label - VERSION_TYPE_FOLDER = 20, // File is a folder (directory) - VERSION_TYPE_PATCHDATASET = 27, // File is a patch data set - VERSION_TYPE_ZIP64 = 45, // File uses ZIP64 format extensions - - VERSION_COMPRESSION_DEFLATE = 20, // File is compressed using Deflate compression - VERSION_COMPRESSION_DEFLATE64 = 21, // File is compressed using Deflate64(tm) - VERSION_COMPRESSION_DCLIMPLODE = 25, // File is compressed using PKWARE DCL Implode - VERSION_COMPRESSION_BZIP2 = 46, // File is compressed using BZIP2 compression* - VERSION_COMPRESSION_LZMA = 63, // File is compressed using LZMA - VERSION_COMPRESSION_PPMD = 63, // File is compressed using PPMd+ - - VERSION_ENCRYPTION_PKWARE = 20, // File is encrypted using traditional PKWARE encryption - VERSION_ENCRYPTION_DES = 50, // File is encrypted using DES - VERSION_ENCRYPTION_3DES = 50, // File is encrypted using 3DES - VERSION_ENCRYPTION_RC2 = 50, // File is encrypted using original RC2 encryption - VERSION_ENCRYPTION_RC4 = 50, // File is encrypted using RC4 encryption - VERSION_ENCRYPTION_AES = 51, // File is encrypted using AES encryption - VERSION_ENCRYPTION_RC2C = 51, // File is encrypted using corrected RC2 encryption** - VERSION_ENCRYPTION_RC4C = 52, // File is encrypted using corrected RC2-64 encryption** - VERSION_ENCRYPTION_NOOAEP = 61, // File is encrypted using non-OAEP key wrapping*** - VERSION_ENCRYPTION_CDR = 62, // Central directory encryption - VERSION_ENCRYPTION_BLOWFISH = 63, // File is encrypted using Blowfish - VERSION_ENCRYPTION_TWOFISH = 63, // File is encrypted using Twofish - }; - - // creator numbers - enum - { - CREATOR_MSDOS = 0, // MS-DOS and OS/2 (FAT / VFAT / FAT32 file systems) - CREATOR_AMIGA = 1, // Amiga - CREATOR_OpenVMS = 2, // OpenVMS - CREATOR_UNIX = 3, // UNIX - CREATOR_VM = 4, // VM/CMS - CREATOR_ATARI = 5, // Atari ST - CREATOR_OS2 = 6, // OS/2 H.P.F.S. - CREATOR_MACINTOSH = 7, // Macintosh - CREATOR_ZSYSTEM = 8, // Z-System - CREATOR_CPM = 9, // CP/M - CREATOR_WINDOWS = 10, // Windows NTFS - CREATOR_MVS = 11, // MVS (OS/390 - Z/OS) - CREATOR_VSE = 12, // VSE - CREATOR_ACORN = 13, // Acorn Risc - CREATOR_VFAT = 14, // VFAT - CREATOR_AMVS = 15, // alternate MVS - CREATOR_BEOS = 16, // BeOS - CREATOR_TANDEM = 17, // Tandem - CREATOR_OS400 = 18, // OS/400 - CREATOR_OSX = 19, // OS X (Darwin) - - CREATOR_UNUSED = 20, // 20 thru 255 - unused - }; - - enum - { - ZIP64_SEE_EXTENSION = -1 // If an archive is in ZIP64 format - // and a value in a field is 0xFFFFFFFF (or 0xFFFF), the size will be - // in the corresponding 8 byte (or 4 byte) ZIP64 extended information. - }; - - // end of Central Directory Record - // followed by the .zip file comment (variable size, can be empty, obtained from nCommentLength) - struct CDREnd - { - enum - { - SIGNATURE = 0x06054b50 - }; - ulong lSignature; // end of central dir signature 4 bytes (0x06054b50) - ushort nDisk; // number of this disk 2 bytes - ushort nCDRStartDisk; // number of the disk with the start of the central directory 2 bytes - ushort numEntriesOnDisk; // total number of entries in the central directory on this disk 2 bytes - ushort numEntriesTotal; // total number of entries in the central directory 2 bytes - ulong lCDRSize; // size of the central directory 4 bytes - ulong lCDROffset; // offset of start of central directory with respect to the starting disk number 4 bytes - ushort nCommentLength; // .ZIP file comment length 2 bytes - - AUTO_STRUCT_INFO - - // .ZIP file comment (variable size, can be empty) follows - } PACK_GCC; - - // end of Central Directory Record - // followed by the zip64 extensible data sector (variable size, can be empty, obtained from nExtDataLength) - struct CDREnd_ZIP64 - { - enum - { - SIGNATURE = 0x06064b50 - }; - ulong lSignature; // end of central dir signature 4 bytes (0x06064b50) - uint64 nExtDataLength; // The value stored into the "size of zip64 end of central directory record" should be the size of the remaining record and should not include the leading 12 bytes. 8 bytes - ushort nVersionMadeBy; // version made by 2 bytes - ushort nVersionNeeded; // version needed to extract 2 bytes - ulong nDisk; // number of this disk 4 bytes - ulong nCDRStartDisk; // number of the disk with the start of the central directory 4 bytes - uint64 numEntriesOnDisk; // total number of entries in the central directory on this disk 8 bytes - uint64 numEntriesTotal; // total number of entries in the central directory 8 bytes - uint64 lCDRSize; // size of the central directory 8 bytes - uint64 lCDROffset; // offset of start of central directory with respect to the starting disk number 8 bytes - - AUTO_STRUCT_INFO - - // zip64 extensible data sector (variable size, can be empty) follows - } PACK_GCC; - - // end of Central Directory Locator - struct CDRLocator_ZIP64 - { - enum - { - SIGNATURE = 0x07064b50 - }; - ulong lSignature; // end of central loc signature 4 bytes (0x07064b50) - ulong nCDR64StartDisk; // number of the disk with the start of the zip64 end of central directory 4 bytes - uint64 lCDR64EndOffset; // relative offset of the zip64 end of central directory record 8 bytes - ulong nDisks; // number of disks 4 bytes - - AUTO_STRUCT_INFO - } PACK_GCC; - - // This descriptor exists only if bit 3 of the general - // purpose bit flag is set (see below). It is byte aligned - // and immediately follows the last byte of compressed data. - // This descriptor is used only when it was not possible to - // seek in the output .ZIP file, e.g., when the output .ZIP file - // was standard output or a non seekable device. For Zip64 format - // archives, the compressed and uncompressed sizes are 8 bytes each. - struct DataDescriptor - { - ulong lCRC32; // crc-32 4 bytes - ulong lSizeCompressed; // compressed size 4 bytes - ulong lSizeUncompressed; // uncompressed size 4 bytes - - bool operator == (const DataDescriptor& d) const - { - return lCRC32 == d.lCRC32 && lSizeCompressed == d.lSizeCompressed && lSizeUncompressed == d.lSizeUncompressed; - } - bool operator != (const DataDescriptor& d) const - { - return lCRC32 != d.lCRC32 || lSizeCompressed != d.lSizeCompressed || lSizeUncompressed != d.lSizeUncompressed; - } - - bool IsZIP64([[maybe_unused]] const DataDescriptor& d) const - { - return lSizeCompressed == (ulong)ZIP64_SEE_EXTENSION || lSizeUncompressed == (ulong)ZIP64_SEE_EXTENSION; - } - - AUTO_STRUCT_INFO - } PACK_GCC; - - // When compressing files, compressed and uncompressed sizes - // should be stored in ZIP64 format (as 8 byte values) when a - // file's size exceeds 0xFFFFFFFF. However ZIP64 format may be - // used regardless of the size of a file. When extracting, if - // the zip64 extended information extra field is present for - // the file the compressed and uncompressed sizes will be 8 - // byte values. - struct DataDescriptor_ZIP64 - { - ulong lCRC32; // crc-32 4 bytes - uint64 lSizeCompressed; // compressed size 8 bytes - uint64 lSizeUncompressed; // uncompressed size 8 bytes - - bool operator == (const DataDescriptor& d) const - { - return lCRC32 == d.lCRC32 && lSizeCompressed == d.lSizeCompressed && lSizeUncompressed == d.lSizeUncompressed; - } - bool operator != (const DataDescriptor& d) const - { - return lCRC32 != d.lCRC32 || lSizeCompressed != d.lSizeCompressed || lSizeUncompressed != d.lSizeUncompressed; - } - - AUTO_STRUCT_INFO - } PACK_GCC; - - // the File Header as it appears in the CDR - // followed by: - // file name (variable size) - // extra field (variable size) - // file comment (variable size) - struct CDRFileHeader - { - enum - { - SIGNATURE = 0x02014b50 - }; - ulong lSignature; // central file header signature 4 bytes (0x02014b50) - ushort nVersionMadeBy; // version made by 2 bytes - ushort nVersionNeeded; // version needed to extract 2 bytes - ushort nFlags; // general purpose bit flag 2 bytes - ushort nMethod; // compression method 2 bytes - ushort nLastModTime; // last mod file time 2 bytes - ushort nLastModDate; // last mod file date 2 bytes - DataDescriptor desc; - ushort nFileNameLength; // file name length 2 bytes - ushort nExtraFieldLength; // extra field length 2 bytes - ushort nFileCommentLength; // file comment length 2 bytes - ushort nDiskNumberStart; // disk number start 2 bytes - ushort nAttrInternal; // internal file attributes 2 bytes - ulong lAttrExternal; // external file attributes 4 bytes - - // This is the offset from the start of the first disk on - // which this file appears, to where the local header should - // be found. If an archive is in zip64 format and the value - // in this field is 0xFFFFFFFF, the size will be in the - // corresponding 8 byte zip64 extended information extra field. - enum - { - ZIP64_LOCAL_HEADER_OFFSET = 0xFFFFFFFF - }; - ulong lLocalHeaderOffset; // relative offset of local header 4 bytes - - bool IsZIP64([[maybe_unused]] const CDRFileHeader& d) const - { - return desc.IsZIP64(desc) || nDiskNumberStart == (ushort)ZIP64_SEE_EXTENSION || lLocalHeaderOffset == (ulong)ZIP64_SEE_EXTENSION; - } - - AUTO_STRUCT_INFO - } PACK_GCC; - - - // this is the local file header that appears before the compressed data - // followed by: - // file name (variable size) - // extra field (variable size) - struct LocalFileHeader - { - enum - { - SIGNATURE = 0x04034b50 - }; - ulong lSignature; // local file header signature 4 bytes (0x04034b50) - ushort nVersionNeeded; // version needed to extract 2 bytes - ushort nFlags; // general purpose bit flag 2 bytes - ushort nMethod; // compression method 2 bytes - ushort nLastModTime; // last mod file time 2 bytes - ushort nLastModDate; // last mod file date 2 bytes - DataDescriptor desc; - ushort nFileNameLength; // file name length 2 bytes - ushort nExtraFieldLength; // extra field length 2 bytes - - bool IsZIP64([[maybe_unused]] const LocalFileHeader& d) const - { - return desc.IsZIP64(desc); - } - - AUTO_STRUCT_INFO - } PACK_GCC; - - // compression methods - enum EExtraHeaderID - { - EXTRA_ZIP64 = 0x0001, // ZIP64 extended information extra field - EXTRA_NTFS = 0x000a, // NTFS - EXTRA_UNIX = 0x000d, // UNIX - EXTRA_PATCH = 0x000f, // Patch Descriptor - }; - - ////////////////////////////////////////////////////////////////////////// - // header1+data1 + header2+data2 . . . - // Each header should consist of: - // Header ID - 2 bytes - // Data Size - 2 bytes - struct ExtraFieldHeader - { - ushort headerID; - ushort dataSize; - - AUTO_STRUCT_INFO - } PACK_GCC; - - struct ExtraNTFSHeader - { - ulong reserved; // 4 bytes. - ushort attrTag; // 2 bytes. - ushort attrSize; // 2 bytes. - - AUTO_STRUCT_INFO - } PACK_GCC; - - ////////////////////////////////////////////////////////////////////////// - // The following is the layout of the zip64 extended - // information "extra" block. If one of the size or - // offset fields in the Local or Central directory - // record is too small to hold the required data, - // a Zip64 extended information record is created. - // The order of the fields in the zip64 extended - // information record is fixed, but the fields MUST - // only appear if the corresponding Local or Central - // directory record field is set to 0xFFFF or 0xFFFFFFFF. - // - // The extended information in the Local header MUST include - // BOTH original and compressed file size fields. - - struct ExtraZIP64LocalFileHeader - { - // LocalFileHeader overrides - uint64 lSizeUncompressed; // uncompressed size 4->8 bytes - uint64 lSizeCompressed; // compressed size 4->8 bytes - - AUTO_STRUCT_INFO - } PACK_GCC; - - struct ExtraZIP64CDRFileHeader - { - // CDRFileHeader overrides - uint64 lSizeUncompressed; // uncompressed size 4->8 bytes - uint64 lSizeCompressed; // compressed size 4->8 bytes - - uint64 lLocalHeaderOffset; // relative offset of local header 4->8 bytes - ulong nDiskNumberStart; // Number of the disk on which this file starts 2->4 bytes - - AUTO_STRUCT_INFO - } PACK_GCC; -} - -#undef PACK_GCC - -#if AZ_TRAIT_CRYCOMMONTOOLS_PACK_1 -#pragma pack(pop) -#endif - -#endif // CRYINCLUDE_CRYCOMMONTOOLS_ZIPDIR_ZIPFILEFORMAT_H diff --git a/Code/Tools/CryCommonTools/ZipDir/ZipFileFormat_info.h b/Code/Tools/CryCommonTools/ZipDir/ZipFileFormat_info.h deleted file mode 100644 index 9f91eec49b..0000000000 --- a/Code/Tools/CryCommonTools/ZipDir/ZipFileFormat_info.h +++ /dev/null @@ -1,112 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYCOMMONTOOLS_ZIPDIR_ZIPFILEFORMAT_INFO_H -#define CRYINCLUDE_CRYCOMMONTOOLS_ZIPDIR_ZIPFILEFORMAT_INFO_H -#pragma once - -#include "ZipFileFormat.h" - -STRUCT_INFO_BEGIN(ZipFile::CDREnd) -STRUCT_VAR_INFO(lSignature, TYPE_INFO(ZipFile::ulong)) -STRUCT_VAR_INFO(nDisk, TYPE_INFO(ZipFile::ushort)) -STRUCT_VAR_INFO(nCDRStartDisk, TYPE_INFO(ZipFile::ushort)) -STRUCT_VAR_INFO(numEntriesOnDisk, TYPE_INFO(ZipFile::ushort)) -STRUCT_VAR_INFO(numEntriesTotal, TYPE_INFO(ZipFile::ushort)) -STRUCT_VAR_INFO(lCDRSize, TYPE_INFO(ZipFile::ulong)) -STRUCT_VAR_INFO(lCDROffset, TYPE_INFO(ZipFile::ulong)) -STRUCT_VAR_INFO(nCommentLength, TYPE_INFO(ZipFile::ushort)) -STRUCT_INFO_END(ZipFile::CDREnd) - -STRUCT_INFO_BEGIN(ZipFile::CDREnd_ZIP64) -STRUCT_VAR_INFO(lSignature, TYPE_INFO(ZipFile::ulong)) -STRUCT_VAR_INFO(nExtDataLength, TYPE_INFO(ZipFile::uint64)) -STRUCT_VAR_INFO(nVersionMadeBy, TYPE_INFO(ZipFile::ushort)) -STRUCT_VAR_INFO(nVersionNeeded, TYPE_INFO(ZipFile::ushort)) -STRUCT_VAR_INFO(nDisk, TYPE_INFO(ZipFile::ulong)) -STRUCT_VAR_INFO(nCDRStartDisk, TYPE_INFO(ZipFile::ulong)) -STRUCT_VAR_INFO(numEntriesOnDisk, TYPE_INFO(ZipFile::uint64)) -STRUCT_VAR_INFO(numEntriesTotal, TYPE_INFO(ZipFile::uint64)) -STRUCT_VAR_INFO(lCDRSize, TYPE_INFO(ZipFile::uint64)) -STRUCT_VAR_INFO(lCDROffset, TYPE_INFO(ZipFile::uint64)) -STRUCT_INFO_END(ZipFile::CDREnd_ZIP64) - -STRUCT_INFO_BEGIN(ZipFile::CDRLocator_ZIP64) -STRUCT_VAR_INFO(lSignature, TYPE_INFO(ZipFile::ulong)) -STRUCT_VAR_INFO(nCDR64StartDisk, TYPE_INFO(ZipFile::ulong)) -STRUCT_VAR_INFO(lCDR64EndOffset, TYPE_INFO(ZipFile::uint64)) -STRUCT_VAR_INFO(nDisks, TYPE_INFO(ZipFile::ulong)) -STRUCT_INFO_END(ZipFile::CDRLocator_ZIP64) - -STRUCT_INFO_BEGIN(ZipFile::DataDescriptor) -STRUCT_VAR_INFO(lCRC32, TYPE_INFO(ZipFile::ulong)) -STRUCT_VAR_INFO(lSizeCompressed, TYPE_INFO(ZipFile::ulong)) -STRUCT_VAR_INFO(lSizeUncompressed, TYPE_INFO(ZipFile::ulong)) -STRUCT_INFO_END(ZipFile::DataDescriptor) - -STRUCT_INFO_BEGIN(ZipFile::DataDescriptor_ZIP64) -STRUCT_VAR_INFO(lCRC32, TYPE_INFO(ZipFile::ulong)) -STRUCT_VAR_INFO(lSizeCompressed, TYPE_INFO(ZipFile::uint64)) -STRUCT_VAR_INFO(lSizeUncompressed, TYPE_INFO(ZipFile::uint64)) -STRUCT_INFO_END(ZipFile::DataDescriptor_ZIP64) - -STRUCT_INFO_BEGIN(ZipFile::CDRFileHeader) -STRUCT_VAR_INFO(lSignature, TYPE_INFO(ZipFile::ulong)) -STRUCT_VAR_INFO(nVersionMadeBy, TYPE_INFO(ZipFile::ushort)) -STRUCT_VAR_INFO(nVersionNeeded, TYPE_INFO(ZipFile::ushort)) -STRUCT_VAR_INFO(nFlags, TYPE_INFO(ZipFile::ushort)) -STRUCT_VAR_INFO(nMethod, TYPE_INFO(ZipFile::ushort)) -STRUCT_VAR_INFO(nLastModTime, TYPE_INFO(ZipFile::ushort)) -STRUCT_VAR_INFO(nLastModDate, TYPE_INFO(ZipFile::ushort)) -STRUCT_VAR_INFO(desc, TYPE_INFO(ZipFile::DataDescriptor)) -STRUCT_VAR_INFO(nFileNameLength, TYPE_INFO(ZipFile::ushort)) -STRUCT_VAR_INFO(nExtraFieldLength, TYPE_INFO(ZipFile::ushort)) -STRUCT_VAR_INFO(nFileCommentLength, TYPE_INFO(ZipFile::ushort)) -STRUCT_VAR_INFO(nDiskNumberStart, TYPE_INFO(ZipFile::ushort)) -STRUCT_VAR_INFO(nAttrInternal, TYPE_INFO(ZipFile::ushort)) -STRUCT_VAR_INFO(lAttrExternal, TYPE_INFO(ZipFile::ulong)) -STRUCT_VAR_INFO(lLocalHeaderOffset, TYPE_INFO(ZipFile::ulong)) -STRUCT_INFO_END(ZipFile::CDRFileHeader) - -STRUCT_INFO_BEGIN(ZipFile::LocalFileHeader) -STRUCT_VAR_INFO(lSignature, TYPE_INFO(ZipFile::ulong)) -STRUCT_VAR_INFO(nVersionNeeded, TYPE_INFO(ZipFile::ushort)) -STRUCT_VAR_INFO(nFlags, TYPE_INFO(ZipFile::ushort)) -STRUCT_VAR_INFO(nMethod, TYPE_INFO(ZipFile::ushort)) -STRUCT_VAR_INFO(nLastModTime, TYPE_INFO(ZipFile::ushort)) -STRUCT_VAR_INFO(nLastModDate, TYPE_INFO(ZipFile::ushort)) -STRUCT_VAR_INFO(desc, TYPE_INFO(ZipFile::DataDescriptor)) -STRUCT_VAR_INFO(nFileNameLength, TYPE_INFO(ZipFile::ushort)) -STRUCT_VAR_INFO(nExtraFieldLength, TYPE_INFO(ZipFile::ushort)) -STRUCT_INFO_END(ZipFile::LocalFileHeader) - -STRUCT_INFO_BEGIN(ZipFile::ExtraFieldHeader) -STRUCT_VAR_INFO(headerID, TYPE_INFO(ZipFile::ushort)) -STRUCT_VAR_INFO(dataSize, TYPE_INFO(ZipFile::ushort)) -STRUCT_INFO_END(ZipFile::ExtraFieldHeader) - -STRUCT_INFO_BEGIN(ZipFile::ExtraNTFSHeader) -STRUCT_VAR_INFO(reserved, TYPE_INFO(ZipFile::ulong)) -STRUCT_VAR_INFO(attrTag, TYPE_INFO(ZipFile::ushort)) -STRUCT_VAR_INFO(attrSize, TYPE_INFO(ZipFile::ushort)) -STRUCT_INFO_END(ZipFile::ExtraNTFSHeader) - -STRUCT_INFO_BEGIN(ZipFile::ExtraZIP64Data) -STRUCT_VAR_INFO(lSizeUncompressed, TYPE_INFO(ZipFile::uint64)) -STRUCT_VAR_INFO(lSizeCompressed, TYPE_INFO(ZipFile::uint64)) -STRUCT_VAR_INFO(lLocalHeaderOffset, TYPE_INFO(ZipFile::uint64)) -STRUCT_VAR_INFO(nDiskNumberStart, TYPE_INFO(ZipFile::ulong)) -STRUCT_INFO_END(ZipFile::ExtraZIP64Data) - - -#endif // CRYINCLUDE_CRYCOMMONTOOLS_ZIPDIR_ZIPFILEFORMAT_INFO_H diff --git a/Code/Tools/CryCommonTools/ZipDir/zipdirstructures.h b/Code/Tools/CryCommonTools/ZipDir/zipdirstructures.h deleted file mode 100644 index dac298c90c..0000000000 --- a/Code/Tools/CryCommonTools/ZipDir/zipdirstructures.h +++ /dev/null @@ -1,426 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// This file contains only the support definitions for CZipDir class -// implementation. This it to unload the ZipDir.h from secondary stuff. - -#ifndef CRYINCLUDE_CRYCOMMONTOOLS_ZIPDIR_ZIPDIRSTRUCTURES_H -#define CRYINCLUDE_CRYCOMMONTOOLS_ZIPDIR_ZIPDIRSTRUCTURES_H -#pragma once - -#include - -namespace ZipDir -{ - // possible errors occuring during the method execution - // to avoid clushing with the global Windows defines, we prefix these with ZD_ - enum ErrorEnum - { - ZD_ERROR_SUCCESS = 0, - ZD_ERROR_IO_FAILED, - ZD_ERROR_UNEXPECTED, - ZD_ERROR_UNSUPPORTED, - ZD_ERROR_INVALID_SIGNATURE, - ZD_ERROR_ZIP_FILE_IS_CORRUPT, - ZD_ERROR_DATA_IS_CORRUPT, - ZD_ERROR_NO_CDR, - ZD_ERROR_CDR_IS_CORRUPT, - ZD_ERROR_NO_MEMORY, - ZD_ERROR_VALIDATION_FAILED, - ZD_ERROR_CRC32_CHECK, - ZD_ERROR_ZLIB_FAILED, - ZD_ERROR_ZLIB_CORRUPTED_DATA, - ZD_ERROR_ZLIB_NO_MEMORY, - ZD_ERROR_CORRUPTED_DATA, - ZD_ERROR_INVALID_CALL, - ZD_ERROR_NOT_IMPLEMENTED, - ZD_ERROR_FILE_NOT_FOUND, - ZD_ERROR_DIR_NOT_FOUND, - ZD_ERROR_NAME_TOO_LONG, - ZD_ERROR_INVALID_PATH, - ZD_ERROR_FILE_ALREADY_EXISTS - }; - - // the error describes the reason of the error, as well as the error code, line of code where it happened etc. - struct Error - { - Error(ErrorEnum _nError, const char* _szDescription, const char* _szFunction, const char* _szFile, unsigned _nLine) - : nError(_nError) - , m_szDescription(_szDescription) - , szFunction(_szFunction) - , szFile(_szFile) - , nLine(_nLine) - { - } - - ErrorEnum nError; - const char* getError(); - - const char* getDescription() {return m_szDescription; } - const char* szFunction, * szFile; - unsigned nLine; - protected: - // the description of the error; if needed, will be made as a dynamic string - const char* m_szDescription; - }; - - //#define THROW_ZIPDIR_ERROR(ZD_ERR,DESC) throw Error (ZD_ERR, DESC, __FUNCTION__, __FILE__, __LINE__) - //#define THROW_ZIPDIR_ERROR(ZD_ERR,DESC) CryWarning( VALIDATOR_MODULE_SYSTEM,VALIDATOR_WARNING,DESC ) - -#define THROW_ZIPDIR_ERROR(ZD_ERR, DESC) - - struct EncryptionKey - { - uint32 key[4]; - - explicit EncryptionKey(const uint32 data[4]) - { - memcpy(key, data, sizeof(key)); - } - - EncryptionKey() - { - memset(key, 0, sizeof(key)); - } - }; - - // possible initialization methods - enum InitMethodEnum - { - // initialize as fast as possible, with minimal validation - ZD_INIT_FAST, - // after initialization, scan through all file headers, precache the actual file data offset values and validate the headers - ZD_INIT_FULL, - // scan all file headers and try to decompress the data, searching for corrupted files - ZD_INIT_VALIDATE, - // maximum level of validation, checks for integrity of the archive - ZD_INIT_VALIDATE_MAX = ZD_INIT_VALIDATE - }; - - typedef void* (* FnAlloc) (void* pUserData, unsigned nItems, unsigned nSize); - typedef void (* FnFree) (void* pUserData, void* pAddress); - - ////////////////////////////////////////////////////////////////////////// - // This structure contains the pointers to functions for memory management - // by default, it's initialized to default malloc/free -#if 0 - struct Allocator - { - FnAlloc fnAlloc; - FnFree fnFree; - void* pOpaque; - - static void* DefaultAlloc (void*, unsigned nItems, unsigned nSize) - { - return malloc (nItems * nSize); - } - - static void DefaultFree (void*, void* pAddress) - { - free (pAddress); - } - - void* Alloc (unsigned nItems, unsigned nSize) - { - return this->fnAlloc(this->pOpaque, nItems, nSize); - } - - void Free (void* pAddress) - { - this->fnFree (this->pOpaque, pAddress); - } - - // constructs the allocator object; by default, the stdlib functions are used - Allocator (FnAlloc fnAllocIn = DefaultAlloc, FnFree fnFreeIn = DefaultFree, void* pOpaqueIn = NULL) - : fnAlloc(fnAllocIn) - , fnFree (fnFreeIn) - , pOpaque(pOpaqueIn) - { - } - }; -#endif - // instance of this class just releases the memory when it's destructed - struct SmartHeapPtr - { - SmartHeapPtr() - : m_pAddress(NULL) - { - } - ~SmartHeapPtr() - { - Release(); - } - - void Attach (void* p) - { - Release(); - m_pAddress = p; - } - - void* Detach() - { - void* p = m_pAddress; - m_pAddress = NULL; - return p; - } - - void Release() - { - if (m_pAddress) - { - free(m_pAddress); - m_pAddress = NULL; - } - } - protected: - // the pointer to free - void* m_pAddress; - }; - - typedef SmartHeapPtr SmartPtr; - - // Uncompresses raw (without wrapping) data that is compressed with method 8 (deflated) in the Zip file - // returns one of the Z_* errors (Z_OK upon success) - extern int ZipRawUncompress (void* pUncompressed, unsigned long* pDestSize, const void* pCompressed, unsigned long nSrcSize); - - // compresses the raw data into raw data. The buffer for compressed data itself with the heap passed. Uses method 8 (deflate) - // returns one of the Z_* errors (Z_OK upon success), and the size in *pDestSize. the pCompressed buffer must be at least nSrcSize*1.001+12 size - - extern int ZipRawCompress (const void* pUncompressed, unsigned long* pDestSize, void* pCompressed, unsigned long nSrcSize, int nLevel); - extern int ZipRawCompressZSTD(const void* pUncompressed, unsigned long* pDestSize, void* pCompressed, unsigned long nSrcSize, int nLevel); - extern int ZipRawCompressLZ4(const void* pUncompressed, unsigned long* pDestSize, void* pCompressed, unsigned long nSrcSize, int nLevel); - - //returns an estimate of the size of the data when compressed - extern int GetCompressedSizeEstimate(unsigned long uncompressedSize, CompressionCodec::Codec codec = CompressionCodec::Codec::ZLIB); - - enum class ValidationResult - { - OK = 0, - SIZE_MISMATCH, - DATA_CORRUPTED, - DATA_NO_MATCH - }; - //decompresses a zstd blob and compares with the original - returns true if original and uncompressed data match - ValidationResult ValidateZSTDCompressedDataWithOriginalData(const void* pUncompressed, unsigned long uncompressedSize, const void* pCompressed, unsigned long compressedSize); - - ////////////////////////////////////////////////////////////////////////// - struct SExtraZipFileData - { - SExtraZipFileData() - : nLastModifyTime(0) {} - - uint64 nLastModifyTime; - }; - - // this is the record about the file in the Zip file. - struct FileEntry - { - enum - { - INVALID_DATA_OFFSET = 0xFFFFFFFF - }; - - ZipFile::DataDescriptor desc; - ZipFile::ulong nFileHeaderOffset; // offset of the local file header - ZipFile::ulong nFileDataOffset; // offset of the packed info inside the file; NOTE: this can be INVALID_DATA_OFFSET, if not calculated yet! - ZipFile::ushort nMethod; // the method of compression (0 if no compression/store) - ZipFile::ushort nNameOffset; // offset of the file name in the name pool for the directory - - // the file modification times - ZipFile::ushort nLastModTime; - ZipFile::ushort nLastModDate; - - uint64 nNTFS_LastModifyTime; - - // the offset to the start of the next file's header - this - // can be used to calculate the available space in zip file - ZipFile::ulong nEOFOffset; - const char* szOriginalFileName; // original filename (for CacheRW) - - FileEntry() - : nFileHeaderOffset(INVALID_DATA_OFFSET) - , szOriginalFileName(0){} - FileEntry(const ZipFile::CDRFileHeader& header, const SExtraZipFileData& extra); - - bool IsInitialized () - { - // structure marked as non-initialized should have nFileHeaderOffset == INVALID_DATA_OFFSET - return nFileHeaderOffset != INVALID_DATA_OFFSET; - } - // returns the name of this file, given the pointer to the name pool - const char* GetName(const char* pNamePool) const - { - return pNamePool + nNameOffset; - } - - // sets the current time to modification time - // calculates CRC32 for the new data - void OnNewFileData(void* pUncompressed, unsigned nSize, unsigned nCompressedSize, unsigned nCompressionMethod, bool bContinuous); - - uint64 GetModificationTime(); - void SetFromFileTimeNTFS(int64 timestamp); - bool CompareFileTimeNTFS(int64 timestamp); - }; - - // tries to refresh the file entry from the given file (reads fromthere if needed) - // returns the error code if the operation was impossible to complete - extern ErrorEnum Refresh (FILE* f, FileEntry* pFileEntry, bool encrpytedHeaders); - - // writes into the file local header - without Extra data - // puts the new offset to the file data to the file entry - // in case of error can put INVALID_DATA_OFFSET into the data offset field of file entry - extern ErrorEnum WriteLocalHeader (FILE* f, FileEntry* pFileEntry, const char* szRelativePath, bool encrypt); - - // conversion routines for the date/time fields used in Zip - extern ZipFile::ushort DOSDate(tm*); - extern ZipFile::ushort DOSTime(tm*); - - extern const char* DOSTimeCStr(ZipFile::ushort nTime); - extern const char* DOSDateCStr(ZipFile::ushort nTime); - - struct DirHeader; - // this structure represents a subdirectory descriptor in the directory record. - // it points to the actual directory info (list of its subdirs and files), as well - // as on its name - struct DirEntry - { - ZipFile::ulong nDirHeaderOffset;// offset, in bytes, relative to this object, of the actual directory record header - ZipFile::ulong nNameOffset; // offset of the dir name in the name pool of the parent directory - // returns the name of this directory, given the pointer to the name pool of hte parent directory - const char* GetName(const char* pNamePool) const - { - return pNamePool + nNameOffset; - } - - // returns the pointer to the actual directory record. - // call this function only for the actual structure instance contained in a directory record and - // followed by the other directory records - const DirHeader* GetDirectory () const - { - return (const DirHeader*)(((const char*)this) + nDirHeaderOffset); - } - DirHeader* GetDirectory () - { - return (DirHeader*)(((char*)this) + nDirHeaderOffset); - } - }; - - // this is the head of the directory record - // the name pool follows straight the directory and file entries. - struct DirHeader - { - ZipFile::ushort numDirs; // number of directory entries - DirEntry structures - ZipFile::ushort numFiles; // number of file entries - FileEntry structures - - // returns the pointer to the name pool that follows this object - // you can only call this method for the structure instance actually followed by the dir record - const char* GetNamePool() const - { - return ((char*)(this + 1)) + (size_t)this->numDirs * sizeof(DirEntry) + (size_t)this->numFiles * sizeof(FileEntry); - } - char* GetNamePool() - { - return ((char*)(this + 1)) + (size_t)this->numDirs * sizeof(DirEntry) + (size_t)this->numFiles * sizeof(FileEntry); - } - - // returns the pointer to the i-th directory - // call this only for the actual instance of the structure at the head of dir record - const DirEntry* GetSubdirEntry(unsigned i) const - { - assert (i < numDirs); - return ((const DirEntry*)(this + 1)) + i; - } - DirEntry* GetSubdirEntry(unsigned i) - { - assert (i < numDirs); - return ((DirEntry*)(this + 1)) + i; - } - - // returns the pointer to the i-th file - // call this only for the actual instance of the structure at the head of dir record - const FileEntry* GetFileEntry (unsigned i) const - { - assert (i < numFiles); - return (const FileEntry*)(((const DirEntry*)(this + 1)) + numDirs) + i; - } - FileEntry* GetFileEntry (unsigned i) - { - assert (i < numFiles); - return (FileEntry*)(((DirEntry*)(this + 1)) + numDirs) + i; - } - - // finds the subdirectory entry by the name, using the names from the name pool - // assumes: all directories are sorted in alphabetical order. - // case-sensitive (must be lower-case if case-insensitive search in Win32 is performed) - DirEntry* FindSubdirEntry(const char* szName); - - // finds the file entry by the name, using the names from the name pool - // assumes: all directories are sorted in alphabetical order. - // case-sensitive (must be lower-case if case-insensitive search in Win32 is performed) - FileEntry* FindFileEntry(const char* szName); - }; - - // this is the sorting predicate for directory entries - struct DirEntrySortPred - { - DirEntrySortPred (const char* pNamePool) - : m_pNamePool (pNamePool) - { - } - - bool operator () (const FileEntry& left, const FileEntry& right) const - { - return strcmp(left.GetName(m_pNamePool), right.GetName(m_pNamePool)) < 0; - } - - bool operator () (const FileEntry& left, const char* szRight) const - { - return strcmp(left.GetName(m_pNamePool), szRight) < 0; - } - - bool operator () (const char* szLeft, const FileEntry& right) const - { - return strcmp(szLeft, right.GetName(m_pNamePool)) < 0; - } - - bool operator () (const DirEntry& left, const DirEntry& right) const - { - return strcmp(left.GetName(m_pNamePool), right.GetName(m_pNamePool)) < 0; - } - - bool operator () (const DirEntry& left, const char* szName) const - { - return strcmp(left.GetName(m_pNamePool), szName) < 0; - } - - bool operator () (const char* szLeft, const DirEntry& right) const - { - return strcmp(szLeft, right.GetName(m_pNamePool)) < 0; - } - - const char* m_pNamePool; - }; - - inline void tolower (string& str) - { - for (size_t i = 0; i < str.length(); ++i) - { - const_cast(str[i]) = ::tolower(str[i]); - } - } - - void Encrypt(char* buffer, size_t size, const EncryptionKey& key); - void Decrypt(char* buffer, size_t size, const EncryptionKey& key); -} - -#endif // CRYINCLUDE_CRYCOMMONTOOLS_ZIPDIR_ZIPDIRSTRUCTURES_H diff --git a/Code/Tools/CryCommonTools/crycommontools_files.cmake b/Code/Tools/CryCommonTools/crycommontools_files.cmake index d68c49836a..204a65f907 100644 --- a/Code/Tools/CryCommonTools/crycommontools_files.cmake +++ b/Code/Tools/CryCommonTools/crycommontools_files.cmake @@ -10,45 +10,6 @@ # set(FILES - PakSystem.cpp - TempFilePakExtraction.cpp - IPakSystem.h - PakSystem.h - PakXmlFileBufferSource.h - TempFilePakExtraction.h - FileUtil.cpp - PathHelpers.cpp StringHelpers.cpp - FileUtil.h - MathHelpers.h - PathHelpers.h - PropertyHelpers.h - PropertyHelpers.cpp - SimpleStringPool.h - StealingThreadPool.cpp - StealingThreadPool.h StringHelpers.h - ThreadUtils.cpp - ZipDir/ZipDirCache.cpp - ZipDir/ZipDirCacheFactory.cpp - ZipDir/ZipDirCacheRW.cpp - ZipDir/ZipDirFind.cpp - ZipDir/ZipDirFindRW.cpp - ZipDir/ZipDirList.cpp - ZipDir/ZipDirStructures.cpp - ZipDir/ZipDirTree.cpp - ThreadUtils.h - ZipDir/ZipDir.h - ZipDir/ZipDirCache.h - ZipDir/ZipDirCacheFactory.h - ZipDir/ZipDirCacheRW.h - ZipDir/ZipDirFind.h - ZipDir/ZipDirFindRW.h - ZipDir/ZipDirList.h - ZipDir/zipdirstructures.h - ZipDir/ZipDirTree.h - ZipDir/ZipFile.h - ZipDir/ZipFileFormat.h - ZipDir/ZipFileFormat_info.h - SuffixUtil.h ) diff --git a/Code/Tools/CryCommonTools/crycommontools_tests_files.cmake b/Code/Tools/CryCommonTools/crycommontools_tests_files.cmake deleted file mode 100644 index 13f6d90d3c..0000000000 --- a/Code/Tools/CryCommonTools/crycommontools_tests_files.cmake +++ /dev/null @@ -1,15 +0,0 @@ -# -# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -# its licensors. -# -# For complete copyright and license terms please see the LICENSE at the root of this -# distribution (the "License"). All use of this software is governed by the License, -# or, if provided, by the license below or the license accompanying this file. Do not -# remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# - -set(FILES - UnitTests/PathHelpersUnitTests.cpp - UnitTests/StringHelpersUnitTests.cpp -) diff --git a/Code/Tools/CryCommonTools/zlibstatd64.lib b/Code/Tools/CryCommonTools/zlibstatd64.lib deleted file mode 100644 index 779712e946..0000000000 --- a/Code/Tools/CryCommonTools/zlibstatd64.lib +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:9d9f51c3e75a4e80f45ba176511a84257146d6bc7c61f0cd582343544fd30e7c -size 277480 diff --git a/Code/Tools/CryXML/CMakeLists.txt b/Code/Tools/CryXML/CMakeLists.txt deleted file mode 100644 index a154fb6bd5..0000000000 --- a/Code/Tools/CryXML/CMakeLists.txt +++ /dev/null @@ -1,32 +0,0 @@ -# -# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -# its licensors. -# -# For complete copyright and license terms please see the LICENSE at the root of this -# distribution (the "License"). All use of this software is governed by the License, -# or, if provided, by the license below or the license accompanying this file. Do not -# remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# - -if (NOT PAL_TRAIT_BUILD_HOST_TOOLS) - return() -endif() -ly_add_target( - NAME CryXML MODULE - NAMESPACE Legacy - FILES_CMAKE - cryxml_files.cmake - INCLUDE_DIRECTORIES - PUBLIC - . - COMPILE_DEFINITIONS - PRIVATE - CRYTOOLS - RESOURCE_COMPILER - BUILD_DEPENDENCIES - PRIVATE - 3rdParty::expat - Legacy::CryCommon - Legacy::CryCommonTools -) diff --git a/Code/Tools/CryXML/CryXML.cpp b/Code/Tools/CryXML/CryXML.cpp deleted file mode 100644 index 597c751b0d..0000000000 --- a/Code/Tools/CryXML/CryXML.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// Description : Defines the entry point for the DLL application. - - -#include "CryXML_precompiled.h" -#include "CryAssert_impl.h" -#include "ICryXML.h" -#include "XMLSerializer.h" -#include -#include - -class CryXML - : public ICryXML -{ -public: - CryXML(); - virtual void AddRef(); - virtual void Release(); - virtual IXMLSerializer* GetXMLSerializer(); - -private: - int nRefCount; - XMLSerializer serializer; -}; - -static CryXML* s_pCryXML = nullptr; - -#if defined(AZ_PLATFORM_WINDOWS) && !defined(AZ_MONOLITHIC_BUILD) -BOOL APIENTRY DllMain([[maybe_unused]] HANDLE hModule, [[maybe_unused]] DWORD ul_reason_for_call, [[maybe_unused]] LPVOID lpReserved) -{ - return TRUE; -} -#endif - -extern "C" DLL_EXPORT ICryXML * __stdcall GetICryXML() -{ - PREVENT_MODULE_AND_ENVIRONMENT_SYMBOL_STRIPPING - - if (!s_pCryXML) - { - s_pCryXML = new CryXML; - } - return s_pCryXML; -} - -CryXML::CryXML() - : nRefCount(0) -{ -} - -void CryXML::AddRef() -{ - ++this->nRefCount; -} - -void CryXML::Release() -{ - --this->nRefCount; - if (this->nRefCount == 0) - { - if (this == s_pCryXML) - { - s_pCryXML = nullptr; - } - delete this; - } -} - -IXMLSerializer* CryXML::GetXMLSerializer() -{ - return &this->serializer; -} - - -// STLPort requires folowing functions defined: - -// when using STL Port _STLP_DEBUG and _STLP_DEBUG_TERMINATE - avoid actually -// crashing (default terminator seems to kill the thread, which isn't nice). -#ifdef _STLP_DEBUG_TERMINATE -void __stl_debug_terminate(void) -{ - assert(0 && "STL Debug Error"); -} -#endif -#ifdef _STLP_DEBUG_MESSAGE -void __stl_debug_message(const char* format_str, ...) -{ - va_list __args; - va_start(__args, format_str); - vprintf(format_str, __args); - va_end(__args); -} -#endif //_STLP_DEBUG_MESSAGE diff --git a/Code/Tools/CryXML/CryXML.def b/Code/Tools/CryXML/CryXML.def deleted file mode 100644 index 6275474eab..0000000000 --- a/Code/Tools/CryXML/CryXML.def +++ /dev/null @@ -1,3 +0,0 @@ -LIBRARY CryXML -EXPORTS - GetICryXML @1 diff --git a/Code/Tools/CryXML/CryXML_precompiled.cpp b/Code/Tools/CryXML/CryXML_precompiled.cpp deleted file mode 100644 index 8bb231ffd1..0000000000 --- a/Code/Tools/CryXML/CryXML_precompiled.cpp +++ /dev/null @@ -1,14 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "CryXML_precompiled.h" diff --git a/Code/Tools/CryXML/CryXML_precompiled.h b/Code/Tools/CryXML/CryXML_precompiled.h deleted file mode 100644 index b7f48067b1..0000000000 --- a/Code/Tools/CryXML/CryXML_precompiled.h +++ /dev/null @@ -1,32 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -// stdafx.h : include file for standard system include files, -// or project specific include files that are used frequently, but -// are changed infrequently -// -#pragma once - -#include - -#define CRY_ASSERT(condition) assert(condition) -#define CRY_ASSERT_TRACE(condition, message) assert(condition) -#define CRY_ASSERT_MESSAGE(condition, message) assert(condition) - -// Define this to prevent including CryAssert (there is no proper hook for turning this off, like the above). -#define CRYINCLUDE_CRYCOMMON_CRYASSERT_H - -#define CRY_STRING -#include - -#include "Cry_Math.h" diff --git a/Code/Tools/CryXML/ICryXML.h b/Code/Tools/CryXML/ICryXML.h deleted file mode 100644 index fddc95e60e..0000000000 --- a/Code/Tools/CryXML/ICryXML.h +++ /dev/null @@ -1,34 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYXML_ICRYXML_H -#define CRYINCLUDE_CRYXML_ICRYXML_H -#pragma once - - -class IXMLSerializer; - -class ICryXML -{ -public: - virtual ~ICryXML() = default; - virtual void AddRef() = 0; - virtual void Release() = 0; - virtual IXMLSerializer* GetXMLSerializer() = 0; -}; - -// Prototype for the function that is exported by the DLL - use this function to -// get a pointer to an ICryXML object. The function is exported by name as GetICryXML(). -typedef ICryXML* (* FnGetICryXML)(); - -#endif // CRYINCLUDE_CRYXML_ICRYXML_H diff --git a/Code/Tools/CryXML/IXMLSerializer.h b/Code/Tools/CryXML/IXMLSerializer.h deleted file mode 100644 index 44347beb5b..0000000000 --- a/Code/Tools/CryXML/IXMLSerializer.h +++ /dev/null @@ -1,68 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYXML_IXMLSERIALIZER_H -#define CRYINCLUDE_CRYXML_IXMLSERIALIZER_H -#pragma once - - -#include "IXml.h" -#include -class IXMLDataSink; -class IXMLDataSource; - -struct IXmlBufferSource -{ - virtual int Read(void* buffer, int size) const = 0; -}; - -class FileXmlBufferSource - : public IXmlBufferSource -{ -public: - FileXmlBufferSource(const char* path) - { - file = nullptr; - azfopen(&file, path, "r"); - } - ~FileXmlBufferSource() - { - if (file) - { - std::fclose(file); - } - } - - virtual int Read(void* buffer, int size) const - { - if (!file) - { - return 0; - } - return check_cast(std::fread(buffer, 1, size, file)); - } - -private: - mutable std::FILE* file; -}; - -class IXMLSerializer -{ -public: - virtual XmlNodeRef CreateNode(const char* tag) = 0; - virtual bool Write(XmlNodeRef root, const char* szFileName) = 0; - - virtual XmlNodeRef Read(const IXmlBufferSource& source, bool bRemoveNonessentialSpacesFromContent, int nErrorBufferSize, char* szErrorBuffer) = 0; -}; - -#endif // CRYINCLUDE_CRYXML_IXMLSERIALIZER_H diff --git a/Code/Tools/CryXML/XML/xml.cpp b/Code/Tools/CryXML/XML/xml.cpp deleted file mode 100644 index 4c117b54c7..0000000000 --- a/Code/Tools/CryXML/XML/xml.cpp +++ /dev/null @@ -1,1400 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "CryXML_precompiled.h" - -//#define _CRT_SECURE_NO_DEPRECATE 1 -//#define _CRT_NONSTDC_NO_DEPRECATE -#include - -#define XML_STATIC -#include -#include "xml.h" -#include "../IXMLSerializer.h" -#include "Util.h" -#include -#include -#include - -#include -#include -#include -#include - -///////////////////////////////////////////////////////////////////// -// String pool implementation (from expat). -///////////////////////////////////////////////////////////////////// -class CSimpleStringPool -{ -public: - enum - { - STD_BLOCK_SIZE = 4096 - }; - struct BLOCK - { - BLOCK* next; - int size; - char s[1]; - }; - unsigned int m_blockSize; - BLOCK* m_blocks; - const char* m_end; - char* m_ptr; - char* m_start; - int nUsedSpace; - int nUsedBlocks; - - CSimpleStringPool() - { - m_blockSize = STD_BLOCK_SIZE; - m_blocks = 0; - m_start = 0; - m_ptr = 0; - m_end = 0; - nUsedSpace = 0; - nUsedBlocks = 0; - } - ~CSimpleStringPool() - { - BLOCK* p = m_blocks; - while (p) - { - BLOCK* temp = p->next; - //nFree++; - CryModuleFree(p); - p = temp; - } - m_blocks = 0; - m_ptr = 0; - m_start = 0; - m_end = 0; - } - void SetBlockSize(unsigned int nBlockSize) - { - if (nBlockSize > 1024 * 1024) - { - nBlockSize = 1024 * 1024; - } - unsigned int size = 512; - while (size < nBlockSize) - { - size *= 2; - } - - m_blockSize = size; - } - char* Append(const char* ptr, int nStrLen) - { - char* ret = m_ptr; - if (m_ptr && nStrLen + 1 < (m_end - m_ptr)) - { - memcpy(m_ptr, ptr, nStrLen); - m_ptr = m_ptr + nStrLen; - *m_ptr++ = 0; // add null termination. - } - else - { - int nNewBlockSize = Util::getMax(nStrLen + 1, (int)m_blockSize); - AllocBlock(nNewBlockSize); - memcpy(m_ptr, ptr, nStrLen); - m_ptr = m_ptr + nStrLen; - *m_ptr++ = 0; // add null termination. - ret = m_start; - } - nUsedSpace += nStrLen; - return ret; - } - char* ReplaceString(const char* str1, const char* str2) - { - int nStrLen1 = strlen(str1); - int nStrLen2 = strlen(str2); - - // undo ptr1 add. - if (m_ptr != m_start) - { - m_ptr = m_ptr - nStrLen1 - 1; - } - - assert(m_ptr == str1); - - int nStrLen = nStrLen1 + nStrLen2; - - char* ret = m_ptr; - if (m_ptr && nStrLen + 1 < (m_end - m_ptr)) - { - memcpy(m_ptr, str1, nStrLen1); - memcpy(m_ptr + nStrLen1, str2, nStrLen2); - m_ptr = m_ptr + nStrLen; - *m_ptr++ = 0; // add null termination. - } - else - { - int nNewBlockSize = Util::getMax(nStrLen + 1, (int)m_blockSize); - if (m_ptr == m_start) - { - ReallocBlock(nNewBlockSize * 2); // Reallocate current block. - memcpy(m_ptr + nStrLen1, str2, nStrLen2); - } - else - { - AllocBlock(nNewBlockSize); - memcpy(m_ptr, str1, nStrLen1); - memcpy(m_ptr + nStrLen1, str2, nStrLen2); - } - - m_ptr = m_ptr + nStrLen; - *m_ptr++ = 0; // add null termination. - ret = m_start; - } - nUsedSpace += nStrLen; - return ret; - } -private: - void AllocBlock(int blockSize) - { - //nMallocs++; - BLOCK* pBlock = (BLOCK*)CryModuleMalloc(offsetof(BLOCK, s) + blockSize * sizeof(char)); - if (!pBlock) - { - // no memory. - //CryError( "Out of memory" ); - m_ptr = 0; - m_start = 0; - m_end = 0; - return; - } - pBlock->size = blockSize; - pBlock->next = m_blocks; - m_blocks = pBlock; - m_ptr = pBlock->s; - m_start = pBlock->s; - m_end = pBlock->s + blockSize; - nUsedBlocks++; - } - void ReallocBlock(int blockSize) - { - BLOCK* pThisBlock = m_blocks; - BLOCK* pPrevBlock = m_blocks->next; - m_blocks = pPrevBlock; - //nMallocs++; - BLOCK* pBlock = (BLOCK*)CryModuleRealloc(pThisBlock, offsetof(BLOCK, s) + blockSize * sizeof(char)); - if (!pBlock) - { - // no memory. - //CryError( "Out of memory" ); - m_ptr = 0; - m_start = 0; - m_end = 0; - return; - } - pBlock->size = blockSize; - pBlock->next = m_blocks; - m_blocks = pBlock; - m_ptr = pBlock->s; - m_start = pBlock->s; - m_end = pBlock->s + blockSize; - } -}; - -////////////////////////////////////////////////////////////////////////// -static int __cdecl ascii_stricmp(const char* dst, const char* src) -{ - int f, l; - do - { - if (((f = (unsigned char)(*(dst++))) >= 'A') && (f <= 'Z')) - { - f -= 'A' - 'a'; - } - if (((l = (unsigned char)(*(src++))) >= 'A') && (l <= 'Z')) - { - l -= 'A' - 'a'; - } - } - while (f && (f == l)); - return(f - l); -} - -////////////////////////////////////////////////////////////////////////// -XmlStrCmpFunc g_pXmlStrCmp = &ascii_stricmp; - -////////////////////////////////////////////////////////////////////////// -class CXmlStringData - : public IXmlStringData -{ -public: - int m_nRefCount; - XmlString m_string; - - CXmlStringData() { m_nRefCount = 0; } - virtual void AddRef() { ++m_nRefCount; } - virtual void Release() - { - if (--m_nRefCount <= 0) - { - delete this; - } - } - - virtual const char* GetString() { return m_string.c_str(); }; - virtual size_t GetStringLength() { return m_string.size(); }; -}; - -class CXmlStringPool - : public IXmlStringPool -{ -public: - char* AddString(const char* str) { return m_stringPool.Append(str, (int)strlen(str)); } -private: - CSimpleStringPool m_stringPool; -}; - -/** -****************************************************************************** -* CXmlNode implementation. -****************************************************************************** -*/ - -void CXmlNode::DeleteThis() -{ - delete this; -} - -CXmlNode::~CXmlNode() -{ - // Clear parent pointer from childs. - for (XmlNodes::const_iterator it = m_childs.begin(); it != m_childs.end(); ++it) - { - IXmlNode* node = *it; - ((CXmlNode*)node)->m_parent = 0; - } - m_pStringPool->Release(); -} - -CXmlNode::CXmlNode() -{ - m_tag = ""; - m_content = ""; - m_parent = 0; - m_nRefCount = 0; - m_pStringPool = 0; // must be changed later. -} - -CXmlNode::CXmlNode(const char* tag) -{ - m_content = ""; - m_parent = 0; - m_nRefCount = 0; - m_pStringPool = new CXmlStringPool; - m_pStringPool->AddRef(); - m_tag = m_pStringPool->AddString(tag); -} - -////////////////////////////////////////////////////////////////////////// -XmlNodeRef CXmlNode::createNode(const char* tag) -{ - CXmlNode* pNewNode = new CXmlNode; - pNewNode->m_pStringPool = m_pStringPool; - m_pStringPool->AddRef(); - pNewNode->m_tag = m_pStringPool->AddString(tag); - return XmlNodeRef(pNewNode); -} - -////////////////////////////////////////////////////////////////////////// -void CXmlNode::setTag(const char* tag) -{ - m_tag = m_pStringPool->AddString(tag); -} - -////////////////////////////////////////////////////////////////////////// -void CXmlNode::setContent(const char* str) -{ - m_content = str; -} - -////////////////////////////////////////////////////////////////////////// -bool CXmlNode::isTag(const char* tag) const -{ - return g_pXmlStrCmp(tag, m_tag) == 0; -} - -const char* CXmlNode::getAttr(const char* key) const -{ - const char* svalue = GetValue(key); - if (svalue) - { - return svalue; - } - return ""; -} - -bool CXmlNode::getAttr(const char* key, const char** value) const -{ - const char* svalue = GetValue(key); - if (svalue) - { - *value = svalue; - return true; - } - else - { - *value = ""; - return false; - } -} - -bool CXmlNode::haveAttr(const char* key) const -{ - XmlAttrConstIter it = GetAttrConstIterator(key); - if (it != m_attributes.end()) - { - return true; - } - return false; -} - -void CXmlNode::delAttr(const char* key) -{ - XmlAttrIter it = GetAttrIterator(key); - if (it != m_attributes.end()) - { - m_attributes.erase(it); - } -} - -void CXmlNode::removeAllAttributes() -{ - m_attributes.clear(); -} - -void CXmlNode::setAttr(const char* key, const char* value) -{ - XmlAttrIter it = GetAttrIterator(key); - if (it == m_attributes.end()) - { - XmlAttribute tempAttr; - tempAttr.key = m_pStringPool->AddString(key); - tempAttr.value = m_pStringPool->AddString(value); - m_attributes.push_back(tempAttr); - // Sort attributes. - //std::sort( m_attributes.begin(),m_attributes.end() ); - } - else - { - // If already exist, override this member. - it->value = m_pStringPool->AddString(value); - } -} - -void CXmlNode::setAttr(const char* key, int value) -{ - char str[128]; - azsnprintf(str, sizeof(str), "%d", value); - setAttr(key, str); -} - -void CXmlNode::setAttr(const char* key, unsigned int value) -{ - char str[128]; - azsnprintf(str, sizeof(str), "%d", value); - setAttr(key, str); -} - -void CXmlNode::setAttr(const char* key, float value) -{ - char str[128]; - azsnprintf(str, sizeof(str), "%g", value); - setAttr(key, str); -} - -void CXmlNode::setAttr(const char* key, double value) -{ - char str[128]; - azsnprintf(str, sizeof(str), "%.17g", value); - setAttr(key, str); -} - -////////////////////////////////////////////////////////////////////////// -void CXmlNode::setAttr(const char* key, int64 value) -{ - char str[32]; - azsnprintf(str, sizeof(str), "%" PRId64, value); - setAttr(key, str); -} - -////////////////////////////////////////////////////////////////////////// -void CXmlNode::setAttr(const char* key, uint64 value, bool useHexFormat) -{ - char str[32]; - if (useHexFormat) - { - azsnprintf(str, sizeof(str), "%" PRIX64, value); - } - else - { - azsnprintf(str, sizeof(str), "%" PRIu64, value); - } - setAttr(key, str); -} - -void CXmlNode::setAttr(const char* key, const Ang3& value) -{ - char str[128]; - azsnprintf(str, sizeof(str), "%g,%g,%g", value.x, value.y, value.z); - setAttr(key, str); -} - -void CXmlNode::setAttr(const char* key, const Vec2& value) -{ - char str[128]; - azsnprintf(str, sizeof(str), "%g,%g", value.x, value.y); - setAttr(key, str); -} - -void CXmlNode::setAttr(const char* key, const Vec2d& value) -{ - char str[128]; - azsnprintf(str, sizeof(str), "%.17g,%.17g", value.x, value.y); - setAttr(key, str); -} - -void CXmlNode::setAttr(const char* key, const Vec3& value) -{ - char str[128]; - azsnprintf(str, sizeof(str), "%g,%g,%g", value.x, value.y, value.z); - setAttr(key, str); -} - -void CXmlNode::setAttr(const char* key, const Vec3d& value) -{ - char str[128]; - azsnprintf(str, sizeof(str), "%.17g,%.17g,%.17g", value.x, value.y, value.z); - setAttr(key, str); -} - -void CXmlNode::setAttr(const char* key, const Vec4& value) -{ - char str[128]; - azsnprintf(str, sizeof(str), "%g,%g,%g,%g", value.x, value.y, value.z, value.w); - setAttr(key, str); -} - -void CXmlNode::setAttr(const char* key, const Quat& value) -{ - char str[128]; - azsnprintf(str, sizeof(str), "%g,%g,%g,%g", value.w, value.v.x, value.v.y, value.v.z); - setAttr(key, str); -} - -////////////////////////////////////////////////////////////////////////// -bool CXmlNode::getAttr(const char* key, int& value) const -{ - const char* svalue = GetValue(key); - if (svalue) - { - value = atoi(svalue); - return true; - } - return false; -} - -bool CXmlNode::getAttr(const char* key, unsigned int& value) const -{ - const char* svalue = GetValue(key); - if (svalue) - { - value = strtoul(svalue, NULL, 10); - return true; - } - return false; -} - -////////////////////////////////////////////////////////////////////////// -bool CXmlNode::getAttr(const char* key, int64& value) const -{ - const char* svalue = GetValue(key); - if (svalue) - { - azsscanf(svalue, "%" PRId64, &value); - return true; - } - return false; -} - -////////////////////////////////////////////////////////////////////////// -bool CXmlNode::getAttr(const char* key, uint64& value, bool useHexFormat) const -{ - const char* svalue = GetValue(key); - if (svalue) - { - if (useHexFormat) - { - azsscanf(svalue, "%" PRIX64, &value); - } - else - { - azsscanf(svalue, "%" PRIu64, &value); - } - return true; - } - return false; -} - -bool CXmlNode::getAttr(const char* key, bool& value) const -{ - const char* svalue = GetValue(key); - if (svalue) - { - value = atoi(svalue) != 0; - return true; - } - return false; -} - -bool CXmlNode::getAttr(const char* key, float& value) const -{ - const char* svalue = GetValue(key); - if (svalue) - { - value = (float)atof(svalue); - return true; - } - return false; -} - -bool CXmlNode::getAttr(const char* key, double& value) const -{ - const char* svalue = GetValue(key); - if (svalue) - { - value = atof(svalue); - return true; - } - return false; -} - -bool CXmlNode::getAttr(const char* key, Ang3& value) const -{ - const char* svalue = GetValue(key); - if (svalue) - { - float x, y, z; - if (azsscanf(svalue, "%f,%f,%f", &x, &y, &z) == 3) - { - value(x, y, z); - return true; - } - } - return false; -} - -bool CXmlNode::getAttr(const char* key, Vec2& value) const -{ - const char* svalue = GetValue(key); - if (svalue) - { - float x, y; - if (azsscanf(svalue, "%f,%f", &x, &y) == 2) - { - value = Vec2(x, y); - return true; - } - } - return false; -} - -bool CXmlNode::getAttr(const char* key, Vec2d& value) const -{ - const char* svalue = GetValue(key); - if (svalue) - { - double x, y; - if (azsscanf(svalue, "%lf,%lf", &x, &y) == 2) - { - value = Vec2d(x, y); - return true; - } - } - return false; -} - -bool CXmlNode::getAttr(const char* key, Vec3& value) const -{ - const char* svalue = GetValue(key); - if (svalue) - { - float x, y, z; - if (azsscanf(svalue, "%f,%f,%f", &x, &y, &z) == 3) - { - value(x, y, z); - return true; - } - } - return false; -} - -bool CXmlNode::getAttr(const char* key, Vec4& value) const -{ - const char* svalue = GetValue(key); - if (svalue) - { - float x, y, z, w; - if (azsscanf(svalue, "%f,%f,%f,%f", &x, &y, &z, &w) == 3) - { - value(x, y, z, w); - return true; - } - } - return false; -} - -bool CXmlNode::getAttr(const char* key, Vec3d& value) const -{ - const char* svalue = GetValue(key); - if (svalue) - { - double x, y, z; - if (azsscanf(svalue, "%lf,%lf,%lf", &x, &y, &z) == 3) - { - value = Vec3d(x, y, z); - return true; - } - } - return false; -} - -bool CXmlNode::getAttr(const char* key, Quat& value) const -{ - const char* svalue = GetValue(key); - if (svalue) - { - float w, x, y, z; - if (azsscanf(svalue, "%f,%f,%f,%f", &w, &x, &y, &z) == 4) - { - if (fabs(w) > VEC_EPSILON || fabs(x) > VEC_EPSILON || fabs(y) > VEC_EPSILON || fabs(z) > VEC_EPSILON) - { - //[AlexMcC|02.03.10] directly assign to members to avoid triggering the assert in Quat() with data from bad assets - value.w = w; - value.v = Vec3(x, y, z); - return value.IsValid(); - } - } - } - return false; -} - -////////////////////////////////////////////////////////////////////////// -bool CXmlNode::getAttr(const char* key, ColorB& value) const -{ - const char* svalue = GetValue(key); - if (svalue) - { - unsigned int r, g, b, a = 255; - int numFound = azsscanf(svalue, "%u,%u,%u,%u", &r, &g, &b, &a); - if (numFound == 3 || numFound == 4) - { - // If we only found 3 values, a should be unchanged, and still be 255 - if (r < 256 && g < 256 && b < 256 && a < 256) - { - value = ColorB(r, g, b, a); - return true; - } - } - } - return false; -} - - -XmlNodeRef CXmlNode::findChild(const char* tag) const -{ - for (XmlNodes::const_iterator it = m_childs.begin(); it != m_childs.end(); ++it) - { - if ((*it)->isTag(tag)) - { - return *it; - } - } - return 0; -} - -////////////////////////////////////////////////////////////////////////// -void CXmlNode::deleteChild(const char* tag) -{ - for (XmlNodes::iterator it = m_childs.begin(); it != m_childs.end(); ++it) - { - if ((*it)->isTag(tag)) - { - m_childs.erase(it); - return; - } - } -} - -////////////////////////////////////////////////////////////////////////// -void CXmlNode::deleteChildAt(int nIndex) -{ - if (nIndex >= 0 && nIndex < (int)m_childs.size()) - { - m_childs.erase(m_childs.begin() + nIndex); - } -} - -//! Adds new child node. -void CXmlNode::addChild(const XmlNodeRef& node) -{ - assert(node != 0); - m_childs.push_back(node); - IXmlNode* n = node; - ((CXmlNode*)n)->m_parent = this; -}; - -void CXmlNode::setParent(const XmlNodeRef& inNewParent) -{ - // note, parent ptrs are not ref counted - IXmlNode* n = inNewParent; - m_parent = (CXmlNode*)n; -} - -void CXmlNode::insertChild(int inIndex, const XmlNodeRef& inNewChild) -{ - assert(inIndex >= 0 && inIndex <= getChildCount()); - assert(inNewChild != 0); - if (inIndex >= 0 && inIndex <= getChildCount() && inNewChild) - { - if (getChildCount() == 0) - { - addChild(inNewChild); - } - else - { - IXmlNode* pNode = ((IXmlNode*)inNewChild); - pNode->AddRef(); - m_childs.insert(m_childs.begin() + inIndex, pNode); - pNode->setParent(this); - } - } -} - -void CXmlNode::replaceChild(int inIndex, const XmlNodeRef& inNewChild) -{ - assert(inIndex >= 0 && inIndex < getChildCount()); - assert(inNewChild != 0); - if (inIndex >= 0 && inIndex < getChildCount() && inNewChild) - { - IXmlNode* wasChild = m_childs[inIndex]; - - if (wasChild->getParent() == this) - { - wasChild->setParent(XmlNodeRef()); // child is orphaned, will be freed by Release() below if this parent is last holding a reference to it - } - wasChild->Release(); - inNewChild->AddRef(); - m_childs[inIndex] = inNewChild; - inNewChild->setParent(this); - } -} - -XmlNodeRef CXmlNode::newChild(const char* tagName) -{ - XmlNodeRef node = createNode(tagName); - addChild(node); - return node; -} - -void CXmlNode::removeChild(const XmlNodeRef& node) -{ - XmlNodes::iterator it = std::find(m_childs.begin(), m_childs.end(), (IXmlNode*)node); - if (it != m_childs.end()) - { - m_childs.erase(it); - } -} - -void CXmlNode::removeAllChilds() -{ - m_childs.clear(); -} - -//! Get XML Node child nodes. -XmlNodeRef CXmlNode::getChild(int i) const -{ - assert(i >= 0 && i < (int)m_childs.size()); - return m_childs[i]; -} - -////////////////////////////////////////////////////////////////////////// -void CXmlNode::copyAttributes(XmlNodeRef fromNode) -{ - IXmlNode* inode = fromNode; - CXmlNode* n = (CXmlNode*)inode; - if (n->m_pStringPool == m_pStringPool) - { - m_attributes = n->m_attributes; - } - else - { - m_attributes.resize(n->m_attributes.size()); - for (int i = 0; i < (int)n->m_attributes.size(); i++) - { - m_attributes[i].key = m_pStringPool->AddString(n->m_attributes[i].key); - m_attributes[i].value = m_pStringPool->AddString(n->m_attributes[i].value); - } - } -} - -////////////////////////////////////////////////////////////////////////// -bool CXmlNode::getAttributeByIndex(int index, const char** key, const char** value) -{ - XmlAttributes::iterator it = m_attributes.begin(); - if (it != m_attributes.end()) - { - std::advance(it, index); - if (it != m_attributes.end()) - { - *key = it->key; - *value = it->value; - return true; - } - } - return false; -} - -////////////////////////////////////////////////////////////////////////// -XmlNodeRef CXmlNode::clone() -{ - CXmlNode* node = new CXmlNode; - node->m_pStringPool = m_pStringPool; - m_pStringPool->AddRef(); - node->m_tag = m_tag; - node->m_content = m_content; - // Clone attributes. - CXmlNode* n = (CXmlNode*)(IXmlNode*)node; - n->copyAttributes(this); - // Clone sub nodes. - for (XmlNodes::const_iterator it = m_childs.begin(); it != m_childs.end(); ++it) - { - XmlNodeRef child = (*it)->clone(); - node->addChild(child); - } - - return node; -} - -////////////////////////////////////////////////////////////////////////// -static void AddTabsToString(XmlString& xml, int level) -{ - static const char* tabs[] = { - "", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - }; - // Add tabs. - if (level < sizeof(tabs) / sizeof(tabs[0])) - { - xml += tabs[level]; - } - else - { - for (int i = 0; i < level; i++) - { - xml += " "; - } - } -} - -////////////////////////////////////////////////////////////////////////// -bool CXmlNode::IsValidXmlString(const char* str) const -{ - if (strcspn(str, "\"\'&><") == strlen(str)) - { - return true; - } - return false; -} - -////////////////////////////////////////////////////////////////////////// -XmlString CXmlNode::MakeValidXmlString(const XmlString& instr) const -{ - XmlString str = instr; - - // check if str contains any invalid characters - str.replace("&", "&"); - str.replace("\"", """); - str.replace("\'", "'"); - str.replace("<", "<"); - str.replace(">", ">"); - - return str; -} - -////////////////////////////////////////////////////////////////////////// -void CXmlNode::AddToXmlString(XmlString& xml, int level) const -{ - AddTabsToString(xml, level); - - // Begin Tag - if (m_attributes.empty()) - { - xml += "<"; - xml += m_tag; - if (*m_content == 0 && m_childs.empty()) - { - // Compact tag form. - xml += " />\n"; - return; - } - xml += ">"; - } - else - { - xml += "<"; - xml += m_tag; - xml += " "; - - // Put attributes. - for (XmlAttributes::const_iterator it = m_attributes.begin(); it != m_attributes.end(); ) - { - xml += it->key; - xml += "=\""; - if (IsValidXmlString(it->value)) - { - xml += it->value; - } - else - { - xml += MakeValidXmlString(it->value); - } - it++; - if (it != m_attributes.end()) - { - xml += "\" "; - } - else - { - xml += "\""; - } - } - if (*m_content == 0 && m_childs.empty()) - { - // Compact tag form. - xml += "/>\n"; - return; - } - xml += ">"; - } - - // Put node content. - if (IsValidXmlString(m_content)) - { - xml += m_content; - } - else - { - xml += MakeValidXmlString(m_content); - } - - if (m_childs.empty()) - { - xml += "\n"; - return; - } - - xml += "\n"; - - // Add sub nodes. - for (XmlNodes::const_iterator it = m_childs.begin(); it != m_childs.end(); ++it) - { - IXmlNode* node = *it; - ((CXmlNode*)node)->AddToXmlString(xml, level + 1); - } - - // Add tabs. - AddTabsToString(xml, level); - xml += "\n"; -} - -IXmlStringData* CXmlNode::getXMLData(int nReserveMem) const -{ - CXmlStringData* pStrData = new CXmlStringData; - pStrData->m_string.reserve(nReserveMem); - AddToXmlString(pStrData->m_string, 0); - return pStrData; -} - -XmlString CXmlNode::getXML(int level) const -{ - static XmlString xml; - xml = ""; - xml.reserve(6000000); - - AddToXmlString(xml, level); - return xml; -} - -bool CXmlNode::saveToFile(const char* fileName) -{ - XmlString xml = getXML(); - FILE* file = nullptr; - azfopen(&file, fileName, "wt"); - if (file) - { - const char* sxml = (const char*)xml; - fprintf(file, "%s", sxml); - fclose(file); - return true; - } - return false; -} - -/** -****************************************************************************** -* XmlParserImp class. -****************************************************************************** -*/ -class XmlParserImp - : public IXmlStringPool -{ -public: - explicit XmlParserImp(bool bRemoveNonessentialSpacesFromContent); - ~XmlParserImp(); - void beginParse(); - bool parse(const char* buffer, int bufLen); - XmlNodeRef endParse(XmlString& errorString); - - // Add new string to pool. - char* AddString(const char* str) { return m_stringPool.Append(str, (int)strlen(str)); } - //char* AddString( const char *str ) { return (char*)str; } - -protected: - void onStartElement(const char* tagName, const char** atts); - void onEndElement(const char* tagName); - void onRawData(const char* data); - - static void startElement(void* userData, const char* name, const char** atts) - { - ((XmlParserImp*)userData)->onStartElement(name, atts); - } - static void endElement(void* userData, const char* name) - { - ((XmlParserImp*)userData)->onEndElement(name); - } - static void characterData(void* userData, const char* s, int len) - { - char str[500000]; - if (len > sizeof(str) - 1) - { - assert(0); - len = sizeof(str) - 1; - } - memcpy(str, s, len); - str[len] = 0; - ((XmlParserImp*)userData)->onRawData(str); - } - - // First node will become root node. - std::vector nodeStack; - XmlNodeRef m_root; - - XML_Parser m_parser; - CSimpleStringPool m_stringPool; - bool m_bRemoveNonessentialSpacesFromContent; -}; - -/** -****************************************************************************** -* XmlParserImp -****************************************************************************** -*/ -void XmlParserImp::onStartElement(const char* tagName, const char** atts) -{ - XmlNodeRef parent; - CXmlNode* pCNode = new CXmlNode; - pCNode->m_pStringPool = this; - pCNode->m_pStringPool->AddRef(); - pCNode->m_tag = AddString(tagName); - - XmlNodeRef node = pCNode; - - if (!nodeStack.empty()) - { - parent = nodeStack.back(); - } - else - { - m_root = node; - } - nodeStack.push_back(node); - - if (parent) - { - parent->addChild(node); - } - - uint64 line = XML_GetCurrentLineNumber((XML_Parser)m_parser); - node->setLine(line > INT_MAX ? INT_MAX : (int)line); - - // Call start element callback. - int i = 0; - int numAttrs = 0; - while (atts[i] != 0) - { - numAttrs++; - i += 2; - } - if (numAttrs > 0) - { - i = 0; - pCNode->m_attributes.resize(numAttrs); - int nAttr = 0; - while (atts[i] != 0) - { - pCNode->m_attributes[nAttr].key = AddString(atts[i]); - pCNode->m_attributes[nAttr].value = AddString(atts[i + 1]); - nAttr++; - i += 2; - } - // Sort attributes. - //std::sort( pCNode->m_attributes.begin(),pCNode->m_attributes.end() ); - } -} - -void XmlParserImp::onEndElement([[maybe_unused]] const char* tagName) -{ - assert(!nodeStack.empty()); - if (!nodeStack.empty()) - { - nodeStack.pop_back(); - } -} - -void XmlParserImp::onRawData(const char* const data) -{ - if (data && data[0]) - { - CXmlNode* const node = (CXmlNode*)(IXmlNode*)nodeStack.back(); - - if (!m_bRemoveNonessentialSpacesFromContent) - { - // Implementation note: Skipping spaces in beginning (even although - // m_bRemoveNonessentialSpacesFromContent is false) allows us - // to avoid having lot of "space only" content nodes - if (node->m_content.empty()) - { - const size_t len = strlen(data); - const size_t spaceCount = strspn(data, "\r\n\t "); - - if (spaceCount < len) - { - node->m_content += &data[spaceCount]; - } - } - else - { - node->m_content += data; - } - } - else - { - const size_t len = strlen(data); - const size_t spaceCount = strspn(data, "\r\n\t "); - - if ((spaceCount > 0) && (!node->m_content.empty())) - { - node->m_content += " "; - } - - if (spaceCount < len) - { - node->m_content += &data[spaceCount]; - } - } - } -} - -////////////////////////////////////////////////////////////////////////// -static void* custom_xml_malloc(size_t nSize) -{ - return CryModuleMalloc(nSize); -} -static void* custom_xml_realloc(void* p, size_t nSize) -{ - return CryModuleRealloc(p, nSize); -} -static void custom_xml_free(void* p) -{ - CryModuleFree(p); -} - -namespace CryXML_Internal -{ - XML_Memory_Handling_Suite memHandler; - XML_Memory_Handling_Suite* GetMemoryHandler() - { - memHandler.malloc_fcn = custom_xml_malloc; // CryModuleMalloc; - memHandler.realloc_fcn = custom_xml_realloc; // CryModuleRealloc; - memHandler.free_fcn = custom_xml_free; // CryModuleFree; - return &memHandler; - } -} - -XmlParserImp::XmlParserImp(bool bRemoveNonessentialSpacesFromContent) -{ - m_bRemoveNonessentialSpacesFromContent = bRemoveNonessentialSpacesFromContent; - - m_root = 0; - nodeStack.reserve(100); - - m_parser = XML_ParserCreate_MM(NULL, CryXML_Internal::GetMemoryHandler(), NULL); - - XML_SetUserData(m_parser, this); - XML_SetElementHandler(m_parser, startElement, endElement); - XML_SetCharacterDataHandler(m_parser, characterData); - XML_SetEncoding(m_parser, "utf-8"); -} - -XmlParserImp::~XmlParserImp() -{ - XML_ParserFree(m_parser); -} - -void XmlParserImp::beginParse() -{ - m_root = 0; - - m_stringPool.SetBlockSize(1 << 20); -} - -bool XmlParserImp::parse(const char* buffer, int bufLen) -{ - if (!XML_Parse(m_parser, buffer, (int)bufLen, 0)) - { - m_root = 0; - return false; - } - return true; -} - -XmlNodeRef XmlParserImp::endParse(XmlString& errorString) -{ - errorString = ""; - - if (!XML_Parse(m_parser, "", 0, 1)) - { - m_root = 0; - } - - if (!m_root) - { - const char* const errorText = XML_ErrorString(XML_GetErrorCode(m_parser)); - if (errorText) - { - errorString += "XML Error: "; - errorString += errorText; - // The following code is disabled by 'if (false)' because XML_GetCurrentLineNumber() - // XML_GetCurrentColumnNumber() return incorrect numbers. - // The issue (wrong numbers) might be fixed if/when we upgrade to a newer version - // of the Expat XML library (on 2014/02/26 CryEngine still uses expat version 1.95.2 - // from 2001/07/27, although the latest expat version is 2.1.0 from 2012/03/24). - if (false) - { - char s[64]; - azsprintf(s, " at line %d, column %d", (int)XML_GetCurrentLineNumber(m_parser), (int)XML_GetCurrentColumnNumber(m_parser)); - errorString += s; - } - } - } - - XmlNodeRef root = m_root; - m_root = 0; - return root; -} - -XmlParser::XmlParser(bool bRemoveNonessentialSpacesFromContent) -{ - m_pImpl = new XmlParserImp(bRemoveNonessentialSpacesFromContent); - m_pImpl->AddRef(); -} - -XmlParser::~XmlParser() -{ - m_pImpl->Release(); -} - -//! Parse xml file. -XmlNodeRef XmlParser::parse(const char* fileName) -{ - m_errorString = ""; - - std::vector buf; - auto pPak = GetISystem()->GetIPak(); - AZ::IO::HandleType file = pPak->FOpen(fileName, "rb"); - if (file) - { - pPak->FSeek(file, 0, SEEK_END); - int fileSize = pPak->FTell(file); - pPak->FSeek(file, 0, SEEK_SET); - buf.resize(fileSize); - pPak->FRead(&(buf[0]), fileSize, file); - pPak->FClose(file); - m_pImpl->parse(&buf[0], buf.size()); - return m_pImpl->endParse(m_errorString); - } - else - { - return XmlNodeRef(); - } -} - -//! Parse xml from memory buffer. -XmlNodeRef XmlParser::parseBuffer(const char* buffer) -{ - m_errorString = ""; - m_pImpl->beginParse(); - m_pImpl->parse(buffer, strlen(buffer)); - return m_pImpl->endParse(m_errorString); -} - -XmlNodeRef XmlParser::parseSource(const IXmlBufferSource* source) -{ - m_errorString = ""; - char buffer[40000]; - enum - { - bufferSize = sizeof(buffer) / sizeof(buffer[0]) - }; - m_pImpl->beginParse(); - int bytesRead = source->Read(buffer, bufferSize); - while (bytesRead) - { - if (!m_pImpl->parse(buffer, bytesRead)) - { - break; - } - bytesRead = source->Read(buffer, bufferSize); - } - return m_pImpl->endParse(m_errorString); -} diff --git a/Code/Tools/CryXML/XML/xml.h b/Code/Tools/CryXML/XML/xml.h deleted file mode 100644 index 8e9072acbf..0000000000 --- a/Code/Tools/CryXML/XML/xml.h +++ /dev/null @@ -1,471 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYXML_XML_XML_H -#define CRYINCLUDE_CRYXML_XML_XML_H -#pragma once - - -#include -#include -#include - -#include "IXml.h" - -struct IXmlBufferSource; - -struct IXmlStringPool -{ -public: - IXmlStringPool() { m_refCount = 0; } - virtual ~IXmlStringPool() {}; - void AddRef() { m_refCount++; }; - void Release() - { - if (--m_refCount <= 0) - { - delete this; - } - }; - virtual char* AddString(const char* str) = 0; -private: - int m_refCount; -}; - -/************************************************************************/ -/* XmlParser class, Parse xml and return root xml node if success. */ -/************************************************************************/ -class XmlParser -{ -public: - explicit XmlParser(bool bRemoveNonessentialSpacesFromContent); - ~XmlParser(); - - //! Parse xml file. - XmlNodeRef parse(const char* fileName); - - //! Parse xml from memory buffer. - XmlNodeRef parseBuffer(const char* buffer); - - XmlNodeRef parseSource(const IXmlBufferSource* source); - - const char* getErrorString() const { return m_errorString; } - -private: - XmlString m_errorString; - class XmlParserImp* m_pImpl; -}; - -// Compare function for string comparasion, can be strcmp or _stricmp -typedef int (__cdecl * XmlStrCmpFunc)(const char* str1, const char* str2); -extern XmlStrCmpFunc g_pXmlStrCmp; - -////////////////////////////////////////////////////////////////////////// -// XmlAttribute class -////////////////////////////////////////////////////////////////////////// -struct XmlAttribute -{ - const char* key; - const char* value; - - bool operator<(const XmlAttribute& attr) const { return g_pXmlStrCmp(key, attr.key) < 0; } - bool operator>(const XmlAttribute& attr) const { return g_pXmlStrCmp(key, attr.key) > 0; } - bool operator==(const XmlAttribute& attr) const { return g_pXmlStrCmp(key, attr.key) == 0; } - bool operator!=(const XmlAttribute& attr) const { return g_pXmlStrCmp(key, attr.key) != 0; } -}; - -//! Xml node attributes class. -typedef std::vector XmlAttributes; -typedef XmlAttributes::iterator XmlAttrIter; -typedef XmlAttributes::const_iterator XmlAttrConstIter; - -/** -****************************************************************************** -* CXmlNode class -* Never use CXmlNode directly instead use reference counted XmlNodeRef. -****************************************************************************** -*/ - -class CXmlNode - : public IXmlNode -{ -public: - //! Constructor. - CXmlNode(); - CXmlNode(const char* tag); - //! Destructor. - ~CXmlNode(); - - virtual void DeleteThis(); - - //! Create new XML node. - XmlNodeRef createNode(const char* tag); - - //! Get XML node tag. - const char* getTag() const { return m_tag; }; - void setTag(const char* tag); - - //! Return true if given tag equal to node tag. - bool isTag(const char* tag) const; - - //! Get XML Node attributes. - virtual int getNumAttributes() const { return (int)m_attributes.size(); }; - //! Return attribute key and value by attribute index. - virtual bool getAttributeByIndex(int index, const char** key, const char** value); - - virtual void copyAttributes(XmlNodeRef fromNode); - - //! Get XML Node attribute for specified key. - const char* getAttr(const char* key) const; - - //! Get XML Node attribute for specified key. - // Returns true if the attribute existes, alse otherwise. - bool getAttr(const char* key, const char** value) const; - - //! Check if attributes with specified key exist. - bool haveAttr(const char* key) const; - - //! Creates new xml node and add it to childs list. - XmlNodeRef newChild(const char* tagName); - - //! Adds new child node. - void addChild(const XmlNodeRef& node); - //! Remove child node. - void removeChild(const XmlNodeRef& node); - - void insertChild(int nIndex, const XmlNodeRef& node); - void replaceChild(int nIndex, const XmlNodeRef& node); - - //! Remove all child nodes. - void removeAllChilds(); - - //! Get number of child XML nodes. - int getChildCount() const { return (int)m_childs.size(); }; - - //! Get XML Node child nodes. - XmlNodeRef getChild(int i) const; - - //! Find node with specified tag. - XmlNodeRef findChild(const char* tag) const; - void deleteChild(const char* tag); - void deleteChildAt(int nIndex); - - //! Get parent XML node. - XmlNodeRef getParent() const { return m_parent; } - void setParent(const XmlNodeRef& inRef); - - //! Returns content of this node. - const char* getContent() const { return m_content.c_str(); }; - void setContent(const char* str); - - XmlNodeRef clone(); - - //! Returns line number for XML tag. - int getLine() const { return m_line; }; - //! Set line number in xml. - void setLine(int line) { m_line = line; }; - - //! Returns XML of this node and sub nodes. - virtual IXmlStringData* getXMLData(int nReserveMem = 0) const; - XmlString getXML(int level = 0) const; - bool saveToFile(const char* fileName) override; - - //! Set new XML Node attribute (or override attribute with same key). - void setAttr(const char* key, const char* value); - void setAttr(const char* key, int value); - void setAttr(const char* key, unsigned int value); - void setAttr(const char* key, int64 value); - void setAttr(const char* key, uint64 value, bool useHexFormat = true); - void setAttr(const char* key, float value); - void setAttr(const char* key, double value); - void setAttr(const char* key, const Vec2& value); - void setAttr(const char* key, const Vec2d& value); - void setAttr(const char* key, const Ang3& value); - void setAttr(const char* key, const Vec3& value); - void setAttr(const char* key, const Vec4& value); - void setAttr(const char* key, const Vec3d& value); - void setAttr(const char* key, const Quat& value); - - //! Delete attrbute. - void delAttr(const char* key); - //! Remove all node attributes. - void removeAllAttributes(); - - //! Get attribute value of node. - bool getAttr(const char* key, int& value) const; - bool getAttr(const char* key, unsigned int& value) const; - bool getAttr(const char* key, int64& value) const; - bool getAttr(const char* key, uint64& value, bool useHexFormat = true /*ignored*/) const; - bool getAttr(const char* key, float& value) const; - bool getAttr(const char* key, double& value) const; - bool getAttr(const char* key, bool& value) const; - bool getAttr(const char* key, XmlString& value) const - { - XmlString v; - if (v = getAttr(key)) - { - value = v; - return true; - } - else - { - return false; - } - } - bool getAttr(const char* key, Vec2& value) const; - bool getAttr(const char* key, Vec2d& value) const; - bool getAttr(const char* key, Ang3& value) const; - bool getAttr(const char* key, Vec3& value) const; - bool getAttr(const char* key, Vec3d& value) const; - bool getAttr(const char* key, Vec4& value) const; - bool getAttr(const char* key, Quat& value) const; - bool getAttr(const char* key, ColorB& value) const; - // bool getAttr( const char *key,string &value ) const { XmlString v; if (getAttr(key,v)) { value = (const char*)v; return true; } else return false; } - -#if !defined(RESOURCE_COMPILER) - // - // Summary: - // Collect all allocated memory - void GetMemoryUsage([[maybe_unused]] ICrySizer* pSizer) const { assert(0); }; - - // Summary: - // Copies children to this node from a given node. - // Children are reference copied (shallow copy) and the children's parent is NOT set to this - // node, but left with its original parent (which is still the parent) - void shareChildren([[maybe_unused]] const XmlNodeRef& fromNode) { assert(0); }; - - // Summary: - // Returns XML of this node and sub nodes into tmpBuffer without XML checks (much faster) - XmlString getXMLUnsafe(int level, [[maybe_unused]] char* tmpBuffer, [[maybe_unused]] uint32 sizeOfTmpBuffer) const { return getXML(level); } - - // Notes: - // Save in small memory chunks. - bool saveToFile([[maybe_unused]] const char* fileName, [[maybe_unused]] size_t chunkSizeBytes, [[maybe_unused]] AZ::IO::HandleType fileHandle = AZ::IO::InvalidHandle) override { assert(0); return false; }; - // -#endif - -private: - void AddToXmlString(XmlString& xml, int level) const; - XmlString MakeValidXmlString(const XmlString& xml) const; - bool IsValidXmlString(const char* str) const; - XmlAttrConstIter GetAttrConstIterator(const char* key) const - { - XmlAttribute tempAttr; - tempAttr.key = key; - - XmlAttributes::const_iterator it = std::find(m_attributes.begin(), m_attributes.end(), tempAttr); - return it; - - /* - XmlAttributes::const_iterator it = std::lower_bound( m_attributes.begin(),m_attributes.end(),tempAttr ); - if (it != m_attributes.end() && _stricmp(it->key,key) == 0) - return it; - return m_attributes.end(); - */ - } - XmlAttrIter GetAttrIterator(const char* key) - { - XmlAttribute tempAttr; - tempAttr.key = key; - - XmlAttributes::iterator it = std::find(m_attributes.begin(), m_attributes.end(), tempAttr); - return it; - - // XmlAttributes::iterator it = std::lower_bound( m_attributes.begin(),m_attributes.end(),tempAttr ); - //if (it != m_attributes.end() && _stricmp(it->key,key) == 0) - //return it; - //return m_attributes.end(); - } - const char* GetValue(const char* key) const - { - XmlAttrConstIter it = GetAttrConstIterator(key); - if (it != m_attributes.end()) - { - return it->value; - } - return 0; - } - -private: - //! Line in XML file where this node firstly appeared (usefull for debugging). - int m_line; - - //! Tag of XML node. - const char* m_tag; - //! Content of XML node. - XmlString m_content; - //! Parent XML node. - CXmlNode* m_parent; - - // String pool used by this node. - IXmlStringPool* m_pStringPool; - - typedef std::vector XmlNodes; - XmlNodes m_childs; - //! Xml node attributes. - XmlAttributes m_attributes; - - friend class XmlParserImp; -}; - -#endif // __XML_HEADER__ - - -/* -#ifndef __XML_HEADER__ -#define __XML_HEADER__ - - - -class CXmlNode : public IXmlNode -{ -public: - //! Constructor. - CXmlNode( const char *tag ); - //! Destructor. - ~CXmlNode(); - - ////////////////////////////////////////////////////////////////////////// - //! Reference counting. - void AddRef() { m_refCount++; }; - //! When ref count reach zero XML node dies. - void Release(); - - //! Create new XML node. - XmlNodeRef createNode( const char *tag ); - - //! Get XML node tag. - const char *getTag() const { return m_tag; }; - void setTag( const char *tag ) { m_tag = tag; } - - //! Return true if givven tag equal to node tag. - bool isTag( const char *tag ) const; - - //! Get XML Node attributes. - virtual int getNumAttributes() const { return (int)m_attributes.size(); }; - //! Return attribute key and value by attribute index. - virtual bool getAttributeByIndex( int index,const char **key,const char **value ); - - virtual void* getFirstAttribute(); - virtual bool getNextAttribute( void** pIterator,const char **key,const char **value ); - - virtual void copyAttributes( XmlNodeRef fromNode ); - - //! Get XML Node attribute for specified key. - const char* getAttr( const char *key ) const; - //! Check if attributes with specified key exist. - bool haveAttr( const char *key ) const; - - //! Adds new child node. - void addChild( const XmlNodeRef &node ); - - //! Creates new xml node and add it to childs list. - XmlNodeRef newChild( const char *tagName ); - - //! Remove child node. - void removeChild( const XmlNodeRef &node ); - - //! Remove all child nodes. - void removeAllChilds(); - - //! Get number of child XML nodes. - int getChildCount() const { return (int)m_childs.size(); }; - - //! Get XML Node child nodes. - XmlNodeRef getChild( int i ) const; - - //! Find node with specified tag. - XmlNodeRef findChild( const char *tag ) const; - - //! Get parent XML node. - XmlNodeRef getParent() const { return m_parent; } - - //! Returns content of this node. - const char* getContent() const { return m_content; }; - void setContent( const char *str ) { m_content = str; }; - void addContent( const char *str ) { m_content += str; }; - - XmlNodeRef clone(); - - //! Returns line number for XML tag. - int getLine() const { return m_line; }; - //! Set line number in xml. - void setLine( int line ) { m_line = line; }; - - //! Returns XML of this node and sub nodes. - XmlString getXML( int level=0 ) const; - XmlString getBinaryXML() const; - bool saveToFile( const char *fileName, bool bBinary = false ); - bool saveToSink(IXMLDataSink* pSink, bool bBinary = false); - - //! Set new XML Node attribute (or override attribute with same key). - void setAttr( const char* key,const char* value ); - void setAttr( const char* key,int value ); - void setAttr( const char* key,unsigned int value ); - void setAttr( const char* key,uint64 value ); - void setAttr( const char* key,float value ); - void setAttr( const char* key,const Ang3& value ); - void setAttr( const char* key,const Vec3& value ); - void setAttr( const char* key,const Quat &value ); - - //! Delete attribute. - void delAttr( const char* key ); - //! Remove all node attributes. - void removeAllAttributes(); - - //! Get attribute value of node. - bool getAttr( const char *key,int &value ) const; - bool getAttr( const char *key,unsigned int &value ) const; - bool getAttr( const char *key,uint64 &value ) const; - bool getAttr( const char *key,float &value ) const; - bool getAttr( const char *key,Ang3& value ) const; - bool getAttr( const char *key,Vec3& value ) const; - bool getAttr( const char *key,Quat &value ) const; - bool getAttr( const char *key,bool &value ) const; - bool getAttr( const char *key,XmlString &value ) const { XmlString v; if (v=getAttr(key)) { value = v; return true; } else return false; } -// bool getAttr( const char *key,string &value ) const { XmlString v; if (getAttr(key,v)) { value = (const char*)v; return true; } else return false; } - - // Add an attribute structure directly. - void addAttr(XmlAttribute& attribute); - - void SetBuffer(StringBuffer* pStringBuffer); - -private: - void AddToXmlString( XmlString &xml,int level ) const; - -private: - StringBuffer* m_pStringBuffer; - - //! Ref count itself, its zeroed on node creation. - int m_refCount; - - //! Line in XML file where this node firstly appeared (usefull for debuggin). - int m_line; - //! Tag of XML node. - XmlString m_tag; - - //! Content of XML node. - XmlString m_content; - //! Parent XML node. - CXmlNode *m_parent; - //! Next XML node in same hierarchy level. - - typedef std::vector XmlNodes; - XmlNodes m_childs; - //! Xml node attributes. - XmlAttributes m_attributes; - static XmlAttribute tempAttr; -}; - -#endif // CRYINCLUDE_CRYXML_XML_XML_H -*/ diff --git a/Code/Tools/CryXML/XMLSerializer.cpp b/Code/Tools/CryXML/XMLSerializer.cpp deleted file mode 100644 index e1152f93a3..0000000000 --- a/Code/Tools/CryXML/XMLSerializer.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#include "CryXML_precompiled.h" -#include "XMLSerializer.h" -#include "XML/xml.h" -#include "IXMLSerializer.h" -#include "StringUtils.h" - -XmlNodeRef XMLSerializer::CreateNode(const char* tag) -{ - return new CXmlNode(tag); -} - -bool XMLSerializer::Write(XmlNodeRef root, const char* szFileName) -{ - return root->saveToFile(szFileName); -} - -XmlNodeRef XMLSerializer::Read(const IXmlBufferSource& source, bool bRemoveNonessentialSpacesFromContent, int nErrorBufferSize, char* szErrorBuffer) -{ - XmlParser parser(bRemoveNonessentialSpacesFromContent); - XmlNodeRef root = parser.parseSource(&source); - if (nErrorBufferSize > 0 && szErrorBuffer) - { - const char* const err = parser.getErrorString(); - cry_strcpy(szErrorBuffer, nErrorBufferSize, err ? err : ""); - } - return root; -} diff --git a/Code/Tools/CryXML/XMLSerializer.h b/Code/Tools/CryXML/XMLSerializer.h deleted file mode 100644 index 7730b19963..0000000000 --- a/Code/Tools/CryXML/XMLSerializer.h +++ /dev/null @@ -1,31 +0,0 @@ -/* -* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -* its licensors. -* -* For complete copyright and license terms please see the LICENSE at the root of this -* distribution (the "License"). All use of this software is governed by the License, -* or, if provided, by the license below or the license accompanying this file. Do not -* remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* -*/ -// Original file Copyright Crytek GMBH or its affiliates, used under license. - -#ifndef CRYINCLUDE_CRYXML_XMLSERIALIZER_H -#define CRYINCLUDE_CRYXML_XMLSERIALIZER_H -#pragma once - - -#include "IXMLSerializer.h" - -class XMLSerializer - : public IXMLSerializer -{ -public: - virtual XmlNodeRef CreateNode(const char* tag); - virtual bool Write(XmlNodeRef root, const char* szFileName); - - virtual XmlNodeRef Read(const IXmlBufferSource& source, bool bRemoveNonessentialSpacesFromContent, int nErrorBufferSize, char* szErrorBuffer); -}; - -#endif // CRYINCLUDE_CRYXML_XMLSERIALIZER_H diff --git a/Code/Tools/CryXML/cryxml_files.cmake b/Code/Tools/CryXML/cryxml_files.cmake deleted file mode 100644 index d81ace11b7..0000000000 --- a/Code/Tools/CryXML/cryxml_files.cmake +++ /dev/null @@ -1,22 +0,0 @@ -# -# All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -# its licensors. -# -# For complete copyright and license terms please see the LICENSE at the root of this -# distribution (the "License"). All use of this software is governed by the License, -# or, if provided, by the license below or the license accompanying this file. Do not -# remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# - -set(FILES - CryXML.cpp - XMLSerializer.cpp - ICryXML.h - IXMLSerializer.h - XMLSerializer.h - XML/xml.cpp - XML/xml.h - CryXML_precompiled.h - CryXML_precompiled.cpp -) diff --git a/Code/Tools/TestBed/ResourceCompilerImage/Input/Bump2NormalHighQ.tif.exportsettings b/Code/Tools/TestBed/ResourceCompilerImage/Input/Bump2NormalHighQ.tif.exportsettings deleted file mode 100644 index e7bbaccd46..0000000000 --- a/Code/Tools/TestBed/ResourceCompilerImage/Input/Bump2NormalHighQ.tif.exportsettings +++ /dev/null @@ -1 +0,0 @@ -/autooptimizefile=0 /bumpblur=0.000000 /bumpstrength=5.000000 /bumptype=1 /mipmirror=1 /preset=Bump2Normalmap_highQ /reduce=1 diff --git a/Code/Tools/TestBed/ResourceCompilerImage/Input/DiffusehighQWithAlpha256512.tif.exportsettings b/Code/Tools/TestBed/ResourceCompilerImage/Input/DiffusehighQWithAlpha256512.tif.exportsettings deleted file mode 100644 index 5f78477ca8..0000000000 --- a/Code/Tools/TestBed/ResourceCompilerImage/Input/DiffusehighQWithAlpha256512.tif.exportsettings +++ /dev/null @@ -1 +0,0 @@ -/autooptimizefile=0 /bumpblur=0.000000 /bumpstrength=5.000000 /mipmirror=1 /preset=Diffuse_highQ /reduce=1 diff --git a/Code/Tools/TestBed/ResourceCompilerImage/Input/DiffusehighQWithAlpha512256.tif.exportsettings b/Code/Tools/TestBed/ResourceCompilerImage/Input/DiffusehighQWithAlpha512256.tif.exportsettings deleted file mode 100644 index 5f78477ca8..0000000000 --- a/Code/Tools/TestBed/ResourceCompilerImage/Input/DiffusehighQWithAlpha512256.tif.exportsettings +++ /dev/null @@ -1 +0,0 @@ -/autooptimizefile=0 /bumpblur=0.000000 /bumpstrength=5.000000 /mipmirror=1 /preset=Diffuse_highQ /reduce=1 diff --git a/Code/Tools/TestBed/ResourceCompilerImage/Input/LuminanceOnly.tif.exportsettings b/Code/Tools/TestBed/ResourceCompilerImage/Input/LuminanceOnly.tif.exportsettings deleted file mode 100644 index 6466dc9099..0000000000 --- a/Code/Tools/TestBed/ResourceCompilerImage/Input/LuminanceOnly.tif.exportsettings +++ /dev/null @@ -1 +0,0 @@ -/autooptimizefile=0 /mipalphacoverage=0 /mipmirror=1 /preset=Diffuse_highQ /reduce=0 diff --git a/Code/Tools/TestBed/ResourceCompilerImage/Input/NoPreset3DC_ddn.tif.exportsettings b/Code/Tools/TestBed/ResourceCompilerImage/Input/NoPreset3DC_ddn.tif.exportsettings deleted file mode 100644 index acfbe2a750..0000000000 --- a/Code/Tools/TestBed/ResourceCompilerImage/Input/NoPreset3DC_ddn.tif.exportsettings +++ /dev/null @@ -1 +0,0 @@ -/autooptimizefile=0 /bumpblur=0.000000 /bumpstrength=5.000000 /mipmirror=0 /preset=Normalmap_lowQ /reduce=0 diff --git a/Code/Tools/TestBed/ResourceCompilerImage/Input/NoPresetX8R8G8B8.tif.exportsettings b/Code/Tools/TestBed/ResourceCompilerImage/Input/NoPresetX8R8G8B8.tif.exportsettings deleted file mode 100644 index 00ecf3a56e..0000000000 --- a/Code/Tools/TestBed/ResourceCompilerImage/Input/NoPresetX8R8G8B8.tif.exportsettings +++ /dev/null @@ -1 +0,0 @@ -/autooptimizefile=0 /bumpblur=0.000000 /bumpstrength=5.000000 /mipmirror=1 /preset=Diffuse_lowQ /reduce=0 diff --git a/Code/Tools/TestBed/ResourceCompilerImage/Input/NoPresetX8R8G8B8WithAlpha.tif.exportsettings b/Code/Tools/TestBed/ResourceCompilerImage/Input/NoPresetX8R8G8B8WithAlpha.tif.exportsettings deleted file mode 100644 index 00ecf3a56e..0000000000 --- a/Code/Tools/TestBed/ResourceCompilerImage/Input/NoPresetX8R8G8B8WithAlpha.tif.exportsettings +++ /dev/null @@ -1 +0,0 @@ -/autooptimizefile=0 /bumpblur=0.000000 /bumpstrength=5.000000 /mipmirror=1 /preset=Diffuse_lowQ /reduce=0 diff --git a/Code/Tools/TestBed/ResourceCompilerImage/Input/NoPresetX8R8G8B8_bump.tif.exportsettings b/Code/Tools/TestBed/ResourceCompilerImage/Input/NoPresetX8R8G8B8_bump.tif.exportsettings deleted file mode 100644 index cab995b31e..0000000000 --- a/Code/Tools/TestBed/ResourceCompilerImage/Input/NoPresetX8R8G8B8_bump.tif.exportsettings +++ /dev/null @@ -1 +0,0 @@ -/autooptimizefile=0 /bumpblur=0.000000 /bumpstrength=5.000000 /mipmirror=1 /preset=Bump2Normalmap_lowQ /reduce=0 diff --git a/Code/Tools/TestBed/ResourceCompilerImage/Input/NoPresetX8R8G8B8_ddn.tif.exportsettings b/Code/Tools/TestBed/ResourceCompilerImage/Input/NoPresetX8R8G8B8_ddn.tif.exportsettings deleted file mode 100644 index c5a53f8bd5..0000000000 --- a/Code/Tools/TestBed/ResourceCompilerImage/Input/NoPresetX8R8G8B8_ddn.tif.exportsettings +++ /dev/null @@ -1 +0,0 @@ -/autooptimizefile=0 /bumpblur=0.000000 /bumpstrength=5.000000 /mipmirror=1 /preset=Normalmap_lowQ /reduce=0 diff --git a/Code/Tools/TestBed/ResourceCompilerImage/Input/NoTIFSettings.tif.exportsettings b/Code/Tools/TestBed/ResourceCompilerImage/Input/NoTIFSettings.tif.exportsettings deleted file mode 100644 index 1048249b71..0000000000 --- a/Code/Tools/TestBed/ResourceCompilerImage/Input/NoTIFSettings.tif.exportsettings +++ /dev/null @@ -1 +0,0 @@ -/autooptimizefile=0 /preset=Diffuse_lowQ diff --git a/Code/Tools/TestBed/ResourceCompilerImage/Input/NoTIFSettings300400.tif.exportsettings b/Code/Tools/TestBed/ResourceCompilerImage/Input/NoTIFSettings300400.tif.exportsettings deleted file mode 100644 index db0b877f24..0000000000 --- a/Code/Tools/TestBed/ResourceCompilerImage/Input/NoTIFSettings300400.tif.exportsettings +++ /dev/null @@ -1 +0,0 @@ -/autooptimizefile=0 /preset=ReferenceImage diff --git a/Code/Tools/TestBed/ResourceCompilerImage/Input/NoTIFSettingsGrey_DDNDIF.tif.exportsettings b/Code/Tools/TestBed/ResourceCompilerImage/Input/NoTIFSettingsGrey_DDNDIF.tif.exportsettings deleted file mode 100644 index 1048249b71..0000000000 --- a/Code/Tools/TestBed/ResourceCompilerImage/Input/NoTIFSettingsGrey_DDNDIF.tif.exportsettings +++ /dev/null @@ -1 +0,0 @@ -/autooptimizefile=0 /preset=Diffuse_lowQ diff --git a/Code/Tools/TestBed/ResourceCompilerImage/Input/NoTIFSettings_DDNDIF.tif.exportsettings b/Code/Tools/TestBed/ResourceCompilerImage/Input/NoTIFSettings_DDNDIF.tif.exportsettings deleted file mode 100644 index 84c0416421..0000000000 --- a/Code/Tools/TestBed/ResourceCompilerImage/Input/NoTIFSettings_DDNDIF.tif.exportsettings +++ /dev/null @@ -1 +0,0 @@ -/autooptimizefile=0 /ms=0 /preset=Diffuse_lowQ /reduce=0 diff --git a/Code/Tools/TestBed/ResourceCompilerImage/Input/NormalmapLowQ.tif.exportsettings b/Code/Tools/TestBed/ResourceCompilerImage/Input/NormalmapLowQ.tif.exportsettings deleted file mode 100644 index c5a53f8bd5..0000000000 --- a/Code/Tools/TestBed/ResourceCompilerImage/Input/NormalmapLowQ.tif.exportsettings +++ /dev/null @@ -1 +0,0 @@ -/autooptimizefile=0 /bumpblur=0.000000 /bumpstrength=5.000000 /mipmirror=1 /preset=Normalmap_lowQ /reduce=0 diff --git a/Code/Tools/TestBed/ResourceCompilerImage/Input/NormalmapLowQReduce1_ddn.tif.exportsettings b/Code/Tools/TestBed/ResourceCompilerImage/Input/NormalmapLowQReduce1_ddn.tif.exportsettings deleted file mode 100644 index cb9f25b5d9..0000000000 --- a/Code/Tools/TestBed/ResourceCompilerImage/Input/NormalmapLowQReduce1_ddn.tif.exportsettings +++ /dev/null @@ -1 +0,0 @@ -/autooptimizefile=0 /bumpblur=0.000000 /bumpstrength=5.000000 /mipmirror=1 /preset=Normalmap_lowQ /reduce=1 diff --git a/Code/Tools/TestBed/ResourceCompilerImage/Input/NormalmapLowQ_ddn.tif.exportsettings b/Code/Tools/TestBed/ResourceCompilerImage/Input/NormalmapLowQ_ddn.tif.exportsettings deleted file mode 100644 index c5a53f8bd5..0000000000 --- a/Code/Tools/TestBed/ResourceCompilerImage/Input/NormalmapLowQ_ddn.tif.exportsettings +++ /dev/null @@ -1 +0,0 @@ -/autooptimizefile=0 /bumpblur=0.000000 /bumpstrength=5.000000 /mipmirror=1 /preset=Normalmap_lowQ /reduce=0 diff --git a/Code/Tools/TestBed/ResourceCompilerImage/Input/TestColorChart_cch.tif.exportsettings b/Code/Tools/TestBed/ResourceCompilerImage/Input/TestColorChart_cch.tif.exportsettings deleted file mode 100644 index 47b9f504fd..0000000000 --- a/Code/Tools/TestBed/ResourceCompilerImage/Input/TestColorChart_cch.tif.exportsettings +++ /dev/null @@ -1 +0,0 @@ -/autooptimizefile=0 /preset=ColorChart diff --git a/Code/Tools/TestBed/ResourceCompilerImage/Input/diamand_plate_ddn.tif.exportsettings b/Code/Tools/TestBed/ResourceCompilerImage/Input/diamand_plate_ddn.tif.exportsettings deleted file mode 100644 index 3e5edcd652..0000000000 --- a/Code/Tools/TestBed/ResourceCompilerImage/Input/diamand_plate_ddn.tif.exportsettings +++ /dev/null @@ -1 +0,0 @@ -/autooptimizefile=0 /bumptype=1 /preset=Bump2Normalmap_lowQ /reduce=0 diff --git a/Gems/Blast/Assets/.p4ignore b/Gems/Blast/Assets/.p4ignore deleted file mode 100644 index 7015097e56..0000000000 --- a/Gems/Blast/Assets/.p4ignore +++ /dev/null @@ -1 +0,0 @@ -*.physx diff --git a/Tools/AnimationTest/assetImportTest.bat b/Tools/AnimationTest/assetImportTest.bat deleted file mode 100644 index 205c17280b..0000000000 --- a/Tools/AnimationTest/assetImportTest.bat +++ /dev/null @@ -1,31 +0,0 @@ -REM -REM -REM All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or -REM its licensors. -REM -REM For complete copyright and license terms please see the LICENSE at the root of this -REM distribution (the "License"). All use of this software is governed by the License, -REM or, if provided, by the license below or the license accompanying this file. Do not -REM remove or modify any license notices. This file is distributed on an "AS IS" BASIS, -REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -REM - -TITLE asset import test - -SETLOCAL EnableExtensions -set EXE=AssetProcessor_tmp.exe -FOR /F %%x IN ('tasklist /NH /FI "IMAGENAME eq %EXE%"') DO IF %%x == %EXE% goto FOUND -echo Make sure asset processor is running before run this script. -goto FIN -:FOUND - -SET F="..\..\Cache\SamplesProject\pc\samplesproject\objects" - -IF EXIST %F% ( - RMDIR /S /Q %F% - ECHO Detected folder at %F% - ECHO Make sure there's no fail / crash in asset processor after all job finished. -) ELSE (ECHO folder %F% NOT FOUND) - -:FIN -PAUSE \ No newline at end of file diff --git a/Tools/DeepBandwidthToExcel/7z.exe b/Tools/DeepBandwidthToExcel/7z.exe deleted file mode 100644 index 85fa5e2917..0000000000 --- a/Tools/DeepBandwidthToExcel/7z.exe +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:2ca56c2a96859b5171e7d24c81ed4d281da0ea26a7eaff7eac975d337eb4a2e1 -size 266752 diff --git a/Tools/DeepBandwidthToExcel/DeepBandwidthToExcel.exe b/Tools/DeepBandwidthToExcel/DeepBandwidthToExcel.exe deleted file mode 100644 index b89cb8c457..0000000000 --- a/Tools/DeepBandwidthToExcel/DeepBandwidthToExcel.exe +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:6b8dc17c53df32173fd82d8bfc844bc3752bf6cbaf1bf2fd334dd6949f44b04b -size 1050344 diff --git a/Tools/DeepBandwidthToExcel/Template/[Content_Types].xml b/Tools/DeepBandwidthToExcel/Template/[Content_Types].xml deleted file mode 100644 index 3c4fc1468a..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/[Content_Types].xml +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/Tools/DeepBandwidthToExcel/Template/_rels/.rels b/Tools/DeepBandwidthToExcel/Template/_rels/.rels deleted file mode 100644 index 74bfd8d955..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/_rels/.rels +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/Tools/DeepBandwidthToExcel/Template/docProps/app.xml b/Tools/DeepBandwidthToExcel/Template/docProps/app.xml deleted file mode 100644 index 6430cd86f5..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/docProps/app.xml +++ /dev/null @@ -1,2 +0,0 @@ - -Microsoft Excel0falseWorksheets9Group TotalsMessage TotalsPolicy CountPolicy ImpactSerialisation ImpactBandwidth Over TimeSocket Packets Over TimeSocket Bits Over TimeWarningsCrytek UKfalsefalsefalse12.0000 \ No newline at end of file diff --git a/Tools/DeepBandwidthToExcel/Template/docProps/core.xml b/Tools/DeepBandwidthToExcel/Template/docProps/core.xml deleted file mode 100644 index f1efda39ff..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/docProps/core.xml +++ /dev/null @@ -1,2 +0,0 @@ - -leelee2012-03-06T13:44:11Z2012-03-23T08:28:17Z \ No newline at end of file diff --git a/Tools/DeepBandwidthToExcel/Template/xl/_rels/workbook.xml.rels b/Tools/DeepBandwidthToExcel/Template/xl/_rels/workbook.xml.rels deleted file mode 100644 index e9dc190f2c..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/_rels/workbook.xml.rels +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/Tools/DeepBandwidthToExcel/Template/xl/calcChain.xml b/Tools/DeepBandwidthToExcel/Template/xl/calcChain.xml deleted file mode 100644 index 2fb95911c6..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/calcChain.xml +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/Tools/DeepBandwidthToExcel/Template/xl/charts/chart1.xml b/Tools/DeepBandwidthToExcel/Template/xl/charts/chart1.xml deleted file mode 100644 index 3e3737423c..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/charts/chart1.xml +++ /dev/null @@ -1,2 +0,0 @@ - -Overall By Schedule Group'Group Totals'!###---SHEET1_COL0---###peterpaul'Group Totals'!###---SHEET1_COL1---###General55 diff --git a/Tools/DeepBandwidthToExcel/Template/xl/charts/chart2.xml b/Tools/DeepBandwidthToExcel/Template/xl/charts/chart2.xml deleted file mode 100644 index 54d3f0da26..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/charts/chart2.xml +++ /dev/null @@ -1,2 +0,0 @@ - -Overall By Message'Message Totals'!###---SHEET2_COL0---###peterpaul'Message Totals'!###---SHEET2_COL1---###General55 diff --git a/Tools/DeepBandwidthToExcel/Template/xl/charts/chart3.xml b/Tools/DeepBandwidthToExcel/Template/xl/charts/chart3.xml deleted file mode 100644 index f405df758f..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/charts/chart3.xml +++ /dev/null @@ -1,2 +0,0 @@ - -Overall By Policy Count'Policy Count'!###---SHEET3_COL0---###ui2eid'Policy Count'!###---SHEET3_COL1---###General20801811398975 diff --git a/Tools/DeepBandwidthToExcel/Template/xl/charts/chart4.xml b/Tools/DeepBandwidthToExcel/Template/xl/charts/chart4.xml deleted file mode 100644 index 6d461a7cd5..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/charts/chart4.xml +++ /dev/null @@ -1,2 +0,0 @@ - -Overall By Policy Impact (Bits Per Policy)'Policy Impact'!###---SHEET4_COL0---###wrlddMov'Policy Impact'!###---SHEET4_COL1---###General5354582913312905 diff --git a/Tools/DeepBandwidthToExcel/Template/xl/charts/chart5.xml b/Tools/DeepBandwidthToExcel/Template/xl/charts/chart5.xml deleted file mode 100644 index 5276503965..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/charts/chart5.xml +++ /dev/null @@ -1,93 +0,0 @@ - - - - - - - - - - - - - - - - Overall By Serialisation Impact (Bits - - - - Per Serialise) - - - - - - - - - - - - - - - - - - - - 'Serialisation Impact'!###---SHEET5_COL0---### - - - - wrld - - - dMov - - - - - - - 'Serialisation Impact'!###---SHEET5_COL1---### - - General - - - 53545829 - - - 13312905 - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Tools/DeepBandwidthToExcel/Template/xl/charts/chart6.xml b/Tools/DeepBandwidthToExcel/Template/xl/charts/chart6.xml deleted file mode 100644 index 3dbcb710ee..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/charts/chart6.xml +++ /dev/null @@ -1,78 +0,0 @@ - - - - - - - - - - - - - - - - Bandwidth Over Time - - - - - - - - - - ###---SHEET6_CHART---### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Tools/DeepBandwidthToExcel/Template/xl/charts/chart7.xml b/Tools/DeepBandwidthToExcel/Template/xl/charts/chart7.xml deleted file mode 100644 index 324a3d0296..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/charts/chart7.xml +++ /dev/null @@ -1,84 +0,0 @@ - - - - - - - - - - - - - - - - Socket - - - - Packets Per Second - - - - - - - - - - - ###---SHEET7_CHART---### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Tools/DeepBandwidthToExcel/Template/xl/charts/chart8.xml b/Tools/DeepBandwidthToExcel/Template/xl/charts/chart8.xml deleted file mode 100644 index 9aed1eaa0b..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/charts/chart8.xml +++ /dev/null @@ -1,83 +0,0 @@ - - - - - - - - - - - - - - - - Socket - - - - Bits Per Second - - - - - - - - - - ###---SHEET8_CHART---### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Tools/DeepBandwidthToExcel/Template/xl/drawings/_rels/drawing1.xml.rels b/Tools/DeepBandwidthToExcel/Template/xl/drawings/_rels/drawing1.xml.rels deleted file mode 100644 index 91223aab09..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/drawings/_rels/drawing1.xml.rels +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/Tools/DeepBandwidthToExcel/Template/xl/drawings/_rels/drawing2.xml.rels b/Tools/DeepBandwidthToExcel/Template/xl/drawings/_rels/drawing2.xml.rels deleted file mode 100644 index 63233beb83..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/drawings/_rels/drawing2.xml.rels +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/Tools/DeepBandwidthToExcel/Template/xl/drawings/_rels/drawing3.xml.rels b/Tools/DeepBandwidthToExcel/Template/xl/drawings/_rels/drawing3.xml.rels deleted file mode 100644 index c53f6617a5..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/drawings/_rels/drawing3.xml.rels +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/Tools/DeepBandwidthToExcel/Template/xl/drawings/_rels/drawing4.xml.rels b/Tools/DeepBandwidthToExcel/Template/xl/drawings/_rels/drawing4.xml.rels deleted file mode 100644 index 7fe138bac4..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/drawings/_rels/drawing4.xml.rels +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/Tools/DeepBandwidthToExcel/Template/xl/drawings/_rels/drawing5.xml.rels b/Tools/DeepBandwidthToExcel/Template/xl/drawings/_rels/drawing5.xml.rels deleted file mode 100644 index 22864411ec..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/drawings/_rels/drawing5.xml.rels +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/Tools/DeepBandwidthToExcel/Template/xl/drawings/_rels/drawing6.xml.rels b/Tools/DeepBandwidthToExcel/Template/xl/drawings/_rels/drawing6.xml.rels deleted file mode 100644 index 424914396d..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/drawings/_rels/drawing6.xml.rels +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/Tools/DeepBandwidthToExcel/Template/xl/drawings/_rels/drawing7.xml.rels b/Tools/DeepBandwidthToExcel/Template/xl/drawings/_rels/drawing7.xml.rels deleted file mode 100644 index b1404c3db9..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/drawings/_rels/drawing7.xml.rels +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/Tools/DeepBandwidthToExcel/Template/xl/drawings/_rels/drawing8.xml.rels b/Tools/DeepBandwidthToExcel/Template/xl/drawings/_rels/drawing8.xml.rels deleted file mode 100644 index a9e371607f..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/drawings/_rels/drawing8.xml.rels +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/Tools/DeepBandwidthToExcel/Template/xl/drawings/drawing1.xml b/Tools/DeepBandwidthToExcel/Template/xl/drawings/drawing1.xml deleted file mode 100644 index 70ea7ed3be..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/drawings/drawing1.xml +++ /dev/null @@ -1,2 +0,0 @@ - -43809902857429952440114299 \ No newline at end of file diff --git a/Tools/DeepBandwidthToExcel/Template/xl/drawings/drawing2.xml b/Tools/DeepBandwidthToExcel/Template/xl/drawings/drawing2.xml deleted file mode 100644 index f8a60ce08a..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/drawings/drawing2.xml +++ /dev/null @@ -1,2 +0,0 @@ - -338100076199285810254057150 \ No newline at end of file diff --git a/Tools/DeepBandwidthToExcel/Template/xl/drawings/drawing3.xml b/Tools/DeepBandwidthToExcel/Template/xl/drawings/drawing3.xml deleted file mode 100644 index 75e5d9ed25..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/drawings/drawing3.xml +++ /dev/null @@ -1,2 +0,0 @@ - -2276225095250283714754019050 \ No newline at end of file diff --git a/Tools/DeepBandwidthToExcel/Template/xl/drawings/drawing4.xml b/Tools/DeepBandwidthToExcel/Template/xl/drawings/drawing4.xml deleted file mode 100644 index de297dbb14..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/drawings/drawing4.xml +++ /dev/null @@ -1,2 +0,0 @@ - -3001333492851435040123824 \ No newline at end of file diff --git a/Tools/DeepBandwidthToExcel/Template/xl/drawings/drawing5.xml b/Tools/DeepBandwidthToExcel/Template/xl/drawings/drawing5.xml deleted file mode 100644 index b7c2cf9c02..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/drawings/drawing5.xml +++ /dev/null @@ -1,2 +0,0 @@ - -25524500104775284572004095250 \ No newline at end of file diff --git a/Tools/DeepBandwidthToExcel/Template/xl/drawings/drawing6.xml b/Tools/DeepBandwidthToExcel/Template/xl/drawings/drawing6.xml deleted file mode 100644 index c610b4c052..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/drawings/drawing6.xml +++ /dev/null @@ -1,2 +0,0 @@ - -338099914287528257174409525 \ No newline at end of file diff --git a/Tools/DeepBandwidthToExcel/Template/xl/drawings/drawing7.xml b/Tools/DeepBandwidthToExcel/Template/xl/drawings/drawing7.xml deleted file mode 100644 index 14d255a242..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/drawings/drawing7.xml +++ /dev/null @@ -1,2 +0,0 @@ - -247624310477526533399389525 \ No newline at end of file diff --git a/Tools/DeepBandwidthToExcel/Template/xl/drawings/drawing8.xml b/Tools/DeepBandwidthToExcel/Template/xl/drawings/drawing8.xml deleted file mode 100644 index 1b94acd279..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/drawings/drawing8.xml +++ /dev/null @@ -1,2 +0,0 @@ - -23809931047752744767539114301 \ No newline at end of file diff --git a/Tools/DeepBandwidthToExcel/Template/xl/sharedStrings.xml b/Tools/DeepBandwidthToExcel/Template/xl/sharedStrings.xml deleted file mode 100644 index 2fbc1ad0b7..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/sharedStrings.xml +++ /dev/null @@ -1,2 +0,0 @@ - -###---STRINGSTABLE---### diff --git a/Tools/DeepBandwidthToExcel/Template/xl/styles.xml b/Tools/DeepBandwidthToExcel/Template/xl/styles.xml deleted file mode 100644 index 8238b50fd0..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/styles.xml +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/Tools/DeepBandwidthToExcel/Template/xl/theme/theme1.xml b/Tools/DeepBandwidthToExcel/Template/xl/theme/theme1.xml deleted file mode 100644 index 9944f3ecab..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/theme/theme1.xml +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/Tools/DeepBandwidthToExcel/Template/xl/workbook.xml b/Tools/DeepBandwidthToExcel/Template/xl/workbook.xml deleted file mode 100644 index 19c26d83b6..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/workbook.xml +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/Tools/DeepBandwidthToExcel/Template/xl/worksheets/_rels/sheet1.xml.rels b/Tools/DeepBandwidthToExcel/Template/xl/worksheets/_rels/sheet1.xml.rels deleted file mode 100644 index 205832e91b..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/worksheets/_rels/sheet1.xml.rels +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/Tools/DeepBandwidthToExcel/Template/xl/worksheets/_rels/sheet2.xml.rels b/Tools/DeepBandwidthToExcel/Template/xl/worksheets/_rels/sheet2.xml.rels deleted file mode 100644 index b48a928346..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/worksheets/_rels/sheet2.xml.rels +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/Tools/DeepBandwidthToExcel/Template/xl/worksheets/_rels/sheet3.xml.rels b/Tools/DeepBandwidthToExcel/Template/xl/worksheets/_rels/sheet3.xml.rels deleted file mode 100644 index c0c5ded4a6..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/worksheets/_rels/sheet3.xml.rels +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/Tools/DeepBandwidthToExcel/Template/xl/worksheets/_rels/sheet4.xml.rels b/Tools/DeepBandwidthToExcel/Template/xl/worksheets/_rels/sheet4.xml.rels deleted file mode 100644 index f34eab954f..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/worksheets/_rels/sheet4.xml.rels +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/Tools/DeepBandwidthToExcel/Template/xl/worksheets/_rels/sheet5.xml.rels b/Tools/DeepBandwidthToExcel/Template/xl/worksheets/_rels/sheet5.xml.rels deleted file mode 100644 index 67118d3a1e..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/worksheets/_rels/sheet5.xml.rels +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/Tools/DeepBandwidthToExcel/Template/xl/worksheets/_rels/sheet6.xml.rels b/Tools/DeepBandwidthToExcel/Template/xl/worksheets/_rels/sheet6.xml.rels deleted file mode 100644 index 656a337f58..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/worksheets/_rels/sheet6.xml.rels +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/Tools/DeepBandwidthToExcel/Template/xl/worksheets/_rels/sheet7.xml.rels b/Tools/DeepBandwidthToExcel/Template/xl/worksheets/_rels/sheet7.xml.rels deleted file mode 100644 index efc518bb3f..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/worksheets/_rels/sheet7.xml.rels +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/Tools/DeepBandwidthToExcel/Template/xl/worksheets/_rels/sheet8.xml.rels b/Tools/DeepBandwidthToExcel/Template/xl/worksheets/_rels/sheet8.xml.rels deleted file mode 100644 index 586d2d3c76..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/worksheets/_rels/sheet8.xml.rels +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/Tools/DeepBandwidthToExcel/Template/xl/worksheets/sheet1.xml b/Tools/DeepBandwidthToExcel/Template/xl/worksheets/sheet1.xml deleted file mode 100644 index 1fbfb22964..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/worksheets/sheet1.xml +++ /dev/null @@ -1,2 +0,0 @@ - -###---SHEET1_DATA---### diff --git a/Tools/DeepBandwidthToExcel/Template/xl/worksheets/sheet2.xml b/Tools/DeepBandwidthToExcel/Template/xl/worksheets/sheet2.xml deleted file mode 100644 index 0d72f8c9da..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/worksheets/sheet2.xml +++ /dev/null @@ -1,2 +0,0 @@ - -###---SHEET2_DATA---### diff --git a/Tools/DeepBandwidthToExcel/Template/xl/worksheets/sheet3.xml b/Tools/DeepBandwidthToExcel/Template/xl/worksheets/sheet3.xml deleted file mode 100644 index 18717c6987..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/worksheets/sheet3.xml +++ /dev/null @@ -1,2 +0,0 @@ - -###---SHEET3_DATA---### diff --git a/Tools/DeepBandwidthToExcel/Template/xl/worksheets/sheet4.xml b/Tools/DeepBandwidthToExcel/Template/xl/worksheets/sheet4.xml deleted file mode 100644 index 9442249676..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/worksheets/sheet4.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - -###---SHEET4_DATA---### - - - diff --git a/Tools/DeepBandwidthToExcel/Template/xl/worksheets/sheet5.xml b/Tools/DeepBandwidthToExcel/Template/xl/worksheets/sheet5.xml deleted file mode 100644 index 14f48b192c..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/worksheets/sheet5.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - -###---SHEET5_DATA---### - - - diff --git a/Tools/DeepBandwidthToExcel/Template/xl/worksheets/sheet6.xml b/Tools/DeepBandwidthToExcel/Template/xl/worksheets/sheet6.xml deleted file mode 100644 index fa7a8d800b..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/worksheets/sheet6.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - -###---SHEET6_DATA---### - - diff --git a/Tools/DeepBandwidthToExcel/Template/xl/worksheets/sheet7.xml b/Tools/DeepBandwidthToExcel/Template/xl/worksheets/sheet7.xml deleted file mode 100644 index 708d01d20c..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/worksheets/sheet7.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - -###---SHEET7_DATA---### - - diff --git a/Tools/DeepBandwidthToExcel/Template/xl/worksheets/sheet8.xml b/Tools/DeepBandwidthToExcel/Template/xl/worksheets/sheet8.xml deleted file mode 100644 index 164cdcdde2..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/worksheets/sheet8.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - -###---SHEET8_DATA---### - - diff --git a/Tools/DeepBandwidthToExcel/Template/xl/worksheets/sheet9.xml b/Tools/DeepBandwidthToExcel/Template/xl/worksheets/sheet9.xml deleted file mode 100644 index a3a3b40230..0000000000 --- a/Tools/DeepBandwidthToExcel/Template/xl/worksheets/sheet9.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - -###---SHEET9_DATA---### - - diff --git a/scripts/build/package/Platform/Windows/package_filelists/atom.json b/scripts/build/package/Platform/Windows/package_filelists/atom.json index f084173cb2..5f3d3b78cb 100644 --- a/scripts/build/package/Platform/Windows/package_filelists/atom.json +++ b/scripts/build/package/Platform/Windows/package_filelists/atom.json @@ -38,24 +38,13 @@ "AzTestRunner/**": "#include", "CrashHandler/**": "#include", "CryCommonTools/**": "#include", - "CrySCompileServer/**": "#include", - "CryXML/**": "#include", "DeltaCataloger/**": "#include", - "GemRegistry/**": "#include", "GridHub/**": "#include", - "HLSLCrossCompiler/**": "#include", - "HLSLCrossCompilerMETAL/**": "#include", - "LyIdentity/**": "#include", - "LyMetrics/**": "#include", "News/**": "#include", "PythonBindingsExample/**": "#include", - "RC/**": "#include", "RemoteConsole/**": "#include", "SceneAPI/**": "#include", "SerializeContextTools/**": "#include", - "ShaderCacheGen/**": "#include", - "SharedQMLResource/**": "#include", - "Woodpecker/**": "#include", "CMakeLists.txt": "#include" }, "CMakeLists.txt": "#include"