Update syncing (WIP)
This commit is contained in:
parent
856171acff
commit
1a8a559697
@ -26,8 +26,6 @@
|
|||||||
</locations>
|
</locations>
|
||||||
<environment>
|
<environment>
|
||||||
<arch>x86_64</arch>
|
<arch>x86_64</arch>
|
||||||
<os>linux</os>
|
|
||||||
<ws>gtk</ws>
|
|
||||||
<nl>en_US</nl>
|
<nl>en_US</nl>
|
||||||
</environment>
|
</environment>
|
||||||
<launcherArgs>
|
<launcherArgs>
|
||||||
|
@ -2,6 +2,7 @@ package me.mrletsplay.shareclient;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -227,10 +228,15 @@ public class ShareClient extends AbstractUIPlugin implements MessageListener, Di
|
|||||||
Files.createFile(filePath);
|
Files.createFile(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String content = sync.content().stream()
|
||||||
|
.map(c -> String.valueOf(c.value()))
|
||||||
|
.collect(Collectors.joining());
|
||||||
|
|
||||||
|
SharedDocument sharedDocument = activeSession.getOrCreateSharedDocument(path, () -> content);
|
||||||
// TODO: update sharedDocuments
|
// TODO: update sharedDocuments
|
||||||
|
|
||||||
if(listener != null) listener.setIgnoreChanges(true);
|
if(listener != null) listener.setIgnoreChanges(true);
|
||||||
Files.write(filePath, sync.content());
|
Files.write(filePath, content.getBytes(StandardCharsets.UTF_8)); // TODO: may cause problems with binary files? but they shouldn't be shared in the first place, so...
|
||||||
sharedProject.getLocal().refreshLocal(IResource.DEPTH_INFINITE, null);
|
sharedProject.getLocal().refreshLocal(IResource.DEPTH_INFINITE, null);
|
||||||
if(listener != null) listener.setIgnoreChanges(false);
|
if(listener != null) listener.setIgnoreChanges(false);
|
||||||
} catch (IOException | CoreException e) {
|
} catch (IOException | CoreException e) {
|
||||||
@ -246,7 +252,6 @@ public class ShareClient extends AbstractUIPlugin implements MessageListener, Di
|
|||||||
// Sync entire (shared) workspace
|
// Sync entire (shared) workspace
|
||||||
for (SharedProject project : activeSession.getSharedProjects()) {
|
for (SharedProject project : activeSession.getSharedProjects()) {
|
||||||
var files = getProjectFiles(project);
|
var files = getProjectFiles(project);
|
||||||
System.out.println(files);
|
|
||||||
if (files == null) return;
|
if (files == null) return;
|
||||||
paths.putAll(files);
|
paths.putAll(files);
|
||||||
}
|
}
|
||||||
@ -275,6 +280,7 @@ public class ShareClient extends AbstractUIPlugin implements MessageListener, Di
|
|||||||
}
|
}
|
||||||
|
|
||||||
RemoteConnection connection = activeSession.getConnection();
|
RemoteConnection connection = activeSession.getConnection();
|
||||||
|
System.out.println(paths);
|
||||||
for (var en : paths.entrySet()) {
|
for (var en : paths.entrySet()) {
|
||||||
if(!sendFullSyncOrChecksum(connection, req.siteID(), en.getKey(), en.getValue(), false)) return;
|
if(!sendFullSyncOrChecksum(connection, req.siteID(), en.getKey(), en.getValue(), false)) return;
|
||||||
}
|
}
|
||||||
@ -321,7 +327,15 @@ public class ShareClient extends AbstractUIPlugin implements MessageListener, Di
|
|||||||
|
|
||||||
RemoteConnection connection = activeSession.getConnection();
|
RemoteConnection connection = activeSession.getConnection();
|
||||||
for(Map.Entry<ProjectRelativePath, Path> en : getProjectFiles(shared).entrySet()) {
|
for(Map.Entry<ProjectRelativePath, Path> en : getProjectFiles(shared).entrySet()) {
|
||||||
// TODO: add new document to sharedDocuments
|
activeSession.getOrCreateSharedDocument(en.getKey(), () -> {
|
||||||
|
try {
|
||||||
|
return Files.readString(en.getValue(), StandardCharsets.UTF_8);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -330,11 +344,11 @@ public class ShareClient extends AbstractUIPlugin implements MessageListener, Di
|
|||||||
if (!Files.isRegularFile(filePath)) return true;
|
if (!Files.isRegularFile(filePath)) return true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
byte[] bytes = Files.readAllBytes(filePath);
|
|
||||||
|
|
||||||
if(!checksum) {
|
if(!checksum) {
|
||||||
connection.send(new FullSyncMessage(siteID, relativePath.toString(), bytes));
|
SharedDocument document = activeSession.getSharedDocument(relativePath);
|
||||||
|
connection.send(new FullSyncMessage(siteID, relativePath.toString(), document.toList()));
|
||||||
}else {
|
}else {
|
||||||
|
byte[] bytes = Files.readAllBytes(filePath);
|
||||||
connection.send(new ChecksumMessage(siteID, relativePath.toString(), ChecksumUtil.generateSHA256(bytes)));
|
connection.send(new ChecksumMessage(siteID, relativePath.toString(), ChecksumUtil.generateSHA256(bytes)));
|
||||||
}
|
}
|
||||||
} catch (IOException | ConnectionException e) {
|
} catch (IOException | ConnectionException e) {
|
||||||
@ -359,6 +373,7 @@ public class ShareClient extends AbstractUIPlugin implements MessageListener, Di
|
|||||||
try {
|
try {
|
||||||
Path projectLocation = project.getLocal().getLocation().toPath();
|
Path projectLocation = project.getLocal().getLocation().toPath();
|
||||||
return Files.walk(projectLocation)
|
return Files.walk(projectLocation)
|
||||||
|
.filter(Files::isRegularFile)
|
||||||
.collect(Collectors.toMap(
|
.collect(Collectors.toMap(
|
||||||
p -> new ProjectRelativePath(project.getRemoteName(), projectLocation.relativize(p).toString()),
|
p -> new ProjectRelativePath(project.getRemoteName(), projectLocation.relativize(p).toString()),
|
||||||
Function.identity()));
|
Function.identity()));
|
||||||
|
@ -78,7 +78,6 @@ public class ShareSession {
|
|||||||
return sharedDocuments;
|
return sharedDocuments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public SharedDocument getSharedDocument(ProjectRelativePath path) {
|
public SharedDocument getSharedDocument(ProjectRelativePath path) {
|
||||||
return sharedDocuments.get(path);
|
return sharedDocuments.get(path);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user