Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'A script to repair StuffIt-expanded Panther zip files' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A script to repair StuffIt-expanded Panther zip files
Authored by: fy on Oct 31, '03 10:03:11AM
named "ReSeZoP" is now here.

property dq : (ASCII character 34)
property thePath : ""

display dialog "First, drop Panther's native zip archives on StuffIt Expander, and drop the generated folder on me."

on open drop_items
	repeat with theObj in drop_items
		tell application "Finder"
			set thePath to theObj as Unicode text
			if (folder thePath exists) and (folder (thePath & "__MACOSX") exists) then
				repeat with i in (list folder theObj)
					if i as Unicode text is not ".DS_Store" and i as Unicode text is not "__MACOSX" then
						my dirConv(alias (thePath & (i as Unicode text)), thePath)
						move (alias (thePath & (i as Unicode text))) to container of theObj with replacing
					end if
				end repeat
				do shell script "rm -r " & dq & (POSIX path of file thePath) & dq
			end if
		end tell
	end repeat
end open

on dirConv(theObj, thePath) --process recursively
	tell application "Finder"
		if (folder (theObj as Unicode text) exists) then --in case of a folder
			repeat with i in (list folder (theObj as Unicode text))
				my dirConv(alias ((theObj as Unicode text) & i), thePath)
			end repeat
		else if (name of (alias (theObj as Unicode text)) ends with ".app") then --in case of a package
			repeat with i in (list folder (theObj as Unicode text))
				my dirConv(alias ((theObj as Unicode text) & ":" & i), thePath)
			end repeat
		else if name of (alias (theObj as Unicode text)) is not ".DS_Store" then --in case of a file other than ".DS_Store"
			set theFile to alias (theObj as Unicode text)
			set oldDelim to text item delimiters of AppleScript
			set text item delimiters of AppleScript to thePath
			set theList to every text item of (container of (alias (theObj as Unicode text)) as Unicode text)
			set text item delimiters of AppleScript to (thePath & "__MACOSX:")
			set theStr to theList as Unicode text
			set text item delimiters of AppleScript to oldDelim
			if alias (theStr & "._" & name of (alias (theObj as Unicode text))) exists then
				set subFile to alias (theStr & "._" & name of (alias (theObj as Unicode text)))
				set theCom to "perl -e 'open(IN," & dq & "<" & (POSIX path of file (subFile as Unicode text)) & dq & ");"
				set theCom to theCom & "for(1..50){$c = getc(IN);if($c eq " & dq & dq & "){close(IN);exit;}}"
				set theCom to theCom & "$s=" & dq & dq & ";for(1..8){$c = getc(IN);if($c eq " & dq & dq & "){close(IN);exit;}$s.=$c;}"
				set theCom to theCom & "for(1..24){$c = getc(IN);if($c eq " & dq & dq & "){close(IN);exit;}} if($s eq " & dq & dq & "){close(IN);exit;}"
				set theCom to theCom & "open(OUT," & dq & ">" & (POSIX path of file (theObj as Unicode text) & "/..namedfork/rsrc") & dq & ");"
				set theCom to theCom & "while(1){$c = getc(IN);if($c eq " & dq & dq & "){last;} print OUT $c;} close(OUT); close(IN);print $s;'"
				do shell script theCom
				set ftct to result
				if ftct is not "" then
					set file type of theObj to (ASCII character (ASCII number (character 1 of ftct))) & (ASCII character (ASCII number (character 2 of ftct))) & (ASCII character (ASCII number (character 3 of ftct))) & (ASCII character (ASCII number (character 4 of ftct)))
					set creator type of theObj to (ASCII character (ASCII number (character 5 of ftct))) & (ASCII character (ASCII number (character 6 of ftct))) & (ASCII character (ASCII number (character 7 of ftct))) & (ASCII character (ASCII number (character 8 of ftct)))
				end if
			end if
		end if
	end tell
end dirConv


[ Reply to This | # ]