public static Dictionary <string, List <string> > ReadVersionFile(string filePath) { Dictionary <string, List <string> > versionInfo = new Dictionary <string, List <string> >(); byte[] versionbytes = ABHelper.ReadFileToBytes(filePath); if (null == versionbytes) { return(versionInfo); } Encrypt(ref versionbytes); //RC4 加密文件 string versionTxt = Encoding.UTF8.GetString(versionbytes); if (!string.IsNullOrEmpty(versionTxt)) { //ui/tips.ab:ba2de82e3fc42e750d317b133096dfea:0:22455:fa7917d4974436b1214dc313fccda2a5 //路径:内容md5:版号:size:路径md5 string[] split = versionTxt.Split('\r'); foreach (string k in split) { string[] split2 = k.Split(':'); versionInfo.Add(split2[0], new List <string>() { split2[1], split2[2], split2[3], split2[4] }); } } return(versionInfo); }
// 拷贝目录,包括 private static void DirCopy(string srcPath, string tarPath, string fileExtension = null) { try { bool needAddExtension = !string.IsNullOrEmpty(fileExtension); // 检查目标目录是否以目录分割字符结束如果不是则添加 if (tarPath[tarPath.Length - 1] != System.IO.Path.DirectorySeparatorChar) { tarPath += System.IO.Path.DirectorySeparatorChar; } // 判断目标目录是否存在如果不存在则新建 if (!System.IO.Directory.Exists(tarPath)) { System.IO.Directory.CreateDirectory(tarPath); } // 得到源目录的文件列表,该里面是包含文件以及目录路径的一个数组 // 如果你指向copy目标文件下面的文件而不包含目录请使用下面的方法 // string[] fileList = Directory.GetFiles(srcPath); string[] fileList = System.IO.Directory.GetFileSystemEntries(srcPath); // 遍历所有的文件和目录 foreach (string file in fileList) { string targetFileName = tarPath + System.IO.Path.GetFileName(file); // 先当作目录处理如果存在这个目录就递归Copy该目录下面的文件 if (System.IO.Directory.Exists(file)) { DirCopy(file, targetFileName, fileExtension); } // 否则直接Copy文件 else { // 剔除meta文件, .DS打头的文件 if (targetFileName.EndsWith(".meta") || targetFileName.Contains(".DS")) { continue; } // 添加后缀 if (needAddExtension) { targetFileName = targetFileName + fileExtension; } byte[] content = ABHelper.ReadFileToBytes(file);; if (null == content || content.Length <= 0) { continue; } ABHelper.Encrypt(ref content); ABHelper.WriteFileByBytes(targetFileName, content); } } } catch (Exception e) { throw; } }
public static string[] ReadVersionNumFile(string filePath) { string[] num = null; byte[] numbytes = ABHelper.ReadFileToBytes(filePath); if (null == numbytes) { return(num); } Encrypt(ref numbytes); //RC4 加密文件 string numTxt = Encoding.UTF8.GetString(numbytes); if (!string.IsNullOrEmpty(numTxt)) { num = ABHelper.VersionNumSplit(numTxt); } return(num); }
private static void CopyLuaFiles(string path) { string filePath = CreatFileUrlMd5(path.Replace("Assets/", "") + ".txt"); filePath = (CurVersionABExportPath + filePath).ToLower(); string fileFolder = Path.GetDirectoryName(filePath); if (!Directory.Exists(fileFolder)) { Directory.CreateDirectory(fileFolder); } if (File.Exists(filePath)) { File.Delete(filePath); } // 加密 byte[] bytes = ABHelper.ReadFileToBytes(path); ABHelper.Encrypt(ref bytes); //RC4 加密lua文件 ABHelper.WriteFileByBytes(filePath, bytes); }
private static byte[] TryLoadLuaFromFile(string fullpath, bool encrypt = true) { byte[] bytes = ABHelper.ReadFileToBytes(fullpath); if (null == bytes) { return(null); } if (encrypt) { ABHelper.Encrypt(ref bytes); } // 转换为utf8 using (Stream stream = new MemoryStream(bytes)) { using (StreamReader sr = new StreamReader(stream)) { string code = sr.ReadToEnd(); return(System.Text.Encoding.UTF8.GetBytes(code)); } } }
public static Dictionary <string, List <string> > ReadManifestFile(string filePath) { Dictionary <string, List <string> > manifestInfo = new Dictionary <string, List <string> >(); byte[] manifestbytes = ABHelper.ReadFileToBytes(filePath); if (null == manifestbytes) { return(manifestInfo); } Encrypt(ref manifestbytes); //RC4 加密文件 string manifestTxt = Encoding.UTF8.GetString(manifestbytes); if (!string.IsNullOrEmpty(manifestTxt)) { // scenesfinal/hottertest.ab:shaders/lpcpbrsoldier.ab,prefabs/monster/cha_archer_l1.ab string[] split = manifestTxt.Split('\r'); foreach (string k in split) { string[] split2 = k.Split(':'); if (!manifestInfo.ContainsKey(split2[0])) { manifestInfo.Add(split2[0], new List <string>()); } string[] split3 = split2[1].Split(','); foreach (string k3 in split3) { if (!manifestInfo[split2[0]].Contains(k3)) { manifestInfo[split2[0]].Add(k3); } } } } return(manifestInfo); }
public static Dictionary <string, List <string> > ReadManifestFileByPath(string filePath) { return(ReadManifestFileByBytes(ABHelper.ReadFileToBytes(filePath))); }
public static string[] ReadVersionNumFileByPath(string filePath) { return(ReadVersionNumFileByBytes(ABHelper.ReadFileToBytes(filePath))); }
// 生成lua的bytecode private static void GenLuaByteCode(string sourceDirName, string destDirName, bool copySubDirs = true) { DirectoryInfo dir = new DirectoryInfo(sourceDirName); if (!dir.Exists) { throw new DirectoryNotFoundException("Source directory does not exist or could not be found: " + sourceDirName); } DirectoryInfo[] dirs = dir.GetDirectories(); if (!Directory.Exists(destDirName)) { Directory.CreateDirectory(destDirName); } // 遍历所有文件 FileInfo[] files = dir.GetFiles(); foreach (FileInfo file in files) { // 剔除meta文件, .DS打头的文件 if (file.Name.EndsWith(".meta") || file.Name.Contains(".DS")) { continue; } string sourcePath = Path.Combine(sourceDirName, file.Name); string destinationPath = Path.Combine(destDirName, file.Name); #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN // 路径转义字符替换 sourcePath = sourcePath.Replace("/", "\\"); destinationPath = destinationPath.Replace("/", "\\"); #endif // 目标路径,加个txt后缀 destinationPath = destinationPath + ".txt"; // 编译bytecode m_process.StartInfo.FileName = m_luajitExePath; m_process.StartInfo.Arguments = string.Format(" -b {0} {1}", sourcePath, destinationPath); m_process.StartInfo.WorkingDirectory = m_luajitWorkingPath; try { m_process.Start(); m_process.WaitForExit(); } catch (Exception e) { Debug.LogError(e.Message); } // Debug.Log("~~~~~执行输出\n" + m_process.StandardOutput.ReadToEnd()); // Debug.Log("~~~~~执行错误\n" + m_process.StandardError.ReadToEnd()); // Debug.Log("~~~~~执行返回码:" + m_process.ExitCode); // 处理成功后 if (m_process.ExitCode == 0) { byte[] content = ABHelper.ReadFileToBytes(sourcePath); ABHelper.Encrypt(ref content); ABHelper.WriteFileByBytes(destinationPath, content); } } if (copySubDirs) { foreach (DirectoryInfo subdir in dirs) { string temppath = Path.Combine(destDirName, subdir.Name); GenLuaByteCode(subdir.FullName, temppath, copySubDirs); } } }