Exemple #1
0
    // Use this for initialization
    public static void Reg(IUpdatable i)
    {
        if (Singleton == null)
        {
            GameObject go = new GameObject("HotFileDBFRAM_Updater");
            Singleton = go.AddComponent <HotFileDBFRAM_Updater>();

            Singleton.Updatables      = new List <IUpdatable>();
            Singleton.mMCU            = INemoControlIOSinglton.Get();
            Singleton.mMCU.EvtOpened += Singleton.Handle_MCU_Connect;
        }

        Singleton.Updatables.Add(i);
    }
Exemple #2
0
    // Use this for initialization
    public static void Reg(IUpdatable i)
    {
        if (Singleton == null)
        {
            GameObject go = new GameObject("HotFileDBFRAM_Updater");
            Singleton = go.AddComponent<HotFileDBFRAM_Updater>();

            Singleton.Updatables = new List<IUpdatable>();
            Singleton.mMCU = INemoControlIOSinglton.Get();
            Singleton.mMCU.EvtOpened += Singleton.Handle_MCU_Connect;
        }

        Singleton.Updatables.Add(i);
    }
Exemple #3
0
    public HotFileDbFRAMIO(string key, string filePath)
    {
        if (GameMain.Singleton != null)
        {
            mMCU = GameMain.Singleton.ArcIO;
        }
        if (mMCU == null)
        {
            mMCU = INemoControlIOSinglton.Get();
        }
        //?????????????
        if (mConn == null)
        {
            if (DataBaseName == "")
            {
                DataBaseName = "GameDB.db";
            }

            string dataPath = System.Environment.CurrentDirectory + "/DataFiles";
            if (!Directory.Exists(dataPath))
            {
                Directory.CreateDirectory(dataPath);
            }


            mConn = new SqliteConnection("Data Source = DataFiles/" + DataBaseName + ";");
            mConn.Open();

            if (mCMD == null)
            {
                mCMD = mConn.CreateCommand();
                mCMD.Parameters.Add(new SqliteParameter());
            }

            mCMD.CommandText = "PRAGMA journal_mode =wal;";//wal??
            mCMD.ExecuteNonQuery();
        }



        mKey    = key;
        mDBType = GetDBType();
        //bool isInitFRAMByDB = false;
        //?????DB_FARM_ID
        if (mMCU.IsOpen() && DB_ID == System.Guid.Empty)
        {
            using (SqliteCommand cmd = mConn.CreateCommand())
            {
                cmd.CommandText = "CREATE TABLE IF NOT EXISTS _DB_GUID(Val BLOB);";
                //cmd.Parameters.Add("@data", System.Data.DbType.Binary).Value = System.Guid.Empty.ToByteArray();
                cmd.ExecuteNonQuery();
                cmd.CommandText = string.Format(" SELECT * FROM _DB_GUID;");
                SqliteDataReader r = cmd.ExecuteReader();
                r.Read();

                if (r.HasRows)//????????????????
                {
                    //???????????guid?
                    DB_ID = new System.Guid(r.GetValue(0) as byte[]);
                    //???FRAM??guid?
                    byte[] guidFRAMByte = null;
                    if (mMCU.Read_Block(0, 16, out guidFRAMByte))//??FRAM???guid???
                    {
                        System.Guid FRAMEGUID = new System.Guid(guidFRAMByte);
                        if (FRAMEGUID != DB_ID)                                      //FRAM??db??guid?????
                        {
                            mMCU.RequestReadWrite(true, 0, 16, DB_ID.ToByteArray()); //??dbid§Õ??FRAM
                            IsInitFRAMByDB = true;
                        }
                    }
                    r.Close();
                }
                else//?????????guid
                {
                    r.Close();
                    //??????dbGUID
                    DB_ID = System.Guid.NewGuid();
                    byte[] guidByteNew = DB_ID.ToByteArray();
                    //????db
                    cmd.CommandText = "INSERT INTO _DB_GUID VALUES (@data)";
                    cmd.Parameters.Add("@data", System.Data.DbType.Binary).Value = guidByteNew;
                    cmd.ExecuteNonQuery();

                    //?????????guid ????FRAM
                    mMCU.RequestReadWrite(true, 0, 16, guidByteNew);
                    IsInitFRAMByDB = true;
                }
            }
        }


        //??????(4294967295 == 0xffffffff)
        mCMD.CommandText = string.Format("CREATE TABLE IF NOT EXISTS {0:s}(Val {1:s} KEY DEFAULT {2:s},Address INTEGER DEFAULT 4294967295,Length INTEGER DEFAULT {3:d});", mKey, GetDBTypeString(), GetDefaultDBValString(), GetValLength());
        mCMD.ExecuteNonQuery();


        //???????????????
        mCMD.CommandText = string.Format(" SELECT * FROM {0:s};", mKey);
        SqliteDataReader reader = mCMD.ExecuteReader();

        reader.Read();

        //
        //System.Guid.NewGuid();

        if (reader.HasRows)//????????????????
        {
            //????????????????????????
            mAddress    = (uint)reader.GetInt64(1);
            mDataLength = (byte)reader.GetInt32(2);
            if (IsInitFRAMByDB)
            {
                WriteToFRAM(ObjectToVal(reader.GetValue(0)));
            }
            reader.Close();
        }
        else//????????????????,????????
        {
            mAddress    = CurrentUseAddress;
            mDataLength = (byte)GetValLength();
            reader.Close();

            //???????????
            mCMD.CommandText   = string.Format("INSERT INTO {0:s} VALUES({1:s},{2:d},{3:d})", mKey, GetDefaultDBValString(), mAddress, mDataLength);
            CurrentUseAddress += GetValLength();//???????
            mCMD.ExecuteNonQuery();

            //?????farm
            WriteToFRAM(GetDefaultVal());
        }

        mUpdateSQLText = "UPDATE " + mKey + " SET Val = ?;";

        ++SqliteConnRefCount;
        HotFileDBIOReleaser.HotFileDBReg(this);
        HotFileDBFRAM_Updater.Reg(this);
    }