Skip to content

Commit

Permalink
#47 Remove config lockout
Browse files Browse the repository at this point in the history
The config directory can now be added to the directory include list to
sync all configs
  • Loading branch information
rheimus committed Feb 15, 2017
1 parent 32db5a4 commit be4bfd5
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 31 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ssversion = 2.6.6
ssversion = 2.6.7
ssname = serversync
2 changes: 1 addition & 1 deletion src/main/java/com/superzanti/lib/RefStrings.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
public class RefStrings {
public static final String MODID = "serversync";
public static final String NAME = "Server Sync";
public static final String VERSION = "2.6.6";
public static final String VERSION = "2.6.7";
}
6 changes: 5 additions & 1 deletion src/main/java/com/superzanti/serversync/ClientWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,10 @@ public void run() {
currentPercent++;

Path clientPath = file.MODPATH;
System.out.println(clientPath);
// Get file at rPath location
boolean exists = Files.exists(clientPath);
System.out.println(exists);

// Exists
if (exists) {
Expand All @@ -258,7 +260,8 @@ public void run() {
errorInUpdates = true;
}

if (clientFile != null) {
if (clientFile != null) {
System.out.println("Comparing: " + clientFile.fileName);
if (!clientFile.compare(file)) {
server.updateFile(file.MODPATH.toString(), clientPath.toFile());
} else {
Expand All @@ -273,6 +276,7 @@ public void run() {
} else {
logs.updateLogs(file.fileName + " " + Main.strings.getString("does_not_exist"), Logger.FULL_LOG);
server.updateFile(file.MODPATH.toString(), clientPath.toFile());
System.out.println("updated file: " + file.MODPATH.toString());
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/main/java/com/superzanti/serversync/ServerSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,16 @@ public static EnumMap<EServerMessage, String> generateServerMessages() {
protected ServerSetup() {
DateFormat dateFormatter = DateFormat.getDateInstance();
ArrayList<Path> _list = null;
boolean configsInDirectoryList = false;

/* SYNC DIRECTORIES */
for (String dir : Main.CONFIG.DIRECTORY_INCLUDE_LIST) {
// Specific config handling later
if (dir.equals("config") || dir.equals("clientmods")) {
if (dir.equals("config")) {
configsInDirectoryList = true;
directories.add(dir);
}
continue;
}
directories.add(dir);
Expand Down Expand Up @@ -102,11 +107,13 @@ protected ServerSetup() {
}

/* CONFIGS */
if (!Main.CONFIG.CONFIG_INCLUDE_LIST.isEmpty()) {
if (!Main.CONFIG.CONFIG_INCLUDE_LIST.isEmpty() && !configsInDirectoryList) {
_list = PathUtils.fileListDeep(Paths.get("config"));
System.out.println("Found " + _list.size() + " files in: config");
if (_list != null) {
for (Path path : _list) {
if (Main.CONFIG.CONFIG_INCLUDE_LIST.contains(path.getFileName().toString())) {
System.out.println("Including config: " + path.getFileName().toString());
allMods.add(new SyncFile(path,false));
}
}
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/com/superzanti/serversync/ServerWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,19 +185,27 @@ public void run() {

// Main file update message
if(message.equals(messages.get(EServerMessage.UPDATE))) {
System.out.println("Writing file to client...");


String filePathName;
try {
filePathName = (String) ois.readObject();
File f = new File(filePathName.replace("\\", "/"));
System.out.println("Writing " + f + " to client...");
byte[] buff = new byte[clientsocket.getSendBufferSize()];
int bytesRead = 0;
InputStream in = new FileInputStream(f);
while((bytesRead = in.read(buff))>0) {
//oos.writeObject("BLOB");
oos.write(buff,0,bytesRead);
if ((bytesRead = in.read(buff)) == -1) {
// End of file
oos.writeBoolean(false);
} else {
oos.writeBoolean(true);
oos.write(buff, 0, bytesRead);

while((bytesRead = in.read(buff))>0) {
//oos.writeObject("BLOB");
oos.write(buff,0,bytesRead);
}
}
in.close();
oos.flush();
Expand Down
36 changes: 24 additions & 12 deletions src/main/java/com/superzanti/serversync/gui/GUI_Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,21 +213,33 @@ public void run() {
}

public void updateProgress(int progress) {
B_sync.setText(progress + "%");
SwingUtilities.invokeLater(new Runnable() {

@Override
public void run() {
B_sync.setText(progress + "%");
}
});
}

public void updateFileProgress(String message, int progress) {
if (!PB_fileProgress.isVisible() && progress < 100) {
PB_fileProgress.setVisible(true);
}

PB_fileProgress.setString("<"+progress+"%> " + message);
PB_fileProgress.setValue(progress);

if (message == null) {
PB_fileProgress.setVisible(false);
PB_fileProgress.setString(null);
}
SwingUtilities.invokeLater(new Runnable() {

@Override
public void run() {
if (!PB_fileProgress.isVisible() && progress < 100) {
PB_fileProgress.setVisible(true);
}

PB_fileProgress.setString("<"+progress+"%> " + message);
PB_fileProgress.setValue(progress);

if (message == null) {
PB_fileProgress.setVisible(false);
PB_fileProgress.setString(null);
}
}
});
}

public void toggleButton() {
Expand Down
38 changes: 28 additions & 10 deletions src/main/java/com/superzanti/serversync/util/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.net.Socket;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.EnumMap;
import java.util.HashMap;
Expand Down Expand Up @@ -421,9 +423,20 @@ public boolean updateFile(String filePath, File currentFile) {
logs.outputError(filePath);
return false;
}

Path pFile = currentFile.toPath();

currentFile.getParentFile().mkdirs();

if (Files.exists(pFile)) {
try {
Files.delete(pFile);
Files.createFile(pFile);
} catch (IOException e) {
System.out.println("Failed to delete file: " + pFile.getFileName().toString());
}
}

try {
logs.updateLogs("Attempting to write file (" + currentFile + ")", Logger.FULL_LOG);
FileOutputStream wr = new FileOutputStream(currentFile);
Expand All @@ -434,18 +447,23 @@ public boolean updateFile(String filePath, File currentFile) {

double factor = 0;


while ((bytesReceived = ois.read(outBuffer)) > 0) {
bytesRecievedSoFar += bytesReceived;
factor = (double) bytesRecievedSoFar / numberOfBytesToRecieve;
System.out.println(factor);
System.out.println(bytesRecievedSoFar + " / " + numberOfBytesToRecieve);
wr.write(outBuffer, 0, bytesReceived);
GUIUpdater.updateProgress((int)Math.ceil(factor * 100), currentFile.getName());
if (factor == 1) {
break;
if(ois.readBoolean()) {
// Not empty file
while ((bytesReceived = ois.read(outBuffer)) > 0) {
bytesRecievedSoFar += bytesReceived;
factor = (double) bytesRecievedSoFar / numberOfBytesToRecieve;
System.out.println(factor);
System.out.println(bytesRecievedSoFar + " / " + numberOfBytesToRecieve);
wr.write(outBuffer, 0, bytesReceived);
GUIUpdater.updateProgress((int)Math.ceil(factor * 100), currentFile.getName());
if (factor == 1) {
break;
}
}
} else {
System.out.println("Empty file: " + currentFile);
}

GUIUpdater.fileFinished();
wr.flush();
wr.close();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/superzanti/serversync/util/SyncFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public SyncFile(Path modPath, boolean isMod) throws IOException {
// makes (ServerSyncDir)/path_to_mod/mod
Path root = Paths.get("");
// TODO update this code chunk to be more OOP
if (MODPATH.toString().contains("clientmods")) {
if (isMod && MODPATH.toString().contains("clientmods")) {
clientOnlyMod = true;
MODPATH = Paths.get(MODPATH.toString().replaceFirst("clientmods", "mods"));
MODPATH = MODPATH.relativize(root);
Expand Down

0 comments on commit be4bfd5

Please sign in to comment.