private static SongInformation[] GetFromDirectory(string directory) { if (!Directory.Exists(directory)) { return(new SongInformation[0]); } var list = new List <SongInformation>(10); using (var reader = PPDDatabase.DB.ExecuteReader("select * from ScoreTable where parentpath = @parentpath", new SQLiteParameter[] { new SQLiteParameter("@parentpath", directory) })) { while (reader.Reader.Read()) { try { var si = new SongInformation { IsPPDSong = DatabaseUtility.GetInt32(reader.Reader, 26) == 1, ID = DatabaseUtility.GetInt32(reader.Reader, 0), DirectoryPath = reader.Reader.GetString(1) }; if (si.IsPPDSong) { si.ThumbStartTime = DatabaseUtility.GetFloat(reader.Reader, 2); si.ThumbEndTime = DatabaseUtility.GetFloat(reader.Reader, 3); si.StartTime = DatabaseUtility.GetFloat(reader.Reader, 4); si.EndTime = DatabaseUtility.GetFloat(reader.Reader, 5); si.BPM = DatabaseUtility.GetFloat(reader.Reader, 6); si.difficultystring = new string[] { reader.Reader.GetString(7), reader.Reader.GetString(8), reader.Reader.GetString(9), reader.Reader.GetString(10) }; si.Difficulty |= DatabaseUtility.GetInt32(reader.Reader, 11) == 1 ? AvailableDifficulty.Easy : AvailableDifficulty.None; si.Difficulty |= DatabaseUtility.GetInt32(reader.Reader, 12) == 1 ? AvailableDifficulty.Normal : AvailableDifficulty.None; si.Difficulty |= DatabaseUtility.GetInt32(reader.Reader, 13) == 1 ? AvailableDifficulty.Hard : AvailableDifficulty.None; si.Difficulty |= DatabaseUtility.GetInt32(reader.Reader, 14) == 1 ? AvailableDifficulty.Extreme : AvailableDifficulty.None; si.resultIDs = new int[] { DatabaseUtility.GetInt32(reader.Reader, 15), DatabaseUtility.GetInt32(reader.Reader, 16), DatabaseUtility.GetInt32(reader.Reader, 17), DatabaseUtility.GetInt32(reader.Reader, 18) }; si.TrimmingData = new MovieTrimmingData( DatabaseUtility.GetFloat(reader.Reader, 21), DatabaseUtility.GetFloat(reader.Reader, 19), DatabaseUtility.GetFloat(reader.Reader, 20), DatabaseUtility.GetFloat(reader.Reader, 22) ); si.GUID = reader.Reader.GetString(23); si.AuthorName = reader.Reader.GetString(24); si.UpdateDate = reader.Reader.GetString(25); si.MovieVolume = DatabaseUtility.GetInt32(reader.Reader, 27); si.moviepath = reader.Reader.GetString(28); si.ParentDirectory = reader.Reader.GetString(29); si.IsOld = DatabaseUtility.GetInt32(reader.Reader, 30) == 1; si.Latency = DatabaseUtility.GetFloat(reader.Reader, 31); if ((si.Difficulty & AvailableDifficulty.Easy) == AvailableDifficulty.Easy) { si.EasyHash = new byte[32]; reader.Reader.GetBytes(32, 0, si.EasyHash, 0, 32); } if ((si.Difficulty & AvailableDifficulty.Normal) == AvailableDifficulty.Normal) { si.NormalHash = new byte[32]; reader.Reader.GetBytes(33, 0, si.NormalHash, 0, 32); } if ((si.Difficulty & AvailableDifficulty.Hard) == AvailableDifficulty.Hard) { si.HardHash = new byte[32]; reader.Reader.GetBytes(34, 0, si.HardHash, 0, 32); } if ((si.Difficulty & AvailableDifficulty.Extreme) == AvailableDifficulty.Extreme) { si.ExtremeHash = new byte[32]; reader.Reader.GetBytes(35, 0, si.ExtremeHash, 0, 32); } si.EasyNoteType = (NoteType)DatabaseUtility.GetInt32(reader.Reader, 36); si.NormalNoteType = (NoteType)DatabaseUtility.GetInt32(reader.Reader, 37); si.HardNoteType = (NoteType)DatabaseUtility.GetInt32(reader.Reader, 38); si.ExtremeNoteType = (NoteType)DatabaseUtility.GetInt32(reader.Reader, 39); si.BPMString = reader.Reader.GetString(40); si.UserVolume = DatabaseUtility.GetInt32(reader.Reader, 41); } list.Add(si); } catch { } } } foreach (SongInformation si in list) { si.UpdateScore(); } list.Sort(new SongInformationComparer()); return(list.ToArray()); }
internal bool WriteScore(int scoreID, Difficulty difficulty, int[] counts, int maxcombo, int score, ResultEvaluateType resulttype, float finishtime, SongInformation songInfo) { bool highscore = false; int bestscoreid = -1; using (var reader = ExecuteReader("select * from ScoreTable where scoreid = @scoreid;", new SQLiteParameter[] { new SQLiteParameter("@scoreid", scoreID) })) { while (reader.Reader.Read()) { switch (difficulty) { case Difficulty.Easy: bestscoreid = reader.Reader.GetInt32(15); break; case Difficulty.Normal: bestscoreid = reader.Reader.GetInt32(16); break; case Difficulty.Hard: bestscoreid = reader.Reader.GetInt32(17); break; case Difficulty.Extreme: bestscoreid = reader.Reader.GetInt32(18); break; } break; } } if (bestscoreid != -1) { using (var reader = ExecuteReader("select * from ResultTable where resultid = @resultid;", new SQLiteParameter[] { new SQLiteParameter("@resultid", bestscoreid) })) { while (reader.Reader.Read()) { var bestscore = reader.Reader.GetInt32(4); var bestcounts = new int[] { reader.Reader.GetInt32(5), reader.Reader.GetInt32(6), reader.Reader.GetInt32(7), reader.Reader.GetInt32(8), reader.Reader.GetInt32(9) }; var bestmaxcombo = reader.Reader.GetInt32(10); highscore = IsHighScore(score, counts, maxcombo, bestscore, bestcounts, bestmaxcombo); } } } else { highscore = true; } highscore = highscore && resulttype != ResultEvaluateType.Mistake; var resultId = (int)ExecuteDataTable(@"insert into ResultTable( scoreid, difficulty, evaluate, score, coolcount, goodcount, safecount, sadcount, worstcount, maxcombo, finishtime, date ) values( @scoreid, @difficulty, @evaluate, @score, @coolcount, @goodcount, @safecount, @sadcount, @worstcount, @maxcombo, @finishtime, @date );", new SQLiteParameter[] { new SQLiteParameter("@scoreid", scoreID), new SQLiteParameter("@difficulty", (int)difficulty), new SQLiteParameter("@evaluate", (int)resulttype), new SQLiteParameter("@score", score), new SQLiteParameter("@coolcount", counts[0]), new SQLiteParameter("@goodcount", counts[1]), new SQLiteParameter("@safecount", counts[2]), new SQLiteParameter("@sadcount", counts[3]), new SQLiteParameter("@worstcount", counts[4]), new SQLiteParameter("@maxcombo", maxcombo), new SQLiteParameter("@finishtime", finishtime), new SQLiteParameter("@date", DateTime.Now.ToString(CultureInfo.InvariantCulture)) }); if (highscore) { ExecuteDataTable("update ScoreTable set " + GetSQLColumn(difficulty) + " = @resultid where scoreid = @scoreid;", new SQLiteParameter[] { new SQLiteParameter("@scoreid", scoreID), new SQLiteParameter("@resultid", resultId) }); songInfo.resultIDs[(int)difficulty] = resultId; songInfo.UpdateScore(); } return(highscore); }