1010using System . Text ;
1111using System . Windows . Forms ;
1212using System . Text . RegularExpressions ;
13+ using FastColoredTextBoxNS ;
1314
1415namespace FreakySources . GUI
1516{
@@ -45,82 +46,61 @@ public frmMain()
4546
4647 var patterns = Directory . GetFiles ( SourcePath , "*.cs" ) ;
4748 foreach ( var pattern in patterns )
48- {
4949 cmbPattern . Items . Add ( Path . GetFileName ( pattern ) ) ;
50- }
50+ cmbPattern . SelectedItem = Settings . Default . SelectedPattern ;
5151 }
5252
5353 private void frmMain_FormClosed ( object sender , FormClosedEventArgs e )
5454 {
55- Settings . Default . InputCode = tbInput . Text ;
56- Settings . Default . OutputTab = tabcOutput . SelectedIndex ;
57- Settings . Default . Kernel = tbKernel . Text ;
58- var extraParams = new StringBuilder ( ) ;
55+ SaveParams ( ) ;
56+ }
57+
58+ private void btnGenerate_Click ( object sender , EventArgs e )
59+ {
60+ string input = tbInput . Text ;
61+
62+ var generator = new QuineGenerator ( tbQuineStr . Text , "Console.Write" , tbKernel . Text ) ;
63+ var extraParams = new List < QuineParam > ( ) ;
5964 for ( int i = 0 ; i < dgvExtraParams . Rows . Count ; i ++ )
6065 if ( ! string . IsNullOrEmpty ( dgvExtraParams [ 0 , i ] . Value as string ) ||
6166 ! string . IsNullOrEmpty ( dgvExtraParams [ 1 , i ] . Value as string ) ||
6267 ! string . IsNullOrEmpty ( dgvExtraParams [ 2 , i ] . Value as string ) ||
6368 ! string . IsNullOrEmpty ( dgvExtraParams [ 3 , i ] . Value as string ) )
6469 {
65- extraParams . AppendFormat ( "{0}~{1}~{2}~{3}|" ,
66- dgvExtraParams [ 0 , i ] . Value as string ,
67- dgvExtraParams [ 1 , i ] . Value as string ,
68- dgvExtraParams [ 2 , i ] . Value as string ,
69- dgvExtraParams [ 3 , i ] . Value as string ) ;
70+ extraParams . Add ( new QuineParam (
71+ dgvExtraParams [ 0 , i ] . Value == null ? "" : ( string ) dgvExtraParams [ 0 , i ] . Value ,
72+ dgvExtraParams [ 1 , i ] . Value == null ? "" : ( string ) dgvExtraParams [ 1 , i ] . Value ,
73+ dgvExtraParams [ 2 , i ] . Value == null ? "" : ( string ) dgvExtraParams [ 2 , i ] . Value ,
74+ dgvExtraParams [ 3 , i ] . Value == null ? "" : ( string ) dgvExtraParams [ 3 , i ] . Value ) ) ;
7075 }
71- Settings . Default . ExtraParams = extraParams . ToString ( ) ;
72- Settings . Default . QuineStr = tbQuineStr . Text ;
73- Settings . Default . WindowLocation = Location ;
74- Settings . Default . WindowSize = Size ;
75- Settings . Default . WindowState = WindowState . ToString ( ) ;
76- Settings . Default . MaxLineLength = ( int ) nudLineLength . Value ;
77- Settings . Default . CompressIdentifiers = cbCompressIdentifiers . Checked ;
78- Settings . Default . Save ( ) ;
79- }
80-
81- private void btnGenerate_Click ( object sender , EventArgs e )
82- {
83- string input = tbInput . Text ;
84- if ( rbQuine . Checked )
85- {
86- var generator = new QuineGenerator ( tbQuineStr . Text , "Console.Write" , tbKernel . Text ) ;
87- var extraParams = new List < QuineParam > ( ) ;
88- for ( int i = 0 ; i < dgvExtraParams . Rows . Count ; i ++ )
89- if ( ! string . IsNullOrEmpty ( dgvExtraParams [ 0 , i ] . Value as string ) ||
90- ! string . IsNullOrEmpty ( dgvExtraParams [ 1 , i ] . Value as string ) ||
91- ! string . IsNullOrEmpty ( dgvExtraParams [ 2 , i ] . Value as string ) ||
92- ! string . IsNullOrEmpty ( dgvExtraParams [ 3 , i ] . Value as string ) )
93- {
94- extraParams . Add ( new QuineParam (
95- dgvExtraParams [ 0 , i ] . Value == null ? "" : ( string ) dgvExtraParams [ 0 , i ] . Value ,
96- dgvExtraParams [ 1 , i ] . Value == null ? "" : ( string ) dgvExtraParams [ 1 , i ] . Value ,
97- dgvExtraParams [ 2 , i ] . Value == null ? "" : ( string ) dgvExtraParams [ 2 , i ] . Value ,
98- dgvExtraParams [ 3 , i ] . Value == null ? "" : ( string ) dgvExtraParams [ 3 , i ] . Value ) ) ;
99- }
100- input = generator . Generate ( input , false , extraParams . ToArray ( ) ) ;
101- }
76+ input = generator . Generate ( input , false , extraParams . ToArray ( ) ) ;
10277
10378 tbOutput . Text = input ;
104- var minifier = new Minifier ( new MinifierOptions ( false ) ) ;
105- tbFormattedOutput . Text = minifier . MinifyFromString ( input ) ;
106- tbConsoleOutput . Text = Checker . Compile ( tbOutput . Text ) . Output ;
107- if ( cbScrollToEnd . Checked )
108- {
109- tbConsoleOutput . VerticalScroll . Value = tbConsoleOutput . VerticalScroll . Maximum ;
110- tbConsoleOutput . VerticalScroll . Value = tbConsoleOutput . VerticalScroll . Maximum ;
111- }
79+ CompileOutput ( ) ;
11280 }
11381
11482 private void btnConsoleOutputToInput_Click ( object sender , EventArgs e )
11583 {
11684 tbOutput . Text = tbConsoleOutput . Text ;
85+ CompileOutput ( ) ;
86+ }
87+
88+ private void CompileOutput ( )
89+ {
11790 var minifier = new Minifier ( new MinifierOptions ( false ) ) ;
91+
11892 tbFormattedOutput . Text = minifier . MinifyFromString ( tbOutput . Text ) ;
119- tbConsoleOutput . Text = Checker . Compile ( tbOutput . Text ) . Output ;
120- if ( cbScrollToEnd . Checked )
93+ var compileResult = Checker . Compile ( tbOutput . Text ) ;
94+ if ( compileResult . Count == 1 && compileResult . First ( ) . Output != null )
12195 {
122- tbConsoleOutput . VerticalScroll . Value = tbConsoleOutput . VerticalScroll . Maximum ;
123- tbConsoleOutput . VerticalScroll . Value = tbConsoleOutput . VerticalScroll . Maximum ;
96+ tbConsoleOutput . ResetText ( ) ;
97+ tbConsoleOutput . Text = compileResult . First ( ) . Output ;
98+ if ( cbScrollToEnd . Checked )
99+ {
100+ //var linesCount = tbConsoleOutput.Text.Split('\n').Length;
101+ tbConsoleOutput . VerticalScroll . Value = tbConsoleOutput . VerticalScroll . Maximum ;
102+ tbConsoleOutput . VerticalScroll . Value = tbConsoleOutput . VerticalScroll . Maximum ;
103+ }
124104 }
125105 }
126106
@@ -159,27 +139,58 @@ private void btnMinifyInput_Click(object sender, EventArgs e)
159139 ignoredIdentifiers . Add ( match . Value ) ;
160140 }
161141 ignoredIdentifiers = ignoredIdentifiers . Where ( id => { long result ; return ! long . TryParse ( id , out result ) ; } ) . ToList ( ) ;
142+ ignoredIdentifiers . Add ( tbQuineStr . Text ) ;
162143
163144 var minifier = new Minifier ( new MinifierOptions ( false )
164145 {
165146 SpacesRemoving = cbRemoveSpaces . Checked ,
166147 LineLength = ( int ) nudLineLength . Value ,
167- IdentifiersCompressing = cbCompressIdentifiers . Checked ,
148+ LocalVarsCompressing = cbCompressIdentifiers . Checked ,
149+ MembersCompressing = cbCompressIdentifiers . Checked ,
150+ TypesCompressing = cbCompressIdentifiers . Checked ,
168151 MiscCompressing = true ,
169152 RegionsRemoving = true ,
170153 CommentsRemoving = true ,
171- ConsoleApp = true
154+ ConsoleApp = true ,
155+ RemoveToStringMethods = true ,
156+ CompressPublic = true ,
157+ RemoveNamespaces = true
172158 } , ignoredIdentifiers . ToArray ( ) , ignoredComments . ToArray ( ) ) ;
173159 tbInput . Text = minifier . MinifyFromString ( tbInput . Text ) ;
160+ }
174161
175-
162+ private void btnGenerateCode_Click ( object sender , EventArgs e )
163+ {
164+ var codeDataGenerator = new CodeDataGenerator ( tbSourceCodeFilesFolder . Text ) ;
165+ tbInput . Text = codeDataGenerator . SubstituteCode ( tbInput . Text ) ;
176166 }
177167
178168 private void btnGenerateData_Click ( object sender , EventArgs e )
179169 {
180170 var dataGenerator = new AsciimationDataGenerator ( File . ReadAllText ( SourcePath + "Asciimation.txt" ) ) ;
181- tbInput . Text = dataGenerator . ChangeGZipCompressedFrames ( tbInput . Text ,
182- "/*$CompressedFramesGZipStream*/" , "/*CompressedFramesGZipStream$*/" ) ;
171+ if ( cmbPattern . SelectedItem . ToString ( ) == "Asciimation_1_1.cs" )
172+ {
173+ tbInput . Text = dataGenerator . ChangeGZipCompressedFrames ( tbInput . Text ,
174+ "/*$CompressedFramesGZipStream*/" , "/*CompressedFramesGZipStream$*/" ) ;
175+ }
176+ else if ( cmbPattern . SelectedItem . ToString ( ) == "Asciimation_1_2.cs" )
177+ {
178+ var codeDataGenerator = new CodeDataGenerator ( tbSourceCodeFilesFolder . Text ) ;
179+ codeDataGenerator . SaveKeys = true ;
180+ tbInput . Text = codeDataGenerator . SubstituteData ( tbInput . Text , new List < CodeDataGeneratorParam > ( )
181+ {
182+ new CodeDataGeneratorParam {
183+ KeyBegin = "/*$HuffmanRleTable*/" ,
184+ KeyEnd = "/*HuffmanRleTable$*/" ,
185+ Value = dataGenerator . GetHuffmanRleTable ( )
186+ } ,
187+ new CodeDataGeneratorParam {
188+ KeyBegin = "/*$HuffmanRleFrames*/" ,
189+ KeyEnd = "/*HuffmanRleFrames$*/" ,
190+ Value = dataGenerator . GetHuffmanRleFrames ( )
191+ }
192+ } ) ;
193+ }
183194 }
184195
185196 private void btnClearData_Click ( object sender , EventArgs e )
@@ -191,7 +202,95 @@ private void btnClearData_Click(object sender, EventArgs e)
191202
192203 private void cmbPattern_SelectedIndexChanged ( object sender , EventArgs e )
193204 {
194- tbInput . Text = File . ReadAllText ( Path . Combine ( SourcePath , cmbPattern . SelectedItem . ToString ( ) ) ) ;
205+ var fileName = cmbPattern . SelectedItem . ToString ( ) ;
206+ if ( fileName != "" )
207+ {
208+ var text = File . ReadAllText ( Path . Combine ( SourcePath , fileName ) ) ;
209+ tbInput . Text = File . ReadAllText ( Path . Combine ( SourcePath , fileName ) ) ;
210+ tbOutput . Text = tbConsoleOutput . Text = tbFormattedOutput . Text = "" ;
211+ dgvCompileErrors . Rows . Clear ( ) ;
212+ }
213+ }
214+
215+ private void btnSaveInput_Click ( object sender , EventArgs e )
216+ {
217+ SaveParams ( ) ;
218+ }
219+
220+ private void SaveParams ( )
221+ {
222+ Settings . Default . InputCode = tbInput . Text ;
223+ Settings . Default . OutputTab = tabcOutput . SelectedIndex ;
224+ Settings . Default . Kernel = tbKernel . Text ;
225+ var extraParams = new StringBuilder ( ) ;
226+ for ( int i = 0 ; i < dgvExtraParams . Rows . Count ; i ++ )
227+ if ( ! string . IsNullOrEmpty ( dgvExtraParams [ 0 , i ] . Value as string ) ||
228+ ! string . IsNullOrEmpty ( dgvExtraParams [ 1 , i ] . Value as string ) ||
229+ ! string . IsNullOrEmpty ( dgvExtraParams [ 2 , i ] . Value as string ) ||
230+ ! string . IsNullOrEmpty ( dgvExtraParams [ 3 , i ] . Value as string ) )
231+ {
232+ extraParams . AppendFormat ( "{0}~{1}~{2}~{3}|" ,
233+ dgvExtraParams [ 0 , i ] . Value as string ,
234+ dgvExtraParams [ 1 , i ] . Value as string ,
235+ dgvExtraParams [ 2 , i ] . Value as string ,
236+ dgvExtraParams [ 3 , i ] . Value as string ) ;
237+ }
238+ Settings . Default . ExtraParams = extraParams . ToString ( ) ;
239+ Settings . Default . QuineStr = tbQuineStr . Text ;
240+ Settings . Default . WindowLocation = Location ;
241+ Settings . Default . WindowSize = Size ;
242+ Settings . Default . WindowState = WindowState . ToString ( ) ;
243+ Settings . Default . MaxLineLength = ( int ) nudLineLength . Value ;
244+ Settings . Default . CompressIdentifiers = cbCompressIdentifiers . Checked ;
245+ Settings . Default . SelectedPattern = cmbPattern . SelectedItem . ToString ( ) ;
246+ Settings . Default . Save ( ) ;
247+ }
248+
249+ private void btnReload_Click ( object sender , EventArgs e )
250+ {
251+ cmbPattern_SelectedIndexChanged ( sender , e ) ;
252+ }
253+
254+ private void btnFormatInput_Click ( object sender , EventArgs e )
255+ {
256+
257+ }
258+
259+ private void btnPerformAllSteps_Click ( object sender , EventArgs e )
260+ {
261+ btnGenerateCode_Click ( sender , e ) ;
262+ btnGenerateData_Click ( sender , e ) ;
263+ btnMinifyInput_Click ( sender , e ) ;
264+ btnFormatInput_Click ( sender , e ) ;
265+ btnGenerate_Click ( sender , e ) ;
266+ }
267+
268+ private void btnCompile_Click ( object sender , EventArgs e )
269+ {
270+ bool input = ( sender as Button ) . Name . Contains ( "Input" ) ;
271+ dgvCompileErrors . Rows . Clear ( ) ;
272+ var checkingResults = Checker . Compile ( input ? tbInput . Text : tbOutput . Text ) ;
273+ foreach ( var result in checkingResults )
274+ {
275+ if ( result . IsError )
276+ dgvCompileErrors . Rows . Add ( result . FirstErrorLine . ToString ( ) , result . FirstErrorColumn . ToString ( ) ,
277+ result . Description , input ? "input" : "output" ) ;
278+ }
279+ }
280+
281+ private void dgvCompileErrors_CellDoubleClick ( object sender , DataGridViewCellEventArgs e )
282+ {
283+ if ( dgvCompileErrors . SelectedRows . Count > 0 )
284+ {
285+ var cells = dgvCompileErrors . SelectedRows [ 0 ] . Cells ;
286+ bool input = cells [ 3 ] . Value . ToString ( ) == "input" ;
287+ FastColoredTextBox textBox = input ? tbInput : tbOutput ;
288+ int line = Convert . ToInt32 ( cells [ 0 ] . Value ) ;
289+ int column = Convert . ToInt32 ( cells [ 1 ] . Value ) ;
290+ textBox . Navigate ( line ) ;
291+ textBox . Selection = new Range ( textBox , column - 1 , line - 1 , column - 1 , line - 1 ) ;
292+ textBox . Focus ( ) ;
293+ }
195294 }
196295 }
197296}
0 commit comments