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