Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 30482c55 authored by Vincent Bourgmayer's avatar Vincent Bourgmayer
Browse files

add stuff to load Sources information (url & local path to use) and fix DownloadSrcController.java

parent 63fab92a
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -27,12 +27,10 @@ import ecorp.easy.installer.models.Phone;
import ecorp.easy.installer.models.steps.IStep;
import ecorp.easy.installer.tasks.CommandExecutionTask;
import ecorp.easy.installer.utils.UiUtils;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.animation.FadeTransition;

import javafx.fxml.Initializable;
import javafx.application.Platform;
import javafx.beans.binding.Bindings;
+17 −5
Original line number Diff line number Diff line
@@ -18,12 +18,15 @@ package ecorp.easy.installer.controllers.subcontrollers;


import ecorp.easy.installer.controllers.MainWindowController;
import ecorp.easy.installer.helpers.DeviceHelper;
import ecorp.easy.installer.tasks.DownloadTask;
import ecorp.easy.installer.utils.UiUtils;
import java.io.IOException;
import java.net.URL;
import java.text.ParseException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.ResourceBundle;
import javafx.concurrent.Service;
import javafx.concurrent.Task;
@@ -47,8 +50,8 @@ public class DownloadSrcController extends AbstractSubController {
    private @FXML Label progressTitle;
    private @FXML Button restartDownloadBtn;
    
    private Map<String, String> sourcesToDownload;
    private Iterator<Map.Entry<String, String>> taskIterator;
    private HashMap<String, String> sourcesToDownload;
    private Iterator<HashMap.Entry<String, String>> taskIterator;
    private DownloadService currentService;
    
    @Override    
@@ -60,7 +63,16 @@ public class DownloadSrcController extends AbstractSubController {
    @Override
    public void setParentController(MainWindowController parentController){
        super.setParentController(parentController);
        sourcesToDownload = parentController.getThreadFactory().getSourcesToDownload();
        
        try{
            sourcesToDownload = DeviceHelper.getSourcesToDownload(parentController.getPhone().getAdbDevice());
        }catch(IOException | ParseException | ClassCastException e){
            logger.debug("Can't load Sources URL & local path from config file: {}", e.getMessage());
            //@TODO add UI information
            
            return;
        }

        taskIterator =  sourcesToDownload.entrySet().iterator();
        startNextDownload();
    }
@@ -69,7 +81,7 @@ public class DownloadSrcController extends AbstractSubController {
        logger.info("startNextDownload()");
        logger.debug("taskIterator has next ? {} "+taskIterator.hasNext());
        if(taskIterator.hasNext()){
            Map.Entry<String, String> source = taskIterator.next();
            HashMap.Entry<String, String> source = taskIterator.next();
            
            currentService = new DownloadService(source.getKey(), source.getValue());
            bindProgressUIToService(currentService);
+7 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package ecorp.easy.installer.helpers;
import ecorp.easy.installer.models.steps.IStep;
import ecorp.easy.installer.models.Process;
import ecorp.easy.installer.utils.ConfigParser;
import static ecorp.easy.installer.utils.ConfigParser.parseSteps;
import java.io.IOException;
import java.io.InputStream;
@@ -60,6 +61,12 @@ public class DeviceHelper {
        return map.get(key);
    }
    
    
    public static HashMap<String, String> getSourcesToDownload(String adbDevice) throws IOException,ParseException, ClassCastException{
        return ConfigParser.parseSourcesToDownload(loadYaml(adbDevice+"_fs.yml"));
    }
    
    
    /**
     * Load a yaml file 
     * @param filename the filename (don't forget extension)
+24 −1
Original line number Diff line number Diff line
@@ -227,4 +227,27 @@ public class ConfigParser {
                titleKey, titleIconName, instructions, cmd);
        return result;
    }
    
    
    /**
     * Parse Sources To Download from Yaml file
     * @param yaml data load from Yaml
     * @return HashMap containing sources's URL & local path to store
     * @throws java.text.ParseException
     */
    public static HashMap<String, String> parseSourcesToDownload(HashMap yaml) throws ParseException, ClassCastException{
        HashMap<String, String> result = new HashMap<>();
        
        for(String key : (Set<String>) yaml.keySet() ){
            Map source = (Map) yaml.get(key); 
            if(key.equals("rom")){
                AppConstants.setEArchivePath((String) source.get("filePath"));
            }
            if(key.equals("twrp")){
                AppConstants.setTwrpImgPath((String) source.get("filePath"));
            }
            result.put((String) source.get("url"), (String) source.get("filePath"));
        }
        return result;
    }
}
 No newline at end of file