63 lines
1.6 KiB
Java
63 lines
1.6 KiB
Java
package electrosphere.game.server.saves;
|
|
|
|
import electrosphere.game.server.db.DatabaseUtils;
|
|
import electrosphere.main.Globals;
|
|
import electrosphere.util.FileUtils;
|
|
import java.util.LinkedList;
|
|
import java.util.List;
|
|
|
|
/**
|
|
*
|
|
* @author satellite
|
|
*/
|
|
public class SaveUtils {
|
|
|
|
static String deriveSaveDirectoryPath(String saveName){
|
|
return "./saves/" + saveName;
|
|
}
|
|
|
|
/**
|
|
* Initializes a save directory
|
|
* @param saveName
|
|
* @return true if initialized save, false if couldn't initialize
|
|
*/
|
|
public static boolean initSave(String saveName){
|
|
String dirPath = deriveSaveDirectoryPath(saveName);
|
|
//check if exists
|
|
if(FileUtils.checkDirectoryExists(dirPath)){
|
|
return false;
|
|
}
|
|
//create dir
|
|
if(!FileUtils.createDirectory(dirPath)){
|
|
//we for some unknown reason, couldn't make the save dir
|
|
return false;
|
|
}
|
|
//init db file
|
|
if(!DatabaseUtils.initCentralDBFile(dirPath)){
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
public static boolean overwriteSave(String saveName){
|
|
boolean rVal = false;
|
|
return rVal;
|
|
}
|
|
|
|
|
|
public static boolean loadSave(String saveName){
|
|
String dirPath = deriveSaveDirectoryPath(saveName);
|
|
String dbFilePath = FileUtils.sanitizeFilePath(dirPath) + "/central.db";
|
|
Globals.dbController.connect(dbFilePath);
|
|
Globals.serverTerrainManager.load(saveName);
|
|
return true;
|
|
}
|
|
|
|
public static List<String> getSaves(){
|
|
return FileUtils.listDirectory("./saves");
|
|
}
|
|
|
|
}
|