Skip to content

Commit 6c2eb99

Browse files
committed
initial commit / first functional version
0 parents  commit 6c2eb99

File tree

6 files changed

+163
-0
lines changed

6 files changed

+163
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.idea
2+
target
3+
*.sav*
4+
ftlautosave.iml

pom.xml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>org.synogen</groupId>
6+
<artifactId>ftlautosave</artifactId>
7+
<version>0.0.1-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<name>ftlautosave</name>
11+
<url>http://maven.apache.org</url>
12+
13+
<properties>
14+
<maven.compiler.source>1.8</maven.compiler.source>
15+
<maven.compiler.target>1.8</maven.compiler.target>
16+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
17+
</properties>
18+
19+
<dependencies>
20+
<dependency>
21+
<groupId>junit</groupId>
22+
<artifactId>junit</artifactId>
23+
<version>4.12</version>
24+
<scope>test</scope>
25+
</dependency>
26+
</dependencies>
27+
28+
<build>
29+
<plugins>
30+
<plugin>
31+
<groupId>org.apache.maven.plugins</groupId>
32+
<artifactId>maven-jar-plugin</artifactId>
33+
<configuration>
34+
<archive>
35+
<manifest>
36+
<mainClass>org.synogen.ftlautosave.App</mainClass>
37+
</manifest>
38+
</archive>
39+
</configuration>
40+
</plugin>
41+
</plugins>
42+
</build>
43+
</project>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.synogen.ftlautosave;
2+
3+
public class App
4+
{
5+
public static void main( String[] args )
6+
{
7+
new Watch().start();
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.synogen.ftlautosave;
2+
3+
public class Config {
4+
5+
public static final Integer WATCH_INTERVAL = 1000;
6+
public static final String PROFILE_FILE = "ae_prof.sav";
7+
public static final String SAVE_FILE = "continue.sav";
8+
9+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package org.synogen.ftlautosave;
2+
3+
import java.io.IOException;
4+
import java.nio.file.Files;
5+
import java.nio.file.Path;
6+
import java.nio.file.Paths;
7+
import java.nio.file.StandardCopyOption;
8+
import java.util.logging.Logger;
9+
10+
public class Watch extends Thread {
11+
12+
private Logger log = Logger.getLogger(this.getName());
13+
14+
@Override
15+
public void run() {
16+
Path root = Paths.get(".");
17+
18+
Long lastModifiedProfile = 0l;
19+
Long lastModifiedSave = 0l;
20+
21+
Long currentModifiedProfile = 0l;
22+
Long currentModifiedSave = 0l;
23+
try {
24+
while (true) {
25+
Path profile = root.resolve(Config.PROFILE_FILE);
26+
Path savefile = root.resolve(Config.SAVE_FILE);
27+
28+
if (profile.toFile().exists()) {
29+
currentModifiedProfile = profile.toFile().lastModified();
30+
}
31+
if (savefile.toFile().exists()) {
32+
currentModifiedSave = savefile.toFile().lastModified();
33+
}
34+
35+
try {
36+
if (currentModifiedProfile.compareTo(lastModifiedProfile) != 0) {
37+
log.info("Profile file has changed, saving new backup");
38+
Path profileBackup = profile.resolveSibling(profile.getFileName() + "." + currentModifiedProfile);
39+
Files.copy(profile, profileBackup, StandardCopyOption.REPLACE_EXISTING);
40+
lastModifiedProfile = currentModifiedProfile;
41+
}
42+
if (currentModifiedSave.compareTo(lastModifiedSave) != 0) {
43+
log.info("Save file has changed, saving new backup");
44+
Path savefileBackup = savefile.resolveSibling(savefile.getFileName() + "." + currentModifiedSave);
45+
Files.copy(savefile, savefileBackup, StandardCopyOption.REPLACE_EXISTING);
46+
lastModifiedSave = currentModifiedSave;
47+
}
48+
} catch (IOException e) {
49+
log.warning("Error while creating backup:");
50+
e.printStackTrace();
51+
}
52+
53+
sleep(Config.WATCH_INTERVAL);
54+
}
55+
} catch (InterruptedException e) {
56+
log.info("Exiting save file watch");
57+
}
58+
}
59+
60+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package org.synogen.ftlautosave;
2+
3+
import junit.framework.Test;
4+
import junit.framework.TestCase;
5+
import junit.framework.TestSuite;
6+
7+
/**
8+
* Unit test for simple App.
9+
*/
10+
public class AppTest
11+
extends TestCase
12+
{
13+
/**
14+
* Create the test case
15+
*
16+
* @param testName name of the test case
17+
*/
18+
public AppTest( String testName )
19+
{
20+
super( testName );
21+
}
22+
23+
/**
24+
* @return the suite of tests being tested
25+
*/
26+
public static Test suite()
27+
{
28+
return new TestSuite( AppTest.class );
29+
}
30+
31+
/**
32+
* Rigourous Test :-)
33+
*/
34+
public void testApp()
35+
{
36+
assertTrue( true );
37+
}
38+
}

0 commit comments

Comments
 (0)