Question 2: exchange writng function to a file

Trips

Well-known member
Joined
Aug 7, 2010
Messages
2,788
hello there,

it was long ago, i made program worked currently on Vista and XP, but not 7, the problem is, even though .NetfreamWork is compiler, it cant compile it on win 7 currently, so it read whole the file, but write nothing for me :( my bad ... have to change
long term of codes
now i wanna ask you what should i replace with writing or even both function .. its part of my codes:

<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; public <span style="color:Blue; void setFile()
{
<span style="color:Blue; try
{
<span style="color:Blue; for (CounterII = 0; CounterII < 10; CounterII++)
{
<span style="color:Blue; if (serverName.GetValue(CounterII).ToString() == lB1.SelectedItem.ToString())
{
<span style="color:Blue; if (File.Exists(gameAdd.GetValue(CounterII).ToString()) == <span style="color:Blue; true)
{
<span style="color:Green; //discover wow.exe address
gameAddWOW = (gameAdd.GetValue(CounterII).ToString()).Replace(<span style="color:#A31515; @"Launcher.exe", <span style="color:#A31515; @"Wow.exe");
<span style="color:Green; //run based on 3.x.x
String gameAddressEditor;
<span style="color:Green; //run based on advance
String gameAddressEditor1;
String gameAddressEditor2;
String gameAddressEditor3;
<span style="color:Blue; if (gameAdv.GetValue(CounterII).ToString() == <span style="color:#A31515; "Advance Game Setting - Slot 1")
{
<span style="color:Green; //check for file setting
<span style="color:Blue; if (!(Settings.Default.AS_S1_A1 == <span style="color:Blue; null || Settings.Default.AS_S1_A1 == <span style="color:#A31515; ""))
{
gameAddressEditor1 = Settings.Default.AS_S1_A1;
}
<span style="color:Blue; else { gameAddressEditor1 = <span style="color:Blue; null; }
<span style="color:Blue; if (!(Settings.Default.AS_S1_A2 == <span style="color:Blue; null || Settings.Default.AS_S1_A2 == <span style="color:#A31515; ""))
{
gameAddressEditor2 = Settings.Default.AS_S1_A2;
}
<span style="color:Blue; else { gameAddressEditor2 = <span style="color:Blue; null; }
<span style="color:Blue; if (!(Settings.Default.AS_S1_A3 == <span style="color:Blue; null || Settings.Default.AS_S1_A3 == <span style="color:#A31515; ""))
{
gameAddressEditor3 = Settings.Default.AS_S1_A3;
}
<span style="color:Blue; else { gameAddressEditor3 = <span style="color:Blue; null; }
<span style="color:Blue; if ((File.Exists(gameAddressEditor1) == <span style="color:Blue; false && gameAddressEditor1 != <span style="color:Blue; null) || (File.Exists(gameAddressEditor2) == <span style="color:Blue; false && gameAddressEditor2 != <span style="color:Blue; null) || (File.Exists(gameAddressEditor3) == <span style="color:Blue; false && gameAddressEditor3 != <span style="color:Blue; null))
{
<span style="color:Green; //if no file exist then return + truefalse :false
MessageBox.Show(<span style="color:#A31515; "Some Realm file missed. please check advance setting and reconfig your moved files!", <span style="color:#A31515; "File Error",MessageBoxButtons.OK,MessageBoxIcon.Warning);
TrueFalse = <span style="color:Blue; false;
<span style="color:Blue; return;
}
<span style="color:Blue; bool write1;
<span style="color:Blue; int i = 0,j=0;
write1 = <span style="color:Blue; true; <span style="color:Green; // if nothing happened data will write
<span style="color:Green; //read file, make true string, and write file

<span style="color:Gray; ///<span style="color:Green; /////////////////
<span style="color:Green; //start for 1ST file
<span style="color:Gray; ///<span style="color:Green; /////////////////
<span style="color:Blue; if (!(gameAddressEditor1 == <span style="color:Blue; null || gameAddressEditor1 == <span style="color:#A31515; ""))
{
String[] AdvanceRealmSpliter1=Settings.Default.AS_S1_S1.Split(<span style="color:#A31515; %);
<span style="color:Blue; if (AdvanceRealmSpliter1.Length != 2)
{
MessageBox.Show(<span style="color:#A31515; "Currect your advance setting string, it must contine 3 part on this sort <firstpart><%><second part>. n like : set realmlist"%" , that set realmlist " is first part then % that will replace with your realm, and then " that is second part", <span style="color:#A31515; "Syntanx Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
TrueFalse = <span style="color:Blue; false;
<span style="color:Blue; return;
}
StreamReader r1 = File.OpenText(gameAddressEditor1);
String[] strLineList1 = <span style="color:Blue; new String[100];
<span style="color:Green; //Read From File
<span style="color:Blue; try
{
<span style="color:Blue; for (i = 0; i < 100; i++)
{
strLineList1 = r1.ReadLine();
}
}
<span style="color:Blue; catch
{
MessageBox.Show(<span style="color:#A31515; "I/O error while reading file", <span style="color:#A31515; "I/O Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
write1 = <span style="color:Blue; false;
}
r1.Close();

<span style="color:Blue; if (write1 == <span style="color:Blue; true)
{
<span style="color:Green; //replace set realmlist
<span style="color:Blue; for (j = 0; j <= 99; j++)
{
<span style="color:Blue; if (strLineList1[j] != <span style="color:Blue; null)
{
<span style="color:Blue; if (strLineList1[j].Contains(AdvanceRealmSpliter1[0]) == <span style="color:Blue; true)
{
strLineList1[j] = AdvanceRealmSpliter1.GetValue(0).ToString() + realmList.GetValue(CounterII).ToString() + AdvanceRealmSpliter1.GetValue(1).ToString();
}
}
}
<span style="color:Green; //set file att (if its read only)
FileInfo ff1 = <span style="color:Blue; new FileInfo(gameAddressEditor1);
ff1.IsReadOnly = <span style="color:Blue; false;

<span style="color:Green; //Write To File
<span style="color:Blue; try
{
StreamWriter w1 = File.CreateText(gameAddressEditor1);
<span style="color:Blue; for (j = 0; j <= 99; j++)
{
<span style="color:Blue; if (strLineList1[j] != <span style="color:Blue; null)
{
w1.WriteLine(strLineList1[j]);
}
}
w1.Close();
TrueFalse = <span style="color:Blue; true;
<span style="color:Blue; return;
}
<span style="color:Blue; catch
{
TrueFalse = <span style="color:Blue; false;
MessageBox.Show(<span style="color:#A31515; "I/O error while writing file", <span style="color:#A31515; "I/O Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}

[/code]


View the full article
 
Back
Top