3624
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2015 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
"{ Package: 'stx:libbasic2' }"
|
|
13 |
|
|
14 |
"{ NameSpace: Smalltalk }"
|
|
15 |
|
|
16 |
Object subclass:#MacPlistBinaryDecoder
|
|
17 |
instanceVariableNames:'inputStream'
|
|
18 |
classVariableNames:''
|
|
19 |
poolDictionaries:''
|
|
20 |
category:'System-Support-FileFormats'
|
|
21 |
!
|
|
22 |
|
|
23 |
!MacPlistBinaryDecoder class methodsFor:'documentation'!
|
|
24 |
|
|
25 |
copyright
|
|
26 |
"
|
|
27 |
COPYRIGHT (c) 2015 by Claus Gittinger
|
|
28 |
All Rights Reserved
|
|
29 |
|
|
30 |
This software is furnished under a license and may be used
|
|
31 |
only in accordance with the terms of that license and with the
|
|
32 |
inclusion of the above copyright notice. This software may not
|
|
33 |
be provided or otherwise made available to, or used by, any
|
|
34 |
other person. No title to or ownership of the software is
|
|
35 |
hereby transferred.
|
|
36 |
"
|
|
37 |
!
|
|
38 |
|
|
39 |
documentation
|
|
40 |
"
|
|
41 |
A common binary file format representation on Mac OSX.
|
|
42 |
On OSX, this is used to store user preferences, settings and application histories.
|
4343
|
43 |
It is also used to provide additional attributes for applications
|
|
44 |
(such as type of document, icons etc.)
|
3624
|
45 |
|
|
46 |
Notice, that OSX is moving towards a new plist format, which is XML based.
|
|
47 |
This decoder reads the old binary format. New applications should use the new format,
|
|
48 |
and only use this decoder to convert/read old plist files.
|
4343
|
49 |
Actually, because I am lazy, this decoder uses a command line utility to first convert from binary
|
|
50 |
to xml plist format. Thus, it will only work on OS-X.
|
3624
|
51 |
|
|
52 |
[author:]
|
|
53 |
Claus Gittinger
|
|
54 |
|
|
55 |
[see also:]
|
|
56 |
MacPlistXMLDecoder MacPlistXMLCoder
|
|
57 |
|
|
58 |
[instance variables:]
|
|
59 |
|
|
60 |
[class variables:]
|
|
61 |
"
|
|
62 |
!
|
|
63 |
|
|
64 |
examples
|
|
65 |
"
|
|
66 |
restore:
|
|
67 |
[exBegin]
|
|
68 |
|inFile d decodedObject|
|
|
69 |
|
|
70 |
inFile := '/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/German.lproj/InfoPlist.strings'.
|
4343
|
71 |
inFile := '/Applications/TextEdit.app/Contents/Resources/German.lproj/Localizable.strings'.
|
3624
|
72 |
|
|
73 |
decodedObject := (MacPlistBinaryDecoder on:inFile asFilename binaryContentsOfEntireFile) decodedObject.
|
|
74 |
decodedObject inspect.
|
|
75 |
[exEnd]
|
|
76 |
|
|
77 |
"
|
|
78 |
! !
|
|
79 |
|
|
80 |
!MacPlistBinaryDecoder class methodsFor:'instance creation'!
|
|
81 |
|
|
82 |
on:aByteArrayOrReadStream
|
|
83 |
Smalltalk requirePackage:'stx:goodies/xml/stx'.
|
|
84 |
|
|
85 |
^ self new on:aByteArrayOrReadStream readStream
|
|
86 |
! !
|
|
87 |
|
|
88 |
!MacPlistBinaryDecoder methodsFor:'decoding'!
|
|
89 |
|
|
90 |
decodedObject
|
|
91 |
"use plutil to convert to XML, then read that"
|
|
92 |
|
|
93 |
|tmpFile tmpXMLFile decoder object|
|
|
94 |
|
4343
|
95 |
tmpFile := Filename newTemporary.
|
3624
|
96 |
[
|
|
97 |
tmpFile contents:inputStream upToEnd.
|
4343
|
98 |
tmpXMLFile := Filename newTemporary.
|
3624
|
99 |
OperatingSystem executeCommand:('plutil -convert xml1 -o %2 %1' bindWith:tmpFile pathName with:tmpXMLFile pathName).
|
|
100 |
tmpXMLFile readingFileDo:[:s |
|
|
101 |
"/ to avoid package dependency from libbasic2 to goodies/xml
|
|
102 |
"/ see package loading on instance-side
|
|
103 |
decoder := (Smalltalk at:#MacPlistXMLDecoder) on:s.
|
|
104 |
object := decoder decodedObject.
|
|
105 |
].
|
|
106 |
] ensure:[
|
|
107 |
tmpFile delete.
|
|
108 |
tmpXMLFile delete.
|
|
109 |
].
|
|
110 |
^ object.
|
4343
|
111 |
|
|
112 |
"Modified: / 22-02-2017 / 11:17:31 / cg"
|
3624
|
113 |
! !
|
|
114 |
|
|
115 |
!MacPlistBinaryDecoder methodsFor:'initialization'!
|
|
116 |
|
|
117 |
on:aStream
|
|
118 |
inputStream := aStream
|
|
119 |
! !
|
|
120 |
|
|
121 |
!MacPlistBinaryDecoder class methodsFor:'documentation'!
|
|
122 |
|
|
123 |
version
|
|
124 |
^ '$Header$'
|
|
125 |
!
|
|
126 |
|
|
127 |
version_CVS
|
|
128 |
^ '$Header$'
|
|
129 |
! !
|
|
130 |
|