/// <summary> /// Checks if the given folder path is in the convention. /// </summary> /// <param name="path">The folder path to be evaluated.</param> /// <returns>Returns the state of the given folder.</returns> public static FolderConventionState CheckFolderConvention(string path) { FolderConventionState result = FolderConventionState.NotValid; if (CheckIgnoreFolder(path)) { result = FolderConventionState.Ignored; } else if (CheckFolderIsValidChild(path)) { result = FolderConventionState.Valid; } else { result = FolderConventionState.NotValid; } return(result); }
/// <summary> /// Checks if the folder path follows the convention /// </summary> /// <param name="file">The file that needs to be processed</param> /// <returns>The state of the folder based on the convention</returns> public static FolderConventionState CheckFolderConvention(FileData file) { FolderConventionState result = FolderConventionState.NotValid; if (CheckIgnoreFolder(file.folderAssetsPath)) { result = FolderConventionState.Ignored; } else if (CheckFolderIsValidChild(file.folderAssetsPath)) { result = FolderConventionState.Valid; } else { result = FolderConventionState.NotValid; } return(result); }
/// <summary> /// Streamiline the evaluation process for the imported files /// </summary> /// <param name="filePath">the path of the file to be evaluated</param> /// <returns>The state of the given file</returns> public static FileConventionState CheckImportFileConvention(string filePath) { FileData file = new FileData(filePath); FolderConventionState folderState = CheckFolderConvention(file); FileConventionState fileState = FileConventionState.NotValid; switch (folderState) { case FolderConventionState.Valid: fileState = CheckFileConvention(file); break; case FolderConventionState.NotValid: fileState = FileConventionState.NotValid; break; } //Show warnings if any if (folderState == FolderConventionState.NotValid) { NotValidFolderDialog(file.folderAssetsPath); } else if (folderState == FolderConventionState.Valid && fileState == FileConventionState.NotValid) { switch (fileState) { case FileConventionState.WrongFileName: FileNameChangeDialog(file); break; case FileConventionState.NotValid: DialogNoValidFile(file); break; } } return(fileState); }
/// <summary> /// Recursively checks the conventions in folders and files /// </summary> /// <param name="path"></param> public static bool ProcessSubFolders(string path) { bool stopProcess = false; FolderConventionState folderState = CheckFolderConvention(path); switch (folderState) { case FolderConventionState.Ignored: //Do nothing, ignore them :) break; case FolderConventionState.Valid: List <string> allowedFileTypes = GetAllTypesOfPath(path); List <FileData> assetList = GetAllFileDataAtPath(path); if (allowedFileTypes != null && assetList.Count > 0) { string localErrorMessage = string.Empty; foreach (FileData asset in assetList) { FileConventionState conventionState = CheckFileConvention(asset); switch (conventionState) { case FileConventionState.WrongFileName: FileNameChangeDialog(asset); break; case FileConventionState.NotValid: DialogNoValidFile(asset); break; } if (conventionState == FileConventionState.WrongFileName || conventionState == FileConventionState.NotValid) { stopProcess = true; } } } else if (allowedFileTypes == null && assetList.Count > 0) { Dialog("The path \"" + path + "\" has FILES which the TYPE IS NOT in the Convention, what to do?", new List <ButtonData>() { new ButtonData("Add FILE TYPES to this path Convention", delegate() { AddFileTypesToPath(path, assetList); }), new ButtonData("Delete wrong FILES", delegate() { //Delete files that are not in the allowed file types list DeleteDialog(delegate() { foreach (FileData asset in assetList) { AssetDatabase.DeleteAsset(asset.assetsFullPath); } AssetDatabase.Refresh(); RecheckConventionDialog(); }); }), new ButtonData("Do nothing right now", delegate() { //Do nothing - Highlight the parent folder just so the user can check it if wants EditorGUIUtility.PingObject(AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(path)); }) }); stopProcess = true; } //Check sub folders if allowed if (allowedFileTypes == null) //There is no aloowed type in the folder { return(false); } List <string> subFolders = new List <string>(AssetDatabase.GetSubFolders(path)); if (allowedFileTypes.Contains("folder")) { for (int i = 0; i < subFolders.Count; i++) { if (ProcessSubFolders(subFolders[i])) //If returns 1, means we need to stop the processing as the validation process might changed { break; } } } else { if (subFolders.Count > 0) { Dialog("The path \"" + path + "\" does not allow FOLDERS and it contains " + subFolders.Count + " folders, what to do?", new List <ButtonData>() { new ButtonData("Add FOLDERS permission to this path", delegate() { AddFolderTypeToPath(path); }), new ButtonData("Delete child FOLDERS", delegate() { //Delete the list of sub folders DeleteDialog(delegate() { foreach (string folder in subFolders) { AssetDatabase.DeleteAsset(folder); } AssetDatabase.Refresh(); RecheckConventionDialog(); }); }), new ButtonData("Do nothing right now", delegate() { //Do nothing - Highlight the parent folder just so the user can check it if wants EditorGUIUtility.PingObject(AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(path)); }) }); stopProcess = true; } } break; case FolderConventionState.NotValid: NotValidFolderDialog(path); stopProcess = true; break; } return(stopProcess); }
/// <summary> /// Processes all folders under the given path seeking convention breaches. /// </summary> /// <param name="path">The path to process to use results on Overview Window</param> public static void OverviewProcessFolder(string path) { JSONObject pathConfig = config["folderStructure"]["check"]["folders"].list.Find(x => x["path"].str == path); List <JSONObject> allowedFileTypes = (pathConfig != null) ? pathConfig["fileTypesAllowed"].list : null; List <FileData> assetList = GetAllFileDataAtPath(path); FolderConventionState folderState = CheckFolderConvention(path); if (folderState != FolderConventionState.Ignored) { FileData folderData = new FileData(path); if (folderState == FolderConventionState.NotValid) { folderData.folderError.Add(FolderConventionState.NotValid); } List <string> subFolders = new List <string>(AssetDatabase.GetSubFolders(path)); if (subFolders.Count > 0) { folderData.folderError.Add(FolderConventionState.NoFoldersAllowed); for (int i = 0; i < subFolders.Count; i++) { OverviewProcessFolder(subFolders[i]); } } if (allowedFileTypes == null && assetList.Count > 0) { folderData.folderError.Add(FolderConventionState.UnknownFiles); } if (folderState != FolderConventionState.Ignored && folderState != FolderConventionState.Valid) { overviewFolderList.Add(folderData); } //Process Files if (assetList.Count > 0) { foreach (FileData asset in assetList) { FileConventionState conventionState = CheckFileConvention(asset); switch (conventionState) { case FileConventionState.WrongFileName: asset.fileError.Add(FileConventionState.WrongFileName); overviewFileList.Add(asset); break; case FileConventionState.NotValid: asset.fileError.Add(FileConventionState.NotValid); overviewFileList.Add(asset); break; } } } } }