static public void Write(string SheetName, string TableKey, string TableValue, string DataKey, string DataValue) { IAPConfigData pIapConfigData = new IAPConfigData(); CocoSqliteDBHelper db = new CocoSqliteDBHelper(DBTool.LocalPath); int pTableCount = db.FindTable(SheetName, DBTool.LocalPath); if (pTableCount == 0) { db.CreateTable(SheetName, new string[] { TableKey, TableValue }, new string[] { "text", "text" }); } SqliteDataReader pDataReader = db.SelectWhere( SheetName, new string[] { TableValue }, new string[] { TableKey }, new string[] { "=" }, new string[] { DataKey }); if (pDataReader.Read()) { db.Delete( SheetName, new string[] { TableKey }, new string[] { "'" + DataKey + "'" } ); } pDataReader.Close(); db.InsertInto(SheetName, new string[] { "'" + DataKey + "'", "'" + DataValue + "'" }); db.CloseSqlConnection(); }
private void WriteAllItemsDataToItemConfig() { string pPath = "data source=" + Application.streamingAssetsPath + "/DB/game.db"; CocoSqliteDBHelper db = new CocoSqliteDBHelper(pPath); string pTableName = "item_config"; int pCount = db.FindTable(pTableName, pPath); int pTotalItem = 0; if (pCount != 0) { //首先清除之前所有的数据 db.DeleteContents(pTableName); List <CocoStoreItem> pAllStoreItems = CocoStoreData.Instance.allProductItems; foreach (var storeItem in pAllStoreItems) { string pKey = "'" + storeItem.itemIdString + "'"; ItemConfigData pData = new ItemConfigData(); pData.id = storeItem.itemIdString; pData.name = storeItem.productId.ToString(); pData.iapConfigId = storeItem.itemIdString; string pValue = "'" + JsonMapper.ToJson(pData) + "'"; db.InsertInto(pTableName, new[] { pKey, pValue }); Debug.LogWarning("Write Data For Item Config Success ! : ( " + pKey + "," + pValue + ")"); pTotalItem += 1; } } db.CloseSqlConnection(); //avoid to database is locked Debug.LogWarning("Write Item Config Data Success ! Total (写入成功!总共):" + pTotalItem.ToString()); }
private void WriteAllItemsDataToIapConfig() { string pPath = "data source=" + Application.streamingAssetsPath + "/DB/game.db"; CocoSqliteDBHelper db = new CocoSqliteDBHelper(pPath); string pTableName = "iap_config"; int pCount = db.FindTable(pTableName, pPath); int pTotalItem = 0; if (pCount != 0) { //首先清除之前所有的数据 db.DeleteContents(pTableName); List <CocoStoreItem> pAllStoreItems = CocoStoreData.Instance.allProductItems; foreach (var storeItem in pAllStoreItems) { string pKey = "'" + storeItem.itemIdString + "'"; IAPConfigData pData = new IAPConfigData(); pData.id = storeItem.itemIdString; pData.name = storeItem.productId.ToString(); pData.noAdsIap = storeItem.isNoAdsLap; switch (storeItem.productType) { case ProductType.Consumable: pData.consumable = true; break; case ProductType.Subscription: pData.isSubscription = true; break; } pData.iapData = new List <IAPData> (); if (!string.IsNullOrEmpty(storeItem.iosIapString)) { pData.iapData.Add(new IAPData { store = StoreType.iOS, iapId = storeItem.iosIapString }); } if (!string.IsNullOrEmpty(storeItem.gpIapString)) { pData.iapData.Add(new IAPData { store = StoreType.Google, iapId = storeItem.gpIapString }); } if (!string.IsNullOrEmpty(storeItem.amIapString)) { pData.iapData.Add(new IAPData { store = StoreType.Amazon, iapId = storeItem.amIapString }); } string pValue = "'" + JsonMapper.ToJson(pData) + "'"; db.InsertInto(pTableName, new[] { pKey, pValue }); Debug.LogWarning("Write Data For IAP Config Success ! : ( " + pKey + "," + pValue + ")"); pTotalItem += 1; } } db.CloseSqlConnection(); //avoid to database is locked Debug.LogWarning("Write IAP Config Data Success ! Total (写入成功!总共):" + pTotalItem.ToString()); }
private void ReadXml(string pAth) { if (string.IsNullOrEmpty(pAth)) { m_Result = "文件路径不能为空"; Debug.LogError(m_Result); return; } List <LeaderboardConfigData> allLeaderboards = new List <LeaderboardConfigData>(); List <AchievementsConfigData> allAchievements = new List <AchievementsConfigData>(); string leaderboardTableName = new LeaderboardConfigData().GetTableName(); string achievementTableName = new AchievementsConfigData().GetTableName(); const string leaderboard_perfix = "leaderboard"; const string achievement_perfix = "achievement"; List <string> nodeNames = new List <string>(); //读取数据 m_Xml = new XmlDocument(); XmlReaderSettings set = new XmlReaderSettings { IgnoreComments = true }; //这个设置是忽略xml注释文档的影响。有时候注释会影响到xml的读取 try { m_Xml.Load(XmlReader.Create(pAth, set)); } catch (IOException e) { m_Result = "IOException : \n" + e.Message; Debug.LogError(e.Message); return; } catch (XmlException e) { m_Result = "XmlException : \n" + e.Message; Debug.LogError(e.Message); return; } //解析数据 XmlNodeList nodes = m_Xml.SelectSingleNode("resources").ChildNodes; foreach (XmlElement node in nodes) { string nodeName = node.GetAttribute("name"); string prefix = nodeName.Split('_')[0]; if (prefix.Equals(leaderboard_perfix)) { nodeNames.Add(nodeName); LeaderboardConfigData item_lb = new LeaderboardConfigData(); item_lb.id = item_lb.leaderboardId = node.InnerText; item_lb.name = nodeName; item_lb.store = EditorHelpers.storeNames[0]; allLeaderboards.Add(item_lb); } else if (prefix.Equals(achievement_perfix)) { nodeNames.Add(nodeName); AchievementsConfigData item_ac = new AchievementsConfigData(); item_ac.id = item_ac.achievementId = node.InnerText; item_ac.name = nodeName; item_ac.store = EditorHelpers.storeNames[0]; item_ac.progress = 0; allAchievements.Add(item_ac); } } //存储数据 if (allLeaderboards.Count > 0 || allAchievements.Count > 0) { string path = "data source=" + Application.streamingAssetsPath + "/DB/game.db"; CocoSqliteDBHelper db = new CocoSqliteDBHelper(path); if (allLeaderboards.Count > 0) { db.DeleteContents(leaderboardTableName); foreach (LeaderboardConfigData itemlb in allLeaderboards) { db.InsertInto(leaderboardTableName, new[] { "'" + itemlb.GetId() + "'", "'" + JsonMapper.ToJson(itemlb) + "'" }); } } if (allAchievements.Count > 0) { db.DeleteContents(achievementTableName); foreach (AchievementsConfigData itemac in allAchievements) { db.InsertInto(achievementTableName, new[] { "'" + itemac.GetId() + "'", "'" + JsonMapper.ToJson(itemac) + "'" }); } } m_Result = string.Format("Complete ! \nleaderboard : {0}\nachievement : {1}", allLeaderboards.Count, allAchievements.Count); Debug.LogError(m_Result.Replace("\n", "")); db.CloseSqlConnection(); CreateProgam(nodeNames); // SetGPGSAndroid (xml.OuterXml); } else { m_Result = "未能读取到有效的数据"; Debug.LogError(m_Result); } }