Ejemplo n.º 1
0
        internal void Update()
        {
            IniReader.WriteValue("QuickList", "FolderHandling", FolderHandling.ToString(), IniFile);
            IniReader.WriteValue("QuickList", "FileInfo", FileInfo.ToString(), IniFile);
            IniReader.WriteValue("QuickList", "ForceShellMedia", ForceShellMedia ? "1" : "0", IniFile);
            IniReader.WriteValue("QuickList", "FileReaderParallelism", FileReaderParallelism.ToString(), IniFile);

            if (ExcludedFilenames?.Count > 0)
            {
                IniReader.WriteValue("QuickList", "ExcludedFilenames", string.Join(":", ExcludedFilenames), IniFile);
            }
        }
Ejemplo n.º 2
0
        internal static Configuration Parse(string iniFile)
        {
            var configuration = new Configuration
            {
                IniFile        = iniFile,
                HeaderFile     = IniReader.ReadValue("ListMagic", "HeaderFile", iniFile),
                Trigger        = IniReader.ReadValue("ListMagic", "trigger", iniFile),
                OutputFolder   = IniReader.ReadValue("ListMagic", "ListLocation", iniFile),
                ShowUi         = string.Equals(IniReader.ReadValue("ListMagic", "Auto", iniFile, "Y").Trim(), "N", StringComparison.OrdinalIgnoreCase),
                ListName       = Path.GetFileNameWithoutExtension(iniFile),
                FileInfo       = (FileInfoLevel)Enum.Parse(typeof(FileInfoLevel), IniReader.ReadValue("QuickList", "FileInfo", iniFile, nameof(FileInfoLevel.Size))),
                FolderHandling = (FolderHandling)Enum.Parse(typeof(FolderHandling),
                                                            IniReader.ReadValue("QuickList", "FolderHandling", iniFile, nameof(FolderHandling.PartialFolders))),
                ForceShellMedia = IniReader.ReadValue("QuickList", "ForceShellMedia", iniFile, "0") == "1"
            };

            var excludedExtensions = IniReader.ReadValue("ListMagic", "Exclude", iniFile);

            if (!string.IsNullOrWhiteSpace(excludedExtensions))
            {
                configuration.ExcludedExtensions = excludedExtensions.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                                                   .Select(x =>
                                                           x.Trim()
                                                           .TrimStart('.').ToLowerInvariant())
                                                   .OrderBy(x => x)
                                                   .ToList();
            }

            int.TryParse(IniReader.ReadValue("QuickList", "FileReaderParallelism", iniFile, "1"), out var fileReaderParallelism);
            if (fileReaderParallelism <= 0)
            {
                fileReaderParallelism = 1;
            }

            configuration.FileReaderParallelism = fileReaderParallelism;

            var excludedFilenames = IniReader.ReadValue("QuickList", "ExcludedFilenames", iniFile, "desktop.ini:thumbs.db");

            if (!string.IsNullOrWhiteSpace(excludedFilenames))
            {
                configuration.ExcludedFilenames = excludedFilenames
                                                  .Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries)
                                                  .Select(x => x.Trim())
                                                  .OrderBy(x => x)
                                                  .ToList();
            }

            var dirsFile = IniReader.ReadValue("ListMagic", "DirsFile", iniFile);

            if (!File.Exists(dirsFile))
            {
                throw new FileNotFoundException($"Folders file \"{dirsFile}\" does not exist!");
            }

            configuration.InputFolders = File.ReadAllLines(dirsFile)
                                         .Select(x => x.Trim())
                                         .Where(x => !string.IsNullOrWhiteSpace(x))
                                         .Distinct()
                                         .ToList();
            configuration.Validate();

            return(configuration);
        }