My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
package PlistMaker;

use Exporter;

@ISA = qw(Exporter);
@EXPORT_OK = qw( p_if p_ifnot CopyPath RemovePath AbortOperation AddSource Exec InstallApp UninstallApp LinkPath MovePath Notice RemoveSource SetStatus IsFirmwareVersion IsPackageInstalled ExistsPath Confirm ExecNoError CreatePackage );
%EXPORT_TAGS = (all => [ qw( p_if p_ifnot CopyPath RemovePath AbortOperation AddSource Exec InstallApp UninstallApp LinkPath MovePath Notice RemoveSource SetStatus IsFirmwareVersion IsPackageInstalled ExistsPath Confirm ExecNoError CreatePackage ) ]);

sub p_if($$) {
my ($test, $commands) = @_;

return p_all("If", $test, $commands);
}

sub p_ifnot($$) {
my ($test, $commands) = @_;

return p_all("IfNot", $test, $commands);
}

sub p_all($$$) {
my ($type, $test, $commands) = @_;

chomp $test;
chomp $commands;
$test =~ s/^/ /mg;
$commands =~ s/^/ /mg;

my $phrase = <<END
<array>
<string>$type</string>
<array>
${test}
</array>
<array>
${commands}
</array>
</array>
END
;
chomp $phrase;
return $phrase;
}


sub callFn {
# From the XML doc pov, the fn name is just another parameter

my $params = "<string>" . join("</string>\n<string>", @_) . "</string>";

$params =~ s/^/ /mg;

my $phrase = <<END;
<array>
$params
</array>
END
;
#chomp $phrase;
return $phrase;
}

# CopyPath(source,dest)
sub CopyPath($$) {
return callFn("CopyPath", @_);
}

# RemovePath(dest)
sub RemovePath($) {
return callFn("RemovePath", @_);
}

# AbortOperation(message)
sub AbortOperation($) {
return callFn("AbortOperation", @_);
}

# AddSource(url)
sub AddSource($) {
return callFn("AddSource", @_);
}

# Exec(command)
sub Exec($) {
return callFn("Exec", @_);
}

# InstallApp(application name)
sub InstallApp($) {
return callFn("InstallApp", @_);
}

# UninstallApp(application name)
sub UninstallApp($) {
return callFn("UninstallApp", @_);
}

# LinkPath(oldPath, newPath)
sub LinkPath($$) {
return callFn("LinkPath", @_);
}

# MovePath(oldPath, newPath)
sub MovePath($$) {
return callFn("MovePath", @_);
}

# Notice(string)
sub Notice($) {
return callFn("Notice", @_);
}

# RemoveSource(url)
sub RemoveSource($) {
return callFn("RemoveSource", @_);
}

# SetStatus(string)
sub SetStatus($) {
return callFn("SetStatus", @_);
}

# FirmwareVersionIs(string)
sub IsFirmwareVersion {
# This one is special... The parameter list is an array.

my $params = "<array>\n <string>" . join("</string>\n <string>", @_) . "</string>\n</array>";

$params =~ s/^/ /mg;

my $phrase = <<END;
<array>
<string>FirmwareVersionIs</string>
$params
</array>
END
;
chomp $phrase;
return $phrase;
}

# InstalledPackage(string)
sub IsPackageInstalled($) {
return callFn("InstalledPackage", @_);
}

# ExistsPath(path)
sub ExistsPath($) {
return callFn("ExistsPath", @_);
}

# Confirm(text, option1, option2)
sub Confirm($$$) {
return callFn("Confirm", @_);
}

# Dunno, exec command, ignoring errors?
sub ExecNoError($) {
return callFn("ExecNoError", @_);
}

#my %Descriptor = ( bundleIdentifier => "ca.pollock.fixEbookDir",
# name => "EBook /mobile fix",
# version => "1.0",
# location => "",
# category => "Tweaks",
# size => "0",
# hash => "",
# url => "http://jason-pollock.blogspot.com/",
# maintainer => "Jason Pollock",
# contact => "jason@pollock.ca",
# description => "Move existing eBooks from /var/root to /var/mobile. Create a link from /var/root to /var/mobile.",
# install => $fix_disk_install,
# preflight => $fix_dist_,
# postflight => "" ,
# uninstall => "",
# update => "");


# Create the package dict entry, from the provided hash.
sub CreatePackage {
my %dict = @_;

foreach my $i (install, uninstall, update, preflight, postflight) {
if (exists $dict{$i}) {
$dict{$i} =~ s/^/ /mg;
$dict{$i} =<<END
<key>$i</key>
<array>
$dict{$i}
</array>
END
;
$dict{$i} =~ s/^/ /mg;
chomp $dict{$i};
}
}

my $phrase = <<END
<dict>
<key>bundleIdentifier</key>
<string>$dict{bundleIdentifier}</string>
<key>name</key>
<string>$dict{name}</string>
<key>version</key>
<string>$dict{version}</string>
<key>location</key>
<string>$dict{location}</string>
<key>category</key>
<string>$dict{category}</string>
<key>size</key>
<string>$dict{size}</string>
<key>hash</key>
<string>$dict{hash}</string>
<key>url</key>
<string>$dict{url}</string>
<key>maintainer</key>
<string>$dict{maintainer}</string>
<key>contact</key>
<string>$dict{contact}</string>
<key>description</key>
<string>$dict{description}</string>
<key>scripts</key>
<dict>
$dict{preflight}
$dict{install}
$dict{update}
$dict{uninstall}
$dict{postflight}
</dict>
</dict>
END
;

return $phrase;
}


1;

Change log

r7 by jason.pollock on May 11, 2008   Diff
Updated to support Books.app v 1.4+
Updated to create the Gutenberg SciFi
collection.
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 5048 bytes, 239 lines
Powered by Google Project Hosting