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