package com.mycompany.update;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.util.Properties;
import org.apache.commons.io.FileUtils;

public class main
{
    public static String path_to_server;
    
    public static void main(String[] args) throws IOException
    {
        String path_to_user = new File("").getAbsolutePath();
        
        functions functions = new functions();
        functions.downloading("", path_to_user, "server.properties");
        
        FileInputStream file_input_stream;
        
        Properties properties_user = new Properties();
        file_input_stream = new FileInputStream("user.properties");
        properties_user.load(file_input_stream);
        Properties properties_server = new Properties();
        file_input_stream = new FileInputStream("server.properties");
        properties_server.load(new InputStreamReader(file_input_stream, Charset.forName("UTF-8")));
        
        String name_program = properties_user.getProperty("name_program");
        String name_object = properties_user.getProperty("name_object");
        path_to_server = properties_server.getProperty(name_program + "_" + name_object).replace(" ", "%20");
        
        file_input_stream.close();
        File file_server_properties = new File("server.properties");
        file_server_properties.delete();
        file_input_stream.close();
        
        System.out.print("Обновление программного обеспечения");
        
        new File("temp").mkdir();
        
        functions.test_1(path_to_server, path_to_user, path_to_user + "\\" + "temp");
        
        functions.test_2();
        
        if(functions.successful_update)
        {
            functions.copying(path_to_user + "\\" + "temp", path_to_user);
        }
        
        if(functions.show_update_information)
        {
            functions.show_update_information();
        }
        
        FileUtils.deleteDirectory(new File("temp"));
    }
}
