Ejemplo n.º 1
0
    /// <summary>
    /// Creates the version asset bundle.
    /// </summary>
    /// <param name="fileCrc">File crc.</param>
    public static void CreateVersionAssetBundle(uint fileCrc)
    {
        string path    = CUtils.GetRealStreamingAssetsPath();//Path.Combine (Application.streamingAssetsPath, CUtils.GetAssetPath(""));
        string outPath = Path.Combine(path, CUtils.GetRightFileName(Common.CRC32_VER_FILENAME));

        Debug.Log("verion to path=" + outPath);
        EditorUtility.DisplayProgressBar("Create Version AssetBundle File", "write file to " + outPath, 0.99f);
        //json 化version{ code,crc32,version}
        StringBuilder verJson = new StringBuilder();

        verJson.Append("{");
        verJson.Append(@"""code"":" + CodeVersion.CODE_VERSION + ",");
        verJson.Append(@"""crc32"":" + fileCrc.ToString() + ",");
        verJson.Append(@"""time"":" + CUtils.ConvertDateTimeInt(System.DateTime.Now) + "");
        verJson.Append("}");

        using (StreamWriter sr = new StreamWriter(outPath, false))
        {
            sr.Write(verJson.ToString());
        }

        Debug.Log("Build Version Complete = " + fileCrc.ToString() + " path " + outPath);
        BuildScript.BuildAssetBundles();
        EditorUtility.ClearProgressBar();
    }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates the develop version asset bundle.
        /// </summary>
        /// <param name="fileCrc">File crc.</param>
        public static void CreateDevelopVersionAssetBundle(uint fileCrc)
        {
            CodeVersion.CODE_VERSION = 0;
            CodeVersion.APP_NUMBER   = 0;
            CodeVersion.RES_VERSION  = 0;
            //读取develop 扩展文件
            string ver_file_name = VerExtends;

            ver_file_name = Path.Combine(VerExtendsPath, CUtils.InsertAssetBundleName(ver_file_name, "_" + CUtils.platform + "_dev").Replace("//", "/"));

            StringBuilder verExtSB = ReadVerExtensionFile(ver_file_name);

            //生成内容
            //json 化version{ code,crc32,version}
            StringBuilder verJson = new StringBuilder();

            verJson.Append("{");
            verJson.Append(@"""code"":" + CodeVersion.CODE_VERSION + ",");
            verJson.Append(@"""crc32"":" + fileCrc.ToString() + ",");
            verJson.Append(@"""time"":" + CUtils.ConvertDateTimeInt(System.DateTime.Now) + ",");
            verJson.Append(@"""version"":""" + CodeVersion.APP_VERSION + @"""");
            verJson.Append(verExtSB.ToString());
            verJson.Append("}");

            //输出文件
            Debug.LogFormat("read develop extends:{0},content={1}", ver_file_name, verExtSB.ToString());
            string path = UpdateOutVersionDevelopPath;
            //check folder
            DirectoryInfo dicInfo = new DirectoryInfo(path);

            if (!dicInfo.Exists)
            {
                dicInfo.Create();
            }
            //ver.txt
            string outfilePath = Path.Combine(UpdateOutDevelopPath, "ver.txt"); //输出ver.txt

            if (File.Exists(outfilePath))
            {
                File.Delete(outfilePath);
            }
            using (StreamWriter sr = new StreamWriter(outfilePath, false))
            {
                sr.Write(verJson.ToString());
            }

            string outPath = Path.Combine(path, CUtils.GetRightFileName(Common.CRC32_VER_FILENAME));

            Debug.Log("ver.txt to path=" + outPath);
            EditorUtility.DisplayProgressBar("Create Version AssetBundle File", "write file to " + outPath, 0.99f);
            // platform
            using (StreamWriter sr = new StreamWriter(outPath, false))
            {
                sr.Write(verJson.ToString());
            }
            Debug.Log(verJson.ToString());
            Debug.Log("Build Develop Version Complete = " + fileCrc.ToString() + " path " + outPath);
            EditorUtility.ClearProgressBar();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates the version asset bundle.
        /// </summary>
        /// <param name="fileCrc">File crc.</param>
        public static void CreateVersionAssetBundle(uint fileCrc)
        {
            //read ver extends
            string ver_file_name = VerExtends;

            ver_file_name = VerExtendsPath + CUtils.InsertAssetBundleName(ver_file_name, "_" + CUtils.platform).Replace("//", "/");

            StringBuilder verExtSB = new StringBuilder();

            if (File.Exists(ver_file_name))
            {
                using (StreamReader sr = new StreamReader(ver_file_name))
                {
                    string item;
                    while ((item = sr.ReadLine()) != null)
                    {
                        verExtSB.AppendFormat(",{0}", item);
                    }
                }

                Debug.LogFormat("read extends:{0},coutent={1}", ver_file_name, verExtSB.ToString());
            }

            string path    = CUtils.GetRealStreamingAssetsPath();//Path.Combine (Application.streamingAssetsPath, CUtils.GetAssetPath(""));
            string outPath = Path.Combine(path, CUtils.GetRightFileName(Common.CRC32_VER_FILENAME));

            Debug.Log("verion to path=" + outPath);
            EditorUtility.DisplayProgressBar("Create Version AssetBundle File", "write file to " + outPath, 0.99f);
            //json 化version{ code,crc32,version}
            CodeVersion.CODE_VERSION = 0;
            CodeVersion.APP_NUMBER   = 0;
            CodeVersion.RES_VERSION  = 0;
            StringBuilder verJson = new StringBuilder();

            verJson.Append("{");
            verJson.Append(@"""code"":" + CodeVersion.CODE_VERSION + ",");
            verJson.Append(@"""crc32"":" + fileCrc.ToString() + ",");
            verJson.Append(@"""time"":" + CUtils.ConvertDateTimeInt(System.DateTime.Now) + ",");
            verJson.Append(@"""version"":""" + CodeVersion.APP_VERSION + @"""");
            verJson.Append(verExtSB.ToString());
            verJson.Append("}");
            // platform
            using (StreamWriter sr = new StreamWriter(outPath, false))
            {
                sr.Write(verJson.ToString());
            }

            Debug.Log("Build Version Complete = " + fileCrc.ToString() + " path " + outPath);
            BuildScript.BuildAssetBundles();
            EditorUtility.ClearProgressBar();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates the version asset bundle.
        /// </summary>
        /// <param name="fileCrc">File crc.</param>
        public static void CreateVersionAssetBundle(uint fileCrc, bool toRelease, bool is_dev_Context = false)
        {
            CodeVersion.CODE_VERSION = 0;
            CodeVersion.APP_NUMBER   = 0;
            //read ver extends
            string ver_file_name = VerExtends;
            string path          = string.Empty;
            string verCopyToPath = string.Empty;

            if (is_dev_Context)
            {
                ver_file_name = Path.Combine(VerExtendsPath, CUtils.InsertAssetBundleName(ver_file_name, "_" + CUtils.platform + "_dev").Replace("//", "/"));
            }
            else
            {
                ver_file_name = Path.Combine(VerExtendsPath, CUtils.InsertAssetBundleName(ver_file_name, "_" + CUtils.platform).Replace("//", "/"));
            }

            if (toRelease)
            {
                path = CUtils.GetRealStreamingAssetsPath();
            }
            else
            {
                path = UpdateOutVersionDevelopPath;
            }

            //check path
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            StringBuilder verExtSB = ReadVerExtensionFile(ver_file_name);

            Debug.LogFormat("read extends:{0},content={1}", ver_file_name, verExtSB.ToString());

            string outPath = Path.Combine(path, CUtils.GetRightFileName(Common.CRC32_VER_FILENAME));

            Debug.Log("verion to path=" + outPath);
            EditorUtility.DisplayProgressBar("Create Version AssetBundle File", "write file to " + outPath, 0.99f);
            //json 化version{ code,crc32,version}
            StringBuilder verJson = new StringBuilder();

            verJson.Append("{");
            verJson.Append(@"""code"":" + CodeVersion.CODE_VERSION + ",");
            verJson.Append(@"""crc32"":" + fileCrc.ToString() + ",");
            verJson.Append(@"""time"":" + CUtils.ConvertDateTimeInt(System.DateTime.Now) + ",");
            verJson.Append(@"""version"":""" + CodeVersion.APP_VERSION + @"""");
            verJson.Append(verExtSB.ToString());
            verJson.Append("}");

            if (toRelease)
            {
                verCopyToPath = UpdateOutPath; //输出ver.txt
                // build ver.u to release
                if (!Directory.Exists(UpdateOutVersionPath))
                {
                    Directory.CreateDirectory(UpdateOutVersionPath);
                }
                string outVerU = Path.Combine(UpdateOutVersionPath, CUtils.GetRightFileName(Common.CRC32_VER_FILENAME));
                using (StreamWriter sr = new StreamWriter(outVerU, false))
                {
                    sr.Write(verJson.ToString());
                }
            }
            else
            {
                verCopyToPath = UpdateOutDevelopPath; //输出ver.txt
            }

            //copy ver.txt
            if (!Directory.Exists(verCopyToPath))
            {
                Directory.CreateDirectory(verCopyToPath);
            }
            using (StreamWriter sr = new StreamWriter(Path.Combine(verCopyToPath, "ver.txt"), false))
            {
                sr.Write(verJson.ToString());
            }

            //build ver.u
            using (StreamWriter sr = new StreamWriter(outPath, false))
            {
                sr.Write(verJson.ToString());
            }
            Debug.Log(verJson.ToString());
            Debug.Log("Build Version Complete = " + fileCrc.ToString() + " path " + outPath);
            // BuildScript.BuildAssetBundles();
            EditorUtility.ClearProgressBar();
        }
Ejemplo n.º 5
0
    public static void GenerateAssetBundlesUpdateFile(string[] allBundles)
    {
        string title = "Generate Update File ";
        string info  = "Compute crc32";

        EditorUtility.DisplayProgressBar(title, info, 0.1f);

        #region 读取首包
        CrcCheck.Clear();
        bool          firstExists = false;
        DirectoryInfo firstDir    = new DirectoryInfo(Application.dataPath);
        string        firstPath   = Path.Combine(firstDir.Parent.Parent.FullName, Common.FirstOutPath);
        string        readPath    = Path.Combine(firstPath, CUtils.GetAssetPath(""));
        readPath = Path.Combine(readPath, CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME));
        Debug.Log(readPath);

        WWW abload = new WWW("file://" + readPath);
        if (string.IsNullOrEmpty(abload.error) && abload.assetBundle != null)
        {
            var       ab = abload.assetBundle;
            TextAsset ta = ab.LoadAllAssets <TextAsset>()[0];
            //ta.text
            Debug.Log(ta);
            string   context = ta.text;
            string[] split   = context.Split('\n');
            System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"\[""(.+)""\]\s+=\s+(\d+)");
            float j = 1;
            float l = split.Length;
            foreach (var line in split)
            {
                System.Text.RegularExpressions.Match match = regex.Match(line);
                if (match.Success)
                {
                    //Debug.Log(match.Groups[1].Value + " " + match.Groups[2].Value);
                    CrcCheck.Add(match.Groups[1].Value, System.Convert.ToUInt32(match.Groups[2].Value));
                }
                //Debug.Log(line);
                EditorUtility.DisplayProgressBar(title, "read first crc => " + j.ToString() + "/" + l.ToString(), j / l);
                j++;
            }
            ab.Unload(true);
            firstExists = true;
        }
        else
        {
            Debug.LogWarning(abload.error + "no frist packeage in " + readPath);
        }
        abload.Dispose();
        #endregion

        #region 生成校验列表
        Dictionary <string, uint> updateList = new Dictionary <string, uint>();
        StringBuilder             sb         = new StringBuilder();
        sb.AppendLine("return {");

        var   selected = string.Empty;
        float i        = 0;
        float allLen   = allBundles.Length;

        //忽略列表
        Dictionary <string, bool> ignore = new Dictionary <string, bool>();
        ignore.Add(CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME), true);
        ignore.Add(CUtils.GetRightFileName(Common.CRC32_VER_FILENAME), true);

        foreach (var str in allBundles)
        {
            string url    = Path.Combine(CUtils.GetRealStreamingAssetsPath(), str);
            uint   outCrc = 0;
            Debug.Log(str);
            string abName = str.Replace("\\", "/");
            string key    = CUtils.GetAssetBundleName(abName);
            if (!ignore.ContainsKey(key) && CrcCheck.CheckLocalFileWeakCrc(url, out outCrc) == false) //如果不一致需要更新
            {
                updateList.Add(abName, outCrc);                                                       //记录导出记录
                sb.AppendLine("[\"" + key + "\"] = " + outCrc + ",");
            }
            EditorUtility.DisplayProgressBar(title, info + "=>" + i.ToString() + "/" + allLen.ToString(), i / allLen);
            i++;
        }
        sb.AppendLine("}");
        //Debug.Log (sb.ToString ());
        CrcCheck.Clear();

        //输出到临时目录
        var    crc32filename = CUtils.GetAssetName(Common.CRC32_FILELIST_NAME);
        string tmpPath       = Path.Combine(Application.dataPath, TmpPath);
        ExportResources.CheckDirectory(tmpPath);
        string assetPath = "Assets/" + TmpPath + crc32filename + ".txt";
        EditorUtility.DisplayProgressBar("Generate file list", "write file to " + assetPath, 0.99f);

        string outPath = Path.Combine(tmpPath, crc32filename + ".txt");
        Debug.Log("write to path=" + outPath);
        using (StreamWriter sr = new StreamWriter(outPath, false))
        {
            sr.Write(sb.ToString());
        }
        //
        //打包到streaming path
        AssetDatabase.Refresh();
        string crc32outfilename = CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME); //(fileCrc32ListName + ".u3d");
        BuildScript.BuildABs(new string[] { assetPath }, null, crc32outfilename, BuildAssetBundleOptions.DeterministicAssetBundle);
        string topath = Path.Combine(GetOutPutPath(), crc32outfilename);
        Debug.Log(info + " assetbunle build complate! " + topath);

        #endregion

        #region 生成版本号
        //生成版本号码
        string crc32Path = "file://" + Path.Combine(CUtils.GetRealStreamingAssetsPath(), CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME)); //CUtils.GetAssetFullPath (fileCrc32ListName+".u3d");
        WWW    loaderVer = new WWW(crc32Path);
        if (!string.IsNullOrEmpty(loaderVer.error))
        {
            Debug.LogError(loaderVer.error);
            return;
        }
        uint crcVer = Crc32.Compute(loaderVer.bytes);
        loaderVer.Dispose();

        tmpPath = CUtils.GetRealStreamingAssetsPath();//Path.Combine (Application.streamingAssetsPath, CUtils.GetAssetPath(""));
        outPath = Path.Combine(tmpPath, CUtils.GetRightFileName(Common.CRC32_VER_FILENAME));
        Debug.Log("verion to path=" + outPath);
        //json 化version{ code,crc32,version}
        StringBuilder verJson = new StringBuilder();
        verJson.Append("{");
        verJson.Append(@"""code"":" + CodeVersion.CODE_VERSION + ",");
        verJson.Append(@"""crc32"":" + crcVer.ToString() + ",");
        verJson.Append(@"""time"":" + CUtils.ConvertDateTimeInt(System.DateTime.Now) + "");
        verJson.Append("}");

        using (StreamWriter sr = new StreamWriter(outPath, false))
        {
            sr.Write(verJson.ToString());
        }

        Debug.Log(info + " Complete! ver=" + crcVer.ToString() + " path " + outPath);
        BuildScript.BuildAssetBundles();

        #endregion

        #region copy更新文件导出
        if (updateList.Count > 0)
        {
            info = "copy updated file ";
            string        updateOutPath = Path.Combine(firstPath, CUtils.GetAssetPath("") + System.DateTime.Now.ToString("_yyyy-MM-dd_HH-mm"));
            DirectoryInfo outDic        = new DirectoryInfo(updateOutPath);
            if (outDic.Exists)
            {
                outDic.Delete();
            }
            outDic.Create();

            if (!firstExists)
            {
                updateList.Clear();               //如果没有首包,只导出校验文件。
            }
            updateList.Add(CUtils.GetRightFileName(Common.CRC32_VER_FILENAME), 0);
            updateList.Add(CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME), crcVer);

            string sourcePath;
            string outfilePath;
            i      = 1;
            allLen = updateList.Count;
            string key = "";
            foreach (var k in updateList)
            {
                key        = CUtils.GetAssetBundleName(k.Key);
                sourcePath = Path.Combine(CUtils.GetRealStreamingAssetsPath(), k.Key);
                if (k.Value != 0)
                {
                    if (key.Equals(CUtils.platformFloder))
                    {
                        key = key + "_" + k.Value.ToString() + "." + Common.ASSETBUNDLE_SUFFIX;
                    }
                    else
                    {
                        key = CUtils.InsertAssetBundleName(key, "_" + k.Value.ToString());//
                    }
                }
                outfilePath = Path.Combine(updateOutPath, key);
                FileHelper.CheckCreateFilePathDirectory(outfilePath);
                File.Copy(sourcePath, outfilePath, true);// source code copy
                EditorUtility.DisplayProgressBar(title, info + "=>" + i.ToString() + "/" + allLen.ToString(), i / allLen);
                i++;
            }
            Debug.Log(" copy  file complete!");
        }
        #endregion

        EditorUtility.ClearProgressBar();
    }