Esempio n. 1
0
 private static void Remove(LogicFolderInfomation info, bool updateParent)
 {
     if (info.IsFolder)
     {
         foreach (LogicFolderInfomation childinfo in info.Children)
         {
             Remove(childinfo, false);
         }
         Delete(info);
     }
     else
     {
         Delete(info);
     }
     if (updateParent)
     {
         var list = PPDDatabase.ParseStringToList(info.Parent.ChildIDs);
         if (list.Contains(info.ID))
         {
             list.Remove(info.ID);
         }
         info.parent.ChildIDs = PPDDatabase.ConverListToString(list);
         UpdateChildIDs(info.Parent.ChildIDs, info.Parent.ID);
     }
     RemoveRelation(info);
 }
Esempio n. 2
0
        private static SongInformation FindSongInformationByHash(byte[] hash, AvailableDifficulty difficulty)
        {
            var queue = new Queue <SongInformation>();

            queue.Enqueue(Root);
            while (queue.Count > 0)
            {
                var info = queue.Dequeue();
                if (info.IsPPDSong)
                {
                    if (difficulty.HasFlag(AvailableDifficulty.Easy))
                    {
                        if (info.EasyHash != null && PPDDatabase.SameHash(hash, info.EasyHash))
                        {
                            return(info);
                        }
                    }
                    if (difficulty.HasFlag(AvailableDifficulty.Normal))
                    {
                        if (info.NormalHash != null && PPDDatabase.SameHash(hash, info.NormalHash))
                        {
                            return(info);
                        }
                    }
                    if (difficulty.HasFlag(AvailableDifficulty.Hard))
                    {
                        if (info.HardHash != null && PPDDatabase.SameHash(hash, info.HardHash))
                        {
                            return(info);
                        }
                    }
                    if (difficulty.HasFlag(AvailableDifficulty.Extreme))
                    {
                        if (info.ExtremeHash != null && PPDDatabase.SameHash(hash, info.ExtremeHash))
                        {
                            return(info);
                        }
                    }
                }
                else
                {
                    foreach (SongInformation child in info.Children)
                    {
                        queue.Enqueue(child);
                    }
                }
            }
            return(null);
        }
Esempio n. 3
0
        private static List <LogicFolderInfomation> GetInfos(string ids, LogicFolderInfomation parent)
        {
            if (string.IsNullOrEmpty(ids))
            {
                return(new List <LogicFolderInfomation>());
            }

            var orderList = PPDDatabase.ParseStringToList(ids);

            ids = ids.Replace('|', ',');
            var list = new List <LogicFolderInfomation>();

            /*            using (SQLiteDataReader reader = PPDDatabase.ExecuteReader("select * from LogicFolder where folderid in (@ids);", new SQLiteParameter[] {
             *              new SQLiteParameter("@ids",ids)}))
             *          {*/
            using (var reader = PPDDatabase.DB.ExecuteReader(String.Format("select * from LogicFolder where folderid in ({0}) order by folderid;", ids), new SQLiteParameter[0]))
            {
                while (reader.Reader.Read())
                {
                    var info = new LogicFolderInfomation
                    {
                        ID       = reader.Reader.GetInt32(0),
                        IsFolder = reader.Reader.GetInt32(2) == 1,
                        Name     = reader.Reader.GetString(3)
                    };
                    if (info.IsFolder)
                    {
                        info.ChildIDs = reader.Reader.GetString(4);
                    }
                    else
                    {
                        info.ScoreID = reader.Reader.GetInt32(1);
                    }
                    info.DateTime = DateTime.Parse(reader.Reader.GetString(5), CultureInfo.InvariantCulture);
                    info.parent   = parent;
                    info.Depth    = parent.Depth + 1;
                    list.Add(info);
                }
            }
            list.Sort(new LogicFolderInformationComparer(orderList));

            return(list);
        }
Esempio n. 4
0
        private static LogicFolderInfomation AddScore(LogicFolderInfomation parent, SongInformation si, string linkName)
        {
            if (parent == null || si == null || !parent.IsFolder || !si.IsPPDSong)
            {
                return(null);
            }
            PPDDatabase.DB.ExecuteDataTable("insert into LogicFolder(scoreid,isfolder,name,date) values(@scoreid,@isfolder,@name,@date);", new SQLiteParameter[] {
                new SQLiteParameter("@scoreid", si.ID), new SQLiteParameter("@isfolder", "0"), new SQLiteParameter("@name", linkName), new SQLiteParameter("@date", DateTime.Now.ToString(CultureInfo.InvariantCulture))
            });
            var newscore = new LogicFolderInfomation();

            using (var reader = PPDDatabase.DB.ExecuteReader("select * from LogicFolder where ROWID = last_insert_rowid();", null))
            {
                while (reader.Reader.Read())
                {
                    newscore.ID       = reader.Reader.GetInt32(0);
                    newscore.IsFolder = reader.Reader.GetInt32(2) == 1;
                    newscore.Name     = reader.Reader.GetString(3);
                    newscore.ScoreID  = reader.Reader.GetInt32(1);
                    newscore.DateTime = DateTime.Parse(reader.Reader.GetString(5), CultureInfo.InvariantCulture);
                    newscore.parent   = parent;
                    newscore.Depth    = parent.Depth + 1;
                    parent.ChildrenList.Add(newscore);
                    break;
                }
            }
            if (newscore != null)
            {
                var ids = PPDDatabase.ParseStringToList(parent.ChildIDs);
                ids.Add(newscore.ID);
                parent.ChildIDs = PPDDatabase.ConverListToString(ids);
                UpdateChildIDs(parent.ChildIDs, parent.ID);
            }
            StaticAfterAdd?.Invoke(newscore, EventArgs.Empty);
            return(newscore);
        }
Esempio n. 5
0
        private static LogicFolderInfomation AddFolder(LogicFolderInfomation parent, string name)
        {
            if (parent == null || !parent.IsFolder)
            {
                return(null);
            }
            PPDDatabase.DB.ExecuteDataTable("insert into LogicFolder(isfolder,name,childids,date) values(@isfolder,@name,@childids,@date);", new SQLiteParameter[] {
                new SQLiteParameter("@isfolder", 1), new SQLiteParameter("@name", name), new SQLiteParameter("@childids", string.Empty), new SQLiteParameter("@date", DateTime.Now.ToString(CultureInfo.InvariantCulture))
            });
            var newfolder = new LogicFolderInfomation();

            using (var reader = PPDDatabase.DB.ExecuteReader("select * from LogicFolder where ROWID = last_insert_rowid();", null))
            {
                while (reader.Reader.Read())
                {
                    newfolder.ID       = reader.Reader.GetInt32(0);
                    newfolder.IsFolder = reader.Reader.GetInt32(2) == 1;
                    newfolder.Name     = reader.Reader.GetString(3);
                    newfolder.ChildIDs = reader.Reader.GetString(4);
                    newfolder.DateTime = DateTime.Parse(reader.Reader.GetString(5), CultureInfo.InvariantCulture);
                    newfolder.parent   = parent;
                    newfolder.Depth    = parent.Depth + 1;
                    parent.ChildrenList.Add(newfolder);
                    break;
                }
            }
            if (newfolder != null)
            {
                var ids = PPDDatabase.ParseStringToList(parent.ChildIDs);
                ids.Add(newfolder.ID);
                parent.ChildIDs = PPDDatabase.ConverListToString(ids);
                UpdateChildIDs(parent.ChildIDs, parent.ID);
            }
            StaticAfterAdd?.Invoke(newfolder, EventArgs.Empty);
            return(newfolder);
        }