added "UseWorkshop" function

Try to find the correct pbo from the steam "!Workshop" folder in order to reduce downloads
This commit is contained in:
Niklas 2020-03-30 17:19:07 +02:00
parent 91c72f06cc
commit b663af52f6
4 changed files with 90 additions and 3 deletions

View File

@ -1060,6 +1060,14 @@ public class LauncherGUI implements Observer {
case FINNISHED: case FINNISHED:
refreshRepoButton.setEnabled(true); refreshRepoButton.setEnabled(true);
updateRepoTree(); updateRepoTree();
final Parameter<Boolean> checkModsetParameter = Parameters.CHECK_MODSET.toBooolParameter();
if(checkModsetParameter.getValue() != null && checkModsetParameter.getValue()) {
if(!fileChecker.isChecked()) {
SwingUtilities.invokeLater(() -> fileCheck(false));
Logger.getLogger(getClass().getName()).log(Level.INFO, "Started file check on launch");
}
}
break; break;
case RUNNING: case RUNNING:
@ -1122,7 +1130,8 @@ public class LauncherGUI implements Observer {
lastSynclist = null; lastSynclist = null;
} else if (s.equals("syncStopped")) { } else if (s.equals("syncStopped")) {
new Thread(() -> fileChecker.check(true)).start(); final Parameter<Boolean> workshopParameter = Parameters.USE_WORKSHOP.toBooolParameter();
new Thread(() -> fileChecker.check(!(workshopParameter.getValue() != null && workshopParameter.getValue()))).start();
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
syncDownloadButton.setEnabled(false); syncDownloadButton.setEnabled(false);
syncDownloadAbortButton.setEnabled(false); syncDownloadAbortButton.setEnabled(false);
@ -1133,7 +1142,8 @@ public class LauncherGUI implements Observer {
TaskBarUtils.getInstance().off(); TaskBarUtils.getInstance().off();
}); });
} else if (s.equals("syncComplete")) { } else if (s.equals("syncComplete")) {
new Thread(() -> fileChecker.check(true)).start(); final Parameter<Boolean> workshopParameter = Parameters.USE_WORKSHOP.toBooolParameter();
new Thread(() -> fileChecker.check(!(workshopParameter.getValue() != null && workshopParameter.getValue()))).start();
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
syncDownloadButton.setEnabled(false); syncDownloadButton.setEnabled(false);
syncDownloadAbortButton.setEnabled(false); syncDownloadAbortButton.setEnabled(false);

View File

@ -138,7 +138,9 @@ public class FileChecker implements Observable {
if (modPath == null) modPath = ""; if (modPath == null) modPath = "";
try { try {
List<Path> filePathList = Files.find(Paths.get(modPath), final Path path = Paths.get(modPath);
if(!path.toFile().exists() || !path.toFile().isDirectory()) return;
List<Path> filePathList = Files.find(path,
Integer.MAX_VALUE, Integer.MAX_VALUE,
(filePath, fileAttr) -> fileAttr.isRegularFile()) (filePath, fileAttr) -> fileAttr.isRegularFile())
.collect(Collectors.toList()); .collect(Collectors.toList());

View File

@ -5,6 +5,8 @@ import co.bitshfted.xapps.zsync.ZsyncException;
import co.bitshfted.xapps.zsync.http.ContentRange; import co.bitshfted.xapps.zsync.http.ContentRange;
import de.mc8051.arma3launcher.ArmA3Launcher; import de.mc8051.arma3launcher.ArmA3Launcher;
import de.mc8051.arma3launcher.LauncherGUI; import de.mc8051.arma3launcher.LauncherGUI;
import de.mc8051.arma3launcher.Parameter;
import de.mc8051.arma3launcher.Parameters;
import de.mc8051.arma3launcher.interfaces.Observable; import de.mc8051.arma3launcher.interfaces.Observable;
import de.mc8051.arma3launcher.interfaces.Observer; import de.mc8051.arma3launcher.interfaces.Observer;
import de.mc8051.arma3launcher.objects.AbstractMod; import de.mc8051.arma3launcher.objects.AbstractMod;
@ -13,15 +15,21 @@ import de.mc8051.arma3launcher.utils.Humanize;
import de.mc8051.arma3launcher.utils.TaskBarUtils; import de.mc8051.arma3launcher.utils.TaskBarUtils;
import javax.swing.*; import javax.swing.*;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.stream.Collectors;
/** /**
* Created by gurkengewuerz.de on 25.03.2020. * Created by gurkengewuerz.de on 25.03.2020.
@ -58,6 +66,8 @@ public class Syncer implements Observable, SyncListener {
private Zsync zsync; private Zsync zsync;
private LauncherGUI gui; private LauncherGUI gui;
private Map<Path, Long> workshopFiles = new HashMap<>();
public Syncer(LauncherGUI gui) { public Syncer(LauncherGUI gui) {
zsync = new Zsync(); zsync = new Zsync();
this.gui = gui; this.gui = gui;
@ -88,6 +98,9 @@ public class Syncer implements Observable, SyncListener {
TaskBarUtils.getInstance().normal(); TaskBarUtils.getInstance().normal();
}); });
final Parameter<Boolean> workshopParameter = Parameters.USE_WORKSHOP.toBooolParameter();
if(workshopParameter.getValue() != null && workshopParameter.getValue()) workshopFiles = WorkshopUtil.workshopFiles();
boolean lastPause = false; boolean lastPause = false;
while (running) { while (running) {
if (stopped) { if (stopped) {
@ -131,6 +144,28 @@ public class Syncer implements Observable, SyncListener {
} }
if (mf != null) { if (mf != null) {
final Path mfPath = mf.getLocaleFile().toPath();
if(!workshopFiles.isEmpty()) {
try {
final String modfilePatj = mf.getModfileString().replace("/", File.separator).toLowerCase();
Map.Entry<Path, Long> workshopFile = workshopFiles.entrySet()
.stream().filter(e -> e.getKey().toAbsolutePath().toString().toLowerCase().endsWith(modfilePatj)).findFirst().get();
if(workshopFile.getValue() == mf.getSize()) {
Files.copy(workshopFile.getKey(), mfPath, StandardCopyOption.REPLACE_EXISTING);
Logger.getLogger(getClass().getName()).log(Level.INFO, "Found workshop file and copied: " + mfPath);
success++;
finnishCurrent();
continue;
}
} catch (NoSuchElementException | IOException ignored) {}
}
if(workshopFiles.containsKey(mfPath)) {
final Long workshopFileSize = workshopFiles.get(mfPath);
if(mf.getSize() == workshopFileSize) {
Logger.getLogger(getClass().getName()).log(Level.INFO, mfPath + "");
}
}
Zsync.Options o = new Zsync.Options(); Zsync.Options o = new Zsync.Options();
o.setOutputFile(Paths.get(mf.getLocaleFile().getAbsolutePath())); o.setOutputFile(Paths.get(mf.getLocaleFile().getAbsolutePath()));
o.setUseragent(ArmA3Launcher.USER_AGENT); o.setUseragent(ArmA3Launcher.USER_AGENT);

View File

@ -0,0 +1,40 @@
package de.mc8051.arma3launcher.repo.sync;
import de.mc8051.arma3launcher.Parameters;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
/**
* Created by gurkengewuerz.de on 30.03.2020.
*/
public class WorkshopUtil {
public static Map<Path, Long> workshopFiles() {
Map<Path, Long> fileMap = new HashMap<>();
final String armaPath = Parameters.ARMA_PATH.toStringParameter().getValue();
if(armaPath == null) return fileMap;
final Path workshopPath = Paths.get(armaPath, "!Workshop");
if(!workshopPath.toFile().exists()) return fileMap;
if(!workshopPath.toFile().isDirectory()) return fileMap;
try {
fileMap = Files.find(workshopPath,
Integer.MAX_VALUE,
(filePath, fileAttr) -> fileAttr.isRegularFile())
.filter((p) -> p.toFile().getName().endsWith(".pbo"))
.collect(Collectors.toMap(path -> path, path -> path.toFile().length()));
return fileMap;
} catch (IOException ex) {
return fileMap;
}
}
}