📄 pgpsdadecode.c
字号:
#if E_BUSNIESS_SERVER || PGPREADER
sCreateDir(gpi->szPrefixPath, gpi->FileName);
#else /* !E_BUSINESS_SERVER && !PGPREADER */
#ifdef WIN32
_mkdir(dirname);
#else /* !WIN32 */
mkdir(dirname, 0700);
#endif /* WIN32 */
#endif /* E_BUSINESS_SERVER || PGPREADER */
// Keep track of it so we can delete it later
FileListFromFile(&gpi->fl,dirname,NULL);
gpi->fl->IsDirectory=TRUE;
gpi->bFeedFilename=TRUE;
}
// Create zero length file and get next
else if (gpi->FileSize==0)
{
char inname[MAX_PATH];
char outname[MAX_PATH];
strcpy(inname,gpi->szPrefixPath);
strcat(inname,gpi->FileName);
Event.type=kSDAEvent_NewFileEvent;
Event.data.newfileData.fileName=inname;
err=(gpi->UserProc)(NULL,&Event,gpi->pUserValue);
if(IsPGPError(err))
{
gpi->err=err;
return 1;
}
Event.type=kSDAEvent_AskFileEvent;
Event.data.askfileData.inName=inname;
Event.data.askfileData.outName=outname;
err=(gpi->UserProc)(NULL,&Event,gpi->pUserValue);
if(IsPGPError(err))
{
gpi->err=err;
return 1;
}
#if E_BUSNIESS_SERVER || PGPREADER
#ifdef WIN32
gpi->fout=fopen(outname,"wb");
#else /* !WIN32 */
#ifdef NO_64INT
gpi->fout=fopen(outname, "wb");
#else /* NO_64INT */
gpi->fout=fopen64(outname, "wb");
#endif /* NO_64INT */
#endif /* WIN32 */
#else /* !E_BUSINESS_SERVER && !PGPREADER */
gpi->fout=fopen(outname,"wb");
#endif /* E_BUSINESS_SERVER || PGPREADER */
if(gpi->fout==0)
{
// Can't create the file
gpi->err=kPGPError_FileOpFailed;
Event.type=kSDAEvent_ErrorEvent;
Event.data.errorData.fileName=outname;
Event.data.errorData.err=gpi->err;
err=(gpi->UserProc)(NULL,&Event,gpi->pUserValue);
return 1;
}
// Keep track of it so we can delete it later
FileListFromFile(&gpi->fl,outname,NULL);
fclose(gpi->fout);
gpi->fout=NULL;
gpi->bFeedFilename=TRUE;
}
// Prepare for real data for file
else
{
char inname[MAX_PATH];
char outname[MAX_PATH];
#ifndef WIN32
/*
* Change directory separator from '\\' to '/' for Unix systems.
*/
char szDirWinSeps[] = "\\";
char *pNext = NULL;
pNext = strstr(gpi->szPrefixPath, szDirWinSeps);
while(pNext != NULL)
{
pNext[0] = '/';
pNext = strstr(pNext, szDirWinSeps);
}
pNext = strstr(gpi->FileName, szDirWinSeps);
while(pNext != NULL)
{
pNext[0] = '/';
pNext = strstr(pNext, szDirWinSeps);
}
#endif /* WIN32 */
strcpy(inname,gpi->szPrefixPath);
strcat(inname,gpi->FileName);
Event.type=kSDAEvent_NewFileEvent;
Event.data.newfileData.fileName=inname;
err=(gpi->UserProc)(NULL,&Event,gpi->pUserValue);
if(IsPGPError(err))
{
gpi->err=err;
return 1;
}
Event.type=kSDAEvent_AskFileEvent;
Event.data.askfileData.inName=inname;
Event.data.askfileData.outName=outname;
err=(gpi->UserProc)(NULL,&Event,gpi->pUserValue);
if(IsPGPError(err))
{
gpi->err=err;
return 1;
}
gpi->bFeedFilename=FALSE;
#if E_BUSINESS_SERVER || PGPREADER
#ifdef WIN32
gpi->fout=fopen(outname,"wb");
#else /* !WIN32 */
#ifdef NO_64INT
gpi->fout=fopen(outname, "wb");
#else /* !NO_64INT */
gpi->fout=fopen64(outname, "wb");
#endif /* NO_64INT */
#endif /* WIN32 || PGP_UNIX_LINUX */
#else /* !E_BUSINESS_SERVER && !PGPREADER */
gpi->fout=fopen(outname,"wb");
#endif /* E_BUSINESS_SERVER || PGPREADER */
if(gpi->fout==0)
{
#if E_BUSINESS_SERVER || PGPREADER
char szFilename[256] = {'\0'};
char *pszLast = NULL;
char szDir[256] = {'\0'};
if(gpi->FileName[0] != szDirSeps[0])
{
sprintf(szFilename, "%s%s", szDirSeps, gpi->FileName);
}
else
strcpy(szFilename, gpi->FileName);
pszLast = strrchr(szFilename, szDirSeps[0]);
if(pszLast != NULL)
*pszLast = '\0';
sCreateDir(gpi->szPrefixPath, szFilename);
strcpy(inname, gpi->szPrefixPath);
if(gpi->szPrefixPath[strlen(gpi->szPrefixPath) - 1] != szDirSeps[0])
strcat(inname, szDirSeps);
strcat(inname, gpi->FileName[0] == szDirSeps[0] ? (char *)&gpi->FileName[1] : gpi->FileName);
Event.type=kSDAEvent_AskFileEvent;
Event.data.askfileData.inName=inname;
Event.data.askfileData.outName=outname;
err=(gpi->UserProc)(NULL,&Event,gpi->pUserValue);
if(IsPGPError(err))
{
gpi->err=err;
return 1;
}
#ifdef WIN32
gpi->fout = fopen(outname, "wb");
#else /* !WIN32 */
#ifdef NO_64INT
gpi->fout = fopen(outname, "wb");
#else /* !NO_64INT */
gpi->fout = fopen64(outname, "wb");
#endif /* NO_64INT */
#endif /* WIN32 || PGP_UNIX_LINUX */
if(gpi->fout == NULL)
{
gpi->err=kPGPError_FileOpFailed;
Event.type=kSDAEvent_ErrorEvent;
Event.data.errorData.fileName=outname;
Event.data.errorData.err=gpi->err;
err=(gpi->UserProc)(NULL,&Event,gpi->pUserValue);
return 1;
}
#else /* !E_BUSINESS_SERVER && !PGPREADER */
// Can't create the file
gpi->err=kPGPError_FileOpFailed;
Event.type=kSDAEvent_ErrorEvent;
Event.data.errorData.fileName=outname;
Event.data.errorData.err=gpi->err;
err=(gpi->UserProc)(NULL,&Event,gpi->pUserValue);
return 1;
#endif /* E_BUSINESS_SERVER || PGPREADER*/
}
// Keep track of it so we can delete it later
FileListFromFile(&gpi->fl,outname,NULL);
gpi->FileIndex=0;
}
gpi->FeedIndex=0;
}
return 1;
}
// Feed in the File!
fputc(c,gpi->fout);
gpi->FileIndex++;
if(gpi->FileIndex==gpi->FileSize)
{
fclose(gpi->fout);
gpi->fout=NULL;
gpi->bFeedFilename=TRUE;
}
return 1;
}
void DoDecompress(void *gpi)
{
#if (NOCOMPRESSION_SEA || NOCOMPRESSION_SDA)
int c;
while((c=decomp_getc_buffer(gpi))!=EOF)
{
decomp_putc_buffer(c,gpi);
}
#else
Deflate_Decompress(gpi);
#endif
}
PGPError SDADecryptFiles(SDAHEADER *SDAHeader,
PGPUInt32 *ExpandedKey,
FILELIST **fl,
char *szInFileName,
char *szPrefixPath,
SDACREATECALLBACK UserProc,void *pUserValue)
{
FILE *fin;
char inbuffer[kBlockSize];
char outbuffer[kBlockSize];
GETPUTINFO gpi;
SDAEvent Event;
memset(&gpi,0x00,sizeof(GETPUTINFO));
#if E_BUSINESS_SERVER || PGPREADER
#ifdef WIN32
fin=fopen(szInFileName,"rb");
#else /* !WIN32 */
#ifdef NO_64INT
fin=fopen(szInFileName,"rb");
#else /* !NO_64INT */
fin=fopen64(szInFileName,"rb");
#endif /* NO_64INT */
#endif /* WIN32 */
#else /* !E_BUSINESS_SERVER && !PGPREADER */
fin=fopen(szInFileName,"rb");
#endif /* E_BUSINESS_SERVER || PGPREADER */
fseek(fin, SDAHeader->offset, SEEK_SET );
gpi.fl=*fl;
gpi.szPrefixPath=szPrefixPath;
gpi.err=kPGPError_NoErr;
gpi.fin=fin;
#ifdef NO_64INT
gpi.NumFiles=SDAHeader->NumFiles[0];
#else /* !NO_64INT */
gpi.NumFiles=SDAHeader->NumFiles;
#endif /* NO_64INT */
gpi.SDAHeader=SDAHeader;
gpi.ExpandedKey=ExpandedKey;
gpi.blockindex=0;
gpi.outbuffer=outbuffer;
gpi.inbuffer=inbuffer;
#ifdef NO_64INT
gpi.from_max=SDAHeader->CompLength[0];
#else /* !NO_64INT */
gpi.from_max=SDAHeader->CompLength;
#endif /* NO_64INT */
gpi.bFeedFilename=TRUE;
gpi.UserProc=UserProc;
gpi.pUserValue=pUserValue;
DoDecompress(&gpi);
// In case of cancellation or unknown abort
if(gpi.fout!=NULL)
fclose(gpi.fout);
memset(inbuffer,0x00,kBlockSize);
memset(outbuffer,0x00,kBlockSize);
Event.type=kSDAEvent_ProgressEvent;
Event.data.progressData.bytesWritten=gpi.from_max;
Event.data.progressData.bytesTotal=gpi.from_max;
(gpi.UserProc)(NULL,&Event,gpi.pUserValue);
fclose(fin);
// Send back the filenames if its an SEA
*fl=gpi.fl;
return gpi.err;
}
/*__Editor_settings____
Local Variables:
tab-width: 4
End:
vi: ts=4 sw=4
vim: si
_____________________*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -