mirror of
https://github.com/Fledge68/WiiFlow_Lite.git
synced 2025-02-02 13:52:36 +01:00
-code cleanup, removed six (!) unneeded source files
-added in the framebuffer cleanup again, why it was taken out overjoy?
This commit is contained in:
parent
8381ad73ec
commit
c9932a1b28
@ -791,7 +791,7 @@ void Nand::CreatePath(const char *path, ...)
|
||||
if(!d)
|
||||
{
|
||||
gprintf("Creating folder: \"%s\"\n", folder);
|
||||
makedir(folder);
|
||||
fsop_MakeFolder(folder);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -126,7 +126,7 @@ bool fsop_FileExist(const char *fn)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool fsop_DirExist (char *path)
|
||||
bool fsop_DirExist(char *path)
|
||||
{
|
||||
DIR *dir;
|
||||
|
||||
@ -140,6 +140,15 @@ bool fsop_DirExist (char *path)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool fsop_MakeFolder(char *path)
|
||||
{
|
||||
if(mkdir(path, S_IREAD | S_IWRITE) == 0)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void *thread_CopyFileReader()
|
||||
{
|
||||
u32 rb;
|
||||
@ -161,7 +170,7 @@ static void *thread_CopyFileReader()
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool fsop_CopyFile (char *source, char *target, progress_callback_t spinner, void *spinner_data)
|
||||
bool fsop_CopyFile(char *source, char *target, progress_callback_t spinner, void *spinner_data)
|
||||
{
|
||||
gprintf("Creating file: %s\n",target);
|
||||
int err = 0;
|
||||
@ -269,7 +278,7 @@ bool fsop_CopyFile (char *source, char *target, progress_callback_t spinner, voi
|
||||
/*
|
||||
Recursive copyfolder
|
||||
*/
|
||||
static bool doCopyFolder (char *source, char *target, progress_callback_t spinner, void *spinner_data)
|
||||
static bool doCopyFolder(char *source, char *target, progress_callback_t spinner, void *spinner_data)
|
||||
{
|
||||
DIR *pdir;
|
||||
struct dirent *pent;
|
||||
@ -277,32 +286,28 @@ static bool doCopyFolder (char *source, char *target, progress_callback_t spinne
|
||||
bool ret = true;
|
||||
|
||||
// If target folder doesn't exist, create it !
|
||||
if (!fsop_DirExist(target))
|
||||
if(!fsop_DirExist(target))
|
||||
{
|
||||
gprintf("Creating directory: %s\n",target);
|
||||
makedir(target);
|
||||
fsop_MakeFolder(target);
|
||||
}
|
||||
|
||||
pdir = opendir(source);
|
||||
|
||||
while ((pent=readdir(pdir)) != NULL && ret == true)
|
||||
while((pent=readdir(pdir)) != NULL && ret == true)
|
||||
{
|
||||
// Skip it
|
||||
if (strcmp (pent->d_name, ".") == 0 || strcmp (pent->d_name, "..") == 0)
|
||||
if(strcmp (pent->d_name, ".") == 0 || strcmp (pent->d_name, "..") == 0)
|
||||
continue;
|
||||
|
||||
snprintf(newSource, sizeof(newSource), "%s/%s", source, pent->d_name);
|
||||
snprintf(newTarget, sizeof(newTarget), "%s/%s", target, pent->d_name);
|
||||
|
||||
// If it is a folder... recurse...
|
||||
if (fsop_DirExist(newSource))
|
||||
{
|
||||
if(fsop_DirExist(newSource))
|
||||
ret = doCopyFolder(newSource, newTarget, spinner, spinner_data);
|
||||
}
|
||||
else // It is a file !
|
||||
{
|
||||
ret = fsop_CopyFile(newSource, newTarget, spinner, spinner_data);
|
||||
}
|
||||
}
|
||||
|
||||
closedir(pdir);
|
||||
@ -310,7 +315,7 @@ static bool doCopyFolder (char *source, char *target, progress_callback_t spinne
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool fsop_CopyFolder (char *source, char *target, progress_callback_t spinner, void *spinner_data)
|
||||
bool fsop_CopyFolder(char *source, char *target, progress_callback_t spinner, void *spinner_data)
|
||||
{
|
||||
gprintf("DML game USB->SD job started!\n");
|
||||
|
||||
@ -327,24 +332,20 @@ void fsop_deleteFolder(char *source)
|
||||
|
||||
pdir = opendir(source);
|
||||
|
||||
while ((pent=readdir(pdir)) != NULL)
|
||||
while((pent=readdir(pdir)) != NULL)
|
||||
{
|
||||
// Skip it
|
||||
if (strcmp (pent->d_name, ".") == 0 || strcmp (pent->d_name, "..") == 0)
|
||||
if(strcmp (pent->d_name, ".") == 0 || strcmp (pent->d_name, "..") == 0)
|
||||
continue;
|
||||
|
||||
snprintf (newSource, sizeof(newSource), "%s/%s", source, pent->d_name);
|
||||
snprintf(newSource, sizeof(newSource), "%s/%s", source, pent->d_name);
|
||||
|
||||
// If it is a folder... recurse...
|
||||
if (fsop_DirExist(newSource))
|
||||
{
|
||||
if(fsop_DirExist(newSource))
|
||||
fsop_deleteFolder(newSource);
|
||||
}
|
||||
else // It is a file !
|
||||
{
|
||||
gprintf("Deleting file: %s\n",newSource);
|
||||
remove(newSource);
|
||||
}
|
||||
}
|
||||
closedir(pdir);
|
||||
gprintf("Deleting directory: %s\n",source);
|
||||
|
@ -14,6 +14,7 @@ u32 fsop_GetFolderKb(char *source);
|
||||
u32 fsop_GetFreeSpaceKb(char *path);
|
||||
bool fsop_FileExist(const char *fn);
|
||||
bool fsop_DirExist(char *path);
|
||||
bool fsop_MakeFolder(char *path);
|
||||
bool fsop_CopyFile(char *source, char *target, progress_callback_t spinner, void *spinner_data);
|
||||
bool fsop_CopyFolder(char *source, char *target, progress_callback_t spinner, void *spinner_data);
|
||||
void fsop_deleteFile(char *source);
|
||||
|
@ -254,8 +254,8 @@ void CVideo::cleanup(void)
|
||||
{
|
||||
m_defaultWaitMessages[i].data.release();
|
||||
}
|
||||
//free(MEM_K1_TO_K0(m_frameBuf[0]));
|
||||
//free(MEM_K1_TO_K0(m_frameBuf[1]));
|
||||
free(MEM_K1_TO_K0(m_frameBuf[0]));
|
||||
free(MEM_K1_TO_K0(m_frameBuf[1]));
|
||||
MEM1_free(m_stencil);
|
||||
MEM1_free(m_fifo);
|
||||
}
|
||||
|
@ -300,14 +300,14 @@ s32 GCDump::DumpGame()
|
||||
if(!fsop_DirExist(folder))
|
||||
{
|
||||
gprintf("Creating directory: %s\n", folder);
|
||||
makedir(folder);
|
||||
fsop_MakeFolder(folder);
|
||||
}
|
||||
memset(folder, 0, sizeof(folder));
|
||||
snprintf(folder, sizeof(folder), "%s/%s [%.06s]%s", fmt((strncmp(gamepartition, "sd", 2) != 0) ? usb_dml_game_dir : DML_DIR, gamepartition), gcheader.title, (char *)gcheader.id, Disc ? "2" : "");
|
||||
if(!fsop_DirExist(folder))
|
||||
{
|
||||
gprintf("Creating directory: %s\n", folder);
|
||||
makedir(folder);
|
||||
fsop_MakeFolder(folder);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -382,7 +382,7 @@ s32 GCDump::DumpGame()
|
||||
if(!fsop_DirExist(folder))
|
||||
{
|
||||
gprintf("Creating directory: %s\n", folder);
|
||||
makedir(folder);
|
||||
fsop_MakeFolder(folder);
|
||||
}
|
||||
|
||||
gprintf("Writing %s/boot.bin\n", folder);
|
||||
|
@ -33,7 +33,6 @@ extern "C" {
|
||||
u64 le64(u64);
|
||||
u32 le32(u32);
|
||||
u16 le16(u16);
|
||||
int makedir(char *newdir);
|
||||
|
||||
typedef volatile unsigned short vu16;
|
||||
typedef volatile unsigned int vu32;
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "utils.h"
|
||||
#include "disc.h"
|
||||
#include "gecko.h"
|
||||
#include "gc/fileOps.h"
|
||||
|
||||
#define MAX_FAT_PATH 1024
|
||||
#define TITLE_LEN 64
|
||||
@ -183,7 +184,7 @@ s32 WBFS_Ext_AddGame(progress_callback_t spinner, void *spinner_data)
|
||||
*cp = '_';
|
||||
snprintf(folder, sizeof(folder), "%s%s/%s [%s]", wbfs_fs_drive, wbfs_ext_dir, cleantitle, header.id);
|
||||
free(cleantitle);
|
||||
makedir((char *)folder);
|
||||
fsop_MakeFolder((char *)folder);
|
||||
snprintf(gamepath, sizeof(gamepath), "%s/%s.wbfs", folder, header.id);
|
||||
|
||||
u64 size = (u64)143432*2*0x8000ULL;
|
||||
|
@ -140,8 +140,6 @@ CMenu::CMenu(CVideo &vid) :
|
||||
m_Emulator_boot = false;
|
||||
}
|
||||
|
||||
extern "C" { int makedir(char *newdir); }
|
||||
|
||||
void CMenu::init(void)
|
||||
{
|
||||
const char *drive = "empty";
|
||||
@ -179,7 +177,7 @@ void CMenu::init(void)
|
||||
if (DeviceHandler::Instance()->IsInserted(i) && DeviceHandler::Instance()->GetFSType(i) != PART_FS_WBFS)
|
||||
{
|
||||
drive = DeviceName[i];
|
||||
makedir((char *)fmt("%s:/%s", DeviceName[i], APPDATA_DIR2)); //Make the apps dir, so saving wiiflow.ini does not fail.
|
||||
fsop_MakeFolder((char *)fmt("%s:/%s", DeviceName[i], APPDATA_DIR2)); //Make the apps dir, so saving wiiflow.ini does not fail.
|
||||
break;
|
||||
}
|
||||
|
||||
@ -327,21 +325,21 @@ void CMenu::init(void)
|
||||
m_cf.init(m_base_font, m_base_font_size, m_vid.vid_50hz());
|
||||
|
||||
//Make important folders first.
|
||||
makedir((char *)m_cacheDir.c_str());
|
||||
makedir((char *)m_settingsDir.c_str());
|
||||
makedir((char *)m_languagesDir.c_str());
|
||||
makedir((char *)m_boxPicDir.c_str());
|
||||
makedir((char *)m_picDir.c_str());
|
||||
makedir((char *)m_themeDir.c_str());
|
||||
makedir((char *)m_musicDir.c_str());
|
||||
makedir((char *)m_videoDir.c_str());
|
||||
makedir((char *)m_fanartDir.c_str());
|
||||
makedir((char *)m_screenshotDir.c_str());
|
||||
makedir((char *)m_txtCheatDir.c_str());
|
||||
makedir((char *)m_cheatDir.c_str());
|
||||
makedir((char *)m_wipDir.c_str());
|
||||
makedir((char *)m_listCacheDir.c_str());
|
||||
makedir((char *)m_helpDir.c_str());
|
||||
fsop_MakeFolder((char *)m_cacheDir.c_str());
|
||||
fsop_MakeFolder((char *)m_settingsDir.c_str());
|
||||
fsop_MakeFolder((char *)m_languagesDir.c_str());
|
||||
fsop_MakeFolder((char *)m_boxPicDir.c_str());
|
||||
fsop_MakeFolder((char *)m_picDir.c_str());
|
||||
fsop_MakeFolder((char *)m_themeDir.c_str());
|
||||
fsop_MakeFolder((char *)m_musicDir.c_str());
|
||||
fsop_MakeFolder((char *)m_videoDir.c_str());
|
||||
fsop_MakeFolder((char *)m_fanartDir.c_str());
|
||||
fsop_MakeFolder((char *)m_screenshotDir.c_str());
|
||||
fsop_MakeFolder((char *)m_txtCheatDir.c_str());
|
||||
fsop_MakeFolder((char *)m_cheatDir.c_str());
|
||||
fsop_MakeFolder((char *)m_wipDir.c_str());
|
||||
fsop_MakeFolder((char *)m_listCacheDir.c_str());
|
||||
fsop_MakeFolder((char *)m_helpDir.c_str());
|
||||
|
||||
// INI files
|
||||
m_cat.load(fmt("%s/" CAT_FILENAME, m_settingsDir.c_str()));
|
||||
|
@ -230,7 +230,7 @@ int CMenu::_GCcopyGame(void *obj)
|
||||
gprintf("Copying from:\n%s\nto:\n%s\n",source,target);
|
||||
LWP_MutexUnlock(m.m_mutex);
|
||||
if (!fsop_DirExist(folder))
|
||||
makedir(folder);
|
||||
fsop_MakeFolder(folder);
|
||||
fsop_CopyFolder(source, target, CMenu::_addDiscProgress, obj);
|
||||
LWP_MutexLock(m.m_mutex);
|
||||
m._setThrdMsg(m._t("wbfsop14", L"Game copied, press Back to boot the game."), 1.f);
|
||||
|
@ -34,7 +34,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "ZipFile.h"
|
||||
#include "miniunz.h"
|
||||
#include "gc/fileOps.h"
|
||||
|
||||
ZipFile::ZipFile(const char *filepath)
|
||||
{
|
||||
@ -143,7 +143,7 @@ bool ZipFile::ExtractAll(const char *dest)
|
||||
char temppath[strlen(writepath)];
|
||||
snprintf(temppath, position, "%s", writepath);
|
||||
|
||||
makedir(temppath);
|
||||
fsop_MakeFolder(temppath);
|
||||
|
||||
if (ret == UNZ_OK)
|
||||
{
|
||||
|
@ -1,62 +0,0 @@
|
||||
|
||||
#include "inflate.h"
|
||||
|
||||
#define CHUNK 1024
|
||||
|
||||
int inflateFile(FILE *source, FILE *dest)
|
||||
{
|
||||
int ret;
|
||||
unsigned have;
|
||||
z_stream strm;
|
||||
unsigned char in[CHUNK];
|
||||
unsigned char out[CHUNK];
|
||||
|
||||
/* allocate inflate state */
|
||||
strm.zalloc = Z_NULL;
|
||||
strm.zfree = Z_NULL;
|
||||
strm.opaque = Z_NULL;
|
||||
strm.avail_in = 0;
|
||||
strm.next_in = Z_NULL;
|
||||
ret = inflateInit(&strm);
|
||||
if (ret != Z_OK)
|
||||
return ret;
|
||||
|
||||
/* decompress until deflate stream ends or end of file */
|
||||
do {
|
||||
strm.avail_in = fread(in, 1, CHUNK, source);
|
||||
if (ferror(source)) {
|
||||
(void)inflateEnd(&strm);
|
||||
return Z_ERRNO;
|
||||
}
|
||||
if (strm.avail_in == 0)
|
||||
break;
|
||||
strm.next_in = in;
|
||||
|
||||
/* run inflate() on input until output buffer not full */
|
||||
do {
|
||||
strm.avail_out = CHUNK;
|
||||
strm.next_out = out;
|
||||
ret = inflate(&strm, Z_NO_FLUSH);
|
||||
switch (ret) {
|
||||
case Z_NEED_DICT:
|
||||
(void)inflateEnd(&strm);
|
||||
return -20;
|
||||
case Z_DATA_ERROR:
|
||||
(void)inflateEnd(&strm);
|
||||
return -21;
|
||||
case Z_MEM_ERROR:
|
||||
(void)inflateEnd(&strm);
|
||||
return -22;
|
||||
}
|
||||
have = CHUNK - strm.avail_out;
|
||||
if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
|
||||
(void)inflateEnd(&strm);
|
||||
return Z_ERRNO;
|
||||
}
|
||||
} while (strm.avail_out == 0);
|
||||
/* done when inflate() says it's done */
|
||||
} while (ret != Z_STREAM_END);
|
||||
/* clean up and return */
|
||||
(void)inflateEnd(&strm);
|
||||
return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
|
||||
#ifndef _INFLATE_H
|
||||
#define _INFLATE_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <zlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int inflateFile(FILE *source, FILE *dest);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //_INFLATE_H
|
@ -1,281 +0,0 @@
|
||||
/*
|
||||
miniunz.c
|
||||
Version 1.01e, February 12th, 2005
|
||||
|
||||
Copyright (C) 1998-2005 Gilles Vollant
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <utime.h>
|
||||
|
||||
#include "mem2.hpp"
|
||||
#include "unzip.h"
|
||||
|
||||
#define CASESENSITIVITY (0)
|
||||
#define WRITEBUFFERSIZE (8192)
|
||||
#define MAXFILENAME (256)
|
||||
|
||||
struct stat exists;
|
||||
|
||||
static int mymkdir(const char* dirname)
|
||||
{
|
||||
if (stat(dirname, &exists) == 0)
|
||||
return 0;
|
||||
return mkdir(dirname,0777);
|
||||
}
|
||||
|
||||
int makedir (char *newdir)
|
||||
{
|
||||
if (stat(newdir, &exists) == 0)
|
||||
return 0;
|
||||
|
||||
char *buffer ;
|
||||
char *p;
|
||||
int len = (int)strlen(newdir);
|
||||
|
||||
if (len <= 0)
|
||||
return 0;
|
||||
|
||||
buffer = (char*)MEM2_alloc(len+1);
|
||||
strcpy(buffer,newdir);
|
||||
|
||||
if (buffer[len-1] == '/') {
|
||||
buffer[len-1] = '\0';
|
||||
}
|
||||
if (mymkdir(buffer) == 0) {
|
||||
MEM2_free(buffer);
|
||||
return 1;
|
||||
}
|
||||
|
||||
p = buffer+1;
|
||||
while (1) {
|
||||
char hold;
|
||||
|
||||
while (*p && *p != '\\' && *p != '/')
|
||||
p++;
|
||||
hold = *p;
|
||||
*p = 0;
|
||||
if ((mymkdir(buffer) == -1) && (errno == ENOENT)) {
|
||||
// printf("couldn't create directory %s\n",buffer);
|
||||
MEM2_free(buffer);
|
||||
return 0;
|
||||
}
|
||||
if (hold == 0)
|
||||
break;
|
||||
*p++ = hold;
|
||||
}
|
||||
MEM2_free(buffer);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static char *fullfilename(const char *basedir, char *filename) {
|
||||
char *file = (char *)MEM2_alloc(strlen(basedir) + strlen(filename) + 1);
|
||||
if (basedir == NULL) {
|
||||
strcpy(file, filename);
|
||||
} else {
|
||||
if (basedir[strlen(basedir) - 1] == '/') {
|
||||
sprintf(file, "%s%s", basedir, filename);
|
||||
} else {
|
||||
sprintf(file, "%s/%s", basedir, filename);
|
||||
}
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
static int do_extract_currentfile(unzFile uf,const int* popt_extract_without_path,int* popt_overwrite,const char* password, const char *basedir) {
|
||||
char filename_inzip[256];
|
||||
char* filename_withoutpath;
|
||||
char* filename_withpath;
|
||||
char* p;
|
||||
int err=UNZ_OK;
|
||||
FILE *fout=NULL;
|
||||
void* buf;
|
||||
uInt size_buf;
|
||||
|
||||
unz_file_info file_info;
|
||||
err = unzGetCurrentFileInfo(uf,&file_info,filename_inzip,sizeof(filename_inzip),NULL,0,NULL,0);
|
||||
|
||||
if (err!=UNZ_OK) {
|
||||
// printf("error %d with zipfile in unzGetCurrentFileInfo\n",err);
|
||||
return err;
|
||||
}
|
||||
|
||||
size_buf = WRITEBUFFERSIZE;
|
||||
buf = (void*)MEM2_alloc(size_buf);
|
||||
if (buf==NULL) {
|
||||
// printf("Error allocating memory\n");
|
||||
return UNZ_INTERNALERROR;
|
||||
}
|
||||
|
||||
p = filename_withoutpath = filename_inzip;
|
||||
filename_withpath = fullfilename(basedir, filename_inzip);
|
||||
while ((*p) != '\0') {
|
||||
if (((*p)=='/') || ((*p)=='\\'))
|
||||
filename_withoutpath = p+1;
|
||||
p++;
|
||||
}
|
||||
|
||||
if ((*filename_withoutpath)=='\0') {
|
||||
if ((*popt_extract_without_path)==0) {
|
||||
|
||||
// Fix the path, this will fail if the directoryname is the same as the first filename in the zip
|
||||
char *path = (char *)MEM2_alloc(strlen(filename_withpath));
|
||||
strcpy(path, filename_withpath);
|
||||
char *ptr = strstr(path, filename_withoutpath);
|
||||
*ptr = '\0';
|
||||
|
||||
// printf("creating directory: %s\n",path);
|
||||
mymkdir(path);
|
||||
|
||||
MEM2_free(path);
|
||||
}
|
||||
} else {
|
||||
char* write_filename;
|
||||
int skip=0;
|
||||
|
||||
if ((*popt_extract_without_path)==0)
|
||||
write_filename = filename_withpath;
|
||||
else
|
||||
write_filename = filename_withoutpath;
|
||||
|
||||
err = unzOpenCurrentFilePassword(uf,password);
|
||||
if (err!=UNZ_OK) {
|
||||
// printf("error %d with zipfile in unzOpenCurrentFilePassword\n",err);
|
||||
}
|
||||
|
||||
if (((*popt_overwrite)==0) && (err==UNZ_OK)) {
|
||||
char rep=0;
|
||||
FILE* ftestexist;
|
||||
ftestexist = fopen(write_filename,"rb");
|
||||
if (ftestexist!=NULL) {
|
||||
fclose(ftestexist);
|
||||
do {
|
||||
char answer[128];
|
||||
int ret;
|
||||
|
||||
// printf("The file %s exists. Overwrite ? [y]es, [n]o, [A]ll: ",write_filename);
|
||||
ret = scanf("%1s",answer);
|
||||
if (ret != 1) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
rep = answer[0] ;
|
||||
if ((rep>='a') && (rep<='z'))
|
||||
rep -= 0x20;
|
||||
} while ((rep!='Y') && (rep!='N') && (rep!='A'));
|
||||
}
|
||||
|
||||
if (rep == 'N')
|
||||
skip = 1;
|
||||
|
||||
if (rep == 'A')
|
||||
*popt_overwrite=1;
|
||||
}
|
||||
|
||||
if ((skip==0) && (err==UNZ_OK)) {
|
||||
fout=fopen(write_filename,"wb");
|
||||
|
||||
/* some zipfile don't contain directory alone before file */
|
||||
if ((fout==NULL) && ((*popt_extract_without_path)==0) &&
|
||||
(filename_withoutpath!=(char*)filename_inzip)) {
|
||||
char c=*(filename_withoutpath-1);
|
||||
*(filename_withoutpath-1)='\0';
|
||||
|
||||
// Fix the path, this will fail if the directoryname is the same as the first filename in the zip
|
||||
char *path = (char *)MEM2_alloc(strlen(write_filename));
|
||||
strcpy(path, write_filename);
|
||||
char *ptr = strstr(path, filename_withoutpath);
|
||||
*ptr = '\0';
|
||||
makedir(path);
|
||||
MEM2_free(path);
|
||||
|
||||
*(filename_withoutpath-1)=c;
|
||||
fout=fopen(write_filename,"wb");
|
||||
}
|
||||
|
||||
if (fout==NULL) {
|
||||
// printf("error opening %s\n",write_filename);
|
||||
}
|
||||
}
|
||||
|
||||
if (fout!=NULL) {
|
||||
// printf(" extracting: %s\n",write_filename);
|
||||
|
||||
do {
|
||||
err = unzReadCurrentFile(uf,buf,size_buf);
|
||||
if (err<0) {
|
||||
// printf("error %d with zipfile in unzReadCurrentFile\n",err);
|
||||
break;
|
||||
}
|
||||
if (err>0)
|
||||
if (fwrite(buf,err,1,fout)!=1) {
|
||||
// printf("error in writing extracted file\n");
|
||||
err=UNZ_ERRNO;
|
||||
break;
|
||||
}
|
||||
} while (err>0);
|
||||
if (fout)
|
||||
fclose(fout);
|
||||
|
||||
}
|
||||
|
||||
if (err==UNZ_OK) {
|
||||
err = unzCloseCurrentFile (uf);
|
||||
if (err!=UNZ_OK) {
|
||||
// printf("error %d with zipfile in unzCloseCurrentFile\n",err);
|
||||
}
|
||||
} else
|
||||
unzCloseCurrentFile(uf); /* don't lose the error */
|
||||
}
|
||||
MEM2_free(filename_withpath);
|
||||
MEM2_free(buf);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
int extractZip(unzFile uf,int opt_extract_without_path,int opt_overwrite,const char* password, const char *basedir) {
|
||||
uLong i;
|
||||
unz_global_info gi;
|
||||
int err;
|
||||
|
||||
err = unzGetGlobalInfo (uf,&gi);
|
||||
if (err!=UNZ_OK)
|
||||
// printf("error %d with zipfile in unzGetGlobalInfo \n",err);
|
||||
|
||||
for (i=0;i<gi.number_entry;i++) {
|
||||
if (do_extract_currentfile(uf,&opt_extract_without_path,
|
||||
&opt_overwrite,
|
||||
password, basedir) != UNZ_OK)
|
||||
break;
|
||||
|
||||
if ((i+1)<gi.number_entry) {
|
||||
err = unzGoToNextFile(uf);
|
||||
if (err!=UNZ_OK) {
|
||||
// printf("error %d with zipfile in unzGoToNextFile\n",err);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int extractZipOnefile(unzFile uf,const char* filename,int opt_extract_without_path,int opt_overwrite,const char* password) {
|
||||
if (unzLocateFile(uf,filename,CASESENSITIVITY)!=UNZ_OK) {
|
||||
// printf("file %s not found in the zipfile\n",filename);
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (do_extract_currentfile(uf,&opt_extract_without_path,
|
||||
&opt_overwrite,
|
||||
password, NULL) == UNZ_OK)
|
||||
return 0;
|
||||
else
|
||||
return 1;
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
|
||||
#ifndef _miniunz_H
|
||||
#define _miniunz_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int extractZip(unzFile uf,int opt_extract_without_path,int opt_overwrite,const char* password, const char *basedir);
|
||||
int extractZipOnefile(unzFile uf,const char* filename,int opt_extract_without_path,int opt_overwrite,const char* password);
|
||||
int makedir(char *newdir);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,283 +0,0 @@
|
||||
/*
|
||||
Additional tools for Minizip
|
||||
Code: Xavier Roche '2004
|
||||
License: Same as ZLIB (www.gzip.org)
|
||||
*/
|
||||
|
||||
/* Code */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "zlib.h"
|
||||
#include "unzip.h"
|
||||
#include "mem2.hpp"
|
||||
|
||||
#define READ_8(adr) ((unsigned char)*(adr))
|
||||
#define READ_16(adr) ( READ_8(adr) | (READ_8(adr+1) << 8) )
|
||||
#define READ_32(adr) ( READ_16(adr) | (READ_16((adr)+2) << 16) )
|
||||
|
||||
#define WRITE_8(buff, n) do { \
|
||||
*((unsigned char*)(buff)) = (unsigned char) ((n) & 0xff); \
|
||||
} while(0)
|
||||
#define WRITE_16(buff, n) do { \
|
||||
WRITE_8((unsigned char*)(buff), n); \
|
||||
WRITE_8(((unsigned char*)(buff)) + 1, (n) >> 8); \
|
||||
} while(0)
|
||||
#define WRITE_32(buff, n) do { \
|
||||
WRITE_16((unsigned char*)(buff), (n) & 0xffff); \
|
||||
WRITE_16((unsigned char*)(buff) + 2, (n) >> 16); \
|
||||
} while(0)
|
||||
|
||||
extern int ZEXPORT unzRepair(file, fileOut, fileOutTmp, nRecovered, bytesRecovered)
|
||||
const char* file;
|
||||
const char* fileOut;
|
||||
const char* fileOutTmp;
|
||||
uLong* nRecovered;
|
||||
uLong* bytesRecovered;
|
||||
{
|
||||
int err = Z_OK;
|
||||
FILE* fpZip = fopen(file, "rb");
|
||||
FILE* fpOut = fopen(fileOut, "wb");
|
||||
FILE* fpOutCD = fopen(fileOutTmp, "wb");
|
||||
if (fpZip != NULL && fpOut != NULL) {
|
||||
int entries = 0;
|
||||
uLong totalBytes = 0;
|
||||
char header[30];
|
||||
char filename[256];
|
||||
char extra[1024];
|
||||
int offset = 0;
|
||||
int offsetCD = 0;
|
||||
while ( fread(header, 1, 30, fpZip) == 30 ) {
|
||||
int currentOffset = offset;
|
||||
|
||||
/* File entry */
|
||||
if (READ_32(header) == 0x04034b50) {
|
||||
unsigned int version = READ_16(header + 4);
|
||||
unsigned int gpflag = READ_16(header + 6);
|
||||
unsigned int method = READ_16(header + 8);
|
||||
unsigned int filetime = READ_16(header + 10);
|
||||
unsigned int filedate = READ_16(header + 12);
|
||||
unsigned int crc = READ_32(header + 14); /* crc */
|
||||
unsigned int cpsize = READ_32(header + 18); /* compressed size */
|
||||
unsigned int uncpsize = READ_32(header + 22); /* uncompressed sz */
|
||||
unsigned int fnsize = READ_16(header + 26); /* file name length */
|
||||
unsigned int extsize = READ_16(header + 28); /* extra field length */
|
||||
filename[0] = extra[0] = '\0';
|
||||
|
||||
/* Header */
|
||||
if (fwrite(header, 1, 30, fpOut) == 30) {
|
||||
offset += 30;
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Filename */
|
||||
if (fnsize > 0) {
|
||||
if (fread(filename, 1, fnsize, fpZip) == fnsize) {
|
||||
if (fwrite(filename, 1, fnsize, fpOut) == fnsize) {
|
||||
offset += fnsize;
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
err = Z_STREAM_ERROR;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Extra field */
|
||||
if (extsize > 0) {
|
||||
if (fread(extra, 1, extsize, fpZip) == extsize) {
|
||||
if (fwrite(extra, 1, extsize, fpOut) == extsize) {
|
||||
offset += extsize;
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Data */
|
||||
{
|
||||
int dataSize = cpsize;
|
||||
if (dataSize == 0) {
|
||||
dataSize = uncpsize;
|
||||
}
|
||||
if (dataSize > 0) {
|
||||
char* data = MEM2_alloc(dataSize);
|
||||
if (data != NULL) {
|
||||
if ((int)fread(data, 1, dataSize, fpZip) == dataSize) {
|
||||
if ((int)fwrite(data, 1, dataSize, fpOut) == dataSize) {
|
||||
offset += dataSize;
|
||||
totalBytes += dataSize;
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
}
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
}
|
||||
MEM2_free(data);
|
||||
if (err != Z_OK) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
err = Z_MEM_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Central directory entry */
|
||||
{
|
||||
char header[46];
|
||||
char* comment = "";
|
||||
int comsize = (int) strlen(comment);
|
||||
WRITE_32(header, 0x02014b50);
|
||||
WRITE_16(header + 4, version);
|
||||
WRITE_16(header + 6, version);
|
||||
WRITE_16(header + 8, gpflag);
|
||||
WRITE_16(header + 10, method);
|
||||
WRITE_16(header + 12, filetime);
|
||||
WRITE_16(header + 14, filedate);
|
||||
WRITE_32(header + 16, crc);
|
||||
WRITE_32(header + 20, cpsize);
|
||||
WRITE_32(header + 24, uncpsize);
|
||||
WRITE_16(header + 28, fnsize);
|
||||
WRITE_16(header + 30, extsize);
|
||||
WRITE_16(header + 32, comsize);
|
||||
WRITE_16(header + 34, 0); /* disk # */
|
||||
WRITE_16(header + 36, 0); /* int attrb */
|
||||
WRITE_32(header + 38, 0); /* ext attrb */
|
||||
WRITE_32(header + 42, currentOffset);
|
||||
/* Header */
|
||||
if (fwrite(header, 1, 46, fpOutCD) == 46) {
|
||||
offsetCD += 46;
|
||||
|
||||
/* Filename */
|
||||
if (fnsize > 0) {
|
||||
if (fwrite(filename, 1, fnsize, fpOutCD) == fnsize) {
|
||||
offsetCD += fnsize;
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
err = Z_STREAM_ERROR;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Extra field */
|
||||
if (extsize > 0) {
|
||||
if (fwrite(extra, 1, extsize, fpOutCD) == extsize) {
|
||||
offsetCD += extsize;
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Comment field */
|
||||
if (comsize > 0) {
|
||||
if ((int)fwrite(comment, 1, comsize, fpOutCD) == comsize) {
|
||||
offsetCD += comsize;
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Success */
|
||||
entries++;
|
||||
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Final central directory */
|
||||
{
|
||||
int entriesZip = entries;
|
||||
char header[22];
|
||||
char* comment = ""; // "ZIP File recovered by zlib/minizip/mztools";
|
||||
int comsize = (int) strlen(comment);
|
||||
if (entriesZip > 0xffff) {
|
||||
entriesZip = 0xffff;
|
||||
}
|
||||
WRITE_32(header, 0x06054b50);
|
||||
WRITE_16(header + 4, 0); /* disk # */
|
||||
WRITE_16(header + 6, 0); /* disk # */
|
||||
WRITE_16(header + 8, entriesZip); /* hack */
|
||||
WRITE_16(header + 10, entriesZip); /* hack */
|
||||
WRITE_32(header + 12, offsetCD); /* size of CD */
|
||||
WRITE_32(header + 16, offset); /* offset to CD */
|
||||
WRITE_16(header + 20, comsize); /* comment */
|
||||
|
||||
/* Header */
|
||||
if (fwrite(header, 1, 22, fpOutCD) == 22) {
|
||||
|
||||
/* Comment field */
|
||||
if (comsize > 0) {
|
||||
if ((int)fwrite(comment, 1, comsize, fpOutCD) != comsize) {
|
||||
err = Z_ERRNO;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
err = Z_ERRNO;
|
||||
}
|
||||
}
|
||||
|
||||
/* Final merge (file + central directory) */
|
||||
fclose(fpOutCD);
|
||||
if (err == Z_OK) {
|
||||
fpOutCD = fopen(fileOutTmp, "rb");
|
||||
if (fpOutCD != NULL) {
|
||||
int nRead;
|
||||
char buffer[8192];
|
||||
while ( (nRead = (int)fread(buffer, 1, sizeof(buffer), fpOutCD)) > 0) {
|
||||
if ((int)fwrite(buffer, 1, nRead, fpOut) != nRead) {
|
||||
err = Z_ERRNO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(fpOutCD);
|
||||
}
|
||||
}
|
||||
|
||||
/* Close */
|
||||
fclose(fpZip);
|
||||
fclose(fpOut);
|
||||
|
||||
/* Wipe temporary file */
|
||||
(void)remove(fileOutTmp);
|
||||
|
||||
/* Number of recovered entries */
|
||||
if (err == Z_OK) {
|
||||
if (nRecovered != NULL) {
|
||||
*nRecovered = entries;
|
||||
}
|
||||
if (bytesRecovered != NULL) {
|
||||
*bytesRecovered = totalBytes;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
err = Z_STREAM_ERROR;
|
||||
}
|
||||
return err;
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
/*
|
||||
Additional tools for Minizip
|
||||
Code: Xavier Roche '2004
|
||||
License: Same as ZLIB (www.gzip.org)
|
||||
*/
|
||||
|
||||
#ifndef _zip_tools_H
|
||||
#define _zip_tools_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef _ZLIB_H
|
||||
#include "zlib.h"
|
||||
#endif
|
||||
|
||||
#include "unzip.h"
|
||||
|
||||
/* Repair a ZIP file (missing central directory)
|
||||
file: file to recover
|
||||
fileOut: output file after recovery
|
||||
fileOutTmp: temporary file name used for recovery
|
||||
*/
|
||||
extern int ZEXPORT unzRepair(const char* file,
|
||||
const char* fileOut,
|
||||
const char* fileOutTmp,
|
||||
uLong* nRecovered,
|
||||
uLong* bytesRecovered);
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user