using System;
using System.Collections.Generic;
using System.IO;
using UnityEngine.Serialization;

namespace UnityEngine.UI.PackgTool
{
    [System.Serializable]
    public class UGUIPackDB
    {
        public List<PackInfo> allPackgInfos = new List<PackInfo>();
        [NonSerialized] public string uiPath2;
        public bool isJiaoYan;

        [System.NonSerialized] public bool isShowPack;
        [System.NonSerialized] public bool isShowUpdatePack;

        public UGUIPackDB()
        {
            uiPath2 = PlayerPrefs.GetString("uiPath", "");
        }

        public PackInfo GetPackgInfo(string packName)
        {
            packName = packName.Replace("\r", "");
            for (int i = 0; i < allPackgInfos.Count; i++)
            {
                if (allPackgInfos[i].packName.Equals(packName))
                {
                    return allPackgInfos[i];
                }
            }

            return null;
        }

        public void ClearUselessPack()
        {
            for (int i = 0; i < allPackgInfos.Count; i++)
            {
                string path = allPackgInfos[i].packgJsonPath;
                if (path != null)
                {
                    if (!File.Exists(Application.dataPath + path))
                    {
                        allPackgInfos.RemoveAt(i);
                        i--;
                    }
                }
            }
#if UNITY_EDITOR
            UGUICacheInfo.SaveDB();
#endif
        }
    }
}