Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Rishabh Gupta
purr-data
Commits
cf3769a6
Commit
cf3769a6
authored
Mar 15, 2017
by
Jonathan Wilkes
Browse files
Merge branch 'aggraef/purr-data-osx-loadprefs-fixes'
parents
9366e8ef
a6a61b00
Changes
2
Hide whitespace changes
Inline
Side-by-side
packages/darwin_app/org.puredata.pd-l2ork.default.plist
View file @
cf3769a6
...
...
@@ -5,7 +5,7 @@
<key>
defeatrt
</key>
<string>
0
</string>
<key>
flags
</key>
<string>
-helppath ~/Library/Pd -helppath /Library/Pd
</string>
<string>
-helppath ~/Library/Pd
-l2ork
-helppath /Library/Pd
-l2ork
</string>
<key>
loadlib1
</key>
<string>
libdir
</string>
<key>
loadlib2
</key>
...
...
pd/src/s_file.c
View file @
cf3769a6
...
...
@@ -259,15 +259,14 @@ static char *sys_prefbuf;
#define BUFSZ 4096
// AG: We have to go to some lengths here since 'defaults read' doesn't
// properly deal with UTF-8 characters in the prefs data. 'defaults export'
// does the trick, however, so we use that to read the entire prefs data at
// once from a pipe, using plutil to convert the resulting data to JSON format
// which can then be translated to Pd's Unix preferences file format using
// sed. The result is stored in a character buffer for efficient access. From
// there we can retrieve the individual keys in the same fashion as on Unix. A
// welcome side effect is that loading the prefs is *much* faster now than
// with the previous method which invoked 'defaults read' on each individual
// key.
// properly deal with UTF-8 characters in the prefs data. 'plutil' does the
// trick, however, so we use that to read the entire prefs data at once from a
// pipe, converting it to JSON format which can then be translated to Pd's
// Unix preferences file format using sed. The result is stored in a character
// buffer for efficient access. From there we can retrieve the individual keys
// in the same fashion as on Unix. A welcome side effect is that loading the
// prefs is *much* faster now than with the previous method which invoked
// 'defaults read' on each individual key.
static
void
sys_initloadpreferences
(
void
)
{
...
...
@@ -275,8 +274,9 @@ static void sys_initloadpreferences(void)
FILE
*
fp
;
size_t
sz
,
n
=
0
;
int
res
;
char
default_prefs
[
FILENAME_MAX
];
// default prefs embedded in the package
char
default_prefs
[
FILENAME_MAX
];
// default prefs embedded in the package
char
embedded_prefs
[
FILENAME_MAX
];
// overrides others for standalone app
char
user_prefs
[
FILENAME_MAX
];
// user preferences
char
embedded_prefs_file
[
FILENAME_MAX
];
char
user_prefs_file
[
FILENAME_MAX
];
const
char
*
prefs
,
*
homedir
=
getenv
(
"HOME"
);
...
...
@@ -292,9 +292,10 @@ static void sys_initloadpreferences(void)
snprintf
(
embedded_prefs
,
FILENAME_MAX
,
"%s/../org.puredata.pd-l2ork"
,
sys_libdir
->
s_name
);
snprintf
(
user_prefs
,
FILENAME_MAX
,
"%s/Library/Preferences/org.puredata.pd-l2ork"
,
homedir
);
snprintf
(
embedded_prefs_file
,
FILENAME_MAX
,
"%s.plist"
,
embedded_prefs
);
snprintf
(
user_prefs_file
,
FILENAME_MAX
,
"%s/Library/Preferences/org.puredata.pd-l2ork.plist"
,
homedir
);
snprintf
(
user_prefs_file
,
FILENAME_MAX
,
"%s.plist"
,
user_prefs
);
if
(
stat
(
embedded_prefs_file
,
&
statbuf
)
==
0
)
{
// Read from and write to the embedded prefs (standalone app).
prefs
=
embedded_prefs
;
...
...
@@ -302,17 +303,16 @@ static void sys_initloadpreferences(void)
}
else
if
(
stat
(
user_prefs_file
,
&
statbuf
)
==
0
)
{
// Read from and write to the user prefs.
prefs
=
current_prefs
;
strcpy
(
current_prefs
,
"org.puredata.pd-l2ork"
);
str
n
cpy
(
current_prefs
,
user_prefs
,
FILENAME_MAX
);
}
else
{
// Read from the package defaults and write to the user prefs.
prefs
=
default_prefs
;
strcpy
(
current_prefs
,
"org.puredata.pd-l2ork"
);
str
n
cpy
(
current_prefs
,
user_prefs
,
FILENAME_MAX
);
}
// This looks complicated, but is rather straightforward. The individual
// stages of the pipe are:
// 1. defaults export: grab our defaults in XML format
// 2. plutil -convert json -r -o - -: convert to JSON
// 3. sed: a few edits remove the extra JSON bits (curly braces, string
// 1. plutil -convert json -r -o -: grab our defaults and convert to JSON
// 2. sed: a few edits remove the extra JSON bits (curly braces, string
// quotes, unwanted whitespace and character escapes) and produce
// Pd-L2Ork's Unix prefs format, i.e.:
// JSON --> Unix prefs
...
...
@@ -322,8 +322,7 @@ static void sys_initloadpreferences(void)
// "path1" : "\/System\/Library\/Fonts" path1: /System/Library/Fonts
// }
snprintf
(
cmdbuf
,
MAXPDSTRING
,
"defaults export %s - "
"| plutil -convert json -r -o - - "
"plutil -convert json -r -o - %s.plist "
"| sed -E "
"-e 's/[{}]//g' "
"-e 's/^ *
\"
(([^
\"
]|
\\\\
.)*)
\"
*: *
\"
(([^
\"
]|
\\\\
.)*)
\"
.*/
\\
1:
\\
3/' "
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment