File: Main.vb

package info (click to toggle)
mono-basic 2.10-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 22,964 kB
  • sloc: cs: 34,086; xml: 7,804; makefile: 471; sh: 317
file content (117 lines) | stat: -rw-r--r-- 4,511 bytes parent folder | download | duplicates (3)
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
' 
' Visual Basic.Net Compiler
' Copyright (C) 2004 - 2010 Rolf Bjarne Kvinge, RKvinge@novell.com
' 
' 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
' 

Imports System
Imports System.Diagnostics
Imports System.io
Imports Microsoft.VisualBasic
Imports System.Collections

Module MainModule
    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

            DisableErrorReporting()

            For Each str As String In cmdArgs
                If str = "/console" OrElse str = "-console" OrElse str = "--console" Then
                    Return ConsoleRunner.Run(cmdArgs)
                End If
            Next

            frmMain = New frmMain
            Application.Run(frmMain)
        Catch ex As System.Exception
            MsgBox(ex.Message & vbNewLine & ex.GetType.ToString & vbNewLine & ex.StackTrace)
        Finally
            EnableErrorReporting()
        End Try
    End Function

    Sub ViewFiles(ByVal ParamArray Filenames As String())
        For Each file As String In Filenames
            If Not IO.File.Exists(file) Then
                Dim result As MsgBoxResult = MsgBox(String.Format("The file '{0}' does not exist. Do you want to create it?", file), MsgBoxStyle.YesNoCancel Or MsgBoxStyle.Question, "File does not exist")
                If result = MsgBoxResult.Yes Then
                    IO.File.WriteAllText(file, String.Empty)
                ElseIf result = MsgBoxResult.Cancel Then
                    Return
                Else
                    Continue For
                End If
            End If
            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