2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
11 #include "HDRStatus.h"
13 #include "utils/Geometry.h"
19 #define BONJOUR_EVENT ( WM_USER + 0x100 ) // Message sent to the Window when a Bonjour event occurs.
20 #define BONJOUR_BROWSER_EVENT ( WM_USER + 0x110 )
21 #define TRAY_ICON_NOTIFY ( WM_USER + 0x120 )
23 struct VideoDriverInfo
34 class CURL
; // forward declaration
40 virtual ~CWIN32Util(void);
42 static char FirstDriveFromMask (ULONG unitmask
);
43 static int GetDriveStatus(const std::string
&strPath
, bool bStatusEx
=false);
44 static bool XBMCShellExecute(const std::string
&strPath
, bool bWaitForScriptExit
=false);
45 static std::string
GetResInfoString();
46 static int GetDesktopColorDepth();
47 static size_t GetSystemMemorySize();
49 static std::string
GetProfilePath(const bool platformDirectories
);
50 static std::string
UncToSmb(const std::string
&strPath
);
51 static std::string
SmbToUnc(const std::string
&strPath
);
52 static bool AddExtraLongPathPrefix(std::wstring
& path
);
53 static bool RemoveExtraLongPathPrefix(std::wstring
& path
);
54 static std::wstring
ConvertPathToWin32Form(const std::string
& pathUtf8
);
55 static std::wstring
ConvertPathToWin32Form(const CURL
& url
);
56 static inline __time64_t
fileTimeToTimeT(const __int64 ftimei64
)
58 // FILETIME is 100-nanoseconds from 00:00:00 UTC 01 Jan 1601
59 // __time64_t is seconds from 00:00:00 UTC 01 Jan 1970
60 return (ftimei64
- 116444736000000000) / 10000000;
62 static __time64_t
fileTimeToTimeT(const FILETIME
& ftimeft
);
63 static __time64_t
fileTimeToTimeT(const LARGE_INTEGER
& ftimeli
);
64 static HRESULT
ToggleTray(const char cDriveLetter
='\0');
65 static HRESULT
EjectTray(const char cDriveLetter
='\0');
66 static HRESULT
CloseTray(const char cDriveLetter
='\0');
67 static BOOL
IsCurrentUserLocalAdministrator();
69 #ifdef TARGET_WINDOWS_DESKTOP
70 static std::string
GetAppDataFolder();
71 static LONG
UtilRegGetValue( const HKEY hKey
, const char *const pcKey
, DWORD
*const pdwType
, char **const ppcBuffer
, DWORD
*const pdwSizeBuff
, const DWORD dwSizeAdd
);
72 static bool UtilRegOpenKeyEx( const HKEY hKeyParent
, const char *const pcKey
, const REGSAM rsAccessRights
, HKEY
*hKey
, const bool bReadX64
= false );
73 static bool GetFocussedProcess(std::string
&strProcessFile
);
74 #endif // TARGET_WINDOWS_DESKTOP
75 static void CropSource(CRect
& src
, CRect
& dst
, CRect target
, UINT rotation
= 0);
77 static std::string
WUSysMsg(DWORD dwError
);
78 static bool SetThreadLocalLocale(bool enable
= true);
80 // HDR display support
81 static HDR_STATUS
ToggleWindowsHDR(DXGI_MODE_DESC
& modeDesc
);
82 static HDR_STATUS
GetWindowsHDRStatus();
83 static bool GetSystemSdrWhiteLevel(const std::wstring
& gdiDeviceName
, float* sdrWhiteLevel
);
85 static void PlatformSyslog();
87 static VideoDriverInfo
GetVideoDriverInfo(const UINT vendorId
, const std::wstring
& driverDesc
);
88 static VideoDriverInfo
GetVideoDriverInfoDX(const UINT vendorId
, LUID adapterLuid
);
89 static VideoDriverInfo
FormatVideoDriverInfo(const UINT vendorId
, uint64_t rawVersion
);
90 static VideoDriverInfo
FormatVideoDriverInfo(const UINT vendorId
, const std::string version
);
91 static std::wstring
GetDisplayFriendlyName(const std::wstring
& GdiDeviceName
);
93 * \brief Set the thread name using SetThreadDescription when available
94 * \param handle handle of the thread
95 * \param name name of the thread
96 * \return true if the name was successfully set, false otherwise (API not supported or API failure)
98 static bool SetThreadName(const HANDLE handle
, const std::string
& name
);
100 * \brief Compare two Windows driver versions (xx.xx.xx.xx string format)
101 * \param version1 First version to compare
102 * \param version2 Second version to compare
103 * \return true when version1 is greater or equal to version2.
104 * Undefined results when the strings are not formatted properly.
106 static bool IsDriverVersionAtLeast(const std::string
& version1
, const std::string
& version2
);
108 * \brief Format a Windows HRESULT value into a string for logging
109 * \param hr The error code
110 * \return Formatted string
112 static std::string
FormatHRESULT(HRESULT hr
);
115 static HDR_STATUS
GetWindowsHDRStatusWin32();