use of mod.Mod in project ParadoxosModManager by ThibautSF.
the class ListManager method applyOneModList.
/**
* @param selected
* @return
* @throws IOException
*/
private boolean applyOneModList(ModList applyList) throws IOException {
List<Mod> applyMods = applyList.getModlist();
String sep = File.separator;
File inputFile = new File(ModManager.PATH + sep + "settings.txt");
File tempFile = new File(ModManager.PATH + sep + "new_setting.tmp");
BufferedReader reader = new BufferedReader(new FileReader(inputFile));
BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile));
String startLineRemove = "gui";
String aloneLineRemove = "language";
String currentLine;
boolean startEdit = false, startCopy = true, noLast_Mods = true, hasEqual = false, waitEqual = false;
while ((currentLine = reader.readLine()) != null) {
// trim newline when comparing with lineToRemove
String trimmedLine = currentLine.trim();
if (hasEqual && trimmedLine.contains("{")) {
hasEqual = false;
startEdit = true;
writer.write(currentLine.substring(0, currentLine.indexOf("{") + 1) + System.getProperty("line.separator"));
}
if (waitEqual && trimmedLine.contains("=")) {
waitEqual = false;
if (trimmedLine.contains("{")) {
startEdit = true;
writer.write(currentLine.substring(0, currentLine.indexOf("{") + 1) + System.getProperty("line.separator"));
} else {
hasEqual = true;
}
}
if (trimmedLine.contains(startLineRemove)) {
String toWrite;
if (trimmedLine.contains(startLineRemove + "={")) {
startEdit = true;
toWrite = currentLine.substring(0, currentLine.indexOf("{") + 1);
} else if (trimmedLine.contains(startLineRemove + "=")) {
hasEqual = true;
toWrite = currentLine.substring(0, currentLine.indexOf("=") + 1);
} else {
waitEqual = true;
toWrite = currentLine.substring(0, currentLine.indexOf(startLineRemove.charAt(startLineRemove.length() - 1)));
}
if (startLineRemove.equals("last_mods")) {
noLast_Mods = false;
}
startCopy = false;
writer.write(toWrite + System.getProperty("line.separator"));
}
if (startEdit) {
if (startLineRemove.equals("gui")) {
printLanguageBloc(applyList.getLanguageCode(), writer);
startLineRemove = "last_mods";
} else {
modPrint(applyMods, writer);
}
startEdit = false;
} else {
if (startCopy) {
if (trimmedLine.contains(aloneLineRemove)) {
writer.write(aloneLineRemove + "=\"" + applyList.getLanguageCode() + "\"" + System.getProperty("line.separator"));
startLineRemove = "last_mods";
} else {
writer.write(currentLine + System.getProperty("line.separator"));
}
}
if (!startCopy && !hasEqual && !waitEqual) {
if (trimmedLine.contains("}")) {
startCopy = true;
writer.write(currentLine.substring(currentLine.indexOf("}"), currentLine.length()) + System.getProperty("line.separator"));
}
}
}
}
if (noLast_Mods) {
writer.write("last_mods={" + System.getProperty("line.separator"));
modPrint(applyMods, writer);
writer.write("}" + System.getProperty("line.separator"));
}
writer.close();
reader.close();
inputFile.delete();
boolean successful = tempFile.renameTo(inputFile);
return successful;
}
use of mod.Mod in project ParadoxosModManager by ThibautSF.
the class ListCreator method refresh.
private void refresh(Languages language) {
cbListLang.setValue(language);
for (Mod mod : selectedModsList) {
if (!listOfMods.contains(mod))
listOfMods.add(mod);
}
for (Mod mod : missingMods) {
if (!listOfMods.contains(mod))
listOfMods.add(mod);
}
if (missingMods.size() > 0)
saveifMissings.setVisible(true);
else
saveifMissings.setVisible(false);
mods.refresh();
modsOrdering.refresh();
}
use of mod.Mod in project ParadoxosModManager by ThibautSF.
the class ListCreator method printModList.
/**
*/
private void printModList() {
List<Mod> modsFromList = list.getModlist();
for (Mod oneMod : modsFromList) {
if (oneMod.isMissing()) {
missingMods.add(oneMod);
continue;
}
if (userMods.contains(oneMod))
selectedModsList.add(oneMod);
}
listOfMods.addAll(missingMods);
listOfMods.addAll(userMods);
mods.setItems(listOfMods);
}
use of mod.Mod in project ParadoxosModManager by ThibautSF.
the class ListManager method applyOneModListV1.
/**
* @param selected
* @return
* @throws IOException
*/
private boolean applyOneModListV1(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());
}
});
}
File inputFile = new File(ModManager.PATH + sep + ModManager.SETTING_FILE);
File tempFile = new File(ModManager.PATH + sep + ModManager.SETTING_FILE + ".tmp");
BufferedReader reader = new BufferedReader(new FileReader(inputFile));
BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile));
String startLineRemove = "gui";
String aloneLineRemove = "language";
String currentLine;
boolean startEdit = false, startCopy = true, noLast_Mods = true, hasEqual = false, waitEqual = false;
while ((currentLine = reader.readLine()) != null) {
// trim newline when comparing with lineToRemove
String trimmedLine = currentLine.trim();
if (hasEqual && trimmedLine.contains("{")) {
hasEqual = false;
startEdit = true;
writer.write(currentLine.substring(0, currentLine.indexOf("{") + 1) + System.getProperty("line.separator"));
}
if (waitEqual && trimmedLine.contains("=")) {
waitEqual = false;
if (trimmedLine.contains("{")) {
startEdit = true;
writer.write(currentLine.substring(0, currentLine.indexOf("{") + 1) + System.getProperty("line.separator"));
} else {
hasEqual = true;
}
}
if (trimmedLine.contains(startLineRemove)) {
String toWrite;
if (trimmedLine.contains(startLineRemove + "={")) {
startEdit = true;
toWrite = currentLine.substring(0, currentLine.indexOf("{") + 1);
} else if (trimmedLine.contains(startLineRemove + "=")) {
hasEqual = true;
toWrite = currentLine.substring(0, currentLine.indexOf("=") + 1);
} else {
waitEqual = true;
toWrite = currentLine.substring(0, currentLine.indexOf(startLineRemove.charAt(startLineRemove.length() - 1)));
}
if (startLineRemove.equals("last_mods")) {
noLast_Mods = false;
}
startCopy = false;
writer.write(toWrite + System.getProperty("line.separator"));
}
if (startEdit) {
if (startLineRemove.equals("gui")) {
printLanguageBloc(applyList.getLanguageCode(), writer);
startLineRemove = "last_mods";
} else {
if (applyList.isCustomOrder())
modPrint(applyMods, writer, "pmm_");
else
modPrint(applyMods, writer);
}
startEdit = false;
} else {
if (startCopy) {
if (trimmedLine.contains(aloneLineRemove)) {
writer.write(aloneLineRemove + "=\"" + applyList.getLanguageCode() + "\"" + System.getProperty("line.separator"));
startLineRemove = "last_mods";
} else {
writer.write(currentLine + System.getProperty("line.separator"));
}
}
if (!startCopy && !hasEqual && !waitEqual) {
if (trimmedLine.contains("}")) {
startCopy = true;
writer.write(currentLine.substring(currentLine.indexOf("}"), currentLine.length()) + System.getProperty("line.separator"));
}
}
}
}
if (noLast_Mods) {
writer.write("last_mods={" + System.getProperty("line.separator"));
if (applyList.isCustomOrder())
modPrint(applyMods, writer, "pmm_");
else
modPrint(applyMods, writer);
writer.write("}" + System.getProperty("line.separator"));
}
writer.close();
reader.close();
inputFile.delete();
boolean successful = tempFile.renameTo(inputFile);
return successful;
}
use of mod.Mod in project ParadoxosModManager by ThibautSF.
the class ListManager method generateCustomModFiles.
/**
* @param applyMods
*/
private void generateCustomModFiles(List<Mod> applyMods) {
String sep = File.separator;
File modDir = new File(ModManager.PATH + sep + "mod");
File[] content = modDir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.toLowerCase().startsWith("pmm_") && name.toLowerCase().endsWith(".mod");
}
});
for (File file : content) {
file.delete();
}
// Create the custom .mod file for each mod (XXX_idorname.mod)
int n = applyMods.size();
int digits = 0;
do {
n = n / 10;
digits++;
} while (n != 0);
String numberFormat = "%0" + digits + "d";
String.format("%03d", 1);
for (int i = 0; i < applyMods.size(); i++) {
Mod mod = applyMods.get(i);
String customModName = String.format(numberFormat, i + 1) + "_" + mod.getName();
File modFile = new File(ModManager.PATH + sep + "mod" + sep + mod.getFileName());
File customModFile = new File(ModManager.PATH + sep + "mod" + sep + "pmm_" + mod.getFileName());
try {
Files.copy(Paths.get(modFile.getAbsolutePath()), Paths.get(customModFile.getAbsolutePath()), StandardCopyOption.REPLACE_EXISTING);
File inputFile = customModFile;
File tempFile = new File(ModManager.PATH + sep + "mod" + sep + String.format(numberFormat, i) + mod.getFileName() + ".tmp");
BufferedReader reader = new BufferedReader(new FileReader(inputFile));
BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile));
String aloneLineRemove = "name";
String currentLine;
boolean startEdit = false, startCopy = true, hasEqual = false, waitEqual = false;
while ((currentLine = reader.readLine()) != null) {
// trim newline when comparing with lineToRemove
String trimmedLine = currentLine.trim();
if (hasEqual && trimmedLine.contains("{")) {
hasEqual = false;
startEdit = true;
writer.write(currentLine.substring(0, currentLine.indexOf("{") + 1) + System.getProperty("line.separator"));
}
if (waitEqual && trimmedLine.contains("=")) {
waitEqual = false;
if (trimmedLine.contains("{")) {
startEdit = true;
writer.write(currentLine.substring(0, currentLine.indexOf("{") + 1) + System.getProperty("line.separator"));
} else {
hasEqual = true;
}
}
if (startEdit) {
startEdit = false;
} else {
if (startCopy) {
if (trimmedLine.contains(aloneLineRemove)) {
writer.write(aloneLineRemove + "=\"" + customModName + "\"" + System.getProperty("line.separator"));
} else {
writer.write(currentLine + System.getProperty("line.separator"));
}
}
if (!startCopy && !hasEqual && !waitEqual) {
if (trimmedLine.contains("}")) {
startCopy = true;
writer.write(currentLine.substring(currentLine.indexOf("}"), currentLine.length()) + System.getProperty("line.separator"));
}
}
}
}
writer.close();
reader.close();
inputFile.delete();
tempFile.renameTo(inputFile);
} catch (IOException e) {
ErrorPrint.printError(e, "Try to create a custom mod file");
}
}
}
Aggregations