public static SQLite3Operate OpenToReadWrite(string InDbName, bool InIsNeedCheck, string InMd5 = null, Func <string, SQLite3Operate> InCheckFailAction = null)
        {
            string persistentDbPath = Path.Combine(Application.persistentDataPath, InDbName);

            if (File.Exists(persistentDbPath))
            {
                if (InIsNeedCheck && !string.IsNullOrEmpty(InMd5) && null != InCheckFailAction)
                {
                    if (!MD5Utility.GetFileMD5(persistentDbPath).Equals(InMd5))
                    {
                        return(InCheckFailAction.Invoke(InDbName));
                    }
                }

                return(new SQLite3Operate(persistentDbPath, SQLite3OpenFlags.ReadWrite));//
            }
            else if (null != InCheckFailAction)
            {
                return(InCheckFailAction.Invoke(InDbName));
            }
            else
            {
                return(null);
            }
        }
        void TestCompress()
        {
            var time = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;

            var filePath           = Application.dataPath + "/StreamingAssets/android/res/art/ui/texture/runtime/temp";
            var sourceFilePath     = filePath + ".assetbundle";
            var compressFilePath   = filePath + "_compressed.assetbundle";
            var decompressFilePath = filePath + "_decompressed.assetbundle";

            LogManager.Error("MD5 before: " + MD5Utility.GetFileMD5(sourceFilePath));

            // var filePath = Application.dataPath + "/Res/Lua/Main";
            // var sourceFilePath = filePath + ".lua";
            // var compressFilePath = filePath + "_compressed.lua";
            // var decompressFilePath = filePath + "_decompressed.lua";
            FileUtility.CompressFile(sourceFilePath, compressFilePath);

            FileUtility.DeCompressFile(compressFilePath, decompressFilePath);
            // var bytes = File.ReadAllBytes(compressFilePath);
            // FileUtility.DeCompressBuffer(bytes, decompressFilePath);

            LogManager.Error("MD5 after: " + MD5Utility.GetFileMD5(decompressFilePath));

            var elapsedTime = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond - time;

            LogManager.Error(string.Format("ElapsedTime: {0}(ms)", elapsedTime));
        }
Exemple #3
0
        /// <summary>
        /// Open a SQLite3 database that exists in the persistentDataPath directory as read-only.
        /// </summary>
        /// <param name="InDbName">The name of the SQLite3 database.</param>
        /// <returns>Operation SQLite3 database handle.</returns>
        public static SQLite3Operate OpenToRead(string InDbName)
        {
#if UNITY_EDITOR
            string dbPath = Path.Combine(Application.streamingAssetsPath, InDbName);
            if (File.Exists(dbPath))
            {
                return(new SQLite3Operate(dbPath, SQLite3OpenFlags.ReadOnly));
            }
            else
            {
                return(null);
            }
#else
            string dbPath = Path.Combine(Application.persistentDataPath, InDbName);

            //return null;
            bool needUpdate = true;
            if (File.Exists(dbPath))
            {
#if DEBUG_MODE
                needUpdate = false;
#else
                SQLite3Version version = Resources.Load <SQLite3Version>("SQLite3Version");
                if (MD5Utility.GetFileMD5(dbPath).Equals(version.DbMd5))
                {
                    needUpdate = false;
                }
#endif
            }

            if (needUpdate)
            {
#if UNITY_ANDROID
                using (WWW www = new WWW(Path.Combine("jar:file://" + Application.dataPath + "!/assets/", InDbName)))
                {
                    while (!www.isDone)
                    {
                    }

                    if (string.IsNullOrEmpty(www.error))
                    {
                        File.WriteAllBytes(dbPath, www.bytes);
                    }
                    else
                    {
                        Debug.LogError("www error " + www.error);
                    }
                }
#elif UNITY_IOS
                File.Copy(Path.Combine(Application.streamingAssetsPath, InDbName), dbPath, true);
#endif
            }
            return(new SQLite3Operate(dbPath, SQLite3OpenFlags.ReadOnly));
#endif
        }
Exemple #4
0
        private static void UpdateSQLite3Version()
        {
            SQLite3Version version = CreateInstance <SQLite3Version>();

            version.DbName = "Static.db";
            version.DbMd5  = MD5Utility.GetFileMD5(Application.streamingAssetsPath + "/Static.db");

            AssetDatabase.CreateAsset(version, "Assets/ThirdPartyPlugin/SQLite3/Resources/SQLite3Version.asset");
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
        static void BuildVersionFile(BuildTarget targetPlatform, string[] files)
        {
            var versionFile = new ResVersionFile(files.Length);

            for (var i = 0; i < files.Length; ++i)
            {
                var file        = files[i];
                var versionInfo = new ResVersionInfo();
                versionInfo.MD5 = MD5Utility.GetFileMD5(file);

                versionFile.Files[i] = file.ReplaceFirst(_outPath + "/", "");
                versionFile.Infos[i] = versionInfo;
            }
            FileUtility.WriteFile(_outPath + "/" + ResConfig.VERSION_FILE, versionFile.Serialize());
            AssetDatabase.Refresh();
        }
        static ResVersionFile BuildVersionFile(string[] files)
        {
            var versionFile = new ResVersionFile(files.Length);

            for (var i = 0; i < files.Length; ++i)
            {
                var file        = files[i];
                var versionInfo = new ResVersionInfo();
                versionInfo.File = file.ReplaceFirst(_outPath + "/", "");
                versionInfo.MD5  = MD5Utility.GetFileMD5(file);

                versionFile.Files[i] = file.ReplaceFirst(_outPath + "/", "");
                versionFile.Infos[i] = versionInfo;
            }

            var filePath = Application.dataPath + "/" + ResConfig.RES_ROOT + "/" + ResConfig.VERSION_FILE;

            FileUtility.WriteFile(filePath, versionFile.Serialize());
            AssetDatabase.Refresh();

            var buildInfo = new AssetBundleBuild();

            buildInfo.assetBundleName = ResConfig.VERSION_FILE;
            var assetName = "Assets/" + ResConfig.RES_ROOT + "/" + ResConfig.VERSION_FILE;

            buildInfo.assetNames = new string[] { assetName };
            ResBuildUtility.ResetBundleName(ref buildInfo);

            var options = _options & (~BuildAssetBundleOptions.ForceRebuildAssetBundle);

            BuildPipeline.BuildAssetBundles(
                _outPath,
                // new AssetBundleBuild[] { buildInfo },
                options,
                _target
                );

            // Remove temp versionFile
            File.Delete(filePath);

            return(versionFile);
        }
Exemple #7
0
        /// <summary>
        /// If there is no database in the persistentDataPath directory,
        /// Then copy the database from the streamingAssetsPath directory to the persistentDataPath directory and open the database in read-only mode
        /// Else if need to match detection
        ///        then If the incoming Md5 is not empty, it is determined whether the database Md5 of the persistentDataPath directory matches.
        ///                else  the incoming Md5 is empty, determine whether the database in the persistentDataPath directory is the same as the streamingAssetsPath directory.
        ///        Else Open the existing database.
        /// </summary>
        /// <param name="InDbName">The name of the sqlite3 database.</param>
        /// <param name="InNeedMatchDetection">Whether need to match detection.</param>
        /// <param name="InMd5"></param>
        /// <returns>Operation sqlite3 database handle.</returns>
        public static SQLite3Operate OpenToRead(string InDbName, bool InNeedMatchDetection, string InMd5 = null)
        {
            string persistentDbPath = Path.Combine(Application.persistentDataPath, InDbName);

#if !UNITY_EDITOR && UNITY_ANDROID
            string streamDbPath = Path.Combine("jar:file://" + Application.dataPath + "!/assets/", InDbName);
#elif UNITY_IOS
            string streamDbPath = Path.Combine(Application.dataPath + "/Raw/", InDbName);
#else
            string streamDbPath = Path.Combine(Application.streamingAssetsPath, InDbName);
#endif

            bool   isNeedOverride = false;
            byte[] dbBytes        = null;
            if (File.Exists(persistentDbPath))
            {
                if (InNeedMatchDetection)
                {
                    if (string.IsNullOrEmpty(InMd5))
                    {
#if !UNITY_EDITOR && UNITY_ANDROID
                        using (WWW www = new WWW(streamDbPath))
                        {
                            while (!www.isDone)
                            {
                            }

                            if (string.IsNullOrEmpty(www.error))
                            {
                                dbBytes        = www.bytes;
                                isNeedOverride = !SQLite3Utility.GetBytesMD5(dbBytes).Equals(SQLite3Utility.GetFileMD5(persistentDbPath));
                            }
                            else
                            {
                                isNeedOverride = true;
                            }
                        }
#else
                        dbBytes        = File.ReadAllBytes(streamDbPath);
                        isNeedOverride = !MD5Utility.GetBytesMD5(dbBytes).Equals(MD5Utility.GetFileMD5(persistentDbPath));
#endif
                    }
                    else
                    {
                        isNeedOverride = !InMd5.Equals(persistentDbPath);
                    }
                }
            }
            else
            {
                isNeedOverride = true;
            }

            if (isNeedOverride)
            {
                if (null == dbBytes)
                {
#if !UNITY_EDITOR && UNITY_ANDROID
                    using (WWW www = new WWW(streamDbPath))
                    {
                        while (!www.isDone)
                        {
                        }

                        if (string.IsNullOrEmpty(www.error))
                        {
                            dbBytes = www.bytes;
                        }
                        else
                        {
                            Debug.LogError("Copy database from streamingAssetsPath to persistentDataPath error. " + www.error);
                        }
                    }
#else
                    dbBytes = File.ReadAllBytes(streamDbPath);
#endif
                }

                File.WriteAllBytes(persistentDbPath, dbBytes);
            }

            return(new SQLite3Operate(persistentDbPath, SQLite3OpenFlags.ReadOnly));
        }