⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 oscar.cpp

📁 c++系统开发实例精粹内附的80例源代码 环境:windows2000,c++6.0
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//////////////////////////////////////////////////////////////////////
// FileFury
// Copyright (c) 2000 Tenebril Incorporated
// All rights reserved.
//
// This source code is governed by the Tenebril open source
// license (http://www.tenebril.com/developers/opensource/license.html)
//
// For more information on this and other open source applications,
// visit the Tenebril OpenSource page:
//       http://www.tenebril.com/developers/opensource
//
//////////////////////////////////////////////////////////////////////

// Oscar.cpp : Defines the class behaviors for the application.
//

#include "stdafx.h"
#include "Oscar.h"

#include "MainFrm.h"
#include "ChildFrm.h"
#include "OscarDoc.h"

#include "DirListView.h"
#include "DirTreeView.h"

#include "FriendsListDoc.h"
#include "FriendsListFrame.h"
#include "FriendsListView.h"
#include "DirectoryListDoc.h"
#include "DirectoryListFrame.h"
#include "DirectoryListView.h"
#include "TransferAgentDoc.h"
#include "TransferAgentFrame.h"
#include "TransferAgentView.h"
#include "InstantMessengerDoc.h"
#include "InstantMessengerFrame.h"
#include "InstantMessengerView.h"
#include "NetworkMonitorDoc.h"
#include "NetworkMonitorFrame.h"
#include "NetworkMonitorView.h"

#include "SendMessageDlg.h"
#include "LicenseAgreementDlg.h"
#include "License.h"

#include "AwareNetDivers.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// COscarApp

BEGIN_MESSAGE_MAP(COscarApp, CWinApp)
	//{{AFX_MSG_MAP(COscarApp)
	ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
	//}}AFX_MSG_MAP
	// Standard file based document commands
	ON_COMMAND(ID_FILE_NEW, OnFileNew)
	ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// COscarApp construction

COscarApp::COscarApp()
{
	m_nNumNewDocs = 0;
	m_nShareFolderIcon[0] = m_nShareFolderIcon[1] = m_nShareFolderIcon[2] = -1;
	m_bCanChangeSettings = TRUE;
	m_bANetInit = FALSE;

	m_pDirectoryList = NULL;
	m_pFriendsList = NULL;
	m_pInstantMessenger = NULL;
	m_pNetworkMonitor = NULL;
	m_pTransferAgent = NULL;
}

/////////////////////////////////////////////////////////////////////////////
// The one and only COscarApp object

COscarApp theApp;

/////////////////////////////////////////////////////////////////////////////
// COscarApp initialization

BOOL COscarApp::InitInstance()
{
	// Check to see if the beta period has expired.
	CTime ExpireTime(2000,              // Year
		             1,                 // Month
					 30,                // Day
					 23,                // Hour
					 59,                // Minute
					 59);               // Second
	CTime CurrentTime = CTime::GetCurrentTime();

	/* Don't bother checking for the expiration; we're no longer
	   doing beta */

	/*
	if(CurrentTime > ExpireTime)
	{
		// The beta has expired.  Direct the user to the web site.
		if(MessageBox(NULL, "This version of the FileFury software is out of date.\n"
			"Would you like to download the latest version?",
			"FileFury test period", MB_YESNO | MB_ICONQUESTION) == IDYES)
		{
			// Open the web site.
			if(::ShellExecute(NULL, "open", _T("http://www.filefury.com"), NULL, 
				NULL, SW_SHOWNORMAL) <= (HINSTANCE)32)
				MessageBox(NULL, "An error occurred in opening your web browser.\n"
					"You need to go to www.filefury.com to download the software.",
					"FileFury upgrade", MB_ICONSTOP | MB_OK);
		}
		else
		{
			// Explain the need to upgrade.
			MessageBox(NULL, 
				"You must upgrade the software; the beta version is time-\n"
				"limited to ensure your copy is of the highest quality.",
				"FileFury beta period", MB_ICONEXCLAMATION | MB_OK);
		}

		// Don't let the program start.
		return FALSE;
	}
	*/

	// Make sure this is the only instance.
	if(!m_cInstanceCheck.Create(_T("Oscar"), false, true))
	{
		// Send a message telling the other instance to open
		// its main view.

		UINT WakeUpMessage = RegisterWindowMessage("Oscar WakeUp");
		SendMessage(HWND_BROADCAST, WakeUpMessage, 0, 0);
		return FALSE;
	}

	if (!AfxSocketInit())
	{
		AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
		return FALSE;
	}

	AfxOleInit();          // Drag / drop
	CoInitialize(NULL);    // COM (shortcuts)

	// Standard initialization

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

	// Change the registry key under which our settings are stored.
	SetRegistryKey(_T("FileFury"));

	LoadStdProfileSettings();  // Load standard INI file options (including MRU)

	// Store the module's directory.
	TCHAR czProgName[4096];
	memset((void *)czProgName, 0, sizeof(czProgName));
	GetModuleFileName(NULL, czProgName, 4096);
	m_cszProgDirectory = czProgName;
	if(m_cszProgDirectory.ReverseFind(_T('\\')) > -1)
		m_cszProgDirectory = 
			m_cszProgDirectory.Left(m_cszProgDirectory.ReverseFind(_T('\\')));

	// Register document templates

	CMultiDocTemplate* pDocTemplate;
	pDocTemplate = new CMultiDocTemplate(
		IDI_DRIVE,
		RUNTIME_CLASS(COscarDoc),
		RUNTIME_CLASS(CChildFrame), // The local view
		RUNTIME_CLASS(CDirListView));
	AddDocTemplate(pDocTemplate);
	pDocTemplate = new CMultiDocTemplate(
		IDI_SHAREDDRIVE,
		RUNTIME_CLASS(COscarDoc),
		RUNTIME_CLASS(CChildFrame), // Remote machine
		RUNTIME_CLASS(CDirListView));
	AddDocTemplate(pDocTemplate);
	pDocTemplate = new CMultiDocTemplate(
		IDI_ANETICON,
		RUNTIME_CLASS(CFriendsListDoc),
		RUNTIME_CLASS(CFriendsListFrame), // Friends list
		RUNTIME_CLASS(CFriendsListView));
	AddDocTemplate(pDocTemplate);
	pDocTemplate = new CMultiDocTemplate(
		IDI_SHAREDDRIVE,
		RUNTIME_CLASS(CDirectoryListDoc),
		RUNTIME_CLASS(CDirectoryListFrame), // Shared directory list
		RUNTIME_CLASS(CDirectoryListView));
	AddDocTemplate(pDocTemplate);
	pDocTemplate = new CMultiDocTemplate(
		IDI_SHAREDDRIVE,
		RUNTIME_CLASS(CTransferAgentDoc),
		RUNTIME_CLASS(CTransferAgentFrame), // Transfer agent
		RUNTIME_CLASS(CTransferAgentView));
	AddDocTemplate(pDocTemplate);
	pDocTemplate = new CMultiDocTemplate(
		IDI_SHAREDDRIVE,
		RUNTIME_CLASS(CInstantMessengerDoc),
		RUNTIME_CLASS(CInstantMessengerFrame), // Instant messenger
		RUNTIME_CLASS(CInstantMessengerView));
	AddDocTemplate(pDocTemplate);
	pDocTemplate = new CMultiDocTemplate(
		IDI_SHAREDDRIVE,
		RUNTIME_CLASS(CNetworkMonitorDoc),
		RUNTIME_CLASS(CNetworkMonitorFrame), // Network monitor
		RUNTIME_CLASS(CNetworkMonitorView));
	AddDocTemplate(pDocTemplate);

	// Load the settings.
	if(!m_cArchive.ReadFromFile(_T("FileFury.settings")))
	{
		// The first time.  Display the licensing agreement.

		CLicensingAgreementDlg LicensingDlg(NULL, czLicensingAgreement);
		LicensingDlg.DoModal();

		if(!LicensingDlg.DidAgree())
			return FALSE;
	}

	// Start the NFS server
	m_pNFSServer = new CNFSServer(m_cArchive.m_pSecurityFilter);
	m_pNFSServer->Start();

	// Start the search server
	m_pSearchServer = new CSearchServer(m_cArchive.m_pSecurityFilter);
	m_pSearchServer->Start();

	// Start the transfer server
	m_pTransferServer = new CTransferServer(m_cArchive.m_pSecurityFilter);
	m_pTransferServer->Start();

	// Start the instant message server
	m_pIMServer = new CInstantMessageServer;
	m_pIMServer->Start();

	// create main MDI Frame window
	CMainFrame* pMainFrame = new CMainFrame;
	if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
		return FALSE;
	m_pMainWnd = pMainFrame;

	// Initialize AwareNet, asynchronously.
	AwareNet_AsyncInitialize(&m_cANet, m_pMainWnd->m_hWnd, AWARENET_OSCAR_TOS, 
		&m_bANetInit);

	// Parse command line for standard shell commands, DDE, file open
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

	// Dispatch commands specified on the command line
	if (!ProcessShellCommand(cmdInfo))
		return FALSE;
//	pMainFrame->ShowWindow(SW_HIDE);
	pMainFrame->UpdateWindow();

	return TRUE;
}

#include <fstream.h>

static CMutex DebugCommentMutex;

void RealStoreDebugComment(CString file, int line, CString comment)
{
	DebugCommentMutex.Lock();
	ofstream DebugFile;
	CString FullComment;
	CString FileName = file;
	CTime CurTime = CTime::GetCurrentTime();

	DebugFile.open("C:\\Oscar.debug.txt", ios::out | ios::app);
	if(DebugFile.is_open() == 0)
	{
		DebugCommentMutex.Unlock();
		return;
	}

	FullComment.Format(_T("%s:%i:(%i:%i:%i)  --  \"%s\"\n"),
		FileName.GetBuffer(0), line, 
		CurTime.GetHour(), CurTime.GetMinute(), CurTime.GetSecond(),
		comment.GetBuffer(0));

	DebugFile.write(FullComment.GetBuffer(0), FullComment.GetLength());
	DebugFile.flush();
	DebugFile.close();

	DebugCommentMutex.Unlock();
	return;
}

int COscarApp::ExitInstance()
{
	// Save the settings.
	m_cArchive.WriteToFile(_T("FileFury.settings"));

	// Send a kill message to the NFS, transfer and IMservers.
	m_pNFSServer->Stop(false);
	m_pTransferServer->Stop(false);
	m_pIMServer->Stop(FALSE);

	// Kill the search server.
	m_pSearchServer->Stop(true);
	delete m_pSearchServer;

	// Kill the NFS server.
	m_pNFSServer->Stop(true);
	delete m_pNFSServer;

	// Kill the transfer server.
	m_pTransferServer->Stop(true);
	delete m_pTransferServer;

	// Kill the IM server.
	m_pIMServer->Stop(true);
	delete m_pIMServer;

	// Wait for the initialization to finish.
	AwareNet_AsyncWait();

	// Handle AwareNet.
	if(m_bANetInit)
	{
		// Close AwareNet.
		m_cANet.Deallocate(AWARENET_OSCAR_TOS);
	}

	return CWinApp::ExitInstance();
}

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
		// No message handlers
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

// App command to run the dialog
void COscarApp::OnAppAbout()
{
	CAboutDlg aboutDlg;
	aboutDlg.DoModal();
}

/////////////////////////////////////////////////////////////////////////////
// COscarApp commands

void COscarApp::OnFileNew()
{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -