Java tutorial
/* * PSXperia Converter Tool - Logging * Copyright (C) 2011 Yifan Lu (http://yifan.lu/) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package com.yifanlu.PSXperiaTool.Interface; import com.android.sdklib.internal.build.SignedJarBuilder; import com.yifanlu.PSXperiaTool.Extractor.CrashBandicootExtractor; import com.yifanlu.PSXperiaTool.Logger; import com.yifanlu.PSXperiaTool.PSXperiaTool; import com.yifanlu.PSXperiaTool.ProgressMonitor; import org.apache.commons.io.FileUtils; import javax.imageio.ImageIO; import javax.swing.*; import java.awt.image.BufferedImage; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintStream; import java.net.URISyntaxException; import java.security.GeneralSecurityException; import java.util.InputMismatchException; import java.util.Properties; public class GUI extends javax.swing.JFrame { /** * Creates new form GUI */ public GUI() { initComponents(); } /** * This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { tabbedPane = new javax.swing.JTabbedPane(); informationPanel = new javax.swing.JPanel(); licenseCheck1 = new javax.swing.JCheckBox(); licenseCheck2 = new javax.swing.JCheckBox(); licenseCheck3 = new javax.swing.JCheckBox(); licenseCheck4 = new javax.swing.JCheckBox(); textScrollPane = new javax.swing.JScrollPane(); licenseText = new javax.swing.JTextArea(); extractPanel = new javax.swing.JPanel(); extractInformation = new javax.swing.JLabel(); apkFileLabel = new javax.swing.JLabel(); apkFileInput = new javax.swing.JTextField(); zpakFileInput = new javax.swing.JTextField(); extractOutputInput = new javax.swing.JTextField(); zpakFileLabel = new javax.swing.JLabel(); extractOutputLabel = new javax.swing.JLabel(); chooseZpakFile = new javax.swing.JButton(); chooseApkFile = new javax.swing.JButton(); chooseOutputDir = new javax.swing.JButton(); extractProgress = new javax.swing.JProgressBar(); extractButton = new javax.swing.JButton(); extractStatus = new javax.swing.JLabel(); createPanel = new javax.swing.JPanel(); chooseData = new javax.swing.JButton(); dataInput = new javax.swing.JTextField(); dataLabel = new javax.swing.JLabel(); isoLabel = new javax.swing.JLabel(); isoInput = new javax.swing.JTextField(); chooseIso = new javax.swing.JButton(); chooseIcon = new javax.swing.JButton(); convertOutputInput = new javax.swing.JTextField(); convertOutputLabel = new javax.swing.JLabel(); chooseConvertOutput = new javax.swing.JButton(); convertSeparator = new javax.swing.JSeparator(); loadXmlButton = new javax.swing.JButton(); gameInformationLabel = new javax.swing.JLabel(); titleIdLabel = new javax.swing.JLabel(); titleIdInput = new javax.swing.JTextField(); nameInput = new javax.swing.JTextField(); nameLabel = new javax.swing.JLabel(); developerInput = new javax.swing.JTextField(); developerLabel = new javax.swing.JLabel(); publisherLabel = new javax.swing.JLabel(); publisherInput = new javax.swing.JTextField(); descriptionLabel = new javax.swing.JLabel(); descriptionTextPane = new javax.swing.JScrollPane(); descriptionTextInput = new javax.swing.JTextArea(); convertProgress = new javax.swing.JProgressBar(); parentalRatingLabel = new javax.swing.JLabel(); parentalRatingInput = new javax.swing.JTextField(); storeTypeLabel = new javax.swing.JLabel(); storeTypeInput = new javax.swing.JTextField(); analogModeCheckbox = new javax.swing.JCheckBox(); convertButton = new javax.swing.JButton(); getTitleIdButton = new javax.swing.JButton(); iconImagePreview = new javax.swing.JLabel(); convertStatus = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("PSXperia Tool"); setName("PSXperia Tool"); // NOI18N setPreferredSize(new java.awt.Dimension(800, 540)); setResizable(false); setSize(new java.awt.Dimension(800, 540)); addWindowListener(new java.awt.event.WindowAdapter() { public void windowOpened(java.awt.event.WindowEvent evt) { formWindowOpened(evt); } }); tabbedPane.setPreferredSize(new java.awt.Dimension(800, 530)); licenseCheck1.setText("Yes, I own a Xperia Play and the Crash Bandicoot APK"); licenseCheck2.setText("Yes, I own the game(s) I will convert and have permission to use them"); licenseCheck3.setText("Yes, I will not distribute/redistribute any of the files generated by this tool"); licenseCheck4.setText("Yes, I understand this is a free tool and does not come with any warranties"); licenseText.setColumns(20); licenseText.setEditable(false); licenseText.setLineWrap(true); licenseText.setRows(5); licenseText.setText( "This tool is designed to allow you to convert PSX game(s) that you OWN and have permission to USE on your Android phone by modifying the files from the \"Crash Bandicoot\" game that is included with the Xperia Play. You must own these files too and the phone to obtain the necessary files. Please understand that piracy hurts the game industry and prevents developers from earning money for their hard work, so do not distribute any files you create with this tool. Finally, know that this tool is completely free and open source and should not be sold as is or part of any package. If you understand all of this, check the boxes and highlight my name below to enable the tool.\n\n-Yifan Lu\nhttp://yifan.lu/\nhttp://github.com/yifanlu/PSXperia\n"); licenseText.setWrapStyleWord(true); licenseText.addCaretListener(new javax.swing.event.CaretListener() { public void caretUpdate(javax.swing.event.CaretEvent evt) { licenseTextCaretUpdate(evt); } }); textScrollPane.setViewportView(licenseText); org.jdesktop.layout.GroupLayout informationPanelLayout = new org.jdesktop.layout.GroupLayout( informationPanel); informationPanel.setLayout(informationPanelLayout); informationPanelLayout.setHorizontalGroup(informationPanelLayout .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(informationPanelLayout.createSequentialGroup().addContainerGap().add(informationPanelLayout .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(textScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 739, Short.MAX_VALUE) .add(licenseCheck4).add(licenseCheck3).add(licenseCheck2).add(licenseCheck1)) .addContainerGap())); informationPanelLayout.setVerticalGroup(informationPanelLayout .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(org.jdesktop.layout.GroupLayout.TRAILING, informationPanelLayout.createSequentialGroup() .addContainerGap() .add(textScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 328, Short.MAX_VALUE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED).add(licenseCheck1) .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED).add(licenseCheck2) .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED).add(licenseCheck3) .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED).add(licenseCheck4) .addContainerGap())); tabbedPane.addTab("Information", informationPanel); java.util.ResourceBundle bundle = java.util.ResourceBundle .getBundle("com/yifanlu/PSXperiaTool/Interface/Strings"); // NOI18N extractInformation.setText(bundle.getString("extract.directions")); // NOI18N apkFileLabel.setText(bundle.getString("extract.apkfile")); // NOI18N zpakFileLabel.setText(bundle.getString("extract.zpakfile")); // NOI18N extractOutputLabel.setText(bundle.getString("extract.output")); // NOI18N chooseZpakFile.setText(bundle.getString("extract.choose")); // NOI18N chooseZpakFile.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { chooseZpakFileActionPerformed(evt); } }); chooseApkFile.setText(bundle.getString("extract.choose")); // NOI18N chooseApkFile.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { chooseApkFileActionPerformed(evt); } }); chooseOutputDir.setText(bundle.getString("extract.choose")); // NOI18N chooseOutputDir.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { chooseOutputDirActionPerformed(evt); } }); extractButton.setText(bundle.getString("extract.extract")); // NOI18N extractButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { extractButtonActionPerformed(evt); } }); org.jdesktop.layout.GroupLayout extractPanelLayout = new org.jdesktop.layout.GroupLayout(extractPanel); extractPanel.setLayout(extractPanelLayout); extractPanelLayout.setHorizontalGroup(extractPanelLayout .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(org.jdesktop.layout.GroupLayout.TRAILING, extractPanelLayout.createSequentialGroup() .addContainerGap() .add(extractPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) .add(org.jdesktop.layout.GroupLayout.LEADING, extractStatus, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 739, Short.MAX_VALUE) .add(org.jdesktop.layout.GroupLayout.LEADING, extractInformation, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 739, Short.MAX_VALUE) .add(extractPanelLayout.createSequentialGroup().add(extractPanelLayout .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(org.jdesktop.layout.GroupLayout.TRAILING, extractPanelLayout .createSequentialGroup() .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 5, Short.MAX_VALUE) .add(extractPanelLayout .createParallelGroup( org.jdesktop.layout.GroupLayout.LEADING) .add(extractOutputLabel).add(zpakFileLabel) .add(apkFileLabel)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(extractPanelLayout .createParallelGroup( org.jdesktop.layout.GroupLayout.TRAILING, false) .add(org.jdesktop.layout.GroupLayout.LEADING, zpakFileInput) .add(org.jdesktop.layout.GroupLayout.LEADING, extractOutputInput) .add(org.jdesktop.layout.GroupLayout.LEADING, apkFileInput, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 562, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))) .add(org.jdesktop.layout.GroupLayout.TRAILING, extractProgress, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 639, Short.MAX_VALUE)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(extractPanelLayout .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(extractButton).add(chooseOutputDir).add(chooseApkFile) .add(chooseZpakFile)))) .addContainerGap())); extractPanelLayout.setVerticalGroup(extractPanelLayout .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(extractPanelLayout.createSequentialGroup().addContainerGap() .add(extractInformation, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(18, 18, 18) .add(extractPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(extractPanelLayout .createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(apkFileInput, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(chooseApkFile)) .add(apkFileLabel)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(extractPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(extractPanelLayout .createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(zpakFileInput, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(chooseZpakFile)) .add(zpakFileLabel)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(extractPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(extractPanelLayout .createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(extractOutputInput, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(chooseOutputDir)) .add(extractOutputLabel)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 167, Short.MAX_VALUE) .add(extractPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) .add(extractProgress, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(extractButton)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(extractStatus, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 15, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addContainerGap())); extractInformation.getAccessibleContext().setAccessibleName(bundle.getString("extractDirections")); // NOI18N tabbedPane.addTab("Extract", extractPanel); chooseData.setText(bundle.getString("convert.choose")); // NOI18N chooseData.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { chooseDataActionPerformed(evt); } }); dataInput.setToolTipText(bundle.getString("convert.extracted_data.tooltip")); // NOI18N dataLabel.setText(bundle.getString("convert.extracted_data")); // NOI18N isoLabel.setText(bundle.getString("convert.iso_input")); // NOI18N chooseIso.setText(bundle.getString("convert.choose")); // NOI18N chooseIso.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { chooseIsoActionPerformed(evt); } }); chooseIcon.setText("Change Icon"); chooseIcon.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { chooseIconActionPerformed(evt); } }); convertOutputLabel.setText(bundle.getString("convert.output_directory")); // NOI18N chooseConvertOutput.setText(bundle.getString("convert.choose")); // NOI18N chooseConvertOutput.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { chooseConvertOutputActionPerformed(evt); } }); loadXmlButton.setText(bundle.getString("convert.load_xml")); // NOI18N loadXmlButton.setToolTipText(bundle.getString("common.disabled_control")); // NOI18N loadXmlButton.setEnabled(false); gameInformationLabel.setText(bundle.getString("convert.game_information")); // NOI18N titleIdLabel.setText(bundle.getString("convert.title_id")); // NOI18N titleIdInput.setToolTipText(bundle.getString("convert.title_id.tooltip")); // NOI18N nameInput.setToolTipText(bundle.getString("convert.name.tooltip")); // NOI18N nameLabel.setText(bundle.getString("convert.name")); // NOI18N developerInput.setToolTipText(bundle.getString("convert.developer.tooltip")); // NOI18N developerLabel.setText(bundle.getString("convert.developer")); // NOI18N publisherLabel.setText(bundle.getString("convert.publisher")); // NOI18N publisherInput.setToolTipText(bundle.getString("convert.publisher.tooltip")); // NOI18N descriptionLabel.setText("Description:"); descriptionTextInput.setColumns(20); descriptionTextInput.setLineWrap(true); descriptionTextInput.setRows(5); descriptionTextInput.setWrapStyleWord(true); descriptionTextPane.setViewportView(descriptionTextInput); parentalRatingLabel.setText(bundle.getString("convert.parental_rating")); // NOI18N parentalRatingInput.setToolTipText(bundle.getString("convert.parental_rating.tooltip")); // NOI18N storeTypeLabel.setText(bundle.getString("convert.store_type")); // NOI18N storeTypeInput.setToolTipText(bundle.getString("convert.store_type.tooltip")); // NOI18N analogModeCheckbox.setText(bundle.getString("convert.analog_mode")); // NOI18N analogModeCheckbox.setToolTipText(bundle.getString("convert.analog_mode.tooltip")); // NOI18N convertButton.setText(bundle.getString("convert.convert")); // NOI18N convertButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { convertButtonActionPerformed(evt); } }); getTitleIdButton.setText(bundle.getString("convert.get_title_id")); // NOI18N getTitleIdButton.setToolTipText(bundle.getString("common.disabled_control")); // NOI18N getTitleIdButton.setEnabled(false); iconImagePreview.setBorder(javax.swing.BorderFactory.createEtchedBorder()); org.jdesktop.layout.GroupLayout createPanelLayout = new org.jdesktop.layout.GroupLayout(createPanel); createPanel.setLayout(createPanelLayout); createPanelLayout.setHorizontalGroup(createPanelLayout .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(org.jdesktop.layout.GroupLayout.TRAILING, createPanelLayout.createSequentialGroup() .addContainerGap() .add(createPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) .add(org.jdesktop.layout.GroupLayout.LEADING, convertStatus, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 739, Short.MAX_VALUE) .add(org.jdesktop.layout.GroupLayout.LEADING, createPanelLayout.createSequentialGroup().add(createPanelLayout .createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) .add(org.jdesktop.layout.GroupLayout.LEADING, createPanelLayout .createSequentialGroup() .add(createPanelLayout .createParallelGroup( org.jdesktop.layout.GroupLayout.LEADING) .add(isoLabel).add(dataLabel) .add(convertOutputLabel)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(createPanelLayout .createParallelGroup( org.jdesktop.layout.GroupLayout.LEADING) .add(convertOutputInput, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 332, Short.MAX_VALUE) .add(isoInput, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 332, Short.MAX_VALUE) .add(dataInput, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 332, Short.MAX_VALUE)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(createPanelLayout .createParallelGroup( org.jdesktop.layout.GroupLayout.LEADING) .add(chooseData).add(chooseIso) .add(chooseConvertOutput))) .add(org.jdesktop.layout.GroupLayout.LEADING, convertSeparator, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 552, Short.MAX_VALUE) .add(createPanelLayout.createSequentialGroup() .add(gameInformationLabel) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 123, Short.MAX_VALUE) .add(getTitleIdButton) .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) .add(loadXmlButton)) .add(org.jdesktop.layout.GroupLayout.LEADING, createPanelLayout .createSequentialGroup() .add(createPanelLayout .createParallelGroup( org.jdesktop.layout.GroupLayout.LEADING) .add(nameLabel).add(developerLabel) .add(descriptionLabel)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(createPanelLayout .createParallelGroup( org.jdesktop.layout.GroupLayout.LEADING) .add(descriptionTextPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 465, Short.MAX_VALUE) .add(createPanelLayout.createSequentialGroup().add( nameInput, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 235, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap( org.jdesktop.layout.LayoutStyle.RELATED) .add(titleIdLabel) .addPreferredGap( org.jdesktop.layout.LayoutStyle.RELATED) .add(titleIdInput, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 160, Short.MAX_VALUE)) .add(createPanelLayout.createSequentialGroup().add( developerInput, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 149, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap( org.jdesktop.layout.LayoutStyle.RELATED) .add(publisherLabel) .addPreferredGap( org.jdesktop.layout.LayoutStyle.RELATED) .add(publisherInput, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 238, Short.MAX_VALUE))))) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(createPanelLayout .createParallelGroup( org.jdesktop.layout.GroupLayout.LEADING) .add(iconImagePreview, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 175, Short.MAX_VALUE) .add(createPanelLayout .createParallelGroup( org.jdesktop.layout.GroupLayout.LEADING, false) .add(org.jdesktop.layout.GroupLayout.TRAILING, chooseIcon, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .add(parentalRatingLabel).add(parentalRatingInput) .add(storeTypeLabel).add(storeTypeInput)) .add(analogModeCheckbox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 174, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))) .add(createPanelLayout.createSequentialGroup() .add(convertProgress, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 637, Short.MAX_VALUE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED).add(convertButton) .add(2, 2, 2))) .addContainerGap())); createPanelLayout.setVerticalGroup(createPanelLayout .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(createPanelLayout.createSequentialGroup().addContainerGap().add(createPanelLayout .createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) .add(createPanelLayout.createSequentialGroup() .add(createPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(createPanelLayout .createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(chooseData).add(dataInput, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .add(dataLabel)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(createPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(createPanelLayout .createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(isoInput, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(chooseIso)) .add(isoLabel)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(createPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(convertOutputLabel) .add(createPanelLayout .createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(convertOutputInput, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(chooseConvertOutput))) .add(18, 18, 18) .add(convertSeparator, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 12, Short.MAX_VALUE) .add(createPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(loadXmlButton).add(gameInformationLabel).add(getTitleIdButton))) .add(iconImagePreview, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE)) .add(18, 18, 18) .add(createPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(titleIdInput, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(titleIdLabel) .add(nameInput, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(chooseIcon).add(nameLabel)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(createPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(createPanelLayout.createSequentialGroup().add(parentalRatingLabel) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(parentalRatingInput, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(storeTypeLabel) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(storeTypeInput, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(analogModeCheckbox)) .add(createPanelLayout.createSequentialGroup().add(createPanelLayout .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(developerLabel) .add(developerInput, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(publisherLabel).add(publisherInput, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .add(18, 18, 18) .add(createPanelLayout .createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(descriptionTextPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 93, Short.MAX_VALUE) .add(descriptionLabel)))) .add(18, 18, 18) .add(createPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) .add(convertButton) .add(convertProgress, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(convertStatus, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 14, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addContainerGap())); tabbedPane.addTab("Convert", createPanel); org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(tabbedPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 800, Short.MAX_VALUE)); layout.setVerticalGroup(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .add(tabbedPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 528, Short.MAX_VALUE) .addContainerGap())); pack(); }// </editor-fold>//GEN-END:initComponents private void setFieldsFromProperties(Properties settings) { nameInput.setText(settings.getProperty("KEY_DISPLAY_NAME")); titleIdInput.setText(settings.getProperty("KEY_TITLE_ID")); developerInput.setText(settings.getProperty("KEY_DEVELOPER")); publisherInput.setText(settings.getProperty("KEY_PUBLISHER")); parentalRatingInput.setText(settings.getProperty("KEY_PARENTAL_RATING")); storeTypeInput.setText(settings.getProperty("KEY_STORE_TYPE")); descriptionTextInput.setText(settings.getProperty("KEY_DESCRIPTION")); analogModeCheckbox.setSelected(settings.getProperty("KEY_ANALOG_MODE").equals("YES") ? true : false); mIconImage = (File) settings.get("IconFile"); } private void setPropertiesFromFields(Properties settings) { settings.setProperty("KEY_DISPLAY_NAME", nameInput.getText()); settings.setProperty("KEY_TITLE_ID", titleIdInput.getText()); settings.setProperty("KEY_DEVELOPER", developerInput.getText()); settings.setProperty("KEY_PUBLISHER", publisherInput.getText()); settings.setProperty("KEY_PARENTAL_RATING", parentalRatingInput.getText()); settings.setProperty("KEY_STORE_TYPE", storeTypeInput.getText()); settings.setProperty("KEY_DESCRIPTION", descriptionTextInput.getText()); settings.setProperty("KEY_ANALOG_MODE", analogModeCheckbox.isSelected() ? "YES" : "NO"); if (mIconImage != null) settings.put("IconFile", mIconImage); } private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened try { tabbedPane.setEnabled(false); // Start logging Logger.setGUIFrame(this); Logger.setLevel(Logger.DEBUG); try { File log = new File(mCurrentDir, "psxperia.log"); if (log.exists()) log.delete(); log.createNewFile(); PrintStream stream = new PrintStream(log); Logger.setOutput(stream); } catch (IOException ex) { Logger.error("Cannot create log file"); } dataInput.setText((new File(mCurrentDir, "/data")).getPath()); extractOutputInput.setText((new File(mCurrentDir, "/data")).getPath()); convertOutputInput.setText((new File(mCurrentDir, "/output")).getPath()); if ((new File(mCurrentDir, "LICENSED")).exists()) { tabbedPane.setEnabled(true); tabbedPane.setSelectedIndex(2); } mSettings = new Properties(); mSettings.loadFromXML(PSXperiaTool.class.getResourceAsStream("/resources/defaults.xml")); setFieldsFromProperties(mSettings); mThis = this; } catch (IOException ex) { Logger.error("Cannot read default settings."); ex.printStackTrace(); } }//GEN-LAST:event_formWindowOpened private void licenseTextCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_licenseTextCaretUpdate String selected = licenseText.getSelectedText(); if (selected != null && selected.endsWith("Yifan Lu")) { if (licenseCheck1.isSelected() && licenseCheck2.isSelected() && licenseCheck3.isSelected() & licenseCheck4.isSelected()) { tabbedPane.setEnabled(true); try { FileOutputStream out = new FileOutputStream(new File(mCurrentDir, "LICENSED")); out.write(1); out.close(); } catch (IOException ex) { Logger.error("Cannot save license status."); ex.printStackTrace(); } } } }//GEN-LAST:event_licenseTextCaretUpdate private void chooseApkFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseApkFileActionPerformed FILE_CHOOSER.setFileSelectionMode(JFileChooser.FILES_ONLY); int returnVal = FILE_CHOOSER.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = FILE_CHOOSER.getSelectedFile(); apkFileInput.setText(file.getPath()); } }//GEN-LAST:event_chooseApkFileActionPerformed private void chooseZpakFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseZpakFileActionPerformed FILE_CHOOSER.setFileSelectionMode(JFileChooser.FILES_ONLY); int returnVal = FILE_CHOOSER.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = FILE_CHOOSER.getSelectedFile(); zpakFileInput.setText(file.getPath()); } }//GEN-LAST:event_chooseZpakFileActionPerformed private void chooseOutputDirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseOutputDirActionPerformed FILE_CHOOSER.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = FILE_CHOOSER.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = FILE_CHOOSER.getSelectedFile(); extractOutputInput.setText(file.getPath()); dataInput.setText(file.getPath()); } }//GEN-LAST:event_chooseOutputDirActionPerformed private void chooseDataActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseDataActionPerformed FILE_CHOOSER.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = FILE_CHOOSER.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = FILE_CHOOSER.getSelectedFile(); extractOutputInput.setText(file.getPath()); dataInput.setText(file.getPath()); } }//GEN-LAST:event_chooseDataActionPerformed private void chooseIconActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseIconActionPerformed FILE_CHOOSER.setFileSelectionMode(JFileChooser.FILES_ONLY); int returnVal = FILE_CHOOSER.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = FILE_CHOOSER.getSelectedFile(); if (!file.getName().endsWith(".png")) { Logger.warning("Invalid PNG image."); return; } try { BufferedImage image = ImageIO.read(file); iconImagePreview.setIcon(new ImageIcon(image)); mIconImage = file; } catch (IOException ex) { Logger.error("Cannot load image!"); ex.printStackTrace(); } } }//GEN-LAST:event_chooseIconActionPerformed private void chooseIsoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseIsoActionPerformed FILE_CHOOSER.setFileSelectionMode(JFileChooser.FILES_ONLY); int returnVal = FILE_CHOOSER.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = FILE_CHOOSER.getSelectedFile(); isoInput.setText(file.getPath()); } }//GEN-LAST:event_chooseIsoActionPerformed private void chooseConvertOutputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseConvertOutputActionPerformed FILE_CHOOSER.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = FILE_CHOOSER.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = FILE_CHOOSER.getSelectedFile(); convertOutputInput.setText(file.getPath()); } }//GEN-LAST:event_chooseConvertOutputActionPerformed private void convertButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_convertButtonActionPerformed Runnable run = new Runnable() { public void run() { try { mThis.setEnabled(false); convertButton.setEnabled(false); CommandLine.verifyTitleID(titleIdInput.getText()); setPropertiesFromFields(mSettings); File inputFile = new File(isoInput.getText()); File dataDir = new File(dataInput.getText()); File outputDir = new File(convertOutputInput.getText()); PSXperiaTool tool = new PSXperiaTool(mSettings, inputFile, dataDir, outputDir); ProgressMonitor.ProgressCallback callback = new ProgressMonitor.ProgressCallback() { public void nextStep(String string) { convertStatus.setText(string); } public void stepsTook(int current, int max) { convertProgress.setMaximum(max); convertProgress.setValue(current); } }; tool.setCallback(callback); tool.startBuild(); convertProgress.setValue(0); convertButton.setEnabled(true); mThis.setEnabled(true); } catch (InputMismatchException ex) { Logger.error("Input error: %s", ex.getMessage()); ex.printStackTrace(); } catch (InterruptedException ex) { Logger.error( "Cannot run build commands, are \"aapk\" and \"jarsigner\" in your system's PATH variable? Java says: %s", ex.getMessage()); ex.printStackTrace(); } catch (IOException ex) { Logger.error("Cannot build APK! Java says: %s", ex.getMessage()); ex.printStackTrace(); } catch (GeneralSecurityException ex) { Logger.error("Error signing JAR, Java says: %s", ex.getMessage()); ex.printStackTrace(); } catch (SignedJarBuilder.IZipEntryFilter.ZipAbortException ex) { Logger.error("Error signing JAR, Java says: %s", ex.getMessage()); ex.printStackTrace(); } finally { convertProgress.setValue(0); convertButton.setEnabled(true); mThis.setEnabled(true); } } }; (new Thread(run)).start(); }//GEN-LAST:event_convertButtonActionPerformed private void extractButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_extractButtonActionPerformed Runnable run = new Runnable() { public void run() { try { mThis.setEnabled(false); extractButton.setEnabled(false); File inputApk = new File(apkFileInput.getText()); File inputZpak = new File(zpakFileInput.getText()); File outputDataDir = new File(extractOutputInput.getText()); if (!inputApk.exists()) { Logger.error("Cannot find APK file!"); return; } if (!inputZpak.exists()) { Logger.error("Cannot find ZPAK file!"); return; } CrashBandicootExtractor extract = new CrashBandicootExtractor(inputApk, inputZpak, outputDataDir); ProgressMonitor.ProgressCallback callback = new ProgressMonitor.ProgressCallback() { public void nextStep(String string) { extractStatus.setText(string); } public void stepsTook(int current, int max) { extractProgress.setMaximum(max); extractProgress.setValue(current); } }; extract.setCallback(callback); extract.extractApk(); extractProgress.setValue(0); extractButton.setEnabled(true); mThis.setEnabled(true); } catch (IOException ex) { Logger.error("Cannot extract APK! Java says %s", ex.getMessage()); ex.printStackTrace(); } catch (UnsupportedOperationException ex) { Logger.error("Unsupported exception: %s", ex.getMessage()); ex.printStackTrace(); } catch (Exception ex) { Logger.error("Exception: %s", ex.getMessage()); ex.printStackTrace(); } finally { extractProgress.setValue(0); extractButton.setEnabled(true); mThis.setEnabled(true); } } }; (new Thread(run)).start(); }//GEN-LAST:event_extractButtonActionPerformed /** * @param args the command line arguments */ public static void main(String args[]) { /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new GUI().setVisible(true); } }); } private JFrame mThis; private static final JFileChooser FILE_CHOOSER = new JFileChooser(); private static final File mCurrentDir = new File(new File(".").getAbsolutePath()); private File mIconImage; private Properties mSettings; // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JCheckBox analogModeCheckbox; private javax.swing.JTextField apkFileInput; private javax.swing.JLabel apkFileLabel; private javax.swing.JButton chooseApkFile; private javax.swing.JButton chooseConvertOutput; private javax.swing.JButton chooseData; private javax.swing.JButton chooseIcon; private javax.swing.JButton chooseIso; private javax.swing.JButton chooseOutputDir; private javax.swing.JButton chooseZpakFile; private javax.swing.JButton convertButton; private javax.swing.JTextField convertOutputInput; private javax.swing.JLabel convertOutputLabel; private javax.swing.JProgressBar convertProgress; private javax.swing.JSeparator convertSeparator; private javax.swing.JLabel convertStatus; private javax.swing.JPanel createPanel; private javax.swing.JTextField dataInput; private javax.swing.JLabel dataLabel; private javax.swing.JLabel descriptionLabel; private javax.swing.JTextArea descriptionTextInput; private javax.swing.JScrollPane descriptionTextPane; private javax.swing.JTextField developerInput; private javax.swing.JLabel developerLabel; private javax.swing.JButton extractButton; private javax.swing.JLabel extractInformation; private javax.swing.JTextField extractOutputInput; private javax.swing.JLabel extractOutputLabel; private javax.swing.JPanel extractPanel; private javax.swing.JProgressBar extractProgress; private javax.swing.JLabel extractStatus; private javax.swing.JLabel gameInformationLabel; private javax.swing.JButton getTitleIdButton; private javax.swing.JLabel iconImagePreview; private javax.swing.JPanel informationPanel; private javax.swing.JTextField isoInput; private javax.swing.JLabel isoLabel; private javax.swing.JCheckBox licenseCheck1; private javax.swing.JCheckBox licenseCheck2; private javax.swing.JCheckBox licenseCheck3; private javax.swing.JCheckBox licenseCheck4; private javax.swing.JTextArea licenseText; private javax.swing.JButton loadXmlButton; private javax.swing.JTextField nameInput; private javax.swing.JLabel nameLabel; private javax.swing.JTextField parentalRatingInput; private javax.swing.JLabel parentalRatingLabel; private javax.swing.JTextField publisherInput; private javax.swing.JLabel publisherLabel; private javax.swing.JTextField storeTypeInput; private javax.swing.JLabel storeTypeLabel; private javax.swing.JTabbedPane tabbedPane; private javax.swing.JScrollPane textScrollPane; private javax.swing.JTextField titleIdInput; private javax.swing.JLabel titleIdLabel; private javax.swing.JTextField zpakFileInput; private javax.swing.JLabel zpakFileLabel; // End of variables declaration//GEN-END:variables }