2008-08-06 18:36:30 +00:00
|
|
|
|
// This file is part of BOINC.
|
2006-06-27 12:56:11 +00:00
|
|
|
|
// http://boinc.berkeley.edu
|
2008-08-06 18:36:30 +00:00
|
|
|
|
// Copyright (C) 2008 University of California
|
2006-06-27 12:56:11 +00:00
|
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
|
// BOINC 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 3 of the License, or (at your option) any later version.
|
2006-06-27 12:56:11 +00:00
|
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2006-06-27 12:56:11 +00:00
|
|
|
|
// 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.
|
|
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2006-06-27 12:56:11 +00:00
|
|
|
|
|
|
|
|
|
/* Installer.cpp */
|
|
|
|
|
|
|
|
|
|
#define CREATE_LOG 1 /* for debugging */
|
|
|
|
|
|
|
|
|
|
#include <Carbon/Carbon.h>
|
|
|
|
|
#include <grp.h>
|
|
|
|
|
|
|
|
|
|
#include <unistd.h> // getlogin
|
|
|
|
|
#include <sys/types.h> // getpwname, getpwuid, getuid
|
|
|
|
|
#include <pwd.h> // getpwname, getpwuid, getuid
|
|
|
|
|
#include <sys/wait.h> // waitpid
|
|
|
|
|
#include <dirent.h>
|
|
|
|
|
#include <sys/param.h> // for MAXPATHLEN
|
2012-01-06 10:44:53 +00:00
|
|
|
|
#include <sys/stat.h>
|
2006-06-27 12:56:11 +00:00
|
|
|
|
|
2013-06-04 07:55:57 +00:00
|
|
|
|
#include "str_util.h"
|
2013-06-07 04:27:05 +00:00
|
|
|
|
#include "str_replace.h"
|
2013-07-02 09:08:21 +00:00
|
|
|
|
#include "translate.h"
|
2006-06-27 12:56:11 +00:00
|
|
|
|
|
|
|
|
|
#define boinc_master_user_name "boinc_master"
|
|
|
|
|
#define boinc_master_group_name "boinc_master"
|
|
|
|
|
#define boinc_project_user_name "boinc_project"
|
|
|
|
|
#define boinc_project_group_name "boinc_project"
|
|
|
|
|
|
|
|
|
|
void Initialize(void); /* function prototypes */
|
2011-12-02 13:11:21 +00:00
|
|
|
|
Boolean IsUserMemberOfGroup(const char *userName, const char *groupName);
|
2013-06-11 12:22:12 +00:00
|
|
|
|
Boolean IsRestartNeeded();
|
2013-07-02 09:08:21 +00:00
|
|
|
|
static void GetPreferredLanguages(char * pkgPath);
|
|
|
|
|
static void LoadPreferredLanguages();
|
|
|
|
|
static void ShowMessage(const char *format, ...);
|
2006-06-27 12:56:11 +00:00
|
|
|
|
static OSErr QuitAppleEventHandler(const AppleEvent *appleEvt, AppleEvent* reply, UInt32 refcon);
|
|
|
|
|
void print_to_log_file(const char *format, ...);
|
|
|
|
|
void strip_cr(char *buf);
|
|
|
|
|
|
2013-06-14 11:50:06 +00:00
|
|
|
|
// We can't use translation because the translation catalogs
|
|
|
|
|
// have not yet been installed when this application is run.
|
|
|
|
|
#define MAX_LANGUAGES_TO_TRY 5
|
|
|
|
|
|
|
|
|
|
static char * Catalog_Name = (char *)"BOINC-Setup";
|
2013-07-02 09:08:21 +00:00
|
|
|
|
static char * Catalogs_Dir = (char *)"/tmp/BOINC_PAX/Library/Application Support/BOINC Data/locale/";
|
2013-06-04 00:57:09 +00:00
|
|
|
|
|
2006-06-27 12:56:11 +00:00
|
|
|
|
Boolean gQuitFlag = false; /* global */
|
|
|
|
|
|
2013-06-11 12:22:12 +00:00
|
|
|
|
#if 0
|
2011-12-02 13:11:21 +00:00
|
|
|
|
CFStringRef valueRestartRequired = CFSTR("RequiredRestart");
|
|
|
|
|
CFStringRef valueLogoutRequired = CFSTR("RequiredLogout");
|
|
|
|
|
CFStringRef valueNoRestart = CFSTR("NoRestart");
|
2013-06-11 12:22:12 +00:00
|
|
|
|
#endif
|
2011-12-02 13:11:21 +00:00
|
|
|
|
|
2006-06-27 12:56:11 +00:00
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
|
{
|
2013-06-11 12:22:12 +00:00
|
|
|
|
char pkgPath[MAXPATHLEN], pkgRestartPath[MAXPATHLEN];
|
|
|
|
|
char infoPlistPath[MAXPATHLEN];
|
|
|
|
|
char MetaPkgPath[MAXPATHLEN], MetaPkgRestartPath[MAXPATHLEN];
|
2007-10-26 10:01:28 +00:00
|
|
|
|
char brand[64], s[256];
|
2006-06-27 12:56:11 +00:00
|
|
|
|
char *p;
|
2013-07-02 10:53:02 +00:00
|
|
|
|
ProcessSerialNumber ourPSN;
|
2006-06-27 12:56:11 +00:00
|
|
|
|
FSRef ourFSRef;
|
2007-10-26 10:01:28 +00:00
|
|
|
|
long response;
|
2006-06-27 12:56:11 +00:00
|
|
|
|
OSStatus err = noErr;
|
2012-01-06 10:44:53 +00:00
|
|
|
|
struct stat stat_buf;
|
2013-06-11 12:22:12 +00:00
|
|
|
|
Boolean restartNeeded = true;
|
|
|
|
|
FILE *restartNeededFile;
|
2011-12-02 13:11:21 +00:00
|
|
|
|
|
2006-06-27 12:56:11 +00:00
|
|
|
|
Initialize();
|
|
|
|
|
|
|
|
|
|
// Get the full path to Installer package inside this application's bundle
|
|
|
|
|
err = GetCurrentProcess (&ourPSN);
|
|
|
|
|
if (err == noErr)
|
|
|
|
|
err = GetProcessBundleLocation(&ourPSN, &ourFSRef);
|
|
|
|
|
|
|
|
|
|
if (err == noErr)
|
|
|
|
|
err = FSRefMakePath (&ourFSRef, (UInt8*)pkgPath, sizeof(pkgPath));
|
|
|
|
|
|
|
|
|
|
strlcpy(infoPlistPath, pkgPath, sizeof(infoPlistPath));
|
|
|
|
|
|
|
|
|
|
strlcat(pkgPath, "/Contents/Resources/", sizeof(pkgPath));
|
|
|
|
|
|
|
|
|
|
// To allow for branding, assume name of installer package inside bundle corresponds to name of this application
|
|
|
|
|
p = strrchr(infoPlistPath, '/'); // Point to name of this application (e.g., "BOINC Installer.app")
|
|
|
|
|
if (p == NULL)
|
|
|
|
|
p = infoPlistPath - 1;
|
2007-10-26 10:01:28 +00:00
|
|
|
|
strlcpy(brand, p+1, sizeof(brand));
|
2006-06-27 12:56:11 +00:00
|
|
|
|
strlcat(pkgPath, p+1, sizeof(pkgPath));
|
2007-10-26 10:01:28 +00:00
|
|
|
|
p = strrchr(pkgPath, ' '); // Strip off last space character and everything following
|
2006-06-27 12:56:11 +00:00
|
|
|
|
if (p)
|
|
|
|
|
*p = '\0';
|
|
|
|
|
|
2011-12-02 16:59:37 +00:00
|
|
|
|
p = strstr(brand, " Installer.app"); // Strip off trailing " Installer.app"
|
|
|
|
|
if (p)
|
|
|
|
|
*p = '\0';
|
|
|
|
|
|
2012-01-06 10:44:53 +00:00
|
|
|
|
strlcpy(MetaPkgPath, pkgPath, sizeof(MetaPkgPath));
|
|
|
|
|
strlcat(MetaPkgPath, "+VirtualBox.mpkg", sizeof(MetaPkgPath));
|
2013-06-11 12:22:12 +00:00
|
|
|
|
|
|
|
|
|
strlcpy(MetaPkgRestartPath, pkgPath, sizeof(MetaPkgRestartPath));
|
2013-06-11 12:40:44 +00:00
|
|
|
|
strlcat(MetaPkgRestartPath, " + VirtualBox.mpkg", sizeof(MetaPkgRestartPath));
|
2013-06-11 12:22:12 +00:00
|
|
|
|
|
|
|
|
|
strlcpy(pkgRestartPath, pkgPath, sizeof(MetaPkgPath));
|
|
|
|
|
strlcat(pkgRestartPath, ".mpkg", sizeof(pkgPath));
|
|
|
|
|
|
2012-01-06 10:44:53 +00:00
|
|
|
|
strlcat(pkgPath, ".pkg", sizeof(pkgPath));
|
2007-10-26 10:01:28 +00:00
|
|
|
|
err = Gestalt(gestaltSystemVersion, &response);
|
|
|
|
|
if (err != noErr)
|
|
|
|
|
return err;
|
|
|
|
|
|
2013-07-02 09:08:21 +00:00
|
|
|
|
GetPreferredLanguages(pkgPath);
|
|
|
|
|
|
2009-12-04 14:39:35 +00:00
|
|
|
|
if (response < 0x1040) {
|
2013-07-02 09:08:21 +00:00
|
|
|
|
LoadPreferredLanguages();
|
2007-10-26 10:01:28 +00:00
|
|
|
|
::SetFrontProcess(&ourPSN);
|
|
|
|
|
p = strrchr(brand, ' '); // Strip off last space character and everything following
|
|
|
|
|
if (p)
|
|
|
|
|
*p = '\0';
|
2013-07-02 09:08:21 +00:00
|
|
|
|
ShowMessage((char *)_("Sorry, this version of %s requires system 10.4 or higher."), brand);
|
2007-10-26 10:01:28 +00:00
|
|
|
|
|
2013-07-02 10:53:02 +00:00
|
|
|
|
} else {
|
2007-10-26 10:01:28 +00:00
|
|
|
|
|
2013-07-02 10:53:02 +00:00
|
|
|
|
// Remove previous installer package receipt so we can run installer again
|
|
|
|
|
// (affects only older versions of OS X and fixes a bug in those versions)
|
|
|
|
|
// "rm -rf /Library/Receipts/GridRepublic.pkg"
|
|
|
|
|
sprintf(s, "rm -rf \"/Library/Receipts/%s.pkg\"", brand);
|
|
|
|
|
system (s);
|
2007-10-26 10:01:28 +00:00
|
|
|
|
|
2013-07-02 10:53:02 +00:00
|
|
|
|
restartNeeded = IsRestartNeeded();
|
|
|
|
|
|
|
|
|
|
// Write a temp file to tell our PostInstall.app whether restart is needed
|
|
|
|
|
restartNeededFile = fopen("/tmp/BOINC_restart_flag", "w");
|
|
|
|
|
if (restartNeededFile) {
|
|
|
|
|
fputs(restartNeeded ? "1\n" : "0\n", restartNeededFile);
|
|
|
|
|
fclose(restartNeededFile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = Gestalt(gestaltSystemVersion, &response);
|
|
|
|
|
if (err != noErr)
|
|
|
|
|
return err;
|
|
|
|
|
|
|
|
|
|
if (err == noErr) {
|
|
|
|
|
if ((response < 0x1050) || stat(MetaPkgPath, &stat_buf)) { // stat() returns zero on success
|
|
|
|
|
sprintf(infoPlistPath, "open \"%s\" &", restartNeeded ? pkgRestartPath : pkgPath);
|
|
|
|
|
} else {
|
|
|
|
|
sprintf(infoPlistPath, "open \"%s\" &", restartNeeded ? MetaPkgRestartPath : MetaPkgPath);
|
|
|
|
|
}
|
|
|
|
|
system(infoPlistPath);
|
2012-01-06 10:44:53 +00:00
|
|
|
|
}
|
2006-06-27 12:56:11 +00:00
|
|
|
|
}
|
2013-07-02 10:53:02 +00:00
|
|
|
|
|
|
|
|
|
system("rm -dfR /tmp/BOINC_PAX");
|
2013-06-14 11:50:06 +00:00
|
|
|
|
|
2006-06-27 12:56:11 +00:00
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-12-02 13:11:21 +00:00
|
|
|
|
Boolean IsUserMemberOfGroup(const char *userName, const char *groupName) {
|
|
|
|
|
group *grp;
|
|
|
|
|
short i = 0;
|
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
|
|
grp = getgrnam(groupName);
|
|
|
|
|
if (!grp) {
|
|
|
|
|
printf("getgrnam(%s) failed\n", groupName);
|
|
|
|
|
fflush(stdout);
|
|
|
|
|
return false; // Group not found
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while ((p = grp->gr_mem[i]) != NULL) { // Step through all users in group admin
|
|
|
|
|
if (strcmp(p, userName) == 0) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
++i;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-06-11 12:22:12 +00:00
|
|
|
|
Boolean IsRestartNeeded()
|
2006-06-27 12:56:11 +00:00
|
|
|
|
{
|
|
|
|
|
passwd *pw = NULL;
|
|
|
|
|
group *grp = NULL;
|
|
|
|
|
gid_t boinc_master_gid = 0, boinc_project_gid = 0;
|
|
|
|
|
uid_t boinc_master_uid = 0, boinc_project_uid = 0;
|
2011-12-02 13:26:17 +00:00
|
|
|
|
OSStatus err = noErr;
|
|
|
|
|
long response;
|
2011-12-02 13:11:21 +00:00
|
|
|
|
char loginName[256];
|
2006-06-27 12:56:11 +00:00
|
|
|
|
|
|
|
|
|
grp = getgrnam(boinc_master_group_name);
|
|
|
|
|
if (grp == NULL)
|
2013-06-11 12:22:12 +00:00
|
|
|
|
return true; // Group boinc_master does not exist
|
2006-06-27 12:56:11 +00:00
|
|
|
|
|
|
|
|
|
boinc_master_gid = grp->gr_gid;
|
|
|
|
|
|
|
|
|
|
grp = getgrnam(boinc_project_group_name);
|
|
|
|
|
if (grp == NULL)
|
2013-06-11 12:22:12 +00:00
|
|
|
|
return true; // Group boinc_project does not exist
|
2006-06-27 12:56:11 +00:00
|
|
|
|
|
|
|
|
|
boinc_project_gid = grp->gr_gid;
|
|
|
|
|
|
|
|
|
|
pw = getpwnam(boinc_master_user_name);
|
|
|
|
|
if (pw == NULL)
|
2013-06-11 12:22:12 +00:00
|
|
|
|
return true; // User boinc_master does not exist
|
2006-06-27 12:56:11 +00:00
|
|
|
|
|
|
|
|
|
boinc_master_uid = pw->pw_uid;
|
2011-12-02 13:11:21 +00:00
|
|
|
|
|
2006-06-27 12:56:11 +00:00
|
|
|
|
if (pw->pw_gid != boinc_master_gid)
|
2013-06-11 12:22:12 +00:00
|
|
|
|
return true; // User boinc_master does not have group boinc_master as its primary group
|
2006-06-27 12:56:11 +00:00
|
|
|
|
|
|
|
|
|
pw = getpwnam(boinc_project_user_name);
|
|
|
|
|
if (pw == NULL)
|
2013-06-11 12:22:12 +00:00
|
|
|
|
return true; // User boinc_project does not exist
|
2011-12-02 15:54:46 +00:00
|
|
|
|
|
|
|
|
|
boinc_project_uid = pw->pw_uid;
|
2006-06-27 12:56:11 +00:00
|
|
|
|
|
|
|
|
|
if (pw->pw_gid != boinc_project_gid)
|
2013-06-11 12:22:12 +00:00
|
|
|
|
return true; // User boinc_project does not have group boinc_project as its primary group
|
2011-12-02 13:26:17 +00:00
|
|
|
|
|
|
|
|
|
err = Gestalt(gestaltSystemVersion, &response);
|
|
|
|
|
if ((err == noErr) && (response >= 0x1050)) {
|
|
|
|
|
if (boinc_master_gid < 501)
|
2013-06-11 12:22:12 +00:00
|
|
|
|
return true; // We will change boinc_master_gid to a value > 501
|
2011-12-02 13:26:17 +00:00
|
|
|
|
if (boinc_project_gid < 501)
|
2013-06-11 12:22:12 +00:00
|
|
|
|
return true; // We will change boinc_project_gid to a value > 501
|
2011-12-02 13:26:17 +00:00
|
|
|
|
if (boinc_master_uid < 501)
|
2013-06-11 12:22:12 +00:00
|
|
|
|
return true; // We will change boinc_master_uid to a value > 501
|
2011-12-02 13:26:17 +00:00
|
|
|
|
if (boinc_project_uid < 501)
|
2013-06-11 12:22:12 +00:00
|
|
|
|
return true; // We will change boinc_project_uid to a value > 501
|
2011-12-02 13:26:17 +00:00
|
|
|
|
}
|
2006-06-27 12:56:11 +00:00
|
|
|
|
|
2011-12-02 13:11:21 +00:00
|
|
|
|
#ifdef SANDBOX
|
|
|
|
|
strncpy(loginName, getenv("USER"), sizeof(loginName)-1);
|
|
|
|
|
if (loginName[0]) {
|
|
|
|
|
if (IsUserMemberOfGroup(loginName, boinc_master_group_name)) {
|
2013-06-11 12:22:12 +00:00
|
|
|
|
return false; // Logged in user is already a member of group boinc_master
|
2011-12-02 13:11:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif // SANDBOX
|
2006-06-27 12:56:11 +00:00
|
|
|
|
|
2013-06-11 12:22:12 +00:00
|
|
|
|
return true;
|
2006-06-27 12:56:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Initialize() /* Initialize some managers */
|
|
|
|
|
{
|
|
|
|
|
OSErr err;
|
|
|
|
|
|
2011-10-18 12:42:53 +00:00
|
|
|
|
// InitCursor();
|
2006-06-27 12:56:11 +00:00
|
|
|
|
|
|
|
|
|
err = AEInstallEventHandler( kCoreEventClass, kAEQuitApplication, NewAEEventHandlerUPP((AEEventHandlerProcPtr)QuitAppleEventHandler), 0, false );
|
|
|
|
|
if (err != noErr)
|
|
|
|
|
ExitToShell();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-06-14 11:50:06 +00:00
|
|
|
|
// Because language preferences are set on a per-user basis, we
|
|
|
|
|
// must get the preferred languages while set to the current
|
|
|
|
|
// user, before the Apple Installer switches us to root.
|
|
|
|
|
// So we get the preferred languages here and write them to a
|
|
|
|
|
// temporary file to be retrieved by our PostInstall app.
|
2013-07-02 09:08:21 +00:00
|
|
|
|
static void GetPreferredLanguages(char * pkgPath) {
|
2013-06-14 11:50:06 +00:00
|
|
|
|
DIR *dirp;
|
|
|
|
|
struct dirent *dp;
|
|
|
|
|
char searchPath[MAXPATHLEN];
|
2013-07-02 09:08:21 +00:00
|
|
|
|
char savedWD[MAXPATHLEN];
|
|
|
|
|
char cmd[MAXPATHLEN+64];
|
2013-06-14 11:50:06 +00:00
|
|
|
|
struct stat sbuf;
|
|
|
|
|
CFMutableArrayRef supportedLanguages;
|
|
|
|
|
CFStringRef aLanguage;
|
|
|
|
|
CFArrayRef preferredLanguages;
|
|
|
|
|
int i, j, k;
|
2013-07-02 09:08:21 +00:00
|
|
|
|
int retval;
|
2013-06-14 11:50:06 +00:00
|
|
|
|
char * language;
|
|
|
|
|
FILE *f;
|
|
|
|
|
|
2013-07-02 09:08:21 +00:00
|
|
|
|
getcwd(savedWD, sizeof(savedWD));
|
|
|
|
|
system("rm -dfR /tmp/BOINC_PAX");
|
|
|
|
|
mkdir("/tmp/BOINC_PAX", 0777);
|
|
|
|
|
chdir("/tmp/BOINC_PAX");
|
|
|
|
|
strlcpy(searchPath, pkgPath, sizeof(searchPath));
|
|
|
|
|
strlcat(searchPath, "/Contents/Archive.pax.gz", sizeof(searchPath));
|
|
|
|
|
snprintf(cmd, sizeof(cmd), "pax -r -z -f \"%s\"", searchPath);
|
|
|
|
|
retval = system(cmd);
|
|
|
|
|
chdir(savedWD);
|
|
|
|
|
if (retval) {
|
|
|
|
|
system("rm -dfR /tmp/BOINC_PAX");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-14 11:50:06 +00:00
|
|
|
|
// Create an array of all our supported languages
|
|
|
|
|
supportedLanguages = CFArrayCreateMutable(NULL, 100, NULL);
|
|
|
|
|
|
|
|
|
|
aLanguage = CFStringCreateWithCString(NULL, "en", kCFStringEncodingMacRoman);
|
|
|
|
|
CFArrayAppendValue(supportedLanguages, aLanguage);
|
2013-06-18 12:45:16 +00:00
|
|
|
|
CFRelease(aLanguage);
|
2013-06-14 11:50:06 +00:00
|
|
|
|
aLanguage = NULL;
|
|
|
|
|
|
|
|
|
|
dirp = opendir(Catalogs_Dir);
|
2013-07-02 09:08:21 +00:00
|
|
|
|
if (!dirp) goto cleanup;
|
2013-06-14 11:50:06 +00:00
|
|
|
|
while (true) {
|
|
|
|
|
dp = readdir(dirp);
|
|
|
|
|
if (dp == NULL)
|
|
|
|
|
break; // End of list
|
|
|
|
|
|
|
|
|
|
if (dp->d_name[0] == '.')
|
|
|
|
|
continue; // Ignore names beginning with '.'
|
|
|
|
|
|
|
|
|
|
strlcpy(searchPath, Catalogs_Dir, sizeof(searchPath));
|
|
|
|
|
strlcat(searchPath, dp->d_name, sizeof(searchPath));
|
|
|
|
|
strlcat(searchPath, "/", sizeof(searchPath));
|
|
|
|
|
strlcat(searchPath, Catalog_Name, sizeof(searchPath));
|
|
|
|
|
strlcat(searchPath, ".mo", sizeof(searchPath));
|
|
|
|
|
if (stat(searchPath, &sbuf) != 0) continue;
|
|
|
|
|
// printf("Adding %s to supportedLanguages array\n", dp->d_name);
|
|
|
|
|
aLanguage = CFStringCreateWithCString(NULL, dp->d_name, kCFStringEncodingMacRoman);
|
|
|
|
|
CFArrayAppendValue(supportedLanguages, aLanguage);
|
2013-06-18 12:45:16 +00:00
|
|
|
|
CFRelease(aLanguage);
|
2013-06-14 11:50:06 +00:00
|
|
|
|
aLanguage = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
closedir(dirp);
|
|
|
|
|
|
|
|
|
|
// Write a temp file to tell our PostInstall.app our preferred languages
|
|
|
|
|
f = fopen("/tmp/BOINC_preferred_languages", "w");
|
|
|
|
|
|
|
|
|
|
for (i=0; i<MAX_LANGUAGES_TO_TRY; ++i) {
|
|
|
|
|
|
|
|
|
|
preferredLanguages = CFBundleCopyLocalizationsForPreferences(supportedLanguages, NULL );
|
|
|
|
|
|
|
|
|
|
#if 0 // For testing
|
|
|
|
|
int c = CFArrayGetCount(preferredLanguages);
|
|
|
|
|
for (k=0; k<c; ++k) {
|
|
|
|
|
CFStringRef s = (CFStringRef)CFArrayGetValueAtIndex(preferredLanguages, k);
|
|
|
|
|
printf("Preferred language %u is %s\n", k, CFStringGetCStringPtr(s, kCFStringEncodingMacRoman));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
for (j=0; j<CFArrayGetCount(preferredLanguages); ++j) {
|
|
|
|
|
aLanguage = (CFStringRef)CFArrayGetValueAtIndex(preferredLanguages, j);
|
|
|
|
|
language = (char *)CFStringGetCStringPtr(aLanguage, kCFStringEncodingMacRoman);
|
|
|
|
|
if (f) {
|
|
|
|
|
fprintf(f, "%s\n", language);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Remove this language from our list of supported languages so
|
|
|
|
|
// we can get the next preferred language in order of priority
|
|
|
|
|
for (k=0; k<CFArrayGetCount(supportedLanguages); ++k) {
|
|
|
|
|
if (CFStringCompare(aLanguage, (CFStringRef)CFArrayGetValueAtIndex(supportedLanguages, k), 0) == kCFCompareEqualTo) {
|
|
|
|
|
CFArrayRemoveValueAtIndex(supportedLanguages, k);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Since the original strings are English, no
|
|
|
|
|
// further translation is needed for language en.
|
|
|
|
|
if (!strcmp(language, "en")) {
|
|
|
|
|
fclose(f);
|
2013-06-18 12:45:16 +00:00
|
|
|
|
CFRelease(preferredLanguages);
|
|
|
|
|
preferredLanguages = NULL;
|
2013-07-02 09:08:21 +00:00
|
|
|
|
goto cleanup;
|
2013-06-14 11:50:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-06-18 12:45:16 +00:00
|
|
|
|
|
|
|
|
|
CFRelease(preferredLanguages);
|
|
|
|
|
preferredLanguages = NULL;
|
|
|
|
|
|
2013-06-14 11:50:06 +00:00
|
|
|
|
}
|
2013-06-18 12:45:16 +00:00
|
|
|
|
|
2013-06-14 11:50:06 +00:00
|
|
|
|
fclose(f);
|
2013-06-18 12:45:16 +00:00
|
|
|
|
|
2013-07-02 09:08:21 +00:00
|
|
|
|
cleanup:
|
2013-06-18 12:45:16 +00:00
|
|
|
|
CFArrayRemoveAllValues(supportedLanguages);
|
|
|
|
|
CFRelease(supportedLanguages);
|
|
|
|
|
supportedLanguages = NULL;
|
2013-07-02 09:08:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void LoadPreferredLanguages(){
|
|
|
|
|
FILE *f;
|
|
|
|
|
int i;
|
|
|
|
|
char *p;
|
|
|
|
|
char language[32];
|
|
|
|
|
|
|
|
|
|
BOINCTranslationInit();
|
|
|
|
|
|
2013-07-02 10:53:02 +00:00
|
|
|
|
// GetPreferredLanguages() wrote a list of our preferred languages to a temp file
|
2013-07-02 09:08:21 +00:00
|
|
|
|
f = fopen("/tmp/BOINC_preferred_languages", "r");
|
|
|
|
|
if (!f) return;
|
|
|
|
|
|
|
|
|
|
for (i=0; i<MAX_LANGUAGES_TO_TRY; ++i) {
|
|
|
|
|
fgets(language, sizeof(language), f);
|
|
|
|
|
if (feof(f)) break;
|
|
|
|
|
language[sizeof(language)-1] = '\0'; // Guarantee a null terminator
|
|
|
|
|
p = strchr(language, '\n');
|
|
|
|
|
if (p) *p = '\0'; // Replace newline with null terminator
|
|
|
|
|
if (language[0]) {
|
|
|
|
|
if (!BOINCTranslationAddCatalog(Catalogs_Dir, language, Catalog_Name)) {
|
|
|
|
|
printf("could not load catalog for langage %s\n", language);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fclose(f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void ShowMessage(const char *format, ...) {
|
|
|
|
|
// CAUTION: vsprintf will produce undesirable results if the string
|
|
|
|
|
// contains a % character that is not a format specification!
|
|
|
|
|
// But CFString is OK!
|
|
|
|
|
|
|
|
|
|
va_list args;
|
|
|
|
|
char s[1024];
|
|
|
|
|
CFOptionFlags responseFlags;
|
|
|
|
|
ProcessSerialNumber ourProcess;
|
|
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
|
va_start(args, format);
|
|
|
|
|
vsprintf(s, format, args);
|
|
|
|
|
va_end(args);
|
|
|
|
|
#else
|
|
|
|
|
strcpy(s, format);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// If defaultButton is nil or an empty string, a default localized
|
|
|
|
|
// button title (<28>OK<4F> in English) is used.
|
|
|
|
|
|
|
|
|
|
CFStringRef myString = CFStringCreateWithCString(NULL, s, kCFStringEncodingUTF8);
|
|
|
|
|
|
|
|
|
|
::GetCurrentProcess (&ourProcess);
|
|
|
|
|
::SetFrontProcess(&ourProcess);
|
|
|
|
|
CFUserNotificationDisplayAlert(0.0, kCFUserNotificationPlainAlertLevel,
|
|
|
|
|
NULL, NULL, NULL, CFSTR(" "), myString,
|
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
|
&responseFlags);
|
|
|
|
|
|
|
|
|
|
if (myString) CFRelease(myString);
|
2013-06-14 11:50:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-06-27 12:56:11 +00:00
|
|
|
|
static OSErr QuitAppleEventHandler( const AppleEvent *appleEvt, AppleEvent* reply, UInt32 refcon )
|
|
|
|
|
{
|
|
|
|
|
gQuitFlag = true;
|
|
|
|
|
|
|
|
|
|
return noErr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// For debugging
|
|
|
|
|
void print_to_log_file(const char *format, ...) {
|
|
|
|
|
#if CREATE_LOG
|
|
|
|
|
FILE *f;
|
|
|
|
|
va_list args;
|
|
|
|
|
char buf[256];
|
|
|
|
|
time_t t;
|
2013-06-04 03:24:48 +00:00
|
|
|
|
safe_strcpy(buf, getenv("HOME"));
|
|
|
|
|
safe_strcat(buf, "/Documents/test_log.txt");
|
2006-06-27 12:56:11 +00:00
|
|
|
|
f = fopen(buf, "a");
|
|
|
|
|
if (!f) return;
|
|
|
|
|
|
|
|
|
|
// freopen(buf, "a", stdout);
|
|
|
|
|
// freopen(buf, "a", stderr);
|
|
|
|
|
|
|
|
|
|
time(&t);
|
2013-06-04 03:24:48 +00:00
|
|
|
|
safe_strcpy(buf, asctime(localtime(&t)));
|
2006-06-27 12:56:11 +00:00
|
|
|
|
strip_cr(buf);
|
|
|
|
|
|
|
|
|
|
fputs(buf, f);
|
|
|
|
|
fputs(" ", f);
|
|
|
|
|
|
|
|
|
|
va_start(args, format);
|
|
|
|
|
vfprintf(f, format, args);
|
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
|
|
fputs("\n", f);
|
|
|
|
|
fflush(f);
|
|
|
|
|
fclose(f);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if CREATE_LOG
|
|
|
|
|
void strip_cr(char *buf)
|
|
|
|
|
{
|
|
|
|
|
char *theCR;
|
|
|
|
|
|
|
|
|
|
theCR = strrchr(buf, '\n');
|
|
|
|
|
if (theCR)
|
|
|
|
|
*theCR = '\0';
|
|
|
|
|
theCR = strrchr(buf, '\r');
|
|
|
|
|
if (theCR)
|
|
|
|
|
*theCR = '\0';
|
|
|
|
|
}
|
|
|
|
|
#endif // CREATE_LOG
|