Skip to content

Commit 7ee5b35

Browse files
committed
v1.1.4 (#150)
* closes #49 * closes #60 * closes #64 * should address #59 * set default doe ISOs with bot bootmgr and isolinux to syslinux * other improvements
1 parent a9c47a4 commit 7ee5b35

11 files changed

Lines changed: 233 additions & 149 deletions

File tree

src/format.c

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ static BOOL ClearMBR(HANDLE hPhysicalDrive)
314314
static BOOL WriteMBR(HANDLE hPhysicalDrive)
315315
{
316316
BOOL r = FALSE;
317+
int dt, fs;
317318
unsigned char* buf = NULL;
318319
size_t SecSize = SelectedDrive.Geometry.BytesPerSector;
319320
size_t nSecs = (0x200 + SecSize -1) / SecSize;
@@ -367,7 +368,9 @@ static BOOL WriteMBR(HANDLE hPhysicalDrive)
367368

368369
fake_fd._ptr = (char*)hPhysicalDrive;
369370
fake_fd._bufsiz = SelectedDrive.Geometry.BytesPerSector;
370-
if (ComboBox_GetItemData(hDOSType, ComboBox_GetCurSel(hDOSType)) == DT_ISO_FAT) {
371+
fs = (int)ComboBox_GetItemData(hFileSystem, ComboBox_GetCurSel(hFileSystem));
372+
dt = (int)ComboBox_GetItemData(hDOSType, ComboBox_GetCurSel(hDOSType));
373+
if ((dt == DT_ISO) && ((fs == FS_FAT16) || (fs == FS_FAT32))) {
371374
r = write_syslinux_mbr(&fake_fd);
372375
} else {
373376
r = write_95b_mbr(&fake_fd);
@@ -484,7 +487,7 @@ DWORD WINAPI FormatThread(LPVOID param)
484487
char bb_msg[512];
485488
char logfile[MAX_PATH], *userdir;
486489
FILE* log_fd;
487-
int r;
490+
int r, fs, dt;
488491

489492
hPhysicalDrive = GetDriveHandle(num, NULL, TRUE, TRUE);
490493
if (hPhysicalDrive == INVALID_HANDLE_VALUE) {
@@ -601,11 +604,10 @@ DWORD WINAPI FormatThread(LPVOID param)
601604
}
602605
UpdateProgress(OP_FIX_MBR, -1.0f);
603606

607+
fs = (int)ComboBox_GetItemData(hFileSystem, ComboBox_GetCurSel(hFileSystem));
608+
dt = (int)ComboBox_GetItemData(hDOSType, ComboBox_GetCurSel(hDOSType));
604609
if (IsChecked(IDC_DOS)) {
605-
switch(ComboBox_GetItemData(hDOSType, ComboBox_GetCurSel(hDOSType))) {
606-
case DT_WINME:
607-
case DT_FREEDOS:
608-
case DT_ISO_NTFS:
610+
if ((dt == DT_WINME) || (dt == DT_FREEDOS) || ((dt == DT_ISO) && (fs == FS_NTFS))) {
609611
// We still have a lock, which we need to modify the volume boot record
610612
// => no need to reacquire the lock...
611613
hLogicalVolume = GetDriveHandle(num, drive_name, TRUE, FALSE);
@@ -624,13 +626,11 @@ DWORD WINAPI FormatThread(LPVOID param)
624626
}
625627
// We must close and unlock the volume to write files to it
626628
safe_unlockclose(hLogicalVolume);
627-
break;
628-
case DT_ISO_FAT:
629+
} else if ((dt == DT_ISO) && ((fs == FS_FAT16) || (fs == FS_FAT32))) {
629630
PrintStatus(0, TRUE, "Installing Syslinux...");
630631
if (!InstallSyslinux(num, drive_name)) {
631632
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_INSTALL_FAILURE;
632633
}
633-
break;
634634
}
635635
} else {
636636
if (IsChecked(IDC_SET_ICON))
@@ -645,18 +645,14 @@ DWORD WINAPI FormatThread(LPVOID param)
645645

646646
if (IsChecked(IDC_DOS)) {
647647
UpdateProgress(OP_DOS, -1.0f);
648-
switch(ComboBox_GetItemData(hDOSType, ComboBox_GetCurSel(hDOSType))) {
649-
case DT_WINME:
650-
case DT_FREEDOS:
648+
if ((dt == DT_WINME) || (dt == DT_FREEDOS)) {
651649
PrintStatus(0, TRUE, "Copying DOS files...");
652650
if (!ExtractDOS(drive_name)) {
653651
if (!FormatStatus)
654652
FormatStatus = ERROR_SEVERITY_ERROR|FAC(FACILITY_STORAGE)|ERROR_CANNOT_COPY;
655653
goto out;
656654
}
657-
break;
658-
case DT_ISO_NTFS:
659-
case DT_ISO_FAT:
655+
} else if (dt == DT_ISO) {
660656
if (iso_path != NULL) {
661657
PrintStatus(0, TRUE, "Copying ISO files...");
662658
drive_name[2] = 0;
@@ -666,7 +662,6 @@ DWORD WINAPI FormatThread(LPVOID param)
666662
goto out;
667663
}
668664
}
669-
break;
670665
}
671666
if (IsChecked(IDC_SET_ICON))
672667
SetAutorun(drive_name);

src/iso.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ static int udf_extract_files(udf_t *p_udf, udf_dirent_t *p_udf_dirent, const cha
177177
goto out;
178178
}
179179
if (udf_is_dir(p_udf_dirent)) {
180-
if (!scan_only) _mkdir(psz_fullpath);
180+
if (!scan_only) _mkdirU(psz_fullpath);
181181
p_udf_dirent2 = udf_opendir(p_udf_dirent);
182182
if (p_udf_dirent2 != NULL) {
183183
if (udf_extract_files(p_udf, p_udf_dirent2, &psz_fullpath[strlen(psz_extract_dir)]))
@@ -287,7 +287,7 @@ static int iso_extract_files(iso9660_t* p_iso, const char *psz_path)
287287
continue;
288288
iso9660_name_translate_ext(p_statbuf->filename, psz_basename, i_joliet_level);
289289
if (p_statbuf->type == _STAT_DIR) {
290-
if (!scan_only) _mkdir(psz_fullpath);
290+
if (!scan_only) _mkdirU(psz_fullpath);
291291
if (iso_extract_files(p_iso, psz_iso_name))
292292
goto out;
293293
} else {

src/libcdio/cdio/util.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ _cdio_memdup (const void *mem, size_t count);
9898
char *
9999
_cdio_strdup_upper (const char str[]);
100100

101+
/* Duplicate path and make it platform compliant. Typically needed for
102+
MinGW/MSYS where a "/c/..." path must be translated to "c:/..." for
103+
use with fopen(), etc. Returned string must be freed by the caller. */
104+
char *
105+
_cdio_strdup_fixpath (const char path[]);
106+
101107
void
102108
_cdio_strfreev(char **strv);
103109

src/libcdio/driver/_cdio_stdio.c

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,43 @@
5656
#define CDIO_FSEEK fseek
5757
#endif
5858

59+
/* Windows'd fopen is not UTF-8 compliant - make it so */
60+
#if !defined(_WIN32)
61+
#define CDIO_FOPEN fopen
62+
#else
63+
#define CDIO_FOPEN fopenU
64+
extern wchar_t* cdio_utf8_to_wchar(const char* str);
65+
static inline FILE* fopenU(const char* filename, const char* mode)
66+
{
67+
FILE* ret = NULL;
68+
wchar_t* wfilename = cdio_utf8_to_wchar(filename);
69+
wchar_t* wmode = cdio_utf8_to_wchar(mode);
70+
ret = _wfopen(wfilename, wmode);
71+
free(wfilename);
72+
free(wmode);
73+
return ret;
74+
}
75+
#endif
76+
5977
/* Use _stati64 if needed, on platforms that don't have transparent LFS support */
6078
#if defined(HAVE__STATI64) && defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64)
61-
#define CDIO_STAT _stati64
79+
#define CDIO_STAT_STRUCT _stati64
80+
#if !defined(_WIN32)
81+
#define CDIO_STAT_CALL _stati64
82+
#else
83+
#define CDIO_STAT_CALL _stati64U
84+
/* Once more, we have to provide an UTF-8 compliant version on Windows */
85+
static inline int _stati64U(const char *path, struct _stati64 *buffer) {
86+
int ret;
87+
wchar_t* wpath = cdio_utf8_to_wchar(path);
88+
ret = _wstati64(wpath, buffer);
89+
free(wpath);
90+
return ret;
91+
}
92+
#endif
6293
#else
63-
#define CDIO_STAT stat
94+
#define CDIO_STAT_STRUCT stat
95+
#define CDIO_STAT_CALL stat
6496
#endif
6597

6698
#define _STRINGIFY(a) #a
@@ -81,8 +113,8 @@ static int
81113
_stdio_open (void *user_data)
82114
{
83115
_UserData *const ud = user_data;
84-
85-
if ((ud->fd = fopen (ud->pathname, "rb")))
116+
117+
if ((ud->fd = CDIO_FOPEN (ud->pathname, "rb")))
86118
{
87119
ud->fd_buf = calloc (1, CDIO_STDIO_BUFSIZE);
88120
setvbuf (ud->fd, ud->fd_buf, _IOFBF, CDIO_STDIO_BUFSIZE);
@@ -225,25 +257,18 @@ cdio_stdio_new(const char pathname[])
225257
CdioDataSource_t *new_obj = NULL;
226258
cdio_stream_io_functions funcs = { NULL, NULL, NULL, NULL, NULL, NULL };
227259
_UserData *ud = NULL;
228-
struct CDIO_STAT statbuf;
260+
struct CDIO_STAT_STRUCT statbuf;
229261
char* pathdup;
230262

231263
if (pathname == NULL)
232264
return NULL;
233265

234-
pathdup = strdup(pathname);
266+
/* MinGW may require a translated path */
267+
pathdup = _cdio_strdup_fixpath(pathname);
235268
if (pathdup == NULL)
236269
return NULL;
237270

238-
#ifdef __MINGW32__
239-
/* _stati64 requires using native Windows paths => convert "/c/..." to "c:/..." */
240-
if ((strlen(pathdup) > 3) && (pathdup[0] == '/') && (pathdup[2] == '/') && (isalpha(pathdup[1])))
241-
{
242-
pathdup[0] = pathdup[1];
243-
pathdup[1] = ':';
244-
}
245-
#endif
246-
if (CDIO_STAT (pathdup, &statbuf) == -1)
271+
if (CDIO_STAT_CALL (pathdup, &statbuf) == -1)
247272
{
248273
cdio_warn ("could not retrieve file info for `%s': %s",
249274
pathdup, strerror (errno));

src/libcdio/driver/utf8.c

Lines changed: 62 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
# include "config.h"
2424
#endif
2525

26-
#ifdef HAVE_JOLIET
2726
#ifdef HAVE_STRING_H
2827
# include <string.h>
2928
#endif
@@ -43,7 +42,66 @@
4342
#include <stdio.h>
4443
#endif
4544

46-
// TODO: also remove the need for iconv on MinGW
45+
/* Windows requires some basic UTF-8 support outside of Joliet */
46+
#if defined(_WIN32)
47+
#include <windows.h>
48+
49+
#define wchar_to_utf8_no_alloc(wsrc, dest, dest_size) \
50+
WideCharToMultiByte(CP_UTF8, 0, wsrc, -1, dest, dest_size, NULL, NULL)
51+
#define utf8_to_wchar_no_alloc(src, wdest, wdest_size) \
52+
MultiByteToWideChar(CP_UTF8, 0, src, -1, wdest, wdest_size)
53+
54+
/*
55+
* Converts an UTF-16 string to UTF8 (allocate returned string)
56+
* Returns NULL on error
57+
*/
58+
char* cdio_wchar_to_utf8(const wchar_t* wstr)
59+
{
60+
int size = 0;
61+
char* str = NULL;
62+
63+
/* Find out the size we need to allocate for our converted string */
64+
size = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL);
65+
if (size <= 1) /* An empty string would be size 1 */
66+
return NULL;
67+
68+
if ((str = (char*)calloc(size, 1)) == NULL)
69+
return NULL;
70+
71+
if (wchar_to_utf8_no_alloc(wstr, str, size) != size) {
72+
free(str);
73+
return NULL;
74+
}
75+
76+
return str;
77+
}
78+
79+
/*
80+
* Converts an UTF8 string to UTF-16 (allocate returned string)
81+
* Returns NULL on error
82+
*/
83+
wchar_t* cdio_utf8_to_wchar(const char* str)
84+
{
85+
int size = 0;
86+
wchar_t* wstr = NULL;
87+
88+
/* Find out the size we need to allocate for our converted string */
89+
size = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0);
90+
if (size <= 1) /* An empty string would be size 1 */
91+
return NULL;
92+
93+
if ((wstr = (wchar_t*)calloc(size, sizeof(wchar_t))) == NULL)
94+
return NULL;
95+
96+
if (utf8_to_wchar_no_alloc(str, wstr, size) != size) {
97+
free(wstr);
98+
return NULL;
99+
}
100+
return wstr;
101+
}
102+
#endif
103+
104+
#ifdef HAVE_JOLIET
47105
#ifdef HAVE_ICONV
48106
#include <iconv.h>
49107
struct cdio_charset_coverter_s
@@ -210,61 +268,6 @@ bool cdio_charset_to_utf8(char *src, size_t src_len, cdio_utf8_t **dst,
210268
return result;
211269
}
212270
#elif defined(_WIN32)
213-
#include <windows.h>
214-
215-
#define wchar_to_utf8_no_alloc(wsrc, dest, dest_size) \
216-
WideCharToMultiByte(CP_UTF8, 0, wsrc, -1, dest, dest_size, NULL, NULL)
217-
#define utf8_to_wchar_no_alloc(src, wdest, wdest_size) \
218-
MultiByteToWideChar(CP_UTF8, 0, src, -1, wdest, wdest_size)
219-
220-
/*
221-
* Converts an UTF-16 string to UTF8 (allocate returned string)
222-
* Returns NULL on error
223-
*/
224-
static inline char* wchar_to_utf8(const wchar_t* wstr)
225-
{
226-
int size = 0;
227-
char* str = NULL;
228-
229-
/* Find out the size we need to allocate for our converted string */
230-
size = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL);
231-
if (size <= 1) /* An empty string would be size 1 */
232-
return NULL;
233-
234-
if ((str = (char*)calloc(size, 1)) == NULL)
235-
return NULL;
236-
237-
if (wchar_to_utf8_no_alloc(wstr, str, size) != size) {
238-
free(str);
239-
return NULL;
240-
}
241-
242-
return str;
243-
}
244-
245-
/*
246-
* Converts an UTF8 string to UTF-16 (allocate returned string)
247-
* Returns NULL on error
248-
*/
249-
static inline wchar_t* utf8_to_wchar(const char* str)
250-
{
251-
int size = 0;
252-
wchar_t* wstr = NULL;
253-
254-
/* Find out the size we need to allocate for our converted string */
255-
size = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0);
256-
if (size <= 1) /* An empty string would be size 1 */
257-
return NULL;
258-
259-
if ((wstr = (wchar_t*)calloc(size, sizeof(wchar_t))) == NULL)
260-
return NULL;
261-
262-
if (utf8_to_wchar_no_alloc(str, wstr, size) != size) {
263-
free(wstr);
264-
return NULL;
265-
}
266-
return wstr;
267-
}
268271

269272
bool cdio_charset_from_utf8(cdio_utf8_t * src, char ** dst,
270273
int * dst_len, const char * dst_charset)
@@ -276,7 +279,7 @@ bool cdio_charset_from_utf8(cdio_utf8_t * src, char ** dst,
276279
return false;
277280

278281
/* Eliminate empty strings */
279-
le_dst = utf8_to_wchar(src);
282+
le_dst = cdio_utf8_to_wchar(src);
280283
if ((le_dst == NULL) || (le_dst[0] == 0)) {
281284
free(le_dst);
282285
return false;
@@ -323,7 +326,7 @@ bool cdio_charset_to_utf8(char *src, size_t src_len, cdio_utf8_t **dst,
323326
((char*)le_src)[2*i+1] = src[2*i];
324327
}
325328
le_src[src_len] = 0;
326-
*dst = wchar_to_utf8(le_src);
329+
*dst = cdio_wchar_to_utf8(le_src);
327330
free(le_src);
328331

329332
return (*dst != NULL);

src/libcdio/driver/util.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
#include "inttypes.h"
3939
#endif
4040

41+
#include <ctype.h>
42+
4143
#include "cdio_assert.h"
4244
#include <cdio/types.h>
4345
#include <cdio/util.h>
@@ -136,6 +138,29 @@ _cdio_strdup_upper (const char str[])
136138
return new_str;
137139
}
138140

141+
/* Convert MinGW/MSYS paths that start in "/c/..." to "c:/..."
142+
so that they can be used with fopen(), stat(), etc. */
143+
char *
144+
_cdio_strdup_fixpath (const char path[])
145+
{
146+
char *new_path = NULL;
147+
148+
if (path)
149+
{
150+
new_path = strdup (path);
151+
#if defined(_WIN32)
152+
if (new_path && (strlen (new_path) >= 3) && (new_path[0] == '/') &&
153+
(new_path[2] == '/') && (isalpha (new_path[1])))
154+
{
155+
new_path[0] = new_path[1];
156+
new_path[1] = ':';
157+
}
158+
#endif
159+
}
160+
161+
return new_path;
162+
}
163+
139164
uint8_t
140165
cdio_to_bcd8 (uint8_t n)
141166
{

0 commit comments

Comments
 (0)