common: refactor common library pt2 (#8588)

- remove common lib
- split settings, remove common-md
- move ipc interop/kb_layout to interop
- rename core -> settings, settings -> old_settings
- os-detect header-only; interop -> PowerToysInterop
- split notifications, move single-use headers where they're used
- winstore lib
- rename com utils
- rename Updating and Telemetry projects
- rename core -> settings-ui and remove examples folder
- rename settings-ui folder + consisent common/version include
This commit is contained in:
Andrey Nekrasov
2020-12-15 15:16:09 +03:00
committed by GitHub
parent cddf48547d
commit 212ea2de30
588 changed files with 3304 additions and 3328 deletions

View File

@@ -2,12 +2,14 @@
#include "util.h"
#include "Settings.h"
#include <common/common.h>
#include <common/dpi_aware.h>
#include <common/display/dpi_aware.h>
#include <common/utils/process_path.h>
#include <common/utils/window.h>
#include <array>
#include <sstream>
#include <complex>
#include <wil/Resource.h>
#include <fancyzones/lib/FancyZonesDataTypes.h>
@@ -18,6 +20,20 @@ namespace NonLocalizable
const wchar_t PowerToysAppFZEditor[] = L"FANCYZONESEDITOR.EXE";
}
bool find_app_name_in_path(const std::wstring& where, const std::vector<std::wstring>& what)
{
for (const auto& row : what)
{
const auto pos = where.rfind(row);
const auto last_slash = where.rfind('\\');
//Check that row occurs in where, and its last occurrence contains in itself the first character after the last backslash.
if (pos != std::wstring::npos && pos <= last_slash + 1 && pos + row.length() > last_slash)
{
return true;
}
}
return false;
}
namespace
{
bool IsZonableByProcessPath(const std::wstring& processPath, const std::vector<std::wstring>& excludedApps)
@@ -65,7 +81,7 @@ namespace FancyZonesUtils
return defaultDeviceId;
}
}
std::optional<FancyZonesDataTypes::DeviceIdData> ParseDeviceId(const std::wstring& str)
{
FancyZonesDataTypes::DeviceIdData data;
@@ -93,7 +109,7 @@ namespace FancyZonesUtils
data.deviceName += L"#" + temp;
}
else if(std::getline(wss, temp, L'_') && !temp.empty())
else if (std::getline(wss, temp, L'_') && !temp.empty())
{
data.deviceName = temp;
}
@@ -153,7 +169,7 @@ namespace FancyZonesUtils
return data;
}
typedef BOOL(WINAPI* GetDpiForMonitorInternalFunc)(HMONITOR, UINT, UINT*, UINT*);
std::wstring GetDisplayDeviceId(const std::wstring& device, std::unordered_map<std::wstring, DWORD>& displayDeviceIdxMap)
{
@@ -618,7 +634,7 @@ namespace FancyZonesUtils
const double eccentricity = 2.0;
auto rectCenter = [](RECT rect) {
return complex {
return complex{
0.5 * rect.left + 0.5 * rect.right,
0.5 * rect.top + 0.5 * rect.bottom
};
@@ -732,4 +748,33 @@ namespace FancyZonesUtils
return windowRect;
}
bool IsProcessOfWindowElevated(HWND window)
{
DWORD pid = 0;
GetWindowThreadProcessId(window, &pid);
if (!pid)
{
return false;
}
wil::unique_handle hProcess{ OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION,
FALSE,
pid) };
wil::unique_handle token;
bool elevated = false;
if (OpenProcessToken(hProcess.get(), TOKEN_QUERY, &token))
{
TOKEN_ELEVATION elevation;
DWORD size;
if (GetTokenInformation(token.get(), TokenElevation, &elevation, sizeof(elevation), &size))
{
return elevation.TokenIsElevated != 0;
}
}
return false;
}
}