123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- using UnityEngine;
- using System.IO;
- using YooAsset;
- namespace GFGGame
- {
- public class SqliteController : SingletonBase<SqliteController>
- {
- /// <summary>
- /// 数据库文件文件夹路径
- /// </summary>
- [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();
- }
- /// <summary>
- /// 检查数据库文件是否存在并且是最新版
- /// </summary>
- // 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<TextAsset>(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
- // }
- }
- }
|