Follow-up to #99.

- Many code style changes.
- Don't increment combo if missing the last slider circle.
- Added player name in ranking screen.
- Don't show null/default player names.
- Only import replays with .osr extension.
- Display loading status for importing replays.
- Moved MD5InputStreamWrapper to package "opsu.io".

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han
2015-06-29 19:22:38 -05:00
parent 7d08a7d391
commit d860a30aed
29 changed files with 513 additions and 426 deletions

View File

@@ -184,10 +184,10 @@ public class Beatmap implements Comparable<Beatmap> {
/** Slider border color. If null, the skin value is used. */
public Color sliderBorder;
/** md5 hash of this file */
/** MD5 hash of this file. */
public String md5Hash;
/**
* [HitObjects]
*/

View File

@@ -19,9 +19,9 @@
package itdelatrisu.opsu.beatmap;
import itdelatrisu.opsu.ErrorHandler;
import itdelatrisu.opsu.MD5InputStreamWrapper;
import itdelatrisu.opsu.Utils;
import itdelatrisu.opsu.db.BeatmapDB;
import itdelatrisu.opsu.io.MD5InputStreamWrapper;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
@@ -68,6 +68,9 @@ public class BeatmapParser {
/** The current status. */
private static Status status = Status.NONE;
/** If no Provider supports a MessageDigestSpi implementation for the MD5 algorithm. */
private static boolean hasNoMD5Algorithm = false;
// This class should not be instantiated.
private BeatmapParser() {}
@@ -209,15 +212,11 @@ public class BeatmapParser {
Beatmap beatmap = new Beatmap(file);
beatmap.timingPoints = new ArrayList<TimingPoint>();
try (InputStream inFileStream = new BufferedInputStream(new FileInputStream(file));){
MD5InputStreamWrapper md5stream = null;
try {
md5stream = new MD5InputStreamWrapper(inFileStream);
} catch (NoSuchAlgorithmException e1) {
ErrorHandler.error("Failed to get MD5 hash stream.", e1, true);
}
BufferedReader in = new BufferedReader(new InputStreamReader(md5stream!=null?md5stream:inFileStream, "UTF-8"));
try (
InputStream bis = new BufferedInputStream(new FileInputStream(file));
MD5InputStreamWrapper md5stream = (!hasNoMD5Algorithm) ? new MD5InputStreamWrapper(bis) : null;
BufferedReader in = new BufferedReader(new InputStreamReader((md5stream != null) ? md5stream : bis, "UTF-8"));
) {
String line = in.readLine();
String tokens[] = null;
while (line != null) {
@@ -594,6 +593,12 @@ public class BeatmapParser {
beatmap.md5Hash = md5stream.getMD5();
} catch (IOException e) {
ErrorHandler.error(String.format("Failed to read file '%s'.", file.getAbsolutePath()), e, false);
} catch (NoSuchAlgorithmException e) {
ErrorHandler.error("Failed to get MD5 hash stream.", e, true);
// retry without MD5
hasNoMD5Algorithm = true;
return parseFile(file, dir, beatmaps, parseObjects);
}
// no associated audio file?

View File

@@ -58,10 +58,9 @@ public class BeatmapSetList {
/** Set of all beatmap set IDs for the parsed beatmaps. */
private HashSet<Integer> MSIDdb;
/** Map of all hash to Beatmap . */
public HashMap<String, Beatmap> beatmapHashesToFile;
/** Map of all MD5 hashes to beatmaps. */
private HashMap<String, Beatmap> beatmapHashDB;
/** Index of current expanded node (-1 if no node is expanded). */
private int expandedIndex;
@@ -88,7 +87,7 @@ public class BeatmapSetList {
private BeatmapSetList() {
parsedNodes = new ArrayList<BeatmapSetNode>();
MSIDdb = new HashSet<Integer>();
beatmapHashesToFile = new HashMap<String, Beatmap>();
beatmapHashDB = new HashMap<String, Beatmap>();
reset();
}
@@ -123,10 +122,12 @@ public class BeatmapSetList {
int msid = beatmaps.get(0).beatmapSetID;
if (msid > 0)
MSIDdb.add(msid);
for(Beatmap f : beatmaps) {
beatmapHashesToFile.put(f.md5Hash, f);
}
// add MD5 hashes to table
for (Beatmap beatmap : beatmaps) {
if (beatmap.md5Hash != null)
beatmapHashDB.put(beatmap.md5Hash, beatmap);
}
return node;
}
@@ -511,8 +512,13 @@ public class BeatmapSetList {
* @return true if id is in the list
*/
public boolean containsBeatmapSetID(int id) { return MSIDdb.contains(id); }
public Beatmap getFileFromBeatmapHash(String beatmapHash) {
return beatmapHashesToFile.get(beatmapHash);
/**
* Returns the beatmap associated with the given hash.
* @param beatmapHash the MD5 hash
* @return the associated beatmap, or {@code null} if no match was found
*/
public Beatmap getBeatmapFromHash(String beatmapHash) {
return beatmapHashDB.get(beatmapHash);
}
}