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
|
# File 'lib/chocbomb/tools/dmg.rb', line 36
def make
@files_for_dmg = chocbomb.files.inject({}) do |files, file|
path_or_helper, options = file
path = case path_or_helper
when Symbol
chocbomb.send path_or_helper
when Proc
path_or_helper.call
else
path_or_helper
end
if path && File.exists?(path)
files[path] = options
options[:name] ||= File.basename(path)
end
if path =~ %r{\.webloc$}
files[path] = options
options[:name] ||= File.basename(path)
options[:link] = true
end
files
end
FileUtils.rm_r(chocbomb.dmg_src_folder) if File.exists? chocbomb.dmg_src_folder
FileUtils.mkdir_p(chocbomb.dmg_src_folder)
@files_for_dmg.each do |path, options|
if options[:link]
webloc = " <?xml version=\"1.0\" encoding=\"UTF-8\"?>\n <!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n <plist version=\"1.0\">\n <dict>\n <key>URL</key>\n <string>\#{options[:url]}</string>\n </dict>\n </plist>\n WEBLOC\n\n target = File.join(chocbomb.dmg_src_folder, options[:name])\n File.open(target, 'w').write(webloc)\n else\n target = File.join(chocbomb.dmg_src_folder, options[:name])\n FileUtils.copy_entry(path, target) \n if options[:exclude]\n exclude_list = options[:exclude].is_a?(Array) ? options[:exclude] : [options[:exclude].to_s]\n exclude_list.each { |exclude| sh ::Escape.shell_command(['rm', '-rf', File.join(target, exclude)]) }\n end\n end\n end\n \n FileUtils.mkdir_p chocbomb.build_path\n FileUtils.rm_f(chocbomb.pkg)\n sh \"hdiutil create -format UDRW -quiet -volname '\#{chocbomb.name}' -srcfolder '\#{chocbomb.dmg_src_folder}' '\#{chocbomb.pkg}'\"\n mount\n sh \"bless --folder '\#{chocbomb.volume_path}' --openfolder '\#{chocbomb.volume_path}'\"\n sh \"sleep 1\"\n \n # Add Volume Icon\n FileUtils.cp(chocbomb.volume_icon, \"\#{chocbomb.volume_path}/.VolumeIcon.icns\")\n sh \"SetFile -a C '\#{chocbomb.volume_path}'\"\n \n # Configure Application Icon\n Mac.applescript <<-SCRIPT.gsub(/^ /, ''), \"apps_icon_script\"\n tell application \"Finder\"\n set applications_folder to displayed name of (path to applications folder) -- i18n\n set dest to disk \"\#{chocbomb.name}\"\n set src to folder applications_folder of startup disk\n make new alias at dest to src\n end tell\n SCRIPT\n \n # Configure DMG Window\n if chocbomb.background_file\n target_background = \"\#{chocbomb.volume_path}/\#{chocbomb.volume_background}\"\n FileUtils.mkdir_p(File.dirname(target_background))\n FileUtils.cp(chocbomb.background_file, target_background) \n end\n Mac.applescript <<-SCRIPT.gsub(/^ /, '')\n tell application \"Finder\"\n set applications_folder to displayed name of (path to applications folder) -- i18n\n set mountpoint to POSIX file (\"\#{chocbomb.volume_path}\" as string) as alias\n tell folder mountpoint\n open\n tell container window\n set toolbar visible to false\n set statusbar visible to false -- doesn't do anything at DMG open time\n set current view to icon view\n delay 1 -- Sync\n set the bounds to {\#{window_bounds.join(\", \")}}\n end tell\n delay 1 -- Sync\n set icon size of the icon view options of container window to \#{chocbomb.icon_size}\n set text size of the icon view options of container window to \#{chocbomb.icon_text_size}\n set arrangement of the icon view options of container window to not arranged\n \#{set_position_of_files}\n \#{set_position_of_shortcuts}\n close\n open\n set the bounds of the container window to {\#{window_bounds.join(\", \")}}\n set background picture of the icon view options of container window to file \"\#{chocbomb.volume_background.gsub(/\\//,':')}\"\n update without registering applications\n delay 5 -- Sync\n close\n end tell\n -- Sync\n delay 5\n end tell\n SCRIPT\n sh \"SetFile -a V '\#{target_background}'\" if chocbomb.background_file\nend\n".gsub(/^ /, '')
|