Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CFBundleShortVersionString to macOS app plist files #5209

Merged
merged 1 commit into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
173 changes: 67 additions & 106 deletions clientgui/mac/SetVersion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,21 @@

// Important: To ensure that the relevant *info.plist and *InfoPlist.strings
// files are available by the time they are needed for building a target:
// [1] include SetVersion in that target's "Target Dependencies" phase,
// [2] if a target is dependent on a file created by SetVersion, make sure
// the file is listed as an Output File for SetVersion's script phase.
// [1] include SetVersion in that target's "Target Dependencies" phase,
// [2] if a target is dependent on a file created by SetVersion, make sure
// the file is listed as an Output File for SetVersion's script phase.
// Otherwise, the build may fail due to a race condition.
//
// Also, make sure the template used by SetVersion to create the file exists
// Also, make sure the template used by SetVersion to create the file exists
// in clientgui/mac/templates.
//

// Set STAND_ALONE TRUE if testing as a separate applicaiton
#define STAND_ALONE 0
#define VERBOSE_SPAWN 0 /* for debugging callPosixSpawn */

#define VERSION_PLACEHOLDER "%VERSION%"

#include <Carbon/Carbon.h>

#include <stdio.h>
Expand All @@ -45,6 +47,8 @@
#include <time.h>
#include <sys/param.h> // for MAXPATHLEN
#include <sys/stat.h>
#include <sstream>
#include <fstream>
#include "version.h"

int file_exists(const char* path);
Expand All @@ -70,56 +74,56 @@ int main(int argc, char** argv) {
printf("Error %d creating directory English.lproj\n", retval);
}
}

// BOINC Manager
err = FixInfoPlist_Strings("./English.lproj/InfoPlist.strings", "BOINC Manager");
if (err) retval = err;
err = FixInfoPlistFile("Info.plist");
if (err) retval = err;

// BOINC Installer
err = FixInfoPlist_Strings("./English.lproj/Installer-InfoPlist.strings", "BOINC Installer");
if (err) retval = err;
err = FixInfoPlistFile("Installer-Info.plist");
if (err) retval = err;

// BOINC PostInstall app
err = FixInfoPlist_Strings("./English.lproj/PostInstall-InfoPlist.strings", "Install BOINC");
if (err) retval = err;
err = FixInfoPlistFile("PostInstall-Info.plist");
if (err) retval = err;

// BOINC Screen Saver
err = FixInfoPlist_Strings("./English.lproj/ScreenSaver-InfoPlist.strings", "BOINC Screen Saver");
if (err) retval = err;
err = FixInfoPlistFile("ScreenSaver-Info.plist");
if (err) retval = err;

// BOINC Uninstaller
err = FixInfoPlist_Strings("./English.lproj/Uninstaller-InfoPlist.strings", "Uninstall BOINC");
if (err) retval = err;
err = FixInfoPlistFile("Uninstaller-Info.plist");
if (err) retval = err;

// SystemMenu is not currently used
err = FixInfoPlistFile("SystemMenu-Info.plist");
if (err) retval = err;

// BOINCCmd
err = FixInfoPlistFile("BoincCmd-Info.plist");
if (err) retval = err;

// WaitPermissions is not currently used
err = FixInfoPlistFile("WaitPermissions-Info.plist");
if (err) retval = err;

// The following are not used by Xcode, and are probably obsolete
err = MakeBOINCPackageInfoPlistFile("./Pkg-Info.plist", "BOINC Manager");
if (err) retval = err;

err = MakeBOINCRestartPackageInfoPlistFile("./Pkg_Restart-Info.plist", "BOINC Manager");
if (err) retval = err;

err = MakeMetaPackageInfoPlistFile("./Mpkg-Info.plist", "BOINC Manager");
return retval;
}
Expand All @@ -142,7 +146,7 @@ int FixInfoPlist_Strings(char* myPath, char* name) {

cur_time = time(NULL);
time_data = localtime( &cur_time );

f = fopen(myPath, "w");
if (f)
{
Expand All @@ -157,106 +161,63 @@ int FixInfoPlist_Strings(char* myPath, char* name) {
printf("Error creating file %s\n", myPath);
retval = -1;
}

return retval;
}

int FixInfoPlistFile(char* name) {
int retval = 0;
FILE *fin = NULL, *fout = NULL;
char *c, a, buf[1024];
char srcPath[MAXPATHLEN], dstPath[MAXPATHLEN];

strcpy(dstPath, "./");
strcat(dstPath, name);

// Construct input and output paths
char srcPath[MAXPATHLEN];
strcpy(srcPath, "../clientgui/mac/templates/");
strcat(srcPath, name);

// Save the old file in case there is an error updating it
if (file_exists(dstPath)) {
rename(dstPath, "./temp");
}

fin = fopen(srcPath, "r");
if (fin == NULL)
goto bail;
char dstPath[MAXPATHLEN];
strcpy(dstPath, "./");
strcat(dstPath, name);

fout = fopen(dstPath, "w");
if (fout == NULL) {
goto bail;
// Check if input path exits
if (!file_exists(srcPath)) {
printf("Error cannot find template plist file %s\n", srcPath);
return -1;
}

// 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>"
// Open input file and read it to a string
std::ifstream infile(srcPath);
if (!infile.is_open()) {
printf("Error cannot read template plist file %s\n", srcPath);
return -1;
}

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);
std::stringstream infile_buffer;
infile_buffer << infile.rdbuf();
std::string plist_template = infile_buffer.str();
infile.close();

// Open output file, and overwrite any existing file at that location
std::ofstream outfile(dstPath, std::ofstream::trunc);
if (!outfile.is_open()) {
printf("Error cannot write to plist file %s\n", dstPath);
return -1;
}

fclose(fin);
fflush(fout);
fclose(fout);

unlink("temp");

return retval;

bail:
if (fin)
fclose(fin);
if (fout)
fclose(fout);

if (file_exists("./temp")) {
rename("./temp", dstPath);
// sprintf(buf, "mv -f temp %s", myPath);
// retval = callPosixSpawn(buf);
} else {
sprintf(buf, "cp -f %s %s", srcPath, dstPath);
retval = callPosixSpawn(buf);
// Copy template to output, replacing any occurences of VERSION_PLACEHOLDER with BOINC_VERSION_STRING
std::string::size_type n = 0;
while ((n = plist_template.find(VERSION_PLACEHOLDER)) != std::string::npos) {
outfile << plist_template.substr(0, n) << BOINC_VERSION_STRING;
plist_template.erase(0, n + strlen(VERSION_PLACEHOLDER));
}
// Write remaining data
if (!plist_template.empty()) {
outfile << plist_template;
}

printf("Error updating version number in file %s\n", dstPath);
return -1;
outfile.close();

return 0;
}


int MakeBOINCPackageInfoPlistFile(char* myPath, char* brand) {
int retval = 0;
FILE *f;

f = fopen(myPath, "w");
if (f)
{
Expand Down Expand Up @@ -290,7 +251,7 @@ int MakeBOINCPackageInfoPlistFile(char* myPath, char* brand) {
printf("Error creating file %s\n", myPath);
retval = -1;
}

return retval;
}

Expand All @@ -299,7 +260,7 @@ int MakeBOINCPackageInfoPlistFile(char* myPath, char* brand) {
int MakeBOINCRestartPackageInfoPlistFile(char* myPath, char* brand) {
int retval = 0;
FILE *f;

f = fopen(myPath, "w");
if (f)
{
Expand All @@ -320,7 +281,7 @@ int MakeBOINCRestartPackageInfoPlistFile(char* myPath, char* brand) {
fprintf(f, "\t<key>IFPkgFlagComponentDirectory</key>\n\t<string>../</string>\n");

fprintf(f, "\t<key>IFPkgFlagPackageList</key>\n");

fprintf(f, "\t<array>\n");
fprintf(f, "\t\t<dict>\n");
fprintf(f, "\t\t\t<key>IFPkgFlagPackageLocation</key>\n\t\t\t<string>BOINC.pkg</string>\n");
Expand All @@ -338,7 +299,7 @@ int MakeBOINCRestartPackageInfoPlistFile(char* myPath, char* brand) {
printf("Error creating file %s\n", myPath);
retval = -1;
}

return retval;
}

Expand All @@ -347,7 +308,7 @@ int MakeBOINCRestartPackageInfoPlistFile(char* myPath, char* brand) {
int MakeMetaPackageInfoPlistFile(char* myPath, char* brand) {
int retval = 0;
FILE *f;

f = fopen(myPath, "w");
if (f)
{
Expand All @@ -368,7 +329,7 @@ int MakeMetaPackageInfoPlistFile(char* myPath, char* brand) {
fprintf(f, "\t<key>IFPkgFlagComponentDirectory</key>\n\t<string>../</string>\n");

fprintf(f, "\t<key>IFPkgFlagPackageList</key>\n");

fprintf(f, "\t<array>\n");
fprintf(f, "\t\t<dict>\n");
fprintf(f, "\t\t\t<key>IFPkgFlagPackageLocation</key>\n\t\t\t<string>BOINC.pkg</string>\n");
Expand All @@ -391,7 +352,7 @@ int MakeMetaPackageInfoPlistFile(char* myPath, char* brand) {
printf("Error creating file %s\n", myPath);
retval = -1;
}

return retval;
}

Expand Down Expand Up @@ -467,7 +428,7 @@ int callPosixSpawn(const char *cmdline) {
int result = 0;
int status = 0;
extern char **environ;

// Make a copy of cmdline because parse_posix_spawn_command_line modifies it
strlcpy(command, cmdline, sizeof(command));
argc = parse_posix_spawn_command_line(const_cast<char*>(command), argv);
Expand All @@ -479,7 +440,7 @@ int callPosixSpawn(const char *cmdline) {
} else {
argv[0] = progName;
}

#if VERBOSE_SPAWN
printf("***********");
for (int i=0; i<argc; ++i) {
Expand Down Expand Up @@ -522,6 +483,6 @@ int callPosixSpawn(const char *cmdline) {
#endif
} // end if (WIFEXITED(status)) else
} // end if waitpid returned 0 sstaus else

return result;
}
4 changes: 3 additions & 1 deletion clientgui/mac/templates/BoincCmd-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<key>CFBundleName</key>
<string> boinccmd </string>
<key>CFBundleVersion</key>
<string>5.10.7</string>
<string>%VERSION%</string>
<key>CFBundleShortVersionString</key>
<string>%VERSION%</string>
</dict>
</plist>
4 changes: 3 additions & 1 deletion clientgui/mac/templates/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
<key>CFBundleSignature</key>
<string>BNC!</string>
<key>CFBundleVersion</key>
<string>7.15.0</string>
<string>%VERSION%</string>
<key>CFBundleShortVersionString</key>
<string>%VERSION%</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NSRequiresAquaSystemAppearance</key>
Expand Down
4 changes: 3 additions & 1 deletion clientgui/mac/templates/Installer-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
<key>CFBundleName</key>
<string>BOINC Installer</string>
<key>CFBundleVersion</key>
<string>5.10.7</string>
<string>%VERSION%</string>
<key>CFBundleShortVersionString</key>
<string>%VERSION%</string>
</dict>
</plist>
4 changes: 3 additions & 1 deletion clientgui/mac/templates/PostInstall-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>5.10.7</string>
<string>%VERSION%</string>
<key>CFBundleShortVersionString</key>
<string>%VERSION%</string>
</dict>
</plist>
4 changes: 3 additions & 1 deletion clientgui/mac/templates/ScreenSaver-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>5.10.7</string>
<string>%VERSION%</string>
<key>CFBundleShortVersionString</key>
<string>%VERSION%</string>
<key>NSPrincipalClass</key>
<string>BOINC_Saver_ModuleView</string>
</dict>
Expand Down
Loading