2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2006-04-28 12:26:19 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2008-08-06 18:36:30 +00:00
|
|
|
// Copyright (C) 2008 University of California
|
2006-04-28 12:26:19 +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-04-28 12:26:19 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2006-04-28 12:26:19 +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-04-28 12:26:19 +00:00
|
|
|
|
2005-03-30 09:56:55 +00:00
|
|
|
/*
|
|
|
|
* SetVersion.c
|
|
|
|
* boinc
|
|
|
|
*
|
|
|
|
* Created by Charlie Fenton on 3/29/05.
|
|
|
|
*
|
|
|
|
*/
|
2005-05-17 11:27:08 +00:00
|
|
|
|
|
|
|
// Set STAND_ALONE TRUE if testing as a separate applicaiton
|
|
|
|
#define STAND_ALONE 0
|
|
|
|
|
2005-03-30 09:56:55 +00:00
|
|
|
#include <stdio.h>
|
2005-05-17 11:27:08 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2006-04-28 12:26:19 +00:00
|
|
|
#include <unistd.h>
|
2005-03-30 09:56:55 +00:00
|
|
|
#include "version.h"
|
|
|
|
|
2005-05-17 11:27:08 +00:00
|
|
|
int IsFileCurrent(char* filePath);
|
|
|
|
int FixInfoPlistFile(char* myPath);
|
2006-01-21 12:42:04 +00:00
|
|
|
int FixInfoPlist_Strings(char* myPath, char* brand);
|
|
|
|
int MakeInstallerInfoPlistFile(char* myPath, char* brand);
|
2005-05-17 11:27:08 +00:00
|
|
|
|
2005-03-30 09:56:55 +00:00
|
|
|
int main(int argc, char** argv) {
|
2005-05-17 11:27:08 +00:00
|
|
|
int retval = 0, err;
|
|
|
|
|
|
|
|
#if STAND_ALONE
|
|
|
|
char myPath[1024];
|
|
|
|
getcwd(myPath, sizeof(myPath));
|
|
|
|
printf("%s\n", myPath); // For debugging
|
|
|
|
err = chdir("../");
|
|
|
|
getcwd(myPath, sizeof(myPath));
|
|
|
|
printf("%s\n", myPath); // For debugging
|
|
|
|
#endif
|
|
|
|
|
2006-01-21 12:42:04 +00:00
|
|
|
err = FixInfoPlist_Strings("./English.lproj/InfoPlist.strings", "BOINC");
|
|
|
|
if (err) retval = err;
|
2005-09-02 04:16:20 +00:00
|
|
|
err = FixInfoPlistFile("./Info.plist");
|
2005-05-17 11:27:08 +00:00
|
|
|
if (err) retval = err;
|
2005-09-02 04:16:20 +00:00
|
|
|
err = FixInfoPlistFile("./Installer-Info.plist");
|
2005-05-17 11:27:08 +00:00
|
|
|
if (err) retval = err;
|
2006-06-27 12:56:11 +00:00
|
|
|
err = FixInfoPlistFile("./PostInstall-Info.plist");
|
|
|
|
if (err) retval = err;
|
2005-09-02 04:16:20 +00:00
|
|
|
err = FixInfoPlistFile("./ScreenSaver-Info.plist");
|
2005-05-17 11:27:08 +00:00
|
|
|
if (err) retval = err;
|
2005-09-02 04:16:20 +00:00
|
|
|
err = FixInfoPlistFile("./SystemMenu-Info.plist");
|
2005-05-17 11:27:08 +00:00
|
|
|
if (err) retval = err;
|
2007-06-06 11:42:51 +00:00
|
|
|
err = FixInfoPlistFile("./Uninstaller-Info.plist");
|
|
|
|
if (err) retval = err;
|
2006-01-21 12:42:04 +00:00
|
|
|
err = MakeInstallerInfoPlistFile("./Pkg-Info.plist", "BOINC Manager");
|
2005-05-17 11:27:08 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int IsFileCurrent(char* filePath) {
|
2005-03-30 09:56:55 +00:00
|
|
|
FILE *f;
|
2005-05-17 11:27:08 +00:00
|
|
|
char *c, buf[1024];
|
|
|
|
|
|
|
|
f = fopen(filePath, "r");
|
|
|
|
if (f == 0)
|
|
|
|
return false;
|
|
|
|
for (;;) {
|
|
|
|
c = fgets(buf, sizeof(buf), f);
|
|
|
|
if (c == NULL)
|
|
|
|
break; // EOF reached without finding correct version string
|
|
|
|
c = strstr(buf, BOINC_VERSION_STRING);
|
|
|
|
if (c) {
|
|
|
|
fclose(f);
|
|
|
|
return true; // File contains current version string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
return false; // File does not contain current version string
|
|
|
|
}
|
|
|
|
|
2005-03-30 09:56:55 +00:00
|
|
|
|
2006-01-21 12:42:04 +00:00
|
|
|
int FixInfoPlist_Strings(char* myPath, char* brand) {
|
2005-05-17 11:27:08 +00:00
|
|
|
int retval = 0;
|
|
|
|
FILE *f;
|
2005-03-30 09:56:55 +00:00
|
|
|
|
2005-05-17 11:27:08 +00:00
|
|
|
if (IsFileCurrent(myPath))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
f = fopen(myPath, "w");
|
2005-03-30 09:56:55 +00:00
|
|
|
if (f)
|
|
|
|
{
|
|
|
|
fprintf(f, "/* Localized versions of Info.plist keys */\n\n");
|
2006-01-21 12:42:04 +00:00
|
|
|
fprintf(f, "CFBundleName = \"%s\";\n", brand);
|
|
|
|
fprintf(f, "CFBundleShortVersionString = \"%s version %s\";\n", brand, BOINC_VERSION_STRING);
|
2009-06-11 10:36:23 +00:00
|
|
|
fprintf(f, "CFBundleGetInfoString = \"%s version %s, Copyright 2009 University of California.\";\n", brand, BOINC_VERSION_STRING);
|
2006-04-28 12:26:19 +00:00
|
|
|
fflush(f);
|
2005-03-30 09:56:55 +00:00
|
|
|
retval = fclose(f);
|
|
|
|
}
|
2005-05-17 11:27:08 +00:00
|
|
|
else {
|
|
|
|
puts("Error updating version number in file InfoPlist.strings\n");
|
2005-03-30 09:56:55 +00:00
|
|
|
retval = -1;
|
2005-05-17 11:27:08 +00:00
|
|
|
}
|
2005-03-30 09:56:55 +00:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-05-17 11:27:08 +00:00
|
|
|
int FixInfoPlistFile(char* myPath) {
|
|
|
|
int retval = 0;
|
|
|
|
FILE *fin = NULL, *fout = NULL;
|
|
|
|
char *c, a, buf[1024];
|
|
|
|
|
|
|
|
if (IsFileCurrent(myPath))
|
|
|
|
return 0;
|
|
|
|
|
2006-04-28 12:26:19 +00:00
|
|
|
rename(myPath, "./temp");
|
|
|
|
// sprintf(buf, "mv -f %s temp", myPath);
|
|
|
|
// retval = system(buf);
|
|
|
|
|
|
|
|
fin = fopen("temp", "r");
|
2005-05-17 11:27:08 +00:00
|
|
|
if (fin == NULL)
|
|
|
|
goto bail;
|
|
|
|
|
2006-04-28 12:26:19 +00:00
|
|
|
fout = fopen(myPath, "w");
|
2005-05-17 11:27:08 +00:00
|
|
|
if (fout == NULL) {
|
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy everything up to version number
|
|
|
|
for (;;) {
|
|
|
|
c = fgets(buf, sizeof(buf), fin);
|
|
|
|
if (c == NULL)
|
|
|
|
goto bail; // EOF
|
|
|
|
c = strstr(buf, "CFBundleVersion</key>");
|
|
|
|
if (c)
|
|
|
|
break; // Found "CFBundleVersion</key>"
|
|
|
|
fputs(buf, fout);
|
|
|
|
}
|
|
|
|
|
|
|
|
c = strstr(buf, "<string>");
|
|
|
|
if (c == NULL) {
|
|
|
|
fputs(buf, fout);
|
|
|
|
c = fgets(buf, sizeof(buf), fin);
|
|
|
|
if (c == NULL)
|
|
|
|
goto bail; // EOF
|
|
|
|
c = strstr(buf, "<string>");
|
|
|
|
if (c == NULL)
|
|
|
|
goto bail; // "CFBundleVersion</key>" not followed by "<string>"
|
|
|
|
}
|
|
|
|
|
|
|
|
a = *(c+8);
|
|
|
|
*(c+8) = '\0'; // Put terminator after "<string>"
|
|
|
|
fputs(buf, fout); // Copy up to end of "<string>"
|
|
|
|
fputs(BOINC_VERSION_STRING, fout); // Write the current version number
|
|
|
|
*(c+8) = a; // Undo terminator we inserted
|
|
|
|
c = strstr(buf, "</string>"); // Skip over old version number in input
|
|
|
|
fputs(c, fout); // Copy rest of input line
|
|
|
|
|
|
|
|
// Copy rest of file
|
|
|
|
for (;;) {
|
|
|
|
c = fgets(buf, sizeof(buf), fin);
|
|
|
|
if (c == NULL)
|
|
|
|
break; // EOF
|
|
|
|
fputs(buf, fout);
|
|
|
|
}
|
2005-03-30 09:56:55 +00:00
|
|
|
|
2005-05-17 11:27:08 +00:00
|
|
|
fclose(fin);
|
2006-04-28 12:26:19 +00:00
|
|
|
fflush(fout);
|
2005-05-17 11:27:08 +00:00
|
|
|
fclose(fout);
|
|
|
|
|
2006-04-28 12:26:19 +00:00
|
|
|
unlink("temp");
|
2005-05-17 11:27:08 +00:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
bail:
|
|
|
|
if (fin)
|
|
|
|
fclose(fin);
|
|
|
|
if (fout)
|
|
|
|
fclose(fout);
|
|
|
|
|
2006-04-28 12:26:19 +00:00
|
|
|
rename("./temp", myPath);
|
|
|
|
// sprintf(buf, "mv -f temp %s", myPath);
|
|
|
|
// retval = system(buf);
|
|
|
|
|
2005-05-17 11:27:08 +00:00
|
|
|
printf("Error updating version number in file %s\n", myPath);
|
|
|
|
return -1;
|
|
|
|
}
|
2005-09-02 04:16:20 +00:00
|
|
|
|
|
|
|
|
2006-01-21 12:42:04 +00:00
|
|
|
int MakeInstallerInfoPlistFile(char* myPath, char* brand) {
|
2005-09-02 04:16:20 +00:00
|
|
|
int retval = 0;
|
|
|
|
FILE *f;
|
|
|
|
|
|
|
|
if (IsFileCurrent(myPath))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
f = fopen(myPath, "w");
|
|
|
|
if (f)
|
|
|
|
{
|
|
|
|
fprintf(f, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
|
|
|
|
fprintf(f, "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n");
|
|
|
|
fprintf(f, "<plist version=\"1.0\">\n<dict>\n");
|
|
|
|
fprintf(f, "\t<key>CFBundleGetInfoString</key>\n");
|
2006-01-21 12:42:04 +00:00
|
|
|
fprintf(f, "\t<string>%s %s</string>\n", brand, BOINC_VERSION_STRING);
|
2005-09-02 04:16:20 +00:00
|
|
|
fprintf(f, "\t<key>CFBundleIdentifier</key>\n\t<string>edu.berkeley.boinc</string>\n");
|
|
|
|
fprintf(f, "\t<key>CFBundleShortVersionString</key>\n");
|
|
|
|
fprintf(f, "\t<string>%s</string>\n", BOINC_VERSION_STRING);
|
|
|
|
fprintf(f, "\t<key>IFPkgFlagAllowBackRev</key>\n\t<integer>1</integer>\n");
|
|
|
|
fprintf(f, "\t<key>IFPkgFlagAuthorizationAction</key>\n\t<string>AdminAuthorization</string>\n");
|
|
|
|
fprintf(f, "\t<key>IFPkgFlagDefaultLocation</key>\n\t<string>/</string>\n");
|
|
|
|
fprintf(f, "\t<key>IFPkgFlagFollowLinks</key>\n\t<integer>0</integer>\n");
|
|
|
|
fprintf(f, "\t<key>IFPkgFlagInstallFat</key>\n\t<integer>0</integer>\n");
|
|
|
|
fprintf(f, "\t<key>IFPkgFlagInstalledSize</key>\n\t<integer>6680</integer>\n");
|
|
|
|
fprintf(f, "\t<key>IFPkgFlagIsRequired</key>\n\t<integer>0</integer>\n");
|
|
|
|
fprintf(f, "\t<key>IFPkgFlagOverwritePermissions</key>\n\t<integer>0</integer>\n");
|
|
|
|
fprintf(f, "\t<key>IFPkgFlagRelocatable</key>\n\t<integer>0</integer>\n");
|
2006-06-23 04:20:32 +00:00
|
|
|
fprintf(f, "\t<key>IFPkgFlagRestartAction</key>\n\t<string>RequiredLogout</string>\n");
|
2005-09-02 04:16:20 +00:00
|
|
|
fprintf(f, "\t<key>IFPkgFlagRootVolumeOnly</key>\n\t<integer>1</integer>\n");
|
|
|
|
fprintf(f, "\t<key>IFPkgFlagUpdateInstalledLanguages</key>\n\t<integer>0</integer>\n");
|
|
|
|
fprintf(f, "\t<key>IFPkgFormatVersion</key>\n\t<real>0.10000000149011612</real>\n");
|
|
|
|
fprintf(f, "</dict>\n</plist>\n");
|
|
|
|
|
2006-04-28 12:26:19 +00:00
|
|
|
fflush(f);
|
2005-09-02 04:16:20 +00:00
|
|
|
retval = fclose(f);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
puts("Error creating file Pkg-Info.plist\n");
|
|
|
|
retval = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-13 09:01:56 +00:00
|
|
|
const char *BOINC_RCSID_9263a2dc22="$Id$";
|