2
0
Эх сурвалжийг харах

[Swf9] added support for using SWC libraries as -swf-lib (fixed issue #1024)

Simon Krajewski 13 жил өмнө
parent
commit
bbe112918e
1 өөрчлөгдсөн 22 нэмэгдсэн , 9 устгасан
  1. 22 9
      genswf.ml

+ 22 - 9
genswf.ml

@@ -424,8 +424,21 @@ let remove_debug_infos as3 =
 
 
 let parse_swf com file =
 let parse_swf com file =
 	let t = Common.timer "read swf" in
 	let t = Common.timer "read swf" in
-	let file = (try Common.find_file com file with Not_found -> failwith ("SWF Library not found : " ^ file)) in
-	let ch = IO.input_channel (open_in_bin file) in
+	let is_swc = file_extension file = "swc" in
+	let file = (try Common.find_file com file with Not_found -> failwith ((if is_swc then "SWC" else "SWF") ^ " Library not found : " ^ file)) in
+	let ch = if is_swc then begin
+		let zip = Zip.open_in file in
+		try
+			let entry = Zip.find_entry zip "library.swf" in
+			let ch = IO.input_string (Zip.read_entry zip entry) in
+			Zip.close_in zip;
+			ch
+		with _ ->
+			Zip.close_in zip;
+			failwith ("The input swc " ^ file ^ " is corrupted")
+	end else 
+		IO.input_channel (open_in_bin file)
+	in
 	let h, tags = (try Swf.parse ch with _ -> failwith ("The input swf " ^ file ^ " is corrupted")) in
 	let h, tags = (try Swf.parse ch with _ -> failwith ("The input swf " ^ file ^ " is corrupted")) in
 	IO.close_in ch;
 	IO.close_in ch;
 	List.iter (fun t ->
 	List.iter (fun t ->
@@ -886,11 +899,11 @@ let build_swf9 com file swc =
 										(* ID3 *)
 										(* ID3 *)
 										if IO.nread i 2 <> "D3" then raise Exit;
 										if IO.nread i 2 <> "D3" then raise Exit;
 										ignore(IO.read_ui16 i); (* version *)
 										ignore(IO.read_ui16 i); (* version *)
-										ignore(IO.read_byte i); (* flags *)
-										let size = IO.read_byte i land 0x7F in
-										let size = size lsl 7 lor (IO.read_byte i land 0x7F) in
-										let size = size lsl 7 lor (IO.read_byte i land 0x7F) in
-										let size = size lsl 7 lor (IO.read_byte i land 0x7F) in
+										ignore(IO.read_byte i); (* flags *)
+										let size = IO.read_byte i land 0x7F in
+										let size = size lsl 7 lor (IO.read_byte i land 0x7F) in
+										let size = size lsl 7 lor (IO.read_byte i land 0x7F) in
+										let size = size lsl 7 lor (IO.read_byte i land 0x7F) in
 										ignore(IO.nread i size); (* id3 data *)
 										ignore(IO.nread i size); (* id3 data *)
 										read_frame()
 										read_frame()
 									| 0xFF ->
 									| 0xFF ->
@@ -900,8 +913,8 @@ let build_swf9 com file swc =
 										let bits = IO.read_byte i in
 										let bits = IO.read_byte i in
 										let bitrate = (if ver = 3 then [|0;32;40;48;56;64;80;96;112;128;160;192;224;256;320;-1|] else [|0;8;16;24;32;40;48;56;64;80;96;112;128;144;160;-1|]).(bits lsr 4) in
 										let bitrate = (if ver = 3 then [|0;32;40;48;56;64;80;96;112;128;160;192;224;256;320;-1|] else [|0;8;16;24;32;40;48;56;64;80;96;112;128;144;160;-1|]).(bits lsr 4) in
 										let srate = [|
 										let srate = [|
-											[|11025;-1;22050;44100|];
-											[|12000;-1;24000;48000|];
+											[|11025;-1;22050;44100|];
+											[|12000;-1;24000;48000|];
 											[|8000;-1;16000;32000|];
 											[|8000;-1;16000;32000|];
 											[|-1;-1;-1;-1|]
 											[|-1;-1;-1;-1|]
 										|].((bits lsr 2) land 2).(ver) in
 										|].((bits lsr 2) land 2).(ver) in