コード例 #1
0
        public static bool TryLoadFromConsole([MaybeNullWhen(false)] out ModulesList modules, out string path, bool includeCurrentDirectory = true)
        {
            modules = null;

            if (includeCurrentDirectory)
            {
                path = "modules.json";
            }
            else
            {
                Console.WriteLine("Please enter the path to a modules.json file");
                Console.Write("> ");
                path = Console.ReadLine();
            }

            while (!string.IsNullOrEmpty(path))
            {
                if (TryLoad(ref path, out modules))
                {
                    return(true);
                }
                Console.WriteLine("modules.json not found in this directory or any parent, please enter the path to a modules.json file");
                Console.Write("> ");
                path = Console.ReadLine();
            }

            return(false);
        }
コード例 #2
0
        public static bool TryLoad(ref string path, [MaybeNullWhen(false)] out ModulesList modules)
        {
            path = path.AsFullDirectoryPath();

            while (!string.IsNullOrEmpty(path))
            {
                var modulePath = Path.Combine(path, "modules.json");
                if (File.Exists(modulePath))
                {
                    modules = JsonConvert.DeserializeObject <ModulesList>(File.ReadAllText(modulePath));
                    return(true);
                }
                path = Path.GetDirectoryName(path);
            }

            modules = null;
            return(false);
        }