Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fr.ketlark77.main;
- import java.awt.AlphaComposite;
- import java.awt.Color;
- import java.awt.Desktop;
- import java.awt.Font;
- import java.awt.FontFormatException;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.awt.Image;
- import java.awt.Point;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.KeyEvent;
- import java.awt.event.KeyListener;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseMotionAdapter;
- import java.io.BufferedReader;
- import java.io.DataInputStream;
- import java.io.DataOutputStream;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.net.HttpURLConnection;
- import java.net.InetAddress;
- import java.net.MalformedURLException;
- import java.net.NetworkInterface;
- import java.net.SocketException;
- import java.net.URI;
- import java.net.URL;
- import java.net.UnknownHostException;
- import java.util.Random;
- import javax.crypto.Cipher;
- import javax.crypto.CipherInputStream;
- import javax.crypto.CipherOutputStream;
- import javax.crypto.SecretKey;
- import javax.crypto.SecretKeyFactory;
- import javax.crypto.spec.PBEKeySpec;
- import javax.crypto.spec.PBEParameterSpec;
- import javax.imageio.ImageIO;
- import javax.swing.Icon;
- import javax.swing.ImageIcon;
- import javax.swing.JCheckBox;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import javax.swing.JPanel;
- import javax.swing.JPasswordField;
- import javax.swing.JTextField;
- import javax.swing.SwingConstants;
- import javax.swing.Timer;
- import fr.theshark34.supdate.BarAPI;
- import fr.theshark34.supdate.SUpdate;
- import fr.theshark34.supdate.application.integrated.FileDeleter;
- import fr.theshark34.supdate.exception.BadServerResponseException;
- import fr.theshark34.supdate.exception.BadServerVersionException;
- import fr.theshark34.supdate.exception.ServerDisabledException;
- import fr.theshark34.supdate.exception.ServerMissingSomethingException;
- public class Panel
- extends JPanel
- implements ActionListener, KeyListener
- {
- private Point initialClick;
- public static final long serialVersionUID = 1L;
- public Image bg;
- public Image field;
- public JTextField user = new JTextField();
- boolean showError;
- String errorMSG;
- public JPasswordField password = new JPasswordField();
- public static String ram_value = "512M";
- public ImgButton play = new ImgButton(this, 350, 420, 130, 42, new String[] {
- "/images/play_1.png",
- "/images/play.png" });
- public ImgButton youtube = new ImgButton(this, 25, 25, 47, 47, new String[] {
- "/images/youtube_1.png",
- "/images/youtube.png" });
- public ImgButton teamspeak = new ImgButton(this, 85, 25, 47, 47, new String[] {
- "/images/teamspeak_1.png",
- "/images/teamspeak.png" });
- public ImgButton quit = new ImgButton(this, 790, 25, 47, 47, new String[] {
- "/images/close_1.png",
- "/images/close.png" });
- public ImgButton reduce = new ImgButton(this, 730, 25, 47, 47, new String[] {
- "/images/reduce_1.png",
- "/images/reduce.png" });
- public static StyledBar bar;
- public String displayLoad;
- public static JLabel state;
- public Panel p;
- public static Home home;
- public ThreadUpdate thread = new ThreadUpdate(this);
- //Ajout Vharion
- public Icon checked = new ImgButtonCheckbox();
- public Icon unchecked = new ImgButtonCheckbox();
- public JCheckBox checkbox = new JCheckBox("", unchecked);
- private Options options;
- public static ConsoleTab console;
- private Font font = null;
- private InputStream inputstream = null;
- public Panel(final Home home) throws FontFormatException, IOException
- {
- addMouseListener(new MouseAdapter()
- {
- public void mousePressed(MouseEvent e)
- {
- Panel.this.initialClick = e.getPoint();
- Panel.this.getComponentAt(Panel.this.initialClick);
- }
- });
- addMouseMotionListener(new MouseMotionAdapter()
- {
- public void mouseDragged(MouseEvent e)
- {
- int thisX = home.getLocation().x;
- int thisY = home.getLocation().y;
- int xMoved = thisX + e.getX() - (thisX + Panel.this.initialClick.x);
- int yMoved = thisY + e.getY() - (thisY + Panel.this.initialClick.y);
- int X = thisX + xMoved;
- int Y = thisY + yMoved;
- home.setLocation(X, Y);
- }
- });
- Panel.home = home;
- try
- {
- this.bg = ImageIO.read(Panel.class.getResource("/images/background.png"));
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- setBounds(0, 0, 850, 500);
- this.inputstream = getClass().getResourceAsStream("police.ttf");
- this.font = Font.createFont(0, this.inputstream).deriveFont(0, 21.0F);
- setLayout(null);
- this.play.addActionListener(this);
- this.youtube.addActionListener(this);
- this.teamspeak.addActionListener(this);
- this.quit.addActionListener(this);
- this.reduce.addActionListener(this);
- this.user.addKeyListener(this);
- this.user.setFocusTraversalKeysEnabled(true);
- this.user.setBorder(null);
- this.user.setFont(new Font("Tahoma", 1, 19));
- this.user.setBackground(new Color(0, 0, 0, 0));
- this.user.setBounds(295, 358, 240, 25);
- this.user.setForeground(Color.BLACK);
- this.user.setHorizontalAlignment(0);
- Panel.state = new JLabel("", SwingConstants.CENTER);
- Panel.state.setBounds(500, 530, 300, 70);
- Panel.state.setOpaque(false);
- Panel.state.setFont(new Font("arial", 0, 11));
- Panel.state.setForeground(Color.WHITE);
- add(Panel.state);
- Integer[] pos = {0, 555};
- Panel.bar = new StyledBar(1282);
- Panel.bar.setBounds(pos[0], pos[1], 0, 21);
- Panel.bar.setDoubleBuffered(true);
- Panel.bar.setOpaque(false);
- ImageIcon imgM = new ImageIcon(Panel.class.getResource("/images/progress.png"));
- Panel.bar.setIcon(imgM);
- add(Panel.bar);
- add(this.user);
- add(this.password);
- add(this.play);
- add(this.youtube);
- add(this.teamspeak);
- add(this.quit);
- add(this.reduce);
- add(this.checkbox);
- setBackground(new Color(0, 150, 0, 0));
- readLastLogin();
- readOptions();
- setVisible(true);
- timer_in.start();
- if(console == null)
- {
- console = new ConsoleTab("Eryzia Launcher - Console");
- console.setVisible(false);
- console.println("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");
- console.println("|| Infos Système ||");
- console.println("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");
- console.println("");
- console.println(new StringBuilder().append("OS Name == '").append(System.getProperty("os.name")).append("'").toString());
- console.println(new StringBuilder().append("OS Version == '").append(System.getProperty("os.version")).append("'").toString());
- console.println(new StringBuilder().append("OS Arch == '").append(System.getProperty("os.arch")).append("'").toString());
- console.println(new StringBuilder().append("Java Version == '").append(System.getProperty("java.version")).append("'").toString());
- console.println(new StringBuilder().append("Java Vendor == '").append(System.getProperty("java.vendor")).append("'").toString());
- console.println(new StringBuilder().append("Java Arch == '").append(System.getProperty("sun.arch.data.model")).append("'").toString());
- console.println("");
- console.println("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");
- console.println("");
- console.println("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");
- console.println("");
- }
- }
- public void paintComponent(Graphics g)
- {
- ((Graphics2D) g).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha_in));
- g.setColor(Color.WHITE);
- g.drawImage(this.bg, 0, 0, 850, 500, this);
- // g.drawImage(this.field, 20, 45, 169, 90, this);
- if (this.showError)
- {
- g.setColor(Color.red);
- g.drawString(this.errorMSG, 220, 125);
- }
- /* else if (this.displayString != null)
- {
- g.setColor(Color.black);
- g.drawString(this.displayString, 220, 125);
- }*/
- }
- private float alpha_in = 0F;
- final Timer timer_in = new Timer(10, new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- alpha_in += 0.01F;
- if (alpha_in >= 1)
- {
- alpha_in = 1;
- timer_in.stop();
- }
- repaint();
- }
- });
- public void actionPerformed(ActionEvent e)
- {
- if (e.getSource() == this.play) {
- play();
- }
- else if (e.getSource() == this.quit)
- {
- System.exit(0);
- }
- else if (e.getSource() == this.reduce)
- {
- home.setState(1);;
- }
- else if (e.getSource() == this.teamspeak)
- {
- try
- {
- URI u = URI.create("ts3server://eryziats.cloudcraft.fr");
- Desktop.getDesktop().browse(u);
- } catch (IOException ex) {
- ex.printStackTrace();
- }
- }
- }
- public void refresh()
- {
- Panel.home.repaint();
- }
- void play()
- {
- if(this.user.getText().length() > 0)
- {
- saveLastLogin();
- this.user.setEnabled(false);
- this.password.setEnabled(false);
- Thread t = new Thread() {
- public void run() {
- SUpdate su = new SUpdate("http://eryzia.franceserv.fr/launcher/", Util.getWorkingDirectory());
- su.addApplication(new FileDeleter());
- su.getServerRequester().setRewriteEnabled(true);
- state.setText("Recherche de fichiers à mettre à jour ...");
- Panel.console.println("Recherche de fichiers à mettre à jour ...");
- Thread t = new Thread() {
- @Override
- public void run() {
- while (!this.isInterrupted()) {
- float percent = (float) ((double) BarAPI.getNumberOfTotalDownloadedBytes() / (double) BarAPI.getNumberOfTotalBytesToDownload());
- bar.setPourcent(percent);
- if (BarAPI.getNumberOfTotalBytesToDownload() != 0) {
- state.setText(String.valueOf(BarAPI.getNumberOfTotalDownloadedBytes()/ 1024 + " / " + BarAPI.getNumberOfTotalBytesToDownload() / 1024 + " Ko"));
- }
- }
- }
- };
- t.start();
- try {
- su.start();
- Panel.console.println("Téléchargement des fichiers en cours ...");
- } catch (BadServerResponseException | ServerDisabledException
- | BadServerVersionException
- | ServerMissingSomethingException | IOException e) {
- e.printStackTrace();
- }
- while(true)
- {
- new LaunchGame(user.getText(), p);
- boolean launchSuccess = LaunchGame.launchGame(user.getText());
- if (launchSuccess) {
- if (console.isVisible()) {
- state.setText("Jeu lancé");
- boolean keepRunning = true;
- while (keepRunning) {
- try {
- Thread.sleep(1000);
- } catch (Exception e) {
- keepRunning = false;
- }
- }
- } else {
- state.setText("Jeu lancé");
- System.exit(0);
- }
- } else {
- state.setText("Le lancement du jeu a échoué, veuillez réessayer en mettant à jour");
- }
- }
- }
- };
- t.start();
- }
- else
- {
- JOptionPane.showMessageDialog(this, "Veuillez rentrez votre utilisateur", "Identifiants manquants", 0);
- }
- }
- public void keyPressed(KeyEvent e)
- {
- if (e.getKeyCode() == 10) {
- play();
- }
- }
- public void keyReleased(KeyEvent e) {}
- public void keyTyped(KeyEvent arg0) {}
- private void readLastLogin()
- {
- File lastLogin = new File(Util.getWorkingDirectory() +
- File.separator + "lastlogin");
- if (!lastLogin.exists()) {
- try
- {
- lastLogin.createNewFile();
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- }
- try
- {
- Cipher ciph = openCipher(2);
- DataInputStream dis = new DataInputStream(
- new CipherInputStream(new FileInputStream(lastLogin), ciph));
- this.user.setText(dis.readUTF());
- this.password.setText(dis.readUTF());
- this.checkbox.setSelected(this.password.getPassword().length > 0);
- dis.close();
- }
- catch (Exception e)
- {
- System.out.println("Failed to read lastLogin file");
- e.printStackTrace();
- }
- }
- private void readOptions()
- {
- File last = new File(Util.getWorkingDirectory(), "options_launch.txt");
- if (last.exists())
- {
- BufferedReader br = null;
- try
- {
- br = new BufferedReader(new FileReader(last));
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
- try
- {
- String resp = br.readLine();
- Panel.ram_value = resp;
- }
- catch (Exception e)
- {
- e.printStackTrace();
- try
- {
- br.close();
- }
- catch (IOException e1)
- {
- e1.printStackTrace();
- }
- }
- finally
- {
- try
- {
- br.close();
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- }
- }
- else
- {
- try {
- last.createNewFile();
- FileWriter ffw = new FileWriter(last);
- ffw.write("512M");
- ffw.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- private void saveLastLogin()
- {
- try
- {
- File lastLogin = new File(Util.getWorkingDirectory() +
- File.separator + "lastlogin");
- Cipher ciph = openCipher(1);
- DataOutputStream dos = new DataOutputStream(new CipherOutputStream(new FileOutputStream(lastLogin), ciph));
- dos.writeUTF(this.user.getText());
- dos.writeUTF(this.checkbox.isSelected() ? new String(this.password.getText()) : "");
- dos.close();
- }
- catch (Exception e)
- {
- System.out.println("Failed to save lastLogin file");
- e.printStackTrace();
- }
- }
- private Cipher openCipher(int mode) throws Exception
- {
- Random rnd = new Random(43287234L);
- byte[] data = new byte[8];
- rnd.nextBytes(data);
- PBEParameterSpec spec = new PBEParameterSpec(data, 5);
- SecretKey key = SecretKeyFactory.getInstance("PBEWithMD5AndDES").generateSecret(new PBEKeySpec("passwordEryzia".toCharArray()));
- Cipher ret = Cipher.getInstance("PBEWithMD5AndDES");
- ret.init(mode, key, spec);
- return ret;
- }
- public Options getOptions()
- {
- return this.options;
- }
- public static String getHTML(String urlToRead)
- {
- String result = "";
- try {
- URL url = new URL(urlToRead);
- HttpURLConnection conn = (HttpURLConnection)url.openConnection();
- conn.setRequestMethod("GET");
- BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
- String line;
- while ((line = rd.readLine()) != null) {
- result = result + line;
- }
- rd.close();
- } catch (Exception e) {
- System.out.println("error while reading");
- return "";
- }
- return result;
- }
- }
Add Comment
Please, Sign In to add comment