public static void BuildFileIndex() { string resPath = (ResourcePath.GetBaseURL() + UUtility.GetPlatformName() + "/").Remove(0, 7); ///----------------------创建文件列表----------------------- string newFilePath = resPath + "files.txt"; if (File.Exists(newFilePath)) { File.Delete(newFilePath); } paths.Clear(); files.Clear(); Recursive(resPath); FileStream fs = new FileStream(newFilePath, FileMode.CreateNew); StreamWriter sw = new StreamWriter(fs); for (int i = 0; i < files.Count; i++) { string file = files[i]; string ext = Path.GetExtension(file); if (file.EndsWith(".meta") || file.Contains(".DS_Store") || file.Contains(".exe")) { continue; } string md5 = LuaUtil.md5file(file); string value = file.Replace(resPath, string.Empty); sw.WriteLine(value + "|" + md5 + "|" + filesLength[i]); } sw.Close(); fs.Close(); }
public static bool ConvertToBinaryXml(string path) { //if (path.StartsWith(Application.dataPath)) { string saveToDir = ResourcePath.GetLocalConfigPath(); if (!Directory.Exists(saveToDir)) { Directory.CreateDirectory(saveToDir); } if (path.ToLower().EndsWith(".xml")) { try { FileInfo fileInfo = new FileInfo(path); string fileName = fileInfo.Name.Substring(0, fileInfo.Name.Length - fileInfo.Extension.Length); TbXmlSerializer serializer = new TbXmlSerializer(); path = path.Replace(Application.dataPath, ""); path = "Assets/Config/" + path; byte[] bytes = serializer.SerializeXmlString((AssetDatabase.LoadMainAssetAtPath(path) as TextAsset).text); string topath = Path.Combine(Path.Combine("../ClientRes", UUtility.GetPlatformName() + "/config/"), ""); topath = topath + fileName + ".bytes"; File.WriteAllBytes(topath, bytes); return(true); } catch (System.Exception exception) { Debug.LogError("Error:" + path); //Debug.LogError(exception.Message); //Debug.LogError(exception.StackTrace); //Debug.LogError(""); } } else { if (!path.ToLower().EndsWith(".meta")) { FileInfo fileInfo = new FileInfo(path); File.Copy(path, saveToDir + "/" + fileInfo.Name, true); return(true); } } } return(false); }