mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-15 03:07:56 +01:00
refactoring
This commit is contained in:
@@ -127,12 +127,14 @@
|
||||
<ClCompile Include="pch.cpp">
|
||||
<PrecompiledHeader Condition="'$(UsePrecompiledHeaders)' != 'false'">Create</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="SnapshotUtils.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="JsonUtils.h" />
|
||||
<ClInclude Include="NameUtils.h" />
|
||||
<ClInclude Include="pch.h" />
|
||||
<ClInclude Include="resource.h" />
|
||||
<ClInclude Include="SnapshotUtils.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
|
||||
@@ -27,6 +27,9 @@
|
||||
<ClInclude Include="JsonUtils.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="SnapshotUtils.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="pch.cpp">
|
||||
@@ -35,6 +38,9 @@
|
||||
<ClCompile Include="main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="SnapshotUtils.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
|
||||
73
src/modules/Projects/ProjectsSnapshotTool/SnapshotUtils.cpp
Normal file
73
src/modules/Projects/ProjectsSnapshotTool/SnapshotUtils.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
#include "pch.h"
|
||||
#include "SnapshotUtils.h"
|
||||
|
||||
#include <Psapi.h>
|
||||
|
||||
#include <projects-common/AppUtils.h>
|
||||
#include <projects-common/WindowEnumerator.h>
|
||||
#include <projects-common/WindowFilter.h>
|
||||
|
||||
#include <common/utils/process_path.h>
|
||||
#include <TlHelp32.h>
|
||||
|
||||
namespace SnapshotUtils
|
||||
{
|
||||
std::vector<Project::Application> GetApps(const std::function<unsigned int(HWND)> getMonitorNumberFromWindowHandle)
|
||||
{
|
||||
std::vector<Project::Application> apps{};
|
||||
|
||||
auto installedApps = Utils::Apps::GetAppsList();
|
||||
auto windows = WindowEnumerator::Enumerate(WindowFilter::Filter);
|
||||
|
||||
for (const auto window : windows)
|
||||
{
|
||||
// filter by window rect size
|
||||
RECT rect = WindowUtils::GetWindowRect(window);
|
||||
if (rect.right - rect.left <= 0 || rect.bottom - rect.top <= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// filter by window title
|
||||
std::wstring title = WindowUtils::GetWindowTitle(window);
|
||||
if (title.empty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// filter by app path
|
||||
std::wstring processPath = get_process_path_waiting_uwp(window);
|
||||
if (processPath.empty() || WindowUtils::IsExcludedByDefault(window, processPath, title))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
auto data = Utils::Apps::GetApp(processPath, installedApps);
|
||||
if (!data.has_value() || data->name.empty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Project::Application app{
|
||||
.name = data.value().name,
|
||||
.title = title,
|
||||
.path = processPath,
|
||||
.packageFullName = data.value().packageFullName,
|
||||
.commandLineArgs = L"",
|
||||
.isMinimized = WindowUtils::IsMinimized(window),
|
||||
.isMaximized = WindowUtils::IsMaximized(window),
|
||||
.position = Project::Application::Position{
|
||||
.x = rect.left,
|
||||
.y = rect.top,
|
||||
.width = rect.right - rect.left,
|
||||
.height = rect.bottom - rect.top,
|
||||
},
|
||||
.monitor = getMonitorNumberFromWindowHandle(window),
|
||||
};
|
||||
|
||||
apps.push_back(app);
|
||||
}
|
||||
|
||||
return apps;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <projects-common/Data.h>
|
||||
|
||||
namespace SnapshotUtils
|
||||
{
|
||||
std::vector<Project::Application> GetApps(const std::function<unsigned int(HWND)> getMonitorNumberFromWindowHandle);
|
||||
};
|
||||
@@ -1,17 +1,14 @@
|
||||
#include "pch.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
|
||||
#include <projects-common/AppUtils.h>
|
||||
#include <projects-common/Data.h>
|
||||
#include <projects-common/GuidUtils.h>
|
||||
#include <projects-common/MonitorUtils.h>
|
||||
#include <projects-common/WindowEnumerator.h>
|
||||
#include <projects-common/WindowFilter.h>
|
||||
|
||||
#include <JsonUtils.h>
|
||||
#include <NameUtils.h>
|
||||
#include <SnapshotUtils.h>
|
||||
|
||||
#include <common/utils/gpo.h>
|
||||
#include <common/utils/logger_helper.h>
|
||||
@@ -56,44 +53,8 @@ int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hInstPrev, LPSTR cmdLine, int cm
|
||||
Project project{ .id = CreateGuidString(), .name = ProjectNameUtils::CreateProjectName(projects), .creationTime = creationTime };
|
||||
Logger::trace(L"Creating project {}:{}", project.name, project.id);
|
||||
|
||||
// save monitor configuration
|
||||
project.monitors = MonitorUtils::IdentifyMonitors();
|
||||
|
||||
// get list of windows
|
||||
auto windows = WindowEnumerator::Enumerate(WindowFilter::Filter);
|
||||
|
||||
// get installed apps list
|
||||
auto apps = Utils::Apps::GetAppsList();
|
||||
|
||||
for (const auto& window : windows)
|
||||
{
|
||||
// filter by window rect size
|
||||
RECT rect = WindowUtils::GetWindowRect(window);
|
||||
if (rect.right - rect.left <= 0 || rect.bottom - rect.top <= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// filter by window title
|
||||
std::wstring title = WindowUtils::GetWindowTitle(window);
|
||||
if (title.empty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// filter by app path
|
||||
std::wstring processPath = get_process_path_waiting_uwp(window);
|
||||
if (processPath.empty() || WindowUtils::IsExcludedByDefault(window, processPath, title))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
auto data = Utils::Apps::GetApp(processPath, apps);
|
||||
if (!data.has_value() || data->name.empty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
project.apps = SnapshotUtils::GetApps([&](HWND window) -> unsigned int {
|
||||
auto windowMonitor = MonitorFromWindow(window, MONITOR_DEFAULTTOPRIMARY);
|
||||
unsigned int monitorNumber = 0;
|
||||
for (const auto& monitor : project.monitors)
|
||||
@@ -105,25 +66,8 @@ int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hInstPrev, LPSTR cmdLine, int cm
|
||||
}
|
||||
}
|
||||
|
||||
Project::Application app {
|
||||
.name = data.value().name,
|
||||
.title = title,
|
||||
.path = processPath,
|
||||
.packageFullName = data.value().packageFullName,
|
||||
.commandLineArgs = L"",
|
||||
.isMinimized = WindowUtils::IsMinimized(window),
|
||||
.isMaximized = WindowUtils::IsMaximized(window),
|
||||
.position = Project::Application::Position {
|
||||
.x = rect.left,
|
||||
.y = rect.top,
|
||||
.width = rect.right - rect.left,
|
||||
.height = rect.bottom - rect.top,
|
||||
},
|
||||
.monitor = monitorNumber,
|
||||
};
|
||||
|
||||
project.apps.push_back(app);
|
||||
}
|
||||
return monitorNumber;
|
||||
});
|
||||
|
||||
projects.push_back(project);
|
||||
ProjectsJsonUtils::Write(fileName, projects);
|
||||
|
||||
@@ -16,12 +16,12 @@ namespace Utils
|
||||
{
|
||||
namespace NonLocalizable
|
||||
{
|
||||
const wchar_t* PackageFullNameProp = L"System.AppUserModel.PackageFullName";
|
||||
const wchar_t* PackageInstallPathProp = L"System.AppUserModel.PackageInstallPath";
|
||||
const wchar_t* InstallPathProp = L"System.Link.TargetParsingPath";
|
||||
constexpr const wchar_t* PackageFullNameProp = L"System.AppUserModel.PackageFullName";
|
||||
constexpr const wchar_t* PackageInstallPathProp = L"System.AppUserModel.PackageInstallPath";
|
||||
constexpr const wchar_t* InstallPathProp = L"System.Link.TargetParsingPath";
|
||||
|
||||
const wchar_t* FileExplorerName = L"File Explorer";
|
||||
const wchar_t* FileExplorerPath = L"C:\\WINDOWS\\EXPLORER.EXE";
|
||||
constexpr const wchar_t* FileExplorerName = L"File Explorer";
|
||||
constexpr const wchar_t* FileExplorerPath = L"C:\\WINDOWS\\EXPLORER.EXE";
|
||||
}
|
||||
|
||||
struct AppData
|
||||
|
||||
Reference in New Issue
Block a user