예제 #1
0
 public static void AddOrUpdateStation(csvData data, int idx, GameData outputData)
 {
     int foundSystem = -1,
         foundStation = -1;
     // See if we already have the StarSystem
     foundSystem = Routines.IndexOfSystem(outputData, data.stations[idx].SystemName);
     if (foundSystem == -1)
     {
         // Not found, add StarSystem.
         outputData.StarSystems.Add(new StarSystem());
         foundSystem = outputData.StarSystems.Count - 1;
         outputData.StarSystems[foundSystem].Name = data.stations[idx].SystemName;
         outputData.StarSystems[foundSystem].Stations.Add(new Station(data.stations[idx]));
     }
     else
     {
         // Found StarSystem, check if we already have the Station
         foundStation = Routines.IndexOfStation(outputData.StarSystems[foundSystem], data.stations[idx].Name);
         if (foundStation == -1)
         {
             // Not found, add Station
             outputData.StarSystems[foundSystem].Stations.Add(new Station(data.stations[idx]));
             foundStation = outputData.StarSystems[foundSystem].Stations.Count - 1;
         }
         else
         {
             // Found, update Commodities
             Routines.UpdateCommodities(outputData.StarSystems[foundSystem].Stations[foundStation],
                                        data.stations[idx].Commodities);
         }
     }
 }
예제 #2
0
 public static int IndexOfSystem(GameData outputData, string systemName)
 {
     for (int i = 0; i < outputData.StarSystems.Count; i++)
         if (outputData.StarSystems[i].Name.Contains(systemName))
             return i;
     return -1;
 }
예제 #3
0
 private void browseEDA_Click(object sender, EventArgs e)
 {
     SaveFileDialog fdlg = new SaveFileDialog();
     fdlg.Title = "EDAssistant File";
     //fdlg.InitialDirectory = @"c:\";
     fdlg.Filter = "ED Trade Assistant (*.edassistant)|*.edassistant";
     fdlg.FilterIndex = 2;
     fdlg.CheckFileExists = false;
     fdlg.CreatePrompt = false;
     fdlg.OverwritePrompt = false;
     fdlg.RestoreDirectory = true;
     if (fdlg.ShowDialog() == DialogResult.OK)
     {
         edaFilename.Text = fdlg.FileName;
         if (!File.Exists(edaFilename.Text) || (new FileInfo( edaFilename.Text ).Length == 0 ))
         {
             // Create new file.
             FileStream newfile = File.Open(edaFilename.Text, FileMode.OpenOrCreate);
             newfile.Close();
             outputData = new GameData();
             fileWasCreated = true;
         }
         else
         {
             // Deserialize XML data
             fileWasCreated = false;
             XmlSerializer deserializer = new XmlSerializer(typeof(GameData));
             TextReader reader = new StreamReader(edaFilename.Text);
             object obj = deserializer.Deserialize(reader);
             outputData = (GameData)obj;
             reader.Close();
         }
     }
 }