mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 19:57:57 +01:00
moved app utils
This commit is contained in:
@@ -7,6 +7,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ProjectsSnapshotTool", "Pro
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "projects-common", "projects-common", "{BA45247D-3046-408D-BE01-128587A7799F}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "projects-common", "projects-common", "{BA45247D-3046-408D-BE01-128587A7799F}"
|
||||||
ProjectSection(SolutionItems) = preProject
|
ProjectSection(SolutionItems) = preProject
|
||||||
|
projects-common\AppUtils.h = projects-common\AppUtils.h
|
||||||
projects-common\Data.h = projects-common\Data.h
|
projects-common\Data.h = projects-common\Data.h
|
||||||
projects-common\GuidUtils.h = projects-common\GuidUtils.h
|
projects-common\GuidUtils.h = projects-common\GuidUtils.h
|
||||||
projects-common\json.h = projects-common\json.h
|
projects-common\json.h = projects-common\json.h
|
||||||
|
|||||||
@@ -80,7 +80,7 @@
|
|||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
<GenerateWindowsMetadata>false</GenerateWindowsMetadata>
|
<GenerateWindowsMetadata>false</GenerateWindowsMetadata>
|
||||||
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">shcore.lib;Shell32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">shcore.lib;Shell32.lib;propsys.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Platform)'=='Win32'">
|
<ItemDefinitionGroup Condition="'$(Platform)'=='Win32'">
|
||||||
@@ -101,7 +101,7 @@
|
|||||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
<OptimizeReferences>true</OptimizeReferences>
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
<GenerateWindowsMetadata>false</GenerateWindowsMetadata>
|
<GenerateWindowsMetadata>false</GenerateWindowsMetadata>
|
||||||
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Release|x64'">shcore.lib;Shell32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Release|x64'">shcore.lib;Shell32.lib;propsys.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
|
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
namespace Utils
|
|
||||||
{
|
|
||||||
namespace Apps
|
|
||||||
{
|
|
||||||
struct AppData
|
|
||||||
{
|
|
||||||
std::wstring name;
|
|
||||||
std::wstring installPath;
|
|
||||||
std::wstring packageFullName;
|
|
||||||
};
|
|
||||||
|
|
||||||
using AppList = std::vector<AppData>; // path; data
|
|
||||||
|
|
||||||
AppList GetAppsList();
|
|
||||||
std::optional<AppData> GetApp(const std::wstring& appPath, const AppList& apps);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -117,14 +117,12 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="MonitorUtils.h" />
|
<ClInclude Include="MonitorUtils.h" />
|
||||||
<ClInclude Include="OnThreadExecutor.h" />
|
<ClInclude Include="OnThreadExecutor.h" />
|
||||||
<ClInclude Include="PackagedAppUtils.h" />
|
|
||||||
<ClInclude Include="pch.h" />
|
<ClInclude Include="pch.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="main.cpp" />
|
<ClCompile Include="main.cpp" />
|
||||||
<ClCompile Include="MonitorUtils.cpp" />
|
<ClCompile Include="MonitorUtils.cpp" />
|
||||||
<ClCompile Include="OnThreadExecutor.cpp" />
|
<ClCompile Include="OnThreadExecutor.cpp" />
|
||||||
<ClCompile Include="PackagedAppUtils.cpp" />
|
|
||||||
<ClCompile Include="pch.cpp">
|
<ClCompile Include="pch.cpp">
|
||||||
<PrecompiledHeader>Create</PrecompiledHeader>
|
<PrecompiledHeader>Create</PrecompiledHeader>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
|||||||
@@ -24,9 +24,6 @@
|
|||||||
<ClInclude Include="OnThreadExecutor.h">
|
<ClInclude Include="OnThreadExecutor.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="PackagedAppUtils.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="pch.cpp">
|
<ClCompile Include="pch.cpp">
|
||||||
@@ -41,9 +38,6 @@
|
|||||||
<ClCompile Include="OnThreadExecutor.cpp">
|
<ClCompile Include="OnThreadExecutor.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="PackagedAppUtils.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="PropertySheet.props" />
|
<None Include="PropertySheet.props" />
|
||||||
|
|||||||
@@ -3,13 +3,13 @@
|
|||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "../projects-common/AppUtils.h"
|
||||||
#include "../projects-common/Data.h"
|
#include "../projects-common/Data.h"
|
||||||
#include "../projects-common/GuidUtils.h"
|
#include "../projects-common/GuidUtils.h"
|
||||||
#include "../projects-common/WindowEnumerator.h"
|
#include "../projects-common/WindowEnumerator.h"
|
||||||
#include "../projects-common/WindowFilter.h"
|
#include "../projects-common/WindowFilter.h"
|
||||||
|
|
||||||
#include "MonitorUtils.h"
|
#include "MonitorUtils.h"
|
||||||
#include "PackagedAppUtils.h"
|
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,21 +1,16 @@
|
|||||||
#include "pch.h"
|
#pragma once
|
||||||
#include "PackagedAppUtils.h"
|
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <winreg.h>
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <filesystem>
|
|
||||||
|
|
||||||
#include <atlbase.h>
|
#include <atlbase.h>
|
||||||
#include <wil/registry.h>
|
|
||||||
#include <ShlObj.h>
|
#include <ShlObj.h>
|
||||||
#include <propvarutil.h>
|
#include <propvarutil.h>
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
namespace Utils
|
namespace Utils
|
||||||
{
|
{
|
||||||
namespace Apps
|
namespace Apps
|
||||||
{
|
{
|
||||||
namespace NonLocalizable
|
namespace NonLocalizable
|
||||||
{
|
{
|
||||||
const wchar_t* PackageFullNameProp = L"System.AppUserModel.PackageFullName";
|
const wchar_t* PackageFullNameProp = L"System.AppUserModel.PackageFullName";
|
||||||
@@ -26,7 +21,16 @@ namespace Utils
|
|||||||
const wchar_t* FileExplorerPath = L"C:\\WINDOWS\\EXPLORER.EXE";
|
const wchar_t* FileExplorerPath = L"C:\\WINDOWS\\EXPLORER.EXE";
|
||||||
}
|
}
|
||||||
|
|
||||||
AppList IterateAppsFolder()
|
struct AppData
|
||||||
|
{
|
||||||
|
std::wstring name;
|
||||||
|
std::wstring installPath;
|
||||||
|
std::wstring packageFullName;
|
||||||
|
};
|
||||||
|
|
||||||
|
using AppList = std::vector<AppData>; // path; data
|
||||||
|
|
||||||
|
inline AppList IterateAppsFolder()
|
||||||
{
|
{
|
||||||
AppList result{};
|
AppList result{};
|
||||||
|
|
||||||
@@ -50,18 +54,17 @@ namespace Utils
|
|||||||
{
|
{
|
||||||
CComPtr<IShellItem> item = items;
|
CComPtr<IShellItem> item = items;
|
||||||
CComHeapPtr<wchar_t> name;
|
CComHeapPtr<wchar_t> name;
|
||||||
|
|
||||||
if (FAILED(item->GetDisplayName(SIGDN_NORMALDISPLAY, &name)))
|
if (FAILED(item->GetDisplayName(SIGDN_NORMALDISPLAY, &name)))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wcout << name.m_pData << std::endl;
|
std::wcout << name.m_pData << std::endl;
|
||||||
AppData data
|
AppData data{
|
||||||
{
|
|
||||||
.name = std::wstring(name.m_pData),
|
.name = std::wstring(name.m_pData),
|
||||||
};
|
};
|
||||||
|
|
||||||
// properties
|
// properties
|
||||||
CComPtr<IPropertyStore> store;
|
CComPtr<IPropertyStore> store;
|
||||||
if (FAILED(item->BindToHandler(NULL, BHID_PropertyStore, IID_PPV_ARGS(&store))))
|
if (FAILED(item->BindToHandler(NULL, BHID_PropertyStore, IID_PPV_ARGS(&store))))
|
||||||
@@ -83,7 +86,7 @@ namespace Utils
|
|||||||
PSGetNameFromPropertyKey(pk, &pkName);
|
PSGetNameFromPropertyKey(pk, &pkName);
|
||||||
|
|
||||||
std::wstring prop(pkName.m_pData);
|
std::wstring prop(pkName.m_pData);
|
||||||
if (prop == NonLocalizable::PackageFullNameProp ||
|
if (prop == NonLocalizable::PackageFullNameProp ||
|
||||||
prop == NonLocalizable::PackageInstallPathProp ||
|
prop == NonLocalizable::PackageInstallPathProp ||
|
||||||
prop == NonLocalizable::InstallPathProp)
|
prop == NonLocalizable::InstallPathProp)
|
||||||
{
|
{
|
||||||
@@ -122,12 +125,12 @@ namespace Utils
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
AppList Utils::Apps::GetAppsList()
|
inline AppList GetAppsList()
|
||||||
{
|
{
|
||||||
return IterateAppsFolder();
|
return IterateAppsFolder();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<AppData> GetApp(const std::wstring& appPath, const AppList& apps)
|
inline std::optional<AppData> GetApp(const std::wstring& appPath, const AppList& apps)
|
||||||
{
|
{
|
||||||
for (const auto& appData : apps)
|
for (const auto& appData : apps)
|
||||||
{
|
{
|
||||||
@@ -137,8 +140,7 @@ namespace Utils
|
|||||||
// edge case, "Windows Software Development Kit" has the same app path as "File Explorer"
|
// edge case, "Windows Software Development Kit" has the same app path as "File Explorer"
|
||||||
if (appPathUpper == NonLocalizable::FileExplorerPath)
|
if (appPathUpper == NonLocalizable::FileExplorerPath)
|
||||||
{
|
{
|
||||||
return AppData
|
return AppData{
|
||||||
{
|
|
||||||
.name = NonLocalizable::FileExplorerName,
|
.name = NonLocalizable::FileExplorerName,
|
||||||
.installPath = appPath,
|
.installPath = appPath,
|
||||||
};
|
};
|
||||||
@@ -164,9 +166,9 @@ namespace Utils
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: not all installed apps found
|
// TODO: not all installed apps found
|
||||||
return AppData {
|
return AppData{
|
||||||
.installPath = appPath
|
.installPath = appPath
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user