Kaydet (Commit) a486a55f authored tarafından Jack Jansen's avatar Jack Jansen

Added support for override preferences

üst db0baced
...@@ -151,17 +151,25 @@ PyMac_GetPythonDir() ...@@ -151,17 +151,25 @@ PyMac_GetPythonDir()
Boolean modified = 0; Boolean modified = 0;
short oldrh, prefrh; short oldrh, prefrh;
oldrh = CurResFile();
/* /*
** Remember old resource file and try to open preferences file ** First look for an override of the preferences file
** in the preferences folder.
*/ */
oldrh = CurResFile(); handle = (AliasHandle)GetResource('alis', PYTHONHOMEOVERRIDE_ID);
prefrh = PyMac_OpenPrefFile(); if ( handle != NULL ) {
/* So, we've opened our preferences file, we hope. Look for the alias */ prefrh = oldrh;
handle = (AliasHandle)Get1Resource('alis', PYTHONHOME_ID); } else {
if ( handle == NULL ) { /*
(void)StopAlert(BADPREFFILE_ID, NULL); ** Remember old resource file and try to open preferences file
exit(1); ** in the preferences folder.
*/
prefrh = PyMac_OpenPrefFile();
/* So, we've opened our preferences file, we hope. Look for the alias */
handle = (AliasHandle)Get1Resource('alis', PYTHONHOME_ID);
if ( handle == NULL ) {
(void)StopAlert(BADPREFFILE_ID, NULL);
exit(1);
}
} }
/* It exists. Resolve it (possibly updating it) */ /* It exists. Resolve it (possibly updating it) */
if ( ResolveAlias(NULL, handle, &dirspec, &modified) != noErr ) { if ( ResolveAlias(NULL, handle, &dirspec, &modified) != noErr ) {
...@@ -172,8 +180,10 @@ PyMac_GetPythonDir() ...@@ -172,8 +180,10 @@ PyMac_GetPythonDir()
ChangedResource((Handle)handle); ChangedResource((Handle)handle);
UpdateResFile(prefrh); UpdateResFile(prefrh);
} }
CloseResFile(prefrh); if ( prefrh != oldrh ) {
UseResFile(oldrh); CloseResFile(prefrh);
UseResFile(oldrh);
}
if ( nfullpath(&dirspec, name) == 0 ) { if ( nfullpath(&dirspec, name) == 0 ) {
strcat(name, ":"); strcat(name, ":");
...@@ -198,6 +208,8 @@ char *dir; ...@@ -198,6 +208,8 @@ char *dir;
char *rv; char *rv;
int i, newlen; int i, newlen;
Str255 pathitem; Str255 pathitem;
int resource_id;
OSErr err;
/* /*
** Remember old resource file and try to open preferences file ** Remember old resource file and try to open preferences file
...@@ -217,8 +229,16 @@ char *dir; ...@@ -217,8 +229,16 @@ char *dir;
if( (rv = malloc(2)) == NULL ) if( (rv = malloc(2)) == NULL )
goto out; goto out;
strcpy(rv, "\n"); strcpy(rv, "\n");
/*
** See whether there's an override.
*/
GetIndString(pathitem, PYTHONPATHOVERRIDE_ID, 1);
if ( pathitem[0] )
resource_id = PYTHONPATHOVERRIDE_ID;
else
resource_id = PYTHONPATH_ID;
for(i=1; ; i++) { for(i=1; ; i++) {
GetIndString(pathitem, PYTHONPATH_ID, i); GetIndString(pathitem, resource_id, i);
if( pathitem[0] == 0 ) if( pathitem[0] == 0 )
break; break;
if ( pathitem[0] >= 9 && strncmp((char *)pathitem+1, "$(PYTHON)", 9) == 0 ) { if ( pathitem[0] >= 9 && strncmp((char *)pathitem+1, "$(PYTHON)", 9) == 0 ) {
...@@ -236,6 +256,25 @@ char *dir; ...@@ -236,6 +256,25 @@ char *dir;
} }
rv[newlen-2] = '\n'; rv[newlen-2] = '\n';
rv[newlen-1] = 0; rv[newlen-1] = 0;
} else if ( pathitem[0] >= 14 && strncmp((char *)pathitem+1, "$(APPLICATION)", 14) == 0 ) {
/* This is the application itself */
char fullname[256];
if ( (err=PyMac_process_location(&dirspec)) != 0 ) {
printf("Cannot get FSSpec for application, error %d\n", err);
exit(1);
}
if ( nfullpath(&dirspec, fullname) != 0 ) {
printf("Cannot convert application fsspec to path\n");
exit(1);
}
newlen = strlen(rv) + strlen(fullname) + 2;
if( (rv=realloc(rv, newlen)) == NULL)
goto out;
strcpy(rv+strlen(rv), fullname);
rv[newlen-2] = '\n';
rv[newlen-1] = 0;
} else { } else {
/* Use as-is */ /* Use as-is */
newlen = strlen(rv) + (pathitem[0]) + 2; newlen = strlen(rv) + (pathitem[0]) + 2;
...@@ -276,7 +315,9 @@ PyMac_PreferenceOptions(int *inspect, int *verbose, int *suppress_print, ...@@ -276,7 +315,9 @@ PyMac_PreferenceOptions(int *inspect, int *verbose, int *suppress_print,
oldrh = CurResFile(); oldrh = CurResFile();
prefrh = PyMac_OpenPrefFile(); prefrh = PyMac_OpenPrefFile();
handle = GetResource('Popt', PYTHONOPTIONS_ID); handle = GetResource('Popt', PYTHONOPTIONSOVERRIDE_ID);
if ( handle == NULL )
handle = GetResource('Popt', PYTHONOPTIONS_ID);
if ( handle == NULL ) { if ( handle == NULL ) {
return; return;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment