16,555
社区成员
发帖
与我相关
我的任务
分享
Imports Microsoft.Win32
Namespace LzmTW.Lotus
Public Class Environment
Private gDirectory As String
Private gPath As String
Private gVersion As String
Private gFile As String
Private iniFile As String
Private ini As LzmTW.uSystem.iniFile '如 x:\Program Files\lotus\notes\notes.ini
Private Sub New()
Me.Initiliaze()
End Sub
''' <summary>
''' 如 x:\Program Files\lotus\notes\data
''' </summary>
Public Property Directory() As String
Get
Return gDirectory
End Get
Private Set(ByVal value As String)
gDirectory = value
End Set
End Property
''' <summary>
''' 如 x:\Program Files\lotus\notes
''' </summary>
Public Property Path() As String
Get
Return gPath
End Get
Private Set(ByVal value As String)
gPath = value
End Set
End Property
''' <summary>
''' 如 x:\Program Files\lotus\notes\notes.exe
''' </summary>
Public Property File() As String
Get
Return gFile
End Get
Private Set(ByVal value As String)
gFile = value
End Set
End Property
Public Property Version() As String
Get
Return gVersion
End Get
Private Set(ByVal value As String)
gVersion = value
End Set
End Property
Private Sub Initiliaze()
Dim LotusKey As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\Lotus")
If LotusKey Is Nothing Then Return
Dim NotesKey As RegistryKey = LotusKey.OpenSubKey("Notes")
If NotesKey Is Nothing Then Return
If NotesKey.SubKeyCount = 0 Then Return
Me.Version = NotesKey.GetSubKeyNames(NotesKey.SubKeyCount - 1) '取最新版本号
Dim VersionKey As RegistryKey = NotesKey.OpenSubKey(Me.Version)
With VersionKey
Me.Directory = .GetValue("DataPath").ToString
Me.Path = .GetValue("Path").ToString
Me.File = System.IO.Path.Combine(Me.Path, .GetValue("Name").ToString)
Me.iniFile = System.IO.Path.Combine(Me.Path, "notes.ini") 'notes.ini 文件
End With
ini = New LzmTW.uSystem.iniFile
ini.File = Me.iniFile
ini.CurrentSection = "Notes"
Me.Server = ini.GetValue("$AFSWServer")
Me.OAPath = ini.GetValue("$AFSWDBPath")
Me.MailPath = ini.GetValue("MailFile").Replace("/", "\")
Me.MailPath = Me.MailPath.Substring(0, Me.MailPath.IndexOf("\") + 1)
End Sub
Private Function IsChinese(ByVal c As Char) As Boolean
Return Not System.Text.Encoding.Unicode.GetBytes(c)(1) = 0
End Function
Private gServer As String
Public Property Server() As String
Get
Return gServer
End Get
Private Set(ByVal value As String)
gServer = value
End Set
End Property
Private gOAPath As String
Public Property OAPath() As String
Get
Return gOAPath
End Get
Private Set(ByVal value As String)
gOAPath = value
End Set
End Property
Private gMailPath As String
Public Property MailPath() As String
Get
Return gMailPath
End Get
Private Set(ByVal value As String)
gMailPath = value
End Set
End Property
Public Property UserID() As String
Get
Return ini.GetValue("KeyFilename").Replace(Me.SpecialChar, "")
End Get
Set(ByVal value As String)
ini.SetValue("KeyFilename", Me.GetSpecialString(value))
End Set
End Property
Public Property MailFile() As String
Get
Return ini.GetValue("MailFile").Replace(Me.SpecialChar, "")
End Get
Set(ByVal value As String)
ini.SetValue("MailFile", Me.GetSpecialString(value))
End Set
End Property
Private Function GetSpecialString(ByVal value As String) As String
If String.IsNullOrEmpty(value) Then Return ""
Dim b As New System.Text.StringBuilder
For index As Integer = 0 To value.Length - 1
Dim c As Char = value.Chars(index)
If Me.IsChinese(c) Then b.Append(Me.SpecialChar)
b.Append(c)
Next
Return b.ToString
End Function
Private ReadOnly SpecialChar As Char = Chr(19)
Private Shared gInstance As Environment
Private Shared internalObject As New Object
Friend Shared Function Instance() As Environment
If gInstance Is Nothing Then
SyncLock internalObject
If gInstance Is Nothing Then
gInstance = New Environment
End If
End SyncLock
End If
Return gInstance
End Function
End Class
End Namespace