private bool ConvertFile(string file, out string errorReason) { try { Application.DoEvents(); string sourcePath = txtSource.Text + file; string sourceText = File.ReadAllText(sourcePath); FileInfo info = new FileInfo(sourcePath); string fileName = info.Name; fileName = fileName.Remove(fileName.Length - info.Extension.Length, info.Extension.Length); sourceText = sourceText.Trim(); if (string.IsNullOrEmpty(sourceText)) { errorReason = string.Format("The file {0} is empty !", sourcePath); return(false); } ConverterEngine engine = new ConverterEngine(LanguageVersion.VB6, sourceText); if (cboLanguage.Text == "VB .NET") { engine.ResultType = DestinationLanguage.VisualBasic; } engine.FileName = fileName; bool success = engine.Convert(); if (success) { string resultPath = string.Format(@"{0}\{1}.{2}", txtDestination.Text, fileName, engine.ResultFileExtension); string resultText = engine.Result; File.WriteAllText(resultPath, resultText); } errorReason = engine.GetErrors(); return(success); } catch (Exception ex) { errorReason = string.Format("Cannot convert due to internal error.\n\nDetails: " + ex.Message); return(false); } }
private void btnConvert_Click(object sender, EventArgs e) { try { if (string.IsNullOrEmpty(SourceEditor.Text)) { MessageBox.Show("There's no source code to convert !", "VB Converter", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); SourceEditor.Focus(); } else { this.Cursor = Cursors.WaitCursor; string source = SourceEditor.Text; ConverterEngine engine = new ConverterEngine(LanguageVersion.VB6, source); if (cboLanguage.Text == "VB .NET") { engine.ResultType = DestinationLanguage.VisualBasic; } bool success = engine.Convert(); string result = success ? engine.Result : engine.GetErrors(); DestinationEditor.Text = result; DestinationEditor.Focus(); if (engine.Errors.Count > 0) { MessageBox.Show("It's not possible to convert the the source code due to compile errors!\n\nCheck the sintax.", "VB Converter", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } } catch (Exception ex) { Debug.WriteLine(ex.ToString()); MessageBox.Show("It's not possible to convert the source code. \n\nDetails: " + ex.Message, "VB Converter", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { this.Cursor = Cursors.Default; } }