Skip to content

Commit

Permalink
v1.1.4 (#150)
Browse files Browse the repository at this point in the history
* closes #49
* closes #60
* closes #64
* should address #59
* set default doe ISOs with bot bootmgr and isolinux to syslinux
* other improvements
  • Loading branch information
pbatard committed Mar 3, 2012
1 parent a9c47a4 commit 7ee5b35
Show file tree
Hide file tree
Showing 11 changed files with 233 additions and 149 deletions.
27 changes: 11 additions & 16 deletions src/format.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ static BOOL ClearMBR(HANDLE hPhysicalDrive)
static BOOL WriteMBR(HANDLE hPhysicalDrive)
{
BOOL r = FALSE;
int dt, fs;
unsigned char* buf = NULL;
size_t SecSize = SelectedDrive.Geometry.BytesPerSector;
size_t nSecs = (0x200 + SecSize -1) / SecSize;
Expand Down Expand Up @@ -367,7 +368,9 @@ static BOOL WriteMBR(HANDLE hPhysicalDrive)

fake_fd._ptr = (char*)hPhysicalDrive;
fake_fd._bufsiz = SelectedDrive.Geometry.BytesPerSector;
if (ComboBox_GetItemData(hDOSType, ComboBox_GetCurSel(hDOSType)) == DT_ISO_FAT) {
fs = (int)ComboBox_GetItemData(hFileSystem, ComboBox_GetCurSel(hFileSystem));
dt = (int)ComboBox_GetItemData(hDOSType, ComboBox_GetCurSel(hDOSType));
if ((dt == DT_ISO) && ((fs == FS_FAT16) || (fs == FS_FAT32))) {
r = write_syslinux_mbr(&fake_fd);
} else {
r = write_95b_mbr(&fake_fd);
Expand Down Expand Up @@ -484,7 +487,7 @@ DWORD WINAPI FormatThread(LPVOID param)
char bb_msg[512];
char logfile[MAX_PATH], *userdir;
FILE* log_fd;
int r;
int r, fs, dt;

hPhysicalDrive = GetDriveHandle(num, NULL, TRUE, TRUE);
if (hPhysicalDrive == INVALID_HANDLE_VALUE) {
Expand Down Expand Up @@ -601,11 +604,10 @@ DWORD WINAPI FormatThread(LPVOID param)
}
UpdateProgress(OP_FIX_MBR, -1.0f);

fs = (int)ComboBox_GetItemData(hFileSystem, ComboBox_GetCurSel(hFileSystem));
dt = (int)ComboBox_GetItemData(hDOSType, ComboBox_GetCurSel(hDOSType));
if (IsChecked(IDC_DOS)) {
switch(ComboBox_GetItemData(hDOSType, ComboBox_GetCurSel(hDOSType))) {
case DT_WINME:
case DT_FREEDOS:
case DT_ISO_NTFS:
if ((dt == DT_WINME) || (dt == DT_FREEDOS) || ((dt == DT_ISO) && (fs == FS_NTFS))) {
// We still have a lock, which we need to modify the volume boot record
// => no need to reacquire the lock...
hLogicalVolume = GetDriveHandle(num, drive_name, TRUE, FALSE);
Expand All @@ -624,13 +626,11 @@ DWORD WINAPI FormatThread(LPVOID param)
}
// We must close and unlock the volume to write files to it
safe_unlockclose(hLogicalVolume);
break;
case DT_ISO_FAT:
} else if ((dt == DT_ISO) && ((fs == FS_FAT16) || (fs == FS_FAT32))) {
PrintStatus(0, TRUE, "Installing Syslinux...");
if (!InstallSyslinux(num, drive_name)) {
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_INSTALL_FAILURE;
}
break;
}
} else {
if (IsChecked(IDC_SET_ICON))
Expand All @@ -645,18 +645,14 @@ DWORD WINAPI FormatThread(LPVOID param)

if (IsChecked(IDC_DOS)) {
UpdateProgress(OP_DOS, -1.0f);
switch(ComboBox_GetItemData(hDOSType, ComboBox_GetCurSel(hDOSType))) {
case DT_WINME:
case DT_FREEDOS:
if ((dt == DT_WINME) || (dt == DT_FREEDOS)) {
PrintStatus(0, TRUE, "Copying DOS files...");
if (!ExtractDOS(drive_name)) {
if (!FormatStatus)
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_CANNOT_COPY;
goto out;
}
break;
case DT_ISO_NTFS:
case DT_ISO_FAT:
} else if (dt == DT_ISO) {
if (iso_path != NULL) {
PrintStatus(0, TRUE, "Copying ISO files...");
drive_name[2] = 0;
Expand All @@ -666,7 +662,6 @@ DWORD WINAPI FormatThread(LPVOID param)
goto out;
}
}
break;
}
if (IsChecked(IDC_SET_ICON))
SetAutorun(drive_name);
Expand Down
4 changes: 2 additions & 2 deletions src/iso.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ static int udf_extract_files(udf_t *p_udf, udf_dirent_t *p_udf_dirent, const cha
goto out;
}
if (udf_is_dir(p_udf_dirent)) {
if (!scan_only) _mkdir(psz_fullpath);
if (!scan_only) _mkdirU(psz_fullpath);
p_udf_dirent2 = udf_opendir(p_udf_dirent);
if (p_udf_dirent2 != NULL) {
if (udf_extract_files(p_udf, p_udf_dirent2, &psz_fullpath[strlen(psz_extract_dir)]))
Expand Down Expand Up @@ -287,7 +287,7 @@ static int iso_extract_files(iso9660_t* p_iso, const char *psz_path)
continue;
iso9660_name_translate_ext(p_statbuf->filename, psz_basename, i_joliet_level);
if (p_statbuf->type == _STAT_DIR) {
if (!scan_only) _mkdir(psz_fullpath);
if (!scan_only) _mkdirU(psz_fullpath);
if (iso_extract_files(p_iso, psz_iso_name))
goto out;
} else {
Expand Down
6 changes: 6 additions & 0 deletions src/libcdio/cdio/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ _cdio_memdup (const void *mem, size_t count);
char *
_cdio_strdup_upper (const char str[]);

/* Duplicate path and make it platform compliant. Typically needed for
MinGW/MSYS where a "/c/..." path must be translated to "c:/..." for
use with fopen(), etc. Returned string must be freed by the caller. */
char *
_cdio_strdup_fixpath (const char path[]);

void
_cdio_strfreev(char **strv);

Expand Down
55 changes: 40 additions & 15 deletions src/libcdio/driver/_cdio_stdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,43 @@
#define CDIO_FSEEK fseek
#endif

/* Windows'd fopen is not UTF-8 compliant - make it so */
#if !defined(_WIN32)
#define CDIO_FOPEN fopen
#else
#define CDIO_FOPEN fopenU
extern wchar_t* cdio_utf8_to_wchar(const char* str);
static inline FILE* fopenU(const char* filename, const char* mode)
{
FILE* ret = NULL;
wchar_t* wfilename = cdio_utf8_to_wchar(filename);
wchar_t* wmode = cdio_utf8_to_wchar(mode);
ret = _wfopen(wfilename, wmode);
free(wfilename);
free(wmode);
return ret;
}
#endif

/* Use _stati64 if needed, on platforms that don't have transparent LFS support */
#if defined(HAVE__STATI64) && defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64)
#define CDIO_STAT _stati64
#define CDIO_STAT_STRUCT _stati64
#if !defined(_WIN32)
#define CDIO_STAT_CALL _stati64
#else
#define CDIO_STAT_CALL _stati64U
/* Once more, we have to provide an UTF-8 compliant version on Windows */
static inline int _stati64U(const char *path, struct _stati64 *buffer) {
int ret;
wchar_t* wpath = cdio_utf8_to_wchar(path);
ret = _wstati64(wpath, buffer);
free(wpath);
return ret;
}
#endif
#else
#define CDIO_STAT stat
#define CDIO_STAT_STRUCT stat
#define CDIO_STAT_CALL stat
#endif

#define _STRINGIFY(a) #a
Expand All @@ -81,8 +113,8 @@ static int
_stdio_open (void *user_data)
{
_UserData *const ud = user_data;
if ((ud->fd = fopen (ud->pathname, "rb")))

if ((ud->fd = CDIO_FOPEN (ud->pathname, "rb")))
{
ud->fd_buf = calloc (1, CDIO_STDIO_BUFSIZE);
setvbuf (ud->fd, ud->fd_buf, _IOFBF, CDIO_STDIO_BUFSIZE);
Expand Down Expand Up @@ -225,25 +257,18 @@ cdio_stdio_new(const char pathname[])
CdioDataSource_t *new_obj = NULL;
cdio_stream_io_functions funcs = { NULL, NULL, NULL, NULL, NULL, NULL };
_UserData *ud = NULL;
struct CDIO_STAT statbuf;
struct CDIO_STAT_STRUCT statbuf;
char* pathdup;

if (pathname == NULL)
return NULL;

pathdup = strdup(pathname);
/* MinGW may require a translated path */
pathdup = _cdio_strdup_fixpath(pathname);
if (pathdup == NULL)
return NULL;

#ifdef __MINGW32__
/* _stati64 requires using native Windows paths => convert "/c/..." to "c:/..." */
if ((strlen(pathdup) > 3) && (pathdup[0] == '/') && (pathdup[2] == '/') && (isalpha(pathdup[1])))
{
pathdup[0] = pathdup[1];
pathdup[1] = ':';
}
#endif
if (CDIO_STAT (pathdup, &statbuf) == -1)
if (CDIO_STAT_CALL (pathdup, &statbuf) == -1)
{
cdio_warn ("could not retrieve file info for `%s': %s",
pathdup, strerror (errno));
Expand Down
121 changes: 62 additions & 59 deletions src/libcdio/driver/utf8.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
# include "config.h"
#endif

#ifdef HAVE_JOLIET
#ifdef HAVE_STRING_H
# include <string.h>
#endif
Expand All @@ -43,7 +42,66 @@
#include <stdio.h>
#endif

// TODO: also remove the need for iconv on MinGW
/* Windows requires some basic UTF-8 support outside of Joliet */
#if defined(_WIN32)
#include <windows.h>

#define wchar_to_utf8_no_alloc(wsrc, dest, dest_size) \
WideCharToMultiByte(CP_UTF8, 0, wsrc, -1, dest, dest_size, NULL, NULL)
#define utf8_to_wchar_no_alloc(src, wdest, wdest_size) \
MultiByteToWideChar(CP_UTF8, 0, src, -1, wdest, wdest_size)

/*
* Converts an UTF-16 string to UTF8 (allocate returned string)
* Returns NULL on error
*/
char* cdio_wchar_to_utf8(const wchar_t* wstr)
{
int size = 0;
char* str = NULL;

/* Find out the size we need to allocate for our converted string */
size = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL);
if (size <= 1) /* An empty string would be size 1 */
return NULL;

if ((str = (char*)calloc(size, 1)) == NULL)
return NULL;

if (wchar_to_utf8_no_alloc(wstr, str, size) != size) {
free(str);
return NULL;
}

return str;
}

/*
* Converts an UTF8 string to UTF-16 (allocate returned string)
* Returns NULL on error
*/
wchar_t* cdio_utf8_to_wchar(const char* str)
{
int size = 0;
wchar_t* wstr = NULL;

/* Find out the size we need to allocate for our converted string */
size = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0);
if (size <= 1) /* An empty string would be size 1 */
return NULL;

if ((wstr = (wchar_t*)calloc(size, sizeof(wchar_t))) == NULL)
return NULL;

if (utf8_to_wchar_no_alloc(str, wstr, size) != size) {
free(wstr);
return NULL;
}
return wstr;
}
#endif

#ifdef HAVE_JOLIET
#ifdef HAVE_ICONV
#include <iconv.h>
struct cdio_charset_coverter_s
Expand Down Expand Up @@ -210,61 +268,6 @@ bool cdio_charset_to_utf8(char *src, size_t src_len, cdio_utf8_t **dst,
return result;
}
#elif defined(_WIN32)
#include <windows.h>

#define wchar_to_utf8_no_alloc(wsrc, dest, dest_size) \
WideCharToMultiByte(CP_UTF8, 0, wsrc, -1, dest, dest_size, NULL, NULL)
#define utf8_to_wchar_no_alloc(src, wdest, wdest_size) \
MultiByteToWideChar(CP_UTF8, 0, src, -1, wdest, wdest_size)

/*
* Converts an UTF-16 string to UTF8 (allocate returned string)
* Returns NULL on error
*/
static inline char* wchar_to_utf8(const wchar_t* wstr)
{
int size = 0;
char* str = NULL;

/* Find out the size we need to allocate for our converted string */
size = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL);
if (size <= 1) /* An empty string would be size 1 */
return NULL;

if ((str = (char*)calloc(size, 1)) == NULL)
return NULL;

if (wchar_to_utf8_no_alloc(wstr, str, size) != size) {
free(str);
return NULL;
}

return str;
}

/*
* Converts an UTF8 string to UTF-16 (allocate returned string)
* Returns NULL on error
*/
static inline wchar_t* utf8_to_wchar(const char* str)
{
int size = 0;
wchar_t* wstr = NULL;

/* Find out the size we need to allocate for our converted string */
size = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0);
if (size <= 1) /* An empty string would be size 1 */
return NULL;

if ((wstr = (wchar_t*)calloc(size, sizeof(wchar_t))) == NULL)
return NULL;

if (utf8_to_wchar_no_alloc(str, wstr, size) != size) {
free(wstr);
return NULL;
}
return wstr;
}

bool cdio_charset_from_utf8(cdio_utf8_t * src, char ** dst,
int * dst_len, const char * dst_charset)
Expand All @@ -276,7 +279,7 @@ bool cdio_charset_from_utf8(cdio_utf8_t * src, char ** dst,
return false;

/* Eliminate empty strings */
le_dst = utf8_to_wchar(src);
le_dst = cdio_utf8_to_wchar(src);
if ((le_dst == NULL) || (le_dst[0] == 0)) {
free(le_dst);
return false;
Expand Down Expand Up @@ -323,7 +326,7 @@ bool cdio_charset_to_utf8(char *src, size_t src_len, cdio_utf8_t **dst,
((char*)le_src)[2*i+1] = src[2*i];
}
le_src[src_len] = 0;
*dst = wchar_to_utf8(le_src);
*dst = cdio_wchar_to_utf8(le_src);
free(le_src);

return (*dst != NULL);
Expand Down
25 changes: 25 additions & 0 deletions src/libcdio/driver/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
#include "inttypes.h"
#endif

#include <ctype.h>

#include "cdio_assert.h"
#include <cdio/types.h>
#include <cdio/util.h>
Expand Down Expand Up @@ -136,6 +138,29 @@ _cdio_strdup_upper (const char str[])
return new_str;
}

/* Convert MinGW/MSYS paths that start in "/c/..." to "c:/..."
so that they can be used with fopen(), stat(), etc. */
char *
_cdio_strdup_fixpath (const char path[])
{
char *new_path = NULL;

if (path)
{
new_path = strdup (path);
#if defined(_WIN32)
if (new_path && (strlen (new_path) >= 3) && (new_path[0] == '/') &&
(new_path[2] == '/') && (isalpha (new_path[1])))
{
new_path[0] = new_path[1];
new_path[1] = ':';
}
#endif
}

return new_path;
}

uint8_t
cdio_to_bcd8 (uint8_t n)
{
Expand Down
Loading

0 comments on commit 7ee5b35

Please sign in to comment.