diff --git a/eclipse.target b/eclipse.target index 9b32648..3cbcedd 100644 --- a/eclipse.target +++ b/eclipse.target @@ -26,8 +26,6 @@ x86_64 - linux - gtk en_US diff --git a/src/main/java/me/mrletsplay/shareclient/ShareClient.java b/src/main/java/me/mrletsplay/shareclient/ShareClient.java index d3031de..c6c759c 100644 --- a/src/main/java/me/mrletsplay/shareclient/ShareClient.java +++ b/src/main/java/me/mrletsplay/shareclient/ShareClient.java @@ -2,6 +2,7 @@ package me.mrletsplay.shareclient; import java.io.IOException; import java.net.URI; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.Arrays; @@ -227,10 +228,15 @@ public class ShareClient extends AbstractUIPlugin implements MessageListener, Di 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 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); if(listener != null) listener.setIgnoreChanges(false); } catch (IOException | CoreException e) { @@ -246,7 +252,6 @@ public class ShareClient extends AbstractUIPlugin implements MessageListener, Di // Sync entire (shared) workspace for (SharedProject project : activeSession.getSharedProjects()) { var files = getProjectFiles(project); - System.out.println(files); if (files == null) return; paths.putAll(files); } @@ -275,6 +280,7 @@ public class ShareClient extends AbstractUIPlugin implements MessageListener, Di } RemoteConnection connection = activeSession.getConnection(); + System.out.println(paths); for (var en : paths.entrySet()) { 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(); for(Map.Entry 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; } } @@ -330,11 +344,11 @@ public class ShareClient extends AbstractUIPlugin implements MessageListener, Di if (!Files.isRegularFile(filePath)) return true; try { - byte[] bytes = Files.readAllBytes(filePath); - 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 { + byte[] bytes = Files.readAllBytes(filePath); connection.send(new ChecksumMessage(siteID, relativePath.toString(), ChecksumUtil.generateSHA256(bytes))); } } catch (IOException | ConnectionException e) { @@ -359,6 +373,7 @@ public class ShareClient extends AbstractUIPlugin implements MessageListener, Di try { Path projectLocation = project.getLocal().getLocation().toPath(); return Files.walk(projectLocation) + .filter(Files::isRegularFile) .collect(Collectors.toMap( p -> new ProjectRelativePath(project.getRemoteName(), projectLocation.relativize(p).toString()), Function.identity())); diff --git a/src/main/java/me/mrletsplay/shareclient/util/ShareSession.java b/src/main/java/me/mrletsplay/shareclient/util/ShareSession.java index 7ef0c7f..462b86e 100644 --- a/src/main/java/me/mrletsplay/shareclient/util/ShareSession.java +++ b/src/main/java/me/mrletsplay/shareclient/util/ShareSession.java @@ -78,7 +78,6 @@ public class ShareSession { return sharedDocuments; } - public SharedDocument getSharedDocument(ProjectRelativePath path) { return sharedDocuments.get(path); }