From 27a141eccac29cd3a289e9ecf013c2bfd574cc82 Mon Sep 17 00:00:00 2001 From: hrydgard Date: Sun, 27 Jul 2008 20:51:02 +0000 Subject: Just submitting some boring minor cleanup and improved error msgs, to isolate my next change. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@92 8ced0084-cf51-0410-be5f-012b33b47a6e --- Source/Core/Common/Src/DynamicLibrary.cpp | 43 +++++++++++++++++++++++++------ Source/Core/Common/Src/DynamicLibrary.h | 4 ++- Source/Core/Common/Src/FileUtil.cpp | 35 +++++++++++++++---------- Source/Core/Common/Src/stdafx.h | 2 ++ Source/Core/Common/Src/x64Emitter.cpp | 8 +++--- 5 files changed, 64 insertions(+), 28 deletions(-) (limited to 'Source/Core/Common') diff --git a/Source/Core/Common/Src/DynamicLibrary.cpp b/Source/Core/Common/Src/DynamicLibrary.cpp index 86f5640a59..92dec9064c 100644 --- a/Source/Core/Common/Src/DynamicLibrary.cpp +++ b/Source/Core/Common/Src/DynamicLibrary.cpp @@ -24,6 +24,7 @@ #endif #include "Common.h" +#include "StringUtil.h" #include "DynamicLibrary.h" DynamicLibrary::DynamicLibrary() @@ -31,6 +32,29 @@ DynamicLibrary::DynamicLibrary() library = 0; } +#ifdef _WIN32 +std::string GetLastErrorAsString() +{ + LPVOID lpMsgBuf = 0; + DWORD error = GetLastError(); + FormatMessage( + FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, + NULL, + error, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language + (LPTSTR) &lpMsgBuf, + 0, NULL); + std::string s; + if (lpMsgBuf) + { + s = ((char *)lpMsgBuf); + LocalFree(lpMsgBuf); + } else { + s = StringFromFormat("(unknown error %08x)", error); + } + return s; +} +#endif bool DynamicLibrary::Load(const char* filename) { @@ -48,6 +72,9 @@ bool DynamicLibrary::Load(const char* filename) #ifdef _WIN32 library = LoadLibrary(filename); + if (!library) { + //PanicAlert("Error loading DLL %s: %s", filename, GetLastErrorAsString().c_str()); + } #else library = dlopen(filename, RTLD_NOW | RTLD_LOCAL); @@ -55,12 +82,10 @@ bool DynamicLibrary::Load(const char* filename) { PanicAlert(dlerror()); } - else - { - printf("Successfully loaded %s", filename); - } #endif - + if (library) { + library_file = filename; + } return(library != 0); } @@ -86,11 +111,14 @@ void* DynamicLibrary::Get(const char* funcname) const { void* retval; #ifdef _WIN32 + if (!library) + { + PanicAlert("Can't find function %s - Library not loaded."); + } retval = GetProcAddress(library, funcname); - if (!retval) { - // PanicAlert("Did not find function %s in DLL", funcname); + PanicAlert("Did not find function %s in library %s.", funcname, library_file.c_str()); } return(retval); @@ -103,7 +131,6 @@ void* DynamicLibrary::Get(const char* funcname) const printf("%s\n", dlerror()); } #endif - } diff --git a/Source/Core/Common/Src/DynamicLibrary.h b/Source/Core/Common/Src/DynamicLibrary.h index f63af4e4c8..49fdb5fa61 100644 --- a/Source/Core/Common/Src/DynamicLibrary.h +++ b/Source/Core/Common/Src/DynamicLibrary.h @@ -21,6 +21,8 @@ #include #endif +#include + class DynamicLibrary { public: @@ -35,7 +37,7 @@ class DynamicLibrary private: - + std::string library_file; #ifdef _WIN32 HINSTANCE library; #else diff --git a/Source/Core/Common/Src/FileUtil.cpp b/Source/Core/Common/Src/FileUtil.cpp index 2d3d827477..b91adc0053 100644 --- a/Source/Core/Common/Src/FileUtil.cpp +++ b/Source/Core/Common/Src/FileUtil.cpp @@ -2,6 +2,8 @@ #include "FileUtil.h" #ifdef _WIN32 #include +#else +#include #endif bool File::Exists(const std::string &filename) @@ -9,7 +11,9 @@ bool File::Exists(const std::string &filename) #ifdef _WIN32 return GetFileAttributes(filename.c_str()) != INVALID_FILE_ATTRIBUTES; #else - return true; //TODO + struct stat file_info; + int result = stat(filename.c_str(), &file_info); + return result == 0; #endif } @@ -17,14 +21,16 @@ bool File::IsDirectory(const std::string &filename) { #ifdef _WIN32 return (GetFileAttributes(filename.c_str()) & FILE_ATTRIBUTE_DIRECTORY) != 0; #else - return false; //TODO + // TODO: Insert POSIX code here. + return false; #endif } std::string SanitizePath(const std::string &filename) { std::string copy = filename; for (int i = 0; i < copy.size(); i++) - if (copy[i] == '/') copy[i] = '\\'; + if (copy[i] == '/') + copy[i] = '\\'; return copy; } @@ -38,6 +44,8 @@ void File::Launch(const std::string &filename) shex.lpFile = win_filename.c_str(); shex.nShow = SW_SHOWNORMAL; ShellExecuteEx(&shex); +#else + // TODO: Insert GNOME/KDE code here. #endif } @@ -51,6 +59,8 @@ void File::Explore(const std::string &path) shex.lpFile = win_path.c_str(); shex.nShow = SW_SHOWNORMAL; ShellExecuteEx(&shex); +#else + // TODO: Insert GNOME/KDE code here. #endif } @@ -59,19 +69,16 @@ bool File::CreateDir(const std::string &path) { #ifdef _WIN32 if (::CreateDirectory(path.c_str(), NULL)) - { return true; - } - else + DWORD error = GetLastError(); + if (error == ERROR_ALREADY_EXISTS) { - DWORD error = GetLastError(); - if (error == ERROR_ALREADY_EXISTS) - { - PanicAlert("%s already exists", path.c_str()); - return true; - } - PanicAlert("Error creating directory: %i", error); - return false; + PanicAlert("%s already exists", path.c_str()); + return true; } + PanicAlert("Error creating directory: %i", error); + return false; +#else + // TODO: Insert POSIX code here. #endif } \ No newline at end of file diff --git a/Source/Core/Common/Src/stdafx.h b/Source/Core/Common/Src/stdafx.h index e0d258d5e1..0e3f646780 100644 --- a/Source/Core/Common/Src/stdafx.h +++ b/Source/Core/Common/Src/stdafx.h @@ -17,7 +17,9 @@ #pragma once +#ifndef _WIN32_WINNT #define _WIN32_WINNT 0x501 +#endif #ifndef _WIN32_IE #define _WIN32_IE 0x0500 // Default value is 0x0400 #endif diff --git a/Source/Core/Common/Src/x64Emitter.cpp b/Source/Core/Common/Src/x64Emitter.cpp index 981ce73177..f996e7bf7e 100644 --- a/Source/Core/Common/Src/x64Emitter.cpp +++ b/Source/Core/Common/Src/x64Emitter.cpp @@ -74,20 +74,20 @@ namespace Gen inline void Write16(u16 value) { *(u16*)code = value; - code+=2; + code += 2; } inline void Write32(u32 value) { *(u32*)code = value; - code+=4; + code += 4; } inline void Write64(u64 value) { _dbg_assert_msg_(DYNA_REC,!mode32,"!mode32"); *(u64*)code = value; - code+=8; + code += 8; } void WriteModRM( int mod, int rm, int reg ) @@ -99,7 +99,6 @@ namespace Gen { Write8((u8)((scale << 6) | ((index & 7) << 3) | (base & 7))); } - void OpArg::WriteRex(bool op64, int customOp) const { @@ -1198,7 +1197,6 @@ namespace Gen void PMOVMSKB(X64Reg dest, OpArg arg) {WriteSSEOp(64, 0xD7, true, dest, arg); } - // Prefixes void LOCK() { Write8(0xF0); } -- cgit v1.2.3