コード例 #1
0
ファイル: Program.cs プロジェクト: LeMyst/scunpacked
        static void Main(string[] args)
        {
            string scDataRoot = null;
            string outputRoot = null;
            bool   doShips    = true;
            bool   doItems    = true;
            bool   doShops    = true;
            bool   doStarmap  = true;
            bool   noCache    = false;
            string typeFilter = null;
            string shipFilter = null;

            var p = new OptionSet
            {
                { "scdata=", v => scDataRoot = v },
                { "input=", v => scDataRoot = v },
                { "output=", v => outputRoot = v },
                { "noships", v => doShips = false },
                { "noitems", v => doItems = false },
                { "noshops", v => doShops = false },
                { "nomap", v => doStarmap = false },
                { "nocache", v => noCache = true },
                { "types=", v => typeFilter = v },
                { "ships=", v => shipFilter = v }
            };

            var extra = p.Parse(args);

            var badArgs = extra.Count > 0;

            if (badArgs)
            {
                Console.WriteLine("Usage:");
                Console.WriteLine("    Loader.exe -input=<path to extracted Star Citizen data> -output=<path to JSON output folder>");
                Console.WriteLine();
                return;
            }

            JsonConvert.DefaultSettings = () => new JsonSerializerSettings
            {
                Formatting        = Formatting.Indented,
                NullValueHandling = NullValueHandling.Ignore,
                Converters        = new List <JsonConverter> {
                    new StringEnumConverter()
                }
            };

            bool incremental = !doShips || !doItems || !doShops || !doStarmap;

            // Prep the output folder
            if (Directory.Exists(outputRoot) && !incremental)
            {
                var info = new DirectoryInfo(outputRoot);
                foreach (var file in info.GetFiles())
                {
                    file.Delete();
                }
                foreach (var dir in info.GetDirectories())
                {
                    dir.Delete(true);
                }
            }
            else
            {
                Directory.CreateDirectory(outputRoot);
            }

            var entitySvc = new EntityService
            {
                OutputFolder = outputRoot,
                DataRoot     = scDataRoot
            };

            entitySvc.Initialise(noCache);

            // Localisation
            Console.WriteLine("Load Localisation");
            var labelLoader = new LabelsLoader
            {
                OutputFolder = outputRoot,
                DataRoot     = scDataRoot
            };
            var labels          = labelLoader.Load("english");
            var localisationSvc = new LocalisationService(labels);

            // Manufacturers
            Console.WriteLine("Load Manufacturers");
            var manufacturerLoader = new ManufacturerLoader(localisationSvc)
            {
                OutputFolder = outputRoot,
                DataRoot     = scDataRoot
            };
            var manufacturerIndex = manufacturerLoader.Load();
            var manufacturerSvc   = new ManufacturerService(manufacturerIndex);

            // Ammunition
            Console.WriteLine("Load Ammunition");
            var ammoLoader = new AmmoLoader
            {
                OutputFolder = outputRoot,
                DataRoot     = scDataRoot
            };
            var ammoIndex = ammoLoader.Load();
            var ammoSvc   = new AmmoService(ammoIndex);

            // Insurance
            Console.WriteLine("Load Insurance");
            var insuranceLoader = new InsuranceLoader()
            {
                DataRoot = scDataRoot
            };
            var insurancePrices = insuranceLoader.Load();
            var insuranceSvc    = new InsuranceService(insurancePrices);

            var xmlLoadoutLoader = new XmlLoadoutLoader {
                DataRoot = scDataRoot
            };
            var manualLoadoutLoader = new ManualLoadoutLoader();
            var loadoutLoader       = new LoadoutLoader(xmlLoadoutLoader, manualLoadoutLoader);
            var itemBuilder         = new ItemBuilder(localisationSvc, manufacturerSvc, ammoSvc, entitySvc);
            var itemInstaller       = new ItemInstaller(entitySvc, loadoutLoader, itemBuilder);

            // Items
            if (doItems)
            {
                Console.WriteLine("Load Items");
                var itemLoader = new ItemLoader(itemBuilder, manufacturerSvc, entitySvc, ammoSvc, itemInstaller, loadoutLoader)
                {
                    OutputFolder = outputRoot,
                    DataRoot     = scDataRoot,
                };
                itemLoader.Load(typeFilter);
            }

            // Ships and vehicles
            if (doShips)
            {
                Console.WriteLine("Load Ships and Vehicles");
                var shipLoader = new ShipLoader(itemBuilder, manufacturerSvc, localisationSvc, entitySvc, itemInstaller, loadoutLoader, insuranceSvc)
                {
                    OutputFolder = outputRoot,
                    DataRoot     = scDataRoot,
                };
                shipLoader.Load(shipFilter);
            }

            // Prices
            if (doShops)
            {
                Console.WriteLine("Load Shops");
                var shopLoader = new ShopLoader(localisationSvc, entitySvc)
                {
                    OutputFolder = outputRoot,
                    DataRoot     = scDataRoot
                };
                shopLoader.Load();
            }

            // Starmap
            if (doStarmap)
            {
                Console.WriteLine("Load Starmap");
                var starmapLoader = new StarmapLoader(localisationSvc)
                {
                    OutputFolder = outputRoot,
                    DataRoot     = scDataRoot
                };
                starmapLoader.Load();
            }

            Console.WriteLine("Finished!");
        }
コード例 #2
0
        static void Main(string[] args)
        {
            string scDataRoot = null;
            string outputRoot = null;
            string itemFile   = null;
            bool   shipsOnly  = false;

            var p = new OptionSet
            {
                { "scdata=", v => scDataRoot = v },
                { "input=", v => scDataRoot = v },
                { "output=", v => outputRoot = v },
                { "itemfile=", v => itemFile = v },
                { "shipsonly", v => shipsOnly = true }
            };

            var extra = p.Parse(args);

            var badArgs = false;

            if (extra.Count > 0)
            {
                badArgs = true;
            }
            else if (!String.IsNullOrEmpty(itemFile) && (!String.IsNullOrEmpty(scDataRoot) || !String.IsNullOrEmpty(outputRoot)))
            {
                badArgs = true;
            }
            else if (String.IsNullOrEmpty(itemFile) && (String.IsNullOrEmpty(scDataRoot) || String.IsNullOrEmpty(outputRoot)))
            {
                badArgs = true;
            }

            if (badArgs)
            {
                Console.WriteLine("Usage:");
                Console.WriteLine("    Loader.exe -input=<path to extracted Star Citizen data> -output=<path to JSON output folder>");
                Console.WriteLine(" or Loader.exe -itemfile=<path to an SCItem XML file>");
                Console.WriteLine();
                return;
            }

            JsonConvert.DefaultSettings = () => new JsonSerializerSettings
            {
                Formatting        = Formatting.Indented,
                NullValueHandling = NullValueHandling.Ignore
            };

            if (itemFile != null)
            {
                var entityParser = new ClassParser <scdb.Xml.Entities.EntityClassDefinition>();
                var entity       = entityParser.Parse(itemFile);
                var json         = JsonConvert.SerializeObject(entity);
                Console.WriteLine(json);
                return;
            }

            // Prep the output folder
            if (Directory.Exists(outputRoot) && !shipsOnly)
            {
                var info = new DirectoryInfo(outputRoot);
                foreach (var file in info.GetFiles())
                {
                    file.Delete();
                }
                foreach (var dir in info.GetDirectories())
                {
                    dir.Delete(true);
                }
            }
            else
            {
                Directory.CreateDirectory(outputRoot);
            }

            // A loadout loader to help with any XML loadouts we encounter while parsing entities
            var loadoutLoader = new LoadoutLoader
            {
                OutputFolder = outputRoot,
                DataRoot     = scDataRoot
            };

            // Localisation
            Console.WriteLine("Load Localisation");
            var labelLoader = new LabelsLoader
            {
                OutputFolder = outputRoot,
                DataRoot     = scDataRoot
            };
            var labels          = labelLoader.Load("english");
            var localisationSvc = new LocalisationService(labels);

            // Manufacturers
            Console.WriteLine("Load Manufacturers");
            var manufacturerLoader = new ManufacturerLoader(localisationSvc)
            {
                OutputFolder = outputRoot,
                DataRoot     = scDataRoot
            };
            var manufacturerIndex = manufacturerLoader.Load();

            // Ammunition
            Console.WriteLine("Load Ammunition");
            var ammoLoader = new AmmoLoader
            {
                OutputFolder = outputRoot,
                DataRoot     = scDataRoot
            };
            var ammoIndex = ammoLoader.Load();

            // Items
            if (!shipsOnly)
            {
                Console.WriteLine("Load Items");
                var itemLoader = new ItemLoader
                {
                    OutputFolder  = outputRoot,
                    DataRoot      = scDataRoot,
                    OnXmlLoadout  = path => loadoutLoader.Load(path),
                    Manufacturers = manufacturerIndex,
                    Ammo          = ammoIndex
                };
                itemLoader.Load();
            }

            // Ships and vehicles
            Console.WriteLine("Load Ships and Vehicles");
            var shipLoader = new ShipLoader
            {
                OutputFolder  = outputRoot,
                DataRoot      = scDataRoot,
                OnXmlLoadout  = path => loadoutLoader.Load(path),
                Manufacturers = manufacturerIndex
            };

            shipLoader.Load();

            // Prices
            if (!shipsOnly)
            {
                Console.WriteLine("Load Shops");
                var shopLoader = new ShopLoader(localisationSvc)
                {
                    OutputFolder = outputRoot,
                    DataRoot     = scDataRoot
                };
                shopLoader.Load();
            }

            // Starmap
            if (!shipsOnly)
            {
                Console.WriteLine("Load Starmap");
                var starmapLoader = new StarmapLoader(localisationSvc)
                {
                    OutputFolder = outputRoot,
                    DataRoot     = scDataRoot
                };
                starmapLoader.Load();
            }

            Console.WriteLine("Finished!");
        }