1659 lines
44 KiB
Plaintext
1659 lines
44 KiB
Plaintext
#if 0
|
|
WORD NewsReg::queryGroups(Block<String> &subscriberList)
|
|
{
|
|
RegKey regKey(RegKey::CurrentUser);
|
|
String groupString;
|
|
String newsGroup;
|
|
DWORD groupNumber(1);
|
|
|
|
subscriberList.remove();
|
|
if(!regKey.openKey(mNewsGroupsKeyName))return FALSE;
|
|
while(TRUE)
|
|
{
|
|
::sprintf(groupString,"%s%ld",(LPSTR)mNewsGroupsKeyValuePrefix,groupNumber++);
|
|
if(!regKey.queryValue(groupString,newsGroup))break;
|
|
subscriberList.insert(&newsGroup);
|
|
}
|
|
return (subscriberList.size()?TRUE:FALSE);
|
|
}
|
|
#endif
|
|
CallbackData::ReturnType MainWindow::timerHandler(CallbackData &/*someCallbackData*/)
|
|
{
|
|
String hostName;
|
|
|
|
killTimer(TimerID);
|
|
mlpEditWindow->setText(mWSASystem.description());
|
|
mlpEditWindow->setText(mWSASystem.systemStatus());
|
|
getHostName(hostName);
|
|
open(hostName);
|
|
mlpEditWindow->setFocus();
|
|
if(!isConnected())return (CallbackData::ReturnType)FALSE;
|
|
// ListItems listItems("c:\\work\\nntp\\newssrc");
|
|
Block<String> articleText;
|
|
GroupItem groupItem;
|
|
// group(listItems[285].groupName(),groupItem);
|
|
group("alt.binaries.pictures.erotica.cheerleaders",groupItem);
|
|
article(NNTPClient::ByNumber,groupItem.firstArticle(),articleText);
|
|
message(articleText);
|
|
// if(isConnected())list();
|
|
return (CallbackData::ReturnType)FALSE;
|
|
}
|
|
|
|
|
|
|
|
WORD NNTPClient::article(SelectionType selectionType,DWORD selection,Block<String> &articleText)
|
|
{
|
|
String controlData;
|
|
String responseLine;
|
|
|
|
if(!isConnected())return FALSE;
|
|
articleText.remove();
|
|
controlData.reserve(String::MaxString);
|
|
::sprintf(controlData,"%s %ld",(LPSTR)mNNTPCmds[Article],selection);
|
|
if(!putControlData(controlData,FALSE))return FALSE;
|
|
// if(!mNNTPControl.receive(responseLine))return FALSE;
|
|
// message(responseLine);
|
|
receiveStrings(articleText);
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
|
|
|
|
// *******************
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MainWindow : public Window, private NNTPThread // private NNTPClient
|
|
|
|
|
|
// if(!isConnected())return;
|
|
// for(int itemIndex=0;itemIndex<subscriberList.size();itemIndex++)saveNews(subscriberList[itemIndex]);
|
|
|
|
|
|
#if 0
|
|
WORD NNTPClient::group(const String &groupName,GroupItem &groupItem)
|
|
{
|
|
String controlData;
|
|
String responseLine;
|
|
|
|
if(!isConnected())return FALSE;
|
|
controlData.reserve(String::MaxString);
|
|
::sprintf(controlData,"%s %s",(LPSTR)mNNTPCmds[Group],(LPSTR)groupName);
|
|
if(!putControlData(controlData,FALSE))return FALSE;
|
|
if(!mNNTPControl.receive(responseLine))return FALSE;
|
|
message(responseLine);
|
|
if(!isInResponse(responseLine.betweenString(0,' '),mAckGroupResponseStrings))return FALSE;
|
|
groupItem<<responseLine;
|
|
return TRUE;
|
|
}
|
|
#endif
|
|
|
|
// ********************************************************************************
|
|
|
|
WORD group(const GroupItem &groupItem);
|
|
WORD shutDown(void);
|
|
WORD list(void);
|
|
WORD list(ListItems &listItems);
|
|
WORD isConnected(void);
|
|
WORD quit(void);
|
|
WORD slave(void);
|
|
WORD article(DWORD selection,Block<String> &articleText,SelectionType selectionType=ByNumber);
|
|
WORD body(void);
|
|
WORD head(void);
|
|
WORD help(void);
|
|
WORD iHave(void);
|
|
WORD last(void);
|
|
WORD newGroups(void);
|
|
WORD newNews(void);
|
|
WORD next(void);
|
|
WORD post(void);
|
|
WORD stat(void);
|
|
|
|
|
|
enum MsgID{MsgOpen,MsgIsConnected,MsgList,MsgQuit,MsgSlave,MsgGroup,MsgArticle,MsgBody,
|
|
MsgHead,MsgHelp,MsgIHave,MsgLast,MsgNewGroups,MsgNewNews,MsgNext,MsgPost,MsgStat,MsgShutDown};
|
|
|
|
|
|
|
|
|
|
|
|
void handleGroup(GroupItem *pGroupItem);
|
|
void handleList(void);
|
|
void handleList(ListItems *pListItems);
|
|
void handleShutDown(void);
|
|
void handleQuit(void);
|
|
void handleSlave(void);
|
|
void handleArticle(void);
|
|
void handleBody(void);
|
|
void handleHead(void);
|
|
void handleHelp(void);
|
|
void handleIHave(void);
|
|
void handleLast(void);
|
|
void handleNewGroups(void);
|
|
void handleNext(void);
|
|
void handlePost(void);
|
|
void handleStat(void);
|
|
|
|
|
|
|
|
|
|
inline
|
|
WORD NNTPThread::shutDown(void)
|
|
{
|
|
ThreadMessage shutDownMessage(ThreadMessage::TM_USER,MsgShutDown,0L,ThreadMessage::PriorityHigh);
|
|
return sendMessage(shutDownMessage);
|
|
}
|
|
|
|
inline
|
|
WORD NNTPThread::group(const GroupItem &groupItem)
|
|
{
|
|
GroupItem *pGroupItem=new GroupItem(groupItem);
|
|
ThreadMessage groupMessage(ThreadMessage::TM_USER,MsgGroup,(LONG)pGroupItem);
|
|
return postMessage(groupMessage);
|
|
}
|
|
|
|
inline
|
|
WORD NNTPThread::quit(void)
|
|
{
|
|
ThreadMessage quitMessage(ThreadMessage::TM_USER,MsgPost,0L);
|
|
return postMessage(quitMessage);
|
|
}
|
|
|
|
inline
|
|
WORD NNTPThread::slave(void)
|
|
{
|
|
ThreadMessage slaveMessage(ThreadMessage::TM_USER,MsgSlave,0L);
|
|
return postMessage(slaveMessage);
|
|
}
|
|
|
|
inline
|
|
WORD NNTPThread::article(DWORD selection,Block<String> &articleText,SelectionType selectionType)
|
|
{
|
|
ThreadMessage articleMessage(ThreadMessage::TM_USER,MsgArticle,0L);
|
|
return postMessage(articleMessage);
|
|
}
|
|
|
|
inline
|
|
WORD NNTPThread::body(void)
|
|
{
|
|
ThreadMessage bodyMessage(ThreadMessage::TM_USER,MsgBody,0L);
|
|
return postMessage(bodyMessage);
|
|
}
|
|
|
|
inline
|
|
WORD NNTPThread::head(void)
|
|
{
|
|
ThreadMessage headMessage(ThreadMessage::TM_USER,MsgHead,0L);
|
|
return postMessage(headMessage);
|
|
}
|
|
|
|
inline
|
|
WORD NNTPThread::help(void)
|
|
{
|
|
ThreadMessage helpMessage(ThreadMessage::TM_USER,MsgHelp,0L);
|
|
return postMessage(helpMessage);
|
|
}
|
|
|
|
inline
|
|
WORD NNTPThread::iHave(void)
|
|
{
|
|
ThreadMessage iHaveMessage(ThreadMessage::TM_USER,MsgIHave,0L);
|
|
return postMessage(iHaveMessage);
|
|
}
|
|
|
|
inline
|
|
WORD NNTPThread::last(void)
|
|
{
|
|
ThreadMessage lastMessage(ThreadMessage::TM_USER,MsgLast,0L);
|
|
return postMessage(lastMessage);
|
|
}
|
|
|
|
inline
|
|
WORD NNTPThread::newGroups(void)
|
|
{
|
|
ThreadMessage newGroupsMessage(ThreadMessage::TM_USER,MsgNewGroups,0L);
|
|
return postMessage(newGroupsMessage);
|
|
}
|
|
|
|
inline
|
|
WORD NNTPThread::newNews(void)
|
|
{
|
|
ThreadMessage newNewsMessage(ThreadMessage::TM_USER,MsgNewNews,0L);
|
|
return postMessage(newNewsMessage);
|
|
}
|
|
|
|
inline
|
|
WORD NNTPThread::next(void)
|
|
{
|
|
ThreadMessage nextMessage(ThreadMessage::TM_USER,MsgNext,0L);
|
|
return postMessage(nextMessage);
|
|
}
|
|
|
|
inline
|
|
WORD NNTPThread::post(void)
|
|
{
|
|
ThreadMessage postitMessage(ThreadMessage::TM_USER,MsgPost,0L);
|
|
return postMessage(postitMessage);
|
|
}
|
|
|
|
inline
|
|
WORD NNTPThread::stat(void)
|
|
{
|
|
ThreadMessage statMessage(ThreadMessage::TM_USER,MsgStat,0L);
|
|
return postMessage(statMessage);
|
|
}
|
|
|
|
|
|
|
|
|
|
case MsgGroup :
|
|
handleGroup((GroupItem*)userData);
|
|
break;
|
|
case MsgIsConnected :
|
|
break;
|
|
case MsgShutDown :
|
|
handleShutDown();
|
|
break;
|
|
case MsgList :
|
|
handleList();
|
|
break;
|
|
case MsgQuit :
|
|
handleQuit();
|
|
break;
|
|
case MsgSlave :
|
|
handleSlave();
|
|
break;
|
|
case MsgArticle :
|
|
handleArticle();
|
|
break;
|
|
case MsgBody :
|
|
handleBody();
|
|
break;
|
|
case MsgHead :
|
|
handleHead();
|
|
break;
|
|
case MsgHelp :
|
|
handleHelp();
|
|
break;
|
|
case MsgIHave :
|
|
handleIHave();
|
|
break;
|
|
case MsgLast :
|
|
handleLast();
|
|
break;
|
|
case MsgNewGroups :
|
|
handleNewGroups();
|
|
break;
|
|
case MsgNext :
|
|
handleNext();
|
|
break;
|
|
case MsgPost :
|
|
handlePost();
|
|
break;
|
|
case MsgStat :
|
|
handleStat();
|
|
break;
|
|
|
|
|
|
void NNTPThread::handleGroup(GroupItem *pGroupItem)
|
|
{
|
|
ThreadMessage groupMessage;
|
|
::OutputDebugString("[NNTPThread::handleGroup]\n");
|
|
if(isConnected())NNTPClient::group(*pGroupItem);
|
|
else {delete pGroupItem;pGroupItem=0;}
|
|
groupMessage.userDataOne((LONG)pGroupItem);
|
|
callHandler(MsgGroup,groupMessage);
|
|
if(pGroupItem)delete pGroupItem;
|
|
}
|
|
|
|
void NNTPThread::handleShutDown(void)
|
|
{
|
|
ThreadMessage shutDownMessage;
|
|
::OutputDebugString("[NNTPThread::handleShutDown]\n");
|
|
if(!NNTPClient::isConnected())return;
|
|
closeSocket();
|
|
callHandler(MsgShutDown,shutDownMessage);
|
|
}
|
|
|
|
void NNTPThread::handleList(void)
|
|
{
|
|
ThreadMessage listMessage;
|
|
::OutputDebugString("[NNTPThread::handleList(void)]\n");
|
|
callHandler(MsgList,listMessage);
|
|
}
|
|
|
|
void NNTPThread::handleList(ListItems *pListItems)
|
|
{
|
|
ThreadMessage listMessage;
|
|
::OutputDebugString("[NNTPThread::handleList(ListItems *pListItems)\n");
|
|
callHandler(MsgList,listMessage);
|
|
}
|
|
|
|
void NNTPThread::handleQuit(void)
|
|
{
|
|
ThreadMessage quitMessage;
|
|
::OutputDebugString("[NNTPThread::handleQuit\n");
|
|
callHandler(MsgQuit,quitMessage);
|
|
}
|
|
|
|
void NNTPThread::handleSlave(void)
|
|
{
|
|
ThreadMessage slaveMessage;
|
|
::OutputDebugString("[NNTPThread::handleSlave]\n");
|
|
callHandler(MsgSlave,slaveMessage);
|
|
}
|
|
|
|
void NNTPThread::handleArticle(void)
|
|
{
|
|
ThreadMessage articleMessage;
|
|
::OutputDebugString("[NNTPThread::handleArticle]\n");
|
|
callHandler(MsgArticle,articleMessage);
|
|
}
|
|
|
|
void NNTPThread::handleBody(void)
|
|
{
|
|
ThreadMessage bodyMessage;
|
|
::OutputDebugString("[NNTPThread::handleBody]\n");
|
|
callHandler(MsgBody,bodyMessage);
|
|
}
|
|
|
|
void NNTPThread::handleHead(void)
|
|
{
|
|
ThreadMessage headMessage;
|
|
::OutputDebugString("[NNTPThread::handleHead]\n");
|
|
callHandler(MsgHead,headMessage);
|
|
}
|
|
|
|
void NNTPThread::handleHelp(void)
|
|
{
|
|
ThreadMessage helpMessage;
|
|
::OutputDebugString("[NNTPThread::handleHelp]\n");
|
|
callHandler(MsgHelp,helpMessage);
|
|
}
|
|
|
|
void NNTPThread::handleIHave(void)
|
|
{
|
|
ThreadMessage iHaveMessage;
|
|
::OutputDebugString("[NNTPThread::handleIHave]\n");
|
|
callHandler(MsgIHave,iHaveMessage);
|
|
}
|
|
|
|
void NNTPThread::handleLast(void)
|
|
{
|
|
ThreadMessage lastMessage;
|
|
::OutputDebugString("[NNTPThread::handleLast]\n");
|
|
callHandler(MsgLast,lastMessage);
|
|
}
|
|
|
|
void NNTPThread::handleNewGroups(void)
|
|
{
|
|
ThreadMessage newGroupsMessage;
|
|
::OutputDebugString("[NNTPThread::handleNewGroups]\n");
|
|
callHandler(MsgNewGroups,newGroupsMessage);
|
|
}
|
|
|
|
void NNTPThread::handleNext(void)
|
|
{
|
|
ThreadMessage nextMessage;
|
|
::OutputDebugString("[NNTPThread::handleNext]\n");
|
|
callHandler(MsgNext,nextMessage);
|
|
}
|
|
|
|
void NNTPThread::handlePost(void)
|
|
{
|
|
ThreadMessage postingMessage;
|
|
::OutputDebugString("[NNTPThread::handlePost]\n");
|
|
callHandler(MsgPost,postingMessage);
|
|
}
|
|
|
|
void NNTPThread::handleStat(void)
|
|
{
|
|
ThreadMessage statMessage;
|
|
::OutputDebugString("[NNTPThread::handleStat]\n");
|
|
callHandler(MsgStat,statMessage);
|
|
}
|
|
|
|
|
|
//inline
|
|
//WORD NNTPThread::isConnected(void)
|
|
//{
|
|
// return NNTPClient::isConnected();
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
WORD NNTPClient::article(DWORD selection,Block<String> &articleText,SelectionType selectionType)
|
|
{
|
|
String controlData;
|
|
String responseLine;
|
|
DWORD responseLines(0);
|
|
|
|
if(!isConnected())return FALSE;
|
|
articleText.remove();
|
|
controlData.reserve(String::MaxString);
|
|
if(ByNumber==selectionType)::sprintf(controlData,"%s %ld",(LPSTR)mNNTPCmds[Article],selection);
|
|
else ::sprintf(controlData,"<%s> %ld",(LPSTR)mNNTPCmds[Article],selection);
|
|
if(!putControlData(controlData,FALSE))return FALSE;
|
|
while(mNNTPControl.receive(responseLine))
|
|
{
|
|
if(mPeriod==responseLine&&1==responseLine.length())break;
|
|
if(!responseLines++)
|
|
{
|
|
String responseString(responseLine.betweenString(0,' '));
|
|
if(isInResponse(responseString,mNackArticleResponseStrings))break;
|
|
if(isInResponse(responseString,mAckArticleResponseStrings))continue;
|
|
}
|
|
articleText.insert(&responseLine);
|
|
}
|
|
return (articleText.size()?TRUE:FALSE);
|
|
}
|
|
#endif
|
|
|
|
|
|
|
|
// WORD article(DWORD selection,Block<String> &articleText,SelectionType selectionType=ByNumber);
|
|
// WORD article(DWORD msgNumber,Block<String> &articleText);
|
|
// WORD article(const MsgID &msgID,Block<String> &articleText);
|
|
|
|
|
|
|
|
// WORD body(DWORD selection,Block<String> &bodyText,SelectionType selectionType);
|
|
// WORD head(DWORD selection,Block<String> &headText,SelectionType selectionType);
|
|
|
|
|
|
#if 0
|
|
WORD NNTPClient::head(DWORD selection,Block<String> &headText,SelectionType selectionType)
|
|
{
|
|
String controlData;
|
|
String responseLine;
|
|
DWORD responseLines(0);
|
|
|
|
if(!isConnected())return FALSE;
|
|
headText.remove();
|
|
controlData.reserve(String::MaxString);
|
|
if(ByNumber==selectionType)::sprintf(controlData,"%s %ld",(LPSTR)mNNTPCmds[Head],selection);
|
|
else ::sprintf(controlData,"<%s> %ld",(LPSTR)mNNTPCmds[Head],selection);
|
|
if(!putControlData(controlData,FALSE))return FALSE;
|
|
while(mNNTPControl.receive(responseLine))
|
|
{
|
|
if(mPeriod==responseLine&&1==responseLine.length())break;
|
|
if(!responseLines++)
|
|
{
|
|
String responseString(responseLine.betweenString(0,' '));
|
|
if(isInResponse(responseString,mNackArticleResponseStrings))break;
|
|
if(isInResponse(responseString,mAckArticleResponseStrings))continue;
|
|
}
|
|
headText.insert(&responseLine);
|
|
}
|
|
return (headText.size()?TRUE:FALSE);
|
|
}
|
|
#endif
|
|
#if 0
|
|
WORD MainWindow::getNewNews(void)
|
|
{
|
|
Block<String> messageIDStrings;
|
|
Block<String> newsGroups;
|
|
Block<String> distributionGroups;
|
|
SystemTime systemTime;
|
|
WORD isGMT(FALSE);
|
|
|
|
systemTime.hour(0);
|
|
systemTime.minute(0);
|
|
systemTime.second(0);
|
|
newsGroups.insert(&String("alt.sounds"));
|
|
newsGroups.insert(&String("alt.sounds.samples"));
|
|
distributionGroups.insert(&String("rec.music"));
|
|
distributionGroups.insert(&String("rec.wav"));
|
|
isGMT=TRUE;
|
|
newNews(newsGroups,distributionGroups,messageIDStrings,systemTime,isGMT);
|
|
return FALSE;
|
|
}
|
|
#endif
|
|
WORD MainWindow::saveNews(const String &newsGroup)
|
|
{
|
|
Block<String> articleText;
|
|
GroupItem groupItem;
|
|
DiskInfo diskInfo;
|
|
WORD okResult;
|
|
|
|
diskInfo.createDirectory(newsGroup);
|
|
diskInfo.setCurrentDirectory(newsGroup);
|
|
groupItem.groupName(newsGroup);
|
|
group(groupItem);
|
|
for(int articleNumber=groupItem.firstArticle();articleNumber<=groupItem.lastArticle();articleNumber++)
|
|
{
|
|
if(!isConnected())return FALSE;
|
|
String articleName;
|
|
::sprintf(articleName,"n%ld.new",articleNumber++);
|
|
message(articleName);
|
|
okResult=article(articleNumber,articleText);
|
|
if(okResult)
|
|
{
|
|
FileHandle saveFile(articleName,FileHandle::Write,FileHandle::ShareRead,FileHandle::Overwrite);
|
|
for(int itemIndex=0;itemIndex<articleText.size();itemIndex++)saveFile.writeLine(articleText[itemIndex]);
|
|
}
|
|
}
|
|
diskInfo.setCurrentDirectory("..");
|
|
message("finished reading news");
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
|
|
void NNTPThread::handleOpen(String *pHostName)
|
|
{
|
|
HANDLE hCurrentThread(::GetCurrentThread());
|
|
int savePriority(::GetThreadPriority(hCurrentThread));
|
|
::SetThreadPriority(hCurrentThread,THREAD_PRIORITY_HIGHEST);
|
|
ThreadMessage openMessage;
|
|
NNTPClient::open(*pHostName);
|
|
delete pHostName;
|
|
openMessage.userDataOne(isConnected());
|
|
callHandler(openMessage);
|
|
::SetThreadPriority(hCurrentThread,savePriority);
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
RegKey regKey(RegKey::CurrentUser);
|
|
DWORD rasState;
|
|
String rasUserName;
|
|
String rasPassword;
|
|
String rasEntryName;
|
|
|
|
if(!regKey.openKey(STRING_RASKEYOPTIONS))return TRUE;
|
|
if(!regKey.queryValue(STRING_RASKEYSTATE,rasState))return TRUE;
|
|
if(!regKey.queryValue(STRING_RASKEYUSERNAME,rasUserName))return TRUE;
|
|
if(!regKey.queryValue(STRING_RASKEYPASSWORD,rasPassword))return TRUE;
|
|
if(!regKey.queryValue(STRING_RASKEYENTRYNAME,rasEntryName))return TRUE;
|
|
if(!rasState)return TRUE;
|
|
mlpRasInterface=new RasInterface;
|
|
if(!mlpRasInterface->isOkay()){delete mlpRasInterface;mlpRasInterface=0;return FALSE;}
|
|
if(!mlpRasInterface->login(rasUserName,rasPassword,rasEntryName)){delete mlpRasInterface;mlpRasInterface=0;return FALSE;}
|
|
return TRUE;
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sendMessage(NewsGroupList,WM_SETREDRAW,FALSE,0L);
|
|
sendMessage(NewsGroupList,LB_RESETCONTENT,0,0L);
|
|
for(int itemIndex=0;itemIndex<subscriberList.size();itemIndex++)
|
|
sendMessage(NewsGroupList,LB_INSERTSTRING,(WPARAM)-1,(LPARAM)(LPSTR)subscriberList[itemIndex]);
|
|
sendMessage(NewsGroupList,WM_SETREDRAW,TRUE,0L);
|
|
|
|
|
|
#if 0
|
|
WORD NewsReg::queryGroups(Block<String> &subscriberList)
|
|
{
|
|
RegKey regKey(RegKey::CurrentUser);
|
|
String groupString;
|
|
String newsGroup;
|
|
String nameValue;
|
|
DWORD groupIndex(0);
|
|
|
|
subscriberList.remove();
|
|
if(!regKey.openKey(mNewsGroupsKeyName))return FALSE;
|
|
while(regKey.enumValue(groupIndex++,nameValue,newsGroup))
|
|
subscriberList.insert(&newsGroup);
|
|
return (subscriberList.size()?TRUE:FALSE);
|
|
}
|
|
#endif
|
|
|
|
|
|
|
|
|
|
//inline
|
|
//void NNTPThread::insertOpenHandler(ThreadCallbackPointer pThreadCallback)
|
|
//{
|
|
// mEventHandler=ThreadCallbackPointer(pThreadCallback);
|
|
//}
|
|
|
|
//inline
|
|
//void NNTPThread::removeOpenHandler(void)
|
|
//{
|
|
// mEventHandler=ThreadCallbackPointer();
|
|
//}
|
|
|
|
|
|
|
|
|
|
// void insertOpenHandler(ThreadCallbackPointer pThreadCallback);
|
|
// void removeOpenHandler(void);
|
|
|
|
|
|
|
|
// ThreadCallbackPointer mEventHandler;
|
|
|
|
|
|
|
|
if(systemTime.month()>=optionsReg.month()&&
|
|
systemTime.day()>=optionsReg.day()&&
|
|
systemTime.year()>=optionsReg.year()&&
|
|
systemTime.hour()>=optionsReg.hour()&&
|
|
systemTime.minute()>=optionsReg.minute())break;
|
|
|
|
|
|
|
|
#if 0
|
|
// makeTimeDateString(postDate,systemTime);
|
|
// setText(PostDate,postDate);
|
|
SystemTime systemTime;
|
|
SystemTime someTime(1997,12,1,5,0,0);
|
|
String timeDateString((String)someTime);
|
|
timeDateString+="\n";
|
|
::OutputDebugString(timeDateString);
|
|
// message((String)someTime);
|
|
#endif
|
|
|
|
|
|
void OptionsDialog::makeTimeDateString(String &timeDateString,const SystemTime &systemTime)const
|
|
{
|
|
timeDateString.reserve(String::MaxString);
|
|
::sprintf(timeDateString,"%02d%02d%02d %02d%02d%02d",
|
|
systemTime.year()>2000?2000-systemTime.year():systemTime.year()-1900,
|
|
systemTime.month(),
|
|
systemTime.day(),
|
|
systemTime.hour(),
|
|
systemTime.minute(),
|
|
systemTime.second());
|
|
}
|
|
|
|
void makeTimeDateString(String &timeDateString,const SystemTime &systemTime)const;
|
|
|
|
|
|
// SystemTime postDateTime(systemTime.year(),systemTime.month(),systemTime.day(),
|
|
// systemTime.hour(),systemTime.minute(),systemTime.second());
|
|
|
|
|
|
#if 0
|
|
void MainWindow::handleRetrieveNews(void)
|
|
{
|
|
String hostName;
|
|
|
|
if(!getSubscriberList(mSubscriberList)){message("No newsgroups in subscriber list, nothing to do!");return;}
|
|
mlpEditWindow->setFocus();
|
|
getHostName(hostName);
|
|
mCancelWait=FALSE;
|
|
open(hostName);
|
|
}
|
|
#endif
|
|
|
|
|
|
|
|
addRootNode(FolderTree::FolderClosed,pathDir,makeItemID(RootNode,1));
|
|
pathFind.dirList(pathDir,dirList);
|
|
if(dirList.size()<=2)return FALSE;
|
|
if(!makeFileName(dirList[0],entryName))return FALSE;
|
|
if(entryName!=String("."))return FALSE;
|
|
if(!makeFileName(dirList[1],entryName))return FALSE;
|
|
if(entryName!=String(".."))return FALSE;
|
|
for(int itemIndex=2;itemIndex<dirList.size();itemIndex++)
|
|
{
|
|
FindData findData;
|
|
findData.attributes(FindData::FileDirectory);
|
|
if(!findData.findFirst(dirList[itemIndex]))continue;
|
|
if(!(findData.attributes()&FindData::FileDirectory))continue;
|
|
if(!makeFileName(dirList[itemIndex],entryName))continue;
|
|
mRootDir.insert(&dirList[itemIndex]);
|
|
if(entryName==String("."))break;
|
|
TreeViewItem insertItem(0,0,0,0,(LPSTR)entryName,entryName.length(),FolderTree::FolderClosed,FolderTree::FolderOpen,0,makeItemID(DirNode,mRootDir.size()-1));
|
|
addNode(TreeView::NodeChild,insertItem,pathDir);
|
|
}
|
|
return TRUE;
|
|
|
|
|
|
|
|
String entryName(mRootDir[indexItem(callbackData)].entryName());
|
|
|
|
String pathEntryName(mRootDir[indexItem(callbackData)].pathEntryName());
|
|
Block<DirEntry> dirEntries;
|
|
getList(pathEntryName,dirEntries,FileList);
|
|
{
|
|
for(int itemIndex=0;itemIndex<dirEntries.size();itemIndex++)
|
|
{
|
|
TreeViewItem insertItem(0,0,0,0,(LPSTR)dirEntries[itemIndex].entryName(),dirEntries[itemIndex].entryName().length(),FolderTree::FolderClosed,FolderTree::FolderOpen,0,makeItemID(FileNode,itemIndex));
|
|
addNode(TreeView::NodeChild,insertItem,entryName);
|
|
}
|
|
}
|
|
// remove(entryName);
|
|
|
|
|
|
|
|
// getList(pathDir,mRootDir,DirectoryList);
|
|
// return showDirList(pathDir,mRootDir);
|
|
|
|
|
|
|
|
#if 0
|
|
Rect controlRect;
|
|
controlRect.bottom(height()/2);
|
|
controlRect.right(width());
|
|
mDirTree=new DirTree(*this,controlRect);
|
|
mDirTree.disposition(SmartPointer<DirTree>::Delete);
|
|
controlRect.top(controlRect.bottom()+1);
|
|
controlRect.bottom(height()/2);
|
|
mEditWindow=new EditWindow(&((Window&)*this),controlRect);
|
|
mEditWindow->disposition(SmartPointer<EditWindow>::Delete);
|
|
KeyControl keyControl;
|
|
keyControl.canScroll(TRUE);
|
|
mEditWindow->setKeyControl(keyControl);
|
|
mEditWindow->setLineHandler(&mLineHandler);
|
|
mDirTree->showDirList("e:\\download");
|
|
#endif
|
|
|
|
|
|
WORD DirTree::showDirList(const String &pathDir,Block<DirEntry> &dirEntries,NodeType nodeType)
|
|
{
|
|
String entryName;
|
|
|
|
// remove();
|
|
if(!dirEntries.size())return FALSE;
|
|
if(DirNode==nodeType)addRootNode(FolderTree::FolderClosed,pathDir,makeItemID(RootNode,1));
|
|
for(int itemIndex=0;itemIndex<dirEntries.size();itemIndex++)
|
|
{
|
|
DirEntry &currEntry=dirEntries[itemIndex];
|
|
TreeViewItem insertItem(0,0,0,0,(LPSTR)currEntry.entryName(),currEntry.entryName().length(),FolderTree::FolderClosed,FolderTree::FolderOpen,0,makeItemID(DirNode,itemIndex));
|
|
addNode(TreeView::NodeChild,insertItem,pathDir);
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
CallbackData::ReturnType DirTree::itemExpandedHandler(CallbackData &callbackData)
|
|
{
|
|
NodeType nodeType(nodeType(callbackData));
|
|
switch(nodeType)
|
|
{
|
|
case RootNode :
|
|
::OutputDebugString("DirTree::itemExpandedHandler(RootNode)\n");
|
|
break;
|
|
case DirNode :
|
|
::OutputDebugString(mRootDir[indexItem(callbackData)].entryName()+String("\n"));
|
|
break;
|
|
case FileNode :
|
|
::OutputDebugString("DirTree::itemExpandedHandler(FileNode)\n");
|
|
break;
|
|
default :
|
|
{
|
|
TreeViewMessageHeader &treeViewMessageHeader=*((TreeViewMessageHeader*)callbackData.lParam());
|
|
String messageString;
|
|
|
|
CallbackData callbackData(0,treeViewMessageHeader.itemNew().lParam());
|
|
::sprintf(messageString,"DirTree::itemExpandedHandler index:%d\n",
|
|
indexItem(callbackData));
|
|
// ::sprintf(messageString,"DirTree::itemExpandedHandler node type:%d item index:%d\n",(int)nodeType,indexItem(callbackData));
|
|
::OutputDebugString(messageString);
|
|
}
|
|
break;
|
|
}
|
|
return (CallbackData::ReturnType)FALSE;
|
|
}
|
|
|
|
|
|
|
|
|
|
// Header articleHeader(pathFileName);
|
|
// if(articleHeader.subject().isNull())
|
|
// {
|
|
// GenDecode genericDecoder;
|
|
// if(!genericDecoder.decode(pathFileName))::OutputDebugString(String("Error decoding article.")+pathFileName+String("\n"));
|
|
// }
|
|
// else ::OutputDebugString(pathFileName+String(" ")+articleHeader.subject()+String("\n"));
|
|
|
|
|
|
void MainWindow::handleRetrieve(void)
|
|
{
|
|
String hostName;
|
|
|
|
mMasterList.remove();
|
|
if((NewsOption::GetNews==mNewsOption.option()||
|
|
NewsOption::GetNewsSim==mNewsOption.option())&&
|
|
!getSubscriberList(mSubscriberList))
|
|
{
|
|
message("No newsgroups in subscriber list, nothing to do!");
|
|
return;
|
|
}
|
|
// retrieveNews(); // this is for debugging
|
|
// return; // this is for debugging
|
|
((EditWindow*)*((SmartPointer<EditWindow>*)mEditMonitor))->setFocus();
|
|
getHostName(hostName);
|
|
mCancelWait=FALSE;
|
|
open(hostName);
|
|
}
|
|
|
|
|
|
#if 0
|
|
DWORD MainWindow::preOpenHandler(ThreadMessage &/*someThreadMessage*/)
|
|
{
|
|
if(!waitForScheduledEvent())return TRUE;
|
|
if(!dialHost())
|
|
{
|
|
message("Could not contact host.");
|
|
return TRUE;
|
|
}
|
|
return FALSE;
|
|
}
|
|
#endif
|
|
|
|
|
|
|
|
|
|
WORD MainWindow::retrieveNews(const String &newsGroup,Block<FilterItem> &filterList,FilterReg::FilterMode mode)
|
|
{
|
|
Block<MsgID> messageIDStrings;
|
|
DiskInfo diskInfo;
|
|
DWORD pastDays;
|
|
String msgString;
|
|
WORD okResult;
|
|
|
|
diskInfo.createDirectory(newsGroup);
|
|
diskInfo.setCurrentDirectory(newsGroup);
|
|
message(String("Retrieving message headers for ")+newsGroup);
|
|
newNews(newsGroup,messageIDStrings,priorDays());
|
|
::sprintf(msgString,"%s has %ld articles.",(LPSTR)newsGroup,messageIDStrings.size());
|
|
message(msgString);
|
|
for(int itemIndex=0;itemIndex<messageIDStrings.size();itemIndex++)
|
|
{
|
|
Block<String> articleText;
|
|
Block<String> headerLines;
|
|
String pathFileName;
|
|
MsgID msgID;
|
|
|
|
if(!isConnected())return FALSE;
|
|
msgID=messageIDStrings[itemIndex];
|
|
::sprintf(pathFileName,"n%ld.new",itemIndex);
|
|
message(newsGroup+String("(")+msgID+String(")"));
|
|
if(mMasterList.searchItem(msgID))
|
|
{
|
|
message(String("Already have ")+msgID);
|
|
continue;
|
|
}
|
|
mMasterList.insert(msgID);
|
|
okResult=head(msgID,headerLines);
|
|
Header articleHeader(headerLines);
|
|
if(isInFilter(articleHeader,filterList,mode))
|
|
{
|
|
message(String("Skipping ")+msgID+String(" because article source is being filtered."));
|
|
continue;
|
|
}
|
|
okResult=article(msgID,articleText);
|
|
if(okResult)saveBlock(pathFileName,articleText);
|
|
}
|
|
diskInfo.setCurrentDirectory("..");
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
WORD MainWindow::isInFilter(Header &articleHeader,Block<FilterItem> &filterList,FilterReg::FilterMode mode)
|
|
{
|
|
for(int itemIndex=0;itemIndex<filterList.size();itemIndex++)
|
|
{
|
|
WORD isInString(articleHeader.from().strstr(filterList[itemIndex].nameFilter()));
|
|
if(FilterReg::Exclude==mode&&isInString)return TRUE;
|
|
else if(FilterReg::Include==mode&&isInString)return FALSE;
|
|
}
|
|
if(FilterReg::Include==mode)return TRUE;
|
|
return FALSE;
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
WORD MainWindow::retrieveNewsSim(const String &newsGroup)
|
|
{
|
|
MessageLog messageLog;
|
|
Block<MsgID> messageIDStrings;
|
|
DiskInfo diskInfo;
|
|
DWORD pastDays;
|
|
String msgString;
|
|
WORD okResult;
|
|
|
|
diskInfo.createDirectory(newsGroup);
|
|
diskInfo.setCurrentDirectory(newsGroup);
|
|
message(String("Retrieving message headers for ")+newsGroup);
|
|
|
|
simulateNewNews(newsGroup,messageIDStrings,priorDays());
|
|
::sprintf(msgString,"%s has %ld articles.",(LPSTR)newsGroup,messageIDStrings.size());
|
|
message(msgString);
|
|
messageLog.setLog("MSGLOG.001");
|
|
for(int itemIndex=0;itemIndex<messageIDStrings.size();itemIndex++)
|
|
{
|
|
Block<String> articleText;
|
|
String pathFileName;
|
|
MsgID msgID;
|
|
|
|
if(!isConnected())return FALSE;
|
|
msgID=messageIDStrings[itemIndex];
|
|
::sprintf(pathFileName,"n%ld.new",itemIndex);
|
|
message(newsGroup+String("(")+msgID+String(")"));
|
|
if(mMasterList.searchItem(msgID))
|
|
{
|
|
message(String("Already have ")+msgID);
|
|
continue;
|
|
}
|
|
mMasterList.insert(msgID);
|
|
okResult=article(msgID,articleText);
|
|
if(okResult)saveBlock(pathFileName,articleText);
|
|
}
|
|
diskInfo.setCurrentDirectory("..");
|
|
return TRUE;
|
|
}
|
|
#endif
|
|
|
|
|
|
|
|
WORD MainWindow::retrieveNews(const String &newsGroup)
|
|
{
|
|
Block<MsgID> messageIDStrings;
|
|
DiskInfo diskInfo;
|
|
GenDecode genericDecoder;
|
|
DWORD pastDays;
|
|
String msgString;
|
|
WORD okResult;
|
|
|
|
diskInfo.createDirectory(newsGroup);
|
|
diskInfo.setCurrentDirectory(newsGroup);
|
|
message(String("Retrieving message headers for ")+newsGroup);
|
|
newNews(newsGroup,messageIDStrings,priorDays());
|
|
::sprintf(msgString,"%s has %ld articles.",(LPSTR)newsGroup,messageIDStrings.size());
|
|
message(msgString);
|
|
for(int itemIndex=0;itemIndex<messageIDStrings.size();itemIndex++)
|
|
{
|
|
Block<String> articleText;
|
|
String pathFileName;
|
|
MsgID msgID;
|
|
|
|
if(!isConnected())return FALSE;
|
|
msgID=messageIDStrings[itemIndex];
|
|
::sprintf(pathFileName,"n%ld.new",itemIndex);
|
|
message(newsGroup+String("(")+msgID+String(")"));
|
|
if(mMasterList.searchItem(msgID))
|
|
{
|
|
message(String("Already have ")+msgID);
|
|
continue;
|
|
}
|
|
mMasterList.insert(msgID);
|
|
okResult=article(msgID,articleText);
|
|
if(okResult)
|
|
{
|
|
saveBlock(pathFileName,articleText);
|
|
if(genericDecoder.decode(pathFileName))::unlink(pathFileName);
|
|
}
|
|
}
|
|
diskInfo.setCurrentDirectory("..");
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
WORD MainWindow::retrieveNewsSim(const String &newsGroup)
|
|
{
|
|
MessageLog messageLog;
|
|
Block<MsgID> messageIDStrings;
|
|
GenDecode genericDecoder;
|
|
DiskInfo diskInfo;
|
|
DWORD pastDays;
|
|
String msgString;
|
|
WORD okResult;
|
|
|
|
diskInfo.createDirectory(newsGroup);
|
|
diskInfo.setCurrentDirectory(newsGroup);
|
|
message(String("Retrieving message headers for ")+newsGroup);
|
|
String strRecover(newsGroup);
|
|
String strMsgLog(newsGroup);
|
|
strRecover+=".001";
|
|
strMsgLog+=".002";
|
|
FileIO msgIDFile;
|
|
msgIDFile.open(strRecover,FileIO::GenericRead,FileIO::FileShareRead,FileIO::OpenExisting,FileIO::Archive);
|
|
if(msgIDFile.isOkay())
|
|
{
|
|
MsgID msgID;
|
|
message(String("using recovery file."));
|
|
while(msgIDFile.readLine(msgID))messageIDStrings.insert(&msgID);
|
|
msgIDFile.close();
|
|
}
|
|
else
|
|
{
|
|
simulateNewNews(newsGroup,messageIDStrings,priorDays());
|
|
FileIO msgIDFile;
|
|
msgIDFile.open(strRecover,FileIO::GenericWrite,FileIO::FileShareRead,FileIO::OpenAlways,FileIO::Archive);
|
|
for(int itemIndex=0;itemIndex<messageIDStrings.size();itemIndex++)msgIDFile.writeLine(messageIDStrings[itemIndex]);
|
|
msgIDFile.close();
|
|
}
|
|
// simulateNewNews(newsGroup,messageIDStrings,priorDays());
|
|
::sprintf(msgString,"%s has %ld articles.",(LPSTR)newsGroup,messageIDStrings.size());
|
|
message(msgString);
|
|
messageLog.setLog(strMsgLog);
|
|
for(int itemIndex=0;itemIndex<messageIDStrings.size();itemIndex++)
|
|
{
|
|
Block<String> articleText;
|
|
String pathFileName;
|
|
MsgID msgID;
|
|
|
|
if(!isConnected())return FALSE;
|
|
msgID=messageIDStrings[itemIndex];
|
|
::sprintf(pathFileName,"n%ld.new",itemIndex);
|
|
message(newsGroup+String("(")+msgID+String(")"));
|
|
if(messageLog.searchItem(msgID)){message(String("Already have ")+msgID);continue;}
|
|
messageLog.insert(msgID);
|
|
okResult=article(msgID,articleText);
|
|
if(okResult)
|
|
{
|
|
saveBlock(pathFileName,articleText);
|
|
if(genericDecoder.decode(pathFileName))::unlink(pathFileName);
|
|
}
|
|
okResult=FALSE;
|
|
messageLog.flush();
|
|
}
|
|
messageLog.close();
|
|
diskInfo.setCurrentDirectory("..");
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
|
|
//#include <common/string.hpp>
|
|
//#include <nntp/main.hpp>
|
|
//#include <nntp/mainwnd.hpp>
|
|
//
|
|
//HINSTANCE Main::smhInstance=0;
|
|
//HINSTANCE Main::smhPrevInstance=0;
|
|
//int Main::smnCmdShow=0;
|
|
//
|
|
//int PASCAL WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR /*lpszCmdLine*/,int nCmdShow)
|
|
//{
|
|
// Main::processInstance(hInstance);
|
|
// Main::previousProcessInstance(hPrevInstance);
|
|
// Main::cmdShow(nCmdShow);
|
|
// if(Main::previousProcessInstance())
|
|
// {
|
|
// HWND hWnd=::FindWindow(MainWindow::className(),MainWindow::className());
|
|
// if(!hWnd)
|
|
// {
|
|
// ::MessageBox(::GetFocus(),(LPSTR)"Failed to maximize previous instance",(LPSTR)"Error",MB_ICONSTOP|MB_SYSTEMMODAL);
|
|
// return FALSE;
|
|
// }
|
|
// ::PostMessage(hWnd,WM_REACTIVATE,0,0L);
|
|
// return FALSE;
|
|
// }
|
|
// MainWindow applicationWindow;
|
|
// return ((GUIWindow&)applicationWindow).messageLoop();
|
|
}
|
|
|
|
|
|
|
|
void MainFrame::registerClass(void)const
|
|
{
|
|
HINSTANCE hInstance(processInstance());
|
|
WNDCLASS wndClass;
|
|
|
|
if(::GetClassInfo(hInstance,className(),(WNDCLASS FAR*)&wndClass))return;
|
|
wndClass.style =CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS;
|
|
wndClass.lpfnWndProc =(WNDPROC)Window::WndProc;
|
|
wndClass.cbClsExtra =0;
|
|
wndClass.cbWndExtra =sizeof(MainWindow*);
|
|
wndClass.hInstance =hInstance;
|
|
wndClass.hIcon =::LoadIcon(NULL,IDI_APPLICATION);
|
|
wndClass.hCursor =::LoadCursor(NULL,IDC_ARROW);
|
|
wndClass.hbrBackground =(HBRUSH)::GetStockObject(LTGRAY_BRUSH);
|
|
wndClass.lpszMenuName =szMenuName;
|
|
wndClass.lpszClassName =szClassName;
|
|
::RegisterClass(&wndClass);
|
|
assert(0!=::GetClassInfo(hInstance,className(),(WNDCLASS FAR*)&wndClass));
|
|
}
|
|
|
|
|
|
|
|
|
|
messageLog.setLog(newsGroup);
|
|
for(int itemIndex=0;itemIndex<messageIDStrings.size();itemIndex++)
|
|
{
|
|
Block<String> articleText;
|
|
String pathFileName;
|
|
MsgID msgID;
|
|
|
|
if(!isConnected())return FALSE;
|
|
msgID=messageIDStrings[itemIndex];
|
|
::sprintf(pathFileName,"n%ld.new",itemIndex);
|
|
message(newsGroup+String("(")+msgID+String(")"));
|
|
if(messageLog.searchItem(msgID)){message(String("Already have ")+msgID);continue;}
|
|
messageLog.insert(msgID);
|
|
okResult=article(msgID,articleText);
|
|
if(okResult)
|
|
{
|
|
saveBlock(pathFileName,articleText);
|
|
if(genericDecoder.decode(pathFileName))::unlink(pathFileName);
|
|
}
|
|
okResult=FALSE;
|
|
messageLog.flush();
|
|
}
|
|
messageLog.close();
|
|
|
|
|
|
|
|
// messageLog.setLog(newsGroup);
|
|
// for(int itemIndex=0;itemIndex<messageIDStrings.size();itemIndex++)
|
|
// {
|
|
// Block<String> articleText;
|
|
// String pathFileName;
|
|
// MsgID msgID;
|
|
//
|
|
// if(!isConnected())return FALSE;
|
|
// msgID=messageIDStrings[itemIndex];
|
|
// ::sprintf(pathFileName,"n%ld.new",itemIndex);
|
|
// message(newsGroup+String("(")+msgID+String(")"));
|
|
// if(messageLog.searchItem(msgID)){message(String("Already have ")+msgID);continue;}
|
|
// messageLog.insert(msgID);
|
|
// okResult=article(msgID,articleText);
|
|
// if(okResult)
|
|
// {
|
|
// saveBlock(pathFileName,articleText);
|
|
// if(genericDecoder.decode(pathFileName))::unlink(pathFileName);
|
|
// }
|
|
// okResult=FALSE;
|
|
// messageLog.flush();
|
|
// }
|
|
// messageLog.close();
|
|
|
|
|
|
|
|
|
|
WORD MainFrame::retrieveNews(const String &newsGroup)
|
|
{
|
|
RecoverLog recoverLog;
|
|
Block<MsgID> messageIDStrings;
|
|
DiskInfo diskInfo;
|
|
String msgString;
|
|
|
|
diskInfo.createDirectory(newsGroup);
|
|
diskInfo.setCurrentDirectory(newsGroup);
|
|
message(String("Retrieving message headers for ")+newsGroup);
|
|
if(recoverLog.haveLog(newsGroup))
|
|
{
|
|
message(String("using recovery file."));
|
|
recoverLog.getEntries(newsGroup,messageIDStrings);
|
|
}
|
|
else
|
|
{
|
|
simulateNewNews(newsGroup,messageIDStrings,priorDays());
|
|
recoverLog.setEntries(newsGroup,messageIDStrings);
|
|
}
|
|
// simulateNewNews(newsGroup,messageIDStrings,priorDays());
|
|
::sprintf(msgString,"%s has %ld articles.",(LPSTR)newsGroup,messageIDStrings.size());
|
|
message(msgString);
|
|
getArticles(newsGroup,messageIDStrings);
|
|
diskInfo.setCurrentDirectory("..");
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
CallbackData::ReturnType ImageView::paintHandler(CallbackData &someCallbackData)
|
|
{
|
|
CursorControl cursorControl;
|
|
|
|
cursorControl.waitCursor(TRUE);
|
|
mMutex.requestMutex();
|
|
if(!mJPGImage.isOkay())
|
|
{
|
|
mMutex.releaseMutex();
|
|
cursorControl.waitCursor(FALSE);
|
|
return (CallbackData::ReturnType)FALSE;
|
|
}
|
|
PaintInformation &paintInfo=*((PaintInformation*)someCallbackData.lParam());
|
|
PureDevice &paintDevice=(PureDevice&)paintInfo;
|
|
|
|
if(mScrollInfo.sizeEvent())
|
|
{
|
|
mScrollInfo.sizeEvent(FALSE);
|
|
mJPGImage.draw(paintDevice,mScrollInfo.currScrollx(),mScrollInfo.currScrolly());
|
|
}
|
|
if(mScrollInfo.scrollEvent())
|
|
{
|
|
Rect paintRect(paintInfo.paintRect());
|
|
mScrollInfo.scrollEvent(FALSE);
|
|
paintRect.right(paintRect.right()-paintRect.left());
|
|
paintRect.bottom(paintRect.bottom()-paintRect.top());
|
|
mJPGImage.draw(paintDevice,,Point(paintRect.left()+mScrollInfo.currScrollx(),paintRect.top()+mScrollInfo.currScrolly()));
|
|
}
|
|
// if(mJPGImage.width()<width()||mJPGImage.height()<height())mJPGImage.draw((PureDevice&)paintInfo);
|
|
// else mJPGImage.preview((PureDevice&)paintInfo);
|
|
// mJPGImage.draw((PureDevice&)paintInfo);
|
|
// mJPGImage.draw(paintDevice);
|
|
// mJPGImage.stretch((PureDevice&)paintInfo,width(),height());
|
|
mMutex.releaseMutex();
|
|
cursorControl.waitCursor(FALSE);
|
|
return (CallbackData::ReturnType)FALSE;
|
|
}
|
|
|
|
DWORD MainFrame::preOpenHandler(ThreadMessage &/*someThreadMessage*/)
|
|
{
|
|
String retryMsg;
|
|
RasOptions rasOptions;
|
|
DWORD maxRetries(rasOptions.rasMaxRetries());
|
|
|
|
if(!waitForScheduledEvent())return TRUE;
|
|
if(dialHost())return FALSE;
|
|
::sprintf(retryMsg,"Could not contact host.");
|
|
message(retryMsg);
|
|
for(int retryCount=0;retryCount<maxRetries;retryCount++)
|
|
{
|
|
::Sleep(1000);
|
|
::sprintf(retryMsg,"retrying ...");
|
|
message(retryMsg);
|
|
if(dialHost())return FALSE;
|
|
::sprintf(retryMsg,"Cound not contact host, attempt %d of %d.",retryCount+1,maxRetries);
|
|
message(retryMsg);
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
//WORD MainFrame::waitForScheduledEvent(void)
|
|
//{
|
|
// SystemTime systemTime;
|
|
// String workString;
|
|
//
|
|
// while(TRUE)
|
|
// {
|
|
// OptionsReg optionsReg;
|
|
// if(!optionsReg.scheduled())return TRUE;
|
|
// if(mCancelWait){message("wait terminated by keystroke.");return FALSE;}
|
|
// systemTime.refresh();
|
|
// message(String("Current time is ")+(String)systemTime);
|
|
// ::sprintf(workString,"waiting for %02d-%02d-%4d %02d:%02d:%02d",
|
|
// optionsReg.month(),optionsReg.day(),optionsReg.year(),
|
|
// optionsReg.hour(),optionsReg.minute(),optionsReg.second());
|
|
// message(workString);
|
|
// if(optionsReg.isInTime(systemTime))break;
|
|
// ::Sleep(2000L);
|
|
// }
|
|
// return TRUE;
|
|
//}
|
|
|
|
|
|
|
|
|
|
BOOL MainFrame::getArticles(const String &newsGroup,Block<MsgID> &msgIDs)
|
|
{
|
|
MessageLog messageLog;
|
|
GenDecode genericDecoder;
|
|
DWORD alreadyHavesInARow(0);
|
|
BOOL okResult;
|
|
|
|
messageLog.setLog(newsGroup);
|
|
alreadyHavesInARow=0;
|
|
group(GroupItem(newsGroup));
|
|
for(int itemIndex=0;itemIndex<msgIDs.size();itemIndex++)
|
|
{
|
|
Block<String> articleText;
|
|
String pathFileName;
|
|
MsgID msgID;
|
|
|
|
if(!isConnected())return FALSE;
|
|
msgID=msgIDs[itemIndex];
|
|
::sprintf(pathFileName,"n%ld.new",itemIndex);
|
|
message(newsGroup+String("(")+msgID+String(")"));
|
|
if(messageLog.searchItem(msgID))
|
|
{
|
|
message(String("Already have ")+msgID);
|
|
alreadyHavesInARow++;
|
|
if(alreadyHavesInARow>250)
|
|
{
|
|
Block<String> headText;
|
|
message("...1 second, I need to ping the News Server...");
|
|
head(msgID,headText);
|
|
alreadyHavesInARow=0;
|
|
}
|
|
continue;
|
|
}
|
|
else alreadyHavesInARow=0;
|
|
messageLog.insert(msgID);
|
|
okResult=article(msgID,articleText);
|
|
if(okResult)
|
|
{
|
|
String strPathImageFile;
|
|
saveBlock(pathFileName,articleText);
|
|
genericDecoder.decode(pathFileName,strPathImageFile);
|
|
if(!strPathImageFile.isNull()&&openImage(strPathImageFile))::unlink(pathFileName);
|
|
// if(genericDecoder.decode(pathFileName,strPathImageFile))
|
|
// {
|
|
// ::unlink(pathFileName);
|
|
// openImage(strPathImageFile);
|
|
// }
|
|
}
|
|
okResult=FALSE;
|
|
messageLog.flush();
|
|
}
|
|
messageLog.close();
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
WORD MainFrame::retrieveNews(const String &newsGroup)
|
|
{
|
|
DiskInfo diskInfo;
|
|
RecoverLog recoverLog;
|
|
Block<MsgID> messageIDStrings;
|
|
String msgString;
|
|
String strNewsDir;
|
|
String strPathNewsGroupDirectory;
|
|
String strPreviousDirectory;
|
|
OptionsReg optionsReg;
|
|
|
|
strNewsDir=optionsReg.newsDir();
|
|
strPathNewsGroupDirectory=strNewsDir+String("\\")+newsGroup;
|
|
if(!diskInfo.setCurrentDirectory(strPathNewsGroupDirectory))
|
|
{
|
|
diskInfo.createDirectory(strPathNewsGroupDirectory);
|
|
diskInfo.setCurrentDirectory(strPathNewsGroupDirectory);
|
|
}
|
|
message(String("Retrieving message headers for ")+newsGroup);
|
|
if(recoverLog.haveLog(newsGroup))
|
|
{
|
|
message(String("using recovery file."));
|
|
recoverLog.getEntries(newsGroup,messageIDStrings);
|
|
}
|
|
else
|
|
{
|
|
// simulateNewNews(newsGroup,messageIDStrings,priorDays());
|
|
// newNews(newsGroup,messageIDStrings,priorDays());
|
|
listGroup(newsGroup,messageIDStrings);
|
|
recoverLog.setEntries(newsGroup,messageIDStrings);
|
|
}
|
|
// simulateNewNews(newsGroup,messageIDStrings,priorDays());
|
|
// newNews(newsGroup,messageIDStrings,priorDays());
|
|
// listGroup(newsGroup,messageIDStrings);
|
|
::sprintf(msgString,"%s has %ld articles.",(LPSTR)newsGroup,messageIDStrings.size());
|
|
message(msgString);
|
|
getArticles(newsGroup,messageIDStrings);
|
|
diskInfo.setCurrentDirectory(strNewsDir);
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
void ImageView::preRegister(WNDCLASS &wndClass)
|
|
{
|
|
wndClass.style|=CS_SAVEBITS|CS_OWNDC;
|
|
wndClass.hbrBackground=(HBRUSH)::GetStockObject(WHITE_BRUSH);
|
|
|
|
// wndClass.hbrBackground=(HBRUSH)COLOR_APPWORKSPACE;
|
|
}
|
|
|
|
|
|
|
|
void JPGImage::verifyDimensions(BitmapInfo &someBitmapInfo)
|
|
{
|
|
DWORD desiredHeight(mBitmapInfo.height()<0?-mBitmapInfo.height():mBitmapInfo.height());
|
|
DWORD desiredWidth(mBitmapInfo.width());
|
|
DWORD imageExtent;
|
|
|
|
imageExtent=(((((LONG)desiredWidth*8)+31)&~31)>>3)*(LONG)desiredHeight;
|
|
if(imageExtent==(LONG)desiredWidth*(LONG)desiredHeight)return;
|
|
else desiredWidth=(WORD)(imageExtent/(LONG)desiredHeight);
|
|
mBitmapInfo.width(desiredWidth);
|
|
}
|
|
|
|
|
|
|
|
for(int index=0;index<strPathFileNames.size();index++)
|
|
{
|
|
GlobalData<BYTE> rawData;
|
|
PakEntry pakEntry;
|
|
|
|
// String strPathFileName(strPathDirectory+String("\\")+strPathFileNames[index]);
|
|
// mThumbPage.insert(strPathFileName,pureDevice);
|
|
String &strPathFileName=strPathFileNames[index];
|
|
mThumbPage.insert(strPathFileName,pureDevice);
|
|
mThumbPage[mThumbPage.entries()-1].getRawData(rawData);
|
|
pakEntry.type(PakEntry::Blob);
|
|
pakEntry.name(strPathFileName);
|
|
pakEntry.id(mMediaPak.entries());
|
|
pakEntry.rawData(rawData);
|
|
mMediaPak.add(pakEntry);
|
|
}
|
|
}
|
|
|
|
|
|
// enum {DefaultWidth=96,DefaultHeight=96,DefaultResampleWidth=96,OffsetImage=(DefaultWidth-DefaultResampleWidth)/2,BottomBorderHeight=0};
|
|
enum {DefaultWidth=72,DefaultHeight=72,DefaultResampleWidth=72,OffsetImage=(DefaultWidth-DefaultResampleWidth)/2,BottomBorderHeight=0};
|
|
ThumbNail(const ThumbNail &someThumbNail);
|
|
ThumbNail &operator=(const ThumbNail &someThumbNail);
|
|
const RGBColor &light(void)const;
|
|
const RGBColor &dark(void)const;
|
|
|
|
|
|
for(index=0;index<strPathDirFileNames.size();index++)
|
|
{
|
|
if(!strPathFileNames.find(strPathDirFileNames[index]))
|
|
{
|
|
GlobalData<BYTE> rawData;
|
|
PakEntry pakEntry;
|
|
|
|
::OutputDebugString(String("Adding ")+strPathDirFileNames[index]+String("\n"));
|
|
strPathFileNames.insert(strPathDirFileNames[index]);
|
|
String strPathFileName(strPathDirectory+String("\\")+strPathDirFileNames[index]);
|
|
// mThumbPage.insert(strPathFileName,pureDevice);
|
|
mThumbPage.insert(strPathFileName);
|
|
mThumbPage[mThumbPage.entries()-1].getRawData(rawData);
|
|
pakEntry.type(PakEntry::Blob);
|
|
pakEntry.name(strPathDirFileNames[index]);
|
|
pakEntry.id(mMediaPak.entries());
|
|
pakEntry.rawData(rawData);
|
|
mMediaPak.add(pakEntry);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void JPGImage::verifyDimensions(BitmapInfo &someBitmapInfo)
|
|
{
|
|
DWORD desiredHeight(someBitmapInfo.height()<0?-someBitmapInfo.height():someBitmapInfo.height());
|
|
DWORD desiredWidth(someBitmapInfo.width());
|
|
DWORD imageExtent;
|
|
|
|
// imageExtent=(((((LONG)desiredWidth*8)+31)&~31)>>3)*(LONG)desiredHeight;
|
|
imageExtent=(((((LONG)desiredWidth*24)+31)&~31)>>3)*(LONG)desiredHeight;
|
|
if(imageExtent==(LONG)desiredWidth*(LONG)desiredHeight)return;
|
|
else desiredWidth=(WORD)(imageExtent/(LONG)desiredHeight);
|
|
someBitmapInfo.width(desiredWidth);
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
CallbackData::ReturnType MainFrame::browseSelectHandler(CallbackData &someCallbackData)
|
|
{
|
|
SmartPointer<MDIWindow> mdiWindow;
|
|
String strPathFileName;
|
|
String strCaption;
|
|
bool haveImage(false);
|
|
|
|
strPathFileName=(char*)someCallbackData.lParam();
|
|
if(getFirstDocument(mdiWindow))
|
|
{
|
|
mdiWindow->windowText(strCaption);
|
|
strCaption=strCaption.betweenString('[',']');
|
|
if(!strCaption.isNull()&&strCaption==strPathFileName)
|
|
{
|
|
mdiWindow->bringWindowToTop();
|
|
haveImage=true;
|
|
}
|
|
while(!haveImage&&getNextDocument(mdiWindow))
|
|
{
|
|
mdiWindow->windowText(strCaption);
|
|
strCaption=strCaption.betweenString('[',']');
|
|
if(!strCaption.isNull()&&strCaption==strPathFileName)
|
|
{
|
|
mdiWindow->bringWindowToTop();
|
|
haveImage=true;
|
|
}
|
|
}
|
|
}
|
|
if(haveImage)return (CallbackData::ReturnType)FALSE;
|
|
if(!openDocument(strPathFileName))::MessageBox(::GetFocus(),"NNTP:Error opening document",(LPSTR)strPathFileName,MB_OK);
|
|
return (CallbackData::ReturnType)FALSE;
|
|
}
|
|
*/
|
|
|
|
|
|
|
|
String pathFileName;
|
|
for(int index=0;index<50;index++)
|
|
{
|
|
::sprintf(pathFileName,"d:\\file_%02d.dat",index);
|
|
FileHandle saveFile(pathFileName,FileHandle::Write,FileHandle::ShareRead,FileHandle::Overwrite);
|
|
saveFile.writeLine(pathFileName);
|
|
}
|
|
::Sleep(60000);
|
|
|
|
|
|
|
|
BOOL MainFrame::getArticles(const String &newsGroup,Block<MsgID> &msgIDs)
|
|
{
|
|
MessageLog messageLog;
|
|
GenDecode genericDecoder;
|
|
|
|
DWORD alreadyHavesInARow(0);
|
|
BOOL okResult;
|
|
|
|
messageLog.setLog(newsGroup);
|
|
alreadyHavesInARow=0;
|
|
group(GroupItem(newsGroup));
|
|
for(int itemIndex=0;itemIndex<msgIDs.size();itemIndex++)
|
|
{
|
|
Block<String> articleText;
|
|
String pathFileName;
|
|
MsgID msgID;
|
|
|
|
if(!isConnected())return FALSE;
|
|
msgID=msgIDs[itemIndex];
|
|
// ::sprintf(pathFileName,"n%ld.new",itemIndex);
|
|
// message(newsGroup+String("(")+msgID+String(")"));
|
|
if(messageLog.searchItem(msgID))
|
|
{
|
|
// message(String("Already have ")+msgID);
|
|
alreadyHavesInARow++;
|
|
if(alreadyHavesInARow>250)
|
|
{
|
|
Block<String> headText;
|
|
// message("...1 second, I need to ping the News Server...");
|
|
head(msgID,headText);
|
|
alreadyHavesInARow=0;
|
|
}
|
|
continue;
|
|
}
|
|
else
|
|
{
|
|
::sprintf(pathFileName,"n%ld.new",itemIndex);
|
|
message(newsGroup+String("(")+msgID+String(")"));
|
|
alreadyHavesInARow=0;
|
|
}
|
|
messageLog.insert(msgID);
|
|
|
|
/* okResult=head(msgID,articleText);
|
|
Header header(articleText);
|
|
message(header.subject());
|
|
|
|
String subject=header.subject();
|
|
subject.upper();
|
|
if(!subject.strstr("YENC"))
|
|
{
|
|
message(String("Skipping ")+header.subject());
|
|
continue;
|
|
}*/
|
|
|
|
okResult=article(msgID,articleText);
|
|
if(okResult)
|
|
{
|
|
String strPathImageFile;
|
|
saveBlock(pathFileName,articleText);
|
|
try
|
|
{
|
|
if(!YDecoder::decode(pathFileName,strPathImageFile))
|
|
{
|
|
genericDecoder.decode(pathFileName,strPathImageFile);
|
|
}
|
|
|
|
// if(!genericDecoder.decode(pathFileName,strPathImageFile))
|
|
// {
|
|
// YDecoder::decode(pathFileName,strPathImageFile);
|
|
// }
|
|
}
|
|
catch(...)
|
|
{
|
|
continue;
|
|
}
|
|
if(!strPathImageFile.isNull()&&openImage(strPathImageFile))::unlink(pathFileName);
|
|
}
|
|
okResult=FALSE;
|
|
messageLog.flush();
|
|
}
|
|
messageLog.close();
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
|
|
// if(!YDecoder::decode(pathFileName,strPathImageFile))
|
|
// {
|
|
// if(!genericDecoder.decode(pathFileName,strPathImageFile))
|
|
// }
|
|
|
|
/* try
|
|
{
|
|
if(!YDecoder::decode(pathFileName,strPathImageFile))
|
|
{
|
|
genericDecoder.decode(pathFileName,strPathImageFile);
|
|
}
|
|
}
|
|
catch(...)
|
|
{
|
|
continue;
|
|
} */
|
|
|
|
|
|
//#if defined(_MSC_VER)
|
|
//#pragma warning(disable:4355)
|
|
//#endif
|
|
|
|
class NNTPThread : private MessageThread, public NNTPClient
|
|
|
|
|
|
WORD NNTPClient::article(DWORD articleNumber,Block<String> &articleText,String &messageID)
|
|
{
|
|
String controlData;
|
|
String responseLine;
|
|
DWORD responseLines(0);
|
|
|
|
::sprintf(controlData,"%s %ld",(LPSTR)mNNTPCmds[Article],articleNumber);
|
|
articleText.remove();
|
|
if(!isConnected())return FALSE;
|
|
if(!putControlData(controlData,FALSE))return FALSE;
|
|
while(mNNTPControl.receive(responseLine))
|
|
{
|
|
if(mPeriod==responseLine && 1==responseLine.length())break;
|
|
if(!responseLines++)
|
|
{
|
|
String responseString(responseLine.betweenString(0,' '));
|
|
messageID=responseLine.betweenString('<','>');
|
|
if(mNackArticleResponseStrings.size() && isInResponse(responseString,mNackArticleResponseStrings))break;
|
|
if(mAckArticleResponseStrings.size() && isInResponse(responseString,mAckArticleResponseStrings))continue;
|
|
}
|
|
articleText.insert(&responseLine);
|
|
}
|
|
return (articleText.size()?TRUE:FALSE);
|
|
// return retrieveBlock(controlData,articleText,mAckArticleResponseStrings,mNackArticleResponseStrings);
|
|
}
|