private void Mirror(BuildTarget target, Model.NodeData node, IEnumerable <PerformGraph.AssetGroups> incoming, IEnumerable <Model.ConnectionData> connectionsToOutput, Action <Model.NodeData, string, float> progressFunc) { try { var srcDir = GetNormalizedPath(m_srcPath[target]); var dstDir = GetNormalizedPath(m_dstPath[target]); if (Directory.Exists(dstDir)) { if (m_mirrorOption[target] == (int)MirrorOption.AlwaysRecreateDestination) { FileUtility.DeleteDirectory(dstDir, true); } else if (m_mirrorOption[target] == (int)MirrorOption.KeepAlreadyCopiedFiles) { var dstFilePaths = FileUtility.GetAllFilePathsInFolder(dstDir); // checking destination files - remove files if not exist in source foreach (var dstPath in dstFilePaths) { var srcPath = dstPath.Replace(dstDir, srcDir); if (!File.Exists(srcPath)) { File.Delete(dstPath); } } } } var targetFilePaths = FileUtility.GetAllFilePathsInFolder(srcDir); int i = 0; foreach (var srcPath in targetFilePaths) { var dstPath = srcPath.Replace(srcDir, dstDir); var dstParentDir = Directory.GetParent(dstPath); if (!dstParentDir.Exists) { var dirPath = dstParentDir.ToString(); Directory.CreateDirectory(dirPath); } var srcInfo = new FileInfo(srcPath); var dstInfo = new FileInfo(dstPath); if (!dstInfo.Exists || srcInfo.LastWriteTimeUtc > dstInfo.LastWriteTimeUtc) { File.Copy(srcPath, dstPath, true); progressFunc(node, string.Format("Copying {0}", Path.GetFileName(srcPath)), (float)(i++) / (float)targetFilePaths.Count); } } } catch (Exception e) { throw new NodeException(node.Name + ":" + e.Message, node); } }
public static void RemakeDirectory(string localFolderPath) { if (Directory.Exists(localFolderPath)) { FileUtility.DeleteDirectory(localFolderPath, true); } Directory.CreateDirectory(localFolderPath); }
public override void OnNodeDelete(Model.NodeData nodeData) { var savedSettingDir = FileUtility.PathCombine(Model.Settings.Path.SavedSettingsPath, "ImportSettings", nodeData.Id); if (AssetDatabase.IsValidFolder(savedSettingDir)) { FileUtility.DeleteDirectory(savedSettingDir, true); } }
public static void DeleteFileThenDeleteFolderIfEmpty(string localTargetFilePath) { File.Delete(localTargetFilePath); File.Delete(localTargetFilePath + Model.Settings.UNITY_METAFILE_EXTENSION); var directoryPath = Directory.GetParent(localTargetFilePath).FullName; var restFiles = GetFilePathsInFolder(directoryPath); if (!restFiles.Any()) { FileUtility.DeleteDirectory(directoryPath, true); File.Delete(directoryPath + Model.Settings.UNITY_METAFILE_EXTENSION); } }
private string PrepareOutputDirectory(BuildTarget target, Model.NodeData node, bool autoCreate, bool throwException) { var outputOption = (OutputOption)m_outputOption [target]; if (outputOption == OutputOption.BuildInCacheDirectory) { return(FileUtility.EnsureAssetBundleCacheDirExists(target, node)); } var outputDir = m_outputDir [target]; outputDir = outputDir.Replace("{Platform}", BuildTargetUtility.TargetToAssetBundlePlatformName(target)); if (throwException) { if (string.IsNullOrEmpty(outputDir)) { throw new NodeException("Output directory is empty.", "Select valid output directory from inspector.", node); } if (target != BuildTargetUtility.GroupToTarget(BuildTargetGroup.Unknown) && outputOption == OutputOption.ErrorIfNoOutputDirectoryFound) { if (!Directory.Exists(outputDir)) { throw new NodeException("Output directory not found. \n" + outputDir, "Create output directory or select other valid directory from inspector.", node); } } } if (autoCreate) { if (outputOption == OutputOption.DeleteAndRecreateOutputDirectory) { if (Directory.Exists(outputDir)) { FileUtility.DeleteDirectory(outputDir, true); } } if (!Directory.Exists(outputDir)) { Directory.CreateDirectory(outputDir); } } return(outputDir); }
public override void Build(BuildTarget target, Model.NodeData node, IEnumerable <PerformGraph.AssetGroups> incoming, IEnumerable <Model.ConnectionData> connectionsToOutput, PerformGraph.Output Output, Action <Model.NodeData, string, float> progressFunc) { if (incoming == null) { return; } var dstPath = GetDestinationPath(m_destinationPath[target]); if (m_destinationOption[target] == (int)DestinationDirectoryOption.DeleteAndRecreateExportDirectory) { if (Directory.Exists(dstPath)) { FileUtility.DeleteDirectory(dstPath, true); } } if (m_destinationOption[target] != (int)DestinationDirectoryOption.ErrorIfNoExportDirectoryFound) { if (!Directory.Exists(dstPath)) { Directory.CreateDirectory(dstPath); } } var opTypeName = m_operationType == FileOperationType.Copy ? "Copy" : "Move"; var isDestinationWithinProject = dstPath.StartsWith(Application.dataPath); var projectPathLength = Directory.GetParent(Application.dataPath).ToString().Length + 1; foreach (var ag in incoming) { foreach (var groupKey in ag.assetGroups.Keys) { var inputSources = ag.assetGroups[groupKey]; foreach (var source in inputSources) { var destination = FileUtility.PathCombine(dstPath, GetReducedPath(source)); var parentDir = Directory.GetParent(destination).ToString(); if (!Directory.Exists(parentDir)) { Directory.CreateDirectory(parentDir); } if (File.Exists(destination)) { File.Delete(destination); } if (string.IsNullOrEmpty(source.importFrom)) { continue; } try { progressFunc?.Invoke(node, $"{opTypeName} {source.fileNameAndExtension}", 0.5f); if (m_operationType == FileOperationType.Copy) { if (source.isProjectAsset && isDestinationWithinProject) { var relativePath = destination.Substring(projectPathLength); AssetDatabase.CopyAsset(source.importFrom, relativePath); } else { File.Copy(source.importFrom, destination); } } else { if (source.isProjectAsset && isDestinationWithinProject) { var relativePath = destination.Substring(projectPathLength); AssetDatabase.MoveAsset(source.importFrom, relativePath); } else { File.Move(source.importFrom, destination); } } } catch (Exception) { // ignored } } } } }
private void Export(BuildTarget target, Model.NodeData node, IEnumerable <PerformGraph.AssetGroups> incoming, IEnumerable <Model.ConnectionData> connectionsToOutput, Action <Model.NodeData, string, float> progressFunc) { if (incoming == null) { return; } var exportPath = GetExportPath(m_exportPath[target]); if (m_exportOption[target] == (int)ExportOption.DeleteAndRecreateExportDirectory) { if (Directory.Exists(exportPath)) { FileUtility.DeleteDirectory(exportPath, true); } } if (m_exportOption[target] != (int)ExportOption.ErrorIfNoExportDirectoryFound) { if (!Directory.Exists(exportPath)) { Directory.CreateDirectory(exportPath); } } var report = new ExportReport(node); var cacheFolderDepth = Model.Settings.Path.BundleBuilderCachePath.Split(Model.Settings.UNITY_FOLDER_SEPARATOR).Length; foreach (var ag in incoming) { foreach (var groupKey in ag.assetGroups.Keys) { var inputSources = ag.assetGroups[groupKey]; foreach (var source in inputSources) { var destinationSourcePath = source.importFrom; string destination = null; if (m_flattenDir[target] == 0) { // in bundleBulider, use platform-package folder for export destination. if (destinationSourcePath.StartsWith(Model.Settings.Path.BundleBuilderCachePath)) { var splitted = destinationSourcePath.Split(Model.Settings.UNITY_FOLDER_SEPARATOR); var reducedArray = new string[splitted.Length - cacheFolderDepth]; Array.Copy(splitted, cacheFolderDepth, reducedArray, 0, reducedArray.Length); var fromDepthToEnd = string.Join(Model.Settings.UNITY_FOLDER_SEPARATOR.ToString(), reducedArray); destinationSourcePath = fromDepthToEnd; } destination = FileUtility.PathCombine(exportPath, destinationSourcePath); } else { destination = FileUtility.PathCombine(exportPath, source.fileNameAndExtension); } var parentDir = Directory.GetParent(destination).ToString(); if (!Directory.Exists(parentDir)) { Directory.CreateDirectory(parentDir); } if (File.Exists(destination)) { File.Delete(destination); } if (string.IsNullOrEmpty(source.importFrom)) { report.AddErrorEntry(source.absolutePath, destination, "Source Asset import path is empty; given asset is not imported by Unity."); continue; } try { if (progressFunc != null) { progressFunc(node, string.Format("Copying {0}", source.fileNameAndExtension), 0.5f); } File.Copy(source.importFrom, destination); report.AddExportedEntry(source.importFrom, destination); } catch (Exception e) { report.AddErrorEntry(source.importFrom, destination, e.Message); } source.exportTo = destination; } } } AssetBundleBuildReport.AddExportReport(report); }