144 lines
4.4 KiB
Plaintext
144 lines
4.4 KiB
Plaintext
*/
|
|
|
|
/*
|
|
#include <uuencode/uuencode.hpp>
|
|
#include <common/string.hpp>
|
|
#include <common/StringBuffer.hpp>
|
|
#include <common/array.hpp>
|
|
#include <stdio.h>
|
|
|
|
String UUEncode::encode(Array<BYTE> &encodeBytes)
|
|
{
|
|
static char Base64Table[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
int length;
|
|
int index;
|
|
StringBuffer strTempLine;
|
|
|
|
strTempLine.growBy(8192);
|
|
if(!(length=encodeBytes.size()))return String();
|
|
for(index=0;index<length-(length%3);index+=3)
|
|
{
|
|
strTempLine.append(Base64Table[encodeBytes[index]/4]);
|
|
strTempLine.append(Base64Table[((encodeBytes[index%4])*16)+(encodeBytes[index+1]/16)]);
|
|
strTempLine.append(Base64Table[((encodeBytes[index+1]%16)*4)+(encodeBytes[index+2]/64)]);
|
|
strTempLine.append(Base64Table[encodeBytes[index+2]%64]);
|
|
}
|
|
if((length%3))
|
|
{
|
|
if(2==(length%3))
|
|
{
|
|
strTempLine.append(Base64Table[encodeBytes[index]/4]);
|
|
strTempLine.append(Base64Table[((encodeBytes[index]%4)*16)+(encodeBytes[index+1]/16)]);
|
|
strTempLine.append(Base64Table[(encodeBytes[index+1]%16)*4]);
|
|
strTempLine.append("=");
|
|
}
|
|
else if(1==(length%3))
|
|
{
|
|
strTempLine.append(Base64Table[encodeBytes[index]/4]);
|
|
strTempLine.append(Base64Table[(encodeBytes[index]%4)*16]);
|
|
strTempLine.append("==");
|
|
}
|
|
}
|
|
return strTempLine.toString();
|
|
}
|
|
|
|
String UUEncode::encode(String strEncode)
|
|
{
|
|
static char Base64Table[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
int length;
|
|
int index;
|
|
String strTempLine;
|
|
|
|
if(strEncode.isNull()||!(length=strEncode.length()))return String();
|
|
for(index=0;index<length-(length%3);index+=3)
|
|
{
|
|
strTempLine+=Base64Table[strEncode.charAt(index)/4];
|
|
strTempLine+=Base64Table[((strEncode.charAt(index)%4)*16)+(strEncode.charAt(index+1)/16)];
|
|
strTempLine+=Base64Table[((strEncode.charAt(index+1)%16)*4)+(strEncode.charAt(index+2)/64)];
|
|
strTempLine+=Base64Table[strEncode.charAt(index+2)%64];
|
|
}
|
|
if((length%3))
|
|
{
|
|
if(2==(length%3))
|
|
{
|
|
strTempLine+=Base64Table[strEncode.charAt(index)/4];
|
|
strTempLine+=Base64Table[((strEncode.charAt(index)%4)*16)+(strEncode.charAt(index+1)/16)];
|
|
strTempLine+=Base64Table[(strEncode.charAt(index+1)%16)*4];
|
|
strTempLine+="=";
|
|
}
|
|
else if(1==(length%3))
|
|
{
|
|
strTempLine+=Base64Table[strEncode.charAt(index)/4];
|
|
strTempLine+=Base64Table[(strEncode.charAt(index)%4)*16];
|
|
strTempLine+="==";
|
|
}
|
|
}
|
|
return strTempLine;
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
#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;
|
|
}
|
|
|
|
*/
|
|
*/ |