PackManager.java 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /*
  2. * Copyright (C) 2015 iZc
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. package de.nplusc.izc.InstallPak.legacy;
  18. import de.nplusc.izc.InstallPak.izsetupReader;
  19. import de.nplusc.izc.tools.IOtools.FileTK;
  20. import de.nplusc.izc.tools.IOtools.registryReader;
  21. import java.util.ArrayList;
  22. import java.util.Arrays;
  23. import java.util.HashMap;
  24. /**
  25. *
  26. * @author LH
  27. */
  28. public class PackManager
  29. {
  30. private HashMap<String,ArrayList<String[]>> groupsplitted = new HashMap<>();
  31. private String[] installingPacks,AllPacks,DetectedPacks,queue;
  32. /**
  33. * Lädt die Liste aller Packs aus der aktiven Datei
  34. * @return PAckliste im FOrmat ID|Name
  35. *
  36. */
  37. public String[] getPackList()
  38. {
  39. String[] ret = new String[AllPacks.length];
  40. for (int i=0;i<AllPacks.length;i++)
  41. {
  42. String id=AllPacks[i];
  43. ArrayList<String[]> group=groupsplitted.get(id);
  44. for (String row[] : group)
  45. {
  46. String[] rowSplit = row;
  47. if(rowSplit[1].equalsIgnoreCase("pack"))
  48. ret[i] = id+"|"+rowSplit[2];
  49. }
  50. }
  51. return ret;
  52. }
  53. public void loadPackageData(String path)
  54. {
  55. String[][] data = izsetupReader.getSysSpezSetupFile(path,true,true);
  56. String groupID="000";
  57. String previousGRPID ="000";
  58. ArrayList<String[]> SubGroup = new ArrayList<>();
  59. for (String[] line : data)
  60. {
  61. if(!(line==null))
  62. {
  63. String[] splittedLine=line;
  64. if(!splittedLine[0].equals("000"))
  65. {
  66. groupID=splittedLine[0];
  67. if(!previousGRPID.equals(groupID)&&!previousGRPID.equals("000"))
  68. {
  69. groupsplitted.put(previousGRPID, SubGroup);//Einlagern der abgeschlossenen gruppe
  70. SubGroup = new ArrayList<>();//resetten für neue daten;
  71. }
  72. SubGroup.add(line);
  73. previousGRPID=groupID;
  74. }
  75. }
  76. }
  77. groupsplitted.put(previousGRPID, SubGroup);//die letzte auch noch einflanschen
  78. String[] groupIDs = groupsplitted.keySet().toArray(new String[0]);
  79. Arrays.sort(groupIDs);
  80. AllPacks = groupIDs;
  81. checkForpackInstalled();
  82. ArrayList<String> installables = new ArrayList<>();
  83. for (String id : AllPacks)
  84. {
  85. if(!packIsInstalled(id))
  86. installables.add(id);
  87. }
  88. installingPacks = installables.toArray(new String[0]);
  89. Arrays.sort(installingPacks);
  90. }
  91. public void setPackInstallState(String packid, boolean state)
  92. {
  93. boolean exists = false;
  94. for (int i = 0; i < installingPacks.length; i++)
  95. {
  96. String id = installingPacks[i];
  97. if(packid.equals(id))
  98. {
  99. exists=true;
  100. if(!state)
  101. {
  102. installingPacks[i]="";
  103. }
  104. }
  105. }
  106. ArrayList<String> newGrps = new ArrayList<>();
  107. for (String cnt : installingPacks)
  108. {
  109. if(cnt.length()>1)
  110. {
  111. newGrps.add(cnt);
  112. }
  113. }
  114. if(!exists&&state)
  115. {
  116. newGrps.add(packid);
  117. }
  118. installingPacks = newGrps.toArray(new String[0]);
  119. newGrps = new ArrayList<>();
  120. for (String cnt : installingPacks)
  121. {
  122. if(packIsInstallable(cnt))
  123. newGrps.add(cnt);
  124. }
  125. installingPacks = newGrps.toArray(new String[0]);
  126. }
  127. public boolean packIsInstallable(String packid)
  128. {
  129. return packIsInstallable(packid, false);
  130. }
  131. public boolean packIsInstallable(String packid,boolean blocksItself)
  132. {
  133. String reqPack = packDependency(packid);
  134. for (String pack : DetectedPacks)//Detektiere obDependency installiert(dependency erfüllt wenn pack bereits installiert
  135. {
  136. if(reqPack.equalsIgnoreCase(pack))
  137. return true;
  138. }
  139. if(blocksItself)
  140. {
  141. for (String pack : installingPacks)//detektiere obDependency in installierliste
  142. {
  143. if(packid.equalsIgnoreCase(pack))
  144. return false;
  145. }
  146. }
  147. for (String pack : installingPacks)//detektiere obDependency in installierliste
  148. {
  149. if(reqPack.equalsIgnoreCase(pack)&&packIsInstallable(reqPack))
  150. return true;
  151. }
  152. if(reqPack.equals("none"))
  153. return true;
  154. return false;
  155. }
  156. public boolean packIsInstalled(String packid)
  157. {
  158. for (String cntnt : DetectedPacks)
  159. {
  160. if(cntnt.equalsIgnoreCase(packid))
  161. return true;
  162. }
  163. return false;
  164. }
  165. public boolean packIsScheduled(String packid)
  166. {
  167. for (String cntnt : installingPacks)
  168. {
  169. if(cntnt.equalsIgnoreCase(packid))
  170. return true;
  171. }
  172. return false;
  173. }
  174. public String packDependency(String packid)
  175. {
  176. ArrayList<String[]> selectedPack = groupsplitted.get(packid);
  177. //002|req|001|nummer des benötigten packs//kann weitere erfordernwenn
  178. for (String[] line : selectedPack)
  179. {
  180. String[] linesegs = line;
  181. if(linesegs[1].equalsIgnoreCase("req"))
  182. return linesegs[2];
  183. }
  184. return "none";
  185. }
  186. //005|Description|Tools für die games aus dem Package
  187. public String getPackDescription(String packid)
  188. {
  189. ArrayList<String[]> selectedPack = groupsplitted.get(packid);
  190. for (String[] line : selectedPack)
  191. {
  192. String[] linesegs = line;
  193. if(linesegs[1].equalsIgnoreCase("Description"))
  194. return linesegs[2];
  195. }
  196. return "Error 0x0404: keine Beschreiubung gefunden";
  197. }
  198. public String getPackName(String packid)
  199. {
  200. ArrayList<String[]> selectedPack = groupsplitted.get(packid);
  201. for (String line[] : selectedPack)
  202. {
  203. String[] linesegs = line;
  204. if(linesegs[1].equalsIgnoreCase("pack"))
  205. return linesegs[2];
  206. }
  207. return "Error 0x0404: kein Name gefunden";
  208. }
  209. private void checkForpackInstalled()
  210. {
  211. ArrayList<String> installedPack = new ArrayList<>();
  212. for (int i=0;i<AllPacks.length;i++)
  213. {
  214. String id=AllPacks[i];
  215. ArrayList<String[]> group=groupsplitted.get(id);
  216. for (String[] row : group)
  217. {
  218. String[] rowSplit = row;
  219. if(rowSplit[1].equalsIgnoreCase("detectInstall"))
  220. {
  221. String detecString = rowSplit[2];
  222. //CMM|File:// benutzt den DateiExistiert-operator
  223. //CMM|Reg:// detektiert unter Win auf Exitenz von Regwert
  224. if(detecString.substring(0,7).equalsIgnoreCase("File://"))
  225. {
  226. String detecpart = detecString.substring(7);
  227. if(FileTK.checkDirExist(detecpart))
  228. {
  229. installedPack.add(id);
  230. }
  231. }
  232. if(detecString.substring(0,6).equalsIgnoreCase("Reg://"))
  233. {
  234. String detecpart = detecString.substring(6);
  235. if(registryReader.checkExistenceOfRegKey(detecpart)||registryReader.checkExistenceOfRegKeyEntry(detecpart))
  236. {
  237. installedPack.add(id);
  238. }
  239. }
  240. }
  241. }
  242. }
  243. DetectedPacks = installedPack.toArray(new String[0]);
  244. }
  245. public void createQueue()
  246. {
  247. Arrays.sort(installingPacks);
  248. ArrayList<String> queuetmp = new ArrayList<>();
  249. for (String id : installingPacks)
  250. {
  251. ArrayList<String[]> grpldr =groupsplitted.get(id);
  252. for (String[] line : grpldr)
  253. {
  254. String[] data = line;
  255. if(data[1].equalsIgnoreCase("packfile"))
  256. {
  257. queuetmp.add("packfile:"+data[2]);
  258. }
  259. if(data[1].startsWith("waitdisk:"))
  260. {
  261. queuetmp.add("waitdisk:"+data[2]+"|"+data[1].substring(9));
  262. }
  263. }
  264. }
  265. queue=queuetmp.toArray(new String[0]);
  266. }
  267. public String[] getQueue()
  268. {
  269. return queue;
  270. }
  271. }