Example #1
0
        public static List <ComponentDescriptor> GetDescriptors()
        {
            string compPath = Global.Relative("Components");

            if (Directory.Exists(compPath))
            {
                List <ComponentDescriptor> descs = new List <ComponentDescriptor>();

                foreach (FileInfo file in new DirectoryInfo(compPath).GetFiles().Where(x => x.Extension == ".json"))
                {
                    try
                    {
                        ComponentDescriptor desc = JsonConvert.DeserializeObject <ComponentDescriptor>(File.ReadAllText(file.FullName));
                        desc.SourcePath      = file.FullName;
                        desc.SourceDirectory = file.DirectoryName;
                        descs.Add(desc);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine($"Failed to load component '{file.Name}' due to  {ex.Message}");
                    }
                }
                foreach (DirectoryInfo dir in new DirectoryInfo(compPath).GetDirectories())
                {
                    string configPath = Path.Combine(dir.FullName, "config.json");
                    if (File.Exists(configPath))
                    {
                        try
                        {
                            ComponentDescriptor desc = JsonConvert.DeserializeObject <ComponentDescriptor>(File.ReadAllText(configPath));
                            desc.SourcePath      = configPath;
                            desc.SourceDirectory = dir.FullName;
                            descs.Add(desc);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine($"Failed to load component '{dir.Name}' due to  {ex.Message}");
                        }
                    }
                }

                return(descs);
            }
            else
            {
                return(new List <ComponentDescriptor>());
            }
        }
        static void Main(string[] args)
        {
            try
            {
                if (args.Length == 0)
                {
                    Console.WriteLine("Would you like to register .sandbox files for this .exe? (y/n)");

                    if (Console.ReadLine().ToLower() == "y")
                    {
                        FileAssociations.EnsureAssociationsSet(new FileAssociation()
                        {
                            ExecutableFilePath  = Assembly.GetExecutingAssembly().Location,
                            Extension           = ".sandbox",
                            FileTypeDescription = "WSB Wrapper",
                            ProgId = "LR_Sandbox"
                        });
                        Console.WriteLine("Done");
                        Console.ReadLine();
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    SandboxDescriptor sandbox = JsonConvert.DeserializeObject <SandboxDescriptor>(File.ReadAllText(args[0]));

                    List <ComponentDescriptor> comps = ComponentDescriptor.GetDescriptors();


                    Sandbox box = new Sandbox(sandbox, comps);

                    box.Prepare();

                    box.Run();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception:" + ex.Message);
                Console.WriteLine("Stacktrace:" + ex.StackTrace);
                Console.ReadLine();
            }
        }