-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d03ffdf
commit 78ece97
Showing
60 changed files
with
1,832 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...Plugin/src/main/java/io/github/deltacv/papervision/plugin/project/PaperVisionProject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.github.deltacv.papervision.plugin.project; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.JsonElement; | ||
|
||
public class PaperVisionProject { | ||
|
||
public long timestamp; | ||
public String path; | ||
public String name; | ||
public JsonElement json; | ||
|
||
private static final Gson gson = new Gson(); | ||
|
||
public PaperVisionProject(long timestamp, String path, String name, JsonElement json) { | ||
this.timestamp = timestamp; | ||
this.path = path; | ||
this.name = name; | ||
this.json = json; | ||
} | ||
|
||
public static PaperVisionProject fromJson(String jsonString) { | ||
return gson.fromJson(jsonString, PaperVisionProject.class); | ||
} | ||
|
||
public String toJson() { | ||
return gson.toJson(this); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...src/main/java/io/github/deltacv/papervision/plugin/project/recovery/RecoveredProject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package io.github.deltacv.papervision.plugin.project.recovery; | ||
|
||
import com.google.gson.Gson; | ||
import io.github.deltacv.papervision.plugin.project.PaperVisionProject; | ||
|
||
public class RecoveredProject { | ||
public String originalProjectPath; | ||
public long date; | ||
public String hash; | ||
public PaperVisionProject project; | ||
|
||
private static final Gson gson = new Gson(); | ||
|
||
public RecoveredProject(String originalProjectPath, long date, String hash, PaperVisionProject project) { | ||
this.originalProjectPath = originalProjectPath; | ||
this.date = date; | ||
this.hash = hash; | ||
this.project = project; | ||
} | ||
|
||
public String toJson() { | ||
return gson.toJson(this); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "RecoveredProject{" + | ||
"path='" + originalProjectPath + '\'' + | ||
", date=" + date + | ||
", hash='" + hash + '\'' + | ||
'}'; | ||
} | ||
|
||
public static RecoveredProject fromJson(String json) { | ||
return gson.fromJson(json, RecoveredProject.class); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
...main/java/io/github/deltacv/papervision/plugin/project/recovery/RecoveryDaemonClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package io.github.deltacv.papervision.plugin.project.recovery; | ||
|
||
import org.java_websocket.client.WebSocketClient; | ||
import org.java_websocket.handshake.ServerHandshake; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
public class RecoveryDaemonClient extends WebSocketClient { | ||
|
||
public static final int MAX_CONNECTION_ATTEMPTS_BEFORE_EXITING = 3; | ||
|
||
public RecoveryDaemonClient(int port) throws URISyntaxException { | ||
super(new URI("ws://localhost:" + port)); | ||
} | ||
|
||
@Override | ||
public void onOpen(ServerHandshake handshakedata) { | ||
System.out.println("Connected to recovery daemon server at port " + uri.getPort()); | ||
} | ||
|
||
@Override | ||
public void onMessage(String message) { | ||
try { | ||
RecoveryData recoveryData = RecoveryData.deserialize(message); | ||
Path recoveryPath = Paths.get(recoveryData.recoveryFolderPath); | ||
|
||
if (!Files.exists(recoveryPath)) { | ||
Files.createDirectories(recoveryPath); | ||
} | ||
|
||
Path recoveryFilePath = recoveryPath.resolve(recoveryData.recoveryFileName); | ||
Files.write(recoveryFilePath, recoveryData.projectData.toJson().getBytes()); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onClose(int code, String reason, boolean remote) { | ||
} | ||
|
||
@Override | ||
public void onError(Exception ex) { | ||
} | ||
|
||
public static void main(String[] args) { | ||
int port = args.length > 0 ? Integer.parseInt(args[0]) : 17112; | ||
|
||
RecoveryDaemonClient client = null; | ||
int connectionAttempts = 0; | ||
|
||
try { | ||
while(!Thread.interrupted()) { | ||
if(connectionAttempts >= MAX_CONNECTION_ATTEMPTS_BEFORE_EXITING) { | ||
System.out.println("Failed to connect to recovery daemon after " + MAX_CONNECTION_ATTEMPTS_BEFORE_EXITING + " attempts. Exiting..."); | ||
System.exit(0); | ||
} | ||
|
||
if(client == null || client.isClosed()) { | ||
client = new RecoveryDaemonClient(port); | ||
client.connect(); | ||
connectionAttempts += 1; | ||
} | ||
|
||
Thread.sleep(100); | ||
} | ||
} catch (URISyntaxException e) { | ||
throw new RuntimeException(e); | ||
} catch(InterruptedException ignored) { } | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...gin/src/main/java/io/github/deltacv/papervision/plugin/project/recovery/RecoveryData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.github.deltacv.papervision.plugin.project.recovery; | ||
|
||
import com.google.gson.Gson; | ||
|
||
public class RecoveryData { | ||
|
||
public String recoveryFolderPath; | ||
public String recoveryFileName; | ||
public RecoveredProject projectData; | ||
|
||
private static final Gson gson = new Gson(); | ||
|
||
public RecoveryData(String recoveryFolderPath, String recoveryFileName, RecoveredProject projectData) { | ||
this.recoveryFolderPath = recoveryFolderPath; | ||
this.recoveryFileName = recoveryFileName; | ||
this.projectData = projectData; | ||
} | ||
|
||
public static String serialize(RecoveryData data) { | ||
return gson.toJson(data); | ||
} | ||
|
||
public static RecoveryData deserialize(String json) { | ||
return gson.fromJson(json, RecoveryData.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.