Catch all exceptions in OsuDB. (fixes #41)

Also added checks for missing audioFilename fields.

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2015-03-08 20:26:37 -04:00
parent 400f9395e7
commit 40476d4f31
2 changed files with 112 additions and 80 deletions

View File

@ -575,6 +575,10 @@ public class OsuParser {
ErrorHandler.error(String.format("Failed to read file '%s'.", file.getAbsolutePath()), e, false); ErrorHandler.error(String.format("Failed to read file '%s'.", file.getAbsolutePath()), e, false);
} }
// no associated audio file?
if (osu.audioFilename == null)
return null;
// if no custom colors, use the default color scheme // if no custom colors, use the default color scheme
if (osu.combo == null) if (osu.combo == null)
osu.combo = Utils.DEFAULT_COMBO; osu.combo = Utils.DEFAULT_COMBO;

View File

@ -33,6 +33,8 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.newdawn.slick.util.Log;
/** /**
* Handles connections and queries with the cached beatmap database. * Handles connections and queries with the cached beatmap database.
*/ */
@ -247,7 +249,11 @@ public class OsuDB {
// batch insert // batch insert
for (OsuFile osu : batch) { for (OsuFile osu : batch) {
try {
setStatementFields(insertStmt, osu); setStatementFields(insertStmt, osu);
} catch (SQLException e) {
Log.error(String.format("Failed to insert map '%s' into database.", osu.getFile().getPath()), e);
}
insertStmt.addBatch(); insertStmt.addBatch();
} }
int[] results = insertStmt.executeBatch(); int[] results = insertStmt.executeBatch();
@ -281,6 +287,7 @@ public class OsuDB {
*/ */
private static void setStatementFields(PreparedStatement stmt, OsuFile osu) private static void setStatementFields(PreparedStatement stmt, OsuFile osu)
throws SQLException { throws SQLException {
try {
stmt.setString(1, osu.getFile().getParentFile().getName()); stmt.setString(1, osu.getFile().getParentFile().getName());
stmt.setString(2, osu.getFile().getName()); stmt.setString(2, osu.getFile().getName());
stmt.setLong(3, osu.getFile().lastModified()); stmt.setLong(3, osu.getFile().lastModified());
@ -320,6 +327,11 @@ public class OsuDB {
stmt.setString(37, osu.timingPointsToString()); stmt.setString(37, osu.timingPointsToString());
stmt.setString(38, osu.breaksToString()); stmt.setString(38, osu.breaksToString());
stmt.setString(39, osu.comboToString()); stmt.setString(39, osu.comboToString());
} catch (SQLException e) {
throw e;
} catch (Exception e) {
throw new SQLException(e);
}
} }
/** /**
@ -392,10 +404,14 @@ public class OsuDB {
String name = rs.getString(2); String name = rs.getString(2);
OsuFile osu = m.get(name); OsuFile osu = m.get(name);
if (osu != null) { if (osu != null) {
try {
if ((flag & LOAD_NONARRAY) > 0) if ((flag & LOAD_NONARRAY) > 0)
setOsuFileFields(rs, osu); setOsuFileFields(rs, osu);
if ((flag & LOAD_ARRAY) > 0) if ((flag & LOAD_ARRAY) > 0)
setOsuFileArrayFields(rs, osu); setOsuFileArrayFields(rs, osu);
} catch (SQLException e) {
Log.error(String.format("Failed to load map '%s/%s' from database.", parent, name), e);
}
if (++count >= size) if (++count >= size)
break; break;
} }
@ -414,6 +430,7 @@ public class OsuDB {
* @throws SQLException * @throws SQLException
*/ */
private static void setOsuFileFields(ResultSet rs, OsuFile osu) throws SQLException { private static void setOsuFileFields(ResultSet rs, OsuFile osu) throws SQLException {
try {
osu.beatmapID = rs.getInt(4); osu.beatmapID = rs.getInt(4);
osu.beatmapSetID = rs.getInt(5); osu.beatmapSetID = rs.getInt(5);
osu.title = OsuParser.getDBString(rs.getString(6)); osu.title = OsuParser.getDBString(rs.getString(6));
@ -447,6 +464,11 @@ public class OsuDB {
osu.widescreenStoryboard = rs.getBoolean(34); osu.widescreenStoryboard = rs.getBoolean(34);
osu.epilepsyWarning = rs.getBoolean(35); osu.epilepsyWarning = rs.getBoolean(35);
osu.bg = OsuParser.getDBString(rs.getString(36)); osu.bg = OsuParser.getDBString(rs.getString(36));
} catch (SQLException e) {
throw e;
} catch (Exception e) {
throw new SQLException(e);
}
} }
/** /**
@ -456,9 +478,15 @@ public class OsuDB {
* @throws SQLException * @throws SQLException
*/ */
private static void setOsuFileArrayFields(ResultSet rs, OsuFile osu) throws SQLException { private static void setOsuFileArrayFields(ResultSet rs, OsuFile osu) throws SQLException {
try {
osu.timingPointsFromString(rs.getString(37)); osu.timingPointsFromString(rs.getString(37));
osu.breaksFromString(rs.getString(38)); osu.breaksFromString(rs.getString(38));
osu.comboFromString(rs.getString(39)); osu.comboFromString(rs.getString(39));
} catch (SQLException e) {
throw e;
} catch (Exception e) {
throw new SQLException(e);
}
} }
/** /**