static void CompressFiles() { var files = new List <string>(); files.Add(Application.dataPath + @"/Tools/ZIPTool/ziptest/zip.txt"); ZIPTool.CompressFiles(files, "", Application.dataPath + @"/Tools/ZIPTool/ziptest", 0); }
static void GenerateResZipImp(string rootDir) { string dirRemove = rootDir + "Assets/StreamingAssets"; string publishDir = rootDir + "Publish/" + MyUnityEditorTool.GetPlatformFolderForAssetBundles(EditorUserBuildSettings.activeBuildTarget) + "/"; // if (PackageWizard.m_wizard) // { // publishDir += PackageWizard.m_wizard.version; // } MyFileUtil.DeleteDir(publishDir); MyFileUtil.CreateDir(publishDir); List <ResInfo> listResInfo = new List <ResInfo>(); //----------------------------------------------------// List <ZipResConfig> listZipConfig = ZipResConfig.GetConfigList(); foreach (ZipResConfig zipConfig in listZipConfig) { //生成Zip资源包 List <string> fileList = new List <string>(); if (string.IsNullOrEmpty(zipConfig.resDir) == false) { string fileDir = rootDir + zipConfig.resDir; if (fileDir.Contains("@Platform")) { fileDir = fileDir.Replace("@Platform", ResourcesManager.GetPlatformDir()); } if (fileDir.Contains("@Version")) { // fileDir = fileDir.Replace("@Version", SDKConfig.GetCurrentVersionResPath().ToLower()); fileDir = fileDir.Replace("@Version", "test"); } if (Directory.Exists(fileDir)) { List <string> ignoreFileTypeList = new List <string>(); ignoreFileTypeList.Add(".meta"); MyFileUtil.GetFileList(fileDir, ref fileList, zipConfig.listResSuffix, ignoreFileTypeList); } } //特殊文件 foreach (string specialResPath in zipConfig.listSpecialResPath) { string newFilePath = rootDir + specialResPath; if (File.Exists(newFilePath)) { fileList.Add(newFilePath); } } if (fileList.Count == 0) { continue; } //zip中不记录文件的时间 string zipResFilePath; // if (PackageWizard.m_wizard) // { // zipResFilePath = rootDir + "Publish/" + // MyUnityEditorTool.GetPlatformFolderForAssetBundles(EditorUserBuildSettings.activeBuildTarget) // + "/" + PackageWizard.m_wizard.version + "/" + zipConfig.resZipName; // } // else // { zipResFilePath = rootDir + "Publish/" + MyUnityEditorTool.GetPlatformFolderForAssetBundles(EditorUserBuildSettings.activeBuildTarget) + "/" + zipConfig.resZipName; // } ZIPTool.CompressFiles(fileList, dirRemove, zipResFilePath, 0, false, true); //资源信息 ResInfo resInfo = new ResInfo(); resInfo.resName = zipConfig.resZipName; resInfo.resMD5 = MD5Tool.GetByFilePath(zipResFilePath); resInfo.resSize = (int)MyFileUtil.GetFileSize(zipResFilePath); resInfo.resRequireID = zipConfig.resRequireID; // if (PackageWizard.m_wizard) // { // resInfo.resURL = PackageWizard.m_wizard.serverAddress + resInfo.resName; // } // else // { resInfo.resURL = resInfo.resName; // } listResInfo.Add(resInfo); } //----------------------------------------------------// //写到发布目录 string xmlContent = VersionInfo.SerializeInEditor(listResInfo); string xmlFilePath; // if (PackageWizard.m_wizard) // { // xmlFilePath = rootDir + "Publish/" + // MyUnityEditorTool.GetPlatformFolderForAssetBundles(EditorUserBuildSettings.activeBuildTarget) // + "/" + PackageWizard.m_wizard.version + "/VersionInfo.xml"; // } // else // { xmlFilePath = rootDir + "Publish/" + MyUnityEditorTool.GetPlatformFolderForAssetBundles(EditorUserBuildSettings.activeBuildTarget) + "/VersionInfo.xml"; // } File.WriteAllText(xmlFilePath, xmlContent); listResInfo.RemoveAll(r => r.resRequireID > 0); xmlContent = VersionInfo.SerializeInEditor(listResInfo); //写到工程目录 string xmlFileInProjectPath = rootDir + "Assets/StreamingAssets/Config/" + VersionManager.VersionInfoFilePath + MyFileUtil.EncryptXMLFileSuffix; byte[] data = System.Text.UTF8Encoding.UTF8.GetBytes(xmlContent); data = MyFileUtil.EncryptData(data); File.WriteAllBytes(xmlFileInProjectPath, data); Debug.Log("生成资源包结束"); }
static void EncryptLuaCodeImp(LuaEncryptType type) { ClearCurrentProjectLuaRes(); //编译Lua代码为bytecode if (SystemConfig.Instance.IsUseLuaBytecode) { List <string> luaFileList = new List <string>(); MyFileUtil.GetFileList(ResourcesManager.LuaDirForBuild, ref luaFileList, ".lua"); foreach (string filePath in luaFileList) { string newFilePath = filePath.Replace(".lua", MyLuaResLoader.LuaByteCodeFileSuffix); switch (type) { case LuaEncryptType.Auto: ///ios 为64位 if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.iOS) { newFilePath = filePath.Replace(".lua", MyLuaResLoader.X64LuaByteCodeFileSuffix); } EncodeLuaFile(filePath, newFilePath, EditorUserBuildSettings.activeBuildTarget, EditorUserBuildSettings.activeBuildTarget == BuildTarget.iOS); break; case LuaEncryptType.WindowsEditor: EncodeLuaFileForEditor(filePath, newFilePath, RuntimePlatform.WindowsEditor); break; case LuaEncryptType.MacEditor: EncodeLuaFileForEditor(filePath, newFilePath, RuntimePlatform.OSXEditor); break; } } AssetDatabase.Refresh(); // if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.iOS) // { // foreach (string filePath in luaFileList) // { // string newFilePath = filePath.Replace(".lua", MyLuaResLoader.X64LuaByteCodeFileSuffix); // EncodeLuaFile(filePath, newFilePath, EditorUserBuildSettings.activeBuildTarget, true); // } // } } //将lua代码打包为zip List <string> luaCodeFileList = new List <string>(); if (SystemConfig.Instance.IsUseLuaBytecode) { MyFileUtil.GetFileList(ResourcesManager.LuaDirForBuild, ref luaCodeFileList, ".bytes"); } else { MyFileUtil.GetFileList(ResourcesManager.LuaDirForBuild, ref luaCodeFileList, ".lua"); } ZIPTool.CompressFiles(luaCodeFileList, MyFileUtil.GetParentDir(ResourcesManager.LuaDirForBuild), ResourcesManager.LuaZipFileFullPath, 0, true, true); //加密lua代码 if (SystemConfig.Instance.IsEncryptLuaCode) { ResourcesManager.EncryptLuaCode(ResourcesManager.LuaZipFileFullPath); } AssetDatabase.Refresh(); Debug.Log("加密Lua结束"); }