Esempio n. 1
0
        public void Parse(IEnumerable <string> args)
        {
            foreach (var arg in args)
            {
                ParseSingleArgument(arg, true);
            }

            if (!DataDirs.Any())
            {
                DataDirs = new List <DataDirSpec> {
                    DataDirSpec.FromPath(Environment.CurrentDirectory)
                }
            }
            ;

            if (Port == -1)
            {
                Port = FindFreePort();
            }
        }
Esempio n. 2
0
        private void ParseSingleArgument(string arg, bool allowConfigFile)
        {
            if (arg.ToLower() == "--help" || arg.ToLower() == "-h")
            {
                OptHelp = true;  return;
            }
            if (arg.ToLower() == "--version")
            {
                OptVersion = true;  return;
            }
            if (arg.ToLower() == "--no-ffmpeg")
            {
                NoFFMPEG = false; return;
            }
            if (arg.ToLower() == "--open-browser")
            {
                AutoOpenBrowser = true;  return;
            }
            if (arg.ToLower() == "--no-auto-previews")
            {
                AutoPreviewGen = false; return;
            }
            if (arg.ToLower() == "--trim-info-json")
            {
                TrimDataJSON = true;  return;
            }
            if (arg.ToLower() == "--no-trim-info-json")
            {
                TrimDataJSON = false; return;
            }

            if (!arg.StartsWith("--"))
            {
                throw new Exception($"Unknown argument: '{arg}'. Use --help for a list of commandline parameters");
            }

            var idx = arg.IndexOf("=", StringComparison.Ordinal);

            var key   = arg.Substring(2, idx - 2).ToLower();
            var value = arg.Substring(idx + 1);

            if (value.StartsWith("\"") && value.EndsWith("\""))
            {
                value = value.Substring(1, value.Length - 2);
            }

            if (key == "config-location")
            {
                if (!allowConfigFile)
                {
                    throw new Exception($"Nested use config-location is not allowed");
                }
                ParseArgumentsFromFile(value);
                return;
            }

            if (key == "path")
            {
                DataDirs.Add(DataDirSpec.Parse(value));           return;
            }
            if (key == "usertheme")
            {
                Themes.Add(ThemeSpec.Parse(value, Themes.Count)); return;
            }

            if (key == "display")
            {
                OptDisplayMode = int.Parse(value);                                                      return;
            }
            if (key == "order")
            {
                OptOrderMode = int.Parse(value);                                                      return;
            }
            if (key == "width")
            {
                OptWidthMode = int.Parse(value);                                                      return;
            }
            if (key == "thumbnailmode")
            {
                OptThumbnailMode = int.Parse(value);                                                      return;
            }
            if (key == "videomode")
            {
                OptVideoMode = int.Parse(value);                                                      return;
            }
            if (key == "theme")
            {
                OptThemeMode = (value.EndsWith(".css") ? value.Substring(0, value.Length - 4) : value); return;
            }
            if (key == "port")
            {
                Port = int.Parse(value);                                                      return;
            }
            if (key == "cache")
            {
                CacheDir = value.Replace("/", Path.DirectorySeparatorChar.ToString());            return;
            }
            if (key == "max-parallel-convert")
            {
                MaxParallelConvertJobs = int.Parse(value);                                                      return;
            }
            if (key == "max-parallel-genprev")
            {
                MaxParallelGenPreviewJobs = int.Parse(value);                                                      return;
            }
            if (key == "preview-width")
            {
                PreviewImageWidth = int.Parse(value);                                                      return;
            }
            if (key == "webm-convert-params")
            {
                ConvertFFMPEGParams = value;                                                                 return;
            }
            if (key == "thumnail-ex-mode")
            {
                ThumbnailExtraction = (ThumbnailExtractionMode)int.Parse(value);                             return;
            }
            if (key == "previewcount-max")
            {
                MaxPreviewImageCount = int.Parse(value);                                                      return;
            }
            if (key == "previewcount-min")
            {
                MinPreviewImageCount = Math.Max(2, int.Parse(value));                                         return;
            }
            if (key == "ffmpeg-debug-dir")
            {
                FFMPEGDebugDir = value.Replace("/", Path.DirectorySeparatorChar.ToString());            return;
            }
            if (key == "exec-ffmpeg")
            {
                FFMPEGExec = value;                                                                 return;
            }
            if (key == "exec-ffprobe")
            {
                FFPROBEExec = value;                                                                 return;
            }
            if (key == "autorefresh-interval")
            {
                AutoRefreshInterval = int.Parse(value);                                                      return;
            }
            if (key == "cronrefresh-interval")
            {
                CronRefreshInterval = int.Parse(value);                                                      return;
            }
            if (key == "htmltitle")
            {
                HTMLTitle = value;                                                                 return;
            }

            throw new Exception($"Unknown argument: '{arg}'. Use --help for a list of commandline parameters");
        }