fixed sync and timestamp when using workshop

This commit is contained in:
Niklas 2020-04-17 15:29:08 +02:00
parent a3ce01014e
commit 610d2e77b1
5 changed files with 40 additions and 13 deletions

View File

@ -1244,7 +1244,6 @@ public class LauncherGUI implements Observer {
techCheck(); techCheck();
} else if (s.equals("syncStopped")) { } else if (s.equals("syncStopped")) {
final Parameter workshopParameter = Parameters.USE_WORKSHOP.toParameter(); final Parameter workshopParameter = Parameters.USE_WORKSHOP.toParameter();
fileCheck(!(workshopParameter.getValue() != null && (boolean) workshopParameter.getValue()));
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
syncDownloadButton.setEnabled(false); syncDownloadButton.setEnabled(false);
syncDownloadAbortButton.setEnabled(false); syncDownloadAbortButton.setEnabled(false);
@ -1253,11 +1252,14 @@ public class LauncherGUI implements Observer {
syncStatusLabel.setText("Sync stopped"); syncStatusLabel.setText("Sync stopped");
TaskBarUtils.getInstance().setValue(0); TaskBarUtils.getInstance().setValue(0);
TaskBarUtils.getInstance().off(); TaskBarUtils.getInstance().off();
if (workshopParameter.getValue() != null && (boolean) workshopParameter.getValue()) checkType = FileChecker.Type.SLOW;
else checkType = FileChecker.Type.FAST;
RepositoryManger.getInstance().refreshModset();
}); });
techCheck(); techCheck();
} else if (s.equals("syncComplete")) { } else if (s.equals("syncComplete")) {
final Parameter workshopParameter = Parameters.USE_WORKSHOP.toParameter(); final Parameter workshopParameter = Parameters.USE_WORKSHOP.toParameter();
fileCheck(!(workshopParameter.getValue() != null && (boolean) workshopParameter.getValue()));
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
syncDownloadButton.setEnabled(false); syncDownloadButton.setEnabled(false);
syncDownloadAbortButton.setEnabled(false); syncDownloadAbortButton.setEnabled(false);
@ -1268,6 +1270,10 @@ public class LauncherGUI implements Observer {
TaskBarUtils.getInstance().off(); TaskBarUtils.getInstance().off();
TaskBarUtils.getInstance().attention(); TaskBarUtils.getInstance().attention();
TaskBarUtils.getInstance().notification("Sync complete", "", TrayIcon.MessageType.INFO); TaskBarUtils.getInstance().notification("Sync complete", "", TrayIcon.MessageType.INFO);
if (workshopParameter.getValue() != null && (boolean) workshopParameter.getValue()) checkType = FileChecker.Type.SLOW;
else checkType = FileChecker.Type.FAST;
RepositoryManger.getInstance().refreshModset();
}); });
techCheck(); techCheck();
} else if (s.equals("syncContinue")) { } else if (s.equals("syncContinue")) {
@ -1315,6 +1321,7 @@ public class LauncherGUI implements Observer {
syncIntensiveCheckButton.setEnabled(false); syncIntensiveCheckButton.setEnabled(false);
syncFastCheckButton.setEnabled(false); syncFastCheckButton.setEnabled(false);
syncCheckAbortButton.setEnabled(true); syncCheckAbortButton.setEnabled(true);
syncCheckProgress.setValue(0);
syncCheckStatusLabel.setText("Running!"); syncCheckStatusLabel.setText("Running!");
new Thread(() -> fileChecker.check(fastscan)).start(); new Thread(() -> fileChecker.check(fastscan)).start();
@ -1325,6 +1332,10 @@ public class LauncherGUI implements Observer {
repoTree.setCheckboxesEnabled(false); repoTree.setCheckboxesEnabled(false);
repoTree.setCheckboxesChecked(false); repoTree.setCheckboxesChecked(false);
syncSizeLabel.setText("0.0 B/0.0 B");
syncFileCountLabel.setText("");
syncDownloadSpeedLabel.setText("");
playButton.setEnabled(false); playButton.setEnabled(false);
playPresetButton.setEnabled(false); playPresetButton.setEnabled(false);
} }

View File

@ -29,7 +29,6 @@ public class ModFile implements AbstractMod {
private String parent; private String parent;
private String localGeneratedSHA1sum = ""; private String localGeneratedSHA1sum = "";
private long lastModified = -1; private long lastModified = -1;
private long localLastModified = -1;
public ModFile(File f, String modfile, String parent, long size, String sha1sum, long lastModified) { public ModFile(File f, String modfile, String parent, long size, String sha1sum, long lastModified) {
// File: Abosolut Path // File: Abosolut Path
@ -95,11 +94,7 @@ public class ModFile implements AbstractMod {
} }
public long getLocalLastModified() { public long getLocalLastModified() {
if (localLastModified <= 0 && exists()) { return (int) (f.lastModified() / 1000);
localLastModified = (int) (f.lastModified() / 1000);
}
return localLastModified;
} }
public long getLastModified() { public long getLastModified() {

View File

@ -137,15 +137,18 @@ public class FileChecker implements Observable {
return true; return true;
} }
if (mf.getLocalSize() != mf.getSize() int reason = -1;
|| mf.getLocalLastModified() != mf.getLastModified() if(mf.getLocalSize() != mf.getSize()) reason = 0;
|| (!fastscan && !mf.getSHA1Sum().equalsIgnoreCase(mf.getLocalGeneratedSHA1Sum()))) { else if (mf.getLocalLastModified() != mf.getLastModified()) reason = 1;
else if (!fastscan && !mf.getSHA1Sum().equalsIgnoreCase(mf.getLocalGeneratedSHA1Sum())) reason = 2;
if (reason != -1) {
if (changed.containsKey(mod)) temp = changed.get(mod); if (changed.containsKey(mod)) temp = changed.get(mod);
temp.add(mf); temp.add(mf);
changed.put(mod, temp); changed.put(mod, temp);
changedCount++; changedCount++;
size += mf.getSize(); size += mf.getSize();
logger.debug("File {} changed", mf.getLocaleFile().getAbsolutePath()); logger.debug("File {} changed. Reason: {}", mf.getLocaleFile().getAbsolutePath(), reason);
return true; return true;
} }

View File

@ -161,6 +161,14 @@ public class Syncer implements Observable, SyncListener {
logger.info("ZSync - Copied"); logger.info("ZSync - Copied");
SwingUtilities.invokeLater(() -> gui.syncStatusLabel.setText(mfModPath + ": Copied")); SwingUtilities.invokeLater(() -> gui.syncStatusLabel.setText(mfModPath + ": Copied"));
success++; success++;
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!");
}
finnishCurrent(); finnishCurrent();
continue; continue;
} }
@ -268,6 +276,16 @@ public class Syncer implements Observable, SyncListener {
final int percentage = (int) ((double) i / (double) Long.valueOf(syncCount).intValue() * 100); final int percentage = (int) ((double) i / (double) Long.valueOf(syncCount).intValue() * 100);
final String modPath = currentDownload.getModPath(); final String modPath = currentDownload.getModPath();
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!");
}
}
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
gui.syncDownloadProgress.setValue(i); gui.syncDownloadProgress.setValue(i);
gui.syncFileCountLabel.setText(i + "/" + syncCount + " (" + failed + " failed)"); gui.syncFileCountLabel.setText(i + "/" + syncCount + " (" + failed + " failed)");

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<properties> <properties>
<gui.version>0.1.1008</gui.version> <gui.version>0.1.1009</gui.version>
</properties> </properties>
<groupId>de.mc8051</groupId> <groupId>de.mc8051</groupId>