/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package de.nplusc.izc.InstallPak;

import de.nplusc.izc.tools.IOtools.FileTK;
import de.nplusc.izc.tools.IOtools.ZipFileHandler;
import de.nplusc.izc.tools.UiToolz.UiTools;
import de.nplusc.izc.tools.baseTools.Lock;
import de.nplusc.izc.tools.baseTools.Tools;
import java.awt.Point;

/**
 *
 * @author LH
 */
public class BundleVerifyGui extends javax.swing.JFrame
{
    public String zf;
    /**
     * Creates new form BundleVerifyGui
     * @param zf das FIle des Bundles
     */
    public BundleVerifyGui(String zfl)
    {
        zf=zfl;
        z=new ZipFileHandler(zf);
        initComponents();
        readInBundle();//file ist im zipfilehandlerdefiniert;
        updatePosition();
        lblVID.setText(InstallManager.VERSION_GUI_TXT);
    }
        private void updatePosition()
    {
        Point p = new Point(ModeSel.topleft_coords_x, ModeSel.topleft_coords_y);
        setLocation(p);
    }
    private boolean isDiskMode=false;
    private String packfileForInstall;
    private void readInBundle()
    {
        String[][] bundledata = izsetupReader.ConvertToSysSpezSetupFile(z.getStringEntry("bundle.izmeta"), false, true, "");
        String baseDir = Tools.processEnvVarsinLine("%temp%\\iZsetup");//sird aktualisiert wenn ein UnCopy-Bundle erkannt wurde
        for (String[] line : bundledata)
        {
            System.err.println(line);
            String[] linedata= line;
            if(linedata[1].equalsIgnoreCase("meta:isZipped")&&linedata[2].equalsIgnoreCase("false"))
            {
                Tools.DebugHelperPrint("Disk?", true, "iZsetup.enableFinerDebug");
                isDiskMode=true;
                baseDir=FileTK.getFilePath(zf);
                unpax.setText("Module auswählen");
                monitorBar.setVisible(false);
            }
            if(linedata[1].equalsIgnoreCase("extractSize"))
               lblSize.setText(UiTools.convertToSizeString(Long.valueOf(linedata[2])));
            if(linedata[1].equalsIgnoreCase("Description"))
               lblDesc.setText(linedata[2]);
            if(linedata[1].equalsIgnoreCase("bundlename"))
               lblName.setText(linedata[2]);
            if(linedata[1].equalsIgnoreCase("packagedata"))
            {
                packfileForInstall = baseDir+"\\"+linedata[2];
                System.err.println("InstPk>>"+packfileForInstall);
            }
        }
    }
    
    
    
    /**
     * 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()
    {

        jSeparator2 = new javax.swing.JSeparator();
        jSeparator3 = new javax.swing.JSeparator();
        monitorBar = new javax.swing.JProgressBar();
        lblName = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        lblDesc = new javax.swing.JLabel();
        lblSize = new javax.swing.JLabel();
        lblVID = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jSeparator4 = new javax.swing.JSeparator();
        unpax = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);
        addComponentListener(new java.awt.event.ComponentAdapter()
        {
            public void componentMoved(java.awt.event.ComponentEvent evt)
            {
                formComponentMoved(evt);
            }
        });

        lblName.setText("Name");

        jLabel2.setText("Beschreibung");

        jLabel3.setText("Speicherverbrauch");

        lblDesc.setText("jLabel5");

        lblSize.setText("jLabel6");

        lblVID.setText("izSetup 1.0.0 (c) 2012 iZc");

        unpax.setText("Entpacken und Module auswählen");
        unpax.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                unpaxActionPerformed(evt);
            }
        });

        jLabel7.setText("Status des Entpackens");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(35, 35, 35)
                                .addComponent(jLabel3)
                                .addGap(18, 18, 18))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addContainerGap()
                                .addComponent(jLabel2)
                                .addGap(35, 35, 35)))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblDesc, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(lblSize, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, Short.MAX_VALUE))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(90, 90, 90)
                        .addComponent(jLabel7)))
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jSeparator4, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblVID)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jSeparator1))
                    .addComponent(monitorBar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(unpax, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(0, 475, Short.MAX_VALUE)
                .addComponent(lblName)
                .addGap(350, 350, 350))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(lblName)
                .addGap(63, 63, 63)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblDesc)
                    .addComponent(jLabel2))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(lblSize))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 74, Short.MAX_VALUE)
                .addComponent(unpax)
                .addGap(1, 1, 1)
                .addComponent(jLabel7)
                .addGap(3, 3, 3)
                .addComponent(monitorBar, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lblVID)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jSeparator4, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(11, 11, 11))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    ZipFileHandler z;
    Lock l = new Lock();
    private void unpaxActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_unpaxActionPerformed
    {//GEN-HEADEREND:event_unpaxActionPerformed

        if(!isDiskMode)
        {
            Tools.DebugHelperPrint("Diskfile Detected", true, "iZsetup.enableCoreDebug");
            try
            {
                l.lock();
            }
            catch (InterruptedException ex)
            {
                ex.printStackTrace();
            }
            new Thread(new Runnable()
            {
                @SuppressWarnings("ResultOfObjectAllocationIgnored")
                @Override
                public void run()
                {
                    
                    z.extractAllToDiskWithMonitoringProgressbar(Tools.processEnvVarsinLine("%temp%\\iZsetup"), monitorBar);
                    l.unlock();
                }
            }).start();
        }
        try
        {
            l.lock();
            l.unlock();
        }
        catch (InterruptedException ex)
        {
        }
        ModeSel.filePath=packfileForInstall;//wird von dem anderen Modul verarbeitet
        new Thread(new Runnable()
        {
            @SuppressWarnings("ResultOfObjectAllocationIgnored")
            @Override
            public void run()
            {
                new PackagerGUI().setVisible(true);
            }
        }).start();
        setVisible(false);
        
    }//GEN-LAST:event_unpaxActionPerformed

    private void formComponentMoved(java.awt.event.ComponentEvent evt)//GEN-FIRST:event_formComponentMoved
    {//GEN-HEADEREND:event_formComponentMoved
        ModeSel.topleft_coords_x = getLocation().x;
        ModeSel.topleft_coords_y = getLocation().x;
    }//GEN-LAST:event_formComponentMoved

    /**
     * @param args the command line arguments
     */
    public static void main(String args[])
    {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try
        {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels())
            {
                if ("Nimbus".equals(info.getName()))
                {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        }
        catch (ClassNotFoundException ex)
        {
            java.util.logging.Logger.getLogger(BundleVerifyGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        catch (InstantiationException ex)
        {
            java.util.logging.Logger.getLogger(BundleVerifyGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        catch (IllegalAccessException ex)
        {
            java.util.logging.Logger.getLogger(BundleVerifyGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        catch (javax.swing.UnsupportedLookAndFeelException ex)
        {
            java.util.logging.Logger.getLogger(BundleVerifyGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable()
        {
            public void run()
            {
                System.err.println("FIFO");
                //new BundleVerifyGui("D:\\\\zip\\\\test.zip").setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JLabel lblDesc;
    private javax.swing.JLabel lblName;
    private javax.swing.JLabel lblSize;
    private javax.swing.JLabel lblVID;
    private javax.swing.JProgressBar monitorBar;
    private javax.swing.JButton unpax;
    // End of variables declaration//GEN-END:variables
}
