private static void MigrateFilters(MaintainerSettings settings)
        {
            MigrateAllIgnores(settings.issuesFinderSettings.pathIgnores,
                              ref settings.issuesFinderSettings.pathIgnoresFilters, FilterKind.Path);
            settings.issuesFinderSettings.pathIgnores = null;

            MigrateAllIgnores(settings.issuesFinderSettings.componentIgnores,
                              ref settings.issuesFinderSettings.componentIgnoresFilters, FilterKind.Type);
            settings.issuesFinderSettings.componentIgnores = null;

            MigrateAllIgnores(settings.issuesFinderSettings.pathIncludes,
                              ref settings.issuesFinderSettings.pathIncludesFilters, FilterKind.Path);
            settings.issuesFinderSettings.pathIncludes = null;

            MigrateAllIgnores(settings.issuesFinderSettings.sceneIncludes,
                              ref settings.issuesFinderSettings.sceneIncludesFilters, FilterKind.Path);
            settings.issuesFinderSettings.sceneIncludes = null;

            MigrateAllIgnores(settings.projectCleanerSettings.pathIgnores,
                              ref settings.projectCleanerSettings.pathIgnoresFilters, FilterKind.Path);
            settings.projectCleanerSettings.pathIgnores = null;

            MigrateAllIgnores(settings.projectCleanerSettings.sceneIgnores,
                              ref settings.projectCleanerSettings.sceneIgnoresFilters, FilterKind.Path);
            settings.projectCleanerSettings.sceneIgnores = null;

            settings.projectCleanerSettings.AddDefaultFilters();
        }
        private static MaintainerSettings CreateNewSettingsFile()
        {
            MaintainerSettings settingsInstance = CreateInstance();

            SaveInstance(settingsInstance);

            return(settingsInstance);
        }
        private static MaintainerSettings CreateInstance()
        {
            MaintainerSettings newInstance = new MaintainerSettings();

            newInstance.issuesFinderSettings   = new IssuesFinderSettings();
            newInstance.projectCleanerSettings = new ProjectCleanerSettings();

            return(newInstance);
        }
 private static void MigrateFromPre_1_4_1_0(MaintainerSettings settings)
 {
     if (!CSFilterTools.IsValueMatchesAnyFilterOfKind("dummy.asmdef",
                                                      settings.projectCleanerSettings.pathIgnoresFilters, FilterKind.Extension))
     {
         ArrayUtility.Add(ref settings.projectCleanerSettings.pathIgnoresFilters,
                          FilterItem.Create(".asmdef", FilterKind.Extension));
     }
 }
        private static void SaveInstance(MaintainerSettings settingsInstance)
        {
            if (!Directory.Exists(DIRECTORY))
            {
                Directory.CreateDirectory(DIRECTORY);
            }

            XmlSerializer serializer = new XmlSerializer(typeof(MaintainerSettings));
            Stream        stream     = new FileStream(PATH, FileMode.Create, FileAccess.Write, FileShare.None);

            serializer.Serialize(stream, settingsInstance);
            stream.Close();
        }
Beispiel #6
0
        private static void SaveInstance(MaintainerSettings settingsInstance)
        {
            if (!Directory.Exists(DIRECTORY))
            {
                Directory.CreateDirectory(DIRECTORY);
            }

            XmlSerializer serializer = new XmlSerializer(typeof(MaintainerSettings));
            StreamWriter  stream     = new StreamWriter(PATH, false, Encoding.UTF8);

            serializer.Serialize(stream, settingsInstance);
            stream.Close();
        }
        private static void SaveInstance(MaintainerSettings settingsInstance)
        {
            if (!System.IO.Directory.Exists(Directory))
            {
                System.IO.Directory.CreateDirectory(Directory);
            }

            try
            {
                UnityEditorInternal.InternalEditorUtility.SaveToSerializedFileAndForget(new Object[] { settingsInstance }, Path, true);
            }
            catch (Exception ex)
            {
                Debug.LogError(Maintainer.ConstructError("Can't save settings!\n" + ex));
            }
        }
        private static void MigrateSettings(MaintainerSettings settings)
        {
            if (string.IsNullOrEmpty(settings.version))
            {
                MigrateFilters(settings);
            }

            if (new Version(settings.version) < new Version("1.4.1.0"))
            {
                MigrateFromPre_1_4_1_0(settings);
            }

            if (new Version(settings.version) < new Version("1.5.1"))
            {
                MigrateFromPre_1_5_1(settings);
            }
        }
        private static void MigrateFromPre_1_5_1(MaintainerSettings settings)
        {
            if (settings.projectCleanerSettings.pathIgnoresFilters != null &&
                settings.projectCleanerSettings.pathIgnoresFilters.Length > 0)
            {
                var defaultFilters   = ProjectCleanerSettings.GetDefaultFilters();
                var mandatoryFilters = settings.projectCleanerSettings.MandatoryFilters;

                var modificationsLog = new StringBuilder();

                for (var i = settings.projectCleanerSettings.pathIgnoresFilters.Length - 1; i >= 0; i--)
                {
                    var pathIgnoresFilter = settings.projectCleanerSettings.pathIgnoresFilters[i];
                    if (pathIgnoresFilter.ignoreCase)
                    {
                        continue;
                    }

                    var isMandatory = false;

                    if (CSFilterTools.IsValueMatchesAnyFilterOfKind(pathIgnoresFilter.value, mandatoryFilters,
                                                                    pathIgnoresFilter.kind))
                    {
                        isMandatory = true;
                    }
                    else
                    {
                        switch (pathIgnoresFilter.kind)
                        {
                        case FilterKind.Extension:
                            var extension = pathIgnoresFilter.value.ToLowerInvariant();
                            if (extension == ".dll" ||
                                extension == ".asmdef" ||
                                extension == ".mdb" ||
                                extension == ".xml" ||
                                extension == ".rsp")
                            {
                                isMandatory = true;
                            }

                            break;

                        case FilterKind.FileName:
                            var value = pathIgnoresFilter.value.ToLowerInvariant();
                            if (value == "readme" ||
                                value == "manual")
                            {
                                isMandatory = true;
                            }

                            break;
                        }
                    }

                    if (isMandatory)
                    {
                        modificationsLog.Append("Removing Project Cleaner filter '")
                        .Append(pathIgnoresFilter.value)
                        .AppendLine("': built-in mandatory filter covers it now.");
                        ArrayUtility.RemoveAt(ref settings.projectCleanerSettings.pathIgnoresFilters, i);
                        continue;
                    }

                    if (CSFilterTools.IsValueMatchesAnyFilterOfKind(pathIgnoresFilter.value, defaultFilters,
                                                                    pathIgnoresFilter.kind))
                    {
                        modificationsLog.Append("Changing default Project Cleaner filter '")
                        .Append(pathIgnoresFilter.value)
                        .AppendLine("': ignore case setting to 'true' for better accuracy.");
                        pathIgnoresFilter.ignoreCase = true;
                    }
                }

                if (modificationsLog.Length > 0)
                {
                    modificationsLog.Insert(0, "Maintainer settings updated, read below for details\n");
                    Debug.Log(Maintainer.LogPrefix + modificationsLog);
                }
            }
        }
 /// <summary>
 /// Call to remove all Maintainer Settings (including personal settings).
 /// </summary>
 public static void Delete()
 {
     instance = null;
     CSFileTools.DeleteFile(Path);
     MaintainerPersonalSettings.Delete();
 }