Opening iggy files as bundles (read only) - still WIP

This commit is contained in:
Jindra Petřík
2016-11-25 15:11:43 +01:00
parent 52e6fdecf3
commit 36eb046291
9 changed files with 3126 additions and 2998 deletions

View File

@@ -1,102 +1,105 @@
/*
* Copyright (C) 2010-2016 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.flash;
import com.jpexs.helpers.Path;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
/**
*
* @author JPEXS
*/
public class SWFSourceInfo {
private final InputStream inputStream;
private String file;
private final String fileTitle;
public SWFSourceInfo(InputStream inputStream, String file, String fileTitle) {
this.inputStream = inputStream;
this.file = file;
this.fileTitle = fileTitle;
}
public InputStream getInputStream() {
return inputStream;
}
public String getFile() {
return file;
}
public void setFile(String file) {
this.file = file;
}
public String getFileTitle() {
return fileTitle;
}
/**
* Get title of the file
*
* @return file title
*/
public String getFileTitleOrName() {
if (fileTitle != null) {
return fileTitle;
}
return file;
}
public boolean isBundle() {
if (inputStream == null) {
File fileObj = new File(file);
String fileName = fileObj.getName();
if (fileName.startsWith("asdec_") && fileName.endsWith(".tmp")) {
return false;
}
String extension = Path.getExtension(fileObj);
return extension == null || !(extension.equals(".swf") || extension.equals(".gfx"));
}
return false;
}
public SWFBundle getBundle(boolean noCheck, SearchMode searchMode) throws IOException {
if (!isBundle()) {
return null;
}
String extension = Path.getExtension(new File(file));
if (extension != null) {
switch (extension) {
case ".swc":
return new SWC(new File(file));
case ".zip":
return new ZippedSWFBundle(new File(file));
}
}
return new BinarySWFBundle(new BufferedInputStream(new FileInputStream(file)), noCheck, searchMode);
}
}
/*
* Copyright (C) 2010-2016 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.flash;
import com.jpexs.decompiler.flash.iggy.conversion.IggySwfBundle;
import com.jpexs.helpers.Path;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
/**
*
* @author JPEXS
*/
public class SWFSourceInfo {
private final InputStream inputStream;
private String file;
private final String fileTitle;
public SWFSourceInfo(InputStream inputStream, String file, String fileTitle) {
this.inputStream = inputStream;
this.file = file;
this.fileTitle = fileTitle;
}
public InputStream getInputStream() {
return inputStream;
}
public String getFile() {
return file;
}
public void setFile(String file) {
this.file = file;
}
public String getFileTitle() {
return fileTitle;
}
/**
* Get title of the file
*
* @return file title
*/
public String getFileTitleOrName() {
if (fileTitle != null) {
return fileTitle;
}
return file;
}
public boolean isBundle() {
if (inputStream == null) {
File fileObj = new File(file);
String fileName = fileObj.getName();
if (fileName.startsWith("asdec_") && fileName.endsWith(".tmp")) {
return false;
}
String extension = Path.getExtension(fileObj);
return extension == null || !(extension.equals(".swf") || extension.equals(".gfx"));
}
return false;
}
public SWFBundle getBundle(boolean noCheck, SearchMode searchMode) throws IOException {
if (!isBundle()) {
return null;
}
String extension = Path.getExtension(new File(file));
if (extension != null) {
switch (extension) {
case ".swc":
return new SWC(new File(file));
case ".zip":
return new ZippedSWFBundle(new File(file));
case ".iggy":
return new IggySwfBundle(new File(file));
}
}
return new BinarySWFBundle(new BufferedInputStream(new FileInputStream(file)), noCheck, searchMode);
}
}

View File

@@ -0,0 +1,104 @@
package com.jpexs.decompiler.flash.iggy.conversion;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.SWFBundle;
import com.jpexs.decompiler.flash.iggy.IggyFile;
import com.jpexs.helpers.Helper;
import com.jpexs.helpers.MemoryInputStream;
import com.jpexs.helpers.ReReadableInputStream;
import com.jpexs.helpers.streams.SeekableInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
/**
*
* @author JPEXS
*/
public class IggySwfBundle implements SWFBundle {
private IggyFile iggyFile;
public IggySwfBundle(InputStream is) throws IOException {
this(is, null);
}
public IggySwfBundle(File filename) throws IOException {
this(null, filename);
}
protected IggySwfBundle(InputStream is, File filename) throws IOException {
initBundle(is, filename);
}
protected void initBundle(InputStream is, File filename) throws IOException {
if (filename == null) {
filename = File.createTempFile("bundle", ".iggy");
Helper.saveStream(is, filename);
}
iggyFile = new IggyFile(filename);
}
@Override
public int length() {
return iggyFile.getSwfCount();
}
@Override
public Set<String> getKeys() {
Set<String> ret = new TreeSet<>();
for (int i = 0; i < length(); i++) {
ret.add(iggyFile.getSwfName(i));
}
return ret;
}
private int keyToSwfIndex(String key) {
for (int i = 0; i < length(); i++) {
if (key.equals(iggyFile.getSwfName(i))) {
return i;
}
}
throw new IllegalArgumentException("Key " + key + " does not exist!");
}
@Override
public SeekableInputStream getSWF(String key) throws IOException {
SWF swf = IggyToSwfConvertor.getSwf(iggyFile, keyToSwfIndex(key));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
swf.saveTo(baos);
MemoryInputStream mis = new MemoryInputStream(baos.toByteArray());
return mis;
}
@Override
public Map<String, SeekableInputStream> getAll() throws IOException {
Map<String, SeekableInputStream> ret = new HashMap<>();
for (String key : getKeys()) {
ret.put(key, getSWF(key));
}
return ret;
}
@Override
public String getExtension() {
return "iggy";
}
@Override
public boolean isReadOnly() {
return true; //TODO: make writable
}
@Override
public boolean putSWF(String key, InputStream is) throws IOException {
throw new UnsupportedOperationException("Not supported yet.");
}
}