using UnityEngine; using System.IO; using YooAsset; namespace GFGGame { public class SqliteController : SingletonBase { /// /// 数据库文件文件夹路径 /// [HideInInspector] public string dirPath; public void Init(bool logable, string resPath) { string dbPath = null; if (string.IsNullOrEmpty(dirPath)) dirPath = $"{Application.persistentDataPath}"; //dbPath = $"{dirPath}/{LauncherConfig.SQL_FILE_NAME}"; dbPath = GetSqlFilePath(resPath); var connectionPath = "data source=" + dbPath; #if !UNITY_EDITOR && UNITY_ANDROID connectionPath = "uri=file:" + dbPath; #endif //Debug.Log($"connectionPath {connectionPath}"); //if(resPath != null) //{ //CheckSqlFile(dbPath, resPath); //} SQLiteHelper.Instance.Init(logable, connectionPath); } private string GetSqlFilePath(string resPath) { RawFileOperationHandle handle = YooAssets.LoadRawFileSync(resPath); return handle.GetRawFilePath(); } /// /// 检查数据库文件是否存在并且是最新版 /// // private void CheckSqlFile(string dbPath, string resPath) // { //#if UNITY_EDITOR // if(GameLauncher.Instance.PlayMode != YooAsset.EPlayMode.OfflinePlayMode) // { //#endif // bool needWrite = true; // var crcKey = "crc" + resPath; // string crc = ""; // VEngine.ManifestBundle version; // if (File.Exists(dbPath)) // { // version = VEngine.Versions.GetBundle(resPath); // crc = PlayerPrefs.GetString(crcKey, ""); // needWrite = crc != version.crc.ToString(); // } // if(needWrite) // { // var asset = GFGAsset.Load(resPath); // byte[] bytes = asset.bytes; // File.WriteAllBytes(dbPath, bytes); // GFGAsset.Release(resPath); // version = VEngine.Versions.GetBundle(resPath); // PlayerPrefs.SetString(crcKey, version.crc.ToString()); // } //#if UNITY_EDITOR // } //#endif // } } }