Fix file syncing
This commit is contained in:
parent
a1f5c9bc60
commit
555307ce2a
@ -35,6 +35,7 @@ import me.mrletsplay.shareclient.util.ProjectAndPath;
|
|||||||
import me.mrletsplay.shareclient.util.ProjectRelativePath;
|
import me.mrletsplay.shareclient.util.ProjectRelativePath;
|
||||||
import me.mrletsplay.shareclient.util.ShareSession;
|
import me.mrletsplay.shareclient.util.ShareSession;
|
||||||
import me.mrletsplay.shareclient.util.SharedProject;
|
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.ShareClientDocumentListener;
|
||||||
import me.mrletsplay.shareclient.util.listeners.ShareClientPageListener;
|
import me.mrletsplay.shareclient.util.listeners.ShareClientPageListener;
|
||||||
import me.mrletsplay.shareclient.util.listeners.ShareClientPartListener;
|
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?
|
// TODO: handle PRE_CLOSE events?
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,13 +106,16 @@ public class ShareClient extends AbstractUIPlugin implements MessageListener, Di
|
|||||||
|
|
||||||
IResource resource = delta.getResource();
|
IResource resource = delta.getResource();
|
||||||
SharedProject project = session.getSharedProject(resource.getProject());
|
SharedProject project = session.getSharedProject(resource.getProject());
|
||||||
|
|
||||||
if(project != null) {
|
if(project != null) {
|
||||||
|
if(project.getSyncState() == SyncState.SYNCING) return; // Project is not done syncing, ignore local changes
|
||||||
|
|
||||||
switch(delta.getKind()) {
|
switch(delta.getKind()) {
|
||||||
case IResourceDelta.ADDED -> {
|
case IResourceDelta.ADDED -> {
|
||||||
if(resource instanceof IFile file) {
|
if(resource instanceof IFile file) {
|
||||||
if(file.isDerived()) return;
|
if(file.isDerived()) return;
|
||||||
|
|
||||||
Path filePath = file.getFullPath().toPath();
|
Path filePath = file.getLocation().toPath();
|
||||||
ProjectAndPath path = getProjectAndPath(file);
|
ProjectAndPath path = getProjectAndPath(file);
|
||||||
ProjectRelativePath relativePath = new ProjectRelativePath(project.getRemoteName(), path.path());
|
ProjectRelativePath relativePath = new ProjectRelativePath(project.getRemoteName(), path.path());
|
||||||
SharedDocument document = session.getSharedDocument(relativePath);
|
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;
|
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) {
|
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) {
|
private ProjectAndPath getProjectAndPath(IFile file) {
|
||||||
IProject project = file.getProject();
|
IProject project = file.getProject();
|
||||||
Path projectLocation = project.getLocation().toPath();
|
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) {
|
private Map<ProjectRelativePath, Path> getProjectFiles(SharedProject project) {
|
||||||
|
@ -9,11 +9,13 @@ public class SharedProject {
|
|||||||
|
|
||||||
private String remoteName;
|
private String remoteName;
|
||||||
private IProject local;
|
private IProject local;
|
||||||
|
private SyncState syncState;
|
||||||
|
|
||||||
public SharedProject(String remoteName, IProject local) {
|
public SharedProject(String remoteName, IProject local) {
|
||||||
super();
|
super();
|
||||||
this.remoteName = remoteName;
|
this.remoteName = remoteName;
|
||||||
this.local = local;
|
this.local = local;
|
||||||
|
this.syncState = SyncState.SYNCING;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRemoteName() {
|
public String getRemoteName() {
|
||||||
@ -24,4 +26,12 @@ public class SharedProject {
|
|||||||
return local;
|
return local;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setSyncState(SyncState syncState) {
|
||||||
|
this.syncState = syncState;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SyncState getSyncState() {
|
||||||
|
return syncState;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
10
src/main/java/me/mrletsplay/shareclient/util/SyncState.java
Normal file
10
src/main/java/me/mrletsplay/shareclient/util/SyncState.java
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package me.mrletsplay.shareclient.util;
|
||||||
|
|
||||||
|
public enum SyncState {
|
||||||
|
|
||||||
|
SYNCING,
|
||||||
|
SYNCED,
|
||||||
|
OUT_OF_SYNC,
|
||||||
|
;
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user