Esempio n. 1
0
        public void UpdateSongDB(string[] folderNames, bool fullRescan)
        {
            List <ulong> hashes = new List <ulong>();

            xxHash.Hash64 hasher = xxHash.Create64(0);

            using (DbTransaction tx = conn.BeginTransaction())
            {
                foreach (string folder in folderNames)
                {
                    AddSong(folder, hasher, hashes, fullRescan);
                }

                DbCommand     deleteUnusedCommand = conn.CreateCommand();
                StringBuilder sb = new StringBuilder();
                foreach (string folderName in folderNames)
                {
                    sb.Append("\"" + folderName + "\", ");
                }
                sb.Remove(sb.Length - 2, 2);
                deleteUnusedCommand.CommandText =
                    string.Format(
                        "SELECT COUNT(hash) FROM songs WHERE directory NOT IN ({0}); DELETE from difficulties where song in (SELECT hash from songs where directory not in ({0})); delete from songs where directory not in ({0});",
                        sb.ToString());
                deleteUnusedCommand.Parameters.Add(new SQLiteParameter("@array", folderNames));
                object result = deleteUnusedCommand.ExecuteScalar();
                Logger.Log("Removed " + result.ToString() + " deleted/moved songs");
                tx.Commit();
            }
        }
Esempio n. 2
0
        private void AddSong(string folder, xxHash.Hash64 hasher, List <ulong> scannedHashes, bool forceAdd)
        {
            // Hash info.json file to use as a key in the db
            hasher.Write(File.ReadAllText(folder + "/info.json"));
            ulong currentHash = hasher.Compute();

            hasher.Reset(0);

            // Ignore duplicates
            if (scannedHashes.Contains(currentHash))
            {
                Logger.Log("The song in directory " + folder + " has a duplicate hash " + currentHash +
                           " and was ignored");
                return;
            }
            scannedHashes.Add(currentHash);

            directoryParam.Value = folder;
            hashParam.Value      = currentHash;

            if (forceAdd || (Int64)checkCommand.ExecuteScalar() == 0)
            {
                Logger.Log("Song is not in DB or has changed, adding or updating");

                // We need to update the database entry for the current song
                CustomSongInfo songInfo = CustomSongInfo.FromPath(folder);
                beatsaveridParam.Value      = 0; //TODO
                leaderboardidParam.Value    = songInfo.GetIdentifier();
                bpmParam.Value              = songInfo.beatsPerMinute;
                previewStartTimeParam.Value = songInfo.previewStartTime;
                previewDurationParam.Value  = songInfo.previewDuration;
                authorNameParam.Value       = songInfo.authorName ?? "";
                songNameParam.Value         = songInfo.songName ?? "";
                songSubnameParam.Value      = songInfo.songSubName ?? "";
                coverImagePathParam.Value   = songInfo.coverImagePath ?? "";
                environmentNameParam.Value  = songInfo.environmentName ?? "";

                updateCommand.ExecuteNonQuery();

                // And add all the difficulties into the database
                foreach (CustomSongInfo.DifficultyLevel diff in songInfo.difficultyLevels)
                {
                    difficultyNameParam.Value = diff.difficulty;
                    difficultyRankParam.Value = diff.difficultyRank;
                    audioPathParam.Value      = diff.audioPath;
                    fileNameParam.Value       = diff.jsonPath;

                    updateDiffCommand.ExecuteNonQuery();
                }
            }
        }