Beispiel #1
0
    /// <summary>
    /// 处理Lua文件
    /// </summary>
    static void PackLuaFiles()
    {
        string resPath = AppDataPath + "/StreamingAssets/";
        string luaPath = resPath + "lua/";

        //----------复制Lua文件----------------
        if (Directory.Exists(luaPath))
        {
            Directory.Delete(luaPath, true);
        }
        Directory.CreateDirectory(luaPath);
        string[] luaPaths = { AppDataPath + "/Scripts/lua/",
                              AppDataPath + "/Tolua/Lua/" };

        for (int i = 0; i < luaPaths.Length; i++)
        {
            int    n           = 0;
            string luaDataPath = luaPaths[i].ToLower();
            var    files       = Directory.GetFiles(luaDataPath, "*.*", SearchOption.AllDirectories);
            foreach (string f in files)
            {
                if (f.EndsWith(".meta"))
                {
                    continue;
                }
                string newfile = f.Replace(luaDataPath, "");
                string newpath = luaPath + newfile;
                string path    = Path.GetDirectoryName(newpath);
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                if (File.Exists(newpath))
                {
                    File.Delete(newpath);
                }
                if (AppConst.LuaByteMode)
                {
                    EncodeLuaFile(f, newpath);
                }
                else
                {
                    File.Copy(f, newpath, true);
                }
                UpdateProgress(n++, files.Length, newpath);
            }
        }
        var allfiles   = Directory.GetFiles(luaPath, "*.*", SearchOption.AllDirectories);
        var scriptFile = resPath + "scripts_" + allfiles.Count() + ".zip";

        if (File.Exists(scriptFile))
        {
            File.Delete(scriptFile);
        }
        CZip.ZipFile(scriptFile, luaPath);
        Directory.Delete(luaPath, true);
        EditorUtility.ClearProgressBar();
        AssetDatabase.Refresh();
    }
Beispiel #2
0
    static void PackCompressDir(string dirName, string fileType)
    {
        var srcPath = AppDataPath + "/" + dirName;

        var allowedExtensions = fileType.Replace("*", "").Split('|');
        var files             = Directory.GetFiles(srcPath, "*.*", SearchOption.AllDirectories)
                                .Where(file => allowedExtensions.Any(file.ToLower().EndsWith)).ToList();

        string zipName = dirName.ToLower().Remove(0, 4) + "_" + files.Count() + ".zip";
        string zipPath = AppDataPath + "/StreamingAssets/" + zipName;

        var zipExtNames = fileType.Replace("*.", "");

        CZip.ZipFile(zipPath, srcPath, zipExtNames);
    }
        /// <summary>
        /// 处理压缩文件
        /// </summary>
        /// <param name="zipFiles"></param>
        /// <param name="updateOK"></param>
        void ProcZipFiles(List <string> zipFiles, Action updateOK)
        {
            if (zipFiles.Count == 0)
            {
                if (updateOK != null)
                {
                    updateOK();
                }
            }
            var zip = CZip.Create();

            foreach (var file in zipFiles)
            {
                var zipfile = Util.DataPath + file;
                if (File.Exists(zipfile))
                {
                    var str       = file.Replace(".zip", "");
                    var strs      = str.Split('_');
                    var fileCount = uint.Parse(strs[2]);
                    zip.AddUnzip(zipfile, Util.DataPath, fileCount);
                }
            }
            /// <summary>
            /// 开始解压文件
            /// </summary>
            var loadingText = "正在解压资源,请稍等...(此过程不消耗流量)";

            zip.DoUnzip(delegate(float curr, float max)
            {
                Util.UpdateLoadingProgress(loadingText, curr, max);
                if (curr >= max)
                {
                    foreach (var file in zipFiles)
                    {
                        var zipfile = Util.DataPath + file;
                        if (File.Exists(zipfile))
                        {
                            File.Delete(zipfile);
                        }
                    }
                    if (updateOK != null)
                    {
                        updateOK();
                    }
                }
            });
        }
    /// <summary>
    /// 开始打补丁
    /// </summary>
    /// <param name="needUpdateFiles"></param>
    static void BuildPatchInternal(List <string> needUpdateFiles)
    {
        var fileSize    = 0L;
        var fileCount   = needUpdateFiles.Count;
        var patchVerDir = localVerInfo.mainVersion + "_" + localVerInfo.primaryVersion;

        RetryCreateDir(patchPath + "temps/");
        RetryCreateDir(patchPath + "files/");
        RetryCreateDir(patchPath + "files/" + patchVerDir);

        foreach (var item in needUpdateFiles)
        {
            fileSize += FileSize(item);
            Debug.Log("update file:>" + item);
            var currPath = item.Replace(AppDataPath, "")
                           .Replace("StreamingAssets/", "");
            currPath = patchPath + "temps" + currPath;
            var dir = currPath.Substring(0, currPath.LastIndexOf('/'));
            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir.ToLower());
            }
            if (File.Exists(currPath))
            {
                File.Delete(currPath);
            }
            File.Copy(item, currPath);  //复制文件
        }
        var fileName = "patch_" + localVerInfo.patchVersion + "_" + fileCount + ".zip";

        var zipFile = patchPath + "files/" + patchVerDir + "/" + fileName;

        CZip.ZipFile(zipFile, patchPath + "temps/");
        Directory.Delete(patchPath + "temps/", true);

        string patchInfo = AppConst.PatchUrl + "files/" + patchVerDir + "/" + fileName + "|" + fileSize;

        File.AppendAllLines(patchPath + "patchs_" + patchVerDir + ".txt", new[] { patchInfo });

        Debug.Log("Create Patch Zipfile:>" + zipFile);
        AssetDatabase.Refresh();
    }