Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'windows-unicode'
Fixed unicode filename handling on Windows.
Made all significant projects build with "Unicode" option on Windows.
Fixed unicode string handling in GUI code on all OSes.

From now on: std::string == UTF-8.

Fixed issue 4111.
Fixed issue 5178.
Fixed issue 5980.
  • Loading branch information
jordan-woyak committed Mar 4, 2013
2 parents cedfa45 + 814c2ff commit fcf87f6
Show file tree
Hide file tree
Showing 107 changed files with 1,109 additions and 1,283 deletions.
4 changes: 2 additions & 2 deletions Source/Core/Common/Common.vcxproj
Expand Up @@ -44,7 +44,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<UseDebugLibraries>false</UseDebugLibraries>
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugFast|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
Expand All @@ -54,7 +54,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<UseDebugLibraries>false</UseDebugLibraries>
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugFast|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
Expand Down
17 changes: 9 additions & 8 deletions Source/Core/Common/Src/ArmCPUDetect.cpp
Expand Up @@ -18,6 +18,7 @@
#include "Common.h"
#include "CPUDetect.h"
#include "StringUtil.h"
#include "FileUtil.h"

const char procfile[] = "/proc/cpuinfo";

Expand All @@ -27,9 +28,9 @@ char *GetCPUString()
char *cpu_string = 0;
// Count the number of processor lines in /proc/cpuinfo
char buf[1024];
FILE *fp;

fp = fopen(procfile, "r");
File::IOFile file(procfile, "r");
auto const fp = file.GetHandle();
if (!fp)
return 0;

Expand All @@ -47,9 +48,9 @@ bool CheckCPUFeature(const char *feature)
{
const char marker[] = "Features\t: ";
char buf[1024];
FILE *fp;

fp = fopen(procfile, "r");

File::IOFile file(procfile, "r");
auto const fp = file.GetHandle();
if (!fp)
return 0;

Expand All @@ -73,9 +74,9 @@ int GetCoreCount()
const char marker[] = "processor\t: ";
int cores = 0;
char buf[1024];
FILE *fp;

fp = fopen(procfile, "r");

File::IOFile file(procfile, "r");
auto const fp = file.GetHandle();
if (!fp)
return 0;

Expand Down
11 changes: 6 additions & 5 deletions Source/Core/Common/Src/CDUtils.cpp
Expand Up @@ -6,6 +6,7 @@
#include <memory> // for std::unique_ptr
#ifdef _WIN32
#include <windows.h>
#include "StringUtil.h"
#elif __APPLE__
#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOBSD.h>
Expand All @@ -25,7 +26,7 @@

#ifdef _WIN32
// takes a root drive path, returns true if it is a cdrom drive
bool is_cdrom(const char drive[])
bool is_cdrom(const TCHAR* drive)
{
return (DRIVE_CDROM == GetDriveType(drive));
}
Expand All @@ -36,15 +37,15 @@ std::vector<std::string> cdio_get_devices()
std::vector<std::string> drives;

const DWORD buffsize = GetLogicalDriveStrings(0, NULL);
std::unique_ptr<char[]> buff(new char[buffsize]);
if (GetLogicalDriveStrings(buffsize, buff.get()) == buffsize - 1)
std::vector<TCHAR> buff(buffsize);
if (GetLogicalDriveStrings(buffsize, buff.data()) == buffsize - 1)
{
const char* drive = buff.get();
auto drive = buff.data();
while (*drive)
{
if (is_cdrom(drive))
{
std::string str(drive);
std::string str(TStrToUTF8(drive));
str.pop_back(); // we don't want the final backslash
drives.push_back(std::move(str));
}
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/Common/Src/ConsoleListener.cpp
Expand Up @@ -61,7 +61,7 @@ void ConsoleListener::Open(bool Hidden, int Width, int Height, const char *Title
// Save the window handle that AllocConsole() created
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
// Set the console window title
SetConsoleTitle(Title);
SetConsoleTitle(UTF8ToTStr(Title).c_str());
// Set letter space
LetterSpace(80, 4000);
//MoveWindow(GetConsoleWindow(), 200,200, 800,800, true);
Expand Down Expand Up @@ -195,7 +195,7 @@ void ConsoleListener::PixelSpace(int Left, int Top, int Width, int Height, bool

static const int MAX_BYTES = 1024 * 16;

std::vector<std::array<CHAR, MAX_BYTES>> Str;
std::vector<std::array<TCHAR, MAX_BYTES>> Str;
std::vector<std::array<WORD, MAX_BYTES>> Attr;

// ReadConsoleOutputAttribute seems to have a limit at this level
Expand Down
9 changes: 6 additions & 3 deletions Source/Core/Common/Src/Crypto/md5.cpp
Expand Up @@ -37,6 +37,8 @@
#include <string.h>
#include <stdio.h>

#include "../FileUtil.h"

/*
* 32-bit integer manipulation macros (little endian)
*/
Expand Down Expand Up @@ -301,7 +303,10 @@ int md5_file( char *path, unsigned char output[16] )
md5_context ctx;
unsigned char buf[1024];

if( ( f = fopen( path, "rb" ) ) == NULL )
File::IOFile file(path, "rb");
f = file.GetHandle();

if (f == NULL)
return( 1 );

md5_starts( &ctx );
Expand All @@ -315,11 +320,9 @@ int md5_file( char *path, unsigned char output[16] )

if( ferror( f ) != 0 )
{
fclose( f );
return( 2 );
}

fclose( f );
return( 0 );
}

Expand Down
9 changes: 6 additions & 3 deletions Source/Core/Common/Src/Crypto/sha1.cpp
Expand Up @@ -36,6 +36,8 @@
#include <string.h>
#include <stdio.h>

#include "../FileUtil.h"

/*
* 32-bit integer manipulation macros (big endian)
*/
Expand Down Expand Up @@ -335,7 +337,10 @@ int sha1_file( char *path, unsigned char output[20] )
sha1_context ctx;
unsigned char buf[1024];

if( ( f = fopen( path, "rb" ) ) == NULL )
File::IOFile file(path, "rb");
f = file.GetHandle();

if (f == NULL)
return( 1 );

sha1_starts( &ctx );
Expand All @@ -349,11 +354,9 @@ int sha1_file( char *path, unsigned char output[20] )

if( ferror( f ) != 0 )
{
fclose( f );
return( 2 );
}

fclose( f );
return( 0 );
}

Expand Down
52 changes: 21 additions & 31 deletions Source/Core/Common/Src/ExtendedTrace.cpp
Expand Up @@ -17,6 +17,7 @@
#include <windows.h>
#include <stdio.h>
#include "ExtendedTrace.h"
#include "StringUtil.h"
using namespace std;

#include <tchar.h>
Expand Down Expand Up @@ -274,13 +275,21 @@ static BOOL GetSourceInfoFromAddress( UINT address, LPTSTR lpszSourceInfo )
return ret;
}

void StackTrace( HANDLE hThread, LPCTSTR lpszMessage, FILE *file )
void PrintFunctionAndSourceInfo(FILE* file, const STACKFRAME& callstack)
{
TCHAR symInfo[BUFFERSIZE] = _T("?");
TCHAR srcInfo[BUFFERSIZE] = _T("?");

GetFunctionInfoFromAddresses((ULONG)callstack.AddrPC.Offset, (ULONG)callstack.AddrFrame.Offset, symInfo);
GetSourceInfoFromAddress((ULONG)callstack.AddrPC.Offset, srcInfo);
etfprint(file, " " + TStrToUTF8(srcInfo) + " : " + TStrToUTF8(symInfo) + "\n");
}

void StackTrace( HANDLE hThread, const char* lpszMessage, FILE *file )
{
STACKFRAME callStack;
BOOL bResult;
CONTEXT context;
TCHAR symInfo[BUFFERSIZE] = _T("?");
TCHAR srcInfo[BUFFERSIZE] = _T("?");
HANDLE hProcess = GetCurrentProcess();

// If it's not this thread, let's suspend it, and resume it at the end
Expand Down Expand Up @@ -318,9 +327,7 @@ void StackTrace( HANDLE hThread, LPCTSTR lpszMessage, FILE *file )
etfprint(file, "Call stack info: \n");
etfprint(file, lpszMessage);

GetFunctionInfoFromAddresses( (ULONG)callStack.AddrPC.Offset, (ULONG)callStack.AddrFrame.Offset, symInfo );
GetSourceInfoFromAddress( (ULONG)callStack.AddrPC.Offset, srcInfo );
etfprint(file, string(" ") + srcInfo + string(" : ") + symInfo + string("\n"));
PrintFunctionAndSourceInfo(file, callStack);

for( ULONG index = 0; ; index++ )
{
Expand All @@ -341,29 +348,15 @@ void StackTrace( HANDLE hThread, LPCTSTR lpszMessage, FILE *file )
if( !bResult || callStack.AddrFrame.Offset == 0 )
break;

GetFunctionInfoFromAddresses( (ULONG)callStack.AddrPC.Offset, (ULONG)callStack.AddrFrame.Offset, symInfo );
GetSourceInfoFromAddress( (UINT)callStack.AddrPC.Offset, srcInfo );
etfprint(file, string(" ") + srcInfo + string(" : ") + symInfo + string("\n"));
PrintFunctionAndSourceInfo(file, callStack);

}

if ( hThread != GetCurrentThread() )
ResumeThread( hThread );
}

void StackTrace( HANDLE hThread, wchar_t const*lpszMessage, FILE *file, DWORD eip, DWORD esp, DWORD ebp )
{
// TODO: remove when Common builds as unicode
size_t origsize = wcslen(lpszMessage) + 1;
const size_t newsize = 100;
size_t convertedChars = 0;
char nstring[newsize];
wcstombs_s(&convertedChars, nstring, origsize, lpszMessage, _TRUNCATE);

StackTrace(hThread, nstring, file, eip, esp, ebp );
}

void StackTrace( HANDLE hThread, LPCTSTR lpszMessage, FILE *file, DWORD eip, DWORD esp, DWORD ebp )
void StackTrace(HANDLE hThread, const char* lpszMessage, FILE *file, DWORD eip, DWORD esp, DWORD ebp )
{
STACKFRAME callStack;
BOOL bResult;
Expand Down Expand Up @@ -391,9 +384,7 @@ void StackTrace( HANDLE hThread, LPCTSTR lpszMessage, FILE *file, DWORD eip, DWO
etfprint(file, "Call stack info: \n");
etfprint(file, lpszMessage);

GetFunctionInfoFromAddresses( (ULONG)callStack.AddrPC.Offset, (ULONG)callStack.AddrFrame.Offset, symInfo );
GetSourceInfoFromAddress( (UINT)callStack.AddrPC.Offset, srcInfo );
etfprint(file, string(" ") + srcInfo + string(" : ") + symInfo + string("\n"));
PrintFunctionAndSourceInfo(file, callStack);

for( ULONG index = 0; ; index++ )
{
Expand All @@ -414,10 +405,7 @@ void StackTrace( HANDLE hThread, LPCTSTR lpszMessage, FILE *file, DWORD eip, DWO
if( !bResult || callStack.AddrFrame.Offset == 0 )
break;

GetFunctionInfoFromAddresses( (ULONG)callStack.AddrPC.Offset, (ULONG)callStack.AddrFrame.Offset, symInfo );
GetSourceInfoFromAddress( (UINT)callStack.AddrPC.Offset, srcInfo );
etfprint(file, string(" ") + srcInfo + string(" : ") + symInfo + string("\n"));

PrintFunctionAndSourceInfo(file, callStack);
}

if ( hThread != GetCurrentThread() )
Expand All @@ -426,15 +414,17 @@ void StackTrace( HANDLE hThread, LPCTSTR lpszMessage, FILE *file, DWORD eip, DWO

char g_uefbuf[2048];

void etfprintf(FILE *file, const char *format, ...) {
void etfprintf(FILE *file, const char *format, ...)
{
va_list ap;
va_start(ap, format);
int len = vsprintf(g_uefbuf, format, ap);
fwrite(g_uefbuf, 1, len, file);
va_end(ap);
}

void etfprint(FILE *file, const std::string &text) {
void etfprint(FILE *file, const std::string &text)
{
size_t len = text.length();
fwrite(text.data(), 1, len, file);
}
Expand Down
9 changes: 4 additions & 5 deletions Source/Core/Common/Src/ExtendedTrace.h
Expand Up @@ -26,15 +26,14 @@

#define EXTENDEDTRACEINITIALIZE( IniSymbolPath ) InitSymInfo( IniSymbolPath )
#define EXTENDEDTRACEUNINITIALIZE() UninitSymInfo()
#define STACKTRACE(file) StackTrace( GetCurrentThread(), _T(""), file)
#define STACKTRACE2(file, eip, esp, ebp) StackTrace(GetCurrentThread(), _T(""), file, eip, esp, ebp)
#define STACKTRACE(file) StackTrace( GetCurrentThread(), "", file)
#define STACKTRACE2(file, eip, esp, ebp) StackTrace(GetCurrentThread(), "", file, eip, esp, ebp)
// class File;

BOOL InitSymInfo( PCSTR );
BOOL UninitSymInfo();
void StackTrace( HANDLE, LPCTSTR, FILE *file);
void StackTrace( HANDLE, LPCTSTR, FILE *file, DWORD eip, DWORD esp, DWORD ebp);
void StackTrace( HANDLE hThread, wchar_t const* lpszMessage, FILE *file, DWORD eip, DWORD esp, DWORD ebp);
void StackTrace(HANDLE, char const* msg, FILE *file);
void StackTrace(HANDLE, char const* msg, FILE *file, DWORD eip, DWORD esp, DWORD ebp);

// functions by Masken
void etfprintf(FILE *file, const char *format, ...);
Expand Down
5 changes: 2 additions & 3 deletions Source/Core/Common/Src/FileSearch.cpp
Expand Up @@ -51,7 +51,7 @@ void CFileSearch::FindFiles(const std::string& _searchString, const std::string&
BuildCompleteFilename(GCMSearchPath, _strPath, _searchString);
#ifdef _WIN32
WIN32_FIND_DATA findData;
HANDLE FindFirst = FindFirstFile(GCMSearchPath.c_str(), &findData);
HANDLE FindFirst = FindFirstFile(UTF8ToTStr(GCMSearchPath).c_str(), &findData);

if (FindFirst != INVALID_HANDLE_VALUE)
{
Expand All @@ -62,7 +62,7 @@ void CFileSearch::FindFiles(const std::string& _searchString, const std::string&
if (findData.cFileName[0] != '.')
{
std::string strFilename;
BuildCompleteFilename(strFilename, _strPath, findData.cFileName);
BuildCompleteFilename(strFilename, _strPath, TStrToUTF8(findData.cFileName));
m_FileNames.push_back(strFilename);
}

Expand Down Expand Up @@ -112,7 +112,6 @@ void CFileSearch::FindFiles(const std::string& _searchString, const std::string&
#endif
}


const CFileSearch::XStringVector& CFileSearch::GetFileNames() const
{
return m_FileNames;
Expand Down

0 comments on commit fcf87f6

Please sign in to comment.