mirror of
https://github.com/pbatard/rufus.git
synced 2024-08-14 23:57:05 +00:00
[iso9660] add file extraction
This commit is contained in:
parent
41e8ac7d52
commit
a9383b6997
2 changed files with 61 additions and 13 deletions
62
src/iso.c
62
src/iso.c
|
@ -28,6 +28,8 @@
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
|
#include <io.h>
|
||||||
|
#include <direct.h>
|
||||||
#ifndef ISO_TEST
|
#ifndef ISO_TEST
|
||||||
#include "rufus.h"
|
#include "rufus.h"
|
||||||
#else
|
#else
|
||||||
|
@ -39,6 +41,10 @@
|
||||||
#include <cdio/iso9660.h>
|
#include <cdio/iso9660.h>
|
||||||
#include <cdio/udf.h>
|
#include <cdio/udf.h>
|
||||||
|
|
||||||
|
#ifndef CEILING
|
||||||
|
#define CEILING(x, y) ((x+(y-1))/y)
|
||||||
|
#endif
|
||||||
|
|
||||||
#define print_vd_info(title, fn) \
|
#define print_vd_info(title, fn) \
|
||||||
if (fn(p_iso, &psz_str)) { \
|
if (fn(p_iso, &psz_str)) { \
|
||||||
uprintf(title ": %s\n", psz_str); \
|
uprintf(title ": %s\n", psz_str); \
|
||||||
|
@ -84,20 +90,28 @@ static void udf_list_files(udf_t *p_udf, udf_dirent_t *p_udf_dirent, const char
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* extract_dir = "D:/tmp/iso";
|
||||||
|
|
||||||
static void iso_list_files(iso9660_t* p_iso, const char *psz_path)
|
static void iso_list_files(iso9660_t* p_iso, const char *psz_path)
|
||||||
{
|
{
|
||||||
char filename[4096], *p;
|
FILE *fd;
|
||||||
|
char filename[4096], *p, *iso_filename;
|
||||||
|
unsigned char buf[ISO_BLOCKSIZE];
|
||||||
CdioListNode_t* p_entnode;
|
CdioListNode_t* p_entnode;
|
||||||
iso9660_stat_t *p_statbuf;
|
iso9660_stat_t *p_statbuf;
|
||||||
CdioList_t* p_entlist;
|
CdioList_t* p_entlist;
|
||||||
|
size_t i, i_blocks;
|
||||||
|
lsn_t lsn;
|
||||||
|
|
||||||
if ( (p_iso == NULL) || (psz_path == NULL))
|
if ( (p_iso == NULL) || (psz_path == NULL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
strncpy(filename, psz_path, 4094);
|
// TODO: safe_###
|
||||||
p = &filename[strlen(psz_path)];
|
strcpy(filename, extract_dir);
|
||||||
*p++ = '/';
|
iso_filename = &filename[strlen(filename)];
|
||||||
*p = 0;
|
strcat(filename, psz_path);
|
||||||
|
strcat(filename, "/");
|
||||||
|
p = &filename[strlen(filename)];
|
||||||
p_entlist = iso9660_ifs_readdir(p_iso, psz_path);
|
p_entlist = iso9660_ifs_readdir(p_iso, psz_path);
|
||||||
|
|
||||||
if (!p_entlist)
|
if (!p_entlist)
|
||||||
|
@ -111,9 +125,43 @@ static void iso_list_files(iso9660_t* p_iso, const char *psz_path)
|
||||||
iso9660_name_translate(p_statbuf->filename, p);
|
iso9660_name_translate(p_statbuf->filename, p);
|
||||||
uprintf("%s [LSN %6d] %8u %s\n", (p_statbuf->type == _STAT_DIR)?"d":"-",
|
uprintf("%s [LSN %6d] %8u %s\n", (p_statbuf->type == _STAT_DIR)?"d":"-",
|
||||||
p_statbuf->lsn, p_statbuf->size, filename);
|
p_statbuf->lsn, p_statbuf->size, filename);
|
||||||
if (p_statbuf->type == _STAT_DIR)
|
if (p_statbuf->type == _STAT_DIR) {
|
||||||
iso_list_files(p_iso, filename);
|
// TODO: Joliet and Unicode support
|
||||||
|
_mkdir(filename);
|
||||||
|
iso_list_files(p_iso, iso_filename);
|
||||||
|
} else {
|
||||||
|
fd = fopen(filename, "wb");
|
||||||
|
if (fd == NULL) {
|
||||||
|
uprintf("Unable to create file %s\n", filename);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
i_blocks = CEILING(p_statbuf->size, ISO_BLOCKSIZE);
|
||||||
|
for (i = 0; i < i_blocks ; i++) {
|
||||||
|
memset (buf, 0, ISO_BLOCKSIZE);
|
||||||
|
lsn = p_statbuf->lsn + i;
|
||||||
|
if (iso9660_iso_seek_read (p_iso, buf, lsn, 1) != ISO_BLOCKSIZE) {
|
||||||
|
uprintf("Error reading ISO 9660 file %s at LSN %lu\n",
|
||||||
|
iso_filename, (long unsigned int)lsn);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
fwrite (buf, ISO_BLOCKSIZE, 1, fd);
|
||||||
|
if (ferror(fd)) {
|
||||||
|
uprintf("Error writing file %s\n", filename);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// TODO: this is slowing us down! Compute the size to use with fwrite instead
|
||||||
|
fflush(fd);
|
||||||
|
/* Make sure the file size has the exact same byte size. Without the
|
||||||
|
truncate below, the file will a multiple of ISO_BLOCKSIZE. */
|
||||||
|
if (_chsize(_fileno(fd), p_statbuf->size)) {
|
||||||
|
uprintf("Error adjusting file size for %s\n", filename);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
fclose(fd);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
out:
|
||||||
_cdio_list_free(p_entlist, true);
|
_cdio_list_free(p_entlist, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
12
src/rufus.rc
12
src/rufus.rc
|
@ -33,7 +33,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_NEUTRAL
|
||||||
IDD_DIALOG DIALOGEX 12, 12, 206, 278
|
IDD_DIALOG DIALOGEX 12, 12, 206, 278
|
||||||
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||||
EXSTYLE WS_EX_APPWINDOW
|
EXSTYLE WS_EX_APPWINDOW
|
||||||
CAPTION "Rufus v1.0.7.137"
|
CAPTION "Rufus v1.0.7.138"
|
||||||
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
||||||
BEGIN
|
BEGIN
|
||||||
DEFPUSHBUTTON "Start",IDC_START,94,236,50,14
|
DEFPUSHBUTTON "Start",IDC_START,94,236,50,14
|
||||||
|
@ -70,7 +70,7 @@ BEGIN
|
||||||
DEFPUSHBUTTON "OK",IDOK,231,175,50,14,WS_GROUP
|
DEFPUSHBUTTON "OK",IDOK,231,175,50,14,WS_GROUP
|
||||||
CONTROL "<a href=""http://rufus.akeo.ie"">http://rufus.akeo.ie</a>",IDC_ABOUT_RUFUS_URL,
|
CONTROL "<a href=""http://rufus.akeo.ie"">http://rufus.akeo.ie</a>",IDC_ABOUT_RUFUS_URL,
|
||||||
"SysLink",WS_TABSTOP,46,47,114,9
|
"SysLink",WS_TABSTOP,46,47,114,9
|
||||||
LTEXT "Version 1.0.7 (Build 137)",IDC_STATIC,46,19,78,8
|
LTEXT "Version 1.0.7 (Build 138)",IDC_STATIC,46,19,78,8
|
||||||
PUSHBUTTON "License...",IDC_ABOUT_LICENSE,46,175,50,14,WS_GROUP
|
PUSHBUTTON "License...",IDC_ABOUT_LICENSE,46,175,50,14,WS_GROUP
|
||||||
EDITTEXT IDC_ABOUT_COPYRIGHTS,46,107,235,63,ES_MULTILINE | ES_READONLY | WS_VSCROLL
|
EDITTEXT IDC_ABOUT_COPYRIGHTS,46,107,235,63,ES_MULTILINE | ES_READONLY | WS_VSCROLL
|
||||||
LTEXT "Report bugs or request enhancements at:",IDC_STATIC,46,66,187,8
|
LTEXT "Report bugs or request enhancements at:",IDC_STATIC,46,66,187,8
|
||||||
|
@ -208,8 +208,8 @@ END
|
||||||
//
|
//
|
||||||
|
|
||||||
VS_VERSION_INFO VERSIONINFO
|
VS_VERSION_INFO VERSIONINFO
|
||||||
FILEVERSION 1,0,7,137
|
FILEVERSION 1,0,7,138
|
||||||
PRODUCTVERSION 1,0,7,137
|
PRODUCTVERSION 1,0,7,138
|
||||||
FILEFLAGSMASK 0x3fL
|
FILEFLAGSMASK 0x3fL
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
FILEFLAGS 0x1L
|
FILEFLAGS 0x1L
|
||||||
|
@ -226,13 +226,13 @@ BEGIN
|
||||||
BEGIN
|
BEGIN
|
||||||
VALUE "CompanyName", "akeo.ie"
|
VALUE "CompanyName", "akeo.ie"
|
||||||
VALUE "FileDescription", "Rufus"
|
VALUE "FileDescription", "Rufus"
|
||||||
VALUE "FileVersion", "1.0.7.137"
|
VALUE "FileVersion", "1.0.7.138"
|
||||||
VALUE "InternalName", "Rufus"
|
VALUE "InternalName", "Rufus"
|
||||||
VALUE "LegalCopyright", "© 2011 Pete Batard (GPL v3)"
|
VALUE "LegalCopyright", "© 2011 Pete Batard (GPL v3)"
|
||||||
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html"
|
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html"
|
||||||
VALUE "OriginalFilename", "rufus.exe"
|
VALUE "OriginalFilename", "rufus.exe"
|
||||||
VALUE "ProductName", "Rufus"
|
VALUE "ProductName", "Rufus"
|
||||||
VALUE "ProductVersion", "1.0.7.137"
|
VALUE "ProductVersion", "1.0.7.138"
|
||||||
END
|
END
|
||||||
END
|
END
|
||||||
BLOCK "VarFileInfo"
|
BLOCK "VarFileInfo"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue