コード例 #1
0
        public static void _BuildZip_Android()
        {
            string path_pre_name = "VersionFiles/AssetBundles/Android/";

            string path = EditorUtils.Utils.GetCurrentWorkingPath() + "/VersionFiles/AssetBundles/Android/AssetBundles_diff";

            //需要构建的版本号

            string v = File.ReadAllText("VersionFiles/VERSION.txt");


            string out_zip_full_name = "android_" + v + ".zip"; // "VersionFiles/" + v + "/android_" + v + ".zip";

            using (ZipFile zip = ZipFile.Create(out_zip_full_name))
            {
                zip.BeginUpdate();
                zip.AddDirectory("AssetBundles");
                try
                {
                    Directory.Delete("AssetBundles_diff", true);
                }
                catch (Exception e)
                {
                }
                //这样绕一下处理diff是因为 lua/lua这个文件 在 原路径下 打包zip会出错(ziplib的BUG)
                EditorUtils.Utils.CopyDir("VersionFiles/AssetBundles/Android/AssetBundles_diff", "AssetBundles_diff");

                foreach (var d in Directory.GetDirectories("AssetBundles_diff"))
                {
                    zip.AddDirectory(d.Replace("AssetBundles_diff", "AssetBundles"));
                }
                foreach (var p in Directory.GetFiles("AssetBundles_diff", "*", SearchOption.AllDirectories))
                {
                    zip.Add(p, p.Replace("AssetBundles_diff", "AssetBundles"));
                }
                zip.CommitUpdate();
                Directory.Delete("AssetBundles_diff", true);
            }
            if (File.Exists("VersionFiles/" + v + "/android_" + v + ".zip"))
            {
                File.Delete("VersionFiles/" + v + "/android_" + v + ".zip");
            }
            if (Directory.Exists("VersionFiles/" + v) == false)
            {
                Directory.CreateDirectory("VersionFiles/" + v);
            }

            File.Move(out_zip_full_name, "VersionFiles/" + v + "/android_" + v + ".zip");
            File.Delete(out_zip_full_name);

            out_zip_full_name = "VersionFiles/" + v + "/android_" + v + ".zip";

            string md5  = MD5Code.GetMD5HashFromFile(out_zip_full_name);
            int    size = 0;

            using (var zip = File.OpenRead(out_zip_full_name))
            {
                size = (int)zip.Length;
            }
            Patches.Version this_version = new Patches.Version();
            Debug.Log("Patch Zip:will build version = " + v);
            this_version.Parse(v);
            this_version.MD5      = md5;
            this_version.FileSize = size;

            //  Debug.LogError(LitJson.JsonMapper.ToJson(this_version));


            {
                var ss = File.CreateText("VersionFiles/" + v + "/android_" + v + ".json");


                ss.Write(LitJson.JsonMapper.ToJson(this_version));
                ss.Flush();
                ss.Close();
            }

            //resfresh all
            {
                //      Debug.LogError(pat);
                var patches = Directory.GetDirectories("VersionFiles", this_version.MainVersion + ".*.*", SearchOption.AllDirectories);
                List <Patches.Version> _patch_vs = new System.Collections.Generic.List <Patches.Version>();
                foreach (var pp in patches)
                {
                    var             p  = Path.GetFileName(pp);
                    Patches.Version vv = new Patches.Version();
                    vv.Parse(p);
                    _patch_vs.Add(vv);
                }
                _patch_vs.Sort();
                VersionList _VL = new VersionList();

                foreach (var p in _patch_vs)
                {
                    string ver    = p.MainVersion.ToString() + "." + p.SubVersion.ToString() + "." + p.PatchVersion.ToString() + "/android_" + p.MainVersion.ToString() + "." + p.SubVersion.ToString() + "." + p.PatchVersion.ToString() + ".json";
                    var    this_v = File.ReadAllText("VersionFiles/" + ver);
                    Debug.LogError(ver);

                    _VL.versions.Add(LitJson.JsonMapper.ToObject <Patches.Version>(this_v));
                }

                {
                    var ss = File.CreateText("VersionFiles/FULL_VERSIONS.json");

                    ss.Write(LitJson.JsonMapper.ToJson(_VL));
                    ss.Flush();
                    ss.Close();
                }
            }
            Debug.Log("Patch Zip:build android done ");
        }
コード例 #2
0
        public static void _BuildZip()
        {
            //需要构建的版本号

            string v = File.ReadAllText("VersionFiles/VERSION.txt");


            string out_zip_full_name = "android_" + v + ".zip"; // "VersionFiles/" + v + "/android_" + v + ".zip";

            using (ZipFile zip = ZipFile.Create(out_zip_full_name))
            {
                zip.BeginUpdate();

                zip.AddDirectory("AssetBundles");

                foreach (var d in Directory.GetDirectories("AssetBundles"))
                {
                    zip.AddDirectory(d);
                }
                foreach (var p in Directory.GetFiles("AssetBundles", "*", SearchOption.AllDirectories))
                {
                    zip.Add(p);
                    //  Debug.LogError(p);
                }

                zip.CommitUpdate();
            }
            if (File.Exists("VersionFiles/" + v + "/android_" + v + ".zip"))
            {
                File.Delete("VersionFiles/" + v + "/android_" + v + ".zip");
            }
            if (Directory.Exists("VersionFiles/" + v) == false)
            {
                Directory.CreateDirectory("VersionFiles/" + v);
            }

            File.Move(out_zip_full_name, "VersionFiles/" + v + "/android_" + v + ".zip");
            File.Delete(out_zip_full_name);

            out_zip_full_name = "VersionFiles/" + v + "/android_" + v + ".zip";

            string md5  = MD5Code.GetMD5HashFromFile(out_zip_full_name);
            int    size = 0;

            using (var zip = File.OpenRead(out_zip_full_name))
            {
                size = (int)zip.Length;
            }
            Patches.Version this_version = new Patches.Version();
            Debug.LogError(v);
            this_version.Parse(v);
            this_version.MD5      = md5;
            this_version.FileSize = size;
            Debug.LogError(LitJson.JsonMapper.ToJson(this_version));

            {
                var ss = File.CreateText("VersionFiles/" + v + "/android_" + v + ".json");
                ss.Write(LitJson.JsonMapper.ToJson(this_version));
                ss.Flush();
                ss.Close();
            }

            //resfresh all
            {
                string pat = this_version.MainVersion.ToString() + "." + this_version.SubVersion.ToString() + ".";
                //      Debug.LogError(pat);
                var        patches   = Directory.GetDirectories("VersionFiles", this_version.MainVersion + "." + this_version.SubVersion + ".*", SearchOption.AllDirectories);
                List <int> _patch_vs = new System.Collections.Generic.List <int>();
                foreach (var pp in patches)
                {
                    var             p  = Path.GetFileName(pp);
                    Patches.Version vv = new Patches.Version();
                    Debug.LogError(pp + "     " + p);
                    vv.Parse(p);
                    _patch_vs.Add(vv.PatchVersion);
                }
                _patch_vs.Sort();
                VersionList _VL = new VersionList();

                foreach (var p in _patch_vs)
                {
                    string ver = this_version.MainVersion.ToString() + "." + this_version.SubVersion.ToString() + "." + p.ToString() + "/android_" + this_version.MainVersion.ToString() + "." + this_version.SubVersion.ToString() + "." + p.ToString() + ".json";

                    var this_v = File.ReadAllText("VersionFiles/" + ver);
                    Debug.LogError(ver);

                    Patches.Version x = new Patches.Version();

                    _VL.versions.Add(LitJson.JsonMapper.ToObject <Patches.Version>(this_v));
                }

                {
                    var ss = File.CreateText("VersionFiles/FULL_VERSIONS.json");

                    ss.Write(LitJson.JsonMapper.ToJson(_VL));
                    ss.Flush();
                    ss.Close();
                }
            }
        }