Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add winuwp build support #112

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions minimp3_ex.h
Original file line number Diff line number Diff line change
Expand Up @@ -1173,7 +1173,7 @@ static int mp3dec_open_file_h(HANDLE file, mp3dec_map_info_t *map_info)

HANDLE mapping = NULL;
LARGE_INTEGER s;
s.LowPart = GetFileSize(file, (DWORD*)&s.HighPart);
s.LowPart = GetFileSizeEx(file, &s);
if (s.LowPart == INVALID_FILE_SIZE && GetLastError() != NO_ERROR)
goto error;
map_info->size = s.QuadPart;
Expand All @@ -1193,12 +1193,28 @@ static int mp3dec_open_file_h(HANDLE file, mp3dec_map_info_t *map_info)
CloseHandle(file);
return MP3D_E_IOERROR;
}

#if !defined(WINAPI_FAMILY) || WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP
#define __mp3dec_create_file(path, omode, smode, cflags) CreateFileW(path, omode, smode, nullptr, cflags, 0, nullptr)
#else
#define __mp3dec_create_file(path, omode, smode, cflags) CreateFile2(path, omode, smode, cflags, nullptr)
#endif
static int mp3dec_open_file(const char *file_name, mp3dec_map_info_t *map_info)
{
if (!file_name)
return MP3D_E_PARAM;
HANDLE file = CreateFileA(file_name, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
int cch = ::MultiByteToWideChar(CP_UTF8, 0, file_name, -1, NULL, 0);
if (cch < 2)
return MP3D_E_PARAM;
wchar_t* file_name_w = (wchar_t*)malloc(cch * sizeof(wchar_t*));
if (!file_name_w)
return MP3D_E_MEMORY;
if (::MultiByteToWideChar(CP_UTF8, 0, file_name, cch, file_name_w, cch) != cch)
{
free(file_name_w);
return MP3D_E_PARAM;
}
HANDLE file = __mp3dec_create_file(file_name_w, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING);
free(file_name_w);
if (INVALID_HANDLE_VALUE == file)
return MP3D_E_IOERROR;
return mp3dec_open_file_h(file, map_info);
Expand All @@ -1208,7 +1224,7 @@ static int mp3dec_open_file_w(const wchar_t *file_name, mp3dec_map_info_t *map_i
{
if (!file_name)
return MP3D_E_PARAM;
HANDLE file = CreateFileW(file_name, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
HANDLE file = __mp3dec_create_file(file_name, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING);
if (INVALID_HANDLE_VALUE == file)
return MP3D_E_IOERROR;
return mp3dec_open_file_h(file, map_info);
Expand Down