Fix file syncing

This commit is contained in:
MrLetsplay 2024-06-26 21:00:17 +02:00
parent a1f5c9bc60
commit 555307ce2a
Signed by: mr
SSH Key Fingerprint: SHA256:92jBH80vpXyaZHjaIl47pjRq+Yt7XGTArqQg1V7hSqg
3 changed files with 29 additions and 3 deletions

View File

@ -35,6 +35,7 @@ import me.mrletsplay.shareclient.util.ProjectAndPath;
import me.mrletsplay.shareclient.util.ProjectRelativePath;
import me.mrletsplay.shareclient.util.ShareSession;
import me.mrletsplay.shareclient.util.SharedProject;
import me.mrletsplay.shareclient.util.SyncState;
import me.mrletsplay.shareclient.util.listeners.ShareClientDocumentListener;
import me.mrletsplay.shareclient.util.listeners.ShareClientPageListener;
import me.mrletsplay.shareclient.util.listeners.ShareClientPartListener;
@ -95,7 +96,7 @@ public class ShareClient extends AbstractUIPlugin implements MessageListener, Di
});
});
ResourcesPlugin.getWorkspace().addResourceChangeListener(event -> handleChange(event.getDelta()), IResourceChangeEvent.POST_CHANGE);
ResourcesPlugin.getWorkspace().addResourceChangeListener(event -> Display.getDefault().asyncExec(() -> handleChange(event.getDelta())), IResourceChangeEvent.POST_CHANGE);
// TODO: handle PRE_CLOSE events?
}
@ -105,13 +106,16 @@ public class ShareClient extends AbstractUIPlugin implements MessageListener, Di
IResource resource = delta.getResource();
SharedProject project = session.getSharedProject(resource.getProject());
if(project != null) {
if(project.getSyncState() == SyncState.SYNCING) return; // Project is not done syncing, ignore local changes
switch(delta.getKind()) {
case IResourceDelta.ADDED -> {
if(resource instanceof IFile file) {
if(file.isDerived()) return;
Path filePath = file.getFullPath().toPath();
Path filePath = file.getLocation().toPath();
ProjectAndPath path = getProjectAndPath(file);
ProjectRelativePath relativePath = new ProjectRelativePath(project.getRemoteName(), path.path());
SharedDocument document = session.getSharedDocument(relativePath);
@ -396,6 +400,8 @@ public class ShareClient extends AbstractUIPlugin implements MessageListener, Di
if(!sendFullSyncOrChecksum(connection, AddressableMessage.BROADCAST_SITE_ID, en.getKey(), en.getValue(), false)) return;
}
shared.setSyncState(SyncState.SYNCED);
}
private boolean sendFullSyncOrChecksum(RemoteConnection connection, int siteID, ProjectRelativePath relativePath, Path filePath, boolean checksum) {
@ -436,7 +442,7 @@ public class ShareClient extends AbstractUIPlugin implements MessageListener, Di
private ProjectAndPath getProjectAndPath(IFile file) {
IProject project = file.getProject();
Path projectLocation = project.getLocation().toPath();
return new ProjectAndPath(file.getProject(), projectLocation.relativize(file.getFullPath().toPath()).toString());
return new ProjectAndPath(file.getProject(), projectLocation.relativize(file.getLocation().toPath()).toString());
}
private Map<ProjectRelativePath, Path> getProjectFiles(SharedProject project) {

View File

@ -9,11 +9,13 @@ public class SharedProject {
private String remoteName;
private IProject local;
private SyncState syncState;
public SharedProject(String remoteName, IProject local) {
super();
this.remoteName = remoteName;
this.local = local;
this.syncState = SyncState.SYNCING;
}
public String getRemoteName() {
@ -24,4 +26,12 @@ public class SharedProject {
return local;
}
public void setSyncState(SyncState syncState) {
this.syncState = syncState;
}
public SyncState getSyncState() {
return syncState;
}
}

View File

@ -0,0 +1,10 @@
package me.mrletsplay.shareclient.util;
public enum SyncState {
SYNCING,
SYNCED,
OUT_OF_SYNC,
;
}