public static List <string> DirectoriesPathList(List <PUManager.AssetPath> paths) { List <string> possibleDirs = new List <string>(); List <TreeView.NodePath> files = new List <TreeView.NodePath>(); paths.ForEach( (p) => { var ph = TreeView.PathHierarchy(p.filePath); foreach (var item in ph) { if (!possibleDirs.Exists((d) => d.Equals(item.path, System.StringComparison.OrdinalIgnoreCase)) && !item.path.Equals(p.filePath, System.StringComparison.OrdinalIgnoreCase)) { possibleDirs.Add(item.path); } } files.Add(new TreeView.NodePath() { name = p.name, isDirectory = false, path = p.filePath }); } ); return(possibleDirs); }
private int RemoveFiles(List <TreeNode> filelist) { float step = .5f / filelist.Count; float progress = .5f + step; var dirs = new List <string>(); int deleted = 0; string appPath = Application.dataPath.Substring(0, Application.dataPath.LastIndexOf(@"Assets")); GC.Collect(); GC.WaitForPendingFinalizers(); foreach (var f in filelist) { EditorUtility.DisplayProgressBar("Uninstalling Package", string.Format("Removing {0}", f.name), progress); progress += step; try { string fullPath = Path.Combine(appPath, f.path); var phList = TreeView.PathHierarchy(f.path); phList.ForEach((ph) => { if (!dirs.Exists(d => d.Equals(ph.path, StringComparison.OrdinalIgnoreCase))) { dirs.Add(ph.path); } }); if (File.Exists(fullPath)) { File.Delete(fullPath); deleted++; } } catch (Exception ex) { Debug.LogError(ex.Message); } finally { try { //deleting meta file string fullPath = Path.Combine(appPath, f.path); var meta = fullPath + ".meta"; if (File.Exists(meta)) { File.Delete(meta); } GC.Collect(); GC.WaitForPendingFinalizers(); } catch { } } } dirs = dirs.OrderByDescending(i => i.Count(x => x == '/')).ToList(); foreach (var item in dirs) { var fullpath = Path.Combine(appPath, item); try { //deleted += (AssetDatabase.DeleteAsset(item) ? 1 : 0); if (Directory.Exists(fullpath)) { if (Directory.GetFiles(fullpath).Length <= 0) { Directory.Delete(fullpath); deleted++; } } } catch (Exception ex) { Debug.LogError(ex.Message); } finally { try { var meta = fullpath + ".meta"; if (File.Exists(meta)) { File.Delete(meta); } } catch { } } } AssetDatabase.Refresh(); return(deleted); }