Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,24 @@
#
# 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.
#
ly_add_target(
NAME CrashSupport STATIC
NAMESPACE AZ
FILES_CMAKE
crash_handler_support_files.cmake
Platform/${PAL_PLATFORM_NAME}/crash_handler_support_${PAL_PLATFORM_NAME_LOWERCASE}_files.cmake
INCLUDE_DIRECTORIES
PUBLIC
include
BUILD_DEPENDENCIES
PRIVATE
AZ::AzCore
)
@@ -0,0 +1,15 @@
#
# 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
include/CrashSupport.h
src/CrashSupport.cpp
)
@@ -0,0 +1,85 @@
/*
* 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.
*
*/
// LY Crash Handler shared support
#pragma once
#include <AzCore/PlatformDef.h>
#include <algorithm>
#include <string>
#define CRASH_HANDLER_MAX_PATH_LEN 1024
#define _MAKE_DEFINE_STRING(x) #x
#define MAKE_DEFINE_STRING(x) _MAKE_DEFINE_STRING(x)
namespace CrashHandler
{
std::string GetTimeString();
void GetExecutablePathA(char* pathBuffer, int& bufferSize);
void GetExecutablePathW(wchar_t* pathBuffer, int& bufferSize);
void GetTimeInfo(tm& curTime);
template <typename T>
inline void GetExecutablePath(T& returnPath)
{
char currentFileName[CRASH_HANDLER_MAX_PATH_LEN] = { 0 };
int bufferLen{ CRASH_HANDLER_MAX_PATH_LEN };
GetExecutablePathA(currentFileName, bufferLen);
returnPath = currentFileName;
std::replace(returnPath.begin(), returnPath.end(), '\\', '/');
}
template <>
inline void GetExecutablePath<std::wstring>(std::wstring& returnPath)
{
wchar_t currentFileName[CRASH_HANDLER_MAX_PATH_LEN] = { 0 };
int bufferLen{ CRASH_HANDLER_MAX_PATH_LEN };
GetExecutablePathW(currentFileName, bufferLen);
returnPath = currentFileName;
std::replace(returnPath.begin(), returnPath.end(), '\\', '/');
}
template<typename T>
inline void GetExecutableFolder(T& returnPath)
{
GetExecutablePath(returnPath);
auto lastPos = returnPath.find_last_of('/');
if (lastPos != T::npos)
{
returnPath = returnPath.substr(0, lastPos + 1);
}
}
template<typename T>
inline void GetExecutableBaseName(T& returnPath)
{
GetExecutablePath(returnPath);
auto lastPos = returnPath.find_last_of('/');
if (lastPos != T::npos)
{
returnPath = returnPath.substr(lastPos + 1, returnPath.length());
}
auto extPos = returnPath.find_last_of('.');
if (extPos != T::npos)
{
returnPath = returnPath.substr(0, extPos);
}
}
}
@@ -0,0 +1,14 @@
#
# 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
../../Platform/win/CrashSupport_win.cpp
)
@@ -0,0 +1,38 @@
/*
* 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 <CrashSupport.h>
#include <mach-o/dyld.h> // Needed for _NSGetExecutablePath
#include <time.h>
namespace CrashHandler
{
void GetExecutablePathA(char* pathBuffer, int& bufferSize)
{
unsigned int localBufferSize{static_cast<unsigned int>(bufferSize)};
_NSGetExecutablePath(pathBuffer, &localBufferSize);
}
void GetExecutablePathW(wchar_t* pathBuffer, int& bufferSize)
{
// Windows only
}
void GetTimeInfo(tm& timeInfo)
{
time_t rawtime;
time(&rawtime);
localtime_r(&rawtime, &timeInfo);
}
}
@@ -0,0 +1,38 @@
/*
* 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 <CrashSupport.h>
#include <algorithm>
#include <AzCore/PlatformIncl.h>
#include <time.h>
namespace CrashHandler
{
void GetExecutablePathA(char* pathBuffer, int& bufferSize)
{
GetModuleFileNameA(nullptr, pathBuffer, bufferSize);
}
void GetExecutablePathW(wchar_t* pathBuffer, int& bufferSize)
{
GetModuleFileNameW(nullptr, pathBuffer, bufferSize);
}
void GetTimeInfo(tm& timeInfo)
{
time_t rawtime;
time(&rawtime);
localtime_s(&timeInfo, &rawtime);
}
}
@@ -0,0 +1,34 @@
/*
* 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.
*
*/
// LY Crash Handler shared support
#include <CrashSupport.h>
#include <time.h>
namespace CrashHandler
{
std::string GetTimeString()
{
const int bufLen = 100;
char buffer[bufLen];
struct tm timeinfo;
GetTimeInfo(timeinfo);
strftime(buffer, bufLen, "%Y-%m-%dT%H:%M:%S", &timeinfo);
return buffer;
}
}