Skip to content

Commit

Permalink
Merge pull request #18699 from hrydgard/adrenotools-error-check
Browse files Browse the repository at this point in the history
Adrenotools driver installation: Fix bad error checks
  • Loading branch information
hrydgard committed Jan 15, 2024
2 parents 15db280 + 775ba0a commit d6e1851
Show file tree
Hide file tree
Showing 57 changed files with 149 additions and 108 deletions.
6 changes: 3 additions & 3 deletions Common/Data/Format/JSONReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
namespace json {

struct JsonGet {
JsonGet(const JsonValue &value) : value_(value) {
}
JsonGet(const JsonValue &value) : value_(value) {}

int numChildren() const;
const JsonNode *get(const char *child_name) const;
Expand Down Expand Up @@ -47,7 +46,8 @@ struct JsonGet {
class JsonReader {
public:
JsonReader(const std::string &filename);
JsonReader(const void *data, size_t size) {
// Makes a copy, after this returns you can free the input buffer.
JsonReader(const char *data, size_t size) {
buffer_ = (char *)malloc(size + 1);
if (buffer_) {
memcpy(buffer_, data, size);
Expand Down
16 changes: 9 additions & 7 deletions Common/GPU/Vulkan/VulkanLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ static const char * const so_names[] = {
};
#endif

static VulkanLibraryHandle VulkanLoadLibrary(const char *logname) {
static VulkanLibraryHandle VulkanLoadLibrary(std::string *errorString) {
#if PPSSPP_PLATFORM(SWITCH)
// Always unavailable, for now.
return nullptr;
Expand Down Expand Up @@ -329,7 +329,7 @@ static VulkanLibraryHandle VulkanLoadLibrary(const char *logname) {
for (int i = 0; i < ARRAY_SIZE(so_names); i++) {
lib = dlopen(so_names[i], RTLD_NOW | RTLD_LOCAL);
if (lib) {
INFO_LOG(G3D, "%s: Library loaded ('%s')", logname, so_names[i]);
INFO_LOG(G3D, "Vulkan library loaded with AdrenoTools ('%s')", so_names[i]);
break;
}
}
Expand Down Expand Up @@ -378,9 +378,10 @@ bool VulkanMayBeAvailable() {
}
INFO_LOG(G3D, "VulkanMayBeAvailable: Device allowed ('%s')", name.c_str());

VulkanLibraryHandle lib = VulkanLoadLibrary("VulkanMayBeAvailable");
std::string errorStr;
VulkanLibraryHandle lib = VulkanLoadLibrary(&errorStr);
if (!lib) {
INFO_LOG(G3D, "Vulkan loader: Library not available");
INFO_LOG(G3D, "Vulkan loader: Library not available: %s", errorStr.c_str());
g_vulkanAvailabilityChecked = true;
g_vulkanMayBeAvailable = false;
return false;
Expand Down Expand Up @@ -545,9 +546,9 @@ bool VulkanMayBeAvailable() {
return g_vulkanMayBeAvailable;
}

bool VulkanLoad() {
bool VulkanLoad(std::string *errorStr) {
if (!vulkanLibrary) {
vulkanLibrary = VulkanLoadLibrary("VulkanLoad");
vulkanLibrary = VulkanLoadLibrary(errorStr);
if (!vulkanLibrary) {
return false;
}
Expand All @@ -565,7 +566,8 @@ bool VulkanLoad() {
INFO_LOG(G3D, "VulkanLoad: Base functions loaded.");
return true;
} else {
ERROR_LOG(G3D, "VulkanLoad: Failed to load Vulkan base functions.");
*errorStr = "Failed to load Vulkan base functions";
ERROR_LOG(G3D, "VulkanLoad: %s", errorStr->c_str());
VulkanFreeLibrary(vulkanLibrary);
return false;
}
Expand Down
3 changes: 2 additions & 1 deletion Common/GPU/Vulkan/VulkanLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#define VK_NO_PROTOTYPES

#include "ext/vulkan/vulkan.h"
#include <string>

// Hacky X11 header workaround
#ifdef Opposite
Expand Down Expand Up @@ -266,7 +267,7 @@ struct VulkanExtensions {
bool VulkanMayBeAvailable();
void VulkanSetAvailable(bool available);

bool VulkanLoad();
bool VulkanLoad(std::string *errorStr);
void VulkanLoadInstanceFunctions(VkInstance instance, const VulkanExtensions &enabledExtensions);
void VulkanLoadDeviceFunctions(VkDevice device, const VulkanExtensions &enabledExtensions);
void VulkanFree();
Expand Down
1 change: 1 addition & 0 deletions Common/System/Request.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ enum class BrowseFileType {
INI,
DB,
SOUND_EFFECT,
ZIP,
ANY,
};

Expand Down
3 changes: 3 additions & 0 deletions Qt/QtMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,9 @@ bool MainUI::HandleCustomEvent(QEvent *e) {
case BrowseFileType::SOUND_EFFECT:
filter = "WAVE files (*.wav)";
break;
case BrowseFileType::ZIP:
filter = "ZIP files (*.zip)";
break;
case BrowseFileType::ANY:
break;
}
Expand Down
6 changes: 4 additions & 2 deletions SDL/SDLVulkanGraphicsContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ bool SDLVulkanGraphicsContext::Init(SDL_Window *&window, int x, int y, int w, in

Version gitVer(PPSSPP_GIT_VERSION);

if (!VulkanLoad()) {
*error_message = "Failed to load Vulkan driver library";
std::string errorStr;
if (!VulkanLoad(&errorStr)) {
*error_message = "Failed to load Vulkan driver library: ";
(*error_message) += errorStr;
return false;
}

Expand Down
94 changes: 55 additions & 39 deletions UI/GameSettingsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1268,59 +1268,75 @@ UI::EventReturn DeveloperToolsScreen::OnCustomDriverChange(UI::EventParams &e) {
UI::EventReturn DeveloperToolsScreen::OnCustomDriverInstall(UI::EventParams &e) {
auto gr = GetI18NCategory(I18NCat::GRAPHICS);

System_BrowseForFile(gr->T("Install Custom Driver..."), BrowseFileType::ANY, [this](const std::string &value, int) {
const Path driverPath = g_Config.internalDataDirectory / "drivers";

if (!value.empty()) {
Path zipPath = Path(value);

bool success = false;

if (zipPath.GetFileExtension() == ".zip") {
ZipFileReader *zipFileReader = ZipFileReader::Create(zipPath, "");

size_t metaDataSize;
uint8_t *metaData = zipFileReader->ReadFile("meta.json", &metaDataSize);
System_BrowseForFile(gr->T("Install Custom Driver..."), BrowseFileType::ZIP, [this](const std::string &value, int) {
if (value.empty()) {
return;
}

Path tempMeta = Path(g_Config.internalDataDirectory / "meta.json");
auto gr = GetI18NCategory(I18NCat::GRAPHICS);

File::CreateEmptyFile(tempMeta);
File::WriteDataToFile(false, metaData, metaDataSize, tempMeta);
Path zipPath = Path(value);

delete[] metaData;
// Don't bother checking the file extension. Can't always do that with files from Download (they have paths like content://com.android.providers.downloads.documents/document/msf%3A1000001095).
// Though, it may be possible to get it in other ways.

json::JsonReader meta = json::JsonReader((g_Config.internalDataDirectory / "meta.json").c_str());
if (meta.ok()) {
std::string driverName = meta.root().get("name")->value.toString();
std::unique_ptr<ZipFileReader> zipFileReader = std::unique_ptr<ZipFileReader>(ZipFileReader::Create(zipPath, "", true));
if (!zipFileReader) {
g_OSD.Show(OSDType::MESSAGE_ERROR, gr->T("The chosen ZIP file doesn't contain a valid driver", "couldn't open zip"));
ERROR_LOG(SYSTEM, "Failed to open file '%s' as zip", zipPath.c_str());
return;
}

Path newCustomDriver = driverPath / driverName;
File::CreateFullPath(newCustomDriver);
size_t metaDataSize;
uint8_t *metaData = zipFileReader->ReadFile("meta.json", &metaDataSize);
if (!metaData) {
g_OSD.Show(OSDType::MESSAGE_ERROR, gr->T("The chosen ZIP file doesn't contain a valid driver"), "meta.json missing");
return;
}

std::vector<File::FileInfo> zipListing;
zipFileReader->GetFileListing("", &zipListing, nullptr);
// Validate the json file. TODO: Be a bit more detailed.
json::JsonReader meta = json::JsonReader((const char *)metaData, metaDataSize);
delete[] metaData;
if (!meta.ok()) {
g_OSD.Show(OSDType::MESSAGE_ERROR, gr->T("The chosen ZIP file doesn't contain a valid driver"), "meta.json not valid json");
return;
}

for (auto file : zipListing) {
File::CreateEmptyFile(newCustomDriver / file.name);
const JsonNode *nameNode = meta.root().get("name");
if (!nameNode) {
g_OSD.Show(OSDType::MESSAGE_ERROR, gr->T("The chosen ZIP file doesn't contain a valid driver"), "missing driver name in json");
return;
}

size_t size;
uint8_t *data = zipFileReader->ReadFile(file.name.c_str(), &size);
File::WriteDataToFile(false, data, size, newCustomDriver / file.name);
std::string driverName = nameNode->value.toString();
if (driverName.empty()) {
g_OSD.Show(OSDType::MESSAGE_ERROR, gr->T("The chosen ZIP file doesn't contain a valid driver"), "driver name empty");
return;
}

delete[] data;
}
const Path newCustomDriver = g_Config.internalDataDirectory / "drivers" / driverName;
NOTICE_LOG(G3D, "Installing driver into '%s'", newCustomDriver.c_str());
File::CreateFullPath(newCustomDriver);

File::Delete(tempMeta);
std::vector<File::FileInfo> zipListing;
zipFileReader->GetFileListing("", &zipListing, nullptr);

success = true;
for (auto file : zipListing) {
File::CreateEmptyFile(newCustomDriver / file.name);

RecreateViews();
}
}
if (!success) {
auto gr = GetI18NCategory(I18NCat::GRAPHICS);
g_OSD.Show(OSDType::MESSAGE_ERROR, gr->T("The file is not a ZIP file containing a compatible driver."));
size_t size;
uint8_t *data = zipFileReader->ReadFile(file.name.c_str(), &size);
if (!data) {
g_OSD.Show(OSDType::MESSAGE_ERROR, gr->T("The chosen ZIP file doesn't contain a valid driver"), file.name.c_str());
return;
}
File::WriteDataToFile(false, data, size, newCustomDriver / file.name);
delete[] data;
}

auto iz = GetI18NCategory(I18NCat::INSTALLZIP);
g_OSD.Show(OSDType::MESSAGE_SUCCESS, iz->T("Installed!"));
RecreateViews();
});
return UI::EVENT_DONE;
}
Expand Down
3 changes: 3 additions & 0 deletions UWP/PPSSPP_UWPMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,9 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string
case BrowseFileType::INI:
supportedExtensions = { ".ini" };
break;
case BrowseFileType::ZIP:
supportedExtensions = { ".zip" };
break;
case BrowseFileType::DB:
supportedExtensions = { ".db" };
break;
Expand Down
6 changes: 4 additions & 2 deletions Windows/GPU/WindowsVulkanContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ bool WindowsVulkanContext::Init(HINSTANCE hInst, HWND hWnd, std::string *error_m

Version gitVer(PPSSPP_GIT_VERSION);

if (!VulkanLoad()) {
*error_message = "Failed to load Vulkan driver library";
std::string errorStr;
if (!VulkanLoad(&errorStr)) {
*error_message = "Failed to load Vulkan driver library: ";
(*error_message) += errorStr;
return false;
}

Expand Down
3 changes: 3 additions & 0 deletions Windows/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,9 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string
case BrowseFileType::INI:
filter = MakeFilter(L"Ini files (*.ini)|*.ini|All files (*.*)|*.*||");
break;
case BrowseFileType::ZIP:
filter = MakeFilter(L"ZIP files (*.zip)|*.zip|All files (*.*)|*.*||");
break;
case BrowseFileType::DB:
filter = MakeFilter(L"Cheat db files (*.db)|*.db|All files (*.*)|*.*||");
break;
Expand Down
5 changes: 3 additions & 2 deletions android/jni/AndroidVulkanContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ bool AndroidVulkanContext::InitAPI() {
INFO_LOG(G3D, "Creating Vulkan context");
Version gitVer(PPSSPP_GIT_VERSION);

if (!VulkanLoad()) {
ERROR_LOG(G3D, "Failed to load Vulkan driver library");
std::string errorStr;
if (!VulkanLoad(&errorStr)) {
ERROR_LOG(G3D, "Failed to load Vulkan driver library: %s", errorStr.c_str());
state_ = GraphicsContextState::FAILED_INIT;
return false;
}
Expand Down
8 changes: 6 additions & 2 deletions android/jni/app-android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1108,12 +1108,16 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string
case SystemRequestType::BROWSE_FOR_FILE:
{
BrowseFileType fileType = (BrowseFileType)param3;
std::string params = StringFromFormat("%d", requestId);
switch (fileType) {
case BrowseFileType::SOUND_EFFECT:
PushCommand("browse_file_audio", StringFromFormat("%d", requestId));
PushCommand("browse_file_audio", params);
break;
case BrowseFileType::ZIP:
PushCommand("browse_file_zip", params);
break;
default:
PushCommand("browse_file", StringFromFormat("%d", requestId));
PushCommand("browse_file", params);
break;
}
return true;
Expand Down
4 changes: 3 additions & 1 deletion android/src/org/ppsspp/ppsspp/NativeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -1409,7 +1409,7 @@ public boolean processCommand(String command, String params) {
Log.e(TAG, e.toString());
return false;
}
} else if (command.equals("browse_file") || command.equals("browse_file_audio")) {
} else if (command.equals("browse_file") || command.equals("browse_file_audio") || command.equals("browse_file_zip")) {
try {
int requestId = Integer.parseInt(params);
int packedResultCode = packResultCode(RESULT_OPEN_DOCUMENT, requestId);
Expand All @@ -1418,6 +1418,8 @@ public boolean processCommand(String command, String params) {
intent.addCategory(Intent.CATEGORY_OPENABLE);
if (command.equals("browse_file_audio")) {
intent.setType("audio/x-wav");
} else if (command.equals("browse_file_zip")) {
intent.setType("application/zip");
} else {
intent.setType("*/*");
}
Expand Down
2 changes: 1 addition & 1 deletion assets/lang/ar_AE.ini
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ Texture Filtering = ‎مفلتر الرسوم
Texture replacement pack activated = Texture replacement pack activated
Texture Scaling = ‎تكبير الرسوم
Texture Shader = Texture shader
The file is not a ZIP file containing a compatible driver. = The file is not a ZIP file containing a compatible driver.
The chosen ZIP file doesn't contain a valid driver = The chosen ZIP file doesn't contain a valid driver
Turn off Hardware Tessellation - unsupported = Turn off "hardware tessellation": unsupported
Unlimited = ‎لا محدود
Up to 1 = Up to 1
Expand Down
2 changes: 1 addition & 1 deletion assets/lang/az_AZ.ini
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ Texture Filtering = Texture filtering
Texture replacement pack activated = Texture replacement pack activated
Texture Scaling = Texture scaling
Texture Shader = Texture shader
The file is not a ZIP file containing a compatible driver. = The file is not a ZIP file containing a compatible driver.
The chosen ZIP file doesn't contain a valid driver = The chosen ZIP file doesn't contain a valid driver
Turn off Hardware Tessellation - unsupported = Turn off "hardware tessellation": unsupported
Unlimited = Unlimited
Up to 1 = Up to 1
Expand Down
2 changes: 1 addition & 1 deletion assets/lang/bg_BG.ini
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ Texture Filtering = Текстурно филтриране
Texture replacement pack activated = Texture replacement pack activated
Texture Scaling = Текстурно мащабиране
Texture Shader = Texture shader
The file is not a ZIP file containing a compatible driver. = The file is not a ZIP file containing a compatible driver.
The chosen ZIP file doesn't contain a valid driver = The chosen ZIP file doesn't contain a valid driver
Turn off Hardware Tessellation - unsupported = Turn off "hardware tessellation": unsupported
Unlimited = Unlimited
Up to 1 = Up to 1
Expand Down
2 changes: 1 addition & 1 deletion assets/lang/ca_ES.ini
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ Texture Filtering = Filtrat de textures
Texture replacement pack activated = Texture replacement pack activated
Texture Scaling = Escalat de textures
Texture Shader = Shader de textura
The file is not a ZIP file containing a compatible driver. = The file is not a ZIP file containing a compatible driver.
The chosen ZIP file doesn't contain a valid driver = The chosen ZIP file doesn't contain a valid driver
Turn off Hardware Tessellation - unsupported = Desactivant tessel·lat per maquinari: no suportat.
Unlimited = Il·limitat
Up to 1 = Fins a 1
Expand Down
2 changes: 1 addition & 1 deletion assets/lang/cz_CZ.ini
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ Texture Filtering = Filtrování textur
Texture replacement pack activated = Texture replacement pack activated
Texture Scaling = Změna velikosti textur
Texture Shader = Texture shader
The file is not a ZIP file containing a compatible driver. = The file is not a ZIP file containing a compatible driver.
The chosen ZIP file doesn't contain a valid driver = The chosen ZIP file doesn't contain a valid driver
Turn off Hardware Tessellation - unsupported = Turn off "hardware tessellation": unsupported
Unlimited = Neomezené
Up to 1 = Up to 1
Expand Down
2 changes: 1 addition & 1 deletion assets/lang/da_DK.ini
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ Texture Filtering = Texturfiltrering
Texture replacement pack activated = Texture replacement pack activated
Texture Scaling = Texturskalering
Texture Shader = Texture shader
The file is not a ZIP file containing a compatible driver. = The file is not a ZIP file containing a compatible driver.
The chosen ZIP file doesn't contain a valid driver = The chosen ZIP file doesn't contain a valid driver
Turn off Hardware Tessellation - unsupported = Turn off "hardware tessellation": unsupported
Unlimited = Ubegrænset
Up to 1 = Up to 1
Expand Down
2 changes: 1 addition & 1 deletion assets/lang/de_DE.ini
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ Texture Filtering = Texturfilterung
Texture replacement pack activated = Texture replacement pack activated
Texture Scaling = Texturskalierung
Texture Shader = Texture shader
The file is not a ZIP file containing a compatible driver. = The file is not a ZIP file containing a compatible driver.
The chosen ZIP file doesn't contain a valid driver = The chosen ZIP file doesn't contain a valid driver
Turn off Hardware Tessellation - unsupported = "Hardware Tessellierung" ausschalten: Nicht unterstützt
Unlimited = Unbegrenzt
Up to 1 = Up to 1
Expand Down
2 changes: 1 addition & 1 deletion assets/lang/dr_ID.ini
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ Texture Filtering = Saring i Texture
Texture replacement pack activated = Texture replacement pack activated
Texture Scaling = Petonggoi Texture
Texture Shader = Texture shader
The file is not a ZIP file containing a compatible driver. = The file is not a ZIP file containing a compatible driver.
The chosen ZIP file doesn't contain a valid driver = The chosen ZIP file doesn't contain a valid driver
Turn off Hardware Tessellation - unsupported = Turn off "hardware tessellation": unsupported
Unlimited = Unlimited
Up to 1 = Up to 1
Expand Down
2 changes: 1 addition & 1 deletion assets/lang/en_US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ Texture Filtering = Texture filtering
Texture replacement pack activated = Texture replacement pack activated
Texture Scaling = Texture scaling
Texture Shader = Texture shader
The file is not a ZIP file containing a compatible driver. = The file is not a ZIP file containing a compatible driver.
The chosen ZIP file doesn't contain a valid driver = The chosen ZIP file doesn't contain a valid driver
Turn off Hardware Tessellation - unsupported = Turn off "hardware tessellation": unsupported
Unlimited = Unlimited
Up to 1 = Up to 1
Expand Down
Loading

0 comments on commit d6e1851

Please sign in to comment.