2020-03-30 15:07:02 +02:00
|
|
|
package de.mc8051.arma3launcher.repo.sync;
|
2020-03-26 02:26:31 +01:00
|
|
|
|
2020-03-27 03:04:15 +01:00
|
|
|
import co.bitshfted.xapps.zsync.Zsync;
|
|
|
|
import co.bitshfted.xapps.zsync.ZsyncException;
|
2020-03-29 21:01:22 +02:00
|
|
|
import co.bitshfted.xapps.zsync.http.ContentRange;
|
2020-03-27 03:04:15 +01:00
|
|
|
import de.mc8051.arma3launcher.ArmA3Launcher;
|
|
|
|
import de.mc8051.arma3launcher.LauncherGUI;
|
2020-03-30 17:19:07 +02:00
|
|
|
import de.mc8051.arma3launcher.Parameter;
|
|
|
|
import de.mc8051.arma3launcher.Parameters;
|
2020-03-27 03:04:15 +01:00
|
|
|
import de.mc8051.arma3launcher.interfaces.Observable;
|
|
|
|
import de.mc8051.arma3launcher.interfaces.Observer;
|
|
|
|
import de.mc8051.arma3launcher.objects.AbstractMod;
|
|
|
|
import de.mc8051.arma3launcher.objects.ModFile;
|
2020-03-27 14:40:44 +01:00
|
|
|
import de.mc8051.arma3launcher.utils.Humanize;
|
2020-03-28 05:17:50 +01:00
|
|
|
import de.mc8051.arma3launcher.utils.TaskBarUtils;
|
2020-04-01 18:55:10 +02:00
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
|
import org.apache.logging.log4j.Logger;
|
2020-03-27 03:04:15 +01:00
|
|
|
|
|
|
|
import javax.swing.*;
|
2020-03-30 17:19:07 +02:00
|
|
|
import java.io.File;
|
2020-03-27 03:04:15 +01:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.net.URI;
|
|
|
|
import java.nio.file.Files;
|
2020-03-29 21:01:22 +02:00
|
|
|
import java.nio.file.Path;
|
2020-03-27 03:04:15 +01:00
|
|
|
import java.nio.file.Paths;
|
2020-03-30 17:19:07 +02:00
|
|
|
import java.nio.file.StandardCopyOption;
|
2020-03-27 03:04:15 +01:00
|
|
|
import java.util.ArrayList;
|
2020-03-30 17:19:07 +02:00
|
|
|
import java.util.HashMap;
|
2020-03-27 03:04:15 +01:00
|
|
|
import java.util.List;
|
2020-03-30 17:19:07 +02:00
|
|
|
import java.util.Map;
|
|
|
|
import java.util.NoSuchElementException;
|
2020-03-27 03:04:15 +01:00
|
|
|
|
2020-03-26 02:26:31 +01:00
|
|
|
/**
|
|
|
|
* Created by gurkengewuerz.de on 25.03.2020.
|
|
|
|
*/
|
2020-03-29 21:01:22 +02:00
|
|
|
public class Syncer implements Observable, SyncListener {
|
2020-03-27 03:04:15 +01:00
|
|
|
|
2020-04-01 18:55:10 +02:00
|
|
|
private static final Logger logger = LogManager.getLogger(Syncer.class);
|
|
|
|
|
2020-03-27 03:04:15 +01:00
|
|
|
private List<Observer> observerList = new ArrayList<>();
|
|
|
|
|
|
|
|
private boolean stopped = false;
|
|
|
|
private boolean paused = false;
|
|
|
|
private boolean running = false;
|
|
|
|
|
|
|
|
private ModFile currentDownload = null;
|
|
|
|
private SyncList modlist;
|
|
|
|
|
|
|
|
private boolean currentDownload_failed = false;
|
|
|
|
private int failed = 0;
|
|
|
|
private int success = 0;
|
|
|
|
|
2020-03-28 05:17:50 +01:00
|
|
|
private long syncSize;
|
|
|
|
private int syncCount;
|
2020-03-27 03:04:15 +01:00
|
|
|
|
2020-04-23 03:56:56 +02:00
|
|
|
private long syncRealCount;
|
2020-03-29 21:01:22 +02:00
|
|
|
|
|
|
|
private SyncObserver syncObserver;
|
|
|
|
|
|
|
|
private long speedCalcSize = 0L;
|
|
|
|
private long speedCalcTime = 0L;
|
|
|
|
|
|
|
|
private long downloadStarted = 0L;
|
|
|
|
private long downloadSize = 0L;
|
2020-04-23 03:56:56 +02:00
|
|
|
private long currentDownloadDownloaded = 0L;
|
2020-03-27 03:04:15 +01:00
|
|
|
|
|
|
|
private Zsync zsync;
|
|
|
|
private LauncherGUI gui;
|
|
|
|
|
2020-03-30 17:19:07 +02:00
|
|
|
private Map<Path, Long> workshopFiles = new HashMap<>();
|
|
|
|
|
2020-03-27 03:04:15 +01:00
|
|
|
public Syncer(LauncherGUI gui) {
|
|
|
|
zsync = new Zsync();
|
|
|
|
this.gui = gui;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void sync(SyncList ml) {
|
|
|
|
modlist = ml;
|
|
|
|
|
|
|
|
stopped = false;
|
|
|
|
paused = false;
|
|
|
|
running = true;
|
|
|
|
|
|
|
|
currentDownload = null;
|
|
|
|
|
|
|
|
failed = 0;
|
|
|
|
success = 0;
|
|
|
|
|
2020-03-29 21:01:22 +02:00
|
|
|
syncRealCount = 0;
|
|
|
|
|
2020-03-27 03:04:15 +01:00
|
|
|
syncSize = ml.getSize();
|
|
|
|
syncCount = ml.getCount();
|
|
|
|
SwingUtilities.invokeLater(() -> {
|
2020-04-23 03:56:56 +02:00
|
|
|
gui.syncDownloadProgress.setMaximum(100);
|
2020-03-27 03:04:15 +01:00
|
|
|
gui.syncDownloadProgress.setValue(0);
|
2020-04-23 03:56:56 +02:00
|
|
|
gui.syncDownloadFileProgress.setMaximum(100);
|
|
|
|
gui.syncDownloadFileProgress.setValue(0);
|
2020-03-28 05:17:50 +01:00
|
|
|
TaskBarUtils.getInstance().normal();
|
2020-03-27 03:04:15 +01:00
|
|
|
});
|
|
|
|
|
2020-03-31 00:11:28 +02:00
|
|
|
final Parameter workshopParameter = Parameters.USE_WORKSHOP.toParameter();
|
|
|
|
if(workshopParameter.getValue() != null && (Boolean) workshopParameter.getValue()) workshopFiles = WorkshopUtil.workshopFiles();
|
2020-03-30 17:19:07 +02:00
|
|
|
|
2020-03-27 03:04:15 +01:00
|
|
|
boolean lastPause = false;
|
|
|
|
while (running) {
|
|
|
|
if (stopped) {
|
|
|
|
running = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (modlist.isEmpty()) {
|
|
|
|
running = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (paused) {
|
|
|
|
if (!lastPause) {
|
|
|
|
lastPause = true;
|
|
|
|
notifyObservers("syncPaused");
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
Thread.sleep(500);
|
|
|
|
} catch (InterruptedException e) {
|
2020-04-01 18:55:10 +02:00
|
|
|
logger.error(e);
|
2020-03-27 03:04:15 +01:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
} else if (lastPause) {
|
|
|
|
lastPause = false;
|
|
|
|
notifyObservers("syncContinue");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentDownload != null) {
|
|
|
|
try {
|
|
|
|
Thread.sleep(100);
|
|
|
|
} catch (InterruptedException e) {
|
2020-04-01 18:55:10 +02:00
|
|
|
logger.error(e);
|
2020-03-27 03:04:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AbstractMod abstractMod = modlist.get(0);
|
|
|
|
|
|
|
|
ModFile mf = null;
|
|
|
|
if (abstractMod instanceof ModFile) {
|
|
|
|
mf = (ModFile) abstractMod;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mf != null) {
|
2020-04-01 18:55:10 +02:00
|
|
|
logger.info("ZSync - Sync file {}", mf.getLocaleFile().getAbsolutePath());
|
|
|
|
|
2020-03-30 17:19:07 +02:00
|
|
|
final Path mfPath = mf.getLocaleFile().toPath();
|
2020-04-01 02:44:12 +02:00
|
|
|
final String mfModPath = mf.getModPath();
|
2020-03-30 17:19:07 +02:00
|
|
|
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()) {
|
2020-04-01 18:55:10 +02:00
|
|
|
logger.info("ZSync - Found file in {}. Copy.", workshopFile.getKey());
|
2020-04-01 02:44:12 +02:00
|
|
|
SwingUtilities.invokeLater(() -> gui.syncStatusLabel.setText(mfModPath + ": Found in Steam-Workshop. Copy."));
|
2020-03-30 17:19:07 +02:00
|
|
|
Files.copy(workshopFile.getKey(), mfPath, StandardCopyOption.REPLACE_EXISTING);
|
2020-04-01 18:55:10 +02:00
|
|
|
logger.info("ZSync - Copied");
|
2020-04-01 02:44:12 +02:00
|
|
|
SwingUtilities.invokeLater(() -> gui.syncStatusLabel.setText(mfModPath + ": Copied"));
|
2020-03-30 17:19:07 +02:00
|
|
|
success++;
|
2020-04-17 15:29:08 +02:00
|
|
|
|
|
|
|
long lastMotified = mf.getLastModified() * 1000;
|
|
|
|
if (mf.getLocaleFile().setLastModified(lastMotified)) {
|
|
|
|
logger.debug("ZSync - set last motified to {}", lastMotified);
|
|
|
|
} else {
|
|
|
|
logger.debug("ZSync - Failed to set last modified!");
|
|
|
|
}
|
|
|
|
|
2020-03-30 17:19:07 +02:00
|
|
|
finnishCurrent();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} catch (NoSuchElementException | IOException ignored) {}
|
|
|
|
}
|
|
|
|
|
2020-03-27 03:04:15 +01:00
|
|
|
Zsync.Options o = new Zsync.Options();
|
|
|
|
o.setOutputFile(Paths.get(mf.getLocaleFile().getAbsolutePath()));
|
2020-03-28 05:17:50 +01:00
|
|
|
o.setUseragent(ArmA3Launcher.USER_AGENT);
|
2020-03-27 03:04:15 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
currentDownload = mf;
|
|
|
|
currentDownload_failed = false;
|
2020-04-23 03:56:56 +02:00
|
|
|
downloadStarted = 0;
|
2020-03-27 03:04:15 +01:00
|
|
|
|
2020-03-29 21:01:22 +02:00
|
|
|
syncObserver = new SyncObserver(this);
|
|
|
|
zsync.zsync(URI.create(mf.getRemoteFile() + ".zsync"), o, syncObserver);
|
2020-03-27 03:04:15 +01:00
|
|
|
} catch (ZsyncException | IllegalArgumentException e) {
|
2020-04-01 18:55:10 +02:00
|
|
|
logger.error(e);
|
2020-03-27 03:04:15 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
modlist.remove(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteFiles();
|
|
|
|
cleanUpEmptyFolders();
|
|
|
|
|
|
|
|
if (stopped) {
|
|
|
|
notifyObservers("syncStopped");
|
|
|
|
} else {
|
|
|
|
notifyObservers("syncComplete");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void finnishCurrent() {
|
|
|
|
modlist.remove(0);
|
|
|
|
currentDownload = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void deleteFiles() {
|
|
|
|
modlist.getDeleted().stream()
|
|
|
|
.filter((p) -> p.toFile().exists())
|
|
|
|
.filter((p) -> p.toFile().canRead())
|
|
|
|
.filter((p) -> p.toFile().canWrite())
|
2020-04-01 18:55:10 +02:00
|
|
|
.forEach((p) -> {
|
|
|
|
logger.info(p.toFile().delete() ? "ZSync - Deleted file {}" : "ZSync - Error deleting file", p);
|
|
|
|
});
|
2020-03-27 03:04:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void cleanUpEmptyFolders() {
|
|
|
|
try {
|
|
|
|
String modPath = ArmA3Launcher.user_config.get("client", "modPath");
|
|
|
|
if (modPath == null) modPath = "";
|
|
|
|
if (modPath.isEmpty()) return;
|
|
|
|
Files.find(Paths.get(modPath),
|
|
|
|
Integer.MAX_VALUE,
|
|
|
|
(filePath, fileAttr) -> fileAttr.isDirectory())
|
|
|
|
.filter((p) -> p.toFile().canRead())
|
|
|
|
.filter((p) -> p.toFile().canWrite())
|
|
|
|
.filter((p) -> p.toFile().list().length == 0)
|
2020-04-01 18:55:10 +02:00
|
|
|
.forEach((p) -> {
|
|
|
|
logger.info(p.toFile().delete() ? "ZSync - Deleted empty folder {}" : "ZSync - Error deleting empty folder", p);
|
|
|
|
});;
|
2020-03-27 03:04:15 +01:00
|
|
|
} catch (IOException e) {
|
2020-04-01 18:55:10 +02:00
|
|
|
logger.error(e);
|
2020-03-27 03:04:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-03-29 21:01:22 +02:00
|
|
|
public void zsyncStarted(Zsync.Options options) {
|
2020-04-01 18:55:10 +02:00
|
|
|
logger.info("ZSync - started " + options.getOutputFile());
|
2020-03-28 05:17:50 +01:00
|
|
|
SwingUtilities.invokeLater(() -> gui.syncStatusLabel.setText(currentDownload.getModPath() + ": Sync started"));
|
2020-03-27 03:04:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void zsyncFailed(Exception exception) {
|
|
|
|
currentDownload_failed = true;
|
2020-04-01 18:55:10 +02:00
|
|
|
logger.error("ZSync - failed", exception);
|
2020-03-28 05:17:50 +01:00
|
|
|
SwingUtilities.invokeLater(() -> gui.syncStatusLabel.setText(currentDownload.getModPath() + ": Sync failed"));
|
2020-03-27 03:04:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void zsyncComplete() {
|
2020-04-01 18:55:10 +02:00
|
|
|
logger.info("ZSync - complete");
|
2020-03-27 03:04:15 +01:00
|
|
|
|
|
|
|
if (currentDownload_failed)
|
|
|
|
failed++;
|
|
|
|
else success++;
|
|
|
|
|
2020-04-23 03:56:56 +02:00
|
|
|
syncRealCount += currentDownloadDownloaded;
|
2020-03-29 21:01:22 +02:00
|
|
|
|
2020-03-28 05:17:50 +01:00
|
|
|
final int i = success + failed;
|
|
|
|
final String modPath = currentDownload.getModPath();
|
2020-03-27 03:04:15 +01:00
|
|
|
|
2020-04-17 15:29:08 +02:00
|
|
|
|
|
|
|
if(!currentDownload_failed) {
|
|
|
|
long lastMotified = currentDownload.getLastModified() * 1000;
|
|
|
|
if (currentDownload.getLocaleFile().setLastModified(lastMotified)) {
|
|
|
|
logger.debug("ZSync - set last motified to {}", lastMotified);
|
|
|
|
} else {
|
|
|
|
logger.debug("ZSync - Failed to set last modified!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-27 03:04:15 +01:00
|
|
|
SwingUtilities.invokeLater(() -> {
|
2020-04-23 03:56:56 +02:00
|
|
|
gui.syncDownloadFileProgress.setValue(0);
|
|
|
|
gui.syncDownloadFileProgress.setString("");
|
2020-03-28 05:17:50 +01:00
|
|
|
gui.syncFileCountLabel.setText(i + "/" + syncCount + " (" + failed + " failed)");
|
|
|
|
|
|
|
|
if (currentDownload_failed)
|
|
|
|
gui.syncStatusLabel.setText(modPath + ": Sync failed");
|
|
|
|
else
|
|
|
|
gui.syncStatusLabel.setText(modPath + ": Sync finished");
|
2020-03-27 03:04:15 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
finnishCurrent();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-03-29 21:01:22 +02:00
|
|
|
public void controlFileDownloadingStarted(Path path, long length) {
|
2020-04-01 18:55:10 +02:00
|
|
|
logger.debug("ZSync - control file downloading started: length {} bytes", length);
|
2020-03-28 05:17:50 +01:00
|
|
|
SwingUtilities.invokeLater(() -> gui.syncStatusLabel.setText(currentDownload.getModPath() + ": Get Header"));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-03-29 21:01:22 +02:00
|
|
|
public void controlFileReadingComplete() {
|
2020-04-01 18:55:10 +02:00
|
|
|
logger.debug("ZSync - control file downloading complete");
|
2020-03-27 03:04:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-03-29 21:01:22 +02:00
|
|
|
public void outputFileWritingStarted(long length) {
|
2020-04-01 18:55:10 +02:00
|
|
|
logger.debug("ZSync - output file writing started: {} bytes", length);
|
2020-03-29 21:01:22 +02:00
|
|
|
SwingUtilities.invokeLater(() -> gui.syncStatusLabel.setText(currentDownload.getModPath() + ": Writing File"));
|
|
|
|
}
|
2020-03-27 03:04:15 +01:00
|
|
|
|
2020-03-29 21:01:22 +02:00
|
|
|
@Override
|
|
|
|
public void outputFileWritingCompleted() {
|
2020-04-01 18:55:10 +02:00
|
|
|
logger.debug("ZSync - output file writing completed");
|
2020-03-29 21:01:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void inputFileReadingStarted(Path inputFile, long length) {
|
2020-04-01 18:55:10 +02:00
|
|
|
logger.info("ZSync - input file reading started: {} bytes", length);
|
2020-03-29 21:01:22 +02:00
|
|
|
SwingUtilities.invokeLater(() -> gui.syncStatusLabel.setText(currentDownload.getModPath() + ": Reading File"));
|
|
|
|
}
|
2020-03-28 05:17:50 +01:00
|
|
|
|
2020-03-29 21:01:22 +02:00
|
|
|
@Override
|
|
|
|
public void inputFileReadingComplete() {
|
2020-04-01 18:55:10 +02:00
|
|
|
logger.debug("ZSync - input file reading complete");
|
2020-03-29 21:01:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void controlFileDownloadingComplete() {
|
2020-04-01 18:55:10 +02:00
|
|
|
logger.debug("ZSync - control file downloading complete");
|
2020-03-29 21:01:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void remoteFileDownloadingInitiated(List<ContentRange> ranges) {
|
|
|
|
downloadStarted = System.currentTimeMillis();
|
2020-04-01 18:55:10 +02:00
|
|
|
logger.debug("ZSync - remote file downloading initiated");
|
2020-03-28 05:17:50 +01:00
|
|
|
SwingUtilities.invokeLater(() -> gui.syncStatusLabel.setText(currentDownload.getModPath() + ": Downloading"));
|
2020-03-27 03:04:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-03-29 21:01:22 +02:00
|
|
|
public void remoteFileDownloadingStarted(long length) {
|
2020-04-01 18:55:10 +02:00
|
|
|
logger.info("ZSync - remote file downloading started: {} bytes", length);
|
2020-03-29 21:01:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void remoteFileDownloadingComplete() {
|
2020-04-01 18:55:10 +02:00
|
|
|
logger.info("ZSync - remote file downloading complete");
|
2020-03-27 03:04:15 +01:00
|
|
|
}
|
|
|
|
|
2020-03-29 21:01:22 +02:00
|
|
|
@Override
|
|
|
|
public void bytesDownloaded(long bytes) {
|
|
|
|
}
|
2020-03-27 03:04:15 +01:00
|
|
|
|
|
|
|
public boolean isStopped() {
|
|
|
|
return stopped;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isPaused() {
|
|
|
|
return paused;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isRunning() {
|
|
|
|
return running;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void stop() {
|
|
|
|
this.stopped = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setPaused(boolean paused) {
|
|
|
|
this.paused = paused;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getCountFailed() {
|
|
|
|
return failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getCountSuccess() {
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void addObserver(Observer observer) {
|
|
|
|
observerList.add(observer);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void removeObserver(Observer observer) {
|
|
|
|
observerList.remove(observer);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void notifyObservers(String obj) {
|
|
|
|
for (Observer obs : observerList) obs.update(obj);
|
|
|
|
}
|
2020-04-23 03:56:56 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void bytesToDownload(long bytes) {
|
|
|
|
downloadSize = bytes;
|
|
|
|
currentDownloadDownloaded = 0;
|
|
|
|
speedCalcSize = 0;
|
|
|
|
speedCalcTime = 0;
|
|
|
|
logger.debug("Must download {} bytes", bytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void downloaded(long bytes) {
|
|
|
|
if(downloadStarted == 0) return;
|
|
|
|
currentDownloadDownloaded += bytes;
|
|
|
|
final int percentageFile = (int) (Long.valueOf(currentDownloadDownloaded).doubleValue() / Long.valueOf(downloadSize).doubleValue() * 100);
|
|
|
|
final String humanCurrent = Humanize.binaryPrefix(currentDownloadDownloaded);
|
|
|
|
final String humanDownloadSize = Humanize.binaryPrefix(downloadSize);
|
|
|
|
|
|
|
|
final long downloadProgress = syncRealCount + currentDownloadDownloaded;
|
|
|
|
final String humanProgress = Humanize.binaryPrefix(downloadProgress);
|
|
|
|
final long finalSize = syncRealCount + modlist.getSize();
|
|
|
|
final String humanfinalSize = Humanize.binaryPrefix(finalSize);
|
|
|
|
final int percentage = (int) (Long.valueOf(downloadProgress).doubleValue() / Long.valueOf(finalSize).doubleValue() * 100);
|
|
|
|
|
|
|
|
speedCalcSize+=currentDownloadDownloaded;
|
|
|
|
speedCalcTime+=System.currentTimeMillis()-downloadStarted;
|
|
|
|
|
|
|
|
if (speedCalcSize > 20 * 1024 * 1024) {
|
|
|
|
final double speedByte = ((double)speedCalcSize)/((double)speedCalcTime /1000);
|
|
|
|
SwingUtilities.invokeLater(() -> gui.syncDownloadSpeedLabel.setText(Humanize.binaryPrefix(Double.valueOf(speedByte).longValue()) + "/s"));
|
|
|
|
speedCalcSize = 0L;
|
|
|
|
speedCalcTime = 0L;
|
|
|
|
}
|
|
|
|
|
|
|
|
SwingUtilities.invokeLater(() -> {
|
|
|
|
gui.syncDownloadFileProgress.setValue(percentageFile);
|
|
|
|
gui.syncDownloadFileProgress.setString(humanCurrent + "/" + humanDownloadSize);
|
|
|
|
|
|
|
|
gui.syncDownloadProgress.setValue(percentage);
|
|
|
|
gui.syncDownloadProgress.setString(percentage + " %");
|
|
|
|
|
|
|
|
gui.syncSizeLabel.setText(humanProgress + "/" + humanfinalSize);
|
|
|
|
|
|
|
|
TaskBarUtils.getInstance().setValue(percentage);
|
|
|
|
});
|
|
|
|
}
|
2020-03-26 02:26:31 +01:00
|
|
|
}
|