package com.qy.utils;

import java.awt.Desktop;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

import org.json.JSONArray;
import org.json.JSONObject;

import com.qy.ui.AppMain;

public class JarToAJar {
	private static JSONObject json;



	public static void start(JSONObject json) {
		JarToAJar.json=json;
		JSONArray array=json.getJSONArray("array");
		String inName=json.isNull("input")?"com.zip":json.getString("input");
		String outName=json.isNull("out")?"rx.jar":json.getString("out")+array.getString(Integer.parseInt(json.getString("switch"))-1)+".jar";
		new JarToAJar(inName,outName);
	}

	public JarToAJar(String inName,String outName) {
		// TODO Auto-generated constructor stub
		try {
			String dx=json.isNull("dx")?"dx.jar":json.getString("dx");
			File outFile=new File(inName);
			if(outFile.exists())
				outFile.delete();
			Tools.toZip(json.getString(json.getString("switch")), new File(inName), true,true);
			Tools.toAJar(dx,inName, outName);
			System.out.println(outName);
			if(AppMain.isOpenWindows)
				Desktop.getDesktop().open(new File(json.getString("out")));
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}


}
