BRT_BuildReportWindow.InitiateDeleteAllUnused C# (CSharp) Method

InitiateDeleteAllUnused() private method

private InitiateDeleteAllUnused ( ) : void
return void
    void InitiateDeleteAllUnused()
    {
        BuildReportTool.AssetList list = _buildInfo.UnusedAssets;
        BuildReportTool.SizePart[] all = list.All;

        int filesToDeleteCount = 0;

        for (int n = 0, len = all.Length; n < len; ++n)
        {
            BuildReportTool.SizePart b = all[n];

            bool okToDelete = BuildReportTool.Util.IsFileOkForDeleteAllOperation(b.Name);

            if (okToDelete)
            {
                //Debug.Log("added " + b.Name + " for deletion");
                ++filesToDeleteCount;
            }
        }

        if (filesToDeleteCount == 0)
        {
            const string nothingToDelete = "Take note that for safety, Build Report Tool assets, Unity editor assets, version control metadata, and Unix-style hidden files will not be included for deletion.\n\nYou can force deleting them by selecting them (via the checkbox) and using \"Delete selected\", or simply delete them the normal way in your project view.";

            EditorApplication.Beep();
            EditorUtility.DisplayDialog("Nothing to delete!", nothingToDelete, "Ok");
            return;
        }

        string plural = "";
        if (filesToDeleteCount > 1)
        {
            plural = "s";
        }

        EditorApplication.Beep();
        if (!EditorUtility.DisplayDialog("Delete?",
                "Among " + all.Length + " file" + plural + " in your project, " + filesToDeleteCount + " will be deleted.\n\nBuild Report Tool assets themselves, Unity editor assets, version control metadata, and Unix-style hidden files will not be included for deletion. You can force-delete those by selecting them (via the checkbox) and use \"Delete selected\", or simply delete them the normal way in your project view.\n\nDeleting a large number of files may take a long time as Unity will rebuild the project's Library folder.\n\nAre you sure about this?\n\nThe file" + plural + " can be recovered from your " + BuildReportTool.Util.NameOfOSTrashFolder + ".", "Yes", "No"))
        {
            return;
        }

        List<BuildReportTool.SizePart> newAll = new List<BuildReportTool.SizePart>();

        int deletedCount = 0;
        for (int n = 0, len = all.Length; n < len; ++n)
        {
            BuildReportTool.SizePart b = all[n];

            bool okToDelete = BuildReportTool.Util.IsFileOkForDeleteAllOperation(b.Name);

            if (okToDelete)
            {
                // delete this
                if (BuildReportTool.Util.ShowFileDeleteProgress(deletedCount, filesToDeleteCount, b.Name, true))
                {
                    return;
                }

                BuildReportTool.Util.DeleteSizePartFile(b);
                ++deletedCount;
            }
            else
            {
                //Debug.Log("added " + b.Name + " to new list");
                newAll.Add(b);
            }
        }
        EditorUtility.ClearProgressBar();

        BuildReportTool.SizePart[] newAllArr = newAll.ToArray();

        BuildReportTool.SizePart[][] perCategoryUnused = BuildReportTool.ReportManager.SegregateAssetSizesPerCategory(newAllArr, _buildInfo.FileFilters);

        list.Reinit(newAllArr, perCategoryUnused);
        list.ClearSelection();

        string finalMessage = filesToDeleteCount + " file" + plural + " removed from your project. They can be recovered from your " + BuildReportTool.Util.NameOfOSTrashFolder + ".";
        Debug.LogWarning(finalMessage);

        EditorApplication.Beep();
        EditorUtility.DisplayDialog("Delete successful", finalMessage, "OK");
    }