/// <summary>
        /// Obtain credentials from a file.  If the file name is not supplied the the default
        /// path of %APPDATA%\EDDI\edsm.json is used
        /// </summary>
        public static StarMapConfiguration FromFile(string filename=null)
        {
            if (filename == null)
            {
                String dataDir = Environment.GetEnvironmentVariable("AppData") + "\\EDDI";
                Directory.CreateDirectory(dataDir);
                filename = dataDir + "\\edsm.json";
            }

            StarMapConfiguration credentials;
            try
            {
                String credentialsData = File.ReadAllText(filename);
                credentials = JsonConvert.DeserializeObject<StarMapConfiguration>(credentialsData);
            }
            catch
            {
                credentials = new StarMapConfiguration();
            }

            credentials.dataPath = filename;
            return credentials;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Obtain credentials from a file.  If the file name is not supplied the the default
        /// path of %APPDATA%\EDDI\edsm.json is used
        /// </summary>
        public static StarMapConfiguration FromFile(string filename = null)
        {
            if (filename == null)
            {
                String dataDir = Environment.GetEnvironmentVariable("AppData") + "\\EDDI";
                Directory.CreateDirectory(dataDir);
                filename = dataDir + "\\edsm.json";
            }

            StarMapConfiguration credentials;

            try
            {
                String credentialsData = File.ReadAllText(filename);
                credentials = JsonConvert.DeserializeObject <StarMapConfiguration>(credentialsData);
            }
            catch
            {
                credentials = new StarMapConfiguration();
            }

            credentials.dataPath = filename;
            return(credentials);
        }
 private void updateEdsmConfiguration()
 {
     StarMapConfiguration edsmConfiguration = new StarMapConfiguration();
     if (!String.IsNullOrWhiteSpace(edsmApiKeyTextBox.Text))
     {
         edsmConfiguration.apiKey = edsmApiKeyTextBox.Text.Trim();
     }
     if (!String.IsNullOrWhiteSpace(edsmCommanderNameTextBox.Text))
     {
         edsmConfiguration.commanderName = edsmCommanderNameTextBox.Text.Trim();
     }
     edsmConfiguration.ToFile();
 }