code style fixes
This commit is contained in:
parent
7161a2416c
commit
9fa69dbad6
2 changed files with 37 additions and 38 deletions
|
@ -2750,23 +2750,20 @@ void GMainWindow::OnGameListCreateShortcut(u64 program_id, const std::string& ga
|
||||||
target_directory / (program_id == 0 ? fmt::format("yuzu-{}.desktop", game_file_name)
|
target_directory / (program_id == 0 ? fmt::format("yuzu-{}.desktop", game_file_name)
|
||||||
: fmt::format("yuzu-{:016X}.desktop", program_id));
|
: fmt::format("yuzu-{:016X}.desktop", program_id));
|
||||||
#elif defined(WIN32)
|
#elif defined(WIN32)
|
||||||
|
|
||||||
// replace colons, which are illegal in windows filenames, by a dash.
|
// replace colons, which are illegal in windows filenames, by a dash.
|
||||||
for (auto& c : title)
|
std::replace(title.begin(), title.end(), ':', '-');
|
||||||
if (c == ':')
|
|
||||||
c = '-';
|
|
||||||
const std::filesystem::path shortcut_path = target_directory / (title + ".lnk").c_str();
|
const std::filesystem::path shortcut_path = target_directory / (title + ".lnk").c_str();
|
||||||
#else
|
#else
|
||||||
const std::filesystem::path shortcut_path{};
|
const std::filesystem::path shortcut_path{};
|
||||||
#endif
|
#endif
|
||||||
std::filesystem::path icon_path =
|
std::filesystem::path icon_path =
|
||||||
icons_path / ((program_id == 0 ? fmt::format("yuzu-{}", game_file_name)
|
icons_path / ((program_id == 0 ? fmt::format("yuzu-{}", game_file_name)
|
||||||
: fmt::format("yuzu-{:016X}", program_id)) +
|
: fmt::format("yuzu-{:016X}", program_id)) +
|
||||||
icon_extension);
|
icon_extension);
|
||||||
|
|
||||||
// Get icon from game file
|
// Get icon from game file
|
||||||
std::vector<u8> icon_image_file{};
|
std::vector<u8> icon_image_file{};
|
||||||
if (control.second != nullptr) {
|
if (control.second) {
|
||||||
icon_image_file = control.second->ReadAllBytes();
|
icon_image_file = control.second->ReadAllBytes();
|
||||||
} else if (loader->ReadIcon(icon_image_file) != Loader::ResultStatus::Success) {
|
} else if (loader->ReadIcon(icon_image_file) != Loader::ResultStatus::Success) {
|
||||||
LOG_WARNING(Frontend, "Could not read icon from {:s}", game_path);
|
LOG_WARNING(Frontend, "Could not read icon from {:s}", game_path);
|
||||||
|
@ -2775,7 +2772,6 @@ void GMainWindow::OnGameListCreateShortcut(u64 program_id, const std::string& ga
|
||||||
QImage icon_data =
|
QImage icon_data =
|
||||||
QImage::fromData(icon_image_file.data(), static_cast<int>(icon_image_file.size()));
|
QImage::fromData(icon_image_file.data(), static_cast<int>(icon_image_file.size()));
|
||||||
|
|
||||||
|
|
||||||
#if defined(__linux__) || defined(__FreeBSD__)
|
#if defined(__linux__) || defined(__FreeBSD__)
|
||||||
// Convert and write the icon
|
// Convert and write the icon
|
||||||
if (!icon_data.save(QString::fromStdString(icon_path.string()))) {
|
if (!icon_data.save(QString::fromStdString(icon_path.string()))) {
|
||||||
|
@ -3806,17 +3802,18 @@ bool GMainWindow::CreateShortcut(const std::string& shortcut_path, const std::st
|
||||||
return true;
|
return true;
|
||||||
#endif
|
#endif
|
||||||
#if defined(WIN32)
|
#if defined(WIN32)
|
||||||
auto wcommand = std::wstring(command.begin(), command.end());
|
auto wcommand = Common::UTF8ToUTF16W(command);
|
||||||
auto warguments = std::wstring(arguments.begin(), arguments.end());
|
auto warguments = Common::UTF8ToUTF16W(arguments);
|
||||||
auto wcomment = std::wstring(comment.begin(), comment.end());
|
auto wcomment = Common::UTF8ToUTF16W(comment);
|
||||||
auto wshortcut_path = std::wstring(shortcut_path.begin(), shortcut_path.end());
|
auto wshortcut_path = Common::UTF8ToUTF16W(shortcut_path);
|
||||||
auto wicon_path = std::wstring(icon_path.begin(), icon_path.end());
|
auto wicon_path = Common::UTF8ToUTF16W(icon_path);
|
||||||
|
|
||||||
IShellLink* pShellLink;
|
IShellLink* pShellLink;
|
||||||
auto hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink,
|
auto hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink,
|
||||||
(void**)&pShellLink);
|
(void**)&pShellLink);
|
||||||
if (FAILED(hres))
|
if (FAILED(hres)) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
pShellLink->SetPath(wcommand.data()); // Path to the object we are referring to
|
pShellLink->SetPath(wcommand.data()); // Path to the object we are referring to
|
||||||
pShellLink->SetArguments(warguments.data());
|
pShellLink->SetArguments(warguments.data());
|
||||||
pShellLink->SetDescription(wcomment.data());
|
pShellLink->SetDescription(wcomment.data());
|
||||||
|
@ -3824,12 +3821,14 @@ bool GMainWindow::CreateShortcut(const std::string& shortcut_path, const std::st
|
||||||
|
|
||||||
IPersistFile* pPersistFile;
|
IPersistFile* pPersistFile;
|
||||||
hres = pShellLink->QueryInterface(IID_IPersistFile, (void**)&pPersistFile);
|
hres = pShellLink->QueryInterface(IID_IPersistFile, (void**)&pPersistFile);
|
||||||
if (FAILED(hres))
|
if (FAILED(hres)) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
hres = pPersistFile->Save(wshortcut_path.data(), TRUE);
|
hres = pPersistFile->Save(wshortcut_path.data(), TRUE);
|
||||||
if (FAILED(hres))
|
if (FAILED(hres)) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
pPersistFile->Release();
|
pPersistFile->Release();
|
||||||
pShellLink->Release();
|
pShellLink->Release();
|
||||||
|
|
|
@ -5,7 +5,10 @@
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include "yuzu/util/util.h"
|
#include "yuzu/util/util.h"
|
||||||
|
#if defined(WIN32)
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <Windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
QFont GetMonospaceFont() {
|
QFont GetMonospaceFont() {
|
||||||
QFont font(QStringLiteral("monospace"));
|
QFont font(QStringLiteral("monospace"));
|
||||||
|
@ -40,16 +43,14 @@ QPixmap CreateCirclePixmapFromColor(const QColor& color) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(WIN32)
|
#if defined(WIN32)
|
||||||
#include <Windows.h>
|
|
||||||
|
|
||||||
#pragma pack(push, 2)
|
#pragma pack(push, 2)
|
||||||
struct ICONDIR {
|
struct IconDir {
|
||||||
WORD idReserved;
|
WORD id_reserved;
|
||||||
WORD idType;
|
WORD id_type;
|
||||||
WORD idCount;
|
WORD id_count;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ICONDIRENTRY {
|
struct IconDirEntry {
|
||||||
BYTE bWidth;
|
BYTE bWidth;
|
||||||
BYTE bHeight;
|
BYTE bHeight;
|
||||||
BYTE bColorCount;
|
BYTE bColorCount;
|
||||||
|
@ -59,7 +60,6 @@ struct ICONDIRENTRY {
|
||||||
DWORD dwBytesInRes;
|
DWORD dwBytesInRes;
|
||||||
DWORD dwImageOffset;
|
DWORD dwImageOffset;
|
||||||
};
|
};
|
||||||
|
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
bool SaveIconToFile(const char* path, QImage image) {
|
bool SaveIconToFile(const char* path, QImage image) {
|
||||||
|
@ -74,37 +74,37 @@ bool SaveIconToFile(const char* path, QImage image) {
|
||||||
bmih.biWidth = sourceImage.width();
|
bmih.biWidth = sourceImage.width();
|
||||||
bmih.biHeight = sourceImage.height() * 2;
|
bmih.biHeight = sourceImage.height() * 2;
|
||||||
bmih.biPlanes = 1;
|
bmih.biPlanes = 1;
|
||||||
bmih.biBitCount = 32;
|
bmih.biBitCount = bytesPerPixel * 8;
|
||||||
bmih.biCompression = BI_RGB;
|
bmih.biCompression = BI_RGB;
|
||||||
|
|
||||||
// Create an ICO header
|
// Create an ICO header
|
||||||
ICONDIR iconDir;
|
IconDir iconDir;
|
||||||
iconDir.idReserved = 0;
|
iconDir.id_reserved = 0;
|
||||||
iconDir.idType = 1;
|
iconDir.id_type = 1;
|
||||||
iconDir.idCount = 1;
|
iconDir.id_count = 1;
|
||||||
|
|
||||||
// Create an ICONDIRENTRY
|
// Create an ICONDIRENTRY
|
||||||
ICONDIRENTRY iconEntry;
|
IconDirEntry iconEntry;
|
||||||
iconEntry.bWidth = sourceImage.width();
|
iconEntry.bWidth = sourceImage.width();
|
||||||
iconEntry.bHeight = sourceImage.height() * 2;
|
iconEntry.bHeight = sourceImage.height() * 2;
|
||||||
iconEntry.bColorCount = 0;
|
iconEntry.bColorCount = 0;
|
||||||
iconEntry.bReserved = 0;
|
iconEntry.bReserved = 0;
|
||||||
iconEntry.wPlanes = 1;
|
iconEntry.wPlanes = 1;
|
||||||
iconEntry.wBitCount = 32;
|
iconEntry.wBitCount = bytesPerPixel * 8;
|
||||||
iconEntry.dwBytesInRes = sizeof(BITMAPINFOHEADER) + imageSize;
|
iconEntry.dwBytesInRes = sizeof(BITMAPINFOHEADER) + imageSize;
|
||||||
iconEntry.dwImageOffset = sizeof(ICONDIR) + sizeof(ICONDIRENTRY);
|
iconEntry.dwImageOffset = sizeof(IconDir) + sizeof(IconDirEntry);
|
||||||
|
|
||||||
// Save the icon data to a file
|
// Save the icon data to a file
|
||||||
std::ofstream iconFile(path, std::ios::binary);
|
std::ofstream iconFile(path, std::ios::binary);
|
||||||
if (iconFile.fail())
|
if (iconFile.fail())
|
||||||
return false;
|
return false;
|
||||||
iconFile.write(reinterpret_cast<const char*>(&iconDir), sizeof(ICONDIR));
|
iconFile.write(reinterpret_cast<const char*>(&iconDir), sizeof(IconDir));
|
||||||
iconFile.write(reinterpret_cast<const char*>(&iconEntry), sizeof(ICONDIRENTRY));
|
iconFile.write(reinterpret_cast<const char*>(&iconEntry), sizeof(IconDirEntry));
|
||||||
iconFile.write(reinterpret_cast<const char*>(&bmih), sizeof(BITMAPINFOHEADER));
|
iconFile.write(reinterpret_cast<const char*>(&bmih), sizeof(BITMAPINFOHEADER));
|
||||||
|
|
||||||
for (int y = 0; y < image.height(); y++) {
|
for (int y = 0; y < image.height(); y++) {
|
||||||
auto line = (char*)sourceImage.scanLine(sourceImage.height() - 1 - y);
|
auto line = reinterpret_cast<const char*>(sourceImage.scanLine(sourceImage.height() - 1 - y));
|
||||||
iconFile.write(line, sourceImage.width() * 4);
|
iconFile.write(line, sourceImage.width() * bytesPerPixel);
|
||||||
}
|
}
|
||||||
|
|
||||||
iconFile.close();
|
iconFile.close();
|
||||||
|
@ -115,4 +115,4 @@ bool SaveIconToFile(const char* path, QImage image) {
|
||||||
bool SaveAsIco(QImage image) {
|
bool SaveAsIco(QImage image) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue