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"
|
2006-01-23 08:47:05 +00:00
|
|
|
#include "network.h"
|
2004-04-11 04:12:44 +00:00
|
|
|
#include "MainFrame.h"
|
2006-01-19 12:22:22 +00:00
|
|
|
#include "Events.h"
|
2004-04-11 04:12:44 +00:00
|
|
|
#include "MainDocument.h"
|
2004-04-10 09:11:03 +00:00
|
|
|
|
|
|
|
|
2005-12-28 12:33:18 +00:00
|
|
|
////@begin XPM images
|
2006-01-12 01:42:55 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
#include "res/boinc_mac.xpm"
|
|
|
|
#include "res/gridrepublic_mac.xpm"
|
|
|
|
#else
|
2005-12-28 12:33:18 +00:00
|
|
|
#include "res/boinc.xpm"
|
2006-01-12 01:42:55 +00:00
|
|
|
#include "res/gridrepublic.xpm"
|
2006-01-24 11:27:26 +00:00
|
|
|
#include "res/cpdnbbc16.xpm"
|
|
|
|
#include "res/cpdnbbc32.xpm"
|
2006-01-25 02:33:01 +00:00
|
|
|
#include "res/cpdnbbcapwizard.xpm"
|
2006-01-12 01:42:55 +00:00
|
|
|
#endif
|
|
|
|
|
2005-12-28 12:33:18 +00:00
|
|
|
#include "res/boincsm.xpm"
|
2006-01-04 13:14:14 +00:00
|
|
|
#include "res/gridrepublicamwizard.xpm"
|
2005-12-28 12:33:18 +00:00
|
|
|
////@end XPM images
|
|
|
|
|
|
|
|
|
2004-12-14 20:15:06 +00:00
|
|
|
#ifdef __WXMSW__
|
2006-01-23 08:47:05 +00:00
|
|
|
typedef BOOL (*pfnClientLibraryStartup)();
|
|
|
|
typedef void (*pfnClientLibraryShutdown)();
|
2006-01-23 21:48:45 +00:00
|
|
|
typedef int (*pfnBOINCIsNetworkAlive)(long* lpdwFlags);
|
2006-01-23 08:47:05 +00:00
|
|
|
typedef int (*pfnBOINCIsNetworkAlwaysOnline)();
|
|
|
|
typedef DWORD (*pfnBOINCGetIdleTickCount)();
|
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-12-28 12:33:18 +00:00
|
|
|
bool CBrandingScheme::OnInit( wxConfigBase *pConfig ) {
|
|
|
|
wxString strBaseConfigLocation = wxEmptyString;
|
|
|
|
wxInt32 iBrandId = 0;
|
|
|
|
|
|
|
|
wxASSERT(pConfig);
|
|
|
|
|
2006-01-11 13:35:35 +00:00
|
|
|
#ifdef __WXMAC__
|
|
|
|
wxChar buf[1024];
|
|
|
|
ProcessSerialNumber ourPSN;
|
|
|
|
FSRef ourFSRef;
|
|
|
|
OSErr err;
|
|
|
|
|
|
|
|
iBrandId = 0; // Default value
|
|
|
|
// Get the full path to core client inside this application's bundle
|
|
|
|
err = GetCurrentProcess (&ourPSN);
|
|
|
|
if (err == noErr) {
|
|
|
|
err = GetProcessBundleLocation(&ourPSN, &ourFSRef);
|
|
|
|
}
|
|
|
|
if (err == noErr) {
|
|
|
|
err = FSRefMakePath (&ourFSRef, (UInt8*)buf, sizeof(buf));
|
|
|
|
}
|
|
|
|
if (err == noErr) {
|
|
|
|
strcat(buf, "/Contents/Resources/Branding");
|
|
|
|
FILE *f = fopen(buf, "r");
|
|
|
|
if (f) {
|
|
|
|
fscanf(f, "BrandId=%d\n", &iBrandId);
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
2005-12-28 12:33:18 +00:00
|
|
|
strBaseConfigLocation = pConfig->GetPath();
|
|
|
|
pConfig->SetPath(strBaseConfigLocation + wxT("Branding"));
|
|
|
|
pConfig->Read(wxT("BrandId"), &iBrandId, 0);
|
|
|
|
pConfig->SetPath(strBaseConfigLocation);
|
2006-01-11 13:35:35 +00:00
|
|
|
#endif
|
2005-12-28 12:33:18 +00:00
|
|
|
|
|
|
|
// If the BrandId is greater than 0 then we are running in
|
|
|
|
// branded mode
|
|
|
|
if (iBrandId) {
|
|
|
|
m_bIsBranded = true;
|
|
|
|
} else {
|
|
|
|
m_bIsBranded = false; // wxWidgets automatically sets bools to
|
|
|
|
// true by default.
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now determine which resources are needed for each BrandId
|
|
|
|
switch (iBrandId) {
|
|
|
|
case 1:
|
|
|
|
// Running as a GridRepublic client.
|
|
|
|
m_strApplicationName = wxT("GridRepublic Manager");
|
|
|
|
m_iconApplicationIcon = wxIcon(gridrepublic_xpm);
|
|
|
|
m_bitmapApplicationLogo = wxBitmap(gridrepublic_xpm);
|
|
|
|
m_strCompanyName = wxT("GridRepublic");
|
|
|
|
m_strCompanyWebsite = wxT("http://www.gridrepublic.com/");
|
|
|
|
m_strProjectName = wxT("GridRepublic");
|
2006-01-15 12:10:42 +00:00
|
|
|
m_strAPWizardTitle = wxEmptyString;
|
2006-01-19 12:22:22 +00:00
|
|
|
m_bDefaultTabSpecified = false;
|
|
|
|
m_iDefaultTab = 0;
|
2006-01-04 13:14:14 +00:00
|
|
|
m_bitmapAPWizardLogo = wxBitmap(gridrepublicamwizard_xpm);
|
2006-01-15 12:10:42 +00:00
|
|
|
m_strAPWizardAccountInfoText = wxEmptyString;
|
|
|
|
m_strAPWizardCompletionTitle = wxEmptyString;
|
2006-01-19 12:22:22 +00:00
|
|
|
m_strAPWizardCompletionBrandedMessage = wxEmptyString;
|
2006-01-15 12:10:42 +00:00
|
|
|
m_strAPWizardCompletionMessage = wxEmptyString;
|
|
|
|
m_strAMWizardTitle = wxEmptyString;
|
2006-01-04 13:14:14 +00:00
|
|
|
m_bitmapAMWizardLogo = wxBitmap(gridrepublicamwizard_xpm);
|
2006-02-01 12:18:10 +00:00
|
|
|
m_strAMWizardAccountInfoText =
|
|
|
|
_("Please provide the email address and password you used to register\n"
|
|
|
|
"at GridRepublic. (if you have not yet created an account at\n"
|
|
|
|
"GridRepublic, please do so at http://www.gridrepublic.org");
|
2006-01-15 12:10:42 +00:00
|
|
|
m_strAMWizardAttachMessage = wxEmptyString;
|
2006-01-23 11:30:25 +00:00
|
|
|
m_strExitMessage = wxEmptyString;
|
2005-12-28 12:33:18 +00:00
|
|
|
break;
|
2006-01-25 01:29:23 +00:00
|
|
|
#ifndef __APPLE__
|
2006-01-09 14:03:13 +00:00
|
|
|
case 2:
|
|
|
|
// Running as a CPDNBBC client.
|
2006-01-19 12:22:22 +00:00
|
|
|
m_strApplicationName = wxT("The BOINC Manager for the BBC Climate Change Experiment");
|
2006-01-24 11:27:26 +00:00
|
|
|
m_iconApplicationIcon = wxIcon(cpdnbbc16_xpm);
|
|
|
|
m_bitmapApplicationLogo = wxBitmap(cpdnbbc32_xpm);
|
2006-01-09 14:03:13 +00:00
|
|
|
m_strCompanyName = wxT("ClimatePrediction.net");
|
2006-01-27 01:06:03 +00:00
|
|
|
m_strCompanyWebsite = wxT("http://bbc.cpdn.org/");
|
2006-01-15 12:10:42 +00:00
|
|
|
m_strProjectName = wxT("BBC Climate Change Experiment");
|
2006-01-19 12:22:22 +00:00
|
|
|
m_bDefaultTabSpecified = true;
|
|
|
|
m_iDefaultTab = ID_LIST_WORKVIEW - ID_LIST_BASE;
|
|
|
|
m_strAPWizardTitle = _("Start Project");
|
2006-01-24 11:27:26 +00:00
|
|
|
m_bitmapAPWizardLogo = wxBitmap(cpdnbbcapwizard_xpm);
|
2006-01-15 12:10:42 +00:00
|
|
|
m_strAPWizardAccountInfoText =
|
2006-01-27 01:06:03 +00:00
|
|
|
_("Please enter an email address and password. You will need your email\n"
|
|
|
|
"address if you want to change your account options or use our message\n"
|
|
|
|
"boards.\n"
|
2006-01-24 11:27:26 +00:00
|
|
|
"\n"
|
2006-01-25 11:58:02 +00:00
|
|
|
"We will send you occasional emails. You can stop these at any time.\n"
|
2006-01-27 01:06:03 +00:00
|
|
|
"We will not pass your email address on to others.");
|
2006-01-15 12:10:42 +00:00
|
|
|
m_strAPWizardCompletionTitle =
|
2006-01-19 12:22:22 +00:00
|
|
|
_("Project Started");
|
|
|
|
m_strAPWizardCompletionBrandedMessage =
|
|
|
|
_("Congratulations, you have now successfully started your Climate\n"
|
2006-01-27 01:06:03 +00:00
|
|
|
"Change Experiment.");
|
2006-01-15 12:10:42 +00:00
|
|
|
m_strAPWizardCompletionMessage =
|
2006-01-24 11:27:26 +00:00
|
|
|
_("Click finish to exit. You will be taken to a web page which tells\n"
|
2006-01-27 01:06:03 +00:00
|
|
|
"you more about your model.");
|
2006-01-15 12:10:42 +00:00
|
|
|
m_strAMWizardTitle = wxEmptyString;
|
2006-01-24 11:27:26 +00:00
|
|
|
m_bitmapAMWizardLogo = wxBitmap(cpdnbbcapwizard_xpm);
|
2006-02-01 12:18:10 +00:00
|
|
|
m_strAMWizardAccountInfoText = wxEmptyString;
|
2006-01-09 14:03:13 +00:00
|
|
|
m_strAMWizardAttachMessage = wxEmptyString;
|
2006-01-23 11:30:25 +00:00
|
|
|
m_strExitMessage =
|
|
|
|
_("This will shut down your experiment until it restarts automatically\n"
|
|
|
|
"following your user preferences. Close window to close the manager\n"
|
|
|
|
"without stopping the experiment.");
|
2006-01-09 14:03:13 +00:00
|
|
|
break;
|
2006-01-25 01:29:23 +00:00
|
|
|
#endif __APPLE__
|
2005-12-28 12:33:18 +00:00
|
|
|
default:
|
|
|
|
// Running in native mode without any branding
|
|
|
|
m_strApplicationName = wxT("BOINC Manager");
|
|
|
|
m_iconApplicationIcon = wxIcon(boinc_xpm);
|
|
|
|
m_bitmapApplicationLogo = wxBitmap(boincsm_xpm);
|
|
|
|
m_strCompanyName = wxT("Space Sciences Laboratory, U.C. Berkeley");
|
|
|
|
m_strCompanyWebsite = wxT("http://boinc.berkeley.edu/");
|
|
|
|
m_strProjectName = wxT("BOINC");
|
2006-01-19 12:22:22 +00:00
|
|
|
m_bDefaultTabSpecified = false;
|
|
|
|
m_iDefaultTab = 0;
|
2006-01-15 12:10:42 +00:00
|
|
|
m_strAPWizardTitle = wxEmptyString;
|
2006-01-25 11:58:02 +00:00
|
|
|
m_bitmapAPWizardLogo = wxNullBitmap;
|
2006-01-15 12:10:42 +00:00
|
|
|
m_strAPWizardCompletionTitle = wxEmptyString;
|
2006-01-19 12:22:22 +00:00
|
|
|
m_strAPWizardCompletionBrandedMessage = wxEmptyString;
|
2006-01-15 12:10:42 +00:00
|
|
|
m_strAPWizardCompletionMessage = wxEmptyString;
|
|
|
|
m_strAMWizardTitle = wxEmptyString;
|
|
|
|
m_strAPWizardAccountInfoText = wxEmptyString;
|
2006-01-25 11:58:02 +00:00
|
|
|
m_bitmapAMWizardLogo = wxNullBitmap;
|
2006-02-01 12:18:10 +00:00
|
|
|
m_strAMWizardAccountInfoText = wxEmptyString;
|
2006-01-06 10:50:59 +00:00
|
|
|
m_strAMWizardAttachMessage = wxEmptyString;
|
2006-01-23 11:30:25 +00:00
|
|
|
m_strExitMessage = wxEmptyString;
|
2005-12-28 12:33:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
bool CBOINCGUIApp::OnInit() {
|
2006-01-23 08:47:05 +00:00
|
|
|
|
|
|
|
// Setup variables with default values
|
|
|
|
m_bBOINCStartedByManager = false;
|
|
|
|
m_bFrameVisible = true;
|
|
|
|
m_lBOINCCoreProcessId = 0;
|
|
|
|
#ifdef __WXMSW__
|
|
|
|
m_hBOINCCoreProcess = NULL;
|
|
|
|
m_hClientLibraryDll = NULL;
|
|
|
|
#endif
|
|
|
|
m_strDefaultWindowStation = wxT("");
|
|
|
|
m_strDefaultDesktop = wxT("");
|
|
|
|
m_strDefaultDisplay = wxT("");
|
|
|
|
|
2006-01-23 13:31:57 +00:00
|
|
|
// Setup application and company information
|
|
|
|
SetAppName(wxT("BOINC Manager"));
|
|
|
|
SetVendorName(wxT("Space Sciences Laboratory, U.C. Berkeley"));
|
|
|
|
|
|
|
|
|
|
|
|
// Initialize the configuration storage module
|
|
|
|
m_pConfig = new wxConfig(GetAppName());
|
|
|
|
wxConfigBase::Set(m_pConfig);
|
|
|
|
wxASSERT(m_pConfig);
|
|
|
|
|
|
|
|
m_pConfig->SetPath(wxT("/"));
|
|
|
|
|
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
|
2006-01-23 13:16:28 +00:00
|
|
|
|
|
|
|
// Setup the branding scheme
|
2006-01-23 13:31:57 +00:00
|
|
|
// NOTE: SetAppName(), SetVendorName(), and the creation of the m_pConfig
|
|
|
|
// variable need to be done before the branding object can be used on
|
|
|
|
// any platform other than the Mac.
|
2006-01-23 13:16:28 +00:00
|
|
|
m_pBranding = new CBrandingScheme;
|
|
|
|
wxASSERT(m_pBranding);
|
|
|
|
|
|
|
|
m_pBranding->OnInit(m_pConfig);
|
|
|
|
|
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.
|
2006-01-21 12:42:04 +00:00
|
|
|
strDirectory = wxT("/Library/Application Support/");
|
2005-03-25 12:23:30 +00:00
|
|
|
#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
|
2006-01-21 12:42:04 +00:00
|
|
|
strDirectory += m_pBranding->GetProjectName();
|
|
|
|
strDirectory += wxT(" Data");
|
2005-04-26 15:03:51 +00:00
|
|
|
if (! wxDirExists(strDirectory))
|
2006-01-21 12:42:04 +00:00
|
|
|
success = wxMkdir(m_pBranding->GetProjectName() + wxT(" Data"), 0777); // Does nothing if dir exists
|
2005-04-07 07:04:50 +00:00
|
|
|
success = ::wxSetWorkingDirectory(strDirectory);
|
2005-03-25 12:23:30 +00:00
|
|
|
// wxChar *wd = wxGetWorkingDirectory(buf, 1000); // For debugging
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // __WXMAC__
|
|
|
|
|
2006-01-23 08:47:05 +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
|
|
|
// 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"));
|
2005-12-28 12:33:18 +00:00
|
|
|
m_pLocale->AddCatalog(wxT("BOINC Manager"));
|
2004-04-10 09:11:03 +00:00
|
|
|
|
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
|
2005-12-28 12:33:18 +00:00
|
|
|
m_pFrame = new CMainFrame(
|
|
|
|
m_pBranding->GetApplicationName(),
|
|
|
|
m_pBranding->GetApplicationIcon()
|
|
|
|
);
|
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
|
2005-10-01 08:56:37 +00:00
|
|
|
#if defined(__WXMSW__) || defined(__WXMAC__)
|
2005-12-28 12:33:18 +00:00
|
|
|
m_pTaskBarIcon = new CTaskBarIcon(
|
|
|
|
m_pBranding->GetApplicationName(),
|
|
|
|
m_pBranding->GetApplicationIcon()
|
|
|
|
);
|
2005-04-27 06:55:28 +00:00
|
|
|
wxASSERT(m_pTaskBarIcon);
|
2005-10-01 08:56:37 +00:00
|
|
|
#endif
|
2005-03-25 12:23:30 +00:00
|
|
|
#ifdef __WXMAC__
|
2006-01-10 13:09:24 +00:00
|
|
|
m_pMacSystemMenu = new CMacSystemMenu(
|
|
|
|
m_pBranding->GetApplicationName(),
|
|
|
|
m_pBranding->GetApplicationIcon()
|
|
|
|
);
|
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
|
2006-01-23 08:47:05 +00:00
|
|
|
ClientLibraryStartup();
|
2004-12-14 02:50:16 +00:00
|
|
|
|
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
|
2006-01-23 08:47:05 +00:00
|
|
|
ClientLibraryShutdown();
|
2004-12-14 02:50:16 +00:00
|
|
|
|
2005-10-01 08:56:37 +00:00
|
|
|
#if defined(__WXMSW__) || defined(__WXMAC__)
|
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-10-01 08:56:37 +00:00
|
|
|
#endif
|
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
|
|
|
|
2006-01-06 10:50:59 +00:00
|
|
|
if (m_pBranding) {
|
|
|
|
delete m_pBranding;
|
|
|
|
}
|
|
|
|
|
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];
|
2005-12-06 11:39:00 +00:00
|
|
|
wxChar *argv[3];
|
2005-03-11 13:08:52 +00:00
|
|
|
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-12-06 11:39:00 +00:00
|
|
|
#if 0 // The Mac version of wxExecute(wxString& ...) crashes if there is a space in the path
|
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-12-06 11:39:00 +00:00
|
|
|
m_lBOINCCoreProcessId = ::wxExecute(strExecute);
|
|
|
|
#else // Use wxExecute(wxChar **argv ...) instead of wxExecute(wxString& ...)
|
|
|
|
strcat(buf, "/Contents/Resources/boinc");
|
|
|
|
argv[0] = buf;
|
|
|
|
argv[1] = "-redirectio";
|
|
|
|
argv[2] = NULL;
|
|
|
|
m_lBOINCCoreProcessId = ::wxExecute(argv);
|
|
|
|
#endif
|
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-12-06 11:39:00 +00:00
|
|
|
m_lBOINCCoreProcessId = ::wxExecute(strExecute);
|
2005-03-11 13:08:52 +00:00
|
|
|
|
|
|
|
#endif // ! __WXMAC__
|
|
|
|
|
|
|
|
#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
|
|
|
|
2006-01-23 08:47:05 +00:00
|
|
|
int CBOINCGUIApp::ClientLibraryStartup() {
|
2004-12-14 02:50:16 +00:00
|
|
|
#ifdef __WXMSW__
|
|
|
|
// load dll and start idle detection
|
2006-01-23 08:47:05 +00:00
|
|
|
m_hClientLibraryDll = LoadLibrary("boinc.dll");
|
|
|
|
if(m_hClientLibraryDll) {
|
|
|
|
pfnClientLibraryStartup fn;
|
|
|
|
fn = (pfnClientLibraryStartup)GetProcAddress(m_hClientLibraryDll, wxT("ClientLibraryStartup"));
|
2005-04-07 07:04:50 +00:00
|
|
|
if(!fn) {
|
2006-01-23 08:47:05 +00:00
|
|
|
FreeLibrary(m_hClientLibraryDll);
|
|
|
|
m_hClientLibraryDll = NULL;
|
2004-12-14 02:50:16 +00:00
|
|
|
return -1;
|
2005-04-07 07:04:50 +00:00
|
|
|
} else {
|
|
|
|
if(!fn()) {
|
2006-01-23 08:47:05 +00:00
|
|
|
FreeLibrary(m_hClientLibraryDll);
|
|
|
|
m_hClientLibraryDll = NULL;
|
2004-12-14 02:50:16 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-01-23 08:47:05 +00:00
|
|
|
int CBOINCGUIApp::ClientLibraryShutdown() {
|
2004-12-14 02:50:16 +00:00
|
|
|
#ifdef __WXMSW__
|
2006-01-23 08:47:05 +00:00
|
|
|
if(m_hClientLibraryDll) {
|
|
|
|
pfnClientLibraryShutdown fn;
|
|
|
|
fn = (pfnClientLibraryShutdown)GetProcAddress(m_hClientLibraryDll, wxT("ClientLibraryShutdown"));
|
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;
|
|
|
|
}
|
2006-01-23 08:47:05 +00:00
|
|
|
FreeLibrary(m_hClientLibraryDll);
|
|
|
|
m_hClientLibraryDll = NULL;
|
2005-01-07 07:32:23 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-01-23 21:48:45 +00:00
|
|
|
int CBOINCGUIApp::IsNetworkAlive(long* lpdwFlags) {
|
2006-01-23 08:47:05 +00:00
|
|
|
#ifdef __WXMSW__
|
|
|
|
if(m_hClientLibraryDll) {
|
|
|
|
pfnBOINCIsNetworkAlive fn;
|
|
|
|
fn = (pfnBOINCIsNetworkAlive)GetProcAddress(m_hClientLibraryDll, wxT("BOINCIsNetworkAlive"));
|
|
|
|
if(fn) {
|
|
|
|
return fn(lpdwFlags);
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int CBOINCGUIApp::IsNetworkAlwaysOnline() {
|
|
|
|
#ifdef __WXMSW__
|
|
|
|
if(m_hClientLibraryDll) {
|
|
|
|
pfnBOINCIsNetworkAlwaysOnline fn;
|
|
|
|
fn = (pfnBOINCIsNetworkAlwaysOnline)GetProcAddress(m_hClientLibraryDll, wxT("BOINCIsNetworkAlwaysOnline"));
|
|
|
|
if(fn) {
|
|
|
|
return fn();
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int CBOINCGUIApp::UpdateSystemIdleDetection() {
|
2005-01-07 07:32:23 +00:00
|
|
|
#ifdef __WXMSW__
|
2006-01-23 08:47:05 +00:00
|
|
|
if (m_hClientLibraryDll) {
|
|
|
|
pfnBOINCGetIdleTickCount fn;
|
|
|
|
fn = (pfnBOINCGetIdleTickCount)GetProcAddress(m_hClientLibraryDll, wxT("BOINCGetIdleTickCount"));
|
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$";
|