Imports Microsoft.Win32.Registry

Public Class Registry

    ''' <summary>
    ''' 注册表存放根路径配置信息
    ''' </summary>
    Public Shared ReadOnly AutsRootDirPath As String = $"software\AUTS"

    ''' <summary>
    ''' 注册表存放数据服务名称配置信息
    ''' </summary>
    Public Shared ReadOnly _dataServiceName As String = $"AUTS_DataService"

    ''' <summary>
    ''' 注册表存放更新服务名称配置信息
    ''' </summary>
    Public Shared ReadOnly _updateServiceName As String = $"AUTS_UpdateService"



    ''' <summary>
    ''' 获取注册表是否存在
    ''' </summary>
    ''' <returns></returns>
    Public Shared Function RootDirExists() As Boolean
        Return LocalMachine.OpenSubKey(AutsRootDirPath) IsNot Nothing
    End Function


    ''' <summary>
    ''' 获取和设置Root根文件路径
    ''' </summary>
    ''' <returns></returns>
    Public Shared Property RootPath() As String
        Get
            Return LocalMachine.OpenSubKey($"{AutsRootDirPath}").GetValue("Path", "").ToString()
        End Get

        Set(value As String)
            LocalMachine.CreateSubKey($"{AutsRootDirPath}").SetValue("Path", value, Microsoft.Win32.RegistryValueKind.String)
        End Set
    End Property


    ''' <summary>
    ''' 获取和设置License路径
    ''' </summary>
    ''' <returns></returns>
    Public Shared Property LicensePath() As String
        Get
            Return LocalMachine.OpenSubKey($"{AutsRootDirPath}\License").GetValue("Path", "").ToString()
        End Get

        Set(value As String)
            LocalMachine.CreateSubKey($"{AutsRootDirPath}\License").SetValue("Path", value, Microsoft.Win32.RegistryValueKind.String)
        End Set
    End Property


    ''' <summary>
    ''' 获取和设置LocalDb路径
    ''' </summary>
    ''' <returns></returns>
    Public Shared Property LocalDb() As String
        Get
            Return LocalMachine.OpenSubKey($"{AutsRootDirPath}\LocalDb").GetValue("Path", "").ToString()
        End Get

        Set(value As String)
            LocalMachine.CreateSubKey($"{AutsRootDirPath}\LocalDb").SetValue("Path", value, Microsoft.Win32.RegistryValueKind.String)
        End Set
    End Property


    ''' <summary>
    ''' 获取和设置DataService名称
    ''' </summary>
    ''' <returns></returns>
    Public Shared Property DataServiceName() As String
        Get
            Return LocalMachine.OpenSubKey($"{AutsRootDirPath}\{_dataServiceName}").GetValue("Name", "").ToString()

        End Get

        Set(value As String)
            LocalMachine.CreateSubKey($"{AutsRootDirPath}\{_dataServiceName}").SetValue("Name", value, Microsoft.Win32.RegistryValueKind.String)
        End Set
    End Property


    ''' <summary>
    ''' 获取和设置DataService版本信息
    ''' </summary>
    ''' <returns></returns>
    Public Shared Property DataServiceVersion() As String
        Get
            Return LocalMachine.OpenSubKey($"{AutsRootDirPath}\{_dataServiceName}").GetValue("Version", "").ToString()
        End Get
        Set(value As String)
            LocalMachine.CreateSubKey($"{AutsRootDirPath}\{_dataServiceName}").SetValue("Version", value, Microsoft.Win32.RegistryValueKind.String)

        End Set
    End Property


    ''' <summary>
    ''' 获取和设置UpdateService名称
    ''' </summary>
    ''' <returns></returns>
    Public Shared Property UpdateServiceName() As String
        Get
            Return LocalMachine.OpenSubKey($"{AutsRootDirPath}\{_updateServiceName}").GetValue("Name", "").ToString()
        End Get
        Set(value As String)
            LocalMachine.CreateSubKey($"{AutsRootDirPath}\{_updateServiceName}").SetValue("Name", value, Microsoft.Win32.RegistryValueKind.String)
        End Set
    End Property


    ''' <summary>
    ''' 获取和设置UpdateService版本信息
    ''' </summary>
    ''' <returns></returns>
    Public Shared Property UpdateServiceVersion() As String
        Get
            Return LocalMachine.OpenSubKey($"{AutsRootDirPath}\{_updateServiceName}").GetValue("Version", "").ToString()
        End Get
        Set(value As String)
            LocalMachine.CreateSubKey($"{AutsRootDirPath}\{_updateServiceName}").SetValue("Version", value, Microsoft.Win32.RegistryValueKind.String)

        End Set
    End Property









    ''' <summary>
    ''' 获取和设置DataService文件路径
    ''' </summary>
    ''' <returns></returns>
    Public Shared Property DataServiceDirPath() As String
        Get
            Return LocalMachine.OpenSubKey($"{AutsRootDirPath}\{_dataServiceName}").GetValue("DirPath", "").ToString()

        End Get

        Set(value As String)
            LocalMachine.CreateSubKey($"{AutsRootDirPath}\{_dataServiceName}").SetValue("DirPath", value, Microsoft.Win32.RegistryValueKind.String)
        End Set
    End Property


    ''' <summary>
    ''' 获取和设置DataService启动程序名称
    ''' </summary>
    ''' <returns></returns>
    Public Shared Property DataServiceExeName() As String
        Get
            Return LocalMachine.OpenSubKey($"{AutsRootDirPath}\{_dataServiceName}").GetValue("ExeName", "").ToString()

        End Get

        Set(value As String)
            LocalMachine.CreateSubKey($"{AutsRootDirPath}\{_dataServiceName}").SetValue("ExeName", value, Microsoft.Win32.RegistryValueKind.String)
        End Set
    End Property


    ''' <summary>
    ''' 获取和设置UpdateService文件路径
    ''' </summary>
    ''' <returns></returns>
    Public Shared Property UpdateServiceDirPath() As String
        Get
            Return LocalMachine.OpenSubKey($"{AutsRootDirPath}\{_updateServiceName}").GetValue("DirPath", "").ToString()

        End Get

        Set(value As String)
            LocalMachine.CreateSubKey($"{AutsRootDirPath}\{_updateServiceName}").SetValue("DirPath", value, Microsoft.Win32.RegistryValueKind.String)
        End Set
    End Property


    ''' <summary>
    ''' 获取和设置UpdateService启动程序名称
    ''' </summary>
    ''' <returns></returns>
    Public Shared Property UpdateServiceExeName() As String
        Get
            Return LocalMachine.OpenSubKey($"{AutsRootDirPath}\{_updateServiceName}").GetValue("ExeName", "").ToString()
        End Get

        Set(value As String)
            LocalMachine.CreateSubKey($"{AutsRootDirPath}\{_updateServiceName}").SetValue("ExeName", value, Microsoft.Win32.RegistryValueKind.String)
        End Set
    End Property







End Class

