[Extractor-gtk-cvslog] SF.net SVN: extractor-gtk: [71] trunk/extractor
Extract files from unusual archive formats
Brought to you by:
someone-guy
From: <som...@us...> - 2008-03-08 21:12:56
|
Revision: 71 http://extractor-gtk.svn.sourceforge.net/extractor-gtk/?rev=71&view=rev Author: someone-guy Date: 2008-03-08 13:12:54 -0800 (Sat, 08 Mar 2008) Log Message: ----------- Add a extract-to-memory function for preview since Windows has no sane way to handle temporary files. Modified Paths: -------------- trunk/extractor/bloodrayne.c trunk/extractor/extractor.c trunk/extractor/formats.h trunk/extractor/generic.c trunk/extractor/helpers.c trunk/extractor/helpers.h trunk/extractor/homeworld2.c trunk/extractor/nwn.c trunk/extractor/pak.c trunk/extractor/wad.c trunk/extractor/xtre.c Modified: trunk/extractor/bloodrayne.c =================================================================== --- trunk/extractor/bloodrayne.c 2008-03-08 20:11:07 UTC (rev 70) +++ trunk/extractor/bloodrayne.c 2008-03-08 21:12:54 UTC (rev 71) @@ -52,4 +52,5 @@ get_list, default_free_list, default_extract_file, + default_extract_mem, }; Modified: trunk/extractor/extractor.c =================================================================== --- trunk/extractor/extractor.c 2008-03-08 20:11:07 UTC (rev 70) +++ trunk/extractor/extractor.c 2008-03-08 21:12:54 UTC (rev 71) @@ -202,7 +202,6 @@ GtkTreeIter iter; GtkWidget *preview_win = data; file_t *file; - FILE *tmpf; int size; uint8_t *tmpdata; GdkPixbufLoader *pbl; @@ -214,15 +213,9 @@ if (!gtk_tree_model_get_iter(model, &iter, path)) return; gtk_tree_model_get(model, &iter, PTR_COL, &file, -1); - tmpf = tmpfile(); - cur_fmt->extract_file(input_file, file, tmpf); - fseek(tmpf, 0, SEEK_END); - size = ftell(tmpf); - if (size > MAX_IMG_SZ) size = MAX_IMG_SZ; - rewind(tmpf); - tmpdata = malloc(size); - fread(tmpdata, 1, size, tmpf); - fclose(tmpf); + tmpdata = malloc(MAX_IMG_SZ); + size = cur_fmt->extract_mem(input_file, file, tmpdata, MAX_IMG_SZ); + if (size > MAX_IMG_SZ || size < 0) size = MAX_IMG_SZ; pbl = gdk_pixbuf_loader_new(); gdk_pixbuf_loader_write(pbl, tmpdata, size, NULL); free(tmpdata); Modified: trunk/extractor/formats.h =================================================================== --- trunk/extractor/formats.h 2008-03-08 20:11:07 UTC (rev 70) +++ trunk/extractor/formats.h 2008-03-08 21:12:54 UTC (rev 71) @@ -22,6 +22,7 @@ file_t *(*get_list)(FILE *in); ///< get a list of files in archive void (*free_list)(file_t *list); ///< free file list obtained via get_list int (*extract_file)(FILE *in, const file_t *file, FILE *out); ///< extract a file + int (*extract_mem)(FILE *in, const file_t *file, uint8_t *out, int out_size); ///< extract a file to a buffer } fmt_desc_t; extern const fmt_desc_t bloodrayne_fmt; Modified: trunk/extractor/generic.c =================================================================== --- trunk/extractor/generic.c 2008-03-08 20:11:07 UTC (rev 70) +++ trunk/extractor/generic.c 2008-03-08 21:12:54 UTC (rev 71) @@ -197,4 +197,5 @@ get_list, default_free_ignorepriv, default_extract_file, + default_extract_mem, }; Modified: trunk/extractor/helpers.c =================================================================== --- trunk/extractor/helpers.c 2008-03-08 20:11:07 UTC (rev 70) +++ trunk/extractor/helpers.c 2008-03-08 21:12:54 UTC (rev 71) @@ -123,3 +123,16 @@ return fcopy(in, out, file->len); } +/** + * \brief default file-extract-to-memory function + * \param in archive file + * \param file description struct of file to extract + * \param out buffer to write data into + * \param size size of buffer + * \return number of bytes written to out + */ +int default_extract_mem(FILE *in, const file_t *file, uint8_t *out, int size) { + if (size > file->len) size = file->len; + fseek(in, file->start, SEEK_SET); + return fread(out, 1, size, in); +} Modified: trunk/extractor/helpers.h =================================================================== --- trunk/extractor/helpers.h 2008-03-08 20:11:07 UTC (rev 70) +++ trunk/extractor/helpers.h 2008-03-08 21:12:54 UTC (rev 71) @@ -13,4 +13,5 @@ void default_free_list(struct file_s *list); void default_free_ignorepriv(struct file_s *list); int default_extract_file(FILE *in, const struct file_s *file, FILE *out); +int default_extract_mem(FILE *in, const struct file_s *file, uint8_t *out, int size); #endif Modified: trunk/extractor/homeworld2.c =================================================================== --- trunk/extractor/homeworld2.c 2008-03-08 20:11:07 UTC (rev 70) +++ trunk/extractor/homeworld2.c 2008-03-08 21:12:54 UTC (rev 71) @@ -93,4 +93,5 @@ get_list, default_free_list, default_extract_file, + default_extract_mem, }; Modified: trunk/extractor/nwn.c =================================================================== --- trunk/extractor/nwn.c 2008-03-08 20:11:07 UTC (rev 70) +++ trunk/extractor/nwn.c 2008-03-08 21:12:54 UTC (rev 71) @@ -70,4 +70,5 @@ get_list, default_free_list, default_extract_file, + default_extract_mem, }; Modified: trunk/extractor/pak.c =================================================================== --- trunk/extractor/pak.c 2008-03-08 20:11:07 UTC (rev 70) +++ trunk/extractor/pak.c 2008-03-08 21:12:54 UTC (rev 71) @@ -48,4 +48,5 @@ get_list, default_free_list, default_extract_file, + default_extract_mem, }; Modified: trunk/extractor/wad.c =================================================================== --- trunk/extractor/wad.c 2008-03-08 20:11:07 UTC (rev 70) +++ trunk/extractor/wad.c 2008-03-08 21:12:54 UTC (rev 71) @@ -57,4 +57,5 @@ get_list, default_free_list, default_extract_file, + default_extract_mem, }; Modified: trunk/extractor/xtre.c =================================================================== --- trunk/extractor/xtre.c 2008-03-08 20:11:07 UTC (rev 70) +++ trunk/extractor/xtre.c 2008-03-08 21:12:54 UTC (rev 71) @@ -75,4 +75,5 @@ get_list, default_free_list, default_extract_file, + default_extract_mem, }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |