📄 oscar.cpp
字号:
if(m_nNumNewDocs == 0)
{
// This is the first document, created automatically. We want to
// show the local system.
m_nNewSysType = 0;
m_cszNewTargetMachine = _T("(Local)");
// And in addition, open the friends' list.
POSITION pos = GetFirstDocTemplatePosition();
CDocTemplate *pTemplate = GetNextDocTemplate(pos);
pTemplate = GetNextDocTemplate(pos);
pTemplate = GetNextDocTemplate(pos); // Third template.
ASSERT(pTemplate);
// We always open the friends' list; it initializes AwareNet.
// if(m_cArchive.m_arch1.bShowingFriendsList)
pTemplate->OpenDocumentFile(NULL);
// And in addition, open the shared directory list.
pTemplate = GetNextDocTemplate(pos); // Fourth template.
ASSERT(pTemplate);
if(m_cArchive.m_arch1.bShowingDirectoryList)
pTemplate->OpenDocumentFile(NULL);
// And in addition, open the transfer agent.
pTemplate = GetNextDocTemplate(pos); // Fifth template.
ASSERT(pTemplate);
if(m_cArchive.m_arch1.bShowingTransferAgent)
pTemplate->OpenDocumentFile(NULL);
// And in addition, open the instant messenger.
pTemplate = GetNextDocTemplate(pos); // Sixth template.
ASSERT(pTemplate);
if(m_cArchive.m_arch2.bShowingInstantMessengerList)
pTemplate->OpenDocumentFile(NULL);
// And in addition, open the network monitor.
pTemplate = GetNextDocTemplate(pos); // Seventh template.
ASSERT(pTemplate);
if(m_cArchive.m_arch2.bShowingNetworkMonitor)
pTemplate->OpenDocumentFile(NULL);
}
else
{
CMainFrame *pMainWnd = (CMainFrame *)m_pMainWnd;
int nSysType;
CString cszTargetMachine;
if(pMainWnd->QueryNewView(nSysType, cszTargetMachine))
{
// Set the global buffers for the document to steal.
m_nNewSysType = nSysType;
m_cszNewTargetMachine = cszTargetMachine;
}
else
return;
}
POSITION pos = GetFirstDocTemplatePosition();
CDocTemplate *pTemplate = GetNextDocTemplate(pos);
if(m_nNewSysType != 0) pTemplate = GetNextDocTemplate(pos);
ASSERT(pTemplate);
if(pTemplate)
pTemplate->OpenDocumentFile(NULL);
m_nNumNewDocs += 1;
}
CSettingsArchive *COscarApp::GetArchive()
{
return &m_cArchive;
}
BOOL COscarApp::GetSharedDirectories(CStringArray &csaDirectories)
{
// Loop over all the directories and add them.
for(int i = 0; 1; i++)
{
CString cszTemp;
ASSERT(m_cArchive.m_pSecurityFilter);
if(!m_cArchive.m_pSecurityFilter->GetDirectory(i, cszTemp))
break; // Done.
// Append the new directory to the buffer.
csaDirectories.Add(cszTemp);
}
return TRUE;
}
BOOL COscarApp::ShowFriendsList()
{
// Make sure it's not shown already.
if(m_pFriendsList) return FALSE;
// Open the friends' list.
POSITION pos = GetFirstDocTemplatePosition();
CDocTemplate *pTemplate = GetNextDocTemplate(pos);
pTemplate = GetNextDocTemplate(pos);
pTemplate = GetNextDocTemplate(pos); // Third template.
ASSERT(pTemplate);
pTemplate->OpenDocumentFile(NULL);
return TRUE;
}
BOOL COscarApp::ShowDirectoriesList()
{
// Make sure it's not shown already.
if(m_pDirectoryList) return FALSE;
// Open the friends' list.
POSITION pos = GetFirstDocTemplatePosition();
CDocTemplate *pTemplate = GetNextDocTemplate(pos);
pTemplate = GetNextDocTemplate(pos);
pTemplate = GetNextDocTemplate(pos);
pTemplate = GetNextDocTemplate(pos); // Fourth template.
ASSERT(pTemplate);
pTemplate->OpenDocumentFile(NULL);
return TRUE;
}
UINT COscarApp::TransferFile(LPCTSTR czFileSrc, LPCTSTR czSrcIP,
LPCTSTR czFileDst, LPCTSTR czDstIP,
BOOL bMove)
{
CString cszFileSrc = czFileSrc;
CString cszSrcMach = czSrcIP;
CString cszFileDst = czFileDst;
CString cszDstMach = czDstIP;
int nLocals = 0;
// Display the wait cursor.
CWaitCursor *pWaitCursor = new CWaitCursor;
ASSERT(pWaitCursor);
// Convert any (Local)'s to "127.0.0.1"'s.
if(cszSrcMach.CompareNoCase(_T("(Local)")) == 0 ||
cszSrcMach.CompareNoCase(_T("127.0.0.1")) == 0)
{
nLocals += 1;
cszSrcMach = _T("127.0.0.1");
}
if(cszDstMach.CompareNoCase(_T("(Local)")) == 0 ||
cszDstMach.CompareNoCase(_T("127.0.0.1")) == 0)
{
nLocals += 1;
cszDstMach = _T("127.0.0.1");
}
// Make sure we're not copying the file onto itself.
if(cszFileSrc.CompareNoCase(cszFileDst) == 0 &&
cszSrcMach.CompareNoCase(cszDstMach) == 0)
{
if(pWaitCursor) delete pWaitCursor;
return 0;
}
// Handle any local-local copies directly; don't
// need the transfer agent.
if(nLocals == 2)
{
CFileSystem cFS;
if(bMove)
{
BOOL bDeleteDest = FALSE;
// Check to see if the file already exists.
if(cFS.GetFileModificationTime(czFileDst) != 0)
{
// Hide the wait cursor.
if(pWaitCursor) delete pWaitCursor;
if(m_pMainWnd->MessageBox(_T("Do you want to overwrite the "
"existing file?"), _T("Move File"), MB_ICONQUESTION | MB_YESNO)
== IDYES)
bDeleteDest = TRUE;
pWaitCursor = new CWaitCursor;
}
if(bDeleteDest)
cFS.DeleteFile(czFileDst);
if(cFS.MoveFile(czFileSrc, czFileDst))
{
if(pWaitCursor) delete pWaitCursor;
return 2;
}
}
else
{
BOOL bFailIfOverwrite = TRUE;
// Check to see if the file already exists.
if(cFS.GetFileModificationTime(czFileDst) != 0)
{
// Hide the wait cursor.
if(pWaitCursor) delete pWaitCursor;
if(m_pMainWnd->MessageBox(_T("Do you want to overwrite the "
"existing file?"), _T("Copy File"), MB_ICONQUESTION | MB_YESNO)
== IDYES)
bFailIfOverwrite = FALSE;
pWaitCursor = new CWaitCursor;
}
if(cFS.CopyFile(czFileSrc, czFileDst, bFailIfOverwrite))
{
if(pWaitCursor) delete pWaitCursor;
return 2;
}
}
if(pWaitCursor) delete pWaitCursor;
return 0;
}
BOOL bCloseTransferAgent = FALSE;
// Check to see if the transfer agent is open.
if(!m_pTransferAgent)
{
// Open the transfer agent.
POSITION pos = GetFirstDocTemplatePosition();
CDocTemplate *pTemplate = GetNextDocTemplate(pos);
pTemplate = GetNextDocTemplate(pos);
pTemplate = GetNextDocTemplate(pos); // Third template.
pTemplate = GetNextDocTemplate(pos); // Fourth template.
pTemplate = GetNextDocTemplate(pos); // Fifth template.
ASSERT(pTemplate);
pTemplate->OpenDocumentFile(NULL);
// Automatically close the transfer agent when the transfer
// is complete.
bCloseTransferAgent = TRUE;
}
ASSERT(m_pTransferAgent);
// Make sure the view can tell the frame to close if necessary.
m_pTransferAgent->RegisterWithView();
if(bCloseTransferAgent)
m_pTransferAgent->AutoCloseOnComplete();
// Get a pointer to the transfer view.
CTransferAgentView *pTransferView =
(CTransferAgentView *)m_pTransferAgent->GetActiveView();
ASSERT(pTransferView);
if(pWaitCursor) delete pWaitCursor;
return pTransferView->AddTransfer(cszFileSrc, cszSrcMach,
cszFileDst, cszDstMach);
}
BOOL COscarApp::ShowTransferAgent()
{
// Make sure it's not shown already.
if(m_pTransferAgent) return FALSE;
// Open the transfer agent.
POSITION pos = GetFirstDocTemplatePosition();
CDocTemplate *pTemplate = GetNextDocTemplate(pos);
pTemplate = GetNextDocTemplate(pos);
pTemplate = GetNextDocTemplate(pos);
pTemplate = GetNextDocTemplate(pos);
pTemplate = GetNextDocTemplate(pos); // Fifth template.
ASSERT(pTemplate);
pTemplate->OpenDocumentFile(NULL);
return TRUE;
}
BOOL COscarApp::NewView(LPCTSTR czMachine, int nSysType)
{
ASSERT(nSysType >= 1); // Remote.
ASSERT(czMachine);
if(!czMachine) return FALSE;
// Set the global buffers for the document to steal.
m_nNewSysType = nSysType;
m_cszNewTargetMachine = czMachine;
POSITION pos = GetFirstDocTemplatePosition();
CDocTemplate *pTemplate = GetNextDocTemplate(pos);
if(m_nNewSysType != 0) pTemplate = GetNextDocTemplate(pos);
pTemplate->OpenDocumentFile(NULL);
m_nNumNewDocs += 1;
return TRUE;
}
BOOL COscarApp::UpdateAfterTransfer(LPCTSTR czDirectory)
{
ASSERT(m_pMainWnd);
if(m_pMainWnd)
{
CMainFrame *pFrame = (CMainFrame *)m_pMainWnd;
return pFrame->UpdateAfterTransfer(czDirectory);
}
return FALSE;
}
BOOL COscarApp::AddInstantMessage(LPCTSTR czIP, LPCTSTR czName, LPCTSTR czMessage,
COLORREF crBack, COLORREF crText, BOOL bTo)
{
// Show the instant messenger if we want it to pop up and it's
// not being shown.
if(m_cArchive.m_arch2.bPopIMWindow && !m_pInstantMessenger)
{
// Check to see if we're in the main thread.
CWinThread *pThread = AfxGetThread();
ASSERT(pThread);
if(pThread->m_pMainWnd)
{
// We're in the main thread. Create the window directly.
ShowInstantMessenger();
}
else
{
// Since we're in a different thread, we have to
// send a message to the main one.
// Get the message.
UINT DisplayIMessenger = RegisterWindowMessage("Oscar Display IMessenger");
// Send it. Block until the call is done.
m_pMainWnd->SendMessage(DisplayIMessenger, 0, 0);
}
}
if(m_pInstantMessenger)
return m_pInstantMessenger->AddMessage(czIP, czName, czMessage, crBack, crText,
bTo);
return FALSE;
}
BOOL COscarApp::ShowNetworkMonitor()
{
// Make sure it's not shown already.
if(m_pNetworkMonitor) return FALSE;
// Open the network monitor.
POSITION pos = GetFirstDocTemplatePosition();
CDocTemplate *pTemplate = GetNextDocTemplate(pos);
pTemplate = GetNextDocTemplate(pos);
pTemplate = GetNextDocTemplate(pos);
pTemplate = GetNextDocTemplate(pos);
pTemplate = GetNextDocTemplate(pos);
pTemplate = GetNextDocTemplate(pos);
pTemplate = GetNextDocTemplate(pos); // Seventh template.
ASSERT(pTemplate);
pTemplate->OpenDocumentFile(NULL);
return TRUE;
}
BOOL COscarApp::ShowInstantMessenger()
{
// Make sure it's not shown already.
if(m_pInstantMessenger) return FALSE;
// Open the network monitor.
POSITION pos = GetFirstDocTemplatePosition();
CDocTemplate *pTemplate = GetNextDocTemplate(pos);
pTemplate = GetNextDocTemplate(pos);
pTemplate = GetNextDocTemplate(pos);
pTemplate = GetNextDocTemplate(pos);
pTemplate = GetNextDocTemplate(pos);
pTemplate = GetNextDocTemplate(pos); // Sixth template.
ASSERT(pTemplate);
pTemplate->OpenDocumentFile(NULL);
return TRUE;
}
BOOL COscarApp::SendInstantMessage(LPCTSTR czRecipient, LPCTSTR czIP)
{
CSendMessageDlg SendMessageDlg(m_pMainWnd, czIP, czRecipient);
// Show the send message dialog box.
if(SendMessageDlg.DoModal() == IDOK)
{
// We want to send the message.
return CInstantMessageServer::SendMessage(SendMessageDlg.GetDestination(),
SendMessageDlg.GetMessage(), czRecipient);
}
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -