1313using System . Xml ;
1414using System . Xml . Linq ;
1515
16- namespace LFAR
16+ namespace TrinityConfigsManager
1717{
1818 public partial class Form1 : Form
1919 {
@@ -45,17 +45,17 @@ private void saveCollectionButton_Click(object sender, EventArgs e)
4545 string pathFile = comboBox1 . Text + ".xml" ;
4646
4747 DataTable dt = new DataTable ( ) ;
48- dt . TableName = "LineJobs " ;
48+ dt . TableName = "ConfigJobs " ;
4949
5050 for ( int i = 0 ; i < dataGridView1 . Columns . Count ; i ++ )
5151 {
5252 if ( dataGridView1 . Columns [ i ] . Visible ) // Add's only Visible columns (if you need it)
5353 {
54- string headerText = dataGridView1 . Columns [ i ] . HeaderText ;
55- headerText = Regex . Replace ( headerText , "[-/, ]" , "_" ) ;
54+ string headerText = dataGridView1 . Columns [ i ] . HeaderText ;
55+ headerText = Regex . Replace ( headerText , "[-/, ]" , "_" ) ;
5656
57- DataColumn column = new DataColumn ( headerText ) ;
58- dt . Columns . Add ( column ) ;
57+ DataColumn column = new DataColumn ( headerText ) ;
58+ dt . Columns . Add ( column ) ;
5959 }
6060 }
6161
@@ -66,7 +66,6 @@ private void saveCollectionButton_Click(object sender, EventArgs e)
6666 dataRow [ 0 ] = DataGVRow . Cells [ 0 ] . Value ;
6767 dataRow [ 1 ] = DataGVRow . Cells [ 1 ] . Value ;
6868 dataRow [ 2 ] = DataGVRow . Cells [ 2 ] . Value ;
69- dataRow [ 3 ] = DataGVRow . Cells [ 3 ] . Value ;
7069
7170 dt . Rows . Add ( dataRow ) ; //dt.Columns.Add();
7271 }
@@ -106,7 +105,7 @@ private void Form1_Load(object sender, EventArgs e)
106105 // focus on last row
107106 try { dataGridView1 . CurrentCell = dataGridView1 . Rows [ dataGridView1 . RowCount - 1 ] . Cells [ 0 ] ; } catch { }
108107
109- label1 . Text = "Total: " + dataGridView1 . RowCount . ToString ( ) + " lines to replace " ;
108+ label1 . Text = "Total: " + dataGridView1 . RowCount . ToString ( ) + " configs prepared. " ;
110109 }
111110
112111 private void deleteCollectionButton_Click ( object sender , EventArgs e )
@@ -132,12 +131,11 @@ private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
132131
133132 XDocument xmlDoc = XDocument . Load ( fileName ) ;
134133
135- foreach ( var coordinate in xmlDoc . Descendants ( "LineJobs " ) )
134+ foreach ( var coordinate in xmlDoc . Descendants ( "ConfigJobs " ) )
136135 {
137136 dataGridView1 . Rows . Add ( coordinate . Element ( "Check" ) . Value ,
138- coordinate . Element ( "Line_to_Search" ) . Value ,
139- coordinate . Element ( "Replace_with" ) . Value ,
140- coordinate . Element ( "Comment" ) . Value ) ;
137+ coordinate . Element ( "Config_Name" ) . Value ,
138+ coordinate . Element ( "Set_Value" ) . Value ) ;
141139 } ;
142140 }
143141
@@ -171,7 +169,7 @@ private void button3_Click(object sender, EventArgs e)
171169
172170 private void button7_Click ( object sender , EventArgs e )
173171 {
174- dataGridView1 . Rows . Add ( false , "......" , "......" , "......" ) ;
172+ dataGridView1 . Rows . Add ( false , "......" , "......" ) ;
175173
176174 // focus on last row
177175 try { dataGridView1 . CurrentCell = dataGridView1 . Rows [ dataGridView1 . RowCount - 1 ] . Cells [ 0 ] ; } catch { }
@@ -191,14 +189,14 @@ private async void buttonDoReplaceJob_Click(object sender, EventArgs e)
191189 {
192190 int replacesCount = 0 ;
193191
194- DialogResult result = MessageBox . Show ( "This action will replace all lines with the values specified ." , "Confirmation" , MessageBoxButtons . YesNo ) ;
192+ DialogResult result = MessageBox . Show ( "This action will replace specified config values with yours ." , "Confirmation" , MessageBoxButtons . YesNo ) ;
195193 if ( result == DialogResult . Yes )
196194 {
197195 if ( File . Exists ( pathOfFile ) )
198196 {
199197 label1 . Text = "Running task, please wait..." ;
200198 replacesCount = await Task . Run ( ( ) => DoReplaceJob ( 1000 ) ) ;
201- label1 . Text = "Jobs finished: " + replacesCount + " replaces ." ;
199+ label1 . Text = "Jobs finished: " + replacesCount + " configs affected ." ;
202200 }
203201 else
204202 MessageBox . Show ( "Please select a valid file!" ) ;
@@ -219,10 +217,24 @@ private int DoReplaceJob(int sleepTime)
219217
220218 foreach ( DataGridViewRow row in dataGridView1 . Rows )
221219 {
222- if ( line . Contains ( row . Cells [ 1 ] . Value . ToString ( ) ) )
220+ if ( ! line . StartsWith ( "#" ) ) // ignore hashtag lines
223221 {
224- line = line . Replace ( line , row . Cells [ 2 ] . Value . ToString ( ) ) ;
225- replacesCount ++ ;
222+ if ( line . Contains ( '=' ) ) // if contains our separator
223+ {
224+ string configName = line . Split ( '=' ) . First ( ) ;
225+
226+ if ( configName . Contains ( row . Cells [ 1 ] . Value . ToString ( ) ) ) // if found the config we are looking for
227+ {
228+ string configValue = line . Split ( '=' ) . Last ( ) ;
229+
230+ if ( ! string . IsNullOrEmpty ( configValue ) ) // if string after separator is not null or empty
231+ {
232+ string newline = configName + "= " + row . Cells [ 2 ] . Value . ToString ( ) ; // prepare new line
233+ line = line . Replace ( line , newline ) ;
234+ replacesCount ++ ;
235+ }
236+ }
237+ }
226238 }
227239 }
228240 text = text + line + Environment . NewLine ;
0 commit comments