Skip to content

Commit

Permalink
libhb: remove UTF-8 to Windows code page conversion, it's not needed …
Browse files Browse the repository at this point in the history
…anymore in recent libdvdread versions.
  • Loading branch information
galad87 committed Jan 18, 2023
1 parent b65d4c6 commit 61d7fc0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 65 deletions.
16 changes: 3 additions & 13 deletions libhb/dvd.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,21 +113,13 @@ hb_dvd_t * hb_dvdread_init( hb_handle_t * h, const char * path )
hb_dvd_t * e;
hb_dvdread_t * d;
int region_mask;
char * path_ccp;

e = calloc( sizeof( hb_dvd_t ), 1 );
d = &(e->dvdread);
d->h = h;

/*
* Convert UTF-8 path to current code page on Windows
* hb_utf8_to_cp() is the same as strdup on non-Windows,
* so no #ifdef required here
*/
path_ccp = hb_utf8_to_cp( path );

/* Log DVD drive region code */
if ( hb_dvd_region( path_ccp, &region_mask ) == 0 )
if ( hb_dvd_region( path, &region_mask ) == 0 )
{
hb_log( "dvd: Region mask 0x%02x", region_mask );
if ( region_mask == 0xFF )
Expand All @@ -137,7 +129,7 @@ hb_dvd_t * hb_dvdread_init( hb_handle_t * h, const char * path )
}

/* Open device */
if( !( d->reader = DVDOpen( path_ccp ) ) )
if( !( d->reader = DVDOpen( path ) ) )
{
/*
* Not an error, may be a stream - which we'll try in a moment.
Expand All @@ -153,16 +145,14 @@ hb_dvd_t * hb_dvdread_init( hb_handle_t * h, const char * path )
goto fail;
}

d->path = strdup( path ); /* hb_dvdread_title_scan assumes UTF-8 path, so not path_ccp here */
free( path_ccp );
d->path = strdup( path );

return e;

fail:
if( d->vmg ) ifoClose( d->vmg );
if( d->reader ) DVDClose( d->reader );
free( e );
free( path_ccp );
return NULL;
}

Expand Down
24 changes: 5 additions & 19 deletions libhb/dvdnav.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,11 @@ static char * hb_dvdnav_name( char * path )
**********************************************************************/
static int hb_dvdnav_reset( hb_dvdnav_t * d )
{
char * path_ccp = hb_utf8_to_cp( d->path );
if ( d->dvdnav )
dvdnav_close( d->dvdnav );

/* Open device */
if( dvdnav_open(&d->dvdnav, path_ccp) != DVDNAV_STATUS_OK )
if( dvdnav_open(&d->dvdnav, d->path) != DVDNAV_STATUS_OK )
{
/*
* Not an error, may be a stream - which we'll try in a moment.
Expand Down Expand Up @@ -137,13 +136,10 @@ static int hb_dvdnav_reset( hb_dvdnav_t * d )
goto fail;
}

free( path_ccp );

return 1;

fail:
if( d->dvdnav ) dvdnav_close( d->dvdnav );
free( path_ccp );
return 0;
}

Expand All @@ -157,21 +153,13 @@ static hb_dvd_t * hb_dvdnav_init( hb_handle_t * h, const char * path )
hb_dvd_t * e;
hb_dvdnav_t * d;
int region_mask;
char * path_ccp;

e = calloc( sizeof( hb_dvd_t ), 1 );
d = &(e->dvdnav);
d->h = h;

/*
* Convert UTF-8 path to current code page on Windows
* hb_utf8_to_cp() is the same as strdup on non-Windows,
* so no #ifdef required here
*/
path_ccp = hb_utf8_to_cp( path );

/* Log DVD drive region code */
if ( hb_dvd_region( path_ccp, &region_mask ) == 0 )
if ( hb_dvd_region( path, &region_mask ) == 0 )
{
hb_log( "dvd: Region mask 0x%02x", region_mask );
if ( region_mask == 0xFF )
Expand All @@ -181,7 +169,7 @@ static hb_dvd_t * hb_dvdnav_init( hb_handle_t * h, const char * path )
}

/* Open device */
if( dvdnav_open(&d->dvdnav, path_ccp) != DVDNAV_STATUS_OK )
if( dvdnav_open(&d->dvdnav, path) != DVDNAV_STATUS_OK )
{
/*
* Not an error, may be a stream - which we'll try in a moment.
Expand Down Expand Up @@ -211,7 +199,7 @@ static hb_dvd_t * hb_dvdnav_init( hb_handle_t * h, const char * path )
}

/* Open device */
if( !( d->reader = DVDOpen( path_ccp ) ) )
if( !( d->reader = DVDOpen( path ) ) )
{
/*
* Not an error, may be a stream - which we'll try in a moment.
Expand All @@ -227,8 +215,7 @@ static hb_dvd_t * hb_dvdnav_init( hb_handle_t * h, const char * path )
goto fail;
}

d->path = strdup( path ); /* hb_dvdnav_title_scan assumes UTF-8 path, so not path_ccp here */
free( path_ccp );
d->path = strdup( path );

return e;

Expand All @@ -237,7 +224,6 @@ static hb_dvd_t * hb_dvdnav_init( hb_handle_t * h, const char * path )
if( d->vmg ) ifoClose( d->vmg );
if( d->reader ) DVDClose( d->reader );
free( e );
free( path_ccp );
return NULL;
}

Expand Down
5 changes: 1 addition & 4 deletions libhb/handbrake/ports.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,12 @@ size_t hb_getline(char **lineptr, size_t *n, FILE *fp);

#ifdef __LIBHB__

// Convert utf8 string to current code page.
char * hb_utf8_to_cp(const char *src);

/* Everything from now is only used internally and hidden to the UI */

/************************************************************************
* DVD utils
***********************************************************************/
int hb_dvd_region(char *device, int *region_mask);
int hb_dvd_region(const char *device, int *region_mask);

#if defined( SYS_DARWIN )
int macOS_get_user_config_directory( char path[512] );
Expand Down
30 changes: 1 addition & 29 deletions libhb/ports.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,35 +109,7 @@ int gettimeofday( struct timeval * tv, struct timezone * tz )
#endif
*/

// Convert utf8 string to current code page.
// The internal string representation in hb is utf8. But some
// libraries (libmkv, and mp4v2) expect filenames in the current
// code page. So we must convert.
char * hb_utf8_to_cp(const char *src)
{
char *dst = NULL;

#if defined( SYS_MINGW )
int num_chars = MultiByteToWideChar(CP_UTF8, 0, src, -1, NULL, 0);
if (num_chars <= 0)
return NULL;
wchar_t * tmp = calloc(num_chars, sizeof(wchar_t));
MultiByteToWideChar(CP_UTF8, 0, src, -1, tmp, num_chars);
int len = WideCharToMultiByte(GetACP(), 0, tmp, num_chars, NULL, 0, NULL, NULL);
if (len <= 0)
return NULL;
dst = calloc(len, sizeof(char));
WideCharToMultiByte(GetACP(), 0, tmp, num_chars, dst, len, NULL, NULL);
free(tmp);
#else
// Other platforms don't have code pages
dst = strdup(src);
#endif

return dst;
}

int hb_dvd_region(char *device, int *region_mask)
int hb_dvd_region(const char *device, int *region_mask)
{
#if defined( DVD_LU_SEND_RPC_STATE ) && defined( DVD_AUTH )
struct stat st;
Expand Down

0 comments on commit 61d7fc0

Please sign in to comment.