2004-05-17 22:15:10 +00:00
|
|
|
// $Id$
|
|
|
|
//
|
2004-04-10 09:11:03 +00:00
|
|
|
// The contents of this file are subject to the BOINC Public License
|
|
|
|
// Version 1.0 (the "License"); you may not use this file except in
|
|
|
|
// compliance with the License. You may obtain a copy of the License at
|
|
|
|
// http://boinc.berkeley.edu/license_1.0.txt
|
|
|
|
//
|
|
|
|
// Software distributed under the License is distributed on an "AS IS"
|
|
|
|
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
|
|
// License for the specific language governing rights and limitations
|
|
|
|
// under the License.
|
|
|
|
//
|
|
|
|
// The Original Code is the Berkeley Open Infrastructure for Network Computing.
|
|
|
|
//
|
|
|
|
// The Initial Developer of the Original Code is the SETI@home project.
|
|
|
|
// Portions created by the SETI@home project are Copyright (C) 2002
|
|
|
|
// University of California at Berkeley. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// Contributor(s):
|
|
|
|
//
|
2004-05-17 22:15:10 +00:00
|
|
|
// Revision History:
|
|
|
|
//
|
2004-04-10 09:11:03 +00:00
|
|
|
|
2004-04-11 04:37:10 +00:00
|
|
|
#if defined(__GNUG__) && !defined(__APPLE__)
|
|
|
|
#pragma implementation "BOINCGUIApp.h"
|
|
|
|
#endif
|
2004-04-10 09:11:03 +00:00
|
|
|
|
2004-04-11 04:37:10 +00:00
|
|
|
#include "stdwx.h"
|
2004-04-11 04:12:44 +00:00
|
|
|
#include "BOINCGUIApp.h"
|
|
|
|
#include "MainFrame.h"
|
|
|
|
#include "MainDocument.h"
|
2004-04-10 09:11:03 +00:00
|
|
|
|
|
|
|
|
2004-12-14 20:15:06 +00:00
|
|
|
#ifdef __WXMSW__
|
2004-12-14 02:50:16 +00:00
|
|
|
typedef BOOL (CALLBACK* IdleTrackerInit)();
|
|
|
|
typedef void (CALLBACK* IdleTrackerTerm)();
|
2004-12-14 20:15:06 +00:00
|
|
|
#endif
|
2004-12-14 02:50:16 +00:00
|
|
|
|
|
|
|
|
2004-04-10 09:11:03 +00:00
|
|
|
IMPLEMENT_APP(CBOINCGUIApp)
|
|
|
|
IMPLEMENT_DYNAMIC_CLASS(CBOINCGUIApp, wxApp)
|
|
|
|
|
|
|
|
|
|
|
|
bool CBOINCGUIApp::OnInit()
|
|
|
|
{
|
2004-12-03 21:35:25 +00:00
|
|
|
// Setup application and company information
|
|
|
|
SetVendorName(wxT("Space Sciences Laboratory, U.C. Berkeley"));
|
|
|
|
SetAppName(wxT("BOINC Manager"));
|
|
|
|
|
2004-11-19 08:11:49 +00:00
|
|
|
// Setup variables with default values
|
2004-11-23 07:45:11 +00:00
|
|
|
m_bBOINCStartedByManager = false;
|
2004-11-19 08:11:49 +00:00
|
|
|
m_bFrameVisible = true;
|
2004-11-23 07:45:11 +00:00
|
|
|
m_lBOINCCoreProccessId = 0;
|
2004-05-21 06:27:15 +00:00
|
|
|
|
2004-12-03 21:35:25 +00:00
|
|
|
// Enable Trace Masks
|
2004-12-10 20:46:43 +00:00
|
|
|
//wxLog::AddTraceMask( wxT("Function Start/End") );
|
2004-12-04 05:42:22 +00:00
|
|
|
|
2004-04-10 09:11:03 +00:00
|
|
|
|
2004-09-21 01:30:29 +00:00
|
|
|
// Enable the in memory virtual file system for
|
|
|
|
// storing images
|
|
|
|
wxFileSystem::AddHandler(new wxMemoryFSHandler);
|
|
|
|
|
2004-10-21 23:07:13 +00:00
|
|
|
// Enable known image types
|
|
|
|
wxImage::AddHandler(new wxXPMHandler);
|
|
|
|
|
2004-12-03 21:35:25 +00:00
|
|
|
// Commandline parsing is done in wxApp::OnInit()
|
|
|
|
if (!wxApp::OnInit())
|
|
|
|
return false;
|
|
|
|
|
2004-04-10 09:11:03 +00:00
|
|
|
// Initialize the internationalization module
|
|
|
|
m_pLocale = new wxLocale();
|
2004-05-21 06:27:15 +00:00
|
|
|
wxASSERT(NULL != m_pLocale);
|
|
|
|
|
2004-04-10 09:11:03 +00:00
|
|
|
m_pLocale->Init();
|
2004-10-31 23:16:09 +00:00
|
|
|
#ifdef __WXMSW__
|
|
|
|
// In Windows local information is stored relative to the executable,
|
|
|
|
// in the Unix world it may be different.
|
|
|
|
m_pLocale->AddCatalogLookupPathPrefix(wxT("locale"));
|
|
|
|
#endif
|
2004-04-10 09:11:03 +00:00
|
|
|
m_pLocale->AddCatalog(GetAppName());
|
|
|
|
|
2004-05-21 06:27:15 +00:00
|
|
|
// Initialize the configuration storage module
|
2004-11-19 08:11:49 +00:00
|
|
|
m_pConfig = new wxConfig(GetAppName());
|
2004-05-27 06:17:58 +00:00
|
|
|
wxConfigBase::Set(m_pConfig);
|
2004-05-21 06:27:15 +00:00
|
|
|
wxASSERT(NULL != m_pConfig);
|
|
|
|
|
2004-04-10 09:11:03 +00:00
|
|
|
// Initialize the main document
|
|
|
|
m_pDocument = new CMainDocument();
|
2004-05-21 06:27:15 +00:00
|
|
|
wxASSERT(NULL != m_pDocument);
|
2004-04-10 09:11:03 +00:00
|
|
|
|
2004-10-23 23:40:11 +00:00
|
|
|
m_pDocument->OnInit();
|
|
|
|
|
2004-04-10 09:11:03 +00:00
|
|
|
// Initialize the main gui window
|
|
|
|
m_pFrame = new CMainFrame(GetAppName());
|
2004-05-21 06:27:15 +00:00
|
|
|
wxASSERT(NULL != m_pFrame);
|
|
|
|
|
2004-10-25 21:42:47 +00:00
|
|
|
#ifndef NOTASKBAR
|
2004-10-23 07:13:18 +00:00
|
|
|
// Initialize the task bar icon
|
|
|
|
m_pTaskBarIcon = new CTaskBarIcon();
|
|
|
|
wxASSERT(NULL != m_pTaskBarIcon);
|
2004-10-25 21:42:47 +00:00
|
|
|
#endif
|
2004-10-23 07:13:18 +00:00
|
|
|
|
2004-11-17 09:27:06 +00:00
|
|
|
// Detect the default Window Station and Desktop and store the
|
|
|
|
// information for later use.
|
|
|
|
DetectDefaultWindowStation();
|
|
|
|
DetectDefaultDesktop();
|
|
|
|
|
2004-12-14 02:50:16 +00:00
|
|
|
// Startup the System Idle Detection code
|
|
|
|
StartupSystemIdleDetection();
|
|
|
|
|
2004-11-23 07:45:11 +00:00
|
|
|
// Detect if we need to start the BOINC Core Client due to configuration
|
|
|
|
StartupBOINCCore();
|
|
|
|
|
2004-11-17 09:27:06 +00:00
|
|
|
// Show the UI
|
2004-04-10 09:11:03 +00:00
|
|
|
SetTopWindow(m_pFrame);
|
2004-11-19 08:11:49 +00:00
|
|
|
if (m_bFrameVisible)
|
|
|
|
m_pFrame->Show();
|
2004-04-10 09:11:03 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int CBOINCGUIApp::OnExit()
|
|
|
|
{
|
2004-11-23 07:45:11 +00:00
|
|
|
// Detect if we need to stop the BOINC Core Client due to configuration
|
|
|
|
ShutdownBOINCCore();
|
|
|
|
|
2004-12-14 02:50:16 +00:00
|
|
|
// Shutdown the System Idle Detection code
|
|
|
|
ShutdownSystemIdleDetection();
|
|
|
|
|
2004-10-25 21:42:47 +00:00
|
|
|
#ifndef NOTASKBAR
|
2004-10-23 07:13:18 +00:00
|
|
|
if (m_pTaskBarIcon)
|
|
|
|
delete m_pTaskBarIcon;
|
2004-10-25 21:42:47 +00:00
|
|
|
#endif
|
2004-10-23 07:13:18 +00:00
|
|
|
|
2004-04-10 09:11:03 +00:00
|
|
|
if (m_pDocument)
|
2004-10-23 23:40:11 +00:00
|
|
|
{
|
|
|
|
m_pDocument->OnExit();
|
2004-04-10 09:11:03 +00:00
|
|
|
delete m_pDocument;
|
2004-10-23 23:40:11 +00:00
|
|
|
}
|
2004-04-10 09:11:03 +00:00
|
|
|
|
|
|
|
if (m_pLocale)
|
|
|
|
delete m_pLocale;
|
|
|
|
|
2004-11-23 07:45:11 +00:00
|
|
|
return wxApp::OnExit();
|
2004-04-10 09:11:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CBOINCGUIApp::OnInitCmdLine(wxCmdLineParser &parser)
|
|
|
|
{
|
2004-11-23 07:45:11 +00:00
|
|
|
wxApp::OnInitCmdLine(parser);
|
2004-04-10 09:11:03 +00:00
|
|
|
static const wxCmdLineEntryDesc cmdLineDesc[] = {
|
2004-11-19 08:11:49 +00:00
|
|
|
{ wxCMD_LINE_SWITCH, wxT("s"), wxT("systray"), _("Startup BOINC so only the system tray icon is visible")},
|
2004-04-10 09:11:03 +00:00
|
|
|
{ wxCMD_LINE_NONE} //DON'T forget this line!!
|
|
|
|
};
|
|
|
|
parser.SetDesc(cmdLineDesc);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool CBOINCGUIApp::OnCmdLineParsed(wxCmdLineParser &parser)
|
|
|
|
{
|
|
|
|
// Give default processing (-?, --help and --verbose) the chance to do something.
|
2004-11-23 07:45:11 +00:00
|
|
|
wxApp::OnCmdLineParsed(parser);
|
2004-11-19 08:11:49 +00:00
|
|
|
if (parser.Found(wxT("systray")))
|
|
|
|
{
|
|
|
|
m_bFrameVisible = false;
|
2004-04-10 09:11:03 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-11-17 09:27:06 +00:00
|
|
|
|
|
|
|
void CBOINCGUIApp::DetectDefaultWindowStation()
|
|
|
|
{
|
|
|
|
wxChar szWindowStation[256];
|
2004-11-24 00:25:54 +00:00
|
|
|
memset(szWindowStation, 0, sizeof(szWindowStation)/sizeof(wxChar));
|
2004-11-17 09:27:06 +00:00
|
|
|
|
|
|
|
#ifdef __WXMSW__
|
|
|
|
|
2004-11-23 07:45:11 +00:00
|
|
|
if ( wxWIN95 != wxGetOsVersion( NULL, NULL ) )
|
2004-11-17 09:27:06 +00:00
|
|
|
{
|
|
|
|
// Retrieve the current window station and desktop names
|
|
|
|
GetUserObjectInformation(
|
|
|
|
GetProcessWindowStation(),
|
|
|
|
UOI_NAME,
|
|
|
|
szWindowStation,
|
|
|
|
(sizeof(szWindowStation) / sizeof(wxChar)),
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
m_strDefaultWindowStation = szWindowStation;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CBOINCGUIApp::DetectDefaultDesktop()
|
|
|
|
{
|
|
|
|
wxChar szDesktop[256];
|
2004-11-24 00:25:54 +00:00
|
|
|
memset(szDesktop, 0, sizeof(szDesktop)/sizeof(wxChar));
|
2004-11-17 09:27:06 +00:00
|
|
|
|
|
|
|
#ifdef __WXMSW__
|
|
|
|
|
2004-11-23 07:45:11 +00:00
|
|
|
if ( wxWIN95 != wxGetOsVersion( NULL, NULL ) )
|
2004-11-17 09:27:06 +00:00
|
|
|
{
|
|
|
|
GetUserObjectInformation(
|
|
|
|
GetThreadDesktop(GetCurrentThreadId()),
|
|
|
|
UOI_NAME,
|
|
|
|
szDesktop,
|
|
|
|
(sizeof(szDesktop) / sizeof(wxChar)),
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
m_strDefaultDesktop = szDesktop;
|
|
|
|
}
|
|
|
|
|
2004-11-23 07:45:11 +00:00
|
|
|
|
|
|
|
bool CBOINCGUIApp::IsBOINCCoreRunning()
|
|
|
|
{
|
|
|
|
wxInt32 iMode = -1;
|
|
|
|
return ( 0 == m_pDocument->GetActivityRunMode(iMode));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CBOINCGUIApp::StartupBOINCCore()
|
|
|
|
{
|
|
|
|
if ( !IsBOINCCoreRunning() )
|
|
|
|
{
|
|
|
|
wxString strExecute = wxEmptyString;
|
|
|
|
wxChar szExecutableDirectory[4096];
|
|
|
|
|
|
|
|
memset(szExecutableDirectory, 0, sizeof(szExecutableDirectory));
|
|
|
|
|
|
|
|
#ifdef __WXMSW__
|
|
|
|
|
|
|
|
// On the surface it would seem that GetCurrentDirectory would be a better choice
|
|
|
|
// for determing which directory we should prepend to the execution string before
|
|
|
|
// starting BOINC, except that we cannot depend on any shortcuts being configured
|
|
|
|
// to startup in the correct directory, since the user may have created the
|
|
|
|
// shortcut themselves. So determine where boinc.exe is based off of our
|
|
|
|
// current execution location and then execute it.
|
|
|
|
GetModuleFileName(
|
|
|
|
NULL,
|
|
|
|
szExecutableDirectory,
|
|
|
|
(sizeof(szExecutableDirectory) / sizeof(wxChar) )
|
|
|
|
);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// We are only interested in the path component of the fully qualified path.
|
|
|
|
wxFileName::SplitPath( szExecutableDirectory, &strExecute, NULL, NULL );
|
|
|
|
|
|
|
|
// Set the current directory ahead of the application launch so the core
|
|
|
|
// client can find its files
|
|
|
|
::wxSetWorkingDirectory( strExecute );
|
|
|
|
|
|
|
|
#ifdef __WXMSW__
|
|
|
|
|
|
|
|
// Append boinc.exe to the end of the strExecute string and get ready to rock
|
|
|
|
strExecute += wxT("\\boinc.exe");
|
|
|
|
|
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
STARTUPINFO si;
|
|
|
|
BOOL bProcessStarted;
|
|
|
|
|
|
|
|
memset(&pi, 0, sizeof(pi));
|
|
|
|
memset(&si, 0, sizeof(si));
|
|
|
|
|
|
|
|
si.cb = sizeof(si);
|
|
|
|
si.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
si.wShowWindow = SW_HIDE;
|
|
|
|
|
|
|
|
bProcessStarted = CreateProcess(
|
|
|
|
NULL,
|
|
|
|
(LPTSTR)strExecute.c_str(),
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
FALSE,
|
|
|
|
CREATE_NEW_PROCESS_GROUP|CREATE_NO_WINDOW,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
&si,
|
|
|
|
&pi
|
|
|
|
);
|
|
|
|
if (bProcessStarted)
|
|
|
|
{
|
|
|
|
m_lBOINCCoreProccessId = pi.dwProcessId;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
// Append boinc.exe to the end of the strExecute string and get ready to rock
|
|
|
|
strExecute += wxT("/boinc");
|
|
|
|
m_lBOINCCoreProccessId = ::wxExecute( strExecute );
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if ( 0 != m_lBOINCCoreProccessId )
|
|
|
|
m_bBOINCStartedByManager = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CBOINCGUIApp::ShutdownBOINCCore()
|
|
|
|
{
|
|
|
|
wxInt32 iCount = 0;
|
|
|
|
bool bClientQuit = false;
|
|
|
|
|
|
|
|
if ( m_bBOINCStartedByManager )
|
|
|
|
{
|
|
|
|
if ( wxProcess::Exists( m_lBOINCCoreProccessId ) )
|
|
|
|
{
|
|
|
|
m_pDocument->CoreClientQuit();
|
2004-12-02 07:43:47 +00:00
|
|
|
/*
|
2004-11-23 07:45:11 +00:00
|
|
|
for ( iCount = 0; iCount <= 10; iCount++ )
|
|
|
|
{
|
2004-12-02 07:43:47 +00:00
|
|
|
if ( !bClientQuit && !wxProcess::Exists( m_lBOINCCoreProccessId ) )
|
2004-11-23 07:45:11 +00:00
|
|
|
{
|
|
|
|
bClientQuit = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
::wxSleep(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !bClientQuit )
|
|
|
|
::wxKill( m_lBOINCCoreProccessId );
|
2004-12-02 07:43:47 +00:00
|
|
|
*/
|
2004-11-23 07:45:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-08 00:40:19 +00:00
|
|
|
|
2004-12-14 02:50:16 +00:00
|
|
|
wxInt32 CBOINCGUIApp::StartupSystemIdleDetection()
|
|
|
|
{
|
|
|
|
#ifdef __WXMSW__
|
|
|
|
// load dll and start idle detection
|
|
|
|
m_hIdleDll = LoadLibrary("boinc.dll");
|
|
|
|
if(m_hIdleDll)
|
|
|
|
{
|
|
|
|
IdleTrackerInit fn;
|
|
|
|
fn = (IdleTrackerInit)GetProcAddress(m_hIdleDll, wxT("IdleTrackerInit"));
|
|
|
|
if(!fn)
|
|
|
|
{
|
|
|
|
FreeLibrary(m_hIdleDll);
|
|
|
|
m_hIdleDll = NULL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(!fn())
|
|
|
|
{
|
|
|
|
FreeLibrary(m_hIdleDll);
|
|
|
|
m_hIdleDll = NULL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxInt32 CBOINCGUIApp::ShutdownSystemIdleDetection()
|
|
|
|
{
|
|
|
|
#ifdef __WXMSW__
|
|
|
|
if(m_hIdleDll) {
|
|
|
|
IdleTrackerTerm fn;
|
|
|
|
fn = (IdleTrackerTerm)GetProcAddress(m_hIdleDll, wxT("IdleTrackerTerm"));
|
|
|
|
if(fn)
|
|
|
|
{
|
|
|
|
fn();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
FreeLibrary(m_hIdleDll);
|
|
|
|
m_hIdleDll = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_487cbf3018 = "$Id$";
|