Moving SystemUtilsApple.mm and SystemUtilsApple.h from CrySystem to AzFramework to fix linker error when building iOS non-monolithically (#631)
This commit is contained in:
@@ -77,7 +77,7 @@ unsigned int g_EnableMultipleAssert = 0;//set to something else than 0 if to ena
|
||||
#endif
|
||||
|
||||
#if defined(APPLE)
|
||||
#include "../CrySystem/SystemUtilsApple.h"
|
||||
#include <AzFramework/Utils/SystemUtilsApple.h>
|
||||
#endif
|
||||
|
||||
#include "StringUtils.h"
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
#define LOG_BACKUP_PATH "@log@/LogBackups"
|
||||
|
||||
#if defined(IOS)
|
||||
#include "SystemUtilsApple.h"
|
||||
#include <AzFramework/Utils/SystemUtilsApple.h>
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#include <AzCore/std/string/string.h>
|
||||
|
||||
#include "MobileDetectSpec.h"
|
||||
#include "SystemUtilsApple.h"
|
||||
#include <AzFramework/Utils/SystemUtilsApple.h>
|
||||
|
||||
namespace MobileSysInspect
|
||||
{
|
||||
|
||||
@@ -8,8 +8,3 @@
|
||||
# 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
|
||||
../../SystemUtilsApple.h
|
||||
../../SystemUtilsApple.mm
|
||||
)
|
||||
|
||||
@@ -13,8 +13,6 @@ set(FILES
|
||||
../../MobileDetectSpec_Ios.cpp
|
||||
../../MobileDetectSpec.cpp
|
||||
../../MobileDetectSpec.h
|
||||
../../SystemUtilsApple.h
|
||||
../../SystemUtilsApple.mm
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -1,78 +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 : Utilities for iOS and Mac OS X. Needs to be separated
|
||||
// due to conflict with the system headers.
|
||||
|
||||
|
||||
#ifndef CRYINCLUDE_CRYSYSTEM_SYSTEMUTILSAPPLE_H
|
||||
#define CRYINCLUDE_CRYSYSTEM_SYSTEMUTILSAPPLE_H
|
||||
#pragma once
|
||||
|
||||
#include <sys/resource.h>
|
||||
#include <sys/types.h>
|
||||
#include <AzCore/std/string/string.h>
|
||||
|
||||
namespace SystemUtilsApple
|
||||
{
|
||||
// Get the path to the application's bundle.
|
||||
// - Returns length of the string or 0 on failure.
|
||||
size_t GetPathToApplicationBundle(char* buffer, size_t bufferLen);
|
||||
|
||||
// Get the path to the application's executable.
|
||||
// - Returns length of the string or 0 on failure.
|
||||
size_t GetPathToApplicationExecutable(char* buffer, size_t bufferLen);
|
||||
|
||||
// Get the path to the application's resources.
|
||||
// - Returns length of the string or 0 on failure.
|
||||
size_t GetPathToApplicationResources(char* buffer, size_t bufferLen);
|
||||
|
||||
// Get the path to the user domain's application support directory.
|
||||
// - Returns length of the string or 0 on failure.
|
||||
// - Used to store application generated content.
|
||||
// - iOS: Not available through file sharing.
|
||||
// - Persistent, backed up by iTunes.
|
||||
size_t GetPathToUserApplicationSupportDirectory(char* buffer, size_t bufferLen);
|
||||
|
||||
// Get the path to the user domain's caches directory.
|
||||
// - Returns length of the string or 0 on failure.
|
||||
// - Used to store application generated content.
|
||||
// - iOS: Not available through file sharing.
|
||||
// - Temporary, not backed up by iTunes.
|
||||
size_t GetPathToUserCachesDirectory(char* buffer, size_t bufferLen);
|
||||
|
||||
// Get the path to the user domain's document directory.
|
||||
// - Returns length of the string or 0 on failure.
|
||||
// - Used to store user generated content.
|
||||
// - iOS: Available through file sharing.
|
||||
// - Persistent, backed up by iTunes.
|
||||
size_t GetPathToUserDocumentDirectory(char* buffer, size_t bufferLen);
|
||||
|
||||
// Get the path to the user domain's library directory.
|
||||
// - Returns length of the string or 0 on failure.
|
||||
// - Parent directory of app support and caches.
|
||||
// - iOS: Not available through file sharing.
|
||||
// - Persistent, backed up by iTunes.
|
||||
size_t GetPathToUserLibraryDirectory(char* buffer, size_t bufferLen);
|
||||
|
||||
// Get the user's name.
|
||||
// - Returns length of the string or 0 on failure.
|
||||
size_t GetUserName(char* buffer, size_t bufferLen);
|
||||
|
||||
// Get the device's machine name
|
||||
// - Returns string representing device identifier or empty string on failure
|
||||
// - Unique for each model
|
||||
AZStd::string GetMachineName();
|
||||
}
|
||||
|
||||
#endif // CRYINCLUDE_CRYSYSTEM_SYSTEMUTILSAPPLE_H
|
||||
@@ -1,131 +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 "SystemUtilsApple.h"
|
||||
#include <AzCore/base.h>
|
||||
#include <AzCore/Debug/Trace.h>
|
||||
#include <Foundation/Foundation.h>
|
||||
#include <mach-o/dyld.h>
|
||||
#include <pthread.h>
|
||||
#include <sys/utsname.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
namespace SystemUtilsApplePrivate
|
||||
{
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Performs a 'safe' string copy from 'NString* source' to 'char* buffer' of 'size_t bufferLen'.
|
||||
// Returns the length of the string, or 0 if the buffer is not large enough to hold the source.
|
||||
// Copying an empty or null string will return 0, and null-terminate the buffer if possible.
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
size_t CopyNSStringToBuffer(NSString* source, char* buffer, const size_t bufferLen)
|
||||
{
|
||||
if (!buffer || !bufferLen)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (source)
|
||||
{
|
||||
const char* src = [source UTF8String];
|
||||
const size_t srcLen = strlen(src);
|
||||
if (srcLen < bufferLen - 1)
|
||||
{
|
||||
azstrncpy(buffer, bufferLen, src, srcLen);
|
||||
buffer[srcLen] = '\0';
|
||||
return srcLen;
|
||||
}
|
||||
}
|
||||
|
||||
// Could not copy the source to the destination buffer.
|
||||
buffer[0] = '\0';
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Get the path to the specified user domain directory.
|
||||
// Returns length of the string or 0 on failure.
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
size_t GetPathToUserDirectory(NSSearchPathDirectory dir, char* buffer, const size_t bufferLen)
|
||||
{
|
||||
NSArray* userDomainDirectoryPaths = NSSearchPathForDirectoriesInDomains(dir, NSUserDomainMask, YES);
|
||||
if ([userDomainDirectoryPaths count] != 0)
|
||||
{
|
||||
NSString* userDomainDirectoryPath = static_cast<NSString*>([userDomainDirectoryPaths objectAtIndex:0]);
|
||||
return CopyNSStringToBuffer(userDomainDirectoryPath, buffer, bufferLen);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
size_t SystemUtilsApple::GetPathToApplicationBundle(char* buffer, const size_t bufferLen)
|
||||
{
|
||||
NSString* bundlePath = [[NSBundle mainBundle] bundlePath];
|
||||
return SystemUtilsApplePrivate::CopyNSStringToBuffer(bundlePath, buffer, bufferLen);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
size_t SystemUtilsApple::GetPathToApplicationExecutable(char* buffer, const size_t bufferLen)
|
||||
{
|
||||
NSString* executablePath = [[NSBundle mainBundle] executablePath];
|
||||
return SystemUtilsApplePrivate::CopyNSStringToBuffer(executablePath, buffer, bufferLen);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
size_t SystemUtilsApple::GetPathToApplicationResources(char* buffer, const size_t bufferLen)
|
||||
{
|
||||
NSString* resourcesPath = [[NSBundle mainBundle] resourcePath];
|
||||
return SystemUtilsApplePrivate::CopyNSStringToBuffer(resourcesPath, buffer, bufferLen);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
size_t SystemUtilsApple::GetPathToUserApplicationSupportDirectory(char* buffer, const size_t bufferLen)
|
||||
{
|
||||
return SystemUtilsApplePrivate::GetPathToUserDirectory(NSApplicationSupportDirectory, buffer, bufferLen);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
size_t SystemUtilsApple::GetPathToUserCachesDirectory(char* buffer, const size_t bufferLen)
|
||||
{
|
||||
return SystemUtilsApplePrivate::GetPathToUserDirectory(NSCachesDirectory, buffer, bufferLen);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
size_t SystemUtilsApple::GetPathToUserDocumentDirectory(char* buffer, const size_t bufferLen)
|
||||
{
|
||||
return SystemUtilsApplePrivate::GetPathToUserDirectory(NSDocumentDirectory, buffer, bufferLen);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
size_t SystemUtilsApple::GetPathToUserLibraryDirectory(char* buffer, const size_t bufferLen)
|
||||
{
|
||||
return SystemUtilsApplePrivate::GetPathToUserDirectory(NSLibraryDirectory, buffer, bufferLen);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
size_t SystemUtilsApple::GetUserName(char* buffer, const size_t bufferLen)
|
||||
{
|
||||
return SystemUtilsApplePrivate::CopyNSStringToBuffer(NSUserName(), buffer, bufferLen);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
AZStd::string SystemUtilsApple::GetMachineName()
|
||||
{
|
||||
utsname systemInfo;
|
||||
if (uname(&systemInfo) == -1)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
return systemInfo.machine;
|
||||
}
|
||||
@@ -66,7 +66,7 @@ __pragma(comment(lib, "Winmm.lib"))
|
||||
#endif
|
||||
|
||||
#if defined(APPLE)
|
||||
#include "SystemUtilsApple.h"
|
||||
#include <AzFramework/Utils/SystemUtilsApple.h>
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -9,7 +9,3 @@
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
#
|
||||
|
||||
set(FILES
|
||||
SystemUtilsApple.h
|
||||
SystemUtilsApple.mm
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user