Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
WindowsPlatformMisc.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
6#include "HAL/PlatformMemory.h"
7#include "GenericPlatform/GenericPlatformMisc.h"
8
9#define UE_DEBUG_BREAK_IMPL() PLATFORM_BREAK()
10
11class GenericApplication;
12struct FGuid;
14
15/** Helper struct used to get the string version of the Windows version. */
17{
19 {
25 };
26
27 static int32 GetOSVersions( FString& OutOSVersion, FString& OutOSSubVersion );
28};
29
30/**
31 * Determines the concurrency model to be set for a thread.
32 *
33 * @see FWindowsPlatformMisc::CoInitialize
34 */
35enum class ECOMModel : uint8
36{
37 Singlethreaded = 0, ///< Single-Threaded Apartment (STA)
38 Multithreaded, ///< Multi-Threaded Apartment (MTA)
39};
40
41/**
42* Windows implementation of the misc OS functions
43**/
46{
47 static void PlatformPreInit();
48 static void PlatformInit();
49 static void PlatformTearDown();
54 static int32 GetMaxPathLength();
55
56 UE_DEPRECATED(4.21, "void FPlatformMisc::GetEnvironmentVariable(Name, Result, Length) is deprecated. Use FString FPlatformMisc::GetEnvironmentVariable(Name) instead.")
57 static void GetEnvironmentVariable(const TCHAR* VariableName, TCHAR* Result, int32 ResultLength);
58
59 static FString GetEnvironmentVariable(const TCHAR* VariableName);
60 static void SetEnvironmentVar(const TCHAR* VariableName, const TCHAR* Value);
61
63 static void SubmitErrorReport( const TCHAR* InErrorHist, EErrorReportMode::Type InMode );
64
66 static bool IsDebuggerPresent();
68#endif
69
71 static void BeginNamedEventFrame();
72 static void BeginNamedEvent(const struct FColor& Color, const TCHAR* Text);
73 static void BeginNamedEvent(const struct FColor& Color, const ANSICHAR* Text);
74 static void EndNamedEvent();
75 static void CustomNamedStat(const TCHAR* Text, float Value, const TCHAR* Graph, const TCHAR* Unit);
76 static void CustomNamedStat(const ANSICHAR* Text, float Value, const ANSICHAR* Graph, const ANSICHAR* Unit);
77#endif
78
79 FORCEINLINE static void MemoryBarrier()
80 {
82 _mm_sfence();
83#elif PLATFORM_CPU_ARM_FAMILY
84 __dmb(_ARM64_BARRIER_SY);
85#endif
86 }
87
88 static bool IsRemoteSession();
89
90 static void SetUTF8Output();
91 static void LocalPrint(const TCHAR *Message);
92
94
96 {
97 //returning true when the debugger is attached is to allow
98 //printing of log lines immediately to the output window.
99 //return false in not attached because OutputDebuString is slow.
100 return IsDebuggerPresent();
101 }
102
103 static void RequestExitWithStatus(bool Force, uint8 ReturnCode);
104 static void RequestExit(bool Force);
105 static const TCHAR* GetSystemErrorMessage(TCHAR* OutBuffer, int32 BufferCount, int32 Error);
106 static void CreateGuid(struct FGuid& Result);
107 static EAppReturnType::Type MessageBoxExt( EAppMsgType::Type MsgType, const TCHAR* Text, const TCHAR* Caption );
108 static bool CommandLineCommands();
110 static bool IsValidAbsolutePathFormat(const FString& Path);
111 static int32 NumberOfCores();
115
116 static const TCHAR* GetPlatformFeaturesModuleName();
117
120
121 static uint32 GetLastError();
122 static void SetLastError(uint32 ErrorCode);
123 static void RaiseException( uint32 ExceptionCode );
124 static bool SetStoredValue(const FString& InStoreId, const FString& InSectionName, const FString& InKeyName, const FString& InValue);
125 static bool GetStoredValue(const FString& InStoreId, const FString& InSectionName, const FString& InKeyName, FString& OutValue);
126 static bool DeleteStoredValue(const FString& InStoreId, const FString& InSectionName, const FString& InKeyName);
127 static bool DeleteStoredSection(const FString& InStoreId, const FString& InSectionName);
128
130 static void CoUninitialize();
131
132 /**
133 * Has the OS execute a command and path pair (such as launch a browser)
134 *
135 * @param ComandType OS hint as to the type of command
136 * @param Command the command to execute
137 * @param CommandLine the commands to pass to the executable
138 *
139 * @return whether the command was successful or not
140 */
141 static bool OsExecute(const TCHAR* CommandType, const TCHAR* Command, const TCHAR* CommandLine = NULL);
142
143 /**
144 * Attempts to get the handle to a top-level window of the specified process.
145 *
146 * If the process has a single main window (root), its handle will be returned.
147 * If the process has multiple top-level windows, the first one found is returned.
148 *
149 * @param ProcessId The identifier of the process to get the window for.
150 * @return Window handle, or 0 if not found.
151 */
152 static Windows::HWND GetTopLevelWindowHandle(uint32 ProcessId);
153
154 /**
155 * Determines if we are running on the Windows version or newer
156 *
157 * See the 'Remarks' section of https://msdn.microsoft.com/en-us/library/windows/desktop/ms724833(v=vs.85).aspx
158 * for a list of MajorVersion/MinorVersion version combinations for Microsoft Windows.
159 *
160 * @return Returns true if the current Windows version if equal or newer than MajorVersion
161 */
162 static bool VerifyWindowsVersion(uint32 MajorVersion, uint32 MinorVersion, uint32 BuildNumber = 0);
163
166#endif //#if !UE_BUILD_SHIPPING
167
168
169 /**
170 * Determines if the cpuid instruction is supported on this processor
171 *
172 * @return Returns true if cpuid is supported
173 */
174 static bool HasCPUIDInstruction();
175
176 /**
177 * Determines if AVX2 instruction set is supported on this platform
178 *
179 * @return Returns true if instruction-set is supported
180 */
182
186 static struct FGPUDriverInfo GetGPUDriverInfo(const FString& DeviceDescription, bool bVerbose = true);
187 static void GetOSVersions( FString& out_OSVersionLabel, FString& out_OSSubVersionLabel );
189 static bool GetDiskTotalAndFreeSpace( const FString& InPath, uint64& TotalNumberOfBytes, uint64& NumberOfFreeBytes );
192
193 /**
194 * Uses cpuid instruction to get the vendor string
195 *
196 * @return CPU info bitfield
197 *
198 * Bits 0-3 Stepping ID
199 * Bits 4-7 Model
200 * Bits 8-11 Family
201 * Bits 12-13 Processor type (Intel) / Reserved (AMD)
202 * Bits 14-15 Reserved
203 * Bits 16-19 Extended model
204 * Bits 20-27 Extended family
205 * Bits 28-31 Reserved
206 */
207 static uint32 GetCPUInfo();
208
209 /** @return whether this cpu supports certain required instructions or not */
211 /** @return whether to check for specific CPU compatibility or not */
213 /** @return whether this cpu has timed pause instruction support or not */
215
216 /**
217 * Provides a simpler interface for fetching and cleanup of registry value queries
218 *
219 * @param InKey The Key (folder) in the registry to search under
220 * @param InSubKey The Sub Key (folder) within the main Key to look for
221 * @param InValueName The Name of the Value (file) withing the Sub Key to look for
222 * @param OutData The Data entered into the Value
223 *
224 * @return true, if it successfully found the Value
225 */
226 static bool QueryRegKey( const Windows::HKEY InKey, const TCHAR* InSubKey, const TCHAR* InValueName, FString& OutData );
227
228 /**
229 * Gets Visual Studio common tools path.
230 *
231 * @param Version Version of VS to get (11 - 2012, 12 - 2013).
232 * @param OutData Output parameter with common tools path.
233 *
234 * @return Returns if succeeded.
235 */
236 static bool GetVSComnTools(int32 Version, FString& OutData);
237
238 UE_DEPRECATED(5.2, "Please use PLATFORM_CACHE_LINE_SIZE instead, runtime query of cache line size not supported")
239 static int32 GetCacheLineSize();
240 /**
241 * @return Windows path separator.
242 */
243 static const TCHAR* GetDefaultPathSeparator();
244
245 /** @return Get the name of the platform specific file manager (Explorer) */
247
248 /**
249 * Returns whether WiFi connection is currently active
250 */
252 {
253 // for now return true
254 return true;
255 }
256
257 /**
258 * Returns whether the platform is running on battery power or not.
259 */
260 static bool IsRunningOnBattery();
261
262 FORCEINLINE static void ChooseHDRDeviceAndColorGamut(uint32 DeviceId, uint32 DisplayNitLevel, EDisplayOutputFormat& OutputDevice, EDisplayColorGamut& ColorGamut)
263 {
264 if (DeviceId == 0x1002 /*AMD*/ || DeviceId == 0x10DE /*NVIDIA*/)
265 {
266 // needs to match GRHIHDRDisplayOutputFormat chosen in FD3D12DynamicRHI::Init
267#if WITH_EDITOR
268 // ScRGB, 1000 or 2000 nits
269 OutputDevice = (DisplayNitLevel == 1000) ? EDisplayOutputFormat::HDR_ACES_1000nit_ScRGB : EDisplayOutputFormat::HDR_ACES_2000nit_ScRGB;
270 // Rec709
271 ColorGamut = EDisplayColorGamut::sRGB_D65;
272#else
273 // ST-2084, 1000 or 2000 nits
275 // Rec2020
277#endif
278 }
279 }
280
281 /**
282 * Gets a globally unique ID the represents a particular operating system install.
283 */
285
287
289
291
292 static uint64 GetFileVersion(const FString &FileName);
293
294 static int32 GetMaxRefreshRate();
295};
296
297
299typedef FWindowsPlatformMisc FPlatformMisc;
300#endif
#define ENABLE_STATNAMEDEVENTS
Definition Build.h:221
#define UE_BUILD_SHIPPING
Definition Build.h:4
#define WITH_EDITOR
Definition Build.h:7
#define STATS
Definition Build.h:317
#define UE_DEPRECATED(Version, Message)
EConvertibleLaptopMode
EDisplayColorGamut
EDisplayOutputFormat
ECrashHandlingType
EInputOutputFlags
#define PLATFORM_CPU_X86_FAMILY
Definition Platform.h:80
#define FORCEINLINE
Definition Platform.h:644
#define WINDOWS_USE_FEATURE_PLATFORMMISC_CLASS
#define PLATFORM_BREAK()
@ Singlethreaded
Single-Threaded Apartment (STA)
@ Multithreaded
Multi-Threaded Apartment (MTA)
Definition Text.h:357
HWND__ * HWND
HKEY__ * HKEY
static FORCEINLINE bool IsDebuggerPresent()
Definition Guid.h:108
static int32 GetOSVersions(FString &OutOSVersion, FString &OutOSSubVersion)
static void CoUninitialize()
static FString GetCPUBrand()
static bool Is64bitOperatingSystem()
static void SetGracefulTerminationHandler()
static const TCHAR * GetDefaultPathSeparator()
static int32 NumberOfWorkerThreadsToSpawn()
static FText GetFileManagerName()
static void CreateGuid(struct FGuid &Result)
static ECrashHandlingType GetCrashHandlingType()
static TArray< uint8 > GetMacAddress()
static FString GetPrimaryGPUBrand()
static bool IsValidAbsolutePathFormat(const FString &Path)
static bool GetPageFaultStats(FPageFaultStats &OutStats, EPageFaultFlags Flags=EPageFaultFlags::All)
static bool VerifyWindowsVersion(uint32 MajorVersion, uint32 MinorVersion, uint32 BuildNumber=0)
static uint32 GetCPUInfo()
static EAppReturnType::Type MessageBoxExt(EAppMsgType::Type MsgType, const TCHAR *Text, const TCHAR *Caption)
static bool DeleteStoredValue(const FString &InStoreId, const FString &InSectionName, const FString &InKeyName)
static bool GetStoredValue(const FString &InStoreId, const FString &InSectionName, const FString &InKeyName, FString &OutValue)
static int32 GetMaxPathLength()
static int32 NumberOfCoresIncludingHyperthreads()
static void SetLastError(uint32 ErrorCode)
static bool HasActiveWiFiConnection()
static void PumpMessagesOutsideMainLoop()
static FORCEINLINE void ChooseHDRDeviceAndColorGamut(uint32 DeviceId, uint32 DisplayNitLevel, EDisplayOutputFormat &OutputDevice, EDisplayColorGamut &ColorGamut)
static bool CoInitialize(ECOMModel Model=ECOMModel::Singlethreaded)
static bool GetVSComnTools(int32 Version, FString &OutData)
static uint64 GetFileVersion(const FString &FileName)
static IPlatformChunkInstall * GetPlatformChunkInstall()
static void SetEnvironmentVar(const TCHAR *VariableName, const TCHAR *Value)
static FString GetDefaultLanguage()
static void CallGracefulTerminationHandler()
static void PlatformPreInit()
static FString GetDefaultLocale()
static const TCHAR * GetSystemErrorMessage(TCHAR *OutBuffer, int32 BufferCount, int32 Error)
static bool SetStoredValue(const FString &InStoreId, const FString &InSectionName, const FString &InKeyName, const FString &InValue)
static bool DeleteStoredSection(const FString &InStoreId, const FString &InSectionName)
static int32 GetCacheLineSize()
static bool IsRemoteSession()
static bool HasAVX2InstructionSupport()
static bool IsLocalPrintThreadSafe()
static int32 GetMaxRefreshRate()
static FString GetOSVersion()
static void PlatformTearDown()
static void LocalPrint(const TCHAR *Message)
static bool QueryRegKey(const Windows::HKEY InKey, const TCHAR *InSubKey, const TCHAR *InValueName, FString &OutData)
static void RequestExit(bool Force)
static FString GetOperatingSystemId()
static bool IsRunningOnBattery()
static bool GetDiskTotalAndFreeSpace(const FString &InPath, uint64 &TotalNumberOfBytes, uint64 &NumberOfFreeBytes)
static const FProcessorGroupDesc & GetProcessorGroupDesc()
static void PlatformInit()
static bool CommandLineCommands()
static bool NeedsNonoptionalCPUFeaturesCheck()
static int32 NumberOfCores()
static uint32 GetLastError()
static bool HasTimedPauseCPUFeature()
static const TCHAR * GetPlatformFeaturesModuleName()
static bool GetBlockingIOStats(FProcessIOStats &OutStats, EInputOutputFlags Flags=EInputOutputFlags::All)
static Windows::HWND GetTopLevelWindowHandle(uint32 ProcessId)
static void RaiseException(uint32 ExceptionCode)
static bool HasCPUIDInstruction()
static void SubmitErrorReport(const TCHAR *InErrorHist, EErrorReportMode::Type InMode)
static ECrashHandlingType SetCrashHandlingType(ECrashHandlingType)
static bool HasNonoptionalCPUFeatures()
static bool OsExecute(const TCHAR *CommandType, const TCHAR *Command, const TCHAR *CommandLine=NULL)
static void SetUTF8Output()
static void GetOSVersions(FString &out_OSVersionLabel, FString &out_OSSubVersionLabel)
static bool IsLowLevelOutputDebugStringStructured()
static FString GetCPUVendor()
static void RequestExitWithStatus(bool Force, uint8 ReturnCode)
static EConvertibleLaptopMode GetConvertibleLaptopMode()