la2launcher.MainFrame.java Source code

Java tutorial

Introduction

Here is the source code for la2launcher.MainFrame.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package la2launcher;

import com.alexkasko.delta.DirDeltaPatcher;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.platform.win32.User32;
import com.sun.jna.platform.win32.WinDef;
import com.sun.jna.platform.win32.WinUser;
import com.sun.jna.ptr.IntByReference;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.RandomAccessFile;
import java.io.StringReader;
import java.io.StringWriter;
import static java.lang.Thread.sleep;
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.nio.file.Files;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Scanner;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import la2launcher.shit.Kernel32;
import la2launcher.shit.W32API;
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;

/**
 *
 * @author user1
 */
public class MainFrame extends javax.swing.JFrame {

    /**
     * Creates new form MaonFrame
     */
    public MainFrame() {
        initComponents();
        new Thread(new ProcWatcher()).start();
        jButton1.grabFocus();
        getRootPane().setDefaultButton(jButton1);

        //  ------
        jButton11.setVisible(false);
        jButton10.setVisible(false);
        new Thread(new Runnable() {
            public void run() {
                try {
                    Thread.sleep(100);
                    jButton11ActionPerformed(null);
                } catch (InterruptedException ex) {
                    Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }).start();
    }

    /**
     * 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() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jTextField1 = new javax.swing.JTextField();
        jButton2 = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jLabel1 = new javax.swing.JLabel();
        jButton4 = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jSplitPane1 = new javax.swing.JSplitPane();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        jPanel4 = new javax.swing.JPanel();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jButton9 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jProgressBar1 = new javax.swing.JProgressBar();
        jScrollPane5 = new javax.swing.JScrollPane();
        jTextArea2 = new javax.swing.JTextArea();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jButton10 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jButton11 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTabbedPane1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                mainTabMouseClicked(evt);
            }
        });

        jTable1.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {

        }, new String[] { "pid", "" }) {
            Class[] types = new Class[] { java.lang.String.class, java.lang.Boolean.class };
            boolean[] canEdit = new boolean[] { false, true };

            public Class getColumnClass(int columnIndex) {
                return types[columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit[columnIndex];
            }
        });
        jScrollPane1.setViewportView(jTable1);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/la2launcher/play.png"))); // NOI18N
        jButton1.setText("? ??");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jTextField1.setText("7");

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/la2launcher/stop.png"))); // NOI18N
        jButton2.setText("  ??");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane2.setViewportView(jTextArea1);

        jLabel1.setText("");

        jButton4.setText("?  ??");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(jPanel1Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addGroup(jPanel1Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup().addComponent(jLabel1)
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(jButton4, javax.swing.GroupLayout.Alignment.LEADING,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jButton2, javax.swing.GroupLayout.Alignment.LEADING,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout
                                                .createSequentialGroup()
                                                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 157,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(jTextField1))
                                        .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING))
                                        .addContainerGap()))));
        jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jButton1).addComponent(jTextField1,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jButton2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jButton4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 222, Short.MAX_VALUE)
                        .addContainerGap()));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout
                .setHorizontalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGap(0, 661, Short.MAX_VALUE)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel2Layout.createSequentialGroup().addContainerGap()
                                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 159,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addContainerGap())));
        jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGap(0, 388, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel2Layout.createSequentialGroup().addContainerGap().addGroup(jPanel2Layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0,
                                        Short.MAX_VALUE)
                                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addContainerGap())));

        jTabbedPane1.addTab(" ", jPanel2);

        jSplitPane1.setDividerLocation(300);

        jTable2.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {

        }, new String[] { "?  ", "?" }) {
            Class[] types = new Class[] { java.lang.String.class, java.lang.Boolean.class };

            public Class getColumnClass(int columnIndex) {
                return types[columnIndex];
            }
        });
        jTable2.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        jScrollPane3.setViewportView(jTable2);

        jSplitPane1.setLeftComponent(jScrollPane3);

        jButton5.setText("     System");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jButton6.setText(" ? ");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jButton7.setText(" ? ");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });

        jButton8.setText("? ");
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });

        jButton9.setText("?");
        jButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton9ActionPerformed(evt);
            }
        });

        jLabel3.setText(" ??");

        jProgressBar1.setName(""); // NOI18N
        jProgressBar1.setStringPainted(true);

        jTextArea2.setColumns(20);
        jTextArea2.setLineWrap(true);
        jTextArea2.setRows(5);
        jTextArea2.setWrapStyleWord(true);
        jScrollPane5.setViewportView(jTextArea2);

        jLabel4.setText("??");

        jLabel5.setText("?");

        jButton10.setText("? ");
        jButton10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton10ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(jPanel4Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel4Layout.createSequentialGroup().addContainerGap()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jScrollPane5, javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE, 335, Short.MAX_VALUE)
                                .addComponent(jButton6, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jButton7, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jButton8, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jButton9, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jProgressBar1, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(jPanel4Layout.createSequentialGroup().addComponent(jLabel4)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jLabel5))
                                .addGroup(jPanel4Layout.createSequentialGroup().addComponent(jLabel3).addGap(0, 0,
                                        Short.MAX_VALUE))
                                .addComponent(jButton10, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addContainerGap()));
        jPanel4Layout.setVerticalGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel4Layout.createSequentialGroup().addContainerGap().addComponent(jButton5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jButton6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jButton7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jButton8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jButton10)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 120, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jButton9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel4).addComponent(jLabel5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 24,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap()));

        jSplitPane1.setRightComponent(jPanel4);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout
                .setHorizontalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 661, Short.MAX_VALUE));
        jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 388, Short.MAX_VALUE));

        jTabbedPane1.addTab(" ", jPanel3);

        jButton3.setText("...");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jLabel2.setText("  ");

        jTextField2.setText("notepad");
        jTextField2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField2ActionPerformed(evt);
            }
        });

        jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/la2launcher/off1.png"))); // NOI18N
        jLabel6.setText("? ?");

        jLabel7.setText(":");

        jButton11.setText("on");
        jButton11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton11ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 62,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                .addGroup(layout.createSequentialGroup().addGap(10, 10, 10).addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jButton11)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel7).addGap(10, 10, 10))
                .addComponent(jTabbedPane1));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addGroup(layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel2)
                        .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jButton3)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel7).addComponent(jButton11))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTabbedPane1)));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

        int c = Integer.valueOf(jTextField1.getText());
        if (c > procLimit) {
            JOptionPane.showMessageDialog(null, " ?? ?.");
            return;
        }
        gamePath = jTextField2.getText();
        new Thread(new Runnable() {
            @Override
            public void run() {
                if (!new File(gamePath + "\\system\\l2.exe").exists()) {
                    JOptionPane.showMessageDialog(MainFrame.this,
                            "?  l2.exe ? . ?/ .");
                    return;
                }
                jButton1.setEnabled(false);
                for (int i = 0; i < c; i++) {
                    try {
                        Process proc = Runtime.getRuntime().exec(gamePath + "\\system\\l2.exe");
                        procs.add(proc);
                        DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel();
                        dtm.addRow(new Object[] { proc.hashCode(), Boolean.TRUE });
                        if (i + 1 < c) {
                            try {
                                Thread.sleep(launchDelay);
                            } catch (Exception ex) {
                                logg("");
                                logg(ex);
                            }
                        }
                    } catch (Exception ex) {
                        logg("");
                        logg(ex);
                    }
                }
                jButton1.setEnabled(true);
            }
        }).start();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        try {
            JFileChooser fc;
            if (gamePath == null || gamePath.trim().equals("")) {
                fc = new JFileChooser();
            } else {
                if (new File(gamePath).isDirectory()) {
                    fc = new JFileChooser(gamePath);
                } else {
                    fc = new JFileChooser();
                }
            }
            fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

            fc.showOpenDialog(this);

            File f = fc.getSelectedFile();

            if (f != null) {
                gamePath = f.getAbsolutePath();
                jTextField2.setText(gamePath);
            }

            boolean systemFound = false;
            for (String fname : f.list()) {
                if (fname.toUpperCase().equals("SYSTEM")) {
                    systemFound = true;
                    break;
                }
            }

            if (!systemFound) {
                JOptionPane.showMessageDialog(this,
                        "?   system.    . ?   ?.");
            }
        } catch (Exception ex) {
            logg("");
            logg(ex);
        }

    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel();
        for (int i = 0; i < dtm.getRowCount(); i++) {
            for (int j = 0; j < procs.size(); j++) {
                if (Boolean.TRUE.equals(dtm.getValueAt(i, 1))) {
                    if ((procs.get(j).hashCode() + "").equals(dtm.getValueAt(i, 0).toString())) {
                        procs.get(j).destroyForcibly();
                    }
                }
            }
        }
    }//GEN-LAST:event_jButton2ActionPerformed

    WinDef.HWND lastHWND;

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed

        DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel();
        int srow = jTable1.getSelectedRow();
        if (srow < 0) {
            return;
        }
        Integer procid = (Integer) dtm.getValueAt(srow, 0);
        for (Process proc : procs) {
            if ((proc.hashCode() + "").equals(procid.toString())) {
                try {
                    Field field = proc.getClass().getDeclaredField("handle");
                    if (!field.isAccessible()) {
                        field.setAccessible(true);
                    }
                    long pid = field.getLong(proc);

                    Kernel32 kernel = Kernel32.INSTANCE;
                    W32API.HANDLE handle = new W32API.HANDLE();
                    handle.setPointer(Pointer.createConstant(pid));
                    long pid_ = kernel.GetProcessId(handle);

                    User32 u32 = User32.INSTANCE;
                    u32.EnumWindows(new WinUser.WNDENUMPROC() {
                        @Override
                        public boolean callback(WinDef.HWND hwnd, Pointer pntr) {
                            char[] windowText = new char[512];
                            u32.GetWindowText(hwnd, windowText, 512);
                            String wText = Native.toString(windowText);

                            if (wText.isEmpty()) {
                                return true;
                            }

                            if (wText.equals("Lineage II")) { //TODO: 111
                                IntByReference pid__ = new IntByReference();
                                u32.GetWindowThreadProcessId(hwnd, pid__);
                                if ((pid__.getValue() + "").equals(pid_ + "")) {
                                    u32.SetForegroundWindow(hwnd);
                                    lastHWND = hwnd;
                                }
                            }
                            return true;
                        }
                    }, null);
                } catch (NoSuchFieldException ex) {
                    Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                } catch (SecurityException ex) {
                    Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IllegalArgumentException ex) {
                    Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IllegalAccessException ex) {
                    Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        processValidation(false);
    }//GEN-LAST:event_jButton5ActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        processValidation(true);
    }//GEN-LAST:event_jButton6ActionPerformed

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
        DefaultTableModel model = (DefaultTableModel) jTable2.getModel();
        for (int i = 0; i < model.getRowCount(); i++) {
            model.setValueAt(true, i, 1);
        }
    }//GEN-LAST:event_jButton7ActionPerformed

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
        DefaultTableModel model = (DefaultTableModel) jTable2.getModel();
        for (int i = 0; i < model.getRowCount(); i++) {
            model.setValueAt(false, i, 1);
        }
    }//GEN-LAST:event_jButton8ActionPerformed

    private long bytesRecieved = 0;
    private long bytesRecievedTotal = 0;
    private long filesProcessed = 0;

    private void extractArchive(String file) {
        try {
            String parentPath = new File(file).getParent();
            Process proc = Runtime.getRuntime().exec("extract.cmd \"" + file + "\" \"" + parentPath + "\"");
            StringWriter writer = new StringWriter();
            IOUtils.copy(proc.getInputStream(), writer, "UTF-8");
            IOUtils.copy(proc.getErrorStream(), writer, "UTF-8");
            String theString = writer.toString();
            System.out.println(theString);
            proc.waitFor();
        } catch (IOException ex) {
            printMsg("? ?? ?  " + file);
        } catch (InterruptedException ex) {
            printMsg("? ?? ?  " + file);
        }
    }

    private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
        final long initTime = new Date().getTime();
        ReentrantLock lock = new ReentrantLock();
        final String patcherUrl = "http://" + updateHost + "/hf//updater.lst.la2";//new ArrayBlockingQueue<Runnable>(10000)
        final ThreadPoolExecutor tpe = new ThreadPoolExecutor(5, 5, 1, TimeUnit.HOURS,
                new ArrayBlockingQueue<Runnable>(10000));
        filesProcessed = 0;
        tpe.execute(new Runnable() {
            @Override
            public void run() {
                jTextArea2.setText("");
                DefaultTableModel model = (DefaultTableModel) jTable2.getModel();
                jProgressBar1.setMinimum(0);
                jProgressBar1.setMaximum(model.getRowCount());
                jProgressBar1.setValue(0);
                jLabel4.setText("0/" + model.getRowCount());
                for (int i = 0; i < model.getRowCount(); i++) {
                    boolean checked = (Boolean) model.getValueAt(i, 1);
                    String fileName = (String) model.getValueAt(i, 0);
                    if (checked) {
                        tpe.execute(new Runnable() {
                            @Override
                            public void run() {

                                final String fileUrl = "http://" + updateHost + "/hf/" + fileName.replace("\\", "/")
                                        + ".la2";
                                try {
                                    printMsg("  " + fileUrl);
                                    File file = new File(gamePath + fileName + ".rar");
                                    File fileExt = new File(gamePath + fileName);

                                    file.getParentFile().mkdirs();
                                    FileOutputStream fos = new FileOutputStream(file);
                                    CloseableHttpClient httpclient = HttpClients.createDefault();
                                    HttpGet httpGet = new HttpGet(fileUrl);
                                    CloseableHttpResponse response1 = httpclient.execute(httpGet);

                                    HttpEntity entity1 = response1.getEntity();
                                    copyStream(entity1.getContent(), fos, new CopyListener() {
                                        @Override
                                        public void transfered(int n) {
                                            bytesRecieved += n;
                                            bytesRecievedTotal += n;
                                        }
                                    });
                                    response1.close();
                                    fos.close();

                                    printMsg("?? : " + fileName);

                                    lock.lock();
                                    //fixBzip2File(file);
                                    //printMsg(" ?");

                                    extractArchive(file.getAbsolutePath());

                                    //BZip2CompressorInputStream bz = new BZip2CompressorInputStream(new FileInputStream(file));
                                    //OutputStream pout = new FileOutputStream(fileExt);
                                    //copyStream(archStream, pout, null);
                                    //pout.close();
                                    //archStream.close();
                                    //jTextArea2.setText(jTextArea2.getText() + "\r\n? : " + fileName);
                                    printMsg("? : " + fileName);
                                    //file.delete();

                                    //                                    File tgt = new File(gamePath + fileName);
                                    //                                    if (tgt.exists()) {
                                    //                                        tgt.delete();
                                    //                                    }
                                    //tgt.getParentFile().mkdirs();
                                    //Files.move(fileExt.toPath(), new File(gamePath + fileName).toPath());
                                    //jTextArea2.setText(jTextArea2.getText() + "\r\n ??: " + fileName);
                                    printMsg(" ??: " + fileName);
                                    jProgressBar1.setIndeterminate(false);
                                    jLabel4.setText((++filesProcessed) + "/" + model.getRowCount());
                                    jProgressBar1.setValue((int) filesProcessed);
                                    lock.unlock();
                                } catch (IOException ex) {
                                    Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                                } catch (Exception ex) {
                                    Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                                }
                            }
                        });
                    }
                }
            }
        });

        jButton5.setEnabled(false);
        jButton6.setEnabled(false);
        jButton7.setEnabled(false);
        jButton8.setEnabled(false);
        jButton9.setEnabled(false);
        jButton10.setEnabled(false);
        jProgressBar1.setIndeterminate(true);
        new Thread() {
            @Override
            public void run() {
                do {
                    long millis = new Date().getTime();
                    try {
                        sleep(300);
                    } catch (InterruptedException ex) {
                        Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    millis = new Date().getTime() - millis;
                    BigDecimal totBig = new BigDecimal(bytesRecievedTotal / (1024 * 1024.0));
                    totBig = totBig.setScale(2, BigDecimal.ROUND_CEILING);
                    jLabel5.setText("?: " + (bytesRecieved / millis) + "KB/s. : "
                            + totBig + " MB");
                    bytesRecieved = 0;
                } while (tpe.getActiveCount() > 0);
                tpe.shutdown();
                jButton5.setEnabled(true);
                jButton6.setEnabled(true);
                jButton7.setEnabled(true);
                jButton8.setEnabled(true);
                jButton9.setEnabled(true);
                jButton10.setEnabled(true);
                jProgressBar1.setIndeterminate(false);
                printMsg("  " + (new Date().getTime() - initTime)
                        + " ?.");
            }
        }.start();
    }//GEN-LAST:event_jButton9ActionPerformed

    private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField2ActionPerformed

    private void mainTabMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mainTabMouseClicked
        jButton1.grabFocus();
    }//GEN-LAST:event_mainTabMouseClicked

    private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed

        Thread th = new Thread() {
            @Override
            public void run() {
                try {
                    jTextArea2.setText(" ");
                    File patch = File.createTempFile("patch", ".zip");
                    patch.deleteOnExit();
                    CloseableHttpClient httpclient = HttpClients.createDefault();
                    HttpGet httpGet = new HttpGet(patchPath);
                    CloseableHttpResponse response1 = httpclient.execute(httpGet);

                    FileOutputStream fos = new FileOutputStream(patch);
                    HttpEntity entity1 = response1.getEntity();
                    copyStream(entity1.getContent(), fos, new CopyListener() {
                        @Override
                        public void transfered(int n) {
                            bytesRecieved += n;
                            bytesRecievedTotal += n;
                        }
                    });
                    response1.close();
                    fos.close();
                    jTextArea2.setText(jTextArea2.getText() + "\r\n ");

                    try {
                        new DirDeltaPatcher().patch(new File(gamePath + "\\system"), patch);
                    } catch (Exception e) {
                        jTextArea2.setText(jTextArea2.getText() + "\r\n" + e);
                        return;
                    }
                    jTextArea2.setText(jTextArea2.getText() + "\r\n? ");

                } catch (IOException ex) {
                    Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        };

        th.start();

        jButton5.setEnabled(false);
        jButton6.setEnabled(false);
        jButton7.setEnabled(false);
        jButton8.setEnabled(false);
        jButton10.setEnabled(false);
        jProgressBar1.setIndeterminate(true);
        new Thread() {
            @Override
            public void run() {
                do {
                    long millis = new Date().getTime();
                    try {
                        sleep(300);
                    } catch (InterruptedException ex) {
                        Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    millis = new Date().getTime() - millis;
                    BigDecimal totBig = new BigDecimal(bytesRecievedTotal / (1024 * 1024.0));
                    totBig = totBig.setScale(2, BigDecimal.ROUND_CEILING);
                    jLabel5.setText("?: " + (bytesRecieved / millis) + "KB/s. : "
                            + totBig + " MB");
                    bytesRecieved = 0;
                } while (th.isAlive());

                jButton5.setEnabled(true);
                jButton6.setEnabled(true);
                jButton7.setEnabled(true);
                jButton8.setEnabled(true);
                jButton10.setEnabled(true);
                jProgressBar1.setIndeterminate(false);
            }
        }.start();

    }//GEN-LAST:event_jButton10ActionPerformed

    private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton11ActionPerformed
        if (!running) {
            pinger = new ServerStatusWatcher();
            new Thread(pinger).start();
            jButton11.setText("off");
            running = true;
        } else {
            pinger.stop();
            jButton11.setText("on");
            running = false;
        }
    }//GEN-LAST:event_jButton11ActionPerformed

    private ServerStatusWatcher pinger;
    private boolean running = false;

    private void processValidation(boolean full) {
        final long initTime = new Date().getTime();
        final String patcherUrl = "http://" + updateHost + "/hf/updater.lst.la2";//new ArrayBlockingQueue<Runnable>(10000)
        final ThreadPoolExecutor tpe = new ThreadPoolExecutor(5, 5, 1, TimeUnit.HOURS,
                new ArrayBlockingQueue<Runnable>(10000));
        tpe.execute(new Runnable() {
            @Override
            public void run() {
                jTextArea2.setText("");
                try {
                    if (full) {
                        jTextArea2.setText(jTextArea2.getText() + "\r\n?  ");
                    } else {
                        jTextArea2.setText(jTextArea2.getText() + "\r\n?  system");
                    }
                    File patcher = File.createTempFile("la2", "la2");
                    patcher.deleteOnExit();
                    File patcherExt = File.createTempFile("la2", "la2");
                    patcherExt.deleteOnExit();
                    FileOutputStream fos = new FileOutputStream(patcher);
                    CloseableHttpClient httpclient = HttpClients.createDefault();
                    HttpGet httpGet = new HttpGet(patcherUrl);
                    CloseableHttpResponse response1 = httpclient.execute(httpGet);

                    HttpEntity entity1 = response1.getEntity();
                    copyStream(entity1.getContent(), fos, null);
                    response1.close();
                    fos.close();
                    jTextArea2.setText(jTextArea2.getText()
                            + "\r\n??  ? ?: " + patcherUrl);

                    fixBzip2File(patcher);
                    jTextArea2.setText(jTextArea2.getText() + "\r\n ?");

                    BZip2CompressorInputStream bz = new BZip2CompressorInputStream(new FileInputStream(patcher));
                    OutputStream pout = new FileOutputStream(patcherExt);
                    copyStream(bz, pout, new CopyListener() {
                        @Override
                        public void transfered(int n) {
                            bytesRecieved += n;
                            bytesRecievedTotal += n;
                        }
                    });
                    pout.close();
                    bz.close();
                    jTextArea2.setText(jTextArea2.getText() + "\r\n? ?");

                    if (full) {
                        jTextArea2.setText(jTextArea2.getText() + "\r\n  ");
                    } else {
                        jTextArea2.setText(jTextArea2.getText()
                                + "\r\n     system");
                    }

                    DefaultTableModel model = (DefaultTableModel) jTable2.getModel();
                    model.setRowCount(0);

                    int filesCount = scanSumFilesCount(patcherExt, full);
                    jProgressBar1.setMinimum(0);
                    jProgressBar1.setMaximum(filesCount);
                    jProgressBar1.setValue(0);
                    jLabel4.setText("0/" + filesCount);
                    scanSumFile(patcherExt, new SumHandler() {

                        private ReentrantLock lock = new ReentrantLock();

                        @Override
                        public void handle(MDNamePair pair) {
                            try {
                                jProgressBar1.setIndeterminate(false);
                                //lock.unlock();
                                tpe.execute(new Runnable() {
                                    @Override
                                    public void run() {
                                        try {
                                            lock.lock();
                                            //printMsg(pair.filename);
                                            String crc = digest(new File(gamePath + pair.filename));
                                            //printMsg("    : " + pair.crc);
                                            //printMsg("   ? ? : " + crc);
                                            if (!pair.crc.equals(crc)) {
                                                DefaultTableModel dtm = (DefaultTableModel) jTable2.getModel();
                                                dtm.addRow(new Object[] { pair.filename, false });
                                            }
                                            jProgressBar1.setValue(jProgressBar1.getValue() + 1);
                                            jLabel4.setText(jProgressBar1.getValue() + "/" + filesCount);
                                            lock.unlock();
                                        } catch (NoSuchAlgorithmException ex) {
                                            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                                        } catch (IOException ex) {
                                            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                                        } finally {
                                            //if (lock.isLocked()) lock.unlock();
                                        }
                                    }
                                });
                            } finally {
                                //if (lock.isLocked()) lock.unlock();
                            }
                        }
                    }, full);
                } catch (IOException ex) {
                    Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });

        jButton5.setEnabled(false);
        jButton6.setEnabled(false);
        jButton7.setEnabled(false);
        jButton8.setEnabled(false);
        jButton10.setEnabled(false);
        jProgressBar1.setIndeterminate(true);
        new Thread() {
            @Override
            public void run() {
                do {
                    long millis = new Date().getTime();
                    try {
                        sleep(300);
                    } catch (InterruptedException ex) {
                        Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    millis = new Date().getTime() - millis;
                    BigDecimal totBig = new BigDecimal(bytesRecievedTotal / (1024 * 1024.0));
                    totBig = totBig.setScale(2, BigDecimal.ROUND_CEILING);
                    jLabel5.setText("?: " + (bytesRecieved / millis) + "KB/s. : "
                            + totBig + " MB");
                    bytesRecieved = 0;
                } while (tpe.getActiveCount() > 0);
                tpe.shutdown();
                jButton5.setEnabled(true);
                jButton6.setEnabled(true);
                jButton7.setEnabled(true);
                jButton8.setEnabled(true);
                jButton10.setEnabled(true);
                jProgressBar1.setIndeterminate(false);
                printMsg("  " + (new Date().getTime() - initTime)
                        + " ?.");
            }
        }.start();
    }

    private synchronized void printMsg(String msg) {
        jTextArea2.setText(jTextArea2.getText() + "\r\n" + msg);
        //        int max = jScrollPane5.getVerticalScrollBar().getMaximum();
        //        System.out.println(max);
        //        jScrollPane5.getVerticalScrollBar().setValue(max);
        jTextArea2.setCaretPosition(jTextArea2.getDocument().getLength());
    }

    interface CopyListener {

        void transfered(int n);
    }

    private void copyStream(InputStream is, OutputStream os, CopyListener listener) throws IOException {
        int n = 0;
        byte buff[] = new byte[1024];
        if (listener == null) {
            while (n >= 0) {
                n = is.read(buff);
                if (n > 0) {
                    os.write(buff, 0, n);
                }
            }
        } else {
            while (n >= 0) {
                n = is.read(buff);
                if (n > 0) {
                    os.write(buff, 0, n);
                    listener.transfered(n);
                }
            }
        }
    }

    private String digest(File f) throws NoSuchAlgorithmException, FileNotFoundException, IOException {
        MessageDigest md = MessageDigest.getInstance("MD5");
        if (f.exists()) {
            FileInputStream fis = new FileInputStream(f);
            int n = 0;
            byte buff[] = new byte[1024];
            while (n >= 0) {
                n = fis.read(buff);
                if (n > 0) {
                    md.update(buff, 0, n);
                }
            }
            fis.close();
        }
        return bytesToHex(md.digest());
    }

    final protected static char[] hexArray = "0123456789ABCDEF".toCharArray();

    private static String bytesToHex(byte[] bytes) {
        char[] hexChars = new char[bytes.length * 2];
        for (int j = 0; j < bytes.length; j++) {
            int v = bytes[j] & 0xFF;
            hexChars[j * 2] = hexArray[v >>> 4];
            hexChars[j * 2 + 1] = hexArray[v & 0x0F];
        }
        return new String(hexChars);
    }

    private class MDNamePair {

        public String filename;
        public String crc;

        public MDNamePair() {
        }

        public MDNamePair(String filename, String crc) {
            this.filename = filename;
            this.crc = crc;
        }
    }

    private interface SumHandler {

        void handle(MDNamePair pair);
    }

    private int scanSumFilesCount(File sums, boolean full) throws FileNotFoundException, IOException {
        FileInputStream fis = new FileInputStream(sums);
        Scanner scn = new Scanner(fis);
        int lc = 0;
        while (scn.hasNextLine()) {
            String line = scn.nextLine();
            if ("#-[Required from required.ini]----------------------------------".equals(line)) {
                break;
            }
            int pipe = line.indexOf('|');
            int nextPipe = line.indexOf('|', pipe + 1);
            String sum = line.substring(0, pipe);
            String name = line.substring(pipe + 1, nextPipe);
            if (!full) {
                if (name.toUpperCase().startsWith("\\SYSTEM")) {
                    lc++;
                }
            } else {
                lc++;
            }
        }
        scn.close();
        fis.close();
        return lc;
    }

    private void scanSumFile(File sums, SumHandler handler, boolean full)
            throws FileNotFoundException, IOException {
        FileInputStream fis = new FileInputStream(sums);
        Scanner scn = new Scanner(fis);
        while (scn.hasNextLine()) {
            String line = scn.nextLine();
            if ("#-[Required from required.ini]----------------------------------".equals(line)) {
                break;
            }
            int pipe = line.indexOf('|');
            int nextPipe = line.indexOf('|', pipe + 1);
            String sum = line.substring(0, pipe);
            String name = line.substring(pipe + 1, nextPipe);
            if (!full) {
                if (name.toUpperCase().startsWith("\\SYSTEM")) {
                    handler.handle(new MDNamePair(name, sum));
                }
            } else {
                handler.handle(new MDNamePair(name, sum));
            }
        }
        scn.close();
        fis.close();
    }

    private void fixBzip2File(File f) throws FileNotFoundException, IOException {
        FileInputStream fis = new FileInputStream(f);

        byte b[] = new byte[5];
        fis.read(b);
        boolean mangled = b[0] == 'l' && b[1] == 'a' && b[2] == '2' && b[3] == 13 && b[4] == 10;
        if (!mangled) {
            System.out.println("  . ?  ?? .");
            return;
        }

        File fix = File.createTempFile("fix", "fix");
        fix.deleteOnExit();
        FileOutputStream fos = new FileOutputStream(fix);

        fos.write("BZh91".getBytes());
        copyStream(fis, fos, null);
        fis.close();
        fos.close();

        fos = new FileOutputStream(f);
        fis = new FileInputStream(fix);
        copyStream(fis, fos, null);
        fis.close();
        fos.close();
    }

    private List<Process> procs = new ArrayList();
    private long launchDelay;
    private String gamePath, updateHost;

    public long getLaunchDelay() {
        return launchDelay;
    }

    public void setLaunchDelay(long launchDelay) {
        this.launchDelay = launchDelay;
    }

    public void setProcCount(String pc) {
        jTextField1.setText(pc);
    }

    public String getProcCount() {
        return jTextField1.getText();
    }

    private void logg(Throwable th) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        th.printStackTrace(new PrintStream(baos));
        byte buff[] = baos.toByteArray();
        jTextArea1.setText(jTextArea1.getText() + "\r\n" + new String(buff));
    }

    private void logg(String str) {
        jTextArea1.setText(jTextArea1.getText() + "\r\n" + str);
    }

    public String getGamePath() {
        return gamePath;
    }

    public void setGamePath(String gamePath) {
        this.gamePath = gamePath;
        jTextField2.setText(gamePath);
    }

    public String getUpdateHost() {
        return updateHost;
    }

    public void setUpdateHost(String updateHost) {
        this.updateHost = updateHost;
    }

    public String getLa2server() {
        return la2server;
    }

    public void setLa2server(String la2server) {
        this.la2server = la2server;
    }

    public int getLa2port() {
        return la2port;
    }

    public void setLa2port(int la2port) {
        this.la2port = la2port;
    }

    public void setTabDevider(int devider) {
        jSplitPane1.setDividerLocation(devider);
    }

    public int getTabDevider() {
        return jSplitPane1.getDividerLocation();
    }

    public int getFilesTableDeviderWidth1() {
        return jTable2.getColumnModel().getColumn(0).getWidth();
    }

    public int getFilesTableDeviderWidth2() {
        return jTable2.getColumnModel().getColumn(1).getWidth();
    }

    public void setFilesTableDeviderWidth1(int width) {
        jTable2.getColumnModel().getColumn(0).setPreferredWidth(width);
    }

    public void setFilesTableDeviderWidth2(int width) {
        jTable2.getColumnModel().getColumn(1).setPreferredWidth(width);
    }

    public String getPatchPath() {
        return patchPath;
    }

    public void setPatchPath(String patchPath) {
        this.patchPath = patchPath;
    }

    private class ProcWatcher implements Runnable {

        public boolean die = false;

        @Override
        public void run() {
            DefaultTableModel dtm = (DefaultTableModel) jTable1.getModel();
            while (!die) {
                List<Object[]> victs = new ArrayList();
                for (Process p : procs) {
                    if (!p.isAlive()) {
                        for (int i = 0; i < dtm.getRowCount(); i++) {
                            if ((p.hashCode() + "").equals(dtm.getValueAt(i, 0).toString())) {
                                victs.add(new Object[] { p, dtm.getValueAt(i, 0).toString() });
                            }
                        }
                    }
                }
                for (Object[] vict : victs) {
                    Process proc = (Process) vict[0];
                    String pid = (String) vict[1];
                    procs.remove(proc);
                    for (int i = 0; i < dtm.getRowCount(); i++) {
                        if (dtm.getValueAt(i, 0).toString().equals(pid)) {
                            dtm.removeRow(i);
                        }
                    }
                }
                try {
                    Thread.sleep(300);
                } catch (InterruptedException ex) {
                    Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }

    private String la2server;
    private int la2port;
    private String patchPath;

    private int procLimit;

    public int getProcLimit() {
        return procLimit;
    }

    public void setProcLimit(int procLimit) {
        this.procLimit = procLimit;
    }

    class ServerStatusWatcher implements Runnable {

        private boolean run = true;

        public void stop() {
            run = false;
        }

        @Override
        public void run() {
            while (run) {
                try {
                    boolean result = pingLA2Server();
                    if (result) {
                        Thread.sleep(30000);
                    } else {
                        Thread.sleep(3000);
                    }
                } catch (InterruptedException ex) {
                    Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/la2launcher/off1.png"))); // NOI18N
        }

        private boolean pingLA2Server() {
            try {
                long l = new Date().getTime();
                Socket soc = new Socket();
                soc.connect(new InetSocketAddress(la2server, la2port), 500);
                l = new Date().getTime() - l;
                jLabel7.setText(": " + l + " ?");
                jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/la2launcher/on1.png"))); // NOI18N
                soc.close();
                return true;
            } catch (IOException ex) {
                jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/la2launcher/off1.png"))); // NOI18N
                jLabel7.setText(": ? ?");
                playSound();
                return false;
            }
        }
    }

    public static synchronized void playSound() {
        new Thread(new Runnable() {
            // The wrapper thread is unnecessary, unless it blocks on the
            // Clip finishing; see comments.
            public void run() {
                try {
                    Clip clip = AudioSystem.getClip();
                    AudioInputStream inputStream = AudioSystem.getAudioInputStream(
                            new BufferedInputStream(this.getClass().getResourceAsStream("alert.vaw")));
                    clip.open(inputStream);
                    //clip.start();
                } catch (Exception e) {
                    System.err.println(e.getMessage());
                }
            }
        }).start();
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton11;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JProgressBar jProgressBar1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTable jTable2;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextArea jTextArea2;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    // End of variables declaration//GEN-END:variables
}