// Decompiled by DJ v3.12.12.96 Copyright 2011 Atanas Neshkov  Date: 08/10/2012 8:47:30
// Home Page: http://members.fortunecity.com/neshkov/dj.html http://www.neshkov.com/dj.html - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   ChequearUpdates.java

package project;

import java.io.*;
import java.net.*;
import java.util.Vector;

// Referenced classes of package project:
//            AccederADatos, EncriptarDesencriptar

public class ChequearUpdates
{

    public ChequearUpdates()
    {
    }

    public static void main(String args[])
    {
        ChequearUpdates chequearUpdates1 = new ChequearUpdates();
    }

    public String[] recogerDatos()
    {
        Vector vector = new Vector();
        try
        {
            URL url = new URL(AccederADatos.leer("h.proxyAddress") + "updates.jsp?version=" + EncriptarDesencriptar.encriptar(AccederADatos.leer("h.version")) + "&" + "encriptar=" + AccederADatos.leer("h.encriptar"));
            System.out.println(url.toString());
            URLConnection connection = url.openConnection();
            if(connection instanceof HttpURLConnection)
            {
                HttpURLConnection httpConnection = (HttpURLConnection)connection;
                connection.setRequestProperty("encriptar", AccederADatos.leer("h.encriptar"));
                httpConnection.setRequestProperty("version", EncriptarDesencriptar.encriptar(AccederADatos.leer("h.version")));
            }
            BufferedInputStream bis = new BufferedInputStream(connection.getInputStream());
            String textoEncriptado = EncriptarDesencriptar.getStringFromInputStream(bis);
            String textoDesencriptado = EncriptarDesencriptar.desencriptar(textoEncriptado);
            InputStream stream = EncriptarDesencriptar.getInputStreamFromString(textoDesencriptado.trim());
            InputStreamReader reader = new InputStreamReader(stream);
            BufferedReader bufferedReader = new BufferedReader(reader);
            String nextLine = null;
            boolean started = false;
            do
            {
                if((nextLine = bufferedReader.readLine()) == null)
                    break;
                if(nextLine.indexOf("=====") > -1)
                {
                    if(started)
                        break;
                    started = true;
                } else
                {
                    nextLine = nextLine.trim();
                    if(started && nextLine.length() > 0)
                    {
                        vector.add(nextLine);
                        System.out.println("nextLine: " + nextLine);
                    }
                }
            } while(true);
            bufferedReader.close();
            reader.close();
            stream.close();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        return (String[])(String[])vector.toArray(new String[vector.size()]);
    }
}