public static void EncodeConfigFile() { if (SystemConfig.Instance.IsEncryptConfigFile == false) { return; } List <string> configList = new List <string>(); MyFileUtil.GetFileList(MyFileUtil.InnerConfigDir, ref configList, ".xml"); foreach (string fileName in configList) { if (fileName.EndsWith(".meta") == true) { continue; } byte[] data = File.ReadAllBytes(fileName); data = DESCrypto.Encrypt(data, MyFileUtil.EncryptKey); File.WriteAllBytes(fileName + MyFileUtil.EncryptXMLFileSuffix, data); //MyFileUtil.DeleteFile(fileName); } AssetDatabase.Refresh(); Debug.Log("加密配置文件结束"); }
private static void CreateSpritePacker(ref SpriteInfo data) { var path = data.path.Substring(data.path.IndexOf("Assets")); var packingTag = Path.GetFileName(path); data.tag = packingTag; data.path = path; List <string> fileList = new List <string>();; MyFileUtil.GetFileList(path, ref fileList, null, ".meta"); List <Sprite> sprites = new List <Sprite>(); foreach (var itemPath in fileList) { var newPath = itemPath.Substring(itemPath.IndexOf("Assets")); var extension = Path.GetExtension(newPath); if (extension.Equals(".asset")) { continue; } var improter = AssetImporter.GetAtPath(newPath) as TextureImporter; improter.textureType = TextureImporterType.Sprite; improter.mipmapEnabled = false; improter.spritePackingTag = packingTag; improter.SaveAndReimport(); sprites.Add(AssetDatabase.LoadAssetAtPath <Sprite>(newPath)); } GeneratePacker(sprites, path + "/" + packingTag + "SpritePacker.asset"); AssetDatabase.Refresh(); }
public static void ClearCoyProjectRes() { string targetDir = CopyProjectTargetDir; //清理目标工程下未加密的配置文件 List <string> configFileList = new List <string>(); MyFileUtil.GetFileList(targetDir + "Assets/StreamingAssets/Config", ref configFileList, ".xml"); foreach (string filePath in configFileList) { MyFileUtil.DeleteFile(filePath); } //清理sdk配置文件 // string localVersionInfoConfigFilePath = targetDir + "Assets/StreamingAssets/Config/" + LocalVersionInfoConfig.fileName + MyFileUtil.EncryptXMLFileSuffix; // MyFileUtil.DeleteFile(localVersionInfoConfigFilePath); //清理目标工程下未加密的lua文件 string luaDir = targetDir + "Assets/StreamingAssets/Lua"; MyFileUtil.DeleteDir(luaDir); //清理lua项目配置文件 List <string> luaProjectFiles = new List <string>(); string streamingAssetsDir = targetDir + "Assets/StreamingAssets"; DirectoryInfo di = new DirectoryInfo(streamingAssetsDir); var fs = di.GetFiles(); foreach (var item in fs) { if (item.FullName.EndsWith(".user")) { MyFileUtil.DeleteFile(item.FullName); } if (item.FullName.EndsWith(".luaproj")) { MyFileUtil.DeleteFile(item.FullName); } if (item.FullName.EndsWith(".config")) { MyFileUtil.DeleteFile(item.FullName); } } //清理Resources目录下的文件 string ResourcesDir = targetDir + "Assets/Resources/" + ResourcesManager.DirNameForAssetBundlesBuildFrom; MyFileUtil.DeleteDir(ResourcesDir); Debug.Log("清理拷贝工程多余资源"); }
static void VersionsDifferenceZipImp(string oldVersionDir, string newVersionDir) { oldVersionDir = MyFileUtil.DealFilePathSlash(oldVersionDir); newVersionDir = MyFileUtil.DealFilePathSlash(newVersionDir); List <string> oldFileList = new List <string>(); List <string> newFileList = new List <string>(); MyFileUtil.GetFileList(oldVersionDir, ref oldFileList); MyFileUtil.GetFileList(newVersionDir, ref newFileList); List <string> modificationFileList = new List <string>(); foreach (string newFilePath in newFileList) { int index = oldFileList.IndexOf(newFilePath); if (index < 0) { //添加新的文件 modificationFileList.Add(newFilePath); } else { string oldFilePath = oldFileList[index]; if (MD5Tool.VerifyFile(newFilePath, oldFilePath) == false) { //文件改变 modificationFileList.Add(newFilePath); } } } //string time = System.DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss"); string modificationDir = MyFileUtil.GetParentDir(newVersionDir) + "update_tmp"; MyFileUtil.DeleteDir(modificationDir); MyFileUtil.CreateDir(modificationDir); foreach (string filePath in modificationFileList) { string newFilePath = filePath.Replace(newVersionDir, modificationDir); MyFileUtil.CopyFile(filePath, newFilePath); } string zipFilePath = modificationDir + ".zip"; ZIPTool.CompressDirectory(modificationDir, zipFilePath, 0, false); Debug.Log(""); }
//[MenuItem("Build/清理当前工程下加密的lua文件")] public static void ClearCurrentProjectLuaRes() { List <string> srcLuaFileList = new List <string>(); MyFileUtil.GetFileList(ResourcesManager.LuaDirForBuild, ref srcLuaFileList, MyFileUtil.EncryptXMLFileSuffix); foreach (string filePath in srcLuaFileList) { MyFileUtil.DeleteFile(filePath); } MyFileUtil.DeleteFile(ResourcesManager.LuaZipFileFullPath); AssetDatabase.Refresh(); }
public static void ClearCurrentProjectRes() { //清理当前工程下加密的配置文件 List <string> srcConfigFileList = new List <string>(); MyFileUtil.GetFileList(MyFileUtil.InnerConfigDir, ref srcConfigFileList, MyFileUtil.EncryptXMLFileSuffix); foreach (string filePath in srcConfigFileList) { MyFileUtil.DeleteFile(filePath); } //清理当前工程下加密的lua文件 ClearCurrentProjectLuaRes(); AssetDatabase.Refresh(); Debug.Log("清理当前工程多余资源"); }
static public List <string> GenerateFileList(string rootDir) { List <string> dirList = new List <string>(); //资源目录--生成此目录下的资源名列表 //Common路径不能交换,即Common目录首先加入 dirList.Add(rootDir + "Common"); //TODO: // dirList.Add(rootDir + SDKConfig.GetCurrentVersionResPath()); Dictionary <string, string> dictFilePath = new Dictionary <string, string>(); foreach (string dir in dirList) { List <string> fileList = new List <string>(); MyFileUtil.GetFileList(dir, ref fileList); foreach (string filePath in fileList) { string fileName = Path.GetFileName(filePath); if (dictFilePath.ContainsKey(fileName)) { if (fileName.EndsWith(".meta")) { continue; } //后加入的资源路径覆盖掉前面的资源路径,即版本目录下的文件覆盖掉Common目录下的同名文件 //string str = string.Format("ResourcesManager.GenerateFileList:资源名{0}重复,使用的资源路径{1}", fileName, filePath); //Debug.Log(str); dictFilePath[fileName] = filePath; } else { dictFilePath.Add(fileName, filePath); } } } return(new List <string>(dictFilePath.Values)); }
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结束"); }