Commit b5254a96 authored by Ghislain MARY's avatar Ghislain MARY

Fix build for Windows 10.

parent 97fed78c
......@@ -128,27 +128,31 @@ static const codepage CodePage[] =
static NOINLINE UINT GetCodePage(const tchar_t* Name, bool_t To)
{
if (Name && Name[0])
{
const codepage* i;
int CP;
if (stscanf(Name,T("CP%d"),&CP)==1 ||
stscanf(Name,T("windows-%d"),&CP)==1)
return CP;
for (i=CodePage;i->Name;++i)
if (tcsisame_ascii(Name,i->Name))
{
if (IsValidCodePage(i->CodePage))
return i->CodePage;
if (i->CodePage2 && IsValidCodePage(i->CodePage2))
return i->CodePage2;
break;
}
}
if (To)
if (Name && Name[0])
{
const codepage* i;
int CP;
if (stscanf(Name, T("CP%d"), &CP) == 1 ||
stscanf(Name, T("windows-%d"), &CP) == 1)
return CP;
for (i = CodePage;i->Name;++i)
if (tcsisame_ascii(Name, i->Name))
{
if (IsValidCodePage(i->CodePage))
return i->CodePage;
if (i->CodePage2 && IsValidCodePage(i->CodePage2))
return i->CodePage2;
break;
}
}
if (To)
#ifndef WINDOWS_DESKTOP
return CP_OEMCP;
#else
return GetOEMCP();
#endif
else
return CP_ACP;
}
......
......@@ -58,7 +58,11 @@ systick_t GetTimeTick()
#else
systick_t GetTimeTick()
{
#ifndef WINDOWS_DESKTOP
return (systick_t)GetTickCount64();
#else
return timeGetTime();
#endif
}
#endif
......
......@@ -47,10 +47,24 @@
#define FOF_NO_UI (0x04|0x10|0x400|0x200)
#endif
#if defined(__MINGW32__) || !defined(WINAPI_FAMILY_PARTITION) || !defined(WINAPI_PARTITION_DESKTOP)
#define WINDOWS_DESKTOP 1
#elif defined(WINAPI_FAMILY_PARTITION)
#if defined(WINAPI_PARTITION_DESKTOP) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
#define WINDOWS_DESKTOP 1
#elif defined(WINAPI_PARTITION_PHONE_APP) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP)
#define WINDOWS_PHONE 1
#elif defined(WINAPI_PARTITION_APP) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
#define WINDOWS_UNIVERSAL 1
#endif
#endif
#if defined(TARGET_WINCE)
static HMODULE CEShellDLL = NULL;
#endif
#ifdef WINDOWS_DESKTOP
static int (WINAPI* FuncSHFileOperation)(SHFILEOPSTRUCT*) = NULL;
#endif
#ifndef ERROR_INVALID_DRIVE_OBJECT
#define ERROR_INVALID_DRIVE_OBJECT 4321L
......@@ -88,10 +102,17 @@ static filepos_t SetFilePointerFP(HANDLE hFile, filepos_t DistanceToMove, DWORD
li.QuadPart = DistanceToMove;
#ifndef WINDOWS_DESKTOP
BOOL ret = SetFilePointerEx(hFile, li, &li, dwMoveMethod);
if (ret == FALSE)
return -1;
#else
li.LowPart = SetFilePointer(hFile, li.LowPart, &li.HighPart, dwMoveMethod);
if (li.LowPart == INVALID_SET_FILE_POINTER && GetLastError() != NO_ERROR)
return -1;
#endif
return (filepos_t)li.QuadPart;
}
......@@ -114,10 +135,17 @@ static err_t Open(filestream* p, const tchar_t* URL, int Flags)
DWORD FileSizeHigh;
HANDLE Handle;
Handle = CreateFile(URL,((Flags & SFLAG_RDONLY || !(Flags & SFLAG_WRONLY))?GENERIC_READ:0)|
#ifndef WINDOWS_DESKTOP
Handle = CreateFile2(URL, ((Flags & SFLAG_RDONLY || !(Flags & SFLAG_WRONLY)) ? GENERIC_READ : 0) |
((Flags & SFLAG_WRONLY || !(Flags & SFLAG_RDONLY)) ? GENERIC_WRITE : 0),
FILE_SHARE_READ | FILE_SHARE_WRITE, (Flags & SFLAG_CREATE) ? CREATE_ALWAYS : OPEN_EXISTING,
NULL);
#else
Handle = CreateFile(URL,((Flags & SFLAG_RDONLY || !(Flags & SFLAG_WRONLY))?GENERIC_READ:0)|
((Flags & SFLAG_WRONLY || !(Flags & SFLAG_RDONLY))?GENERIC_WRITE:0),
FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,(Flags & SFLAG_CREATE)?CREATE_ALWAYS:OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,NULL);
#endif
if (Handle == INVALID_HANDLE_VALUE)
{
......@@ -135,7 +163,16 @@ static err_t Open(filestream* p, const tchar_t* URL, int Flags)
p->Flags = Flags & ~SFLAG_REOPEN;
p->Handle = Handle;
#ifndef WINDOWS_DESKTOP
{
WIN32_FILE_ATTRIBUTE_DATA attr_data;
GetFileAttributesEx(URL, GetFileExInfoStandard, &attr_data);
FileSizeLow = attr_data.nFileSizeLow;
FileSizeHigh = attr_data.nFileSizeHigh;
}
#else
FileSizeLow = GetFileSize(Handle,&FileSizeHigh);
#endif
if (FileSizeLow != INVALID_FILE_SIZE || GetLastError()==NO_ERROR)
p->Length = (filepos_t)(((int64_t)FileSizeHigh << 32) | FileSizeLow);
......@@ -341,7 +378,11 @@ static err_t SetLength(filestream* p,dataid UNUSED_PARAM(Id),const filepos_t* Da
static err_t OpenDir(filestream* p,const tchar_t* URL,int UNUSED_PARAM(Flags))
{
#ifndef WINDOWS_DESKTOP
WIN32_FILE_ATTRIBUTE_DATA attr_data;
#else
DWORD Attrib;
#endif
tchar_t Path[MAXPATHFULL];
if (p->Find != INVALID_HANDLE_VALUE)
......@@ -359,17 +400,30 @@ static err_t OpenDir(filestream* p,const tchar_t* URL,int UNUSED_PARAM(Flags))
else
#endif
{
#ifndef WINDOWS_DESKTOP
if (GetFileAttributesEx(URL, GetFileExInfoStandard, &attr_data) == 0)
return ERR_FILE_NOT_FOUND;
if (!(attr_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
return ERR_NOT_DIRECTORY;
#else
Attrib = GetFileAttributes(URL);
if (Attrib == (DWORD)-1)
return ERR_FILE_NOT_FOUND;
if (!(Attrib & FILE_ATTRIBUTE_DIRECTORY))
return ERR_NOT_DIRECTORY;
#endif
tcscpy_s(Path,TSIZEOF(Path),URL);
AddPathDelimiter(Path,TSIZEOF(Path));
tcscat_s(Path,TSIZEOF(Path),T("*.*"));
#ifndef WINDOWS_DESKTOP
WIN32_FIND_DATA FileData;
p->Find = FindFirstFileEx(Path, FindExInfoStandard, &FileData, FindExSearchNameMatch, NULL, 0);
#else
p->Find = FindFirstFile(Path, &p->FindData);
#endif
}
return ERR_NONE;
......@@ -382,7 +436,7 @@ static err_t EnumDir(filestream* p,const tchar_t* Exts,bool_t ExtFilter,streamdi
Item->FileName[0] = 0;
Item->DisplayName[0] = 0;
#if !defined(TARGET_WINCE)
#if !defined(TARGET_WINCE) && defined(WINDOWS_DESKTOP)
if (p->DriveNo>=0)
{
size_t n = GetLogicalDriveStrings(0,NULL);
......@@ -468,7 +522,7 @@ static err_t CreateFunc(node* UNUSED_PARAM(p))
CEShellDLL = LoadLibrary(T("ceshell.dll"));
if (CEShellDLL)
*(FARPROC*)(void*)&FuncSHFileOperation = GetProcAddress(CEShellDLL,MAKEINTRESOURCE(14));
#else
#elif defined(WINDOWS_DESKTOP)
FuncSHFileOperation = SHFileOperation;
#endif
......@@ -514,9 +568,15 @@ bool_t FolderCreate(nodecontext* UNUSED_PARAM(p),const tchar_t* Path)
bool_t FileExists(nodecontext* UNUSED_PARAM(p),const tchar_t* Path)
{
#ifndef WINDOWS_DESKTOP
WIN32_FILE_ATTRIBUTE_DATA attr_data;
return GetFileAttributesEx(Path, GetFileExInfoStandard, &attr_data) != 0;
#else
return GetFileAttributes(Path) != (DWORD)-1;
#endif
}
#ifdef WINDOWS_DESKTOP
static bool_t FileRecycle(const tchar_t* Path)
{
tchar_t PathEnded[MAXPATHFULL];
......@@ -534,47 +594,77 @@ static bool_t FileRecycle(const tchar_t* Path)
Ret = FuncSHFileOperation(&DelStruct);
return Ret == 0;
}
#endif
bool_t FileErase(nodecontext* UNUSED_PARAM(p),const tchar_t* Path, bool_t Force, bool_t Safe)
{
if (Force)
{
DWORD attr = GetFileAttributes(Path);
#ifndef WINDOWS_DESKTOP
WIN32_FILE_ATTRIBUTE_DATA attr_data;
if ((GetFileAttributesEx(Path, GetFileExInfoStandard, &attr_data) != 0) && (attr_data.dwFileAttributes & FILE_ATTRIBUTE_READONLY)) {
attr_data.dwFileAttributes ^= FILE_ATTRIBUTE_READONLY;
SetFileAttributes(Path, attr_data.dwFileAttributes);
}
#else
DWORD attr = GetFileAttributes(Path);
if ((attr != (DWORD)-1) && (attr & FILE_ATTRIBUTE_READONLY))
{
attr ^= FILE_ATTRIBUTE_READONLY;
SetFileAttributes(Path,attr);
}
#endif
}
#ifndef WINDOWS_DESKTOP
return DeleteFile(Path) != FALSE;
#else
if (!Safe || !FuncSHFileOperation)
return DeleteFile(Path) != FALSE;
else
return FileRecycle(Path);
#endif
}
bool_t FolderErase(nodecontext* UNUSED_PARAM(p),const tchar_t* Path, bool_t Force, bool_t Safe)
{
if (Force)
{
#ifndef WINDOWS_DESKTOP
WIN32_FILE_ATTRIBUTE_DATA attr_data;
if ((GetFileAttributesEx(Path, GetFileExInfoStandard, &attr_data) != 0) && (attr_data.dwFileAttributes & FILE_ATTRIBUTE_READONLY)) {
attr_data.dwFileAttributes ^= FILE_ATTRIBUTE_READONLY;
SetFileAttributes(Path, attr_data.dwFileAttributes);
}
#else
DWORD attr = GetFileAttributes(Path);
if ((attr != (DWORD)-1) && (attr & FILE_ATTRIBUTE_READONLY))
{
attr ^= FILE_ATTRIBUTE_READONLY;
SetFileAttributes(Path,attr);
}
#endif
}
#ifndef WINDOWS_DESKTOP
return RemoveDirectory(Path) != FALSE;
#else
if (!Safe || !FuncSHFileOperation)
return RemoveDirectory(Path) != FALSE;
else
return FileRecycle(Path);
#endif
}
bool_t PathIsFolder(nodecontext* UNUSED_PARAM(p),const tchar_t* Path)
{
DWORD attr = GetFileAttributes(Path);
#ifndef WINDOWS_DESKTOP
WIN32_FILE_ATTRIBUTE_DATA attr_data;
return (GetFileAttributesEx(Path, GetFileExInfoStandard, &attr_data) != 0) && ((attr_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY);
#else
DWORD attr = GetFileAttributes(Path);
return (attr != (DWORD)-1) && (attr & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY;
#endif
}
datetime_t FileDateTime(nodecontext* UNUSED_PARAM(p),const tchar_t* Path)
......@@ -583,7 +673,12 @@ datetime_t FileDateTime(nodecontext* UNUSED_PARAM(p),const tchar_t* Path)
HANDLE Find;
WIN32_FIND_DATA FindData;
#ifndef WINDOWS_DESKTOP
WIN32_FIND_DATA FileData;
Find = FindFirstFileEx(Path, FindExInfoStandard, &FileData, FindExSearchNameMatch, NULL, 0);
#else
Find = FindFirstFile(Path, &FindData);
#endif
if (Find != INVALID_HANDLE_VALUE)
{
Date = FileTimeToRel(&FindData.ftLastWriteTime);
......@@ -594,7 +689,11 @@ datetime_t FileDateTime(nodecontext* UNUSED_PARAM(p),const tchar_t* Path)
bool_t FileMove(nodecontext* UNUSED_PARAM(p),const tchar_t* In,const tchar_t* Out)
{
#ifndef WINDOWS_DESKTOP
return MoveFileEx(In, Out, 0);
#else
return MoveFile(In,Out) != 0;
#endif
}
void FindFiles(nodecontext* UNUSED_PARAM(p),const tchar_t* Path, const tchar_t* Mask, void(*Process)(const tchar_t*,void*),void* Param)
......@@ -605,7 +704,12 @@ void FindFiles(nodecontext* UNUSED_PARAM(p),const tchar_t* Path, const tchar_t*
tcscpy_s(FindPath,TSIZEOF(FindPath),Path);
tcscat_s(FindPath,TSIZEOF(FindPath),Mask);
#ifndef WINDOWS_DESKTOP
WIN32_FIND_DATA FileData;
Find = FindFirstFileEx(Path, FindExInfoStandard, &FileData, FindExSearchNameMatch, NULL, 0);
#else
Find = FindFirstFile(FindPath,&FindData);
#endif
if (Find != INVALID_HANDLE_VALUE)
{
......
......@@ -32,8 +32,21 @@
#include <windows.h>
#if defined(__MINGW32__) || !defined(WINAPI_FAMILY_PARTITION) || !defined(WINAPI_PARTITION_DESKTOP)
#define WINDOWS_DESKTOP 1
#elif defined(WINAPI_FAMILY_PARTITION)
#if defined(WINAPI_PARTITION_DESKTOP) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
#define WINDOWS_DESKTOP 1
#elif defined(WINAPI_PARTITION_PHONE_APP) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP)
#define WINDOWS_PHONE 1
#elif defined(WINAPI_PARTITION_APP) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
#define WINDOWS_UNIVERSAL 1
#endif
#endif
int RunCommand(anynode *p, const tchar_t *Cmd, const tchar_t *CmdParams, bool_t Silent)
{
#ifdef WINDOWS_DESKTOP
STARTUPINFO si;
PROCESS_INFORMATION pi;
DWORD returnCode;
......@@ -52,4 +65,7 @@ int RunCommand(anynode *p, const tchar_t *Cmd, const tchar_t *CmdParams, bool_t
while (GetExitCodeProcess(pi.hProcess, &returnCode) && returnCode==STILL_ACTIVE)
Sleep(100);
return (int)returnCode;
#else
return 0;
#endif
}
......@@ -42,9 +42,25 @@
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#if defined(__MINGW32__) || !defined(WINAPI_FAMILY_PARTITION) || !defined(WINAPI_PARTITION_DESKTOP)
#define WINDOWS_DESKTOP 1
#elif defined(WINAPI_FAMILY_PARTITION)
#if defined(WINAPI_PARTITION_DESKTOP) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
#define WINDOWS_DESKTOP 1
#elif defined(WINAPI_PARTITION_PHONE_APP) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP)
#define WINDOWS_PHONE 1
#elif defined(WINAPI_PARTITION_APP) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
#define WINDOWS_UNIVERSAL 1
#endif
#endif
int tcsicmp(const tchar_t* a,const tchar_t* b)
{
#ifndef WINDOWS_DESKTOP
int i = CompareStringEx(LOCALE_NAME_USER_DEFAULT, NORM_IGNORECASE, a, -1, b, -1, NULL, NULL, 0);
#else
int i = CompareString(LOCALE_USER_DEFAULT,NORM_IGNORECASE,a,-1,b,-1);
#endif
if (i)
return i-CSTR_EQUAL;
......@@ -58,7 +74,11 @@ int tcsicmp(const tchar_t* a,const tchar_t* b)
int tcsnicmp(const tchar_t* a,const tchar_t* b,size_t n)
{
int i = CompareString(LOCALE_USER_DEFAULT,NORM_IGNORECASE,a,min(tcslen(a),n),b,min(tcslen(b),n));
#ifndef WINDOWS_DESKTOP
int i = CompareStringEx(LOCALE_NAME_USER_DEFAULT, NORM_IGNORECASE, a, min(tcslen(a), n), b, min(tcslen(b), n), NULL, NULL, 0);
#else
int i = CompareString(LOCALE_USER_DEFAULT,NORM_IGNORECASE,a,min(tcslen(a),n),b,min(tcslen(b),n));
#endif
if (i)
return i-CSTR_EQUAL;
......@@ -72,7 +92,11 @@ int tcsnicmp(const tchar_t* a,const tchar_t* b,size_t n)
int tcscmp(const tchar_t* a,const tchar_t* b)
{
int i = CompareString(LOCALE_USER_DEFAULT,0,a,-1,b,-1);
#ifndef WINDOWS_DESKTOP
int i = CompareStringEx(LOCALE_NAME_USER_DEFAULT, 0, a, -1, b, -1, NULL, NULL, 0);
#else
int i = CompareString(LOCALE_USER_DEFAULT,0,a,-1,b,-1);
#endif
if (i)
return i-CSTR_EQUAL;
......@@ -86,7 +110,11 @@ int tcscmp(const tchar_t* a,const tchar_t* b)
int tcsncmp(const tchar_t* a,const tchar_t* b,size_t n)
{
int i = CompareString(LOCALE_USER_DEFAULT,0,a,min(tcslen(a),n),b,min(tcslen(b),n));
#ifndef WINDOWS_DESKTOP
int i = CompareStringEx(LOCALE_NAME_USER_DEFAULT, 0, a, min(tcslen(a), n), b, min(tcslen(b), n), NULL, NULL, 0);
#else
int i = CompareString(LOCALE_USER_DEFAULT,0,a,min(tcslen(a),n),b,min(tcslen(b),n));
#endif
if (i)
return i-CSTR_EQUAL;
......@@ -100,8 +128,12 @@ int tcsncmp(const tchar_t* a,const tchar_t* b,size_t n)
tchar_t* TcsToUpper(tchar_t* Out,size_t OutLen,const tchar_t* In)
{
#ifndef WINDOWS_DESKTOP
if (LCMapStringEx(LOCALE_NAME_USER_DEFAULT, LCMAP_UPPERCASE, In, -1, Out, OutLen, NULL, NULL, 0))
#else
if (LCMapString(LOCALE_USER_DEFAULT,LCMAP_UPPERCASE,In,-1,Out,OutLen))
return Out;
#endif
return Out;
// fallback
if (OutLen)
......
......@@ -293,7 +293,7 @@ static err_t ReadData(ebml_master *Element, stream *Input, const ebml_parser_con
{
int UpperEltFound = 0;
bool_t bFirst = 1;
ebml_element *SubElement;
ebml_element *SubElement = NULL;
ebml_crc *CRCElement = NULL;
stream *ReadStream = Input;
array CrcBuffer;
......
......@@ -81,8 +81,7 @@ static err_t ReadData(ebml_string *Element, stream *Input, const ebml_parser_con
if (Stream_Seek(Input,EBML_ElementPositionData((ebml_element*)Element),SEEK_SET)==INVALID_FILEPOS_T)
{
Result = ERR_READ;
goto failed;
return ERR_READ;
}
Buffer = malloc((size_t)Element->Base.DataSize+1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment