Show icon for autoplay in control panel and modify test app (#197)
* Show icon for autoplay in control panel and modify test app * Remove commented method
This commit is contained in:
Родитель
65c2322b4e
Коммит
ba913d8ffc
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:bc838717529809a5ac5eefed213205b89e7c51b1ae03cdb0b23670c87c24888a
|
||||
size 3112115
|
||||
oid sha256:7bb0c5a3f3c3e720c1b5091975bd5b8d4ccf2a834e5dd5b8771ab0a6f35dc642
|
||||
size 3112113
|
||||
|
|
|
@ -198,7 +198,11 @@ HRESULT AutoPlay::ParseManifest()
|
|||
autoPlay.appUserModelId = m_msixRequest->GetPackageInfo()->GetId();
|
||||
|
||||
//get the logo
|
||||
autoPlay.defaultIcon = m_msixRequest->GetPackageInfo()->GetPackageDirectoryPath() + m_msixRequest->GetPackageInfo()->GetRelativeLogoPath();
|
||||
std::wstring logoPath = m_msixRequest->GetPackageInfo()->GetPackageDirectoryPath() + m_msixRequest->GetPackageInfo()->GetRelativeLogoPath();
|
||||
std::wstring iconPath;
|
||||
|
||||
RETURN_IF_FAILED(ConvertLogoToIcon(logoPath, iconPath));
|
||||
autoPlay.defaultIcon = iconPath.c_str();
|
||||
|
||||
//verb
|
||||
Text<wchar_t> id;
|
||||
|
@ -279,7 +283,11 @@ HRESULT AutoPlay::ParseManifest()
|
|||
autoPlay.appUserModelId = m_msixRequest->GetPackageInfo()->GetId();
|
||||
|
||||
//get the logo
|
||||
autoPlay.defaultIcon = m_msixRequest->GetPackageInfo()->GetPackageDirectoryPath() + m_msixRequest->GetPackageInfo()->GetRelativeLogoPath();
|
||||
std::wstring logoPath = m_msixRequest->GetPackageInfo()->GetPackageDirectoryPath() + m_msixRequest->GetPackageInfo()->GetRelativeLogoPath();
|
||||
std::wstring iconPath;
|
||||
|
||||
RETURN_IF_FAILED(ConvertLogoToIcon(logoPath, iconPath));
|
||||
autoPlay.defaultIcon = iconPath.c_str();
|
||||
|
||||
//handle event
|
||||
Text<wchar_t> handleEvent;
|
||||
|
|
|
@ -10,15 +10,7 @@
|
|||
#include <TraceLoggingProvider.h>
|
||||
#include "RegistryKey.hpp"
|
||||
#include "MsixTraceLoggingProvider.hpp"
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
|
||||
// MSIXWindows.hpp defines NOMINMAX and undefines min and max because we want to use std::min/std::max from <algorithm>
|
||||
// GdiPlus.h requires a definiton for min and max. We can't use namespace std because c++17 defines std::byte, which conflicts with ::byte
|
||||
#define max std::max
|
||||
#define min std::min
|
||||
#include <GdiPlus.h>
|
||||
using namespace std;
|
||||
using namespace MsixCoreLib;
|
||||
|
||||
const PCWSTR FileTypeAssociation::HandlerName = L"FileTypeAssociation";
|
||||
|
@ -163,54 +155,6 @@ HRESULT FileTypeAssociation::ExecuteForAddRequest()
|
|||
return S_OK;
|
||||
}
|
||||
|
||||
/// Creates an .ico file next to the logo path which is .png by simply prepending the ICO header.
|
||||
HRESULT ConvertLogoToIcon(std::wstring logoPath, std::wstring & iconPath)
|
||||
{
|
||||
experimental::filesystem::path path(logoPath);
|
||||
iconPath = path.replace_extension(L".ico");
|
||||
|
||||
bool fileExists = false;
|
||||
RETURN_IF_FAILED(FileExists(iconPath, fileExists));
|
||||
if (fileExists)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
uintmax_t size = experimental::filesystem::file_size(logoPath);
|
||||
ifstream input(logoPath, std::ios::binary);
|
||||
ofstream output(iconPath, std::ios::binary);
|
||||
|
||||
Gdiplus::Image image(logoPath.c_str());
|
||||
|
||||
//See https://en.wikipedia.org/wiki/ICO_(file_format)
|
||||
BYTE iconHeader[] = {
|
||||
0,0, // reserved
|
||||
1,0, // 1 for .ico icon
|
||||
1,0, // 1 image in file
|
||||
static_cast<BYTE>(image.GetWidth()), // width
|
||||
static_cast<BYTE>(image.GetHeight()), // height
|
||||
0, // colors in color palette
|
||||
0, // reserved
|
||||
1,0, // color planes
|
||||
32,0, // bits per pixel
|
||||
0,0,0,0, // size of image in bytes
|
||||
0,0,0,0 }; // offset from start of file of actual image
|
||||
|
||||
// fill in size
|
||||
iconHeader[14] = static_cast<BYTE>(size % 256);
|
||||
iconHeader[15] = static_cast<BYTE>(size / 256);
|
||||
|
||||
// fill in offset from start of file, which is the size of this header
|
||||
iconHeader[18] = static_cast<BYTE>(ARRAYSIZE(iconHeader));
|
||||
|
||||
for (int i = 0; i < ARRAYSIZE(iconHeader); i++)
|
||||
{
|
||||
output << iconHeader[i];
|
||||
}
|
||||
output << input.rdbuf();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT FileTypeAssociation::ProcessFtaForAdd(Fta& fta)
|
||||
{
|
||||
bool needToProcessAnyExtensions = false;
|
||||
|
|
|
@ -5,7 +5,19 @@
|
|||
#include <iostream>
|
||||
#include <sddl.h>
|
||||
#include <memory>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
|
||||
// MSIXWindows.hpp defines NOMINMAX and undefines min and max because we want to use std::min/std::max from <algorithm>
|
||||
// GdiPlus.h requires a definiton for min and max. We can't use namespace std because c++17 defines std::byte, which conflicts with ::byte
|
||||
#define max std::max
|
||||
#define min std::min
|
||||
#include <GdiPlus.h>
|
||||
|
||||
#pragma warning(disable : 4996)
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace MsixCoreLib
|
||||
{
|
||||
std::string utf16_to_utf8(const std::wstring& utf16string)
|
||||
|
@ -80,6 +92,54 @@ namespace MsixCoreLib
|
|||
return S_OK;
|
||||
}
|
||||
|
||||
/// Creates an .ico file next to the logo path which is .png by simply prepending the ICO header.
|
||||
HRESULT ConvertLogoToIcon(std::wstring logoPath, std::wstring & iconPath)
|
||||
{
|
||||
experimental::filesystem::path path(logoPath);
|
||||
iconPath = path.replace_extension(L".ico");
|
||||
|
||||
bool fileExists = false;
|
||||
RETURN_IF_FAILED(FileExists(iconPath, fileExists));
|
||||
if (fileExists)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
uintmax_t size = experimental::filesystem::file_size(logoPath);
|
||||
ifstream input(logoPath, std::ios::binary);
|
||||
ofstream output(iconPath, std::ios::binary);
|
||||
|
||||
Gdiplus::Image image(logoPath.c_str());
|
||||
|
||||
//See https://en.wikipedia.org/wiki/ICO_(file_format)
|
||||
BYTE iconHeader[] = {
|
||||
0,0, // reserved
|
||||
1,0, // 1 for .ico icon
|
||||
1,0, // 1 image in file
|
||||
static_cast<BYTE>(image.GetWidth()), // width
|
||||
static_cast<BYTE>(image.GetHeight()), // height
|
||||
0, // colors in color palette
|
||||
0, // reserved
|
||||
1,0, // color planes
|
||||
32,0, // bits per pixel
|
||||
0,0,0,0, // size of image in bytes
|
||||
0,0,0,0 }; // offset from start of file of actual image
|
||||
|
||||
// fill in size
|
||||
iconHeader[14] = static_cast<BYTE>(size % 256);
|
||||
iconHeader[15] = static_cast<BYTE>(size / 256);
|
||||
|
||||
// fill in offset from start of file, which is the size of this header
|
||||
iconHeader[18] = static_cast<BYTE>(ARRAYSIZE(iconHeader));
|
||||
|
||||
for (int i = 0; i < ARRAYSIZE(iconHeader); i++)
|
||||
{
|
||||
output << iconHeader[i];
|
||||
}
|
||||
output << input.rdbuf();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT GetCurrentUserSidString(std::wstring & userSidString)
|
||||
{
|
||||
HANDLE token;
|
||||
|
|
|
@ -247,6 +247,8 @@ namespace MsixCoreLib
|
|||
|
||||
HRESULT FileExists(std::wstring file, _Out_ bool &exists);
|
||||
|
||||
HRESULT ConvertLogoToIcon(std::wstring logoPath, std::wstring & iconPath);
|
||||
|
||||
class AutoCoInitialize
|
||||
{
|
||||
public:
|
||||
|
|
Загрузка…
Ссылка в новой задаче