/
AstroJohn
/
MailRobot
Обзор
Документация
Войти
/
AstroJohn
/
MailRobot
Код
Запросы
0
Задачи
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
MailRobotService/ProjectInstaller.vb
186 строк
6 KB
AstroJohn
1st commit
11 сен 2024, 13:31
11 сен 2024, 13:31
0f57dc5
Код
Авторство
О чём код?
Imports System.ComponentModel Imports System.Configuration.Install Imports CsConfig Imports Microsoft.Win32 <RunInstaller(True)> Public Class ProjectInstaller Inherits Installer #Region " Component Designer generated code " Public Sub New() MyBase.New() Try 'This call is required by the Component Designer. InitializeComponent() Catch ex As Exception Throw ex End Try End Sub 'Installer overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Component Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Component Designer 'It can be modified using the Component Designer. 'Do not modify it using the code editor. Friend WithEvents ServiceInstaller As System.ServiceProcess.ServiceInstaller Friend WithEvents ServiceProcessInstaller As System.ServiceProcess.ServiceProcessInstaller <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.ServiceProcessInstaller = New System.ServiceProcess.ServiceProcessInstaller() Me.ServiceInstaller = New System.ServiceProcess.ServiceInstaller() ' 'ServiceProcessInstaller ' Me.ServiceProcessInstaller.Account = System.ServiceProcess.ServiceAccount.LocalSystem Me.ServiceProcessInstaller.Password = Nothing Me.ServiceProcessInstaller.Username = Nothing ' 'ServiceInstaller ' Me.ServiceInstaller.Description = "E-Mail contest log downloader and parserlogs" Me.ServiceInstaller.DisplayName = "MailRobotService" Me.ServiceInstaller.ServiceName = "MailRobotService" Me.ServiceInstaller.StartType = System.ServiceProcess.ServiceStartMode.Automatic ' 'ProjectInstaller ' Me.Installers.AddRange(New System.Configuration.Install.Installer() {Me.ServiceProcessInstaller, Me.ServiceInstaller}) End Sub #End Region Protected Overrides Sub OnAfterUninstall(savedState As IDictionary) MyBase.OnAfterUninstall(savedState) Try Registry.LocalMachine.DeleteSubKeyTree(ConfigReader.RegistryKeyPath) Registry.LocalMachine.DeleteSubKeyTree(ConfigReader.RegistryKeyPath32Bit) Catch ex As Exception Console.WriteLine(ex.Message) Console.WriteLine(ex.StackTrace) End Try End Sub Protected Overrides Sub OnBeforeInstall(savedState As IDictionary) MyBase.OnBeforeInstall(savedState) Try Dim cfgFilePath As String Dim period As String Dim recalc As String cfgFilePath = Context.Parameters("config") If cfgFilePath = String.Empty Then Console.WriteLine(ConfigReader.UsageToolTip) Throw New InstallException("Missing parameter: 'config'.") End If period = Context.Parameters("period") If period = String.Empty Then period = "2" ' 2 ������ ElseIf Not IsInteger(period) Then Console.WriteLine(ConfigReader.UsageToolTip) Throw New InstallException("Invalid parameter: 'period'.") End If Console.WriteLine(String.Format("Period = {0}", period)) recalc = Context.Parameters("recalc") If recalc = String.Empty Then recalc = "30" ' 30 ����� ElseIf Not IsInteger(recalc) Then Console.WriteLine(ConfigReader.UsageToolTip) Throw New InstallException("Invalid parameter: 'recalc'.") End If Console.WriteLine(String.Format("Recalc = {0}", recalc)) Dim regKey As RegistryKey regKey = Registry.LocalMachine.OpenSubKey(ConfigReader.RegistryKeyPath, True) If regKey Is Nothing Then regKey = Registry.LocalMachine.CreateSubKey(ConfigReader.RegistryKeyPath, RegistryKeyPermissionCheck.ReadWriteSubTree) End If regKey.SetValue(ConfigReader.PeriodRegistryValueName, period) regKey.SetValue(ConfigReader.RecalcRegistryValueName, recalc) Dim filePaths As String() = cfgFilePath.Split(";"c) For i As Integer = 1 To filePaths.Count If i = 1 Then regKey.SetValue(ConfigReader.XmlConfigFileNameRegistryValueName, filePaths(i - 1)) Else regKey.SetValue(ConfigReader.XmlConfigFileNameRegistryValueName + (i - 1).ToString, filePaths(i - 1)) End If Console.WriteLine(String.Format("Config file no. {0}: {1}", i, filePaths(i - 1))) Next regKey.Close() Catch ex As Exception Console.WriteLine(ex.Message) Console.WriteLine(ex.StackTrace) Throw End Try End Sub Public Shared Function IsInteger(expression As String) As Boolean If expression Is Nothing Then Return False End If Dim length As Integer = expression.Length() If length = 0 Then Return False End If Dim i As Integer If expression.Chars(0) = "-" Then If length = 1 Then Return False End If End If For i = 1 To length - 1 Dim c As Char = expression.Chars(i) If c <= "/" OrElse c >= ":" Then Return False End If Next Return True End Function End Class