Skip to content

Commit

Permalink
Merge pull request #9354 from hrydgard/uwp-prep
Browse files Browse the repository at this point in the history
Prepare code to build in UWP mode
  • Loading branch information
hrydgard authored Feb 25, 2017
2 parents 89ac1a5 + c219ae9 commit 49a37e9
Show file tree
Hide file tree
Showing 76 changed files with 497 additions and 374 deletions.
14 changes: 10 additions & 4 deletions Common/ArmABI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/

#include "ppsspp_config.h"

#if PPSSPP_ARCH(ARM)

#include "ArmEmitter.h"
#include "ArmABI.h"

Expand Down Expand Up @@ -108,15 +112,17 @@ void ARMXEmitter::UpdateAPSR(bool NZCVQ, u8 Flags, bool GE, u8 GEval)
ARMABI_MOVI2R(R14, Imm);
_MSR(true, true, R14);
}
else
if(NZCVQ)
else {
if (NZCVQ)
{
Operand2 value(Flags << 1, 3);
_MSR(true, false, value);
}
else if(GE)
} else if (GE)
{
Operand2 value(GEval << 2, 9);
_MSR(false, true, value);
}
}
}

#endif
12 changes: 5 additions & 7 deletions Common/ChunkFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <snappy-c.h>

#include "ChunkFile.h"
#include "StringUtils.h"

PointerWrapSection PointerWrap::Section(const char *title, int ver) {
return Section(title, ver, ver);
Expand All @@ -28,9 +29,8 @@ PointerWrapSection PointerWrap::Section(const char *title, int minVer, int ver)
char marker[16] = {0};
int foundVersion = ver;

strncpy(marker, title, sizeof(marker));
if (!ExpectVoid(marker, sizeof(marker)))
{
truncate_cpy(marker, title);
if (!ExpectVoid(marker, sizeof(marker))) {
// Might be before we added name markers for safety.
if (foundVersion == 1 && ExpectVoid(&foundVersion, sizeof(foundVersion)))
DoMarker(title);
Expand Down Expand Up @@ -283,13 +283,11 @@ CChunkFileReader::Error CChunkFileReader::SaveFile(const std::string &filename,
header.Revision = REVISION_CURRENT;
header.ExpectedSize = (u32)sz;
header.UncompressedSize = (u32)sz;
strncpy(header.GitVersion, gitVersion, 32);
header.GitVersion[31] = '\0';
truncate_cpy(header.GitVersion, gitVersion);

// Setup the fixed-length title.
char titleFixed[128];
strncpy(titleFixed, title.c_str(), sizeof(titleFixed));
titleFixed[sizeof(titleFixed) - 1] = '\0';
truncate_cpy(titleFixed, title.c_str());

// Write to file
if (compress) {
Expand Down
5 changes: 1 addition & 4 deletions Common/CommonFuncs.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,7 @@ inline u64 __rotr64(u64 x, unsigned int shift){
#if _M_IX86
#define Crash() {__asm int 3}
#else
extern "C" {
__declspec(dllimport) void __stdcall DebugBreak(void);
}
#define Crash() {DebugBreak();}
#define Crash() {__debugbreak();}
#endif // M_IX86
#endif // WIN32 ndef

Expand Down
3 changes: 3 additions & 0 deletions Common/ConsoleListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <stdarg.h>
#endif

#include "ppsspp_config.h"
#include "thread/threadutil.h"
#include "util/text/utf8.h"
#include "Common.h"
Expand Down Expand Up @@ -64,6 +65,8 @@ ConsoleListener::ConsoleListener() : bHidden(true)
bUseColor = false;
#elif defined(IOS)
bUseColor = false;
#elif PPSSPP_PLATFORM(UWP)
bUseColor = false;
#else
bUseColor = isatty(fileno(stdout));
#endif
Expand Down
33 changes: 0 additions & 33 deletions Common/Crypto/md5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#include "md5.h"

#include <string.h>
#include <stdio.h>

/*
* 32-bit integer manipulation macros (little endian)
Expand Down Expand Up @@ -291,38 +290,6 @@ void md5( unsigned char *input, int ilen, unsigned char output[16] )
memset( &ctx, 0, sizeof( md5_context ) );
}

/*
* output = MD5( file contents )
*/
int md5_file( char *path, unsigned char output[16] )
{
FILE *f;
size_t n;
md5_context ctx;
unsigned char buf[1024];

if( ( f = fopen( path, "rb" ) ) == NULL )
return( 1 );

md5_starts( &ctx );

while( ( n = fread( buf, 1, sizeof( buf ), f ) ) > 0 )
md5_update( &ctx, buf, (int) n );

md5_finish( &ctx, output );

memset( &ctx, 0, sizeof( md5_context ) );

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

fclose( f );
return( 0 );
}

/*
* MD5 HMAC context setup
*/
Expand Down
32 changes: 0 additions & 32 deletions Common/Crypto/sha1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,38 +325,6 @@ void sha1( unsigned char *input, int ilen, unsigned char output[20] )
memset( &ctx, 0, sizeof( sha1_context ) );
}

/*
* output = SHA-1( file contents )
*/
int sha1_file( char *path, unsigned char output[20] )
{
FILE *f;
size_t n;
sha1_context ctx;
unsigned char buf[1024];

if( ( f = fopen( path, "rb" ) ) == NULL )
return( 1 );

sha1_starts( &ctx );

while( ( n = fread( buf, 1, sizeof( buf ), f ) ) > 0 )
sha1_update( &ctx, buf, (int) n );

sha1_finish( &ctx, output );

memset( &ctx, 0, sizeof( sha1_context ) );

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

fclose( f );
return( 0 );
}

/*
* SHA-1 HMAC context setup
*/
Expand Down
32 changes: 28 additions & 4 deletions Common/FileUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#endif
#endif

#include "ppsspp_config.h"

#include "FileUtil.h"
#include "StringUtils.h"

Expand Down Expand Up @@ -121,13 +123,17 @@ bool Exists(const std::string &filename) {
StripTailDirSlashes(fn);

#if defined(_WIN32)
#if PPSSPP_PLATFORM(UWP)
return false;
#else
std::wstring copy = ConvertUTF8ToWString(fn);

// Make sure Windows will no longer handle critical errors, which means no annoying "No disk" dialog
int OldMode = SetErrorMode(SEM_FAILCRITICALERRORS);
bool success = GetFileAttributes(copy.c_str()) != INVALID_FILE_ATTRIBUTES;
SetErrorMode(OldMode);
return success;
#endif
#else
struct stat64 file_info;
return stat64(fn.c_str(), &file_info) == 0;
Expand All @@ -142,11 +148,12 @@ bool IsDirectory(const std::string &filename)

#if defined(_WIN32)
std::wstring copy = ConvertUTF8ToWString(fn);
DWORD result = GetFileAttributes(copy.c_str());
if (result == INVALID_FILE_ATTRIBUTES) {
WIN32_FILE_ATTRIBUTE_DATA data{};
if (!GetFileAttributesEx(copy.c_str(), GetFileExInfoStandard, &data)) {
WARN_LOG(COMMON, "GetFileAttributes failed on %s: %08x", fn.c_str(), GetLastError());
return false;
}
DWORD result = data.dwFileAttributes;
return (result & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY;
#else
std::string copy(fn);
Expand Down Expand Up @@ -328,9 +335,14 @@ bool Copy(const std::string &srcFilename, const std::string &destFilename)
INFO_LOG(COMMON, "Copy: %s --> %s",
srcFilename.c_str(), destFilename.c_str());
#ifdef _WIN32
#if PPSSPP_PLATFORM(UWP)
if (CopyFile2(ConvertUTF8ToWString(srcFilename).c_str(), ConvertUTF8ToWString(destFilename).c_str(), nullptr))
return true;
return false;
#else
if (CopyFile(ConvertUTF8ToWString(srcFilename).c_str(), ConvertUTF8ToWString(destFilename).c_str(), FALSE))
return true;

#endif
ERROR_LOG(COMMON, "Copy: failed %s --> %s: %s",
srcFilename.c_str(), destFilename.c_str(), GetLastErrorMsg());
return false;
Expand Down Expand Up @@ -547,8 +559,13 @@ bool CreateEmptyFile(const std::string &filename)
// Deletes the given directory and anything under it. Returns true on success.
bool DeleteDirRecursively(const std::string &directory)
{
#if PPSSPP_PLATFORM(UWP)
return false;
#else
INFO_LOG(COMMON, "DeleteDirRecursively: %s", directory.c_str());

#ifdef _WIN32

// Find the first file in the directory.
WIN32_FIND_DATA ffd;
HANDLE hFind = FindFirstFile(ConvertUTF8ToWString(directory + "\\*").c_str(), &ffd);
Expand Down Expand Up @@ -613,10 +630,11 @@ bool DeleteDirRecursively(const std::string &directory)
closedir(dirp);
#endif
File::DeleteDir(directory);

return true;
#endif
}


// Create directory and copy contents (does not overwrite existing files)
void CopyDir(const std::string &source_path, const std::string &dest_path)
{
Expand Down Expand Up @@ -653,12 +671,17 @@ void CopyDir(const std::string &source_path, const std::string &dest_path)
else if (!File::Exists(dest)) File::Copy(source, dest);
}
closedir(dirp);
#else
ERROR_LOG(COMMON, "CopyDir not supported on this platform");
#endif
}

void openIniFile(const std::string fileName) {
std::string iniFile;
#if defined(_WIN32)
#if PPSSPP_PLATFORM(UWP)
// Not supported
#else
iniFile = fileName;
// Can't rely on a .txt file extension to auto-open in the right editor,
// so let's find notepad
Expand Down Expand Up @@ -690,6 +713,7 @@ void openIniFile(const std::string fileName) {
}
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
#endif
#elif !defined(MOBILE_DEVICE)
#if defined(__APPLE__)
iniFile = "open ";
Expand Down
8 changes: 8 additions & 0 deletions Common/MemArenaWin32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,20 @@ void MemArena::ReleaseSpace() {

void *MemArena::CreateView(s64 offset, size_t size, void *base) {
size = roundup(size);
#if PPSSPP_PLATFORM(UWP)
// TODO
void *ptr = nullptr;
#else
void *ptr = MapViewOfFileEx(hMemoryMapping, FILE_MAP_ALL_ACCESS, 0, (DWORD)((u64)offset), size, base);
#endif
return ptr;
}

void MemArena::ReleaseView(void* view, size_t size) {
#if PPSSPP_PLATFORM(UWP)
#else
UnmapViewOfFile(view);
#endif
}

bool MemArena::NeedsProbing() {
Expand Down
27 changes: 27 additions & 0 deletions Common/OSVersion.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "ppsspp_config.h"

#ifdef _MSC_VER

Expand All @@ -6,6 +7,12 @@
#include "Common/CommonWindows.h"

bool DoesVersionMatchWindows(uint32_t major, uint32_t minor, uint32_t spMajor, uint32_t spMinor, bool greater) {
#if PPSSPP_PLATFORM(UWP)
if (greater)
return true;
else
return major >= 7;
#else
uint64_t conditionMask = 0;
OSVERSIONINFOEX osvi;
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
Expand All @@ -25,6 +32,26 @@ bool DoesVersionMatchWindows(uint32_t major, uint32_t minor, uint32_t spMajor, u
const uint32_t typeMask = VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR;

return VerifyVersionInfo(&osvi, typeMask, conditionMask) != FALSE;
#endif
}

bool IsVistaOrHigher() {
#if PPSSPP_PLATFORM(UWP)
return true;
#else
OSVERSIONINFOEX osvi;
DWORDLONG dwlConditionMask = 0;
int op = VER_GREATER_EQUAL;
ZeroMemory(&osvi, sizeof(osvi));
osvi.dwOSVersionInfoSize = sizeof(osvi);
osvi.dwMajorVersion = 6; // Vista is 6.0
osvi.dwMinorVersion = 0;

VER_SET_CONDITION(dwlConditionMask, VER_MAJORVERSION, op);
VER_SET_CONDITION(dwlConditionMask, VER_MINORVERSION, op);

return VerifyVersionInfo(&osvi, VER_MAJORVERSION | VER_MINORVERSION, dwlConditionMask) != FALSE;
#endif
}

std::string GetWindowsVersion() {
Expand Down
1 change: 1 addition & 0 deletions Common/OSVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#ifdef _MSC_VER

bool IsVistaOrHigher();
bool DoesVersionMatchWindows(uint32_t major, uint32_t minor, uint32_t spMajor, uint32_t spMinor, bool acceptGreater);
std::string GetWindowsVersion();
std::string GetWindowsSystemArchitecture();
Expand Down
4 changes: 4 additions & 0 deletions Common/StringUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@


void truncate_cpy(char *dest, size_t destSize, const char *src);
template<size_t Count>
inline void truncate_cpy(char(&out)[Count], const char *src) {
truncate_cpy(out, Count, src);
}

long parseHexLong(std::string s);
long parseLong(std::string s);
Expand Down
Loading

0 comments on commit 49a37e9

Please sign in to comment.