package de.nplusc.izc.tools.UiToolz;


import de.nplusc.izc.tools.IOtools.FileTK;
import java.io.File;
import java.net.URISyntaxException;
import java.util.ArrayList;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author LH
 */
public class GuiFileManager
{
    public final GuiFileManager GFM = new GuiFileManager();
    private String basePath;
    private String[] guifiles = new String[]{""};
    
    protected GuiFileManager()
    {
        try
        {
            basePath = cmdGUI.class.getResource("cmdGUI.class").toURI().toString().split("!")[0];
        }
        catch (URISyntaxException ex)
        {
            ex.printStackTrace();
            if(true)
            {
                throw new UnsupportedOperationException("Base-Path defect");
            }
        }
    }
    
    public String[] getGUIFiles()
    {
        return guifiles;
    }
    
    
    
    public void initManager()
    {
        String[] temp = FileTK.walkDirectoryRecursively(basePath+"\\UIFiles");
        ArrayList<String> t2= new ArrayList<>();
        for (String fileetr : temp)
        {
            if( FileTK.getFileExt(fileetr).equalsIgnoreCase("GUIFile"))
            {
                t2.add(fileetr);
            }
        }
        guifiles = t2.toArray(guifiles);
    }
    
    public boolean installGUIFile(String SrcPath)
    {
        //TODO: UIFile laden als Test;
        
        
        String data = "";
        String[] DataA = FileTK.fileload(SrcPath);
        for (String string : DataA)
        {
            data+=string;
        }
        
        String fname = SrcPath.split("\\\\")[SrcPath.split("\\\\").length-1];
        File tir = new File(basePath+"\\UIFiles");
        if(tir.exists()&&tir.isDirectory())
        {
            FileTK.writeFile(data, tir.toString()+"\\"+fname);
        }
        
        
        
        
        
        return false;
    }
}
