2013-03-10 22:08:57 +00:00
|
|
|
// Copyright (c) 2012- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
2017-02-24 17:59:41 +00:00
|
|
|
#include "ppsspp_config.h"
|
|
|
|
|
2013-08-12 21:26:01 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2013-08-26 17:00:16 +00:00
|
|
|
// For shell links
|
2021-02-14 18:02:28 +00:00
|
|
|
#include "Common/CommonWindows.h"
|
2013-08-26 17:00:16 +00:00
|
|
|
#include "winnls.h"
|
|
|
|
#include "shobjidl.h"
|
|
|
|
#include "objbase.h"
|
|
|
|
#include "objidl.h"
|
|
|
|
#include "shlguid.h"
|
2017-01-16 12:08:26 +00:00
|
|
|
#pragma warning(push)
|
2015-09-17 20:02:15 +00:00
|
|
|
#pragma warning(disable:4091) // workaround bug in VS2015 headers
|
2013-08-26 17:00:16 +00:00
|
|
|
#include "shlobj.h"
|
2017-01-16 12:08:26 +00:00
|
|
|
#pragma warning(pop)
|
2013-08-26 17:00:16 +00:00
|
|
|
|
|
|
|
// native stuff
|
2020-10-04 08:10:55 +00:00
|
|
|
#include "Common/System/Display.h"
|
2020-10-04 08:30:18 +00:00
|
|
|
#include "Common/System/NativeApp.h"
|
2020-10-01 07:36:43 +00:00
|
|
|
#include "Common/Input/InputState.h"
|
|
|
|
#include "Common/Input/KeyCodes.h"
|
2020-10-01 11:05:04 +00:00
|
|
|
#include "Common/Data/Encoding/Utf8.h"
|
2020-10-04 18:48:47 +00:00
|
|
|
#include "Common/File/DirListing.h"
|
2016-05-28 05:00:14 +00:00
|
|
|
#include "Common/StringUtils.h"
|
2020-10-04 18:48:47 +00:00
|
|
|
|
2013-01-29 20:38:05 +00:00
|
|
|
#include "Core/Core.h"
|
|
|
|
#include "Core/Config.h"
|
2018-06-17 01:42:31 +00:00
|
|
|
#include "Core/ConfigValues.h"
|
2013-03-29 21:56:57 +00:00
|
|
|
#include "Core/CoreParameter.h"
|
2013-05-04 21:21:06 +00:00
|
|
|
#include "Core/System.h"
|
2016-05-28 05:00:14 +00:00
|
|
|
#include "Core/Debugger/SymbolMap.h"
|
2020-07-20 09:38:39 +00:00
|
|
|
#include "Core/Instance.h"
|
|
|
|
|
2015-09-19 11:14:05 +00:00
|
|
|
#include "Windows/EmuThread.h"
|
2017-06-27 09:46:10 +00:00
|
|
|
#include "Windows/WindowsAudio.h"
|
2015-09-19 11:14:05 +00:00
|
|
|
#include "Windows/WindowsHost.h"
|
|
|
|
#include "Windows/MainWindow.h"
|
2017-02-24 17:59:41 +00:00
|
|
|
|
2019-05-10 21:25:57 +00:00
|
|
|
#if PPSSPP_API(ANY_GL)
|
2015-11-03 22:22:09 +00:00
|
|
|
#include "Windows/GPU/WindowsGLContext.h"
|
2019-05-03 22:06:50 +00:00
|
|
|
#endif
|
2015-10-10 14:41:19 +00:00
|
|
|
#include "Windows/GPU/WindowsVulkanContext.h"
|
2015-11-03 22:22:09 +00:00
|
|
|
#include "Windows/GPU/D3D9Context.h"
|
2016-12-23 08:58:15 +00:00
|
|
|
#include "Windows/GPU/D3D11Context.h"
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2013-07-03 05:59:47 +00:00
|
|
|
#include "Windows/Debugger/DebuggerShared.h"
|
|
|
|
#include "Windows/Debugger/Debugger_Disasm.h"
|
|
|
|
#include "Windows/Debugger/Debugger_MemoryDlg.h"
|
2013-07-06 17:08:59 +00:00
|
|
|
|
2019-05-03 22:06:50 +00:00
|
|
|
#ifndef _M_ARM
|
2013-07-06 17:08:59 +00:00
|
|
|
#include "Windows/DinputDevice.h"
|
2019-05-03 22:06:50 +00:00
|
|
|
#endif
|
2013-07-06 17:08:59 +00:00
|
|
|
#include "Windows/XinputDevice.h"
|
|
|
|
|
2015-09-19 11:14:05 +00:00
|
|
|
#include "Windows/main.h"
|
2016-05-28 05:00:14 +00:00
|
|
|
#include "UI/OnScreenDisplay.h"
|
2022-12-05 12:14:14 +00:00
|
|
|
#include <Core/HLE/Plugins.h>
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2017-01-16 12:08:26 +00:00
|
|
|
float g_mouseDeltaX = 0;
|
|
|
|
float g_mouseDeltaY = 0;
|
2013-08-12 21:26:01 +00:00
|
|
|
|
2015-12-31 15:59:40 +00:00
|
|
|
static BOOL PostDialogMessage(Dialog *dialog, UINT message, WPARAM wParam = 0, LPARAM lParam = 0) {
|
2013-07-03 05:59:47 +00:00
|
|
|
return PostMessage(dialog->GetDlgHandle(), message, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
2015-12-31 15:59:40 +00:00
|
|
|
WindowsHost::WindowsHost(HINSTANCE hInstance, HWND mainWindow, HWND displayWindow)
|
2018-10-09 04:21:37 +00:00
|
|
|
: hInstance_(hInstance),
|
2021-02-15 18:29:34 +00:00
|
|
|
displayWindow_(displayWindow),
|
|
|
|
mainWindow_(mainWindow)
|
2014-06-29 20:13:53 +00:00
|
|
|
{
|
2017-01-16 12:08:26 +00:00
|
|
|
g_mouseDeltaX = 0;
|
|
|
|
g_mouseDeltaY = 0;
|
2013-07-06 17:08:59 +00:00
|
|
|
|
2014-05-30 19:32:25 +00:00
|
|
|
//add first XInput device to respond
|
2019-06-28 22:55:45 +00:00
|
|
|
input.push_back(std::make_unique<XinputDevice>());
|
2019-05-03 22:06:50 +00:00
|
|
|
#ifndef _M_ARM
|
2014-05-30 19:32:25 +00:00
|
|
|
//find all connected DInput devices of class GamePad
|
2018-10-09 04:21:37 +00:00
|
|
|
numDinputDevices_ = DinputDevice::getNumPads();
|
|
|
|
for (size_t i = 0; i < numDinputDevices_; i++) {
|
2019-06-28 22:55:45 +00:00
|
|
|
input.push_back(std::make_unique<DinputDevice>(static_cast<int>(i)));
|
2014-05-30 19:32:25 +00:00
|
|
|
}
|
2019-05-03 22:06:50 +00:00
|
|
|
#endif
|
2013-07-06 17:08:59 +00:00
|
|
|
SetConsolePosition();
|
|
|
|
}
|
|
|
|
|
2015-09-19 12:28:43 +00:00
|
|
|
void WindowsHost::SetConsolePosition() {
|
|
|
|
HWND console = GetConsoleWindow();
|
2020-07-20 09:38:39 +00:00
|
|
|
if (console != NULL && g_Config.iConsoleWindowX != -1 && g_Config.iConsoleWindowY != -1) {
|
2015-09-19 12:28:43 +00:00
|
|
|
SetWindowPos(console, NULL, g_Config.iConsoleWindowX, g_Config.iConsoleWindowY, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
|
2020-07-20 09:38:39 +00:00
|
|
|
}
|
2015-09-19 12:28:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WindowsHost::UpdateConsolePosition() {
|
|
|
|
RECT rc;
|
|
|
|
HWND console = GetConsoleWindow();
|
2015-12-31 15:59:40 +00:00
|
|
|
if (console != NULL && GetWindowRect(console, &rc) && !IsIconic(console)) {
|
2015-09-19 12:28:43 +00:00
|
|
|
g_Config.iConsoleWindowX = rc.left;
|
|
|
|
g_Config.iConsoleWindowY = rc.top;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-31 15:59:40 +00:00
|
|
|
bool WindowsHost::InitGraphics(std::string *error_message, GraphicsContext **ctx) {
|
|
|
|
WindowsGraphicsContext *graphicsContext = nullptr;
|
2014-08-17 14:07:14 +00:00
|
|
|
switch (g_Config.iGPUBackend) {
|
2019-05-10 21:25:57 +00:00
|
|
|
#if PPSSPP_API(ANY_GL)
|
2017-12-26 23:55:24 +00:00
|
|
|
case (int)GPUBackend::OPENGL:
|
2015-12-31 15:59:40 +00:00
|
|
|
graphicsContext = new WindowsGLContext();
|
|
|
|
break;
|
2019-05-03 22:06:50 +00:00
|
|
|
#endif
|
2017-12-26 23:55:24 +00:00
|
|
|
case (int)GPUBackend::DIRECT3D9:
|
2015-12-31 15:59:40 +00:00
|
|
|
graphicsContext = new D3D9Context();
|
|
|
|
break;
|
2017-12-26 23:55:24 +00:00
|
|
|
case (int)GPUBackend::DIRECT3D11:
|
2016-12-23 08:58:15 +00:00
|
|
|
graphicsContext = new D3D11Context();
|
|
|
|
break;
|
2017-12-26 23:55:24 +00:00
|
|
|
case (int)GPUBackend::VULKAN:
|
2016-03-13 18:23:46 +00:00
|
|
|
graphicsContext = new WindowsVulkanContext();
|
|
|
|
break;
|
2014-08-17 14:07:14 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2015-12-31 15:59:40 +00:00
|
|
|
|
|
|
|
if (graphicsContext->Init(hInstance_, displayWindow_, error_message)) {
|
|
|
|
*ctx = graphicsContext;
|
|
|
|
gfx_ = graphicsContext;
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
delete graphicsContext;
|
|
|
|
*ctx = nullptr;
|
|
|
|
gfx_ = nullptr;
|
|
|
|
return false;
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2014-09-20 19:55:58 +00:00
|
|
|
void WindowsHost::ShutdownGraphics() {
|
2015-12-31 15:59:40 +00:00
|
|
|
gfx_->Shutdown();
|
|
|
|
delete gfx_;
|
|
|
|
gfx_ = nullptr;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2015-09-19 12:28:43 +00:00
|
|
|
void WindowsHost::SetWindowTitle(const char *message) {
|
2017-03-17 10:55:14 +00:00
|
|
|
#ifdef GOLD
|
|
|
|
const char *name = "PPSSPP Gold ";
|
2017-03-17 18:55:17 +00:00
|
|
|
#else
|
|
|
|
const char *name = "PPSSPP ";
|
2017-03-17 10:55:14 +00:00
|
|
|
#endif
|
|
|
|
std::wstring winTitle = ConvertUTF8ToWString(std::string(name) + PPSSPP_GIT_VERSION);
|
2014-06-22 12:17:57 +00:00
|
|
|
if (message != nullptr) {
|
2013-09-13 19:17:55 +00:00
|
|
|
winTitle.append(ConvertUTF8ToWString(" - "));
|
|
|
|
winTitle.append(ConvertUTF8ToWString(message));
|
2012-12-03 15:44:29 +00:00
|
|
|
}
|
2017-11-13 09:09:44 +00:00
|
|
|
#ifdef _DEBUG
|
|
|
|
winTitle.append(L" (debug)");
|
|
|
|
#endif
|
2020-08-18 08:07:12 +00:00
|
|
|
lastTitle_ = winTitle;
|
2012-12-03 15:44:29 +00:00
|
|
|
|
2013-09-13 19:17:55 +00:00
|
|
|
MainWindow::SetWindowTitle(winTitle.c_str());
|
2014-06-29 20:13:53 +00:00
|
|
|
PostMessage(mainWindow_, MainWindow::WM_USER_WINDOW_TITLE_CHANGED, 0, 0);
|
2012-11-30 20:49:59 +00:00
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2015-09-19 12:28:43 +00:00
|
|
|
void WindowsHost::InitSound() {
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2015-01-11 20:00:56 +00:00
|
|
|
// UGLY!
|
|
|
|
extern WindowsAudioBackend *winAudioBackend;
|
|
|
|
|
2015-09-19 12:28:43 +00:00
|
|
|
void WindowsHost::UpdateSound() {
|
2015-01-11 20:00:56 +00:00
|
|
|
if (winAudioBackend)
|
|
|
|
winAudioBackend->Update();
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2015-09-19 12:28:43 +00:00
|
|
|
void WindowsHost::ShutdownSound() {
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2015-09-19 12:28:43 +00:00
|
|
|
void WindowsHost::UpdateUI() {
|
2014-06-29 20:13:53 +00:00
|
|
|
PostMessage(mainWindow_, MainWindow::WM_USER_UPDATE_UI, 0, 0);
|
2020-08-18 08:07:12 +00:00
|
|
|
|
|
|
|
int peers = GetInstancePeerCount();
|
|
|
|
if (PPSSPP_ID >= 1 && peers != lastNumInstances_) {
|
|
|
|
lastNumInstances_ = peers;
|
|
|
|
PostMessage(mainWindow_, MainWindow::WM_USER_WINDOW_TITLE_CHANGED, 0, 0);
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2015-09-19 12:28:43 +00:00
|
|
|
void WindowsHost::UpdateMemView() {
|
2020-09-23 22:17:31 +00:00
|
|
|
if (memoryWindow)
|
|
|
|
PostDialogMessage(memoryWindow, WM_DEB_UPDATE);
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2015-09-19 12:28:43 +00:00
|
|
|
void WindowsHost::UpdateDisassembly() {
|
2020-09-23 22:17:31 +00:00
|
|
|
if (disasmWindow)
|
|
|
|
PostDialogMessage(disasmWindow, WM_DEB_UPDATE);
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2015-09-19 12:28:43 +00:00
|
|
|
void WindowsHost::SetDebugMode(bool mode) {
|
2020-09-23 22:17:31 +00:00
|
|
|
if (disasmWindow)
|
|
|
|
PostDialogMessage(disasmWindow, WM_DEB_SETDEBUGLPARAM, 0, (LPARAM)mode);
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2017-03-15 05:01:18 +00:00
|
|
|
void WindowsHost::PollControllers() {
|
2018-10-09 04:21:37 +00:00
|
|
|
static int checkCounter = 0;
|
|
|
|
static const int CHECK_FREQUENCY = 71;
|
|
|
|
if (checkCounter++ > CHECK_FREQUENCY) {
|
2019-05-03 22:06:50 +00:00
|
|
|
#ifndef _M_ARM
|
2018-10-09 04:21:37 +00:00
|
|
|
size_t newCount = DinputDevice::getNumPads();
|
|
|
|
if (newCount > numDinputDevices_) {
|
|
|
|
INFO_LOG(SYSTEM, "New controller device detected");
|
|
|
|
for (size_t i = numDinputDevices_; i < newCount; i++) {
|
2019-06-28 22:55:45 +00:00
|
|
|
input.push_back(std::make_unique<DinputDevice>(static_cast<int>(i)));
|
2018-10-09 04:21:37 +00:00
|
|
|
}
|
|
|
|
numDinputDevices_ = newCount;
|
|
|
|
}
|
2019-05-03 22:06:50 +00:00
|
|
|
#endif
|
2018-10-09 04:21:37 +00:00
|
|
|
checkCounter = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto &device : input) {
|
2017-03-15 05:01:18 +00:00
|
|
|
if (device->UpdateState() == InputDevice::UPDATESTATE_SKIP_PAD)
|
2019-06-28 22:55:45 +00:00
|
|
|
break;
|
2013-04-08 01:41:26 +00:00
|
|
|
}
|
2013-08-12 21:26:01 +00:00
|
|
|
|
2017-04-26 14:48:55 +00:00
|
|
|
// Disabled by default, needs a workaround to map to psp keys.
|
2018-10-09 04:21:37 +00:00
|
|
|
if (g_Config.bMouseControl) {
|
2023-02-25 12:09:44 +00:00
|
|
|
float scaleFactor_x = g_display.dpi_scale_x * 0.1 * g_Config.fMouseSensitivity;
|
|
|
|
float scaleFactor_y = g_display.dpi_scale_y * 0.1 * g_Config.fMouseSensitivity;
|
2018-10-09 04:21:37 +00:00
|
|
|
|
|
|
|
float mx = std::max(-1.0f, std::min(1.0f, g_mouseDeltaX * scaleFactor_x));
|
|
|
|
float my = std::max(-1.0f, std::min(1.0f, g_mouseDeltaY * scaleFactor_y));
|
|
|
|
AxisInput axisX, axisY;
|
|
|
|
axisX.axisId = JOYSTICK_AXIS_MOUSE_REL_X;
|
|
|
|
axisX.deviceId = DEVICE_ID_MOUSE;
|
|
|
|
axisX.value = mx;
|
|
|
|
axisY.axisId = JOYSTICK_AXIS_MOUSE_REL_Y;
|
|
|
|
axisY.deviceId = DEVICE_ID_MOUSE;
|
|
|
|
axisY.value = my;
|
|
|
|
|
2017-04-26 14:48:55 +00:00
|
|
|
if (GetUIState() == UISTATE_INGAME || g_Config.bMapMouse) {
|
2019-07-15 00:45:08 +00:00
|
|
|
NativeAxis(axisX);
|
|
|
|
NativeAxis(axisY);
|
2017-04-26 14:48:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_mouseDeltaX *= g_Config.fMouseSmoothing;
|
|
|
|
g_mouseDeltaY *= g_Config.fMouseSmoothing;
|
2022-12-05 12:14:14 +00:00
|
|
|
|
|
|
|
HLEPlugins::PluginDataAxis[JOYSTICK_AXIS_MOUSE_REL_X] = g_mouseDeltaX;
|
|
|
|
HLEPlugins::PluginDataAxis[JOYSTICK_AXIS_MOUSE_REL_Y] = g_mouseDeltaY;
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2015-09-19 12:28:43 +00:00
|
|
|
void WindowsHost::BootDone() {
|
2021-02-05 05:43:19 +00:00
|
|
|
if (g_symbolMap)
|
|
|
|
g_symbolMap->SortSymbols();
|
2017-05-27 08:41:31 +00:00
|
|
|
PostMessage(mainWindow_, WM_USER + 1, 0, 0);
|
2013-04-05 07:57:43 +00:00
|
|
|
|
|
|
|
SetDebugMode(!g_Config.bAutoRun);
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2021-05-15 05:48:32 +00:00
|
|
|
static Path SymbolMapFilename(const Path ¤tFilename, const char *ext) {
|
2022-12-11 05:09:50 +00:00
|
|
|
File::FileInfo info{};
|
2013-07-29 11:06:01 +00:00
|
|
|
// can't fail, definitely exists if it gets this far
|
2021-05-15 05:48:32 +00:00
|
|
|
File::GetFileInfo(currentFilename, &info);
|
2015-09-19 12:28:43 +00:00
|
|
|
if (info.isDirectory) {
|
2021-05-15 05:48:32 +00:00
|
|
|
return currentFilename / (std::string(".ppsspp-symbols") + ext);
|
2013-07-29 11:06:01 +00:00
|
|
|
}
|
2021-05-15 05:48:32 +00:00
|
|
|
return currentFilename.WithReplacedExtension(ext);
|
2013-01-19 22:05:46 +00:00
|
|
|
}
|
|
|
|
|
2015-09-19 12:28:43 +00:00
|
|
|
bool WindowsHost::AttemptLoadSymbolMap() {
|
2021-02-05 05:43:19 +00:00
|
|
|
if (!g_symbolMap)
|
|
|
|
return false;
|
2021-05-15 05:48:32 +00:00
|
|
|
bool result1 = g_symbolMap->LoadSymbolMap(SymbolMapFilename(PSP_CoreParameter().fileToStart, ".ppmap"));
|
2014-01-26 05:12:16 +00:00
|
|
|
// Load the old-style map file.
|
|
|
|
if (!result1)
|
2021-05-15 05:48:32 +00:00
|
|
|
result1 = g_symbolMap->LoadSymbolMap(SymbolMapFilename(PSP_CoreParameter().fileToStart, ".map"));
|
|
|
|
bool result2 = g_symbolMap->LoadNocashSym(SymbolMapFilename(PSP_CoreParameter().fileToStart, ".sym"));
|
2013-07-29 11:06:01 +00:00
|
|
|
return result1 || result2;
|
2013-03-31 04:42:43 +00:00
|
|
|
}
|
|
|
|
|
2015-09-19 12:28:43 +00:00
|
|
|
void WindowsHost::SaveSymbolMap() {
|
2021-02-05 05:43:19 +00:00
|
|
|
if (g_symbolMap)
|
2021-05-15 05:48:32 +00:00
|
|
|
g_symbolMap->SaveSymbolMap(SymbolMapFilename(PSP_CoreParameter().fileToStart, ".ppmap"));
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2020-09-12 11:45:25 +00:00
|
|
|
void WindowsHost::NotifySymbolMapUpdated() {
|
2021-02-05 05:43:19 +00:00
|
|
|
if (g_symbolMap)
|
|
|
|
g_symbolMap->SortSymbols();
|
2020-09-12 11:45:25 +00:00
|
|
|
PostMessage(mainWindow_, WM_USER + 1, 0, 0);
|
|
|
|
}
|
|
|
|
|
2015-09-19 12:28:43 +00:00
|
|
|
bool WindowsHost::IsDebuggingEnabled() {
|
2012-11-01 15:19:01 +00:00
|
|
|
#ifdef _DEBUG
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
2013-06-26 07:32:49 +00:00
|
|
|
|
2013-08-26 17:00:16 +00:00
|
|
|
// http://msdn.microsoft.com/en-us/library/aa969393.aspx
|
|
|
|
HRESULT CreateLink(LPCWSTR lpszPathObj, LPCWSTR lpszArguments, LPCWSTR lpszPathLink, LPCWSTR lpszDesc) {
|
|
|
|
HRESULT hres;
|
2022-12-11 05:09:50 +00:00
|
|
|
IShellLink *psl = nullptr;
|
|
|
|
hres = CoInitializeEx(NULL, COINIT_MULTITHREADED);
|
|
|
|
if (FAILED(hres))
|
|
|
|
return hres;
|
2013-08-26 17:00:16 +00:00
|
|
|
|
|
|
|
// Get a pointer to the IShellLink interface. It is assumed that CoInitialize
|
|
|
|
// has already been called.
|
|
|
|
hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (LPVOID*)&psl);
|
2022-12-11 05:09:50 +00:00
|
|
|
if (SUCCEEDED(hres) && psl) {
|
|
|
|
IPersistFile *ppf = nullptr;
|
2013-08-26 17:00:16 +00:00
|
|
|
|
|
|
|
// Set the path to the shortcut target and add the description.
|
|
|
|
psl->SetPath(lpszPathObj);
|
|
|
|
psl->SetArguments(lpszArguments);
|
|
|
|
psl->SetDescription(lpszDesc);
|
|
|
|
|
|
|
|
// Query IShellLink for the IPersistFile interface, used for saving the
|
|
|
|
// shortcut in persistent storage.
|
|
|
|
hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*)&ppf);
|
|
|
|
|
2022-12-11 05:09:50 +00:00
|
|
|
if (SUCCEEDED(hres) && ppf) {
|
2013-08-26 17:00:16 +00:00
|
|
|
// Save the link by calling IPersistFile::Save.
|
|
|
|
hres = ppf->Save(lpszPathLink, TRUE);
|
|
|
|
ppf->Release();
|
|
|
|
}
|
|
|
|
psl->Release();
|
|
|
|
}
|
|
|
|
CoUninitialize();
|
|
|
|
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2014-09-20 19:55:58 +00:00
|
|
|
bool WindowsHost::CanCreateShortcut() {
|
|
|
|
return false; // Turn on when below function fixed
|
|
|
|
}
|
|
|
|
|
2013-08-26 17:00:16 +00:00
|
|
|
bool WindowsHost::CreateDesktopShortcut(std::string argumentPath, std::string gameTitle) {
|
|
|
|
// TODO: not working correctly
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
// Get the desktop folder
|
2020-01-04 17:02:10 +00:00
|
|
|
// TODO: Not long path safe.
|
2013-08-26 17:00:16 +00:00
|
|
|
wchar_t *pathbuf = new wchar_t[MAX_PATH + gameTitle.size() + 100];
|
|
|
|
SHGetFolderPath(0, CSIDL_DESKTOPDIRECTORY, NULL, SHGFP_TYPE_CURRENT, pathbuf);
|
|
|
|
|
|
|
|
// Sanitize the game title for banned characters.
|
|
|
|
const char bannedChars[] = "<>:\"/\\|?*";
|
|
|
|
for (size_t i = 0; i < gameTitle.size(); i++) {
|
2020-07-20 09:38:39 +00:00
|
|
|
for (char c : bannedChars) {
|
|
|
|
if (gameTitle[i] == c) {
|
2013-08-26 17:00:16 +00:00
|
|
|
gameTitle[i] = '_';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wcscat(pathbuf, L"\\");
|
|
|
|
wcscat(pathbuf, ConvertUTF8ToWString(gameTitle).c_str());
|
|
|
|
|
2020-01-04 17:02:10 +00:00
|
|
|
std::wstring moduleFilename;
|
|
|
|
size_t sz;
|
|
|
|
do {
|
|
|
|
moduleFilename.resize(moduleFilename.size() + MAX_PATH);
|
|
|
|
// On failure, this will return the same value as passed in, but success will always be one lower.
|
|
|
|
sz = GetModuleFileName(nullptr, &moduleFilename[0], (DWORD)moduleFilename.size());
|
|
|
|
} while (sz >= moduleFilename.size());
|
|
|
|
moduleFilename.resize(sz);
|
2013-08-26 17:00:16 +00:00
|
|
|
|
2020-01-04 17:02:10 +00:00
|
|
|
CreateLink(moduleFilename.c_str(), ConvertUTF8ToWString(argumentPath).c_str(), pathbuf, ConvertUTF8ToWString(gameTitle).c_str());
|
2013-08-26 17:00:16 +00:00
|
|
|
|
|
|
|
delete [] pathbuf;
|
|
|
|
return false;
|
2013-08-06 23:38:54 +00:00
|
|
|
}
|
2013-10-13 17:24:49 +00:00
|
|
|
|
2013-10-13 18:25:59 +00:00
|
|
|
void WindowsHost::ToggleDebugConsoleVisibility() {
|
|
|
|
MainWindow::ToggleDebugConsoleVisibility();
|
2013-10-13 18:14:28 +00:00
|
|
|
}
|
2016-05-28 05:00:14 +00:00
|
|
|
|
|
|
|
void WindowsHost::NotifyUserMessage(const std::string &message, float duration, u32 color, const char *id) {
|
|
|
|
osm.Show(message, duration, color, -1, true, id);
|
|
|
|
}
|
2017-12-09 22:11:39 +00:00
|
|
|
|
|
|
|
void WindowsHost::SendUIMessage(const std::string &message, const std::string &value) {
|
|
|
|
NativeMessageReceived(message.c_str(), value.c_str());
|
|
|
|
}
|
2020-10-22 09:14:35 +00:00
|
|
|
|
|
|
|
void WindowsHost::NotifySwitchUMDUpdated() {
|
|
|
|
PostMessage(mainWindow_, MainWindow::WM_USER_SWITCHUMD_UPDATED, 0, 0);
|
|
|
|
}
|