#include #include #include #include #include #include #include #include bool YDecoder::isYEnc(const String &pathFileName) { YHeader yHeader; String strLine; File inFile; bool haveHeader=false; if(!inFile.open(pathFileName,"rb"))return false; while(true) { if(!inFile.readLine(strLine))break; if(yHeader.fromString(strLine)) { haveHeader=true; break; } } if(!haveHeader)return false; return true; } bool YDecoder::decode(const String &pathFileName,String &strPathImageFile,Method method) { File inFile; File outFile; String strLine; YHeader yHeader; PureDecoder pureDecoder; String strPath; bool haveHeader=false; bool result=false; Profile profile; if(!inFile.open(pathFileName,"rb"))return false; while(true) { if(!inFile.readLine(strLine))break; if(yHeader.fromString(strLine)) { haveHeader=true; break; } } if(!haveHeader)return false; ::unlink(strPath+yHeader.getName()); inFile.readLine(strLine); strPath=pathFileName; if(!Profile::makeDirectoryName(strPath))strPath=String(); else strPath+=String("\\"); outFile.open(strPath+yHeader.getName(),"w+b"); packFile(outFile,yHeader.getSize()); yHeader.setPart(0); try { result=pureDecoder.yDecode(outFile.getFile(),inFile.getFile(),yHeader.getLine(),yHeader.getSize(),yHeader.getPart()); } catch(...) { ::printf("[YDecoder::decode] caught an exception decoding %s\n",pathFileName); } if(!result && AbortOnError==method) { outFile.close(); ::unlink(strPath+yHeader.getName()); return false; } strPathImageFile=yHeader.getName(); outFile.close(); inFile.close(); return true; } void YDecoder::packFile(File &outFile,int byteCount) { Array bytes; bytes.size(byteCount); ::memset(&bytes[0],255,byteCount); outFile.write(&bytes[0],byteCount); outFile.rewind(); } void main(int argc,char**argv) { FindData findData; String strPathImageFile; String strPath; String strPattern; String strSeparator("\\"); if(argc!=3) { ::printf("USAGE: \n"); ::printf("(ie) ydecode ..\\news *.uue\n"); return; } strPath=argv[1]; strPattern=argv[2]; ::printf("%s%s%s\n",strPath.str(),strSeparator.str(),strPattern.str()); if(findData.findFirst(strPath+strSeparator+strPattern)) { if(!YDecoder::decode(strPath+strSeparator+findData.fileName(),strPathImageFile,YDecoder::ForceDecode)) ::printf("Decode failed for %s\n",String(strPath+strSeparator+findData.fileName()).str()); else ::printf("Decoded %s->%s\n",String(strPath+strSeparator+findData.fileName()).str(),strPathImageFile.str()); while(findData.findNext()) { if(!YDecoder::decode(strPath+strSeparator+findData.fileName(),strPathImageFile,YDecoder::ForceDecode)) ::printf("Decode failed for %s\n",String(strPath+strSeparator+findData.fileName()).str()); else ::printf("Decoded %s->%s\n",String(strPath+strSeparator+findData.fileName()).str(),strPathImageFile.str()); } } }