// This file is part of BOINC. // http://boinc.berkeley.edu // Copyright (C) 2008 University of California // // 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. // // BOINC 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. // // You should have received a copy of the GNU Lesser General Public License // along with BOINC. If not, see . /* * SetVersion.c * boinc * * Created by Charlie Fenton on 3/29/05. * */ // Set STAND_ALONE TRUE if testing as a separate applicaiton #define STAND_ALONE 0 #include #include #include #include #include "version.h" int IsFileCurrent(char* filePath); int FixInfoPlistFile(char* myPath); int FixInfoPlist_Strings(char* myPath, char* brand); int MakeInstallerInfoPlistFile(char* myPath, char* brand); int main(int argc, char** argv) { 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 err = FixInfoPlist_Strings("./English.lproj/InfoPlist.strings", "BOINC"); if (err) retval = err; err = FixInfoPlistFile("./Info.plist"); if (err) retval = err; err = FixInfoPlistFile("./Installer-Info.plist"); if (err) retval = err; err = FixInfoPlistFile("./PostInstall-Info.plist"); if (err) retval = err; err = FixInfoPlistFile("./ScreenSaver-Info.plist"); if (err) retval = err; err = FixInfoPlistFile("./SystemMenu-Info.plist"); if (err) retval = err; err = FixInfoPlistFile("./Uninstaller-Info.plist"); if (err) retval = err; err = MakeInstallerInfoPlistFile("./Pkg-Info.plist", "BOINC Manager"); return retval; } int IsFileCurrent(char* filePath) { FILE *f; 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 } int FixInfoPlist_Strings(char* myPath, char* brand) { int retval = 0; FILE *f; if (IsFileCurrent(myPath)) return 0; f = fopen(myPath, "w"); if (f) { fprintf(f, "/* Localized versions of Info.plist keys */\n\n"); fprintf(f, "CFBundleName = \"%s\";\n", brand); fprintf(f, "CFBundleShortVersionString = \"%s version %s\";\n", brand, BOINC_VERSION_STRING); fprintf(f, "CFBundleGetInfoString = \"%s version %s, Copyright 2009 University of California.\";\n", brand, BOINC_VERSION_STRING); fflush(f); retval = fclose(f); } else { puts("Error updating version number in file InfoPlist.strings\n"); retval = -1; } return retval; } int FixInfoPlistFile(char* myPath) { int retval = 0; FILE *fin = NULL, *fout = NULL; char *c, a, buf[1024]; if (IsFileCurrent(myPath)) return 0; rename(myPath, "./temp"); // sprintf(buf, "mv -f %s temp", myPath); // retval = system(buf); fin = fopen("temp", "r"); if (fin == NULL) goto bail; fout = fopen(myPath, "w"); 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"); if (c) break; // Found "CFBundleVersion" fputs(buf, fout); } c = strstr(buf, ""); if (c == NULL) { fputs(buf, fout); c = fgets(buf, sizeof(buf), fin); if (c == NULL) goto bail; // EOF c = strstr(buf, ""); if (c == NULL) goto bail; // "CFBundleVersion" not followed by "" } a = *(c+8); *(c+8) = '\0'; // Put terminator after "" fputs(buf, fout); // Copy up to end of "" fputs(BOINC_VERSION_STRING, fout); // Write the current version number *(c+8) = a; // Undo terminator we inserted c = strstr(buf, ""); // 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); } fclose(fin); fflush(fout); fclose(fout); unlink("temp"); return retval; bail: if (fin) fclose(fin); if (fout) fclose(fout); rename("./temp", myPath); // sprintf(buf, "mv -f temp %s", myPath); // retval = system(buf); printf("Error updating version number in file %s\n", myPath); return -1; } int MakeInstallerInfoPlistFile(char* myPath, char* brand) { int retval = 0; FILE *f; if (IsFileCurrent(myPath)) return 0; f = fopen(myPath, "w"); if (f) { fprintf(f, "\n"); fprintf(f, "\n"); fprintf(f, "\n\n"); fprintf(f, "\tCFBundleGetInfoString\n"); fprintf(f, "\t%s %s\n", brand, BOINC_VERSION_STRING); fprintf(f, "\tCFBundleIdentifier\n\tedu.berkeley.boinc\n"); fprintf(f, "\tCFBundleShortVersionString\n"); fprintf(f, "\t%s\n", BOINC_VERSION_STRING); fprintf(f, "\tIFPkgFlagAllowBackRev\n\t1\n"); fprintf(f, "\tIFPkgFlagAuthorizationAction\n\tAdminAuthorization\n"); fprintf(f, "\tIFPkgFlagDefaultLocation\n\t/\n"); fprintf(f, "\tIFPkgFlagFollowLinks\n\t0\n"); fprintf(f, "\tIFPkgFlagInstallFat\n\t0\n"); fprintf(f, "\tIFPkgFlagInstalledSize\n\t6680\n"); fprintf(f, "\tIFPkgFlagIsRequired\n\t0\n"); fprintf(f, "\tIFPkgFlagOverwritePermissions\n\t0\n"); fprintf(f, "\tIFPkgFlagRelocatable\n\t0\n"); fprintf(f, "\tIFPkgFlagRestartAction\n\tRequiredLogout\n"); fprintf(f, "\tIFPkgFlagRootVolumeOnly\n\t1\n"); fprintf(f, "\tIFPkgFlagUpdateInstalledLanguages\n\t0\n"); fprintf(f, "\tIFPkgFormatVersion\n\t0.10000000149011612\n"); fprintf(f, "\n\n"); fflush(f); retval = fclose(f); } else { puts("Error creating file Pkg-Info.plist\n"); retval = -1; } return retval; } const char *BOINC_RCSID_9263a2dc22="$Id$";