61 lines
2.0 KiB
C++
61 lines
2.0 KiB
C++
#include <smtp/uuencode.hpp>
|
|
#include <common/openfile.hpp>
|
|
#include <common/pview.hpp>
|
|
#include <common/filemap.hpp>
|
|
#include <common/progress.hpp>
|
|
#include <common/profile.hpp>
|
|
|
|
BOOL UUEncode::encode(GUIWindow &parentWindow,String srcPathFileName,Block<String> &lineStrings,BOOL initBlock)const
|
|
{
|
|
Profile iniProfile;
|
|
char readBuff[45];
|
|
int readCount;
|
|
int byteCount;
|
|
int lineCount;
|
|
char *ptrBuff;
|
|
String outLine;
|
|
int ch;
|
|
|
|
if(initBlock)lineStrings.remove();
|
|
if(srcPathFileName.isNull())return FALSE;
|
|
FileHandle readFile(srcPathFileName,FileHandle::Read,FileHandle::ShareRead);
|
|
if(!readFile.isOkay())return FALSE;
|
|
FileMap readMap(readFile);
|
|
PureViewOfFile readView(readMap);
|
|
iniProfile.makeFileName(srcPathFileName);
|
|
srcPathFileName.removeTokens("\\/");
|
|
::sprintf(outLine,"begin %d %s",644,(char*)srcPathFileName);
|
|
lineStrings.insert(&outLine);
|
|
Progress encodeProgress(parentWindow,srcPathFileName);
|
|
encodeProgress.canCancel(TRUE);
|
|
encodeProgress.show(TRUE);
|
|
encodeProgress.setText("encoding... (press ESC to cancel).");
|
|
while(sizeof(readBuff)==readView.read(readBuff,sizeof(readBuff))){parentWindow.yieldTask();lineCount++;}
|
|
readView.rewind();
|
|
encodeProgress.range(lineCount);
|
|
while(readCount=readView.read(readBuff,sizeof(readBuff)))
|
|
{
|
|
String lineString;
|
|
char *ptrLine=(LPSTR)lineString;
|
|
*(ptrLine++)=chEncode(readCount);
|
|
for(ptrBuff=readBuff,byteCount=readCount;byteCount>0;byteCount-=3,ptrBuff+=3)
|
|
{
|
|
*(ptrLine++)=chEncode(*ptrBuff>>2);
|
|
*(ptrLine++)=chEncode((*ptrBuff<<4)&0x30|(ptrBuff[1]>>4)&0x0F);
|
|
*(ptrLine++)=chEncode((ptrBuff[1]<<2)&0x3C|(ptrBuff[2]>>6)&0x03);
|
|
*(ptrLine++)=chEncode(ptrBuff[2]&0x3F);
|
|
parentWindow.yieldTask();
|
|
}
|
|
lineStrings.insert(&lineString);
|
|
encodeProgress++;
|
|
if(!encodeProgress.isOkay()){lineStrings.remove();return FALSE;}
|
|
if(readCount!=sizeof(readBuff))break;
|
|
}
|
|
String lastLine;
|
|
lastLine+=(char)('\0'?('\0'&0x3F)+' ':'`');
|
|
lineStrings.insert(&lastLine);
|
|
lineStrings.insert(&String("end"));
|
|
return TRUE;
|
|
}
|
|
|