1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
|
'
' Visual Basic.Net COmpiler
' Copyright (C) 2004 - 2006 Rolf Bjarne Kvinge, rbjarnek at users.sourceforge.net
'
' This library is free software; you can redistribute it and/or
' modify it under the terms of the GNU Lesser General Public
' License as published by the Free Software Foundation; either
' version 2.1 of the License, or (at your option) any later version.
'
' This library is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
' Lesser General Public License for more details.
'
' You should have received a copy of the GNU Lesser General Public
' License along with this library; if not, write to the Free Software
' Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
'
Option Explicit On
Option Strict On
Imports System
Imports System.Diagnostics
Imports System.io
Imports Microsoft.VisualBasic
Imports System.Collections
Module MainModule
Public CommandLine As New CommandLine
Public frmMain As frmMain
''' <summary>
''' The main function...
''' </summary>
''' <param name="cmdArgs"></param>
''' <returns></returns>
''' <remarks></remarks>
Function Main(ByVal cmdArgs() As String) As Integer
Try
Application.EnableVisualStyles()
Process.GetCurrentProcess.PriorityClass = ProcessPriorityClass.BelowNormal
CommandLine.Parse(cmdArgs)
If CommandLine.Spawn Then Return 0
'Try to upgrade the settings
If My.Settings.IsFirstRun Then
My.Settings.Upgrade()
My.Settings.IsFirstRun = False
Debug.WriteLine("Settings have been upgraded.")
End If
DisableErrorReporting()
frmMain = New frmMain
Using frmMain
If CommandLine.ExitOnSuccess Then
frmMain.WindowState = FormWindowState.Maximized
frmMain.WindowState = FormWindowState.Minimized
frmMain.Visible = True
frmMain.RunTests()
While frmMain.TestExecutor.QueueCount > 0
Application.DoEvents()
Threading.Thread.Sleep(50)
End While
If frmMain.Tests.TestsFailed = 0 Then
Return 0
Else
frmMain.Hide()
frmMain.WindowState = FormWindowState.Maximized
frmMain.Text = "FAILED " & frmMain.Text
End If
End If
If Not (frmMain.Disposing OrElse frmMain.IsDisposed) Then frmMain.ShowDialog()
End Using
Catch ex As System.Exception
MsgBox(ex.Message & vbNewLine & ex.GetType.ToString & vbNewLine & ex.StackTrace)
Finally
EnableErrorReporting()
End Try
End Function
''' <summary>
'''
''' </summary>
''' <param name="Filename"></param>
''' <param name="newExt">Don't include a dot.</param>
''' <returns></returns>
''' <remarks></remarks>
Function ChangeExtension(ByVal Filename As String, ByVal newExt As String) As String
Return IO.Path.Combine(IO.Path.GetDirectoryName(Filename), IO.Path.GetFileNameWithoutExtension(Filename)) & "." & newExt
End Function
Function ChangeOutputToVerified(ByVal Test As Test, ByVal Overwrite As Boolean, Optional ByVal Copy As Boolean = False) As Integer
Dim result As Integer
Try
Dim xmlfiles As String()
xmlfiles = Test.GetOutputFiles
For Each xmlfile As String In xmlfiles
Dim verified As String
verified = xmlfile.Replace(Test.OutputExtension, Test.VerifiedExtension)
If verified.Contains(".exceptions.") = False Then
If IO.File.Exists(verified) Then
If Overwrite Then
IO.File.Delete(verified)
If Copy Then
IO.File.Copy(xmlfile, verified)
Else
IO.File.Move(xmlfile, verified)
End If
result += 1
End If
Else
If Copy Then
IO.File.Copy(xmlfile, verified)
Else
IO.File.Move(xmlfile, verified)
End If
result += 1
End If
End If
Next
Catch ex As Exception
MsgBox("Error while changing output xml files to verified xml files: " & ex.Message)
End Try
Return result
End Function
Sub ChangeOutputToVerified(ByVal Directory As String, ByVal Overwrite As Boolean, ByVal Recursive As Boolean)
Try
Dim xmlfiles As String()
xmlfiles = IO.Directory.GetFiles(Directory, "*.*.output.xml")
For Each xmlfile As String In xmlfiles
Dim verified As String
verified = xmlfile.Replace(".output.xml", ".verified.xml")
If verified.Contains(".exceptions.") = False Then
If IO.File.Exists(verified) Then
If Overwrite Then
IO.File.Delete(verified)
IO.File.Move(xmlfile, verified)
End If
Else
IO.File.Move(xmlfile, verified)
End If
End If
Next
If Recursive Then
Dim dirs() As String
dirs = IO.Directory.GetDirectories(Directory)
For Each dir As String In dirs
ChangeOutputToVerified(dir, Overwrite, False)
Next
End If
Catch ex As Exception
MsgBox("Error while changing output xml files to verified xml files: " & ex.Message)
End Try
End Sub
Sub ViewFiles(ByVal ParamArray Filenames As String())
For Each file As String In Filenames
Process.Start(file)
Next
End Sub
<Conditional("DEBUG")> Sub StopIfDebugging()
If Diagnostics.Debugger.IsAttached Then
Stop
End If
End Sub
Private Sub EnableErrorReporting()
Try
CheckForRegistryConformance()
If My.Settings.ModifyRegistry = "Y" Then
If Environment.OSVersion.Platform <> PlatformID.Unix Then
Microsoft.Win32.Registry.SetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PCHealth\ErrorReporting", "ShowUI", 1, Microsoft.Win32.RegistryValueKind.DWord)
End If
End If
Catch ex As Exception
Global.System.Diagnostics.Debug.WriteLine("Could not enable error reporting: " & ex.Message)
End Try
End Sub
Private Sub DisableErrorReporting()
Try
CheckForRegistryConformance()
If My.Settings.ModifyRegistry = "Y" Then
If Environment.OSVersion.Platform <> PlatformID.Unix Then
Microsoft.Win32.Registry.SetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PCHealth\ErrorReporting", "ShowUI", 0, Microsoft.Win32.RegistryValueKind.DWord)
End If
End If
Catch ex As Exception
Global.System.Diagnostics.Debug.WriteLine("Could not disable error reporting: " & ex.Message)
End Try
End Sub
Private Sub CheckForRegistryConformance()
If My.Settings.ModifyRegistry = "" Then
Dim result As MsgBoxResult
result = MsgBox("This application will modify registry values for the entire machine, OK?" & vbNewLine & "(Check source for exact keys and values)", MsgBoxStyle.YesNoCancel Or MsgBoxStyle.Question)
If result = MsgBoxResult.Yes Then
My.Settings.ModifyRegistry = "Y"
ElseIf result = MsgBoxResult.No Then
My.Settings.ModifyRegistry = "N"
End If
End If
End Sub
End Module
|