summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorlat9nq <lat9nq@gmail.com>2022-07-10 20:08:20 +0200
committerlat9nq <lat9nq@gmail.com>2022-07-10 20:08:20 +0200
commit4f15d9ed6fba4fa1804c5be3f9378e3ad3d32688 (patch)
tree78795445528ff6f9c96874e8ef461f5f5e6ae871 /src
parentyuzu: Rename check_vulkan to startup_checks (diff)
downloadyuzu-4f15d9ed6fba4fa1804c5be3f9378e3ad3d32688.tar
yuzu-4f15d9ed6fba4fa1804c5be3f9378e3ad3d32688.tar.gz
yuzu-4f15d9ed6fba4fa1804c5be3f9378e3ad3d32688.tar.bz2
yuzu-4f15d9ed6fba4fa1804c5be3f9378e3ad3d32688.tar.lz
yuzu-4f15d9ed6fba4fa1804c5be3f9378e3ad3d32688.tar.xz
yuzu-4f15d9ed6fba4fa1804c5be3f9378e3ad3d32688.tar.zst
yuzu-4f15d9ed6fba4fa1804c5be3f9378e3ad3d32688.zip
Diffstat (limited to 'src')
-rw-r--r--src/yuzu/main.cpp15
-rw-r--r--src/yuzu/startup_checks.cpp61
-rw-r--r--src/yuzu/startup_checks.h3
3 files changed, 78 insertions, 1 deletions
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index 64be8bf61..f2e449560 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -3853,6 +3853,21 @@ void GMainWindow::SetDiscordEnabled([[maybe_unused]] bool state) {
#endif
int main(int argc, char* argv[]) {
+#ifdef _WIN32
+ char variable_contents[32];
+ const DWORD startup_check_var =
+ GetEnvironmentVariable(STARTUP_CHECK_ENV_VAR, variable_contents, 32);
+ if (startup_check_var != 0) {
+ std::fprintf(stderr, "perform statup checks\n");
+ CheckVulkan();
+ return 0;
+ } else {
+ std::fprintf(stderr, "%d\n", StartupChecks());
+ }
+#elif YUZU_UNIX
+#error "Unimplemented"
+#endif
+
Common::DetachedTasks detached_tasks;
MicroProfileOnThreadCreate("Frontend");
SCOPE_EXIT({ MicroProfileShutdown(); });
diff --git a/src/yuzu/startup_checks.cpp b/src/yuzu/startup_checks.cpp
index e6d66ab34..cfd14a6d5 100644
--- a/src/yuzu/startup_checks.cpp
+++ b/src/yuzu/startup_checks.cpp
@@ -3,6 +3,15 @@
#include "video_core/vulkan_common/vulkan_wrapper.h"
+#ifdef _WIN32
+#include <cstring> // for memset, strncpy
+#include <processthreadsapi.h>
+#include <windows.h>
+#elif defined(YUZU_UNIX)
+#include <unistd.h>
+#endif
+
+#include <cstdio>
#include <filesystem>
#include <fstream>
#include "common/fs/fs.h"
@@ -10,7 +19,7 @@
#include "common/logging/log.h"
#include "video_core/vulkan_common/vulkan_instance.h"
#include "video_core/vulkan_common/vulkan_library.h"
-#include "yuzu/check_vulkan.h"
+#include "yuzu/startup_checks.h"
#include "yuzu/uisettings.h"
constexpr char TEMP_FILE_NAME[] = "vulkan_check";
@@ -51,3 +60,53 @@ bool CheckVulkan() {
std::filesystem::remove(temp_file_loc);
return true;
}
+
+bool StartupChecks() {
+#ifdef _WIN32
+ const bool env_var_set = SetEnvironmentVariableA(STARTUP_CHECK_ENV_VAR, "ON");
+ if (!env_var_set) {
+ LOG_ERROR(Frontend, "SetEnvironmentVariableA failed to set {}, {}", STARTUP_CHECK_ENV_VAR,
+ GetLastError());
+ return false;
+ }
+
+ STARTUPINFOA startup_info;
+ PROCESS_INFORMATION process_info;
+
+ std::memset(&startup_info, '\0', sizeof(startup_info));
+ std::memset(&process_info, '\0', sizeof(process_info));
+ startup_info.cb = sizeof(startup_info);
+
+ char p_name[255];
+ std::strncpy(p_name, "yuzu.exe", 255);
+
+ // TODO: use argv[0] instead of yuzu.exe
+ const bool process_created = CreateProcessA(nullptr, // lpApplicationName
+ p_name, // lpCommandLine
+ nullptr, // lpProcessAttributes
+ nullptr, // lpThreadAttributes
+ false, // bInheritHandles
+ 0, // dwCreationFlags
+ nullptr, // lpEnvironment
+ nullptr, // lpCurrentDirectory
+ &startup_info, // lpStartupInfo
+ &process_info // lpProcessInformation
+ );
+ if (!process_created) {
+ LOG_ERROR(Frontend, "CreateProcessA failed, {}", GetLastError());
+ return false;
+ }
+
+ // wait until the processs exits
+ DWORD exit_code = STILL_ACTIVE;
+ while (exit_code == STILL_ACTIVE) {
+ GetExitCodeProcess(process_info.hProcess, &exit_code);
+ }
+
+ std::fprintf(stderr, "exit code: %d\n", exit_code);
+
+ CloseHandle(process_info.hProcess);
+ CloseHandle(process_info.hThread);
+#endif
+ return true;
+}
diff --git a/src/yuzu/startup_checks.h b/src/yuzu/startup_checks.h
index e4ea93582..98bd5f4bf 100644
--- a/src/yuzu/startup_checks.h
+++ b/src/yuzu/startup_checks.h
@@ -3,4 +3,7 @@
#pragma once
+constexpr char STARTUP_CHECK_ENV_VAR[] = "YUZU_DO_STARTUP_CHECKS";
+
bool CheckVulkan();
+bool StartupChecks();