<commit_before>package kubach.gui;

import java.awt.Component;
import java.awt.Insets;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JProgressBar;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;
import kubach.ConfigManager;
import kubach.Constants;
import kubach.packet.PacketFilesList;
import kubach.packet.PacketLoginResponse;
import kubach.util.LaunchCommandBuilder;
import kubach.util.Md5Checksum;
import kubach.workers.AuthWorker;
import kubach.workers.ChangePasswordWorker;
import kubach.workers.DownloadFileWorker;
import kubach.workers.LoadCaptchaWorker;
import kubach.workers.ProcessMonitorWorker;
import kubach.workers.ProcessMonitorWorker.ProcessState;
import kubach.workers.RemoveSkinWorker;
import kubach.workers.RequestFilesListWorker;
import kubach.workers.UploadSkinWorker;
import kubach.zip.ExtractingDialog;
import net.minecraft.skintest.ModelPreview;

/**
 * Main frame
 *
 * @author Cr0s
 */
public class MainFrame extends javax.swing.JFrame {

    private String loggedUsername, session;
    // Sync
    private int numFilesToSync, numFilesSynced;
    private PacketFilesList p;
    private SyncState syncState = SyncState.WAITING;
    private boolean expectExit;
    private Process process;

    public void cancelRegistration() {
        txtUsername.setEnabled(true);
        txtPassword.setEnabled(true);

        btnLogin.setEnabled(true);
        btnRegister.setEnabled(true);
        btnRegister.setText("Register");

        this.currentState = LauncherState.WAIT_LOGIN;
    }

    private void startFileSync() {
        this.syncState = SyncState.STARTED;

        RequestFilesListWorker rflw = new RequestFilesListWorker(this, ConfigManager.getInstance().getProperties().getProperty("clientprefix"));
        rflw.execute();
    }

    public void parseFilesList(PacketFilesList p) {
        this.numFilesToSync = 0;
        this.pbSync.setValue(0);

        DefaultTableModel model = (DefaultTableModel) tblSync.getModel();
        int rows = model.getRowCount();
        for (int i = rows - 1; i >= 0; i--) {
            model.removeRow(i);
        }


        this.syncState = SyncState.STARTED;

        boolean needToBeSync = false;

        for (String s : p.files) {
            String[] args = s.split(":");

            if (isFileNeedToSync(args[0], args[1])) {
                needToBeSync = true;
                this.numFilesToSync++;
                this.pbSync.setMaximum(this.numFilesToSync);

                // Make nonexistent dirs first
                String pathToFile = ConfigManager.getInstance().pathToJar + args[0];

                File f = new File(pathToFile);
                File pf = f.getParentFile();

                if (pf != null && !pf.exists()) {
                    pf.mkdirs();
                }

                // Create worker to download
                ((DefaultTableModel) tblSync.getModel()).addRow(new Object[]{args[0], "-", new JProgressBar()});
                DownloadFileWorker wsi = new DownloadFileWorker(this, f.getPath(), args[0], tblSync.getModel().getRowCount() - 1);
                wsi.execute();
            }
        }
        
        if (!needToBeSync) {
            this.syncState = SyncState.COMPLETE;
        }
    }

    private boolean isFileNeedToSync(String path, String md5) {
        File f = new File(ConfigManager.getInstance().pathToJar + path);

        try {
            if (!f.exists() || !md5.equals(Md5Checksum.getMD5Checksum(f.getPath()))) {
                return true;
            }
        } catch (Exception ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
            return true;
        }

        return false;
    }

    public void setSyncTableRow(int tableRowIndex, String status, int progressValue, int totalProgressValue, File file) {
        tblSync.getModel().setValueAt(status, tableRowIndex, 1);

        Component c = (Component) tblSync.getValueAt(tableRowIndex, 2);

        if (c instanceof JProgressBar) {
            ((JProgressBar) c).setMaximum(totalProgressValue);
            ((JProgressBar) c).setValue(progressValue);
        }

        // TODO: determine its thread-safe or not
        if (status.equals("Finished")) {
            this.numFilesSynced++;
            
            // Just downloaded package, extract it
            if (file.getPath().endsWith(".package")) {
                ExtractingDialog ed = new ExtractingDialog(this, false, file);
            }
        }<commit_msg>Fixed extraction dialog not shows<commit_after>package kubach.gui;

import java.awt.Component;
import java.awt.Insets;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JProgressBar;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;
import kubach.ConfigManager;
import kubach.Constants;
import kubach.packet.PacketFilesList;
import kubach.packet.PacketLoginResponse;
import kubach.util.LaunchCommandBuilder;
import kubach.util.Md5Checksum;
import kubach.workers.AuthWorker;
import kubach.workers.ChangePasswordWorker;
import kubach.workers.DownloadFileWorker;
import kubach.workers.LoadCaptchaWorker;
import kubach.workers.ProcessMonitorWorker;
import kubach.workers.ProcessMonitorWorker.ProcessState;
import kubach.workers.RemoveSkinWorker;
import kubach.workers.RequestFilesListWorker;
import kubach.workers.UploadSkinWorker;
import kubach.zip.ExtractingDialog;
import net.minecraft.skintest.ModelPreview;

/**
 * Main frame
 *
 * @author Cr0s
 */
public class MainFrame extends javax.swing.JFrame {

    private String loggedUsername, session;
    // Sync
    private int numFilesToSync, numFilesSynced;
    private PacketFilesList p;
    private SyncState syncState = SyncState.WAITING;
    private boolean expectExit;
    private Process process;

    public void cancelRegistration() {
        txtUsername.setEnabled(true);
        txtPassword.setEnabled(true);

        btnLogin.setEnabled(true);
        btnRegister.setEnabled(true);
        btnRegister.setText("Register");

        this.currentState = LauncherState.WAIT_LOGIN;
    }

    private void startFileSync() {
        this.syncState = SyncState.STARTED;

        RequestFilesListWorker rflw = new RequestFilesListWorker(this, ConfigManager.getInstance().getProperties().getProperty("clientprefix"));
        rflw.execute();
    }

    public void parseFilesList(PacketFilesList p) {
        this.numFilesToSync = 0;
        this.pbSync.setValue(0);

        DefaultTableModel model = (DefaultTableModel) tblSync.getModel();
        int rows = model.getRowCount();
        for (int i = rows - 1; i >= 0; i--) {
            model.removeRow(i);
        }


        this.syncState = SyncState.STARTED;

        boolean needToBeSync = false;

        for (String s : p.files) {
            String[] args = s.split(":");

            if (isFileNeedToSync(args[0], args[1])) {
                needToBeSync = true;
                this.numFilesToSync++;
                this.pbSync.setMaximum(this.numFilesToSync);

                // Make nonexistent dirs first
                String pathToFile = ConfigManager.getInstance().pathToJar + args[0];

                File f = new File(pathToFile);
                File pf = f.getParentFile();

                if (pf != null && !pf.exists()) {
                    pf.mkdirs();
                }

                // Create worker to download
                ((DefaultTableModel) tblSync.getModel()).addRow(new Object[]{args[0], "-", new JProgressBar()});
                DownloadFileWorker wsi = new DownloadFileWorker(this, f.getPath(), args[0], tblSync.getModel().getRowCount() - 1);
                wsi.execute();
            }
        }
        
        if (!needToBeSync) {
            this.syncState = SyncState.COMPLETE;
        }
    }

    private boolean isFileNeedToSync(String path, String md5) {
        File f = new File(ConfigManager.getInstance().pathToJar + path);

        try {
            if (!f.exists() || !md5.equals(Md5Checksum.getMD5Checksum(f.getPath()))) {
                return true;
            }
        } catch (Exception ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
            return true;
        }

        return false;
    }

    public void setSyncTableRow(int tableRowIndex, String status, int progressValue, int totalProgressValue, File file) {
        tblSync.getModel().setValueAt(status, tableRowIndex, 1);

        Component c = (Component) tblSync.getValueAt(tableRowIndex, 2);

        if (c instanceof JProgressBar) {
            ((JProgressBar) c).setMaximum(totalProgressValue);
            ((JProgressBar) c).setValue(progressValue);
        }

        // TODO: determine its thread-safe or not
        if (status.equals("Finished")) {
            this.numFilesSynced++;
            
            // Just downloaded package, extract it
            if (file.getPath().endsWith(".package")) {
                ExtractingDialog ed = new ExtractingDialog(this, false, file);
                ed.setVisible(true);
            }
        }
{'fraction_non_alphanumeric': 0.10538803756796837, 'fraction_numerical': 0.0035590706870983688, 'mean_word_length': 2.7068523268596554, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4866531', 'n_tokens_mistral': 2948, 'n_tokens_neox': 2838, 'n_words': 591}