Contenido del config.ini
Código:
[List] 1=San Siro 2=Camp Nou 3=Estadio Del Nuevo Triunfo 4=Stade de Sagittaire 5=Stade Louis II 6=Old Trafford 7=Ville Marie Stadium 8=Bristol Mary Stadium 9= Mohamed Lewis Stadium 10=Konami Stadium 11=Nouvo Stadio della Juventus 12=Stadio Olimpico 13=Estadio de Escorpiao 14=Stadio Orione 15=Rose Park Stadium 16=Santiago Bernabeu 17=Royal London Stadium 18=Burg Stadion 19=Estadio do Morumbi 20=Estadio Urbano Caldeira 21=Estadio Da Luz 22=Estadio Do Dragao 23=Estadio Jose Alvalade 24=Stade de France 25=Wemblem Stadium 26=Estadio De Palenque 27=Estadio Amazonas 28=Giuseppe Meazza 29=Saitama Stadium 2002 30=Allianz Arena 31=Camp de Mestalla 32=Vicente Calderon 33=Ciutat de Valencia 34=Reyno de Navarra 35=Ramon Sanchez Pizjuan 36=La Rosaleda 37=Estadio RCD Espanyol 38=Campo San Mames 39=Benito Villamarin 40=Coliseum Alfonso Perez 41=Nuevo Los Carmenes 42=lBerostar Estadi 43=Anoeta 44=Campo de Futbol de Vallecas 45=Estadio de La Romareda
Clase Ini (esto me parece que esta bien)
Código:
using System; using System.IO; using System.Runtime.InteropServices; using System.Text; namespace Ini { class IniFile { public string path; [DllImport("kernel32")] private static extern long WritePrivateProfileString(string section, string key, string val, string filePath); [DllImport("kernel32")] private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath); public IniFile(string INIPath) { path = INIPath; } public void IniWriteValue(string Section, string Key, string Value) { WritePrivateProfileString(Section, Key, Value, this.path); } public string IniReadValue(string Section, string Key) { StringBuilder temp = new StringBuilder(255); int i = GetPrivateProfileString(Section, Key, "", temp, 255, this.path); return temp.ToString(); } } }
El codigo fuente
Código:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Diagnostics; using Ini; namespace selector { public partial class Form1 : Form { int gameplan = 0; string addScoreboard; public Form1() { InitializeComponent(); string[] Scoreboardfolder = Directory.GetDirectories(@".\data\Stadiums"); foreach (string subfolder in Scoreboardfolder) { addScoreboard = subfolder.Substring(16, subfolder.Length - 16); listBox1.Items.Add(addScoreboard); } } private void Form1_Load(object sender, EventArgs e) { #region ADD stadium IniFile stadium = new IniFile(Application.StartupPath + @"./data/Stadiums/config.ini"); if (stadium.IniReadValue("List", "Replace") != "") { listBox2.SelectedIndex = Convert.ToInt32(stadium.IniReadValue("List", "Replace")); } listBox2.Items.Add(stadium.IniReadValue("List", "1") + " " + stadium.IniReadValue("Replace", "1")); listBox2.Items.Add(stadium.IniReadValue("List", "2") + " " + stadium.IniReadValue("Replace", "2")); listBox2.Items.Add(stadium.IniReadValue("List", "3") + " " + stadium.IniReadValue("Replace", "3")); listBox2.Items.Add(stadium.IniReadValue("List", "4") + " " + stadium.IniReadValue("Replace", "4")); listBox2.Items.Add(stadium.IniReadValue("List", "5") + " " + stadium.IniReadValue("Replace", "5")); listBox2.Items.Add(stadium.IniReadValue("List", "6") + " " + stadium.IniReadValue("Replace", "6")); listBox2.Items.Add(stadium.IniReadValue("List", "7") + " " + stadium.IniReadValue("Replace", "7")); listBox2.Items.Add(stadium.IniReadValue("List", "8") + " " + stadium.IniReadValue("Replace", "8")); listBox2.Items.Add(stadium.IniReadValue("List", "9") + " " + stadium.IniReadValue("Replace", "9")); listBox2.Items.Add(stadium.IniReadValue("List", "10") + " " + stadium.IniReadValue("Replace", "10")); listBox2.Items.Add(stadium.IniReadValue("List", "11") + " " + stadium.IniReadValue("Replace", "11")); listBox2.Items.Add(stadium.IniReadValue("List", "12") + " " + stadium.IniReadValue("Replace", "12")); listBox2.Items.Add(stadium.IniReadValue("List", "13") + " " + stadium.IniReadValue("Replace", "13")); listBox2.Items.Add(stadium.IniReadValue("List", "14") + " " + stadium.IniReadValue("Replace", "14")); listBox2.Items.Add(stadium.IniReadValue("List", "15") + " " + stadium.IniReadValue("Replace", "15")); listBox2.Items.Add(stadium.IniReadValue("List", "16") + " " + stadium.IniReadValue("Replace", "16")); listBox2.Items.Add(stadium.IniReadValue("List", "17") + " " + stadium.IniReadValue("Replace", "17")); listBox2.Items.Add(stadium.IniReadValue("List", "18") + " " + stadium.IniReadValue("Replace", "18")); listBox2.Items.Add(stadium.IniReadValue("List", "19") + " " + stadium.IniReadValue("Replace", "19")); listBox2.Items.Add(stadium.IniReadValue("List", "20") + " " + stadium.IniReadValue("Replace", "20")); listBox2.Items.Add(stadium.IniReadValue("List", "21") + " " + stadium.IniReadValue("Replace", "21")); listBox2.Items.Add(stadium.IniReadValue("List", "22") + " " + stadium.IniReadValue("Replace", "22")); listBox2.Items.Add(stadium.IniReadValue("List", "23") + " " + stadium.IniReadValue("Replace", "23")); listBox2.Items.Add(stadium.IniReadValue("List", "24") + " " + stadium.IniReadValue("Replace", "24")); listBox2.Items.Add(stadium.IniReadValue("List", "25") + " " + stadium.IniReadValue("Replace", "25")); listBox2.Items.Add(stadium.IniReadValue("List", "26") + " " + stadium.IniReadValue("Replace", "26")); listBox2.Items.Add(stadium.IniReadValue("List", "27") + " " + stadium.IniReadValue("Replace", "27")); listBox2.Items.Add(stadium.IniReadValue("List", "28") + " " + stadium.IniReadValue("Replace", "28")); listBox2.Items.Add(stadium.IniReadValue("List", "29") + " " + stadium.IniReadValue("Replace", "29")); listBox2.Items.Add(stadium.IniReadValue("List", "30") + " " + stadium.IniReadValue("Replace", "30")); listBox2.Items.Add(stadium.IniReadValue("List", "31") + " " + stadium.IniReadValue("Replace", "31")); listBox2.Items.Add(stadium.IniReadValue("List", "32") + " " + stadium.IniReadValue("Replace", "32")); listBox2.Items.Add(stadium.IniReadValue("List", "33") + " " + stadium.IniReadValue("Replace", "33")); listBox2.Items.Add(stadium.IniReadValue("List", "34") + " " + stadium.IniReadValue("Replace", "34")); listBox2.Items.Add(stadium.IniReadValue("List", "35") + " " + stadium.IniReadValue("Replace", "35")); listBox2.Items.Add(stadium.IniReadValue("List", "36") + " " + stadium.IniReadValue("Replace", "36")); listBox2.Items.Add(stadium.IniReadValue("List", "37") + " " + stadium.IniReadValue("Replace", "37")); listBox2.Items.Add(stadium.IniReadValue("List", "38") + " " + stadium.IniReadValue("Replace", "38")); listBox2.Items.Add(stadium.IniReadValue("List", "39") + " " + stadium.IniReadValue("Replace", "39")); listBox2.Items.Add(stadium.IniReadValue("List", "40") + " " + stadium.IniReadValue("Replace", "40")); listBox2.Items.Add(stadium.IniReadValue("List", "41") + " " + stadium.IniReadValue("Replace", "41")); listBox2.Items.Add(stadium.IniReadValue("List", "42") + " " + stadium.IniReadValue("Replace", "42")); listBox2.Items.Add(stadium.IniReadValue("List", "43") + " " + stadium.IniReadValue("Replace", "43")); listBox2.Items.Add(stadium.IniReadValue("List", "44") + " " + stadium.IniReadValue("Replace", "44")); listBox2.Items.Add(stadium.IniReadValue("List", "45") + " " + stadium.IniReadValue("Replace", "45")); #endregion }