📄 extracttitle.cpp
字号:
///********************************************************
// \\\|///
// \\ - - //
// ( @ @ )
//┏━━━━━━━━━━━━━oOOo-(_)-oOOo━━━━━━━━━━━━┓
//┃☆☆☆☆☆☆ ≈≈≈大家好!我是【王晓钰】≈≈≈ ☆☆☆☆☆☆┃
//┃№№№№$$$$№№№№$$$$№№№№$$$$№№№№$$$ ┃
//┃¤¤※※※※ ≈≈≈≈≈≈谢谢大家的厚爱≈≈≈≈≈≈※※※※¤¤┃
//┃★★★★★主页“笑语小园”:http://xiaoyuyeah.yeah.net★★★★★┃
//┃★★★★★主页“笑语小园”:http://xiaoyuyeah.126.com ★★★★★┃
//┃★★★★★☆☆电子邮件: Garden.XiaoYu@263.net ☆☆★★★★★┃
//┃★★★★★OICQ: 285126 ★★★★★┃
//┃☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆ ┃
//┃ Oooo〖王晓钰〗2001年02月12日┃
//┗━━━━━━━━━━━━━━oooO---( )━━━━━━━━━━━━┛
// ( ) ) /
// \ ( (_/
// \_)
///*******************************************************
/// ExtractTitle.cpp: implementation of the CExtractTitle class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "ExtractTitle.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CExtractTitle::CExtractTitle()
{ totalFileNumber=0;
fileNum=0;
saved=false;
}
CExtractTitle::~CExtractTitle()
{
}
//DEL CExtractTitle::CExtractTitle(CString sourceStr,CString srcInsert,LPCTSTR insertAfter,int after=1)
//DEL { initSource();
//DEL }
//DEL CString CExtractTitle::test()
//DEL { //return CString("sucessful for this class");
//DEL /*CString ss=memFile;
//DEL ss.MakeLower();
//DEL int ii=ss.Find("<body>");
//DEL return ss.Left(ii);
//DEL ExtractFile("test.html");
//DEL cout<<"\n\nlook here :title\nbegin|=>"<<fileInfo.title<<"<=|end\n";
//DEL cout<<"\n\nlook here :topic\nbegin|=>"<<fileInfo.topic<<"<=|end\n";
//DEL return fileInfo.title;
//DEL */
//DEL ExtractFile("test.html");
//DEL resultInfo.insertLine(memFileStr);
//DEL myWriteFile("result.html");
//DEL return "";
//DEL }
int CExtractTitle::myReadFile(LPCTSTR file)
{ fileInfo.name=file;
if(!f.GetStatus(fileInfo.name,status))
return 1; //file not exist;
fileInfo.size=status.m_size;
if(status.m_size<10) return 3;
if(!f.Open(fileInfo.name,CFile::modeRead))
return 2; //error in read;
fileInfo.length=f.GetLength();
maxNum=fileInfo.length>MAXNUM?MAXNUM:fileInfo.length;
maxNum=f.Read(memFile,maxNum);
f.Close();
memFileStr=memFile;
memFileStrOrginal=memFile;
memFileStr.MakeLower();
index=0;
return 0;
}
CString CExtractTitle::searchTitle()
{ int start,end,length;
start=memFileStr.Find("<title>",index)+7;
end=memFileStr.Find("</title>",index);
if(start<0 || end<0) return "";
index=end;
length=(end-start)>MAXLENGTH?
MAXLENGTH:(end-start); //找到了
fileInfo.title=memFileStrOrginal.Mid(start,length);
if(!IsOk(fileInfo.title)) fileInfo.title+=" ";
return fileInfo.title;
}
//查找主题,程序的关键。
CString CExtractTitle::searchTopic()
{ int start,end,length,tmpStart;
CString scriptStr;
tmpStart=memFileStr.Find("<body",index); //perfect <body
if(tmpStart>1) index=tmpStart;
else index=memFileStr.Find("<",index); //以防文中没有<body...>
index=memFileStr.Find(">",index)+1; //perfect <body...>
start=index;
do{
search:
tmpStart=start;
end=memFileStr.Find("<",start);
if(end>-1)
{
start=memFileStr.Find(">",end);
if(start>-1)
{ ///identify the :<script>
scriptStr=memFileStrOrginal.Mid(end,start);
if(!scriptStr.Find("<script",0))// .CompareNoCase("<script"))
{ start=memFileStr.Find("</script>",start);
start=memFileStr.Find('>',start);
goto search;
}
length=end-tmpStart;//(end-tmpStart)>MAXLENGTH?MAXLENGTH:(end-tmpStart);
}
else //原文件有问题。'<'不匹配
length=2*MAXLENGTH;
}
else length=2*MAXLENGTH;
// fileInfo.topic.Empty();
fileInfo.topic=memFileStrOrginal.Mid(tmpStart+1,length-1);
}while(!IsOk(fileInfo.topic));
index=tmpStart;
fileInfo.topic=DelSpace(fileInfo.topic);
if(fileInfo.topic.GetLength()>MAXLENGTH)
fileInfo.topic=fileInfo.topic.Left(MAXLENGTH);
if(fileInfo.topic.GetLength()==0) fileInfo.topic+=" ";
fileInfo.topic+=char(0x0d);
fileInfo.topic+=char(0x0a);
return fileInfo.topic;
}
int CExtractTitle::ExtractFile(CString file)
{ saved=false;
Display(fileInfo.name);
totalFileNumber++;
int result=myReadFile(file);
if(result)
{ ::MessageBox(NULL,"读取文件有错误","错误",MB_ICONERROR|MB_OK);
return result;
}
searchTitle();
searchTopic();
//这是一种输出的信息,以后可以改。
//if(fileNum %10==1) Seperate();
CString out,insertStr;
int theIndex;
insertStr=resultInfo.GetInsertString();
out.Format("%d",fileNum);
theIndex=insertStr.Find("</td>");
insertStr.Insert(theIndex,out);
theIndex=insertStr.Find("</td>",theIndex+out.GetLength()+5);
int nn=totalPathlength;
CString dispStr=fileInfo.name.Mid(nn);
nn=dispStr.GetLength();
if(nn>25)
{ //dispStr=dispStr.Right(25);
nn=dispStr.ReverseFind(char(0x5c));
dispStr=dispStr.Mid(nn);
}
out.Format("<a href=\"%s\" target=\"_blank\">%s</a>",
fileInfo.name,dispStr
);
insertStr.Insert(theIndex,out);
theIndex=insertStr.Find("</td>",theIndex+out.GetLength()+5);
insertStr.Insert(theIndex,fileInfo.title);
theIndex=insertStr.Find("</td>",theIndex+fileInfo.title.GetLength()+5);
insertStr.Insert(theIndex,fileInfo.topic);
theIndex=insertStr.Find("</td>",theIndex+fileInfo.topic.GetLength()+5);
out.Format("%ub",fileInfo.size);
insertStr.Insert(theIndex,out);
resultInfo.insertLine(insertStr);
/*×××为了让用户能够看清楚,不要这个提示。
CString str;
str.Format("已经提取了%d个文件",totalFileNumber);
Display(str);
*/
return 0;
}
/*
//这是一种输出的信息,以后可以改。
CString out1("
<tr>
<td width=\"25%%\"></td>
<td width=\"35%%\"></td>
<td width=\"35%%\"></td>
<td width=\"5%%\"></td>
</tr>");
CString out;
out.LoadString(IDS_TR);
CString fileName="<a href=\"";
fileName+=fileInfo.name;
fileName+="\" target=\"_blank\">";
//int theIndex;//=fileInfo.name.ReverseFind(TCHAR(0x5c));
fileName+=fileInfo.name.Right(20);//theIndex));
fileName+="</a>";
//插入文件名
theIndex=out.Find("</td>");
out.Insert(theIndex,fileName);
theIndex=out.Find("</td>");
out.Insert(theIndex,fileInfo.title); //title
theIndex=out.Find("</td>");
out.Insert(theIndex,fileInfo.topic); //topic
theIndex=out.Find("</td>");
out.Insert(theIndex,(LPCTSTR)fileInfo.size); //size
resultInfo.insertLine(out); //fileInfo.title);//+fileInfo.name);
return 0;
}
*/
int CExtractTitle::ExtractDir(CString dir)
{ if(dir.Right(2)=="..")
return -1;
CString dispDir;
int fileFound=0;
dispDir.Format("<tr border=\"0\" bgcolor=\"#FFCCFF\" borderColorDark=#ffffff borderColorLight=#6868d0 > \
<td colspan=\"5\" class=\"14p\" height=\"1\" bgcolor=\"#FFCCFF\"> \
<div align=\"center\"><a href=\"%s\" target=\'_blank\'>当前目录: %s</a></div> \
</td></tr> \
",dir,dir);
CFileFind finder;
dir+="\\*.htm*";
BOOL bWorking = finder.FindFile(dir);
while (bWorking)
{ bWorking = finder.FindNextFile();
fileNum++;
if(fileFound==0) resultInfo.insertLine(dispDir);
fileFound++;
fileInfo.name=finder.GetFilePath();
//path=finder.GetRoot();
ExtractFile(finder.GetFilePath());
}
return 0;
}
int CExtractTitle::_resultInfo::insertLine(CString oneFileTopic)
{ int insertBack= out.Insert(index,oneFileTopic);
index+=oneFileTopic.GetLength();
return insertBack;
}
int CExtractTitle::myWriteFile(LPCTSTR file)
{ //if(f.GetStatus(file,status)) return 1; //already exist
if(!f.Open(file,CFile::modeCreate | CFile::modeWrite)) return 2; //error in write;
f.Write(resultInfo.out,resultInfo.out.GetLength());
f.Close();
return 0;
}
//DEL void CExtractTitle::testGood()
//DEL { initSource();
//DEL char dir[50];
//DEL GetCurrentDirectory(50,dir);
//DEL path=dir;
//DEL ExtractDir((LPCTSTR)dir);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -