Parcourir la source

Merge pull request #3572 from FearlessTobi/port-5127

Port citra-emu/citra#5127: "common: Port some changes from dolphin"
bunnei il y a 6 ans
Parent
commit
b128beb3a9
2 fichiers modifiés avec 16 ajouts et 15 suppressions
  1. 13 9
      src/common/file_util.cpp
  2. 3 6
      src/common/thread.cpp

+ 13 - 9
src/common/file_util.cpp

@@ -3,6 +3,7 @@
 // Refer to the license.txt file included.
 // Refer to the license.txt file included.
 
 
 #include <array>
 #include <array>
+#include <limits>
 #include <memory>
 #include <memory>
 #include <sstream>
 #include <sstream>
 #include <unordered_map>
 #include <unordered_map>
@@ -530,11 +531,11 @@ void CopyDir(const std::string& source_path, const std::string& dest_path) {
 std::optional<std::string> GetCurrentDir() {
 std::optional<std::string> GetCurrentDir() {
 // Get the current working directory (getcwd uses malloc)
 // Get the current working directory (getcwd uses malloc)
 #ifdef _WIN32
 #ifdef _WIN32
-    wchar_t* dir;
-    if (!(dir = _wgetcwd(nullptr, 0))) {
+    wchar_t* dir = _wgetcwd(nullptr, 0);
+    if (!dir) {
 #else
 #else
-    char* dir;
-    if (!(dir = getcwd(nullptr, 0))) {
+    char* dir = getcwd(nullptr, 0);
+    if (!dir) {
 #endif
 #endif
         LOG_ERROR(Common_Filesystem, "GetCurrentDirectory failed: {}", GetLastErrorMsg());
         LOG_ERROR(Common_Filesystem, "GetCurrentDirectory failed: {}", GetLastErrorMsg());
         return {};
         return {};
@@ -918,19 +919,22 @@ void IOFile::Swap(IOFile& other) noexcept {
 
 
 bool IOFile::Open(const std::string& filename, const char openmode[], int flags) {
 bool IOFile::Open(const std::string& filename, const char openmode[], int flags) {
     Close();
     Close();
+    bool m_good;
 #ifdef _WIN32
 #ifdef _WIN32
     if (flags != 0) {
     if (flags != 0) {
         m_file = _wfsopen(Common::UTF8ToUTF16W(filename).c_str(),
         m_file = _wfsopen(Common::UTF8ToUTF16W(filename).c_str(),
                           Common::UTF8ToUTF16W(openmode).c_str(), flags);
                           Common::UTF8ToUTF16W(openmode).c_str(), flags);
+        m_good = m_file != nullptr;
     } else {
     } else {
-        _wfopen_s(&m_file, Common::UTF8ToUTF16W(filename).c_str(),
-                  Common::UTF8ToUTF16W(openmode).c_str());
+        m_good = _wfopen_s(&m_file, Common::UTF8ToUTF16W(filename).c_str(),
+                           Common::UTF8ToUTF16W(openmode).c_str()) == 0;
     }
     }
 #else
 #else
-    m_file = fopen(filename.c_str(), openmode);
+    m_file = std::fopen(filename.c_str(), openmode);
+    m_good = m_file != nullptr;
 #endif
 #endif
 
 
-    return IsOpen();
+    return m_good;
 }
 }
 
 
 bool IOFile::Close() {
 bool IOFile::Close() {
@@ -956,7 +960,7 @@ u64 IOFile::Tell() const {
     if (IsOpen())
     if (IsOpen())
         return ftello(m_file);
         return ftello(m_file);
 
 
-    return -1;
+    return std::numeric_limits<u64>::max();
 }
 }
 
 
 bool IOFile::Flush() {
 bool IOFile::Flush() {

+ 3 - 6
src/common/thread.cpp

@@ -28,11 +28,8 @@ namespace Common {
 #ifdef _MSC_VER
 #ifdef _MSC_VER
 
 
 // Sets the debugger-visible name of the current thread.
 // Sets the debugger-visible name of the current thread.
-// Uses undocumented (actually, it is now documented) trick.
-// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsdebug/html/vxtsksettingthreadname.asp
-
-// This is implemented much nicer in upcoming msvc++, see:
-// http://msdn.microsoft.com/en-us/library/xcb2z8hs(VS.100).aspx
+// Uses trick documented in:
+// https://docs.microsoft.com/en-us/visualstudio/debugger/how-to-set-a-thread-name-in-native-code
 void SetCurrentThreadName(const char* name) {
 void SetCurrentThreadName(const char* name) {
     static const DWORD MS_VC_EXCEPTION = 0x406D1388;
     static const DWORD MS_VC_EXCEPTION = 0x406D1388;
 
 
@@ -47,7 +44,7 @@ void SetCurrentThreadName(const char* name) {
 
 
     info.dwType = 0x1000;
     info.dwType = 0x1000;
     info.szName = name;
     info.szName = name;
-    info.dwThreadID = -1; // dwThreadID;
+    info.dwThreadID = std::numeric_limits<DWORD>::max();
     info.dwFlags = 0;
     info.dwFlags = 0;
 
 
     __try {
     __try {