2005-01-20 23:22:22 +00:00
|
|
|
// Berkeley Open Infrastructure for Network Computing
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2005 University of California
|
2004-05-17 22:15:10 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation;
|
|
|
|
// either version 2.1 of the License, or (at your option) any later version.
|
2004-04-10 09:11:03 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This software is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
2004-05-17 22:15:10 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// To view the GNU Lesser General Public License visit
|
|
|
|
// http://www.gnu.org/copyleft/lesser.html
|
|
|
|
// or write to the Free Software Foundation, Inc.,
|
|
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
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
|
|
|
|
2005-07-05 00:06:47 +00:00
|
|
|
#ifdef __WXMAC__
|
|
|
|
#include <Carbon/Carbon.h>
|
|
|
|
#endif
|
|
|
|
|
2004-04-11 04:37:10 +00:00
|
|
|
#include "stdwx.h"
|
2004-04-11 04:12:44 +00:00
|
|
|
#include "BOINCGUIApp.h"
|
2005-02-01 00:54:06 +00:00
|
|
|
#include "diagnostics.h"
|
2004-04-11 04:12:44 +00:00
|
|
|
#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)();
|
2005-01-07 07:32:23 +00:00
|
|
|
typedef DWORD (CALLBACK* IdleTrackerGetIdleTickCount)();
|
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)
|
|
|
|
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
bool CBOINCGUIApp::OnInit() {
|
2005-02-02 22:20:25 +00:00
|
|
|
#ifdef __WXMSW__
|
|
|
|
|
|
|
|
TCHAR szPath[MAX_PATH-1];
|
|
|
|
|
|
|
|
// change the current directory to the boinc install directory
|
|
|
|
GetModuleFileName(NULL, szPath, (sizeof(szPath)/sizeof(TCHAR)));
|
|
|
|
|
|
|
|
TCHAR *pszProg = strrchr(szPath, '\\');
|
|
|
|
if (pszProg) {
|
|
|
|
szPath[pszProg - szPath + 1] = 0;
|
|
|
|
SetCurrentDirectory(szPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2005-03-25 12:23:30 +00:00
|
|
|
#ifdef __WXMAC__
|
|
|
|
|
|
|
|
wxString strDirectory = wxEmptyString;
|
|
|
|
bool success;
|
|
|
|
|
|
|
|
// Set the current directory ahead of the application launch so the core
|
|
|
|
// client can find its files
|
2005-04-27 12:59:53 +00:00
|
|
|
#if 0 // Code for separate data in each user's private directory
|
2005-03-25 12:23:30 +00:00
|
|
|
wxChar buf[1024];
|
|
|
|
wxExpandPath(buf, "~/Library/Application Support");
|
|
|
|
strDirectory = wxT(buf);
|
2005-04-27 12:59:53 +00:00
|
|
|
#else // All users share the same data
|
|
|
|
// The mac installer sets the "setuid & setgid" bits for the
|
|
|
|
// BOINC Manager and core client so any user can run them and
|
|
|
|
// they can operate on shared data.
|
2005-03-25 12:23:30 +00:00
|
|
|
strDirectory = wxT("/Library/Application Support");
|
|
|
|
#endif
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
success = ::wxSetWorkingDirectory(strDirectory);
|
|
|
|
if (success) {
|
|
|
|
// If SetWD failed, don't create a directory in wrong place
|
2005-03-25 12:23:30 +00:00
|
|
|
strDirectory += wxT("/BOINC Data");
|
2005-04-26 15:03:51 +00:00
|
|
|
if (! wxDirExists(strDirectory))
|
2005-04-07 07:04:50 +00:00
|
|
|
success = wxMkdir(wxT("BOINC Data"), 0777); // Does nothing if dir exists
|
|
|
|
success = ::wxSetWorkingDirectory(strDirectory);
|
2005-03-25 12:23:30 +00:00
|
|
|
// wxChar *wd = wxGetWorkingDirectory(buf, 1000); // For debugging
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // __WXMAC__
|
|
|
|
|
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;
|
2005-01-06 22:25:53 +00:00
|
|
|
m_lBOINCCoreProcessId = 0;
|
2005-01-07 17:05:21 +00:00
|
|
|
#ifdef __WXMSW__
|
2005-01-06 22:25:53 +00:00
|
|
|
m_hBOINCCoreProcess = NULL;
|
2005-01-07 17:05:21 +00:00
|
|
|
m_hIdleDetectionDll = NULL;
|
|
|
|
#endif
|
2005-02-17 19:53:41 +00:00
|
|
|
m_strDefaultWindowStation = wxT("");
|
|
|
|
m_strDefaultDesktop = wxT("");
|
|
|
|
m_strDefaultDisplay = wxT("");
|
2005-02-07 04:47:18 +00:00
|
|
|
|
2004-05-21 06:27:15 +00:00
|
|
|
|
2005-02-01 00:54:06 +00:00
|
|
|
// Initialize the BOINC Diagnostics Framework
|
|
|
|
int dwDiagnosticsFlags =
|
|
|
|
BOINC_DIAG_DUMPCALLSTACKENABLED |
|
|
|
|
BOINC_DIAG_HEAPCHECKENABLED |
|
|
|
|
BOINC_DIAG_MEMORYLEAKCHECKENABLED |
|
2005-05-25 19:48:01 +00:00
|
|
|
#if defined(__WXMSW__) || defined(__WXMAC__)
|
2005-02-01 00:54:06 +00:00
|
|
|
BOINC_DIAG_REDIRECTSTDERR |
|
|
|
|
BOINC_DIAG_REDIRECTSTDOUT |
|
2005-05-05 18:59:55 +00:00
|
|
|
#endif
|
2005-02-01 00:54:06 +00:00
|
|
|
BOINC_DIAG_TRACETOSTDOUT;
|
|
|
|
|
|
|
|
diagnostics_init(
|
|
|
|
dwDiagnosticsFlags,
|
|
|
|
"stdoutgui",
|
|
|
|
"stderrgui"
|
2005-04-08 16:58:55 +00:00
|
|
|
);
|
2004-12-04 05:42:22 +00:00
|
|
|
|
2005-02-01 00:54:06 +00:00
|
|
|
// Initialize the configuration storage module
|
|
|
|
m_pConfig = new wxConfig(GetAppName());
|
|
|
|
wxConfigBase::Set(m_pConfig);
|
2005-04-27 06:55:28 +00:00
|
|
|
wxASSERT(m_pConfig);
|
2005-02-01 00:54:06 +00:00
|
|
|
|
2005-02-07 04:47:18 +00:00
|
|
|
m_pConfig->SetPath(wxT("/"));
|
|
|
|
|
2005-02-01 00:54:06 +00:00
|
|
|
// Enable Logging and Trace Masks
|
|
|
|
m_pLog = new wxLogBOINC();
|
|
|
|
wxLog::SetActiveTarget(m_pLog);
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
m_pLog->AddTraceMask(wxT("Function Start/End"));
|
|
|
|
m_pLog->AddTraceMask(wxT("Function Status"));
|
2004-04-10 09:11:03 +00:00
|
|
|
|
2004-10-21 23:07:13 +00:00
|
|
|
// Enable known image types
|
|
|
|
wxImage::AddHandler(new wxXPMHandler);
|
|
|
|
|
2004-04-10 09:11:03 +00:00
|
|
|
// Initialize the internationalization module
|
|
|
|
m_pLocale = new wxLocale();
|
2005-04-27 06:55:28 +00:00
|
|
|
wxASSERT(m_pLocale);
|
2004-05-21 06:27:15 +00:00
|
|
|
|
2005-02-07 04:47:18 +00:00
|
|
|
wxInt32 iSelectedLanguage = m_pConfig->Read(wxT("Language"), 0L);
|
|
|
|
|
|
|
|
// Locale information is stored relative to the executable.
|
|
|
|
m_pLocale->Init(iSelectedLanguage);
|
2004-10-31 23:16:09 +00:00
|
|
|
m_pLocale->AddCatalogLookupPathPrefix(wxT("locale"));
|
2004-04-10 09:11:03 +00:00
|
|
|
m_pLocale->AddCatalog(GetAppName());
|
|
|
|
|
2005-02-07 04:47:18 +00:00
|
|
|
InitSupportedLanguages();
|
|
|
|
|
2005-07-21 09:43:40 +00:00
|
|
|
// Note: JAWS for Windows will only speak the context-sensitive
|
|
|
|
// help if you use this help provider:
|
|
|
|
wxHelpProvider::Set(new wxHelpControllerHelpProvider());
|
|
|
|
|
2005-02-01 00:54:06 +00:00
|
|
|
// Commandline parsing is done in wxApp::OnInit()
|
2005-04-08 16:58:55 +00:00
|
|
|
if (!wxApp::OnInit()) {
|
2005-02-01 00:54:06 +00:00
|
|
|
return false;
|
2005-04-08 16:58:55 +00:00
|
|
|
}
|
2004-05-21 06:27:15 +00:00
|
|
|
|
2004-04-10 09:11:03 +00:00
|
|
|
// Initialize the main document
|
|
|
|
m_pDocument = new CMainDocument();
|
2005-04-27 06:55:28 +00:00
|
|
|
wxASSERT(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());
|
2005-04-27 06:55:28 +00:00
|
|
|
wxASSERT(m_pFrame);
|
2004-05-21 06:27:15 +00:00
|
|
|
|
2004-10-23 07:13:18 +00:00
|
|
|
// Initialize the task bar icon
|
|
|
|
m_pTaskBarIcon = new CTaskBarIcon();
|
2005-04-27 06:55:28 +00:00
|
|
|
wxASSERT(m_pTaskBarIcon);
|
2005-03-25 12:23:30 +00:00
|
|
|
#ifdef __WXMAC__
|
|
|
|
m_pMacSystemMenu = new CMacSystemMenu();
|
2005-04-27 06:55:28 +00:00
|
|
|
wxASSERT(m_pMacSystemMenu);
|
2004-10-25 21:42:47 +00:00
|
|
|
#endif
|
2004-10-23 07:13:18 +00:00
|
|
|
|
2005-02-15 06:32:43 +00:00
|
|
|
// Detect the display info and store for later use.
|
|
|
|
DetectDisplayInfo();
|
2004-11-17 09:27:06 +00:00
|
|
|
|
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();
|
|
|
|
|
2005-04-26 15:03:51 +00:00
|
|
|
#ifdef __WXMAC__
|
|
|
|
ProcessSerialNumber psn;
|
|
|
|
ProcessInfoRec pInfo;
|
|
|
|
OSStatus err;
|
|
|
|
|
|
|
|
GetCurrentProcess(&psn);
|
|
|
|
memset(&pInfo, 0, sizeof(pInfo));
|
|
|
|
pInfo.processInfoLength = sizeof( ProcessInfoRec );
|
|
|
|
err = GetProcessInformation(&psn, &pInfo);
|
|
|
|
if (!err) {
|
|
|
|
psn = pInfo.processLauncher;
|
|
|
|
memset(&pInfo, 0, sizeof(pInfo));
|
|
|
|
pInfo.processInfoLength = sizeof( ProcessInfoRec );
|
|
|
|
err = GetProcessInformation(&psn, &pInfo);
|
|
|
|
}
|
|
|
|
// Don't open main window if we were started automatically at login
|
2005-04-27 12:59:53 +00:00
|
|
|
if (pInfo.processSignature == 'lgnw') { // Login Window app
|
2005-04-26 15:03:51 +00:00
|
|
|
m_bFrameVisible = false;
|
2005-04-27 12:59:53 +00:00
|
|
|
|
|
|
|
// If the system was just started, we usually get a "Connection
|
|
|
|
// failed" error if we try to connect too soon, so delay a bit.
|
|
|
|
sleep(10);
|
|
|
|
}
|
2005-04-26 15:03:51 +00:00
|
|
|
#endif
|
|
|
|
|
2004-11-17 09:27:06 +00:00
|
|
|
// Show the UI
|
2004-04-10 09:11:03 +00:00
|
|
|
SetTopWindow(m_pFrame);
|
2005-04-07 07:04:50 +00:00
|
|
|
if (m_bFrameVisible) {
|
2004-11-19 08:11:49 +00:00
|
|
|
m_pFrame->Show();
|
2005-04-07 07:04:50 +00:00
|
|
|
} else {
|
2005-07-06 05:16:53 +00:00
|
|
|
#ifdef __WXMAC__
|
|
|
|
GetCurrentProcess(&psn);
|
|
|
|
ShowHideProcess(&psn, false);
|
|
|
|
#else
|
2005-02-11 00:08:01 +00:00
|
|
|
m_pFrame->Show();
|
|
|
|
m_pFrame->Show(false);
|
2005-05-07 12:37:01 +00:00
|
|
|
#endif
|
2005-02-11 00:08:01 +00:00
|
|
|
}
|
|
|
|
|
2004-04-10 09:11:03 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
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();
|
|
|
|
|
2005-04-08 16:58:55 +00:00
|
|
|
if (m_pTaskBarIcon) {
|
2004-10-23 07:13:18 +00:00
|
|
|
delete m_pTaskBarIcon;
|
2005-04-08 16:58:55 +00:00
|
|
|
}
|
2005-03-25 12:23:30 +00:00
|
|
|
#ifdef __WXMAC__
|
2005-04-08 16:58:55 +00:00
|
|
|
if (m_pMacSystemMenu) {
|
2005-03-25 12:23:30 +00:00
|
|
|
delete m_pMacSystemMenu;
|
2005-04-08 16:58:55 +00:00
|
|
|
}
|
2004-10-25 21:42:47 +00:00
|
|
|
#endif
|
2004-10-23 07:13:18 +00:00
|
|
|
|
2005-04-07 07:04:50 +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
|
|
|
|
2005-04-08 16:58:55 +00:00
|
|
|
if (m_pLocale) {
|
2004-04-10 09:11:03 +00:00
|
|
|
delete m_pLocale;
|
2005-04-08 16:58:55 +00:00
|
|
|
}
|
2004-04-10 09:11:03 +00:00
|
|
|
|
2004-11-23 07:45:11 +00:00
|
|
|
return wxApp::OnExit();
|
2004-04-10 09:11:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-07 07:04:50 +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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
bool CBOINCGUIApp::OnCmdLineParsed(wxCmdLineParser &parser) {
|
2004-04-10 09:11:03 +00:00
|
|
|
// Give default processing (-?, --help and --verbose) the chance to do something.
|
2004-11-23 07:45:11 +00:00
|
|
|
wxApp::OnCmdLineParsed(parser);
|
2005-04-07 07:04:50 +00:00
|
|
|
if (parser.Found(wxT("systray"))) {
|
2004-11-19 08:11:49 +00:00
|
|
|
m_bFrameVisible = false;
|
2004-04-10 09:11:03 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-11-17 09:27:06 +00:00
|
|
|
|
2005-02-15 06:32:43 +00:00
|
|
|
void CBOINCGUIApp::DetectDisplayInfo() {
|
|
|
|
#ifdef __WXMSW__
|
2004-11-17 09:27:06 +00:00
|
|
|
wxChar szWindowStation[256];
|
2004-11-24 00:25:54 +00:00
|
|
|
memset(szWindowStation, 0, sizeof(szWindowStation)/sizeof(wxChar));
|
2005-02-15 06:46:42 +00:00
|
|
|
wxChar szDesktop[256];
|
2005-02-15 06:32:43 +00:00
|
|
|
memset(szDesktop, 0, sizeof(szDesktop)/sizeof(wxChar));
|
2004-11-17 09:27:06 +00:00
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
if (wxWIN95 != wxGetOsVersion(NULL, NULL)) {
|
2004-11-17 09:27:06 +00:00
|
|
|
// Retrieve the current window station and desktop names
|
2005-04-07 07:04:50 +00:00
|
|
|
GetUserObjectInformation(
|
2004-11-17 09:27:06 +00:00
|
|
|
GetProcessWindowStation(),
|
|
|
|
UOI_NAME,
|
|
|
|
szWindowStation,
|
|
|
|
(sizeof(szWindowStation) / sizeof(wxChar)),
|
|
|
|
NULL
|
|
|
|
);
|
2005-04-07 07:04:50 +00:00
|
|
|
GetUserObjectInformation(
|
2004-11-17 09:27:06 +00:00
|
|
|
GetThreadDesktop(GetCurrentThreadId()),
|
|
|
|
UOI_NAME,
|
|
|
|
szDesktop,
|
|
|
|
(sizeof(szDesktop) / sizeof(wxChar)),
|
|
|
|
NULL
|
|
|
|
);
|
2005-02-15 06:32:43 +00:00
|
|
|
m_strDefaultWindowStation = szWindowStation;
|
|
|
|
m_strDefaultDesktop = szDesktop;
|
2004-11-17 09:27:06 +00:00
|
|
|
}
|
|
|
|
|
2005-02-15 06:32:43 +00:00
|
|
|
#else
|
|
|
|
char* p = getenv("DISPLAY");
|
|
|
|
if (p) m_strDefaultDisplay = p;
|
2004-11-17 09:27:06 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2004-11-23 07:45:11 +00:00
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
void CBOINCGUIApp::InitSupportedLanguages() {
|
2005-02-07 04:47:18 +00:00
|
|
|
wxInt32 iIndex = 0;
|
|
|
|
const wxLanguageInfo* liLanguage = NULL;
|
|
|
|
|
2005-06-28 15:55:59 +00:00
|
|
|
// Prepare the array
|
|
|
|
m_astrLanguages.Insert(wxEmptyString, 0, wxLANGUAGE_USER_DEFINED+1);
|
|
|
|
|
2005-02-07 04:47:18 +00:00
|
|
|
// These are just special tags so deal with them in a special way
|
2005-06-28 15:55:59 +00:00
|
|
|
m_astrLanguages[wxLANGUAGE_DEFAULT] = _("(Automatic Detection)");
|
|
|
|
m_astrLanguages[wxLANGUAGE_UNKNOWN] = _("(Unknown)");
|
|
|
|
m_astrLanguages[wxLANGUAGE_USER_DEFINED] = _("(User Defined)");
|
2005-02-07 04:47:18 +00:00
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
for (iIndex = 0; iIndex <= wxLANGUAGE_USER_DEFINED; iIndex++) {
|
|
|
|
liLanguage = wxLocale::GetLanguageInfo(iIndex);
|
2005-04-27 06:55:28 +00:00
|
|
|
if (liLanguage) {
|
2005-06-28 15:55:59 +00:00
|
|
|
m_astrLanguages[iIndex] = liLanguage->Description;
|
2005-02-07 04:47:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
bool CBOINCGUIApp::IsBOINCCoreRunning() {
|
2005-04-15 20:49:23 +00:00
|
|
|
wxLogTrace(wxT("Function Start/End"), wxT("CBOINCGUIApp::IsBOINCCoreRunning - Function Begin"));
|
2005-04-15 18:45:06 +00:00
|
|
|
|
2005-05-05 18:59:55 +00:00
|
|
|
int retval;
|
|
|
|
bool running;
|
2005-04-08 04:23:37 +00:00
|
|
|
RPC_CLIENT rpc;
|
2005-05-25 19:26:37 +00:00
|
|
|
retval = rpc.init("localhost"); // synchronous is OK since local
|
2005-05-05 18:59:55 +00:00
|
|
|
running = (retval == 0);
|
|
|
|
rpc.close();
|
2005-04-15 18:45:06 +00:00
|
|
|
|
2005-04-15 20:49:23 +00:00
|
|
|
wxLogTrace(wxT("Function Start/End"), wxT("CBOINCGUIApp::IsBOINCCoreRunning - Function End"));
|
2005-05-05 18:59:55 +00:00
|
|
|
return running;
|
2004-11-23 07:45:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
void CBOINCGUIApp::StartupBOINCCore() {
|
|
|
|
if (!IsBOINCCoreRunning()) {
|
2005-03-25 12:23:30 +00:00
|
|
|
#ifndef __WXMAC__
|
2005-02-01 06:16:13 +00:00
|
|
|
wxString strDirectory = wxEmptyString;
|
2005-03-25 12:23:30 +00:00
|
|
|
#endif // ! __WXMAC__
|
|
|
|
|
2004-11-23 07:45:11 +00:00
|
|
|
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.
|
2005-04-07 07:04:50 +00:00
|
|
|
GetModuleFileName(
|
2004-11-23 07:45:11 +00:00
|
|
|
NULL,
|
|
|
|
szExecutableDirectory,
|
2005-04-07 07:04:50 +00:00
|
|
|
(sizeof(szExecutableDirectory) / sizeof(wxChar))
|
2004-11-23 07:45:11 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2005-03-11 13:08:52 +00:00
|
|
|
#ifdef __WXMAC__
|
|
|
|
|
|
|
|
{
|
|
|
|
wxChar buf[1024];
|
|
|
|
ProcessSerialNumber ourPSN;
|
|
|
|
FSRef ourFSRef;
|
|
|
|
OSErr err;
|
|
|
|
|
|
|
|
// Get the full path to core client inside this application's bundle
|
|
|
|
err = GetCurrentProcess (&ourPSN);
|
2005-04-08 16:58:55 +00:00
|
|
|
if (err == noErr) {
|
2005-03-11 13:08:52 +00:00
|
|
|
err = GetProcessBundleLocation(&ourPSN, &ourFSRef);
|
2005-04-08 16:58:55 +00:00
|
|
|
}
|
|
|
|
if (err == noErr) {
|
2005-03-11 13:08:52 +00:00
|
|
|
err = FSRefMakePath (&ourFSRef, (UInt8*)buf, sizeof(buf));
|
2005-04-08 16:58:55 +00:00
|
|
|
}
|
2005-04-07 07:04:50 +00:00
|
|
|
if (err == noErr) {
|
2005-03-11 13:08:52 +00:00
|
|
|
strExecute = wxT("\"");
|
|
|
|
strExecute += wxT(buf);
|
2005-04-23 15:14:52 +00:00
|
|
|
strExecute += wxT("/Contents/Resources/boinc\" -redirectio");
|
2005-04-07 07:04:50 +00:00
|
|
|
} else {
|
2005-03-11 13:08:52 +00:00
|
|
|
buf[0] = '\0';
|
2005-04-07 07:04:50 +00:00
|
|
|
}
|
2005-03-11 13:08:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#else // ! __WXMAC__
|
|
|
|
|
2005-07-07 20:32:28 +00:00
|
|
|
#ifndef __WXMSW__
|
|
|
|
// copy the path to the boinmgr from argv[0]
|
|
|
|
strncpy(szExecutableDirectory, wxGetApp().argv[0], sizeof(szExecutableDirectory));
|
|
|
|
#endif
|
|
|
|
|
2004-11-23 07:45:11 +00:00
|
|
|
// We are only interested in the path component of the fully qualified path.
|
2005-04-07 07:04:50 +00:00
|
|
|
wxFileName::SplitPath(szExecutableDirectory, &strDirectory, NULL, NULL);
|
2004-11-23 07:45:11 +00:00
|
|
|
|
|
|
|
// Set the current directory ahead of the application launch so the core
|
|
|
|
// client can find its files
|
2005-04-07 07:04:50 +00:00
|
|
|
::wxSetWorkingDirectory(strDirectory);
|
2004-11-23 07:45:11 +00:00
|
|
|
|
2005-03-11 13:08:52 +00:00
|
|
|
#endif // ! __WXMAC__
|
|
|
|
|
2004-11-23 07:45:11 +00:00
|
|
|
#ifdef __WXMSW__
|
|
|
|
|
|
|
|
// Append boinc.exe to the end of the strExecute string and get ready to rock
|
2005-02-01 06:16:13 +00:00
|
|
|
strExecute = wxT("\"") + strDirectory + wxT("\\boinc.exe\" -redirectio");
|
2004-11-23 07:45:11 +00:00
|
|
|
|
|
|
|
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,
|
2005-02-01 06:16:13 +00:00
|
|
|
(LPTSTR)strDirectory.c_str(),
|
2004-11-23 07:45:11 +00:00
|
|
|
&si,
|
|
|
|
&pi
|
|
|
|
);
|
2005-04-07 07:04:50 +00:00
|
|
|
if (bProcessStarted) {
|
2005-01-06 22:25:53 +00:00
|
|
|
m_lBOINCCoreProcessId = pi.dwProcessId;
|
|
|
|
m_hBOINCCoreProcess = pi.hProcess;
|
2004-11-23 07:45:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2005-03-11 13:08:52 +00:00
|
|
|
#ifndef __WXMAC__
|
|
|
|
|
2004-11-23 07:45:11 +00:00
|
|
|
// Append boinc.exe to the end of the strExecute string and get ready to rock
|
2005-07-08 09:04:21 +00:00
|
|
|
strExecute = wxT("./boinc -redirectio");
|
2005-03-11 13:08:52 +00:00
|
|
|
|
|
|
|
#endif // ! __WXMAC__
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
m_lBOINCCoreProcessId = ::wxExecute(strExecute);
|
2004-11-23 07:45:11 +00:00
|
|
|
|
2005-03-11 13:08:52 +00:00
|
|
|
#endif // ! __WXMSW__
|
2004-11-23 07:45:11 +00:00
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
if (0 != m_lBOINCCoreProcessId) {
|
2004-11-23 07:45:11 +00:00
|
|
|
m_bBOINCStartedByManager = true;
|
2005-04-07 07:04:50 +00:00
|
|
|
}
|
2004-11-23 07:45:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-05-06 09:24:30 +00:00
|
|
|
#if defined(__WXMSW__)
|
2005-01-07 20:47:40 +00:00
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
void CBOINCGUIApp::ShutdownBOINCCore() {
|
2005-02-17 21:05:24 +00:00
|
|
|
wxInt32 iCount = 0;
|
|
|
|
bool bClientQuit = false;
|
|
|
|
DWORD dwExitCode;
|
|
|
|
wxString strMachineName = wxT("localhost");
|
2004-11-23 07:45:11 +00:00
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
if (m_bBOINCStartedByManager) {
|
2005-02-17 19:53:41 +00:00
|
|
|
// The user may have gone off to look at another machine on the network, and
|
|
|
|
// we don't want to leave any dangling processes if we started them up.
|
2005-02-17 21:05:24 +00:00
|
|
|
m_pDocument->Connect(strMachineName);
|
2005-04-07 07:04:50 +00:00
|
|
|
if (GetExitCodeProcess(m_hBOINCCoreProcess, &dwExitCode)) {
|
|
|
|
if (STILL_ACTIVE == dwExitCode) {
|
2005-01-07 07:32:23 +00:00
|
|
|
m_pDocument->CoreClientQuit();
|
2005-04-07 07:04:50 +00:00
|
|
|
for (iCount = 0; iCount <= 10; iCount++) {
|
|
|
|
if (!bClientQuit && GetExitCodeProcess(m_hBOINCCoreProcess, &dwExitCode)) {
|
|
|
|
if (STILL_ACTIVE != dwExitCode) {
|
2005-01-07 07:32:23 +00:00
|
|
|
bClientQuit = true;
|
|
|
|
continue;
|
|
|
|
}
|
2005-01-06 22:25:53 +00:00
|
|
|
}
|
2005-04-21 06:12:11 +00:00
|
|
|
::Sleep(1);
|
2005-01-07 07:32:23 +00:00
|
|
|
}
|
2004-11-23 07:45:11 +00:00
|
|
|
}
|
2005-01-07 07:32:23 +00:00
|
|
|
}
|
2005-01-07 20:47:40 +00:00
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
if (!bClientQuit) {
|
|
|
|
::wxKill(m_lBOINCCoreProcessId);
|
|
|
|
}
|
2005-01-07 20:47:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-06 09:24:30 +00:00
|
|
|
#elif defined(__WXMAC__)
|
|
|
|
|
2005-09-20 00:45:00 +00:00
|
|
|
static char * PersistentFGets(char *buf, size_t buflen, FILE *f) {
|
|
|
|
char *p = buf;
|
|
|
|
size_t len = buflen;
|
|
|
|
size_t datalen = 0;
|
|
|
|
|
|
|
|
*buf = '\0';
|
|
|
|
while (datalen < (buflen - 1)) {
|
|
|
|
fgets(p, len, f);
|
|
|
|
if (feof(f)) break;
|
|
|
|
if (ferror(f) && (errno != EINTR)) break;
|
|
|
|
if (strchr(buf, '\n')) break;
|
|
|
|
datalen = strlen(buf);
|
|
|
|
p = buf + datalen;
|
|
|
|
len -= datalen;
|
|
|
|
}
|
|
|
|
return (buf[0] ? buf : NULL);
|
|
|
|
}
|
|
|
|
|
2005-05-06 09:24:30 +00:00
|
|
|
bool CBOINCGUIApp::ProcessExists(pid_t thePID)
|
|
|
|
{
|
|
|
|
FILE *f;
|
|
|
|
char buf[256];
|
|
|
|
pid_t aPID;
|
|
|
|
|
|
|
|
f = popen("ps -a -x -c -o pid,state", "r");
|
|
|
|
if (f == NULL)
|
|
|
|
return false;
|
|
|
|
|
2005-09-20 00:45:00 +00:00
|
|
|
while (PersistentFGets(buf, sizeof(buf), f)) {
|
2005-05-06 09:24:30 +00:00
|
|
|
aPID = atol(buf);
|
|
|
|
if (aPID == thePID) {
|
|
|
|
if (strchr(buf, 'Z')) // A 'zombie', stopped but waiting
|
|
|
|
break; // for us (its parent) to quit
|
|
|
|
pclose(f);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pclose(f);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// wxProcess::Exists and wxKill are unimplemented in WxMac-2.6.0
|
|
|
|
void CBOINCGUIApp::ShutdownBOINCCore() {
|
|
|
|
wxInt32 iCount = 0;
|
|
|
|
wxString strMachineName = wxT("localhost");
|
|
|
|
|
|
|
|
if (m_bBOINCStartedByManager) {
|
|
|
|
// The user may have gone off to look at another machine on the network, and
|
|
|
|
// we don't want to leave any dangling processes if we started them up.
|
|
|
|
m_pDocument->Connect(strMachineName);
|
|
|
|
|
|
|
|
if (ProcessExists(m_lBOINCCoreProcessId)) {
|
|
|
|
m_pDocument->CoreClientQuit();
|
|
|
|
for (iCount = 0; iCount <= 10; iCount++) {
|
|
|
|
if (!ProcessExists(m_lBOINCCoreProcessId))
|
|
|
|
return;
|
|
|
|
|
|
|
|
::wxSleep(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Client did not quit after 10 seconds so kill it
|
|
|
|
kill(m_lBOINCCoreProcessId, SIGKILL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-07 07:32:23 +00:00
|
|
|
#else
|
2005-01-07 20:47:40 +00:00
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
void CBOINCGUIApp::ShutdownBOINCCore() {
|
2005-01-07 20:47:40 +00:00
|
|
|
wxInt32 iCount = 0;
|
|
|
|
bool bClientQuit = false;
|
2005-04-08 04:23:37 +00:00
|
|
|
wxString strMachineName = wxT("localhost");
|
2005-01-07 20:47:40 +00:00
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
if (m_bBOINCStartedByManager) {
|
2005-04-08 04:23:37 +00:00
|
|
|
// The user may have gone off to look at another machine on the network, and
|
|
|
|
// we don't want to leave any dangling processes if we started them up.
|
|
|
|
m_pDocument->Connect(strMachineName);
|
2005-04-07 07:04:50 +00:00
|
|
|
if (wxProcess::Exists(m_lBOINCCoreProcessId)) {
|
2005-01-07 20:47:40 +00:00
|
|
|
m_pDocument->CoreClientQuit();
|
2005-04-07 07:04:50 +00:00
|
|
|
for (iCount = 0; iCount <= 10; iCount++) {
|
|
|
|
if (!bClientQuit && !wxProcess::Exists(m_lBOINCCoreProcessId)) {
|
2005-01-07 20:47:40 +00:00
|
|
|
bClientQuit = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
::wxSleep(1);
|
|
|
|
}
|
2005-01-07 07:32:23 +00:00
|
|
|
}
|
2005-01-07 20:47:40 +00:00
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
if (!bClientQuit) {
|
|
|
|
::wxKill(m_lBOINCCoreProcessId);
|
|
|
|
}
|
2004-11-23 07:45:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-07 20:47:40 +00:00
|
|
|
#endif
|
|
|
|
|
2004-12-08 00:40:19 +00:00
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
wxInt32 CBOINCGUIApp::StartupSystemIdleDetection() {
|
2004-12-14 02:50:16 +00:00
|
|
|
#ifdef __WXMSW__
|
|
|
|
// load dll and start idle detection
|
2005-01-07 07:32:23 +00:00
|
|
|
m_hIdleDetectionDll = LoadLibrary("boinc.dll");
|
2005-04-07 07:04:50 +00:00
|
|
|
if(m_hIdleDetectionDll) {
|
2004-12-14 02:50:16 +00:00
|
|
|
IdleTrackerInit fn;
|
2005-01-07 07:32:23 +00:00
|
|
|
fn = (IdleTrackerInit)GetProcAddress(m_hIdleDetectionDll, wxT("IdleTrackerInit"));
|
2005-04-07 07:04:50 +00:00
|
|
|
if(!fn) {
|
2005-01-07 07:32:23 +00:00
|
|
|
FreeLibrary(m_hIdleDetectionDll);
|
|
|
|
m_hIdleDetectionDll = NULL;
|
2004-12-14 02:50:16 +00:00
|
|
|
return -1;
|
2005-04-07 07:04:50 +00:00
|
|
|
} else {
|
|
|
|
if(!fn()) {
|
2005-01-07 07:32:23 +00:00
|
|
|
FreeLibrary(m_hIdleDetectionDll);
|
|
|
|
m_hIdleDetectionDll = NULL;
|
2004-12-14 02:50:16 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
wxInt32 CBOINCGUIApp::ShutdownSystemIdleDetection() {
|
2004-12-14 02:50:16 +00:00
|
|
|
#ifdef __WXMSW__
|
2005-01-07 07:32:23 +00:00
|
|
|
if(m_hIdleDetectionDll) {
|
2004-12-14 02:50:16 +00:00
|
|
|
IdleTrackerTerm fn;
|
2005-01-07 07:32:23 +00:00
|
|
|
fn = (IdleTrackerTerm)GetProcAddress(m_hIdleDetectionDll, wxT("IdleTrackerTerm"));
|
2005-04-07 07:04:50 +00:00
|
|
|
if(fn) {
|
2005-01-07 07:32:23 +00:00
|
|
|
fn();
|
2005-04-07 07:04:50 +00:00
|
|
|
} else {
|
2005-01-07 07:32:23 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
FreeLibrary(m_hIdleDetectionDll);
|
|
|
|
m_hIdleDetectionDll = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
wxInt32 CBOINCGUIApp::UpdateSystemIdleDetection() {
|
2005-01-07 07:32:23 +00:00
|
|
|
#ifdef __WXMSW__
|
2005-04-07 07:04:50 +00:00
|
|
|
if (m_hIdleDetectionDll) {
|
2005-01-07 07:32:23 +00:00
|
|
|
IdleTrackerGetIdleTickCount fn;
|
|
|
|
fn = (IdleTrackerGetIdleTickCount)GetProcAddress(m_hIdleDetectionDll, wxT("IdleTrackerGetIdleTickCount"));
|
2005-04-07 07:04:50 +00:00
|
|
|
if(fn) {
|
2004-12-14 02:50:16 +00:00
|
|
|
fn();
|
2005-04-07 07:04:50 +00:00
|
|
|
} else {
|
2004-12-14 02:50:16 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_487cbf3018 = "$Id$";
|