private void DrawStatsBody() { using (new GUILayout.HorizontalScope(UIHelpers.panelWithBackground)) { GUILayout.Space(10); using (new GUILayout.VerticalScope()) { GUILayout.Space(5); if (resultsStats == null) { GUILayout.Label("N/A"); } else { GUILayout.Space(5); GUILayout.Label("Physical size"); UIHelpers.Separator(); GUILayout.Label("Total found: " + CSEditorTools.FormatBytes(resultsStats.totalSize)); GUILayout.Label("Selected: " + CSEditorTools.FormatBytes(resultsStats.selectedSize)); } GUILayout.Space(5); } GUILayout.Space(10); } }
/// <summary> /// Starts garbage search, cleans what was found with optional confirmation and /// generates report to let you know what were cleaned up. /// </summary> /// <param name="showConfirmation">Enables or disables confirmation dialog about cleaning up found stuff.</param> /// <returns>Project Cleaner report about removed items.</returns> /// %Maintainer window is not shown. /// <br/>Useful when you wish to integrate %Maintainer in your build pipeline. public static string SearchAndCleanAndReport(bool showConfirmation = true) { var foundGarbage = StartSearch(false); var cleanedGarbage = StartClean(foundGarbage, false, showConfirmation); var header = "Total cleaned bytes: " + CSEditorTools.FormatBytes(cleanedBytes); header += "\nFollowing items were cleaned up:"; // ReSharper disable once CoVariantArrayConversion return(ReportsBuilder.GenerateReport(ModuleName, cleanedGarbage, header)); }
protected override void ConstructBody(StringBuilder text) { text.Append("<b>Path:</b> ").Append(beautyPath); if (size > 0) { text.AppendLine().Append("<b>Size:</b> ").Append(CSEditorTools.FormatBytes(size)); } if (type == RecordType.UnreferencedAsset) { text.AppendLine().Append("<b>Full Type:</b> ").Append(assetType.FullName); } }
/// <summary> /// Starts clean of the garbage found with StartSearch() method. /// </summary> /// <param name="recordsToClean">Pass records you wish to clean here or leave null to let it load last search results.</param> /// <param name="showResults">Shows results in the %Maintainer window if true.</param> /// <param name="showConfirmation">Shows confirmation dialog before performing cleanup if true.</param> /// <returns>Array of CleanRecords which were cleaned up.</returns> public static CleanerRecord[] StartClean(CleanerRecord[] recordsToClean = null, bool showResults = true, bool showConfirmation = true) { var records = recordsToClean; if (records == null) { records = SearchResultsStorage.CleanerSearchResults; } if (records.Length == 0) { return(null); } cleanedBytes = 0; itemsToClean = 0; foreach (var record in records) { if (record.selected) { itemsToClean++; } } if (itemsToClean == 0) { EditorUtility.DisplayDialog(ModuleName, "Please select items to clean up!", "Ok"); return(null); } if (!showConfirmation || itemsToClean == 1 || EditorUtility.DisplayDialog("Confirmation", "Do you really wish to delete " + itemsToClean + " items?\n" + Maintainer.DataLossWarning, "Go for it!", "Cancel")) { var sw = System.Diagnostics.Stopwatch.StartNew(); var cleanCanceled = CleanRecords(records); var cleanedRecords = new List <CleanerRecord>(records.Length); var notCleanedRecords = new List <CleanerRecord>(records.Length); foreach (var record in records) { if (record.cleaned) { cleanedRecords.Add(record); } else { notCleanedRecords.Add(record); } } records = notCleanedRecords.ToArray(); sw.Stop(); EditorUtility.ClearProgressBar(); if (!cleanCanceled) { Debug.Log(Maintainer.LogPrefix + ModuleName + " results: " + cleanedRecords.Count + " items (" + CSEditorTools.FormatBytes(cleanedBytes) + " in size) cleaned in " + sw.Elapsed.TotalSeconds.ToString("0.000") + " seconds."); } else { Debug.Log(Maintainer.LogPrefix + "Deletion was canceled by user!"); } SearchResultsStorage.CleanerSearchResults = records; if (showResults) { MaintainerWindow.ShowCleaner(); } return(cleanedRecords.ToArray()); } return(null); }
protected override string GetReportHeader() { return(resultsStats != null ? "Total found garbage size: " + CSEditorTools.FormatBytes(resultsStats.totalSize) : null); }
public static ReferencesTreeElement BuildTreeBranch(AssetInfo referencedAsset, int depth, int id, List <ReferencesTreeElement> results) { // excludes assets without references if necessary and excludes assets which were ignored if (AssetIsFilteredOut(referencedAsset, depth)) { return(null); } var assetPath = referencedAsset.Path; var assetType = referencedAsset.Type; string assetTypeName; if (referencedAsset.SettingsKind == AssetSettingsKind.NotSettings) { assetTypeName = assetType != null && !string.IsNullOrEmpty(assetType.Name) ? assetType.Name : "Unknown type"; } else { assetTypeName = "Settings Asset"; } var element = new ReferencesTreeElement { id = id + results.Count, name = CSPathTools.NicifyAssetPath(referencedAsset.Path, referencedAsset.Kind), assetPath = assetPath, assetTypeName = assetTypeName, assetSize = referencedAsset.Size, assetSizeFormatted = CSEditorTools.FormatBytes(referencedAsset.Size), assetIsTexture = assetType != null && (assetType.BaseType == CSReflectionTools.textureType), assetSettingsKind = referencedAsset.SettingsKind, isReferenced = referencedAsset.referencedAtInfoList != null && referencedAsset.referencedAtInfoList.Length > 0, depth = depth }; results.Add(element); var recursionId = CheckParentsForRecursion(element, results); if (recursionId > -1) { element.name += " [RECURSION]"; element.recursionId = recursionId; return(element); } if (referencedAsset.referencedAtInfoList.Length > 0) { foreach (var referencedAtInfo in referencedAsset.referencedAtInfoList) { //if (CSFilterTools.IsValueMatchesAnyFilter(referencedAtInfo.assetInfo.Path, MaintainerSettings.References.pathIgnoresFilters)) continue; if (referencedAtInfo.assetInfo.Kind == AssetKind.FromPackage) { continue; } var newDepth = depth + 1; if (newDepth > 1) { continue; } var childElement = BuildTreeBranch(referencedAtInfo.assetInfo, newDepth, id, results); if (childElement == null) { continue; } var referencedAtType = referencedAtInfo.assetInfo.Type; if (referencedAtType == CSReflectionTools.gameObjectType || referencedAtType == CSReflectionTools.sceneAssetType || referencedAtType == CSReflectionTools.monoScriptType || referencedAtType == CSReflectionTools.monoBehaviourType || referencedAtType != null && referencedAtType.BaseType == CSReflectionTools.scriptableObjectType) { if (referencedAtInfo.entries != null) { childElement.referencingEntries = referencedAtInfo.entries; } else { var collectedData = ReferencesFinder.ConjunctionInfoList.FirstOrDefault(d => d.asset == referencedAtInfo.assetInfo); if (collectedData == null) { collectedData = new AssetConjunctions(); ReferencesFinder.ConjunctionInfoList.Add(collectedData); collectedData.asset = referencedAtInfo.assetInfo; } var tc = collectedData.conjunctions.FirstOrDefault(c => c.referencedAsset == referencedAsset); if (tc == null) { tc = new TreeConjunction { referencedAsset = referencedAsset, referencedAtInfo = referencedAtInfo }; collectedData.conjunctions.Add(tc); } tc.treeElements.Add(childElement); } } } } return(element); }