Change how UWP Apps are enumerated

Now using powershell-script
experimental/UWP_Inject
Peter Repukat 2 years ago
parent 0b1e98a4e2
commit 6b7127e1bb

@ -44,7 +44,7 @@ Global
HideSolutionNode = FALSE HideSolutionNode = FALSE
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
Qt5Version = $(DefaultQtVersion)
SolutionGuid = {789386B6-7D1E-4F9C-BF2E-9B5EDC3BB7C8} SolutionGuid = {789386B6-7D1E-4F9C-BF2E-9B5EDC3BB7C8}
Qt5Version = 6.2.2_msvc2019_64
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal

@ -0,0 +1,40 @@
#stolen and adapted from: https://github.com/BrianLima/UWPHook/blob/master/UWPHook/Resources/GetAUMIDScript.ps1
$installedapps = get-AppxPackage
$invalidNames = '*ms-resource*', '*DisplayName*'
$aumidList = @()
foreach ($app in $installedapps)
{
try {
if(-not $app.IsFramework){
foreach ($id in (Get-AppxPackageManifest $app).package.applications.application.id)
{
$appx = Get-AppxPackageManifest $app;
$name = $appx.Package.Properties.DisplayName;
if($name -like '*DisplayName*' -or $name -like '*ms-resource*')
{
$name = $appx.Package.Applications.Application.VisualElements.DisplayName;
}
if($name -like '*DisplayName*' -or $name -like '*ms-resource*')
{
$name = "-Error-";
}
$installDir = $app.InstallLocation;
$logo = $app.InstallLocation + "\" + $appx.Package.Applications.Application.VisualElements.Square150x150Logo;
$aumidList += $name + "|" + $installDir + "|" + $logo + "|" +
$app.packagefamilyname + "!" + $id + ";"
}
}
}
catch
{
$ErrorMessage = $_.Exception.Message
$FailedItem = $_.Exception.ItemName
}
}
$aumidList;

@ -31,13 +31,13 @@
<Import Project="$(QtMsBuild)\qt_defaults.props" /> <Import Project="$(QtMsBuild)\qt_defaults.props" />
</ImportGroup> </ImportGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" Label="QtSettings"> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" Label="QtSettings">
<QtInstall>$(DefaultQtVersion)</QtInstall> <QtInstall>6.2.2_msvc2019_64</QtInstall>
<QtModules>quick</QtModules> <QtModules>quick</QtModules>
<QtBuildConfig>debug</QtBuildConfig> <QtBuildConfig>debug</QtBuildConfig>
<QtQMLDebugEnable>true</QtQMLDebugEnable> <QtQMLDebugEnable>true</QtQMLDebugEnable>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'" Label="QtSettings"> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'" Label="QtSettings">
<QtInstall>$(DefaultQtVersion)</QtInstall> <QtInstall>6.2.2_msvc2019_64</QtInstall>
<QtModules>quick</QtModules> <QtModules>quick</QtModules>
<QtBuildConfig>release</QtBuildConfig> <QtBuildConfig>release</QtBuildConfig>
</PropertyGroup> </PropertyGroup>
@ -135,6 +135,7 @@
<ClCompile Include="main.cpp" /> <ClCompile Include="main.cpp" />
<ClCompile Include="UIModel.cpp" /> <ClCompile Include="UIModel.cpp" />
<None Include=".clang-format" /> <None Include=".clang-format" />
<None Include="GetAUMIDs.ps1" />
<None Include="qml\AddSelectTypeDialog.qml" /> <None Include="qml\AddSelectTypeDialog.qml" />
<None Include="qml\FluentTextInput.qml" /> <None Include="qml\FluentTextInput.qml" />
<None Include="qml\InfoDialog.qml" /> <None Include="qml\InfoDialog.qml" />

@ -64,6 +64,7 @@
<Filter>qml</Filter> <Filter>qml</Filter>
</None> </None>
<None Include=".clang-format" /> <None Include=".clang-format" />
<None Include="GetAUMIDs.ps1" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<QtMoc Include="UIModel.h"> <QtMoc Include="UIModel.h">

@ -51,8 +51,8 @@ END
// //
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 0,0,3,105001394320 FILEVERSION 0,0,3,108000010980
PRODUCTVERSION 0,0,3,105001394320 PRODUCTVERSION 0,0,3,108000010980
FILEFLAGSMASK 0x3fL FILEFLAGSMASK 0x3fL
#ifdef _DEBUG #ifdef _DEBUG
FILEFLAGS 0x1L FILEFLAGS 0x1L
@ -69,12 +69,12 @@ BEGIN
BEGIN BEGIN
VALUE "CompanyName", "Peter Repukat - FlatspotSoftware" VALUE "CompanyName", "Peter Repukat - FlatspotSoftware"
VALUE "FileDescription", "GlosSI - Config" VALUE "FileDescription", "GlosSI - Config"
VALUE "FileVersion", "0.0.3.1-5-g139432c" VALUE "FileVersion", "0.0.3.1-8-g0b1e98a"
VALUE "InternalName", "GlosSIConfig" VALUE "InternalName", "GlosSIConfig"
VALUE "LegalCopyright", "Copyright (C) 2021 Peter Repukat - FlatspotSoftware" VALUE "LegalCopyright", "Copyright (C) 2021 Peter Repukat - FlatspotSoftware"
VALUE "OriginalFilename", "GlosSIConfig.exe" VALUE "OriginalFilename", "GlosSIConfig.exe"
VALUE "ProductName", "GlosSi" VALUE "ProductName", "GlosSi"
VALUE "ProductVersion", "0.0.3.1-5-g139432c" VALUE "ProductVersion", "0.0.3.1-8-g0b1e98a"
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"
@ -678,6 +678,134 @@ END

@ -1,23 +1,16 @@
#pragma once #pragma once
#include <QVariant> #include <QVariant>
#include <QProcess>
#include <QVariantMap>
#include <VersionHelpers.h> #include <VersionHelpers.h>
#include <Windows.h> #include <Windows.h>
#include <appmodel.h>
#include <appxpackaging.h>
#include <collection.h>
#include <shlwapi.h>
#include <strsafe.h>
#include <windows.h>
#pragma comment(lib, "Shlwapi.lib")
using namespace Windows::Management::Deployment;
using namespace Windows::Foundation::Collections;
namespace UWPFetch { namespace UWPFetch {
QVariantList UWPAppList() QVariantList UWPAppList()
{ {
// TODO really should do this async, and notify gui when complete...
if (!IsWindows10OrGreater()) { if (!IsWindows10OrGreater()) {
return QVariantList(); return QVariantList();
} }
@ -34,204 +27,51 @@ QVariantList UWPAppList()
}; };
QVariantList pairs; QVariantList pairs;
// is it considered stealing when you take code that was pull-requested by someone else into your own repo?
// Anyway... Stolen from: https://github.com/Thracky/GloSC/commit/3cd92e058498e3ab9d73ced140bbd7e490f639a7
// https://github.com/Alia5/GloSC/commit/3cd92e058498e3ab9d73ced140bbd7e490f639a7
// TODO: only return apps for current user.
// TODO: I have no clue how this WinRT shit works; HELP MEH!
// BTW: This config app needs to run as admin, in order to modify steams shortcuts.vdf
// This won't hopefully be a problem fetching UWP apps for a specific user?
PackageManager ^ packageManager = ref new PackageManager();
IIterable<Windows::ApplicationModel::Package ^> ^ packages = packageManager->FindPackages();
int packageCount = 0;
// Only way to get the count of packages is to iterate through the whole collection first
std::for_each(Windows::Foundation::Collections::begin(packages), Windows::Foundation::Collections::end(packages),
[&](Windows::ApplicationModel::Package ^ package) {
packageCount += 1;
});
int currPackage = 0;
// Iterate through all the packages
std::for_each(Windows::Foundation::Collections::begin(packages), Windows::Foundation::Collections::end(packages),
[&](Windows::ApplicationModel::Package ^ package) {
QGuiApplication::processEvents();
HRESULT hr = S_OK;
IStream* inputStream = NULL;
UINT32 pathLen = 0;
IAppxManifestReader* manifestReader = NULL;
IAppxFactory* appxFactory = NULL;
LPWSTR appId = NULL;
LPWSTR manifestAppName = NULL;
LPWSTR iconName = NULL;
// Get the package path on disk so we can load the manifest XML and get the PRAID
GetPackagePathByFullName(package->Id->FullName->Data(), &pathLen, NULL);
if (pathLen > 0) {
// Length of the path + "\\AppxManifest.xml" that we'll be appending
UINT32 manifestLen = pathLen + 20;
PWSTR pathBuf = (PWSTR)malloc(manifestLen * sizeof(wchar_t));
GetPackagePathByFullName(package->Id->FullName->Data(), &pathLen, pathBuf);
PWSTR manifest_xml = L"\\AppxManifest.xml";
hr = StringCchCatW(pathBuf, manifestLen, manifest_xml);
// Let's ignore a bunch of built in apps and such
if (wcsstr(pathBuf, L"SystemApps")) {
hr = E_FAIL;
}
else if (wcsstr(pathBuf, L".NET.Native."))
hr = E_FAIL;
else if (wcsstr(pathBuf, L".VCLibs."))
hr = E_FAIL;
else if (wcsstr(pathBuf, L"Microsoft.UI"))
hr = E_FAIL;
else if (wcsstr(pathBuf, L"Microsoft.Advertising"))
hr = E_FAIL;
else if (wcsstr(pathBuf, L"Microsoft.Services.Store"))
hr = E_FAIL;
BOOL hasCurrent = FALSE;
// Open the manifest XML QProcess proc;
if (SUCCEEDED(hr)) { proc.setProgram("powershell.exe");
QStringList args;
hr = SHCreateStreamOnFileEx( args.push_back(".\\GetAUMIDs.ps1");
pathBuf, proc.setArguments(args);
STGM_READ | STGM_SHARE_EXCLUSIVE, proc.start();
0, // default file attributes proc.waitForFinished(300000000);
FALSE, // do not create new file const auto baseList = QString(proc.readAllStandardOutput()).split(";");
NULL, // no template QVariantList list;
&inputStream); for (const auto& entry : baseList) {
} auto subList = entry.split('|');
if (SUCCEEDED(hr)) { if (subList.size() < 4)
continue;
hr = CoCreateInstance( auto name = QString(subList[0]).replace("\r\n", "");
__uuidof(AppxFactory), if (name == "-Error-")
NULL, continue;
CLSCTX_INPROC_SERVER, qDebug() << "name: " << name << " installDir: " << subList[1] << " logo: " << subList[2] << " aumid: "
__uuidof(IAppxFactory), << subList[3];
(LPVOID*)(&appxFactory)); QVariantMap uwpPair;
} uwpPair.insert("AppName", name);
if (SUCCEEDED(hr)) { uwpPair.insert("Path", subList[1]);
hr = appxFactory->CreateManifestReader(inputStream, &manifestReader); uwpPair.insert("AppUMId", subList[3]);
}
// Grab application ID (PRAID) and DisplayName from the XML QString icoFName = subList[2];
if (SUCCEEDED(hr)) { std::filesystem::path icoPath(icoFName.toStdString());
IAppxManifestApplicationsEnumerator* applications = NULL;
manifestReader->GetApplications(&applications); std::vector<QString> possibleextensions = {".scale-100", ".scale-125", ".scale-150", ".scale-200"};
if (SUCCEEDED(hr)) { if (!std::filesystem::exists(icoPath)) {
hr = applications->GetHasCurrent(&hasCurrent); for (const auto& ext : possibleextensions) {
if (hasCurrent) { QString maybeFname = QString(icoFName).replace(".png", ext + ".png");
IAppxManifestApplication* application = NULL; std::filesystem::path maybePath(maybeFname.toStdString());
hr = applications->GetCurrent(&application); if (std::filesystem::exists(maybePath)) {
if (SUCCEEDED(hr)) { icoPath = maybePath;
application->GetStringValue(L"Id", &appId); break;
application->GetStringValue(L"DisplayName", &manifestAppName); }
for (auto& logoNameStr : logoNames) { }
application->GetStringValue(logoNameStr.c_str(), &iconName); }
if (!std::wstring(iconName).empty()) {
break; uwpPair.insert("IconPath", QString::fromStdString(icoPath.string()));
}
} list.push_back(uwpPair);
application->Release(); }
} return list;
}
else {
hr = S_FALSE;
}
applications->Release();
}
manifestReader->Release();
inputStream->Release();
}
if (SUCCEEDED(hr)) {
PWSTR appNameBuf;
QString AppUMId = QString::fromWCharArray(package->Id->FamilyName->Data());
QString AppName;
QString Path = QString::fromWCharArray(package->EffectivePath->Data());
// QString thumbToken = QString::fromWCharArray(package->GetThumbnailToken()->Data());
if (manifestAppName != NULL) {
// If the display name is an indirect string, we'll try and load it using SHLoadIndirectString
if (wcsstr(manifestAppName, L"ms-resource:")) {
PWSTR res_name = wcsdup(&manifestAppName[12]);
appNameBuf = (PWSTR)malloc(1026);
LPCWSTR resource_str = L"@{";
std::wstring reslookup = std::wstring(resource_str) + package->Id->FullName->Data() + L"?ms-resource://" + package->Id->Name->Data() + L"/resources/" + res_name + L"}";
PCWSTR res_str = reslookup.c_str();
hr = SHLoadIndirectString(res_str, appNameBuf, 512, NULL);
// Try several resource paths
if (!SUCCEEDED(hr)) {
std::wstring reslookup = std::wstring(resource_str) + package->Id->FullName->Data() + L"?ms-resource://" + package->Id->Name->Data() + L"/Resources/" + res_name + L"}";
PCWSTR res_str = reslookup.c_str();
hr = SHLoadIndirectString(res_str, appNameBuf, 512, NULL);
// If the third one doesn't work, we give up and use the package name from PackageManager
if (!SUCCEEDED(hr)) {
std::wstring reslookup = std::wstring(resource_str) + package->Id->FullName->Data() + L"?ms-resource://" + package->Id->Name->Data() + L"/" + res_name + L"}";
PCWSTR res_str = reslookup.c_str();
hr = SHLoadIndirectString(res_str, appNameBuf, 512, NULL);
}
}
if (!SUCCEEDED(hr))
AppName = QString::fromWCharArray(package->DisplayName->Data());
else
AppName = QString::fromWCharArray(appNameBuf);
free(appNameBuf);
}
else {
appNameBuf = manifestAppName;
AppName = QString::fromWCharArray(appNameBuf);
}
}
else {
AppName = QString::fromWCharArray(package->DisplayName->Data());
}
QString PRAID = QString::fromWCharArray(appId);
CoTaskMemFree(appId);
if (!PRAID.isEmpty()) {
AppUMId = AppUMId.append("!");
AppUMId = AppUMId.append(PRAID);
}
QVariantMap uwpPair;
uwpPair.insert("AppName", AppName);
uwpPair.insert("AppUMId", AppUMId);
uwpPair.insert("Path", Path);
QString icoFName = Path + "/" + QString::fromWCharArray(iconName);
std::filesystem::path icoPath(icoFName.toStdString());
std::vector<QString> possibleextensions = {".scale-100", ".scale-125", ".scale-150", ".scale-200"};
if (!std::filesystem::exists(icoPath)) {
for (const auto& ext : possibleextensions) {
QString maybeFname = QString(icoFName).replace(".png", ext + ".png");
std::filesystem::path maybePath(maybeFname.toStdString());
if (std::filesystem::exists(maybePath)) {
icoPath = maybePath;
break;
}
}
}
uwpPair.insert("IconPath", QString::fromStdString(icoPath.string()));
free(pathBuf);
pairs.push_back(uwpPair);
}
}
currPackage += 1;
});
return pairs;
} }
} // namespace UWPFetch } // namespace UWPFetch

@ -110,6 +110,7 @@ int main(int argc, char* argv[])
{ {
#if defined(Q_OS_WIN) #if defined(Q_OS_WIN)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
HRESULT hr = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
#endif #endif
if (argc < 3) { if (argc < 3) {

@ -51,8 +51,8 @@ END
// //
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 0,0,3,105001394320 FILEVERSION 0,0,3,108000010980
PRODUCTVERSION 0,0,3,105001394320 PRODUCTVERSION 0,0,3,108000010980
FILEFLAGSMASK 0x3fL FILEFLAGSMASK 0x3fL
#ifdef _DEBUG #ifdef _DEBUG
FILEFLAGS 0x1L FILEFLAGS 0x1L
@ -69,12 +69,12 @@ BEGIN
BEGIN BEGIN
VALUE "CompanyName", "Peter Repukat - FlatspotSoftware" VALUE "CompanyName", "Peter Repukat - FlatspotSoftware"
VALUE "FileDescription", "GlosSI - SteamTarget" VALUE "FileDescription", "GlosSI - SteamTarget"
VALUE "FileVersion", "0.0.3.1-5-g139432c" VALUE "FileVersion", "0.0.3.1-8-g0b1e98a"
VALUE "InternalName", "GlosSITarget" VALUE "InternalName", "GlosSITarget"
VALUE "LegalCopyright", "Copyright (C) 2021 Peter Repukat - FlatspotSoftware" VALUE "LegalCopyright", "Copyright (C) 2021 Peter Repukat - FlatspotSoftware"
VALUE "OriginalFilename", "GlosSITarget.exe" VALUE "OriginalFilename", "GlosSITarget.exe"
VALUE "ProductName", "GlosSI" VALUE "ProductName", "GlosSI"
VALUE "ProductVersion", "0.0.3.1-5-g139432c" VALUE "ProductVersion", "0.0.3.1-8-g0b1e98a"
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"
@ -639,6 +639,10 @@ END

Loading…
Cancel
Save