public List <IMazeElement> FindPath() { List <IMazeElement> unexploredWalkableMazeElementsList = unexploredMazeElements.GetUnexploredList(); bool destinationReach = false; startMazeElement.PathFindWeight = 0; while (unexploredWalkableMazeElementsList.Count > 0 && destinationReach == false) { unexploredWalkableMazeElementsList.Sort((x, y) => x.PathFindWeight.CompareTo(y.PathFindWeight)); IMazeElement currentMazeElement = unexploredWalkableMazeElementsList[0]; pathFindProcessMetric.IncreaseNumberOfVisitedNodes(); if (currentMazeElement == destinationMazeElement) { destinationReach = true; continue; } unexploredWalkableMazeElementsList.Remove(currentMazeElement); List <IMazeElement> neighbourMazeElementList = planeBuilder.GetNeighboursOfMazeElement(currentMazeElement); ProcessNeighboursPathFindParameters(neighbourMazeElementList, unexploredWalkableMazeElementsList, currentMazeElement); } List <IMazeElement> listFromStartToDestination = DestinationPath.GetListFromStartToDestination(destinationMazeElement); pathFindProcessMetric.SetPathLengthExpressedInNumberOfNodes(listFromStartToDestination.Count); return(DestinationPath.GetListFromStartToDestination(destinationMazeElement)); }
public List <IMazeElement> FindPath() { startMazeElement.PathFindWeight = 0; openCloseListController.AddToOpenList(startMazeElement); while (openCloseListController.OpenListCount() > 0 && destinationReach == false) { IMazeElement currentMazeElement = openCloseListController.GetMazeElementWithLowestWeight(); Debug.Log(currentMazeElement.Index); openCloseListController.RemoveFirstElementFromOpenList(currentMazeElement); openCloseListController.AddToCloseList(currentMazeElement); pathFindProcessMetric.IncreaseNumberOfVisitedNodes(); if (currentMazeElement == destinationMazeElement) { destinationReach = true; continue; } currentMazeElement.Tag = "PathFindSolution"; neighboursPathFindParametersProcessor.ProcessNeighboursPathFindParameters(currentMazeElement, openCloseListController, pathFindProcessMetric); } List <IMazeElement> listFromStartToDestination = DestinationPath.GetListFromStartToDestination(destinationMazeElement); pathFindProcessMetric.SetPathLengthExpressedInNumberOfNodes(listFromStartToDestination.Count); return(listFromStartToDestination); }
private void ChangeNameSpace() { if (string.IsNullOrEmpty(NameSpace) && string.IsNullOrEmpty(ProjectPath) == false) { var projectName = Path.GetFileNameWithoutExtension(ProjectPath); NameSpace = projectName + DestinationPath?.Split(new string[] { projectName }, StringSplitOptions.None).Last().Replace("/", ".").Replace("\\", "."); } }
// Module defining this command // Optional custom code for this activity /// <summary> /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run. /// </summary> /// <param name="context">The NativeActivityContext for the currently running activity.</param> /// <returns>A populated instance of System.Management.Automation.PowerShell</returns> /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks> protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context) { System.Management.Automation.PowerShell invoker = global::System.Management.Automation.PowerShell.Create(); System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName); // Initialize the arguments if (DestinationPath.Expression != null) { targetCommand.AddParameter("DestinationPath", DestinationPath.Get(context)); } if (LiteralPath.Expression != null) { targetCommand.AddParameter("LiteralPath", LiteralPath.Get(context)); } if (Module.Expression != null) { targetCommand.AddParameter("Module", Module.Get(context)); } if (FullyQualifiedModule.Expression != null) { targetCommand.AddParameter("FullyQualifiedModule", FullyQualifiedModule.Get(context)); } if (UICulture.Expression != null) { targetCommand.AddParameter("UICulture", UICulture.Get(context)); } if (Credential.Expression != null) { targetCommand.AddParameter("Credential", Credential.Get(context)); } if (UseDefaultCredentials.Expression != null) { targetCommand.AddParameter("UseDefaultCredentials", UseDefaultCredentials.Get(context)); } if (Force.Expression != null) { targetCommand.AddParameter("Force", Force.Get(context)); } return(new ActivityImplementationContext() { PowerShellInstance = invoker }); }
protected override void Execute(CodeActivityContext context) { try { //Read input values string sourceDirectory = SourcePath.Get(context); int cutOfNumber = (int)InDays.Get(context); string distinationDirectory = DestinationPath.Get(context); int actionType = this.Action.GetHashCode(); bool isRequiredToPerformSubFolder = this.IncludeSubFolder.GetHashCode() == 1 ? true : false; bool Flag = false; //Make sure source folder path is valid if (Directory.Exists(sourceDirectory)) { string[] files = Directory.GetFiles(sourceDirectory); switch (actionType) { case 1: Flag = DeleteFiles(files, cutOfNumber, sourceDirectory, isRequiredToPerformSubFolder); break; case 2: Flag = CopyFiles(files, cutOfNumber, sourceDirectory, distinationDirectory, isRequiredToPerformSubFolder); break; case 3: Flag = MoveFiles(files, cutOfNumber, sourceDirectory, distinationDirectory, isRequiredToPerformSubFolder); break; case 4: Flag = CompressToZip(files, cutOfNumber, sourceDirectory, distinationDirectory, isRequiredToPerformSubFolder); break; } } if (!Flag) { ErrorMessage.Set(context, "None of the files found in giving criteria 'file CreatedDate < " + DateTime.Now.AddDays(-cutOfNumber).Date.ToString("MM-dd-yyyy") + "'"); } Result.Set(context, Flag); } catch (Exception ex) { Result.Set(context, false); ErrorMessage.Set(context, ex.Message.ToString()); } }
protected override void Execute(NativeActivityContext context) { var todayDate = DateTime.UtcNow.Date; var in_FilePaths = InputFilePaths.Get(context); var in_DestPath = DestinationPath.Get(context); // var fileName = ""; var in_ZipFolderName = ZipFolderName.Get(context); if (in_ZipFolderName.Equals("")) { in_ZipFolderName = todayDate.ToString("dd.MM.yyyy") + "_CompressFile"; } Directory.CreateDirectory(in_DestPath + "\\" + "TempFile"); var patharray = in_FilePaths.Split(','); CopyFolderFile(patharray, in_DestPath + "\\TempFile"); /* * foreach(string file in patharray) * { * * fileName = Path.GetFileName(file); * * FileAttributes fa = File.GetAttributes(file); * * if ((fa & FileAttributes.Directory) == FileAttributes.Directory) { * * * } * * File.Copy(file, in_DestPath + "\\" + "TempFile\\" +fileName,true); * * } */ ZipFile.CreateFromDirectory(in_DestPath + "\\" + "TempFile", in_DestPath + "\\" + in_ZipFolderName + ".zip"); Directory.Delete(in_DestPath + "\\" + "TempFile", true); }
private void AddToProject(string filePath) { var proj = Microsoft.Build.Evaluation.ProjectCollection.GlobalProjectCollection.LoadedProjects.FirstOrDefault(pr => pr.FullPath == ProjectPath); if (proj is null) { proj = new Project(ProjectPath); } var projectName = Path.GetFileNameWithoutExtension(ProjectPath); var filePathToProject = DestinationPath?.Split(new string[] { projectName }, StringSplitOptions.None).Last() + "\\" + Path.GetFileName(filePath); if (filePathToProject.StartsWith("\\")) { filePathToProject = filePathToProject.Remove(0, 1); } if (proj.Items.FirstOrDefault(x => x.EvaluatedInclude == filePathToProject) is null) { proj.AddItem("Compile", filePathToProject); proj.Save(); } }
/// <inheritdoc /> public override int GetHashCode() { return(DestinationPath.GetHashCode()); // this should be a unique identifier }
protected void btnUpload_Click(object sender, EventArgs e) { MediaLibraryInfo mli = MediaLibraryInfoProvider.GetMediaLibraryInfo(LibraryID); if (!MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(mli, "manage")) { // Check 'File create' permission if (!MediaLibraryInfoProvider.IsUserAuthorizedPerLibrary(mli, "filecreate")) { RaiseOnNotAllowed("filecreate"); return; } } if (String.IsNullOrWhiteSpace(fileUploader.FileName) && !fileUploader.HasFile) { lblError.Text = GetString("media.selectfile"); lblError.Visible = true; return; } // Check if preview file is image if ((previewUploader.HasFile) && (!ImageHelper.IsImage(Path.GetExtension(previewUploader.FileName))) && (Path.GetExtension(previewUploader.FileName).ToLowerCSafe() != ".ico") && (Path.GetExtension(previewUploader.FileName).ToLowerCSafe() != ".tif") && (Path.GetExtension(previewUploader.FileName).ToLowerCSafe() != ".tiff") && (Path.GetExtension(previewUploader.FileName).ToLowerCSafe() != ".wmf")) { lblError.Text = GetString("Media.File.PreviewIsNotImage"); lblError.Visible = true; return; } // Check if the preview file with given extension is allowed for library module // Check if file with given extension is allowed for library module string fileExt = Path.GetExtension(fileUploader.FileName).TrimStart('.'); string previewFileExt = Path.GetExtension(previewUploader.FileName).TrimStart('.'); // Check file extension if (!MediaLibraryHelper.IsExtensionAllowed(fileExt)) { lblError.Text = String.Format(GetString("media.newfile.extensionnotallowed"), fileExt); lblError.Visible = true; return; } // Check preview extension if ((previewFileExt.Trim() != "") && !MediaLibraryHelper.IsExtensionAllowed(previewFileExt)) { lblError.Text = String.Format(GetString("media.newfile.extensionnotallowed"), previewFileExt); lblError.Visible = true; return; } if (mli != null) { try { // Create new Media file MediaFileInfo mfi = new MediaFileInfo(fileUploader.PostedFile, LibraryID, DestinationPath); // Save record to the database MediaFileInfoProvider.SetMediaFileInfo(mfi); // Save preview if presented if (previewUploader.HasFile) { // Get preview suffix if not set if (String.IsNullOrEmpty(PreviewSuffix)) { PreviewSuffix = MediaLibraryHelper.GetMediaFilePreviewSuffix(SiteContext.CurrentSiteName); } if (!String.IsNullOrEmpty(PreviewSuffix)) { // Get physical path within the media library String path; if ((DestinationPath != null) && DestinationPath.TrimEnd('/') != "") { path = DirectoryHelper.CombinePath(Path.EnsureBackslashes(DestinationPath, true), MediaLibraryHelper.GetMediaFileHiddenFolder(SiteContext.CurrentSiteName)); } else { path = MediaLibraryHelper.GetMediaFileHiddenFolder(SiteContext.CurrentSiteName); } string previewExtension = Path.GetExtension(previewUploader.PostedFile.FileName); string previewName = Path.GetFileNameWithoutExtension(MediaLibraryHelper.GetPreviewFileName(mfi.FileName, mfi.FileExtension, previewExtension, SiteContext.CurrentSiteName, PreviewSuffix)); // Save preview file MediaFileInfoProvider.SaveFileToDisk(SiteContext.CurrentSiteName, mli.LibraryFolder, path, previewName, previewExtension, mfi.FileGUID, previewUploader.PostedFile.InputStream, false); } } // Clear cache if (PortalContext.CurrentPageManager != null) { PortalContext.CurrentPageManager.ClearCache(); } // Display info to the user lblInfo.Text = GetString("media.fileuploaded"); lblInfo.Visible = true; if (OnAfterFileUpload != null) { OnAfterFileUpload(); } } catch (Exception ex) { lblError.Visible = true; lblError.Text = ex.Message; lblError.ToolTip = ex.StackTrace; } } }
////[MenuItem("Assets/Bundle/Reference Build")] //public static void ReferenceBuild() //{ // Regex MatchRegex = new Regex(@"\{\s*fileID\s*:\s*([0-9]+)\s*,\s*guid\s*:\s*([0-9a-f]+)\s*,\s*type\s*:\s*([0-9])\s*\}"); // Regex MatchFileIDRegex = new Regex(@"(?:fileID\s*:\s*)([0-9]+)"); // Regex MatchGUIDRegex = new Regex(@"(?:guid\s*:\s*)([0-9a-f]+)"); // Regex MatchTypeRegex = new Regex(@"(?:type\s*:\s*)([0-9])"); // Regex MatchClassIDAndFileIDInAssetRegex = new Regex(@"^(?:\s*---\s*!u!([0-9]+)\s*&([0-9]+)\s*)$"); // Regex MatchGUIDInMetaRegex = new Regex(@"^(?:\s*guid\s*:\s*([0-9a-f]+))$"); // Regex MatchAssetBundleName = new Regex(@"^(?:\s*assetBundleName\s*:\s*(\S*)\s*)$"); // Dictionary<string, Dictionary<long, string>> guid_fileID_extractPath_map = new Dictionary<string, Dictionary<long, string>>(); // Action command = null; // ExtractDefaultResources(); // Execute(); // void Execute() // { // try // { // UnityEngine.Object[][] objectGrops = FindObjectGrops(); // FindReference(objectGrops); // Task.Factory.StartNew(() => // { // LoadRecordedPaths(); // command?.Invoke(); // Debug.Log("Asset bundle build complete."); // }); // } // catch(Exception e) // { // Revert(); // Debug.Log("Asset bundle build faild."); // throw e; // } // } // void Revert() // { // } // UnityEngine.Object[][] FindObjectGrops() // { // ResetAllAssetBundleNames(); // string[] abNames = AssetDatabase.GetAllAssetBundleNames(); // List<UnityEngine.Object[]> objGrops = new List<UnityEngine.Object[]>(); // foreach (string abName in abNames) // { // string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundle(abName); // List<UnityEngine.Object> objGrop = new List<UnityEngine.Object>(); // foreach (string assetPath in assetPaths) // { // Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath); // objGrop.Add(AssetDatabase.LoadAssetAtPath(assetPath, assetType)); // } // objGrops.Add(objGrop.ToArray()); // } // return objGrops.ToArray(); // } // void FindReference(UnityEngine.Object[][] grops) // { // for(int i = 0; i < grops.Length; i++) // { // int gropId = i; // for(int j = 0; j < grops[i].Length; i++) // { // UnityEngine.Object obj = grops[i][j]; // Find(obj, gropId); // } // } // void Find(UnityEngine.Object obj, int gropId) // { // string assetPath = AssetDatabase.GetAssetPath(obj); // } // void GetObjectInfos(string assetPath) // { // string absAssetPath = Path.Combine(Environment.CurrentDirectory, assetPath); // //guid from .meta // string guid = GetGUID(assetPath); // //fileID from asset // } // } // bool IsYMALFile(string assetPath) // { // return true; // } // string GetGUID(string assetPath) // { // string absAssetPath = Path.Combine(Environment.CurrentDirectory, assetPath); // string metaPath = absAssetPath + ".meta"; // string[] lines = File.ReadAllLines(metaPath); // for (int i = 0; i < lines.Length; i++) // { // MatchCollection matches = MatchGUIDInMetaRegex.Matches(lines[i]); // if (matches.Count > 0) // { // GroupCollection groups = matches[0].Groups; // string value = groups[1].Value; // if (!string.IsNullOrWhiteSpace(value)) // { // return value; // } // } // } // return null; // } // string[] GetFileIDs(string assetPath) // { // string absAssetPath = Path.Combine(Environment.CurrentDirectory, assetPath); // string[] lines = File.ReadAllLines(absAssetPath); // for (int i = 0; i < lines.Length; i++) // { // MatchCollection matches = MatchClassIDAndFileIDInAssetRegex.Matches(lines[i]); // if (matches.Count > 0) // { // GroupCollection groups = matches[0].Groups; // //TODO // } // } // return null; // } // void SetAssetBunldeName(string assetPath, string assetBundleName) // { // string absAssetPath = Path.Combine(Environment.CurrentDirectory, assetPath); // string metaPath = absAssetPath + ".meta"; // string[] lines = File.ReadAllLines(metaPath); // for(int i = 0; i < lines.Length; i++) // { // if (MatchAssetBundleName.IsMatch(lines[i])) // { // lines[i] = " assetBundleName: " + assetBundleName; // } // } // } // string GetAssetBundleName(string assetPath) // { // string absAssetPath = Path.Combine(Environment.CurrentDirectory, assetPath); // string metaPath = absAssetPath + ".meta"; // string[] lines = File.ReadAllLines(metaPath); // for (int i = 0; i < lines.Length; i++) // { // MatchCollection matches = MatchAssetBundleName.Matches(lines[i]); // if (matches.Count > 0) // { // GroupCollection groups = matches[0].Groups; // string value = groups[1].Value; // if (!string.IsNullOrWhiteSpace(value)) // { // return value; // } // } // } // return null; // } // MatchedLine[] MatchFileText(string filePath) // { // List<MatchedLine> matchedLines = new List<MatchedLine>(); // string[] lines = File.ReadAllLines(filePath); // for (int i = 0; i < lines.Length; i++) // { // MatchCollection matches = MatchRegex.Matches(lines[i]); // if (matches.Count > 0) // { // GroupCollection groups = matches[0].Groups; // matchedLines.Add(new MatchedLine() // { // filePath = filePath, // lineIndex = i, // fileID = long.Parse(groups[1].Value), // guid = groups[2].Value, // type = int.Parse(groups[3].Value) // }); // } // } // return matchedLines.ToArray(); // } // void ReplaceWithNew(MatchedLine[] oris, long newFileID, string newGUID, int newType) // { // Dictionary<string, List<MatchedLine>> reorder = new Dictionary<string, List<MatchedLine>>(); // for (int i = 0; i < oris.Length; i++) // { // MatchedLine matchedLine = oris[i]; // if (!reorder.TryGetValue(matchedLine.filePath, out List<MatchedLine> matchLineList)) // { // reorder[matchedLine.filePath] = matchLineList = new List<MatchedLine>(); // } // matchLineList.Add(matchedLine); // } // foreach (KeyValuePair<string, List<MatchedLine>> kv in reorder) // { // string filePath = kv.Key; // List<MatchedLine> list = kv.Value; // string[] lines = File.ReadAllLines(filePath); // for (int i = 0; i < list.Count; i++) // { // MatchedLine matchedLine = list[i]; // string oriLine = lines[matchedLine.lineIndex]; // MatchFileIDRegex.Replace(oriLine, "fileID: " + newFileID.ToString()); // MatchGUIDRegex.Replace(oriLine, "guid: " + newGUID); // MatchTypeRegex.Replace(oriLine, "type: " + newType.ToString()); // } // command += () => // { // File.WriteAllLines(filePath, lines); // }; // } // } // void LoadRecordedPaths() // { // Regex KeyValueMatch = new Regex(@"^(?:\s*([\w]+(?:\s+\w+)*)\s*:\s*([\w]+(?:\s+\w+)*)\s*)$"); // string filePath = Path.Combine(Environment.CurrentDirectory, BuildinResourcesIDsPath); // if (File.Exists(filePath)) // { // string[] lines = File.ReadAllLines(filePath); // Dictionary<long, string> currGrop = null; // foreach (string line in lines) // { // MatchCollection matchCollection = KeyValueMatch.Matches(line); // if (matchCollection.Count > 0) // { // Match match = matchCollection[0]; // GroupCollection groups = match.Groups; // string key = groups[1].Value; // string value = groups[2].Value; // if (!string.IsNullOrWhiteSpace(key)) // { // if (string.IsNullOrWhiteSpace(value)) // { // currGrop = guid_fileID_extractPath_map[key] = new Dictionary<long, string>(); // } // else // { // currGrop[long.Parse(key)] = value; // } // } // } // } // } // else // { // throw new FileNotFoundException(BuildinResourcesIDsPath + " dosen't exist."); // } // } // string GetFormPathMap(string guid, long fileID) // { // if (guid_fileID_extractPath_map.TryGetValue(guid, out Dictionary<long, string> fileID_extractPath_map)) // { // if (fileID_extractPath_map.TryGetValue(fileID, out string value)) // { // return value; // } // } // return null; // } //} public static void ExtractDefaultResources() { Regex AssetsFolderMatch = new Regex(@"^(?:Asset[\\/]).*"); Regex FolderPathSplit = new Regex(@"\s*[\\/]+\s*"); Regex NameRegex = new Regex(@"[\s\\/]"); Dictionary <string, Dictionary <long, string> > guid_fileID_extractPath_map = new Dictionary <string, Dictionary <long, string> >(); if (Check()) { Execute(); } bool Check() { string targetPath = Path.Combine(Environment.CurrentDirectory, CopyResourcesFolderName, ResourcesFolderName); string buildinResourcesIDsPath = Path.Combine(Environment.CurrentDirectory, BuildinResourcesIDsPath); if (!CheckVersion() || !Directory.Exists(targetPath) || !File.Exists(buildinResourcesIDsPath)) { return(true); } return(false); } bool CheckVersion() { string key = "_unity_buildin_resources_version_"; if (PlayerPrefs.HasKey(key)) { string unityVersion = Application.unityVersion; if (PlayerPrefs.GetString(key).Equals(unityVersion)) { return(true); } } return(false); } void UpdateVersion() { string key = "_unity_buildin_resources_version_"; PlayerPrefs.SetString(key, Application.unityVersion); } void Execute() { try { Revert(); string[] resourcesGUIDs = GetResourcesGUIDs(); foreach (string guid in resourcesGUIDs) { string resourcesPath = AssetDatabase.GUIDToAssetPath(guid); UnityEngine.Object[] resources = AssetDatabase.LoadAllAssetsAtPath(resourcesPath); if (resources != null && resources.Length > 0) { RecordPath(resources); CopyToFolder(resources); } } CopyResourcesFolder(); SaveRecordedPaths(); UpdateVersion(); Debug.Log("Extract default resources complete."); } catch (Exception e) { Revert(); Debug.Log("Extract default resources faild."); throw e; } } void Revert() { string resourcesPath = Path.Combine(Environment.CurrentDirectory, ParentFolderName, ResourcesFolderName); string targetPath = Path.Combine(Environment.CurrentDirectory, CopyResourcesFolderName, ResourcesFolderName); string buildinResourcesIDsPath = Path.Combine(Environment.CurrentDirectory, BuildinResourcesIDsPath); if (Directory.Exists(targetPath)) { Directory.Delete(targetPath, true); } if (Directory.Exists(resourcesPath)) { AssetDatabase.DeleteAsset(Path.Combine(ParentFolderName, ResourcesFolderName)); } if (File.Exists(buildinResourcesIDsPath)) { File.Delete(buildinResourcesIDsPath); } } string[] GetResourcesGUIDs() { string[] filePaths = AssetDatabase.FindAssets("buildin_resources_guids"); if (filePaths.Length == 0) { return(new string[0]); } TextAsset resourcesGUIDsText = AssetDatabase.LoadAssetAtPath <TextAsset>(AssetDatabase.GUIDToAssetPath(filePaths[0])); if (resourcesGUIDsText == null) { Debug.LogError("buildin_resources_guids.txt not exist."); return(new string[0]); } string[] splitStrs = new Regex(@"\s+").Split(resourcesGUIDsText.text); List <string> resultStrs = new List <string>(); for (int i = 0; i < splitStrs.Length; i++) { if (!string.IsNullOrWhiteSpace(splitStrs[i])) { resultStrs.Add(splitStrs[i].Trim()); } } return(resultStrs.ToArray()); } void RecordPath(UnityEngine.Object[] resources) { for (int i = 0; i < resources.Length; i++) { UnityEngine.Object asset = resources[i]; Type assetType = asset.GetType(); if (assetType != typeof(MonoScript)) { if (AssetDatabase.TryGetGUIDAndLocalFileIdentifier(asset, out string guid, out long localID)) { string extractPath = Path.Combine(assetType.Name, ConvertName(asset.name)); AddToPathMap(guid, localID, extractPath); } } } } void CopyResourcesFolder() { string resourcesPath = Path.Combine(Environment.CurrentDirectory, ParentFolderName, ResourcesFolderName); string targetPath = Path.Combine(Environment.CurrentDirectory, CopyResourcesFolderName, ResourcesFolderName); if (Directory.Exists(targetPath)) { Directory.Delete(targetPath, true); } if (Directory.Exists(resourcesPath)) { CopyDirectory(resourcesPath, targetPath, true); AssetDatabase.DeleteAsset(Path.Combine(ParentFolderName, ResourcesFolderName)); } void CopyDirectory(string SourcePath, string DestinationPath, bool overwriteexisting) { try { SourcePath = SourcePath.EndsWith(@"\") ? SourcePath : SourcePath + @"\"; DestinationPath = DestinationPath.EndsWith(@"\") ? DestinationPath : DestinationPath + @"\"; if (Directory.Exists(SourcePath)) { if (!Directory.Exists(DestinationPath)) { Directory.CreateDirectory(DestinationPath); } foreach (string fls in Directory.GetFiles(SourcePath)) { FileInfo flinfo = new FileInfo(fls); flinfo.CopyTo(DestinationPath + flinfo.Name, overwriteexisting); } foreach (string drs in Directory.GetDirectories(SourcePath)) { DirectoryInfo drinfo = new DirectoryInfo(drs); CopyDirectory(drs, DestinationPath + drinfo.Name, overwriteexisting); } } } catch (IOException e) { throw e; } } } void SaveRecordedPaths() { if (guid_fileID_extractPath_map.Count > 0) { StringBuilder sb = new StringBuilder(); foreach (KeyValuePair <string, Dictionary <long, string> > kv in guid_fileID_extractPath_map) { sb.AppendLine(kv.Key + ":"); foreach (KeyValuePair <long, string> kvvkv in kv.Value) { sb.AppendLine(" " + kvvkv.Key + ": " + kvvkv.Value); } } string text = sb.ToString(); File.WriteAllText(Path.Combine(Environment.CurrentDirectory, BuildinResourcesIDsPath), text); } } void AddToPathMap(string guid, long fileID, string extractPath) { if (!guid_fileID_extractPath_map.TryGetValue(guid, out Dictionary <long, string> fileID_extractPath_map)) { guid_fileID_extractPath_map[guid] = fileID_extractPath_map = new Dictionary <long, string>(); } fileID_extractPath_map[fileID] = extractPath; } void CopyToFolder(UnityEngine.Object[] resources) { for (int i = 0; i < resources.Length; i++) { UnityEngine.Object asset = resources[i]; Type assetType = asset.GetType(); if (assetType != typeof(MonoScript)) { string folderPath = Path.Combine(ParentFolderName, ResourcesFolderName, assetType.Name); string filePath = Path.Combine(folderPath, ConvertName(asset.name) + ".asset"); string sysFilePath = Path.Combine(Environment.CurrentDirectory, filePath); if (File.Exists(sysFilePath)) { AssetDatabase.DeleteAsset(filePath); } CreateExtractFolder(folderPath); UnityEngine.Object clone = CloneAsset(asset, assetType); if (clone != null) { AssetDatabase.CreateAsset(clone, filePath); } } } AssetDatabase.SaveAssets(); EditorUtility.UnloadUnusedAssetsImmediate(); } void CreateExtractFolder(string folderPath) { if (AssetsFolderMatch.IsMatch(folderPath)) { string[] folders = FolderPathSplit.Split(folderPath); if (folders.Length > 0) { string parentPath = null; for (int i = 0; i < folders.Length; i++) { string folder = folders[i]; if (!string.IsNullOrWhiteSpace(folder)) { if (parentPath != null) { string currFolderPath = Path.Combine(parentPath, folder); if (!AssetDatabase.IsValidFolder(currFolderPath)) { AssetDatabase.CreateFolder(parentPath, folder); } parentPath = currFolderPath; } else { parentPath = folder; } } } } } else { folderPath = Path.Combine(Environment.CurrentDirectory, folderPath); if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } } } UnityEngine.Object CloneAsset(UnityEngine.Object asset, Type type) { UnityEngine.Object clone; if (type.BaseType == typeof(Texture)) { clone = CloneTexture(asset); } else { clone = UnityEngine.Object.Instantiate(asset); } clone.name = asset.name; return(clone); UnityEngine.Object CloneTexture(UnityEngine.Object obj) { SerializedObject serializedObject = new SerializedObject(obj); serializedObject.Update(); SerializedProperty isReadableProperty = serializedObject.FindProperty("m_IsReadable"); bool isReadable = isReadableProperty.boolValue; isReadableProperty.boolValue = true; serializedObject.ApplyModifiedProperties(); serializedObject.Dispose(); UnityEngine.Object obj0 = UnityEngine.Object.Instantiate(obj); SerializedObject serializedClone = new SerializedObject(obj0); serializedClone.Update(); serializedClone.FindProperty("m_IsReadable").boolValue = isReadable; serializedClone.ApplyModifiedProperties(); serializedClone.Dispose(); return(obj0); } } string ConvertName(string name) { return(NameRegex.Replace(name, "_")); } }
public override bool Execute() { bool success = false; try { Log.LogMessage("Stitch Task"); var json = File.ReadAllText(JsonConfig).Replace("$(ProjectDir)", RootPath.Replace("\\", "\\\\")).Replace("$(OutDir)", DestinationPath.Replace("\\", "\\\\")); Log.LogMessage($"Stitch Task with following Config: {json}"); Stitcher.Stitch.UsingJsonConfig(json).Sew(); success = true; } catch (Exception ex) { Log.LogError(ex.ToString()); } finally { Log.LogMessage("End Stitch Task"); } return(success); }
void JunctionQueryCompleted(object sender, BatchRunner.TaskCompletedEventArgs e) { string dateTail = DateTime.Now.ToString("_yyyy-MM-dd HH-mm-ss"); List <Junction> junctions = new List <Junction>(); Regex junctionRegex = new Regex(@"<JUNCTION>\s*([^[]*)\[([^]]*)]"); string dir = null; foreach (string line in e.Output) { if (line.StartsWith(" Directory of ")) { dir = line.Substring(14); } else if (line.Contains("<JUNCTION>")) { Match M = junctionRegex.Match(line); junctions.Add(new Junction(dir + "\\" + M.Groups[1].Value.TrimEnd(), M.Groups[2].Value)); } } foreach (Junction J in junctions) { try { DirectoryInfo DI = new DirectoryInfo(J.Source); J.Hidden = DI.Attributes.HasFlag(FileAttributes.Hidden); } catch { } } BatchRunner mover = new BatchRunner(Path + "\\MoveJunctions" + dateTail + ".bat", Path + "\\MoveLog.txt", CodePage); BatchRunner recovery = new BatchRunner(Path + "\\RecoverJunctions" + dateTail + ".bat", null, CodePage); BatchRunner finalizer = new BatchRunner(Path + "\\FinalizeJunctions" + dateTail + ".bat", null, CodePage); mover.Echo("Moving directories..."); string[] destDirs = new string[Directories.Count]; int i = 0; foreach (string d in Directories) { destDirs[i] = DestinationPath + d.Substring(3); mover.AddCommand("robocopy \"" + d + "\" \"" + destDirs[i] + "\" /MIR /XJ /COPYALL /ZB"); i++; } mover.Echo("Renaming directories..."); bool hidden, system; foreach (string d in Directories) { hidden = false; system = false; try { DirectoryInfo DI = new DirectoryInfo(d); hidden = DI.Attributes.HasFlag(FileAttributes.Hidden); system = DI.Attributes.HasFlag(FileAttributes.System); } catch { } if (system || hidden) { mover.AddCommand("attrib " + (system ? "-S " : "") + (hidden ? "-H " : "") + "\"" + d + "\"", true); recovery.AddCommand("attrib " + (system ? "-S " : "") + (hidden ? "-H " : "") + "\"" + d + "\""); } mover.AddCommand("rename \"" + d + "\" \"" + d.Substring(d.LastIndexOf('\\') + 1) + RenameTail + "\"", true); mover.AddCommand("attrib +H \"" + d + RenameTail + "\"", true); recovery.AddCommand("attrib -H \"" + d + RenameTail + "\""); recovery.AddCommand("rmdir \"" + d + "\" /Q"); recovery.AddCommand("rename \"" + d + RenameTail + "\" \"" + d.Substring(d.LastIndexOf('\\') + 1) + "\"", true); if (hidden || system) { recovery.AddCommand("attrib " + (system ? "+S " : "") + (hidden ? "+H " : "") + "\"" + d + "\""); } finalizer.AddCommand("attrib -H \"" + SourceVolumeOnTargetOS + d.Substring(1) + RenameTail + "\""); finalizer.AddCommand("rmdir \"" + SourceVolumeOnTargetOS + d.Substring(1) + RenameTail + "\" /S /Q"); } recovery.FinalizeFile(); finalizer.FinalizeFile(); string destinationPathForTargetOS = DestinationVolumeOnTargetOS + DestinationPath.Substring(1); mover.Echo("Making softlinks..."); foreach (string d in Directories) { mover.AddCommand("mklink /J \"" + d + "\" \"" + destinationPathForTargetOS + d.Substring(3) + "\"", true); hidden = false; system = false; try { DirectoryInfo DI = new DirectoryInfo(d); hidden = DI.Attributes.HasFlag(FileAttributes.Hidden); system = DI.Attributes.HasFlag(FileAttributes.System); if (system || hidden) { mover.AddCommand("attrib " + (system ? "+S " : "") + (hidden ? "+H " : "") + "\"" + d + "\" /L", true); } } catch { } } mover.Echo("Making junctions..."); foreach (Junction j in junctions) { string source = DestinationPath + j.Source.Substring(3); string target = j.Target; mover.AddCommand("mklink /J \"" + source + "\" \"" + target + "\"", true); if (j.Hidden) { mover.AddCommand("attrib +H \"" + source + "\"", true); } } mover.TaskCompleted += mover_TaskCompleted; if (Execute) { mover.Run(); } else { mover.FinalizeFile(); } }