From 246b515a869ebe4a8d6c12773db85724e8156f5d Mon Sep 17 00:00:00 2001
From: B3n30 <benediktthomas@gmail.com>
Date: Sun, 11 Aug 2019 12:28:07 +0200
Subject: [PATCH 1/3] citra_qt: on osx chdir to bundle dir to allow detection
 of user folder

---
 src/yuzu/main.cpp | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index a7c656fdbf..693bb1fcf7 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -6,6 +6,7 @@
 #include <clocale>
 #include <memory>
 #include <thread>
+#include <unistd.h>
 
 // VFS includes must be before glad as they will conflict with Windows file api, which uses defines.
 #include "applets/error.h"
@@ -2168,6 +2169,11 @@ int main(int argc, char* argv[]) {
     QCoreApplication::setOrganizationName(QStringLiteral("yuzu team"));
     QCoreApplication::setApplicationName(QStringLiteral("yuzu"));
 
+#ifdef __APPLE__
+    std::string bin_path = FileUtil::GetBundleDirectory() + DIR_SEP + "..";
+    chdir(bin_path.c_str());
+#endif
+
     // Enables the core to make the qt created contexts current on std::threads
     QCoreApplication::setAttribute(Qt::AA_DontCheckOpenGLContextThreadAffinity);
     QApplication app(argc, argv);

From 05801129406cb44e615925bd614f25067b92ac8f Mon Sep 17 00:00:00 2001
From: Weiyi Wang <wwylele@gmail.com>
Date: Tue, 13 Aug 2019 15:42:22 -0400
Subject: [PATCH 2/3] Guard unistd.h with MacOS only macro

Fix compile error on Windows caused by #4877
Weird, I thought I saw this guard during the code review...
---
 src/yuzu/main.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index 693bb1fcf7..e871fef7b2 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -6,7 +6,9 @@
 #include <clocale>
 #include <memory>
 #include <thread>
-#include <unistd.h>
+#ifdef __APPLE__
+#include <unistd.h> // for chdir
+#endif
 
 // VFS includes must be before glad as they will conflict with Windows file api, which uses defines.
 #include "applets/error.h"

From 1aec2ff4d24432a9083996b3549d2cb81c86cc7a Mon Sep 17 00:00:00 2001
From: FearlessTobi <thm.frey@gmail.com>
Date: Thu, 5 Sep 2019 03:40:49 +0200
Subject: [PATCH 3/3] Address review comments

---
 src/yuzu/main.cpp | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index e871fef7b2..4d61ad46f3 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -2172,7 +2172,10 @@ int main(int argc, char* argv[]) {
     QCoreApplication::setApplicationName(QStringLiteral("yuzu"));
 
 #ifdef __APPLE__
-    std::string bin_path = FileUtil::GetBundleDirectory() + DIR_SEP + "..";
+    // If you start a bundle (binary) on OSX without the Terminal, the working directory is "/".
+    // But since we require the working directory to be the executable path for the location of the
+    // user folder in the Qt Frontend, we need to cd into that working directory
+    const std::string bin_path = FileUtil::GetBundleDirectory() + DIR_SEP + "..";
     chdir(bin_path.c_str());
 #endif