Example #1
0
    public static void Init(SimpleSQLManager database, PicturePack pack = null, List <PictureSaveData> saves = null)
    {
        DatabaseManager.db = database;
        bool flag = false;

        if (DatabaseManager.Version == 0)
        {
            int num  = DatabaseManager.CreatePicDb();
            int num2 = DatabaseManager.CreateSaveDb();
            if (num != -1 && num2 != -1)
            {
                DatabaseManager.Version = 1;
                UnityEngine.Debug.Log("initial db creation successful");
            }
            else
            {
                UnityEngine.Debug.Log(string.Concat(new object[]
                {
                    "db error picDb:",
                    num,
                    " saveDb:",
                    num2
                }));
            }
            flag = true;
        }
        if (DatabaseManager.Version == 1)
        {
            DatabaseManager.DbUpdateOne();
            DatabaseManager.Version = 2;
        }
        if (DatabaseManager.Version == 2)
        {
            DatabaseManager.CreateGiftDb(false);
            DatabaseManager.Version = 3;
        }
        if (DatabaseManager.Version == 3)
        {
            DatabaseManager.CreateNewsDb(false);
            DatabaseManager.Version = 4;
        }
        DatabaseValidator.Validate(DatabaseManager.db);
        if (flag && pack != null && pack.Pictures != null)
        {
            DatabaseManager.InitialDbFill(pack, saves);
        }
    }
Example #2
0
 private static void InitialDbFill(PicturePack pack, List <PictureSaveData> saves)
 {
     for (int i = 0; i < pack.Pictures.Count; i++)
     {
         DatabaseManager.AddPicture(pack.Pictures[i]);
     }
     if (saves != null)
     {
         for (int j = 0; j < saves.Count; j++)
         {
             try
             {
                 SaveDb saveDb = DbTypeConvertor.FromPictureSaveData(saves[j]);
                 saveDb.TimeStamp -= (long)(j * 10000000);
                 DatabaseManager.db.Insert(saveDb);
             }
             catch (Exception ex)
             {
                 FMLogger.Log("error while inital save db fill. e:" + ex.Message);
             }
         }
     }
 }
Example #3
0
    public void Init()
    {
        if (this.inited)
        {
            return;
        }
        if (!this.inited)
        {
            this.inited = true;
        }
        string @string = PlayerPrefs.GetString("packsdKey", string.Empty);
        PackCollectionIndex packCollectionIndex;

        if (string.IsNullOrEmpty(@string))
        {
            packCollectionIndex = new PackCollectionIndex();
            PlayerPrefs.SetString("packsdKey", JsonUtility.ToJson(packCollectionIndex));
        }
        else
        {
            packCollectionIndex = JsonUtility.FromJson <PackCollectionIndex>(@string);
        }
        Dictionary <int, PicturePack> dictionary = new Dictionary <int, PicturePack>();

        for (int i = packCollectionIndex.packIds.Count - 1; i >= 0; i--)
        {
            int    num     = packCollectionIndex.packIds[i];
            string string2 = PlayerPrefs.GetString(PackCollectionIndex.IndexToKey(num), string.Empty);
            if (!string.IsNullOrEmpty(string2))
            {
                PicturePack value = JsonUtility.FromJson <PicturePack>(string2);
                dictionary.Add(num, value);
            }
            else
            {
                packCollectionIndex.packIds.RemoveAt(i);
            }
        }
        string   string3 = PlayerPrefs.GetString("feedKey", string.Empty);
        FeedData feedData;

        if (string.IsNullOrEmpty(string3))
        {
            feedData       = new FeedData();
            feedData.saves = new List <PictureSaveData>();
            PlayerPrefs.SetString("feedKey", JsonUtility.ToJson(feedData));
            PlayerPrefs.Save();
        }
        else
        {
            feedData = JsonUtility.FromJson <FeedData>(string3);
        }
        this.CleanSysPack(feedData);
        PicturePack pack = null;

        if (dictionary.ContainsKey(0))
        {
            pack = dictionary[0];
        }
        DatabaseManager.Init(this.simpleSqlManager, pack, (feedData == null) ? null : feedData.saves);
    }