Replay importing
This commit is contained in:
@@ -19,15 +19,20 @@
|
||||
package itdelatrisu.opsu.replay;
|
||||
|
||||
import itdelatrisu.opsu.ErrorHandler;
|
||||
import itdelatrisu.opsu.GameMod;
|
||||
import itdelatrisu.opsu.Options;
|
||||
import itdelatrisu.opsu.OsuFile;
|
||||
import itdelatrisu.opsu.ScoreData;
|
||||
import itdelatrisu.opsu.Utils;
|
||||
import itdelatrisu.opsu.io.OsuReader;
|
||||
import itdelatrisu.opsu.io.OsuWriter;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.CharBuffer;
|
||||
import java.nio.charset.CharsetEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -100,6 +105,8 @@ public class Replay {
|
||||
/** Seed. (?) */
|
||||
public int seed;
|
||||
|
||||
private ScoreData scoreData;
|
||||
|
||||
/** Seed string. */
|
||||
private static final String SEED_STRING = "-12345";
|
||||
|
||||
@@ -130,6 +137,41 @@ public class Replay {
|
||||
reader.close();
|
||||
loaded = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a ScoreData object encapsulating all game data.
|
||||
* If score data already exists, the existing object will be returned
|
||||
* (i.e. this will not overwrite existing data).
|
||||
* @param osu the OsuFile
|
||||
* @return the ScoreData object
|
||||
*/
|
||||
public ScoreData getScoreData(OsuFile osu) {
|
||||
if (scoreData != null)
|
||||
return scoreData;
|
||||
|
||||
scoreData = new ScoreData();
|
||||
scoreData.timestamp = file.lastModified() / 1000L;
|
||||
scoreData.MID = osu.beatmapID;
|
||||
scoreData.MSID = osu.beatmapSetID;
|
||||
scoreData.title = osu.title;
|
||||
scoreData.artist = osu.artist;
|
||||
scoreData.creator = osu.creator;
|
||||
scoreData.version = osu.version;
|
||||
scoreData.hit300 = hit300;
|
||||
scoreData.hit100 = hit100;
|
||||
scoreData.hit50 = hit50;
|
||||
scoreData.geki = geki;
|
||||
scoreData.katu = katu;
|
||||
scoreData.miss = miss;
|
||||
scoreData.score = score;
|
||||
scoreData.combo = combo;
|
||||
scoreData.perfect = perfect;
|
||||
scoreData.mods = mods;
|
||||
scoreData.replayString = file!=null ? file.getName() : getReplayFilename();
|
||||
scoreData.playerName = playerName!=null ? playerName : "No Name";
|
||||
return scoreData;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Loads the replay header data.
|
||||
@@ -139,6 +181,7 @@ public class Replay {
|
||||
private void loadHeader(OsuReader reader) throws IOException {
|
||||
this.mode = reader.readByte();
|
||||
this.version = reader.readInt();
|
||||
System.out.println("Header:"+file.getName()+" "+mode+" "+version);
|
||||
this.beatmapHash = reader.readString();
|
||||
this.playerName = reader.readString();
|
||||
this.replayHash = reader.readString();
|
||||
@@ -232,7 +275,7 @@ public class Replay {
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try (FileOutputStream out = new FileOutputStream(file)) {
|
||||
try (OutputStream out = new BufferedOutputStream(new FileOutputStream(file))) {
|
||||
OsuWriter writer = new OsuWriter(out);
|
||||
|
||||
// header
|
||||
|
||||
44
src/itdelatrisu/opsu/replay/ReplayImporter.java
Normal file
44
src/itdelatrisu/opsu/replay/ReplayImporter.java
Normal file
@@ -0,0 +1,44 @@
|
||||
package itdelatrisu.opsu.replay;
|
||||
|
||||
import itdelatrisu.opsu.ErrorHandler;
|
||||
import itdelatrisu.opsu.Options;
|
||||
import itdelatrisu.opsu.OsuFile;
|
||||
import itdelatrisu.opsu.OsuGroupList;
|
||||
import itdelatrisu.opsu.ScoreData;
|
||||
import itdelatrisu.opsu.db.ScoreDB;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class ReplayImporter {
|
||||
public static void importAllReplaysFromDir(File dir) {
|
||||
System.out.println(OsuGroupList.get().beatmapHashesToFile);
|
||||
for (File replayToImport : dir.listFiles()) {
|
||||
try {
|
||||
Replay r = new Replay(replayToImport);
|
||||
r.load();
|
||||
OsuFile oFile = OsuGroupList.get().getFileFromBeatmapHash(r.beatmapHash);
|
||||
if(oFile != null){
|
||||
//ErrorHandler.error("Importing"+replayToImport+" forBeatmap:"+oFile, null, false);
|
||||
ScoreData data = r.getScoreData(oFile);
|
||||
File moveToFile = new File(Options.getReplayDir(),replayToImport.getName());
|
||||
System.out.println("Moving "+replayToImport+" to "+moveToFile);
|
||||
if(
|
||||
!replayToImport.renameTo(moveToFile)
|
||||
){
|
||||
System.out.println("Rename Failed "+moveToFile);
|
||||
}
|
||||
data.replayString = replayToImport.getName().substring(0, replayToImport.getName().length()-4);
|
||||
ScoreDB.addScore(data);;
|
||||
} else {
|
||||
//ErrorHandler.error("Could not find beatmap for replay "+replayToImport, null, false);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
//e.printStackTrace();
|
||||
System.out.println(e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user