123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292 |
- /*
- * Copyright (C) 2015 iZc
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package de.nplusc.izc.InstallPak.legacy;
- import de.nplusc.izc.InstallPak.izsetupReader;
- import de.nplusc.izc.tools.IOtools.FileTK;
- import de.nplusc.izc.tools.IOtools.registryReader;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.HashMap;
- /**
- *
- * @author LH
- */
- public class PackManager
- {
- private HashMap<String,ArrayList<String[]>> groupsplitted = new HashMap<>();
- private String[] installingPacks,AllPacks,DetectedPacks,queue;
-
- /**
- * Lädt die Liste aller Packs aus der aktiven Datei
- * @return PAckliste im FOrmat ID|Name
- *
- */
- public String[] getPackList()
- {
- String[] ret = new String[AllPacks.length];
- for (int i=0;i<AllPacks.length;i++)
- {
- String id=AllPacks[i];
- ArrayList<String[]> group=groupsplitted.get(id);
- for (String row[] : group)
- {
- String[] rowSplit = row;
- if(rowSplit[1].equalsIgnoreCase("pack"))
- ret[i] = id+"|"+rowSplit[2];
- }
- }
- return ret;
- }
-
- public void loadPackageData(String path)
- {
- String[][] data = izsetupReader.getSysSpezSetupFile(path,true,true);
- String groupID="000";
- String previousGRPID ="000";
-
- ArrayList<String[]> SubGroup = new ArrayList<>();
- for (String[] line : data)
- {
- if(!(line==null))
- {
- String[] splittedLine=line;
- if(!splittedLine[0].equals("000"))
- {
- groupID=splittedLine[0];
- if(!previousGRPID.equals(groupID)&&!previousGRPID.equals("000"))
- {
- groupsplitted.put(previousGRPID, SubGroup);//Einlagern der abgeschlossenen gruppe
- SubGroup = new ArrayList<>();//resetten für neue daten;
- }
- SubGroup.add(line);
- previousGRPID=groupID;
- }
- }
- }
- groupsplitted.put(previousGRPID, SubGroup);//die letzte auch noch einflanschen
- String[] groupIDs = groupsplitted.keySet().toArray(new String[0]);
- Arrays.sort(groupIDs);
- AllPacks = groupIDs;
- checkForpackInstalled();
- ArrayList<String> installables = new ArrayList<>();
- for (String id : AllPacks)
- {
- if(!packIsInstalled(id))
- installables.add(id);
- }
- installingPacks = installables.toArray(new String[0]);
- Arrays.sort(installingPacks);
- }
- public void setPackInstallState(String packid, boolean state)
- {
- boolean exists = false;
- for (int i = 0; i < installingPacks.length; i++)
- {
- String id = installingPacks[i];
- if(packid.equals(id))
- {
- exists=true;
- if(!state)
- {
- installingPacks[i]="";
- }
- }
- }
- ArrayList<String> newGrps = new ArrayList<>();
- for (String cnt : installingPacks)
- {
- if(cnt.length()>1)
- {
- newGrps.add(cnt);
- }
- }
- if(!exists&&state)
- {
- newGrps.add(packid);
- }
- installingPacks = newGrps.toArray(new String[0]);
- newGrps = new ArrayList<>();
- for (String cnt : installingPacks)
- {
- if(packIsInstallable(cnt))
- newGrps.add(cnt);
-
- }
- installingPacks = newGrps.toArray(new String[0]);
- }
- public boolean packIsInstallable(String packid)
- {
- return packIsInstallable(packid, false);
- }
- public boolean packIsInstallable(String packid,boolean blocksItself)
- {
- String reqPack = packDependency(packid);
-
- for (String pack : DetectedPacks)//Detektiere obDependency installiert(dependency erfüllt wenn pack bereits installiert
- {
- if(reqPack.equalsIgnoreCase(pack))
- return true;
- }
- if(blocksItself)
- {
- for (String pack : installingPacks)//detektiere obDependency in installierliste
- {
- if(packid.equalsIgnoreCase(pack))
- return false;
- }
- }
- for (String pack : installingPacks)//detektiere obDependency in installierliste
- {
- if(reqPack.equalsIgnoreCase(pack)&&packIsInstallable(reqPack))
- return true;
- }
- if(reqPack.equals("none"))
- return true;
- return false;
- }
-
- public boolean packIsInstalled(String packid)
- {
- for (String cntnt : DetectedPacks)
- {
- if(cntnt.equalsIgnoreCase(packid))
- return true;
- }
- return false;
- }
-
-
-
- public boolean packIsScheduled(String packid)
- {
- for (String cntnt : installingPacks)
- {
- if(cntnt.equalsIgnoreCase(packid))
- return true;
- }
- return false;
- }
-
- public String packDependency(String packid)
- {
- ArrayList<String[]> selectedPack = groupsplitted.get(packid);
- //002|req|001|nummer des benötigten packs//kann weitere erfordernwenn
- for (String[] line : selectedPack)
- {
- String[] linesegs = line;
- if(linesegs[1].equalsIgnoreCase("req"))
- return linesegs[2];
- }
-
-
- return "none";
- }
- //005|Description|Tools für die games aus dem Package
- public String getPackDescription(String packid)
- {
- ArrayList<String[]> selectedPack = groupsplitted.get(packid);
- for (String[] line : selectedPack)
- {
- String[] linesegs = line;
- if(linesegs[1].equalsIgnoreCase("Description"))
- return linesegs[2];
- }
- return "Error 0x0404: keine Beschreiubung gefunden";
- }
-
- public String getPackName(String packid)
- {
- ArrayList<String[]> selectedPack = groupsplitted.get(packid);
- for (String line[] : selectedPack)
- {
- String[] linesegs = line;
- if(linesegs[1].equalsIgnoreCase("pack"))
- return linesegs[2];
- }
- return "Error 0x0404: kein Name gefunden";
- }
-
-
- private void checkForpackInstalled()
- {
- ArrayList<String> installedPack = new ArrayList<>();
- for (int i=0;i<AllPacks.length;i++)
- {
- String id=AllPacks[i];
- ArrayList<String[]> group=groupsplitted.get(id);
- for (String[] row : group)
- {
- String[] rowSplit = row;
- if(rowSplit[1].equalsIgnoreCase("detectInstall"))
- {
- String detecString = rowSplit[2];
- //CMM|File:// benutzt den DateiExistiert-operator
- //CMM|Reg:// detektiert unter Win auf Exitenz von Regwert
- if(detecString.substring(0,7).equalsIgnoreCase("File://"))
- {
- String detecpart = detecString.substring(7);
- if(FileTK.checkDirExist(detecpart))
- {
- installedPack.add(id);
- }
- }
- if(detecString.substring(0,6).equalsIgnoreCase("Reg://"))
- {
- String detecpart = detecString.substring(6);
- if(registryReader.checkExistenceOfRegKey(detecpart)||registryReader.checkExistenceOfRegKeyEntry(detecpart))
- {
- installedPack.add(id);
- }
- }
- }
- }
- }
- DetectedPacks = installedPack.toArray(new String[0]);
- }
- public void createQueue()
- {
- Arrays.sort(installingPacks);
- ArrayList<String> queuetmp = new ArrayList<>();
- for (String id : installingPacks)
- {
- ArrayList<String[]> grpldr =groupsplitted.get(id);
- for (String[] line : grpldr)
- {
- String[] data = line;
- if(data[1].equalsIgnoreCase("packfile"))
- {
- queuetmp.add("packfile:"+data[2]);
- }
- if(data[1].startsWith("waitdisk:"))
- {
- queuetmp.add("waitdisk:"+data[2]+"|"+data[1].substring(9));
- }
- }
- }
- queue=queuetmp.toArray(new String[0]);
- }
- public String[] getQueue()
- {
- return queue;
- }
- }
|