public void Freeze(int version) { if (version <= 0) { return; } var repositoryRoot = AssetSyncConfiger.GetInstance().GetRepositoryRootPath(); if (string.IsNullOrEmpty(repositoryRoot)) { return; } var syncItems = AssetSyncConfiger.GetInstance().syncItems; if (syncItems == null || syncItems.Count <= 0) { return; } string versionFolderName = string.Format("{0}", version); string repositoryPath = XPathTools.Combine(repositoryRoot, versionFolderName); foreach (var syncItem in syncItems) { string destPath = XPathTools.Combine(repositoryPath, syncItem.realSearcePath); if (XFolderTools.Exists(destPath)) { XFolderTools.DeleteDirectory(destPath, true); } } }
public void Sync(int version) { var syncItems = AssetSyncConfiger.GetInstance().syncItems; if (syncItems == null || syncItems.Count <= 0) { return; } string fullPath = XPathTools.Combine(AssetSyncConfiger.GetInstance().repositoryRootPath, string.Format("{0}", version)); string repositoryPath = fullPath; string versionFolderName = Path.GetFileNameWithoutExtension(fullPath); int curVersion = AssetSyncConfiger.GetInstance().GetRepositoryVersion(versionFolderName); if (curVersion > 0 && curVersion >= AssetSyncConfiger.GetInstance().minVersion) { foreach (var syncItem in syncItems) { string srcPath = syncItem.srcPath; string searchPath = XPathTools.Combine(repositoryPath, syncItem.realSearcePath); string syncPath = XPathTools.Combine(repositoryPath, syncItem.realSyncPath); if (XFolderTools.Exists(srcPath) && XFolderTools.Exists(searchPath) && XFolderTools.Exists(syncPath)) { List <string> syncFileList = new List <string>(); List <string> syncFolderList = new List <string>(); if (syncItem.searchMode == AssetSyncItem.SearchMode.Forward) //根据搜索文件找资源 { string srcEx = GetFolderFirstFileExtension(srcPath); XFolderTools.TraverseFiles(searchPath, (filePath) => { string fileKey = null; if (syncItem.searchKey == AssetSyncItem.SearchKey.AssetName) { fileKey = Path.GetFileNameWithoutExtension(filePath); } else if (syncItem.searchKey == AssetSyncItem.SearchKey.AssetPrefix) { fileKey = XStringTools.SplitPathKey(filePath); } string srcFilePath = XPathTools.Combine(srcPath, string.Format("{0}{1}", fileKey, srcEx)); if (XFileTools.Exists(srcFilePath)) { syncFileList.Add(srcFilePath); } }); XFolderTools.TraverseFolder(searchPath, (folderPath) => { string fileKey = null; if (syncItem.searchKey == AssetSyncItem.SearchKey.AssetName) { fileKey = Path.GetFileNameWithoutExtension(folderPath); } else if (syncItem.searchKey == AssetSyncItem.SearchKey.AssetPrefix) { fileKey = XStringTools.SplitPathKey(folderPath); } string srcFolderPath = XPathTools.Combine(srcPath, string.Format("{0}", fileKey)); if (XFolderTools.Exists(srcFolderPath)) { syncFolderList.Add(srcFolderPath); } }); } else if (syncItem.searchMode == AssetSyncItem.SearchMode.Reverse) //根据资源匹对文件 { XFolderTools.TraverseFiles(srcPath, (filePath) => { string fileKey = null; if (syncItem.searchKey == AssetSyncItem.SearchKey.AssetName) { fileKey = Path.GetFileNameWithoutExtension(filePath); } else if (syncItem.searchKey == AssetSyncItem.SearchKey.AssetPrefix) { fileKey = XStringTools.SplitPathKey(filePath); } string searchFilePath = XPathTools.Combine(searchPath, string.Format("{0}", fileKey)); if (XFileTools.Exists(searchFilePath)) { syncFileList.Add(filePath); } }); XFolderTools.TraverseFolder(srcPath, (folderPath) => { string fileKey = null; if (syncItem.searchKey == AssetSyncItem.SearchKey.AssetName) { fileKey = Path.GetFileNameWithoutExtension(folderPath); } else if (syncItem.searchKey == AssetSyncItem.SearchKey.AssetPrefix) { fileKey = XStringTools.SplitPathKey(folderPath); } string searchFilePath = XPathTools.Combine(searchPath, string.Format("{0}", fileKey)); if (XFileTools.Exists(searchFilePath)) { syncFolderList.Add(folderPath); } }); } HashSet <string> syncFileDict = new HashSet <string>(); foreach (var syncSrcFile in syncFileList) { //把文件拷贝到同步目录 string syncFileName = Path.GetFileName(syncSrcFile); string syncDestPath = XPathTools.Combine(syncPath, syncFileName); XFileTools.Delete(syncDestPath); XFileTools.Copy(syncSrcFile, syncDestPath); if (!syncFileDict.Contains(syncDestPath)) { syncFileDict.Add(syncDestPath); } } HashSet <string> syncFolderDict = new HashSet <string>(); foreach (var syncSrcFolder in syncFolderList) { //把文件拷贝到同步目录 string syncFileName = Path.GetFileName(syncSrcFolder); string syncDestPath = XPathTools.Combine(syncPath, syncFileName); XFolderTools.DeleteDirectory(syncDestPath, true); XFolderTools.CopyDirectory(syncSrcFolder, syncDestPath); if (!syncFolderDict.Contains(syncDestPath)) { syncFolderDict.Add(syncDestPath); } } //移除不在同步的文件 XFolderTools.TraverseFiles(syncPath, (syncFullPath) => { if (!syncFileDict.Contains(syncFullPath)) { XFileTools.Delete(syncFullPath); } }); XFolderTools.TraverseFolder(syncPath, (syncFullPath) => { if (!syncFolderDict.Contains(syncFullPath)) { XFolderTools.DeleteDirectory(syncFullPath, true); } }); } } } }
private void DoEnd() { //处理无效的Checkfile文件 string checkfileFolderPath = AssetProcesserConfiger.GetInstance().GetCheckfileSaveFolderPath(_progresersName); //TODO:这里如果全部放到一个路径下,会被别的干扰到了 bool isUseGUID = AssetProcesserConfiger.GetInstance().useGUID4SaveCheckfileName; bool createFolderOrAddSuffix = AssetProcesserConfiger.GetInstance().createFolderOrAddSuffix; XFolderTools.TraverseFiles(checkfileFolderPath, (fullPath) => { string exName = Path.GetExtension(fullPath).ToLower(); if (exName.Contains("meta")) { return; } string realPath = XPathTools.GetRelativePath(fullPath); //路径做Key,有的资源可能名字相同 string realPathLow = realPath.ToLower(); if (isUseGUID) { string srcPath = AssetDatabase.GUIDToAssetPath(realPath); if (string.IsNullOrEmpty(srcPath) || !_assetMap.ContainsKey(realPathLow)) { XFileTools.Delete(fullPath); } } else { bool canDelete = true; if (!createFolderOrAddSuffix) { string fileNameWithoutEx = Path.GetFileNameWithoutExtension(realPath); if (!fileNameWithoutEx.EndsWith(_progresersName)) { canDelete = false; } } if (canDelete && !_checkfilePath2srcAssetPath.ContainsKey(realPath)) { XFileTools.Delete(fullPath); } } }); //处理无效输出文件 string outputFolderPath = AssetProcesserConfiger.GetInstance().GetProcessSaveFolderPath(_progresersName); XFolderTools.TraverseFolder(outputFolderPath, (fullPath) => { string realPath = XPathTools.GetRelativePath(fullPath); string checkKey1 = Path.GetFileNameWithoutExtension(fullPath); string checkKey2 = XStringTools.SplitPathKey(fullPath); //但凡在名字上有点关系都移除,多重key检测 if (!_processPath2srcAssetPath.ContainsKey(checkKey1) && !_processPath2srcAssetPath.ContainsKey(checkKey2) && !_processPath2srcAssetPath.ContainsKey(realPath)) { XFolderTools.DeleteDirectory(fullPath, true); } }); XFolderTools.TraverseFiles(outputFolderPath, (fullPath) => { string exName = Path.GetExtension(fullPath).ToLower(); if (exName.Contains("meta")) { return; } string realPath = XPathTools.GetRelativePath(fullPath); //路径做Key,有的资源可能名字相同 string checkKey1 = Path.GetFileNameWithoutExtension(fullPath); string checkKey2 = XStringTools.SplitPathKey(fullPath); //但凡在名字上有点关系都移除,多重key检测 if (!_processPath2srcAssetPath.ContainsKey(checkKey1) && !_processPath2srcAssetPath.ContainsKey(checkKey2) && !_processPath2srcAssetPath.ContainsKey(realPath)) { XFileTools.Delete(fullPath); } }); OnEnd(); }