コード例 #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();
    }
コード例 #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);
    }
コード例 #3
0
    /// <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();
    }