Storage of configuration for Elite: Dangerous ships as obtained by the Companion App
        /// <summary>
        /// Obtain ships configuration from a file.  If the file name is not supplied the the default
        /// path of Constants.Data_DIR\ships.json is used
        /// </summary>
        public static ShipsConfiguration FromFile(string filename = null)
        {
            if (filename == null)
            {
                filename = Constants.DATA_DIR + @"\ships.json";
            }

            ShipsConfiguration configuration = new ShipsConfiguration();

            try
            {
                configuration = JsonConvert.DeserializeObject <ShipsConfiguration>(File.ReadAllText(filename));
            }
            catch (Exception ex)
            {
                Logging.Debug("Failed to read ships configuration", ex);
            }
            if (configuration == null)
            {
                configuration = new ShipsConfiguration();
            }

            // There was a bug that caused null entries to be written to the ships configuration; remove these if present
            configuration.Ships = configuration.Ships.Where(x => x.role != null).ToList();

            configuration.dataPath = filename;
            return(configuration);
        }
        private static void AugmentShipInfo(Ship ship, List <Ship> storedShips)
        {
            Logging.Debug("Entered");
            ShipsConfiguration     shipsConfiguration = ShipsConfiguration.FromFile();
            Dictionary <int, Ship> lookup             = shipsConfiguration.Ships.ToDictionary(o => o.LocalId);

            Ship shipConfig;

            // Start with our current ship
            if (lookup.TryGetValue(ship.LocalId, out shipConfig))
            {
                // Already exists; grab the relevant information and supplement it
                // Ship config name might be just whitespace, in which case we unset it
                if (shipConfig.name != null && shipConfig.name.Trim().Length > 0)
                {
                    ship.name = shipConfig.name.Trim();
                }
                if (shipConfig.phoneticname != null && shipConfig.phoneticname.Trim().Length > 0)
                {
                    ship.phoneticname = shipConfig.phoneticname.Trim();
                }
                ship.role = shipConfig.role;
            }
            else
            {
                // Doesn't already exist; add a default role
                ship.role = Role.MultiPurpose;
            }

            // Work through our shipyard
            foreach (Ship storedShip in storedShips)
            {
                if (lookup.TryGetValue(storedShip.LocalId, out shipConfig))
                {
                    // Already exists; grab the relevant information and supplement it
                    storedShip.name         = shipConfig.name;
                    storedShip.phoneticname = shipConfig.phoneticname;
                    storedShip.role         = shipConfig.role;
                }
                else
                {
                    // Doesn't already exist; add a default role
                    storedShip.role = Role.MultiPurpose;
                }
            }

            // Update our configuration with the new data (this also removes any old redundant ships)
            shipsConfiguration.Ships = new List <Ship>();
            shipsConfiguration.Ships.Add(ship);
            shipsConfiguration.Ships.AddRange(storedShips);
            shipsConfiguration.ToFile();
            Logging.Debug("Leaving");
        }
        /// <summary>
        /// Obtain ships configuration from a file.  If the file name is not supplied the the default
        /// path of Constants.Data_DIR\ships.json is used
        /// </summary>
        public static ShipsConfiguration FromFile(string filename=null)
        {
            if (filename == null)
            {
                filename = Constants.DATA_DIR + @"\ships.json";
            }

            ShipsConfiguration configuration = new ShipsConfiguration();
            try
            {
                configuration = JsonConvert.DeserializeObject<ShipsConfiguration>(File.ReadAllText(filename));
            }
            catch {}

            configuration.dataPath = filename;
            return configuration;
        }
Exemple #4
0
        /// <summary>
        /// Obtain ships configuration from a file.  If the file name is not supplied the the default
        /// path of Constants.Data_DIR\ships.json is used
        /// </summary>
        public static ShipsConfiguration FromFile(string filename = null)
        {
            if (filename == null)
            {
                filename = Constants.DATA_DIR + @"\ships.json";
            }

            ShipsConfiguration configuration = new ShipsConfiguration();

            try
            {
                configuration = JsonConvert.DeserializeObject <ShipsConfiguration>(File.ReadAllText(filename));
            }
            catch {}

            configuration.dataPath = filename;
            return(configuration);
        }
 // Handle changes to the Shipyard tab
 private void setShipyardFromConfiguration()
 {
     shipsConfiguration = new ShipsConfiguration();
     List<Ship> ships = new List<Ship>();
     if (profile != null)
     {
         ships.Add(profile.Ship);
         ships.AddRange(profile.Shipyard);
     }
     shipsConfiguration.Ships = ships;
     shipyardData.ItemsSource = ships;
 }