Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from hrydgard:master #86

Merged
merged 8 commits into from
Jan 27, 2025
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,16 @@ if(NOT MSVC)
elseif(ANDROID)
add_compile_options(-fsigned-char)
endif()

check_symbol_exists(getauxval sys/auxv.h HAVE_GETAUXVAL)
if(HAVE_GETAUXVAL)
add_definitions(-DHAVE_GETAUXVAL)
endif()

check_symbol_exists(elf_aux_info sys/auxv.h HAVE_ELF_AUX_INFO)
if(HAVE_ELF_AUX_INFO)
add_definitions(-DHAVE_ELF_AUX_INFO)
endif()
else()
# Disable warnings about MS-specific _s variants of libc functions
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
Expand Down
12 changes: 12 additions & 0 deletions Common/CommonWindows.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
#pragma once

#if defined(_MSC_VER) && _MSC_VER < 1700
#error You need a newer version of Visual Studio
#else
#undef _WIN32_WINNT
#define _WIN32_WINNT 0x601 // Compile for Win7 on Visual Studio 2012 and above
#undef WINVER
#define WINVER 0x601
#endif

#undef _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES
#define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1

#ifdef _WIN32
#pragma warning(disable:4091)

Expand Down
23 changes: 14 additions & 9 deletions Common/RiscVCPUDetect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <cstring>
#include <set>
#include <sstream>
#ifndef __OpenBSD__
#if defined(HAVE_GETAUXVAL) || defined(HAVE_ELF_AUX_INFO)
#include <sys/auxv.h>
#endif
#include <vector>
Expand Down Expand Up @@ -203,22 +203,27 @@ void CPUInfo::Detect()
}
#endif

#ifdef __OpenBSD__
/* OpenBSD uses RV64GC */
RiscV_M = true;
RiscV_A = true;
RiscV_F = true;
RiscV_D = true;
RiscV_C = true;
RiscV_V = false;
#if defined(HAVE_GETAUXVAL) || defined(HAVE_ELF_AUX_INFO)
#ifdef HAVE_ELF_AUX_INFO
unsigned long hwcap = 0;
elf_aux_info(AT_HWCAP, &hwcap, sizeof(hwcap));
#else
unsigned long hwcap = getauxval(AT_HWCAP);
#endif
RiscV_M = ExtensionSupported(hwcap, 'M');
RiscV_A = ExtensionSupported(hwcap, 'A');
RiscV_F = ExtensionSupported(hwcap, 'F');
RiscV_D = ExtensionSupported(hwcap, 'D');
RiscV_C = ExtensionSupported(hwcap, 'C');
RiscV_V = ExtensionSupported(hwcap, 'V');
#elif defined(__OpenBSD__)
/* OpenBSD uses RV64GC */
RiscV_M = true;
RiscV_A = true;
RiscV_F = true;
RiscV_D = true;
RiscV_C = true;
RiscV_V = false;
#endif
// We assume as in RVA20U64 that F means Zicsr is available.
RiscV_Zicsr = RiscV_F;
Expand Down
6 changes: 4 additions & 2 deletions Core/HLE/HLE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,8 @@ static void updateSyscallStats(int modulenum, int funcnum, double total)
}

static void CallSyscallWithFlags(const HLEFunction *info) {
_dbg_assert_(g_stackSize == 0);
// _dbg_assert_(g_stackSize == 0);
g_stackSize = 0;

const int stackSize = g_stackSize;
if (stackSize == 0) {
Expand Down Expand Up @@ -749,7 +750,8 @@ static void CallSyscallWithFlags(const HLEFunction *info) {
}

static void CallSyscallWithoutFlags(const HLEFunction *info) {
_dbg_assert_(g_stackSize == 0);
// _dbg_assert_(g_stackSize == 0);
g_stackSize = 0;

const int stackSize = g_stackSize;
if (stackSize == 0) {
Expand Down
2 changes: 1 addition & 1 deletion UI/GameSettingsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@ void GameSettingsScreen::CreateToolsSettings(UI::ViewGroup *tools) {

tools->Add(new ItemHeader(ms->T("Tools")));

const bool showRetroAchievements = true; // System_GetPropertyInt(SYSPROP_DEVICE_TYPE) != DEVICE_TYPE_VR;
const bool showRetroAchievements = System_GetPropertyInt(SYSPROP_DEVICE_TYPE) != DEVICE_TYPE_VR;
if (showRetroAchievements) {
auto retro = tools->Add(new Choice(sy->T("RetroAchievements")));
retro->OnClick.Add([=](UI::EventParams &) -> UI::EventReturn {
Expand Down
64 changes: 60 additions & 4 deletions Windows/W32Util/ShellUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,66 @@
#include "Common/Data/Format/PNGLoad.h"
#include "ShellUtil.h"

#include <shobjidl.h> // For IFileDialog and related interfaces
#include <shlobj.h>
#include <commdlg.h>
#include <cderr.h>

namespace W32Util {
std::string BrowseForFolder(HWND parent, std::string_view title, std::string_view initialPath) {
std::wstring titleString = ConvertUTF8ToWString(title);
return BrowseForFolder(parent, titleString.c_str(), initialPath);

std::string BrowseForFolder2(HWND parent, std::string_view title, std::string_view initialPath) {
const std::wstring wtitle = ConvertUTF8ToWString(title);
const std::wstring initialDir = ConvertUTF8ToWString(initialPath);

std::wstring selectedFolder;

// Create the FileOpenDialog object
IFileDialog* pFileDialog = nullptr;
HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pFileDialog));
if (!SUCCEEDED(hr)) {
return "";
}
// Set the options to select folders instead of files
DWORD dwOptions;
hr = pFileDialog->GetOptions(&dwOptions);
if (SUCCEEDED(hr)) {
hr = pFileDialog->SetOptions(dwOptions | FOS_PICKFOLDERS);
} else {
return "";
}

// Set the initial directory
if (!initialDir.empty()) {
IShellItem* pShellItem = nullptr;
hr = SHCreateItemFromParsingName(initialDir.c_str(), nullptr, IID_PPV_ARGS(&pShellItem));
if (SUCCEEDED(hr)) {
hr = pFileDialog->SetFolder(pShellItem);
pShellItem->Release();
}
}
pFileDialog->SetTitle(wtitle.c_str());

// Show the dialog
hr = pFileDialog->Show(parent);
if (SUCCEEDED(hr)) {
// Get the selected folder
IShellItem* pShellItem = nullptr;
hr = pFileDialog->GetResult(&pShellItem);
if (SUCCEEDED(hr)) {
PWSTR pszFilePath = nullptr;
hr = pShellItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);
if (SUCCEEDED(hr)) {
selectedFolder = pszFilePath;
CoTaskMemFree(pszFilePath);
}
pShellItem->Release();
}
}

pFileDialog->Release();
return ConvertWStringToUTF8(selectedFolder);
}

static int CALLBACK BrowseFolderCallback(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData) {
if (uMsg == BFFM_INITIALIZED) {
LPCTSTR path = reinterpret_cast<LPCTSTR>(lpData);
Expand Down Expand Up @@ -72,6 +122,12 @@ namespace W32Util {
return result;
}

std::string BrowseForFolder(HWND parent, std::string_view title, std::string_view initialPath) {
std::wstring titleString = ConvertUTF8ToWString(title);
return BrowseForFolder(parent, titleString.c_str(), initialPath);
}


bool BrowseForFileName(bool _bLoad, HWND _hParent, const wchar_t *_pTitle,
const wchar_t *_pInitialFolder, const wchar_t *_pFilter, const wchar_t *_pExtension,
std::string &_strFileName) {
Expand Down Expand Up @@ -333,4 +389,4 @@ bool CreateICOFromPNGData(const uint8_t *imageData, size_t imageDataSize, const
return true;
}

} // namespace
} // namespace W32Util
7 changes: 5 additions & 2 deletions Windows/W32Util/ShellUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@

class Path;

namespace W32Util
{
namespace W32Util {

// Can't make initialPath a string_view, need the null so might as well require it.
std::string BrowseForFolder(HWND parent, std::string_view title, std::string_view initialPath);
std::string BrowseForFolder(HWND parent, const wchar_t *title, std::string_view initialPath);
// Modern dialog
std::string BrowseForFolder2(HWND parent, std::string_view title, std::string_view initialPath);

bool BrowseForFileName(bool _bLoad, HWND _hParent, const wchar_t*_pTitle,
const wchar_t *_pInitialFolder, const wchar_t *_pFilter, const wchar_t*_pExtension,
std::string& _strFileName);
Expand Down
13 changes: 6 additions & 7 deletions Windows/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string
case SystemRequestType::BROWSE_FOR_FOLDER:
{
std::thread([=] {
std::string folder = W32Util::BrowseForFolder(MainWindow::GetHWND(), param1, param2);
std::string folder = W32Util::BrowseForFolder2(MainWindow::GetHWND(), param1, param2);
if (folder.size()) {
g_requestManager.PostSystemSuccess(requestId, folder.c_str());
} else {
Expand Down Expand Up @@ -843,7 +843,11 @@ static void InitMemstickDirectory() {
}

static void WinMainInit() {
CoInitializeEx(NULL, COINIT_MULTITHREADED);
HRESULT hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
if (FAILED(hr)) {
_dbg_assert_(false);
}

net::Init(); // This needs to happen before we load the config. So on Windows we also run it in Main. It's fine to call multiple times.

// Windows, API init stuff
Expand All @@ -859,11 +863,6 @@ static void WinMainInit() {
#endif
PROFILE_INIT();

#if PPSSPP_ARCH(AMD64) && defined(_MSC_VER) && _MSC_VER < 1900
// FMA3 support in the 2013 CRT is broken on Vista and Windows 7 RTM (fixed in SP1). Just disable it.
_set_FMA3_enable(0);
#endif

InitDarkMode();
}

Expand Down
17 changes: 0 additions & 17 deletions Windows/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,6 @@

#pragma once

#undef _WIN32_WINNT

#if defined(_MSC_VER) && _MSC_VER < 1700
#error You need a newer version of Visual Studio
#else
#define _WIN32_WINNT 0x601 // Compile for Win7 on Visual Studio 2012 and above
#endif

#undef WINVER
#define WINVER _WIN32_WINNT
#ifndef _WIN32_IE
#define _WIN32_IE 0x0600 // Default value is 0x0400
#endif

#undef _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES
#define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1

#ifndef __clang__
#if defined _M_IX86
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
Expand Down
Loading