use of mod.Mod in project ParadoxosModManager by ThibautSF.
the class ListManager method applyOneModListV2.
/**
* @param applyList
* @return
* @throws IOException
*/
private boolean applyOneModListV2(ModList applyList) throws IOException {
List<Mod> applyMods = applyList.getModlist();
String sep = File.separator;
// Clean customModFiles
deleteCustomModFiles();
if (applyList.isCustomOrder()) {
// Generate .mod files with custom name
generateCustomModFiles(applyMods);
} else {
// Sort list to ASCII order before apply
Collections.sort(applyMods, new Comparator<Mod>() {
@Override
public int compare(Mod m1, Mod m2) {
return m1.getName().compareTo(m2.getName());
}
});
}
Collections.reverse(applyMods);
File inputFile = new File(ModManager.PATH + sep + ModManager.ACTMOD_FILE);
File tempFile = new File(ModManager.PATH + sep + ModManager.ACTMOD_FILE + ".tmp");
FileReader fileReader = new FileReader(inputFile);
FileWriter fileWriter = new FileWriter(tempFile);
Gson gson = new Gson();
JsonObject json = new JsonObject();
json = gson.fromJson(fileReader, JsonObject.class);
/*
if(!json.containsKey("disabled_dlcs"))
json.put("disabled_dlcs", new String[0]);
*/
JsonArray enabled_mods = new JsonArray();
String modfolder = "mod/";
// if(!(modfolder.lastIndexOf("/")==modfolder.length()-1)) modfolder+="/";
String prefix = "";
if (applyList.isCustomOrder())
prefix = "pmm_";
for (Mod mod : applyMods) {
String modpath = modfolder + prefix + mod.getFileName();
enabled_mods.add(modpath);
}
json.add("enabled_mods", enabled_mods);
try {
fileWriter.write(json.toString());
} catch (IOException e) {
ErrorPrint.printError(e, "When writing json");
e.printStackTrace();
}
fileReader.close();
fileWriter.close();
inputFile.delete();
boolean successful = tempFile.renameTo(inputFile);
return successful;
}
use of mod.Mod in project ParadoxosModManager by ThibautSF.
the class MyXML method getSavedList.
/**
* @return
*/
public List<ModList> getSavedList(Map<String, Mod> availableMods) {
List<ModList> userLists = new ArrayList<ModList>();
List<Element> modLists = root.getChildren(LIST);
Iterator<Element> i = modLists.iterator();
while (i.hasNext()) {
List<Mod> listMods = new ArrayList<Mod>();
Map<Integer, Mod> sortedMods = new TreeMap<Integer, Mod>();
List<Mod> unsortedMods = new ArrayList<Mod>();
Element oneListElement = (Element) i.next();
String listName = oneListElement.getAttribute(NAME).getValue();
boolean listCustomOrder = false;
try {
Attribute customOrderAttribute = oneListElement.getAttribute(CUSTOM_ORDER);
if (customOrderAttribute != null) {
listCustomOrder = customOrderAttribute.getBooleanValue();
}
} catch (DataConversionException e) {
// Bad value
}
String listDescr = "";
Element listDescrElement = oneListElement.getChild(DESCR);
if (listDescrElement != null)
listDescr = listDescrElement.getText();
String launchArgs = "";
Element listArgsElement = oneListElement.getChild(LAUNCHARGS);
if (listArgsElement != null)
launchArgs = listArgsElement.getText();
String listLang = null;
Element listLangElement = oneListElement.getChild(LANG);
if (listLangElement != null)
listLang = listLangElement.getText();
List<Element> modsElements = oneListElement.getChildren(MOD);
for (Element modElement : modsElements) {
List<Attribute> modElementAttr = modElement.getAttributes();
String fileName = "", modName = "", remoteFileId = null;
int modOrder = -1;
for (Attribute attribute : modElementAttr) {
switch(attribute.getName()) {
case ID:
case FILE_NAME:
fileName = attribute.getValue();
break;
case MOD_NAME:
modName = attribute.getValue();
break;
case REMOTE_ID:
remoteFileId = attribute.getValue();
break;
case MOD_ORDER:
try {
modOrder = attribute.getIntValue();
} catch (DataConversionException e) {
ErrorPrint.printError(e, "When reading mod order attribute (import)");
e.printStackTrace();
}
break;
default:
break;
}
}
Mod oneMod = availableMods.get(fileName);
if (oneMod == null) {
oneMod = new Mod(modName, fileName, remoteFileId);
if (remoteFileId != null && !"".equals(remoteFileId)) {
for (Mod mod : availableMods.values()) {
if (mod.getRemoteFileID().equals(remoteFileId)) {
oneMod = mod;
}
}
}
}
if (!unsortedMods.contains(oneMod) && !sortedMods.values().contains(oneMod)) {
if (modOrder >= 0) {
sortedMods.put(modOrder, oneMod);
} else {
unsortedMods.add(oneMod);
}
}
}
// Append mods with order value
listMods.addAll(sortedMods.values());
// Append mods without order value at the end of the list
Collections.sort(unsortedMods, new Comparator<Mod>() {
@Override
public int compare(Mod m1, Mod m2) {
return m1.getName().compareTo(m2.getName());
}
});
listMods.addAll(unsortedMods);
ModList oneList = new ModList(listName, listDescr, Languages.getLanguage(listLang), listMods, listCustomOrder, launchArgs);
userLists.add(oneList);
}
return userLists;
}
use of mod.Mod in project ParadoxosModManager by ThibautSF.
the class MyXML method importList.
public String importList(String xml, Map<String, Mod> availableMods) throws Exception {
SAXBuilder sxb = new SAXBuilder();
Document importDocument = sxb.build(xml);
Element importRoot = importDocument.getRootElement();
if (importRoot.getAttribute(GAME_ID).getValue().equals(ModManager.STEAM_ID.toString())) {
List<Element> modLists = importRoot.getChildren(LIST);
Iterator<Element> i = modLists.iterator();
while (i.hasNext()) {
List<Mod> listMods = new ArrayList<Mod>();
Map<Integer, Mod> sortedMods = new TreeMap<Integer, Mod>();
List<Mod> unsortedMods = new ArrayList<Mod>();
Element oneListElement = (Element) i.next();
String listName = oneListElement.getAttribute(NAME).getValue();
boolean listCustomOrder = false;
try {
Attribute customOrderAttribute = oneListElement.getAttribute(CUSTOM_ORDER);
if (customOrderAttribute != null) {
listCustomOrder = customOrderAttribute.getBooleanValue();
}
} catch (DataConversionException e) {
// Bad value
}
String listDescr = "";
Element listDescrElement = oneListElement.getChild(DESCR);
if (listDescrElement != null)
listDescr = listDescrElement.getText();
String launchArgs = "";
Element listArgsElement = oneListElement.getChild(LAUNCHARGS);
if (listArgsElement != null)
launchArgs = listArgsElement.getText();
String listLang = null;
Element listLangElement = oneListElement.getChild(LANG);
if (listLangElement != null)
listLang = listLangElement.getText();
List<Element> modsElements = oneListElement.getChildren(MOD);
for (Element modElement : modsElements) {
List<Attribute> modElementAttr = modElement.getAttributes();
String fileName = "", modName = "", remoteFileId = null;
int modOrder = -1;
for (Attribute attribute : modElementAttr) {
switch(attribute.getName()) {
case ID:
case FILE_NAME:
fileName = attribute.getValue();
break;
case MOD_NAME:
modName = attribute.getValue();
break;
case REMOTE_ID:
remoteFileId = attribute.getValue();
break;
case MOD_ORDER:
try {
modOrder = attribute.getIntValue();
} catch (DataConversionException e) {
ErrorPrint.printError(e, "When reading mod order attribute (import)");
e.printStackTrace();
}
break;
default:
break;
}
}
Mod oneMod = availableMods.get(fileName);
if (oneMod == null) {
oneMod = new Mod(modName, fileName, remoteFileId);
if (remoteFileId != null && !"".equals(remoteFileId)) {
for (Mod mod : availableMods.values()) {
if (mod.getRemoteFileID().equals(remoteFileId)) {
oneMod = mod;
}
}
}
}
if (!unsortedMods.contains(oneMod) && !sortedMods.values().contains(oneMod)) {
if (modOrder >= 0) {
sortedMods.put(modOrder, oneMod);
} else {
unsortedMods.add(oneMod);
}
}
}
// Append mods with order value
listMods.addAll(sortedMods.values());
// Append mods without order value at the end of the list
Collections.sort(unsortedMods, new Comparator<Mod>() {
@Override
public int compare(Mod m1, Mod m2) {
return m1.getName().compareTo(m2.getName());
}
});
listMods.addAll(unsortedMods);
ModList oneList = new ModList("[Imported]" + listName + "_" + System.currentTimeMillis(), listDescr, Languages.getLanguage(listLang), listMods, listCustomOrder, launchArgs);
modifyList(oneList);
}
return "Import done.";
}
return "Import procedure aborted, this list is not for the current game !";
}
use of mod.Mod in project ParadoxosModManager by ThibautSF.
the class TestMod method modifiedFilestest.
@Test
public void modifiedFilestest() {
Mod mod = new Mod(modName, true);
Set<String> modifiedFiles = mod.getModifiedFiles();
Assert.assertEquals(7, modifiedFiles.size());
Assert.assertTrue(modifiedFiles.contains("gfx\\interface\\player_counters_toggle.dds"));
Assert.assertTrue(modifiedFiles.contains("gfx\\interface\\radar_toggle.dds"));
Assert.assertTrue(modifiedFiles.contains("gfx\\texticons\\air_experience_20x20.dds"));
Assert.assertTrue(modifiedFiles.contains("gfx\\texticons\\army_experience_20x20.dds"));
Assert.assertTrue(modifiedFiles.contains("gfx\\texticons\\navy_experience_20x20.dds"));
Assert.assertTrue(modifiedFiles.contains("localisation\\additional.yml"));
Assert.assertTrue(modifiedFiles.contains("localisation\\additional_l_french.yml"));
}
Aggregations