Beispiel #1
0
        private static void AutoCleanFolders()
        {
            if (!MaintainerSettings.Cleaner.findEmptyFolders || !MaintainerSettings.Cleaner.findEmptyFoldersAutomatically)
            {
                return;
            }

            var results = new List <CleanerRecord>();

            ScanFolders(results, false);

            if (results.Count > 0)
            {
                var result = EditorUtility.DisplayDialogComplex("Maintainer", ModuleName + " found " + results.Count + " empty folders. Do you wish to remove them?\n" + Maintainer.DataLossWarning, "Yes", "No", "Show in Maintainer");
                if (result == 0)
                {
                    var records = results.ToArray();
                    CleanRecords(records, false);
                    Debug.Log(Maintainer.LogPrefix + results.Count + " empty folders cleaned.");
                }
                else if (result == 2)
                {
                    SearchResultsStorage.CleanerSearchResults = results.ToArray();
                    MaintainerWindow.ShowCleaner();
                }
            }
        }
Beispiel #2
0
        private static void AutoCleanFolders()
        {
            if (!MaintainerSettings.Cleaner.findEmptyFolders || !MaintainerSettings.Cleaner.findEmptyFoldersAutomatically)
            {
                return;
            }

            List <CleanerRecord> results = new List <CleanerRecord>();

            ScanFolders(results, false);

            if (results.Count > 0)
            {
                int result = EditorUtility.DisplayDialogComplex("Maintainer", MODULE_NAME + " found " + results.Count + " empty folders. Do you wish to remove them?\n" + DATA_LOSS_WARNING, "Yes", "No", "Show in Maintainer");
                if (result == 0)
                {
                    CleanerRecord[] records = results.ToArray();
                    CleanRecords(records, false);
                    Debug.Log(Maintainer.LOG_PREFIX + results.Count + " empty folders cleaned.");
                }
                else if (result == 2)
                {
                    SearchResultsStorage.CleanerSearchResults = results.ToArray();
                    MaintainerWindow.ShowCleaner();
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Starts garbage search with current settings.
        /// </summary>
        /// <param name="showResults">Shows results in %Maintainer window if true.</param>
        /// <returns>Array of CleanerRecords in case you wish to manually iterate over them and make custom report.</returns>
        public static CleanerRecord[] StartSearch(bool showResults)
        {
            var results = new List <CleanerRecord>();

            phasesCount  = 0;
            currentPhase = 0;

            if (MaintainerSettings.Cleaner.findEmptyFolders)
            {
                phasesCount++;
            }
            if (MaintainerSettings.Cleaner.findUnreferencedAssets)
            {
                phasesCount++;
            }

            var searchCanceled = !CSSceneTools.SaveCurrentModifiedScenes(true);

            if (searchCanceled)
            {
                Debug.Log(Maintainer.LogPrefix + "Search canceled by user!");
                return(null);
            }

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);

            try
            {
                var sw = System.Diagnostics.Stopwatch.StartNew();

                CSEditorTools.lastRevealSceneOpenResult = null;

                if (MaintainerSettings.Cleaner.findEmptyFolders)
                {
                    searchCanceled = ScanFolders(results);
                }

                if (!searchCanceled && MaintainerSettings.Cleaner.findUnreferencedAssets)
                {
                    searchCanceled = ScanProjectFiles(results);
                }

                sw.Stop();

                EditorUtility.ClearProgressBar();

                if (!searchCanceled)
                {
                    Debug.Log(Maintainer.LogPrefix + ModuleName + " results: " + results.Count +
                              " items found in " + sw.Elapsed.TotalSeconds.ToString("0.000") +
                              " seconds.");
                }
                else
                {
                    Debug.Log(Maintainer.LogPrefix + "Search canceled by user!");
                }
            }
            catch (Exception e)
            {
                Debug.Log(Maintainer.LogPrefix + e);
                EditorUtility.ClearProgressBar();
            }

            SearchResultsStorage.CleanerSearchResults = results.ToArray();
            if (showResults)
            {
                MaintainerWindow.ShowCleaner();
            }

            return(results.ToArray());
        }
Beispiel #4
0
        /// <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);
        }
Beispiel #5
0
        /// <summary>
        /// Starts garbage search with current settings.
        /// </summary>
        /// <param name="showResults">Shows results in %Maintainer window if true.</param>
        /// <returns>Array of CleanerRecords in case you wish to manually iterate over them and make custom report.</returns>
        public static CleanerRecord[] StartSearch(bool showResults)
        {
            List <CleanerRecord> results = new List <CleanerRecord>();

            phasesCount  = 0;
            currentPhase = 0;

            if (MaintainerSettings.Cleaner.findEmptyFolders)
            {
                phasesCount++;
            }
            if (MaintainerSettings.Cleaner.findEmptyScenes)
            {
                if (!CSSceneTools.SaveCurrentSceneIfUserWantsTo())
                {
                    Debug.Log(Maintainer.LOG_PREFIX + "Search canceled by user!");
                    return(null);
                }
                phasesCount++;
                searchStartScene = CSSceneTools.GetCurrentScenePath(true);
            }

            Stopwatch sw = Stopwatch.StartNew();

            bool searchCanceled = false;

            if (MaintainerSettings.Cleaner.findEmptyFolders)
            {
                searchCanceled = !ScanFolders(results);
            }

            if (MaintainerSettings.Cleaner.findEmptyScenes)
            {
                searchCanceled = !ScanSceneFiles(results);
            }

            sw.Stop();

            // opening scene where we started scan
            if (MaintainerSettings.Cleaner.findEmptyScenes)
            {
                if (string.IsNullOrEmpty(searchStartScene))
                {
                    CSSceneTools.NewScene();
                }
                else if (CSSceneTools.GetCurrentScenePath() != searchStartScene)
                {
                    CSSceneTools.OpenScene(searchStartScene);
                }
            }
            EditorUtility.ClearProgressBar();

            if (!searchCanceled)
            {
                Debug.Log(Maintainer.LOG_PREFIX + MODULE_NAME + " results: " + results.Count +
                          " items found in " + sw.Elapsed.TotalSeconds.ToString("0.000") +
                          " seconds.");
            }
            else
            {
                Debug.Log(Maintainer.LOG_PREFIX + "Search canceled by user!");
            }

            SearchResultsStorage.CleanerSearchResults = results.ToArray();
            if (showResults)
            {
                MaintainerWindow.ShowCleaner();
            }

            return(results.ToArray());
        }
Beispiel #6
0
        /// <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)
        {
            CleanerRecord[] records = recordsToClean;
            if (records == null)
            {
                records = SearchResultsStorage.CleanerSearchResults;
            }

            if (records.Length == 0)
            {
                return(null);
            }

            itemsToClean = 0;

            foreach (CleanerRecord record in records)
            {
                if (record.selected)
                {
                    itemsToClean++;
                }
            }

            if (itemsToClean == 0)
            {
                EditorUtility.DisplayDialog(MODULE_NAME, "Please select items to clean up!", "Ok");
                return(null);
            }

            if (!showConfirmation || EditorUtility.DisplayDialog("Confirmation", "Do you really wish to delete " + itemsToClean + " items?\n" + DATA_LOSS_WARNING, "Go for it!", "Cancel"))
            {
                Stopwatch sw = Stopwatch.StartNew();

                bool cleanCanceled = CleanRecords(records);

                List <CleanerRecord> cleanedRecords    = new List <CleanerRecord>(records.Length);
                List <CleanerRecord> notCleanedRecords = new List <CleanerRecord>(records.Length);

                foreach (CleanerRecord 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.LOG_PREFIX + MODULE_NAME + " results: " + itemsToClean +
                              " items cleaned in " + sw.Elapsed.TotalSeconds.ToString("0.000") +
                              " seconds.");
                }
                else
                {
                    Debug.Log(Maintainer.LOG_PREFIX + "Clean canceled by user!");
                }

                SearchResultsStorage.CleanerSearchResults = records;
                if (showResults)
                {
                    MaintainerWindow.ShowCleaner();
                }

                return(cleanedRecords.ToArray());
            }

            return(null);
        }
Beispiel #7
0
        /// <summary>
        /// Starts garbage search with current settings.
        /// </summary>
        /// <param name="showResults">Shows results in %Maintainer window if true.</param>
        /// <returns>Array of CleanerRecords in case you wish to manually iterate over them and make custom report.</returns>
        public static CleanerRecord[] StartSearch(bool showResults)
        {
            List <CleanerRecord> results = new List <CleanerRecord>();

            phasesCount  = 0;
            currentPhase = 0;

            if (MaintainerSettings.Cleaner.findEmptyFolders)
            {
                phasesCount++;
            }
            if (MaintainerSettings.Cleaner.findUnusedAssets)
            {
                phasesCount++;
            }

            bool searchCanceled = false;

            AssetDatabase.SaveAssets();

            try
            {
                Stopwatch sw = Stopwatch.StartNew();

                if (MaintainerSettings.Cleaner.findEmptyFolders)
                {
                    searchCanceled = ScanFolders(results);
                }

                if (!searchCanceled && MaintainerSettings.Cleaner.findUnusedAssets)
                {
                    searchCanceled = ScanProjectFiles(results);
                }

                sw.Stop();

                EditorUtility.ClearProgressBar();

                if (!searchCanceled)
                {
                    Debug.Log(Maintainer.LOG_PREFIX + MODULE_NAME + " results: " + results.Count +
                              " items found in " + sw.Elapsed.TotalSeconds.ToString("0.000") +
                              " seconds.");
                }
                else
                {
                    Debug.Log(Maintainer.LOG_PREFIX + "Search canceled by user!");
                }
            }
            catch (Exception e)
            {
                Debug.Log(e);
                EditorUtility.ClearProgressBar();
            }

            SearchResultsStorage.CleanerSearchResults = results.ToArray();
            if (showResults)
            {
                MaintainerWindow.ShowCleaner();
            }

            return(results.ToArray());
        }