c43ef9c011
- modifiche per AboutBox - tolte costanti inutili - semplificato Ini file - modificata generazione licenza.
197 lines
6.7 KiB
VB.net
197 lines
6.7 KiB
VB.net
Imports System.Threading
|
|
Imports System.Math
|
|
Imports EgtUILib
|
|
Imports EgtWPFLib5
|
|
|
|
Public Class MainWindowM
|
|
|
|
#Region "FIELDS"
|
|
|
|
Private m_sDataRoot As String = String.Empty
|
|
Friend ReadOnly Property sDataRoot As String
|
|
Get
|
|
Return m_sDataRoot
|
|
End Get
|
|
End Property
|
|
|
|
Private m_sConfigDir As String = String.Empty
|
|
Public ReadOnly Property sConfigDir As String
|
|
Get
|
|
Return m_sConfigDir
|
|
End Get
|
|
End Property
|
|
|
|
Private m_sDbConnect As String = String.Empty
|
|
Public ReadOnly Property sDbConnect As String
|
|
Get
|
|
Return m_sDbConnect
|
|
End Get
|
|
End Property
|
|
|
|
Private m_sKeygenPath As String = String.Empty
|
|
Public ReadOnly Property sKeygenPath As String
|
|
Get
|
|
Return m_sKeygenPath
|
|
End Get
|
|
End Property
|
|
|
|
Private m_sKeygenDataDir As String = String.Empty
|
|
Public ReadOnly Property sKeygenDataDir As String
|
|
Get
|
|
Return m_sKeygenDataDir
|
|
End Get
|
|
End Property
|
|
|
|
Private m_objMutex As Mutex
|
|
|
|
Private m_nUserLevel As Integer = 1
|
|
Friend ReadOnly Property nUserLevel As Integer
|
|
Get
|
|
Return m_nUserLevel
|
|
End Get
|
|
End Property
|
|
|
|
Private m_nKeyLevel As Integer = 0
|
|
Friend ReadOnly Property nKeyLevel As Integer
|
|
Get
|
|
Return m_nKeyLevel
|
|
End Get
|
|
End Property
|
|
|
|
Private m_nKeyOptions As UInteger = 0
|
|
Friend ReadOnly Property nKeyOptions As UInteger
|
|
Get
|
|
Return m_nKeyOptions
|
|
End Get
|
|
End Property
|
|
|
|
Private m_sTempDir As String
|
|
Friend ReadOnly Property sTempDir As String
|
|
Get
|
|
Return m_sTempDir
|
|
End Get
|
|
End Property
|
|
Private m_sLogFile As String
|
|
Friend ReadOnly Property sLogFile As String
|
|
Get
|
|
Return m_sLogFile
|
|
End Get
|
|
End Property
|
|
|
|
#End Region ' FIELDS
|
|
|
|
#Region "CONSTRUCTOR"
|
|
|
|
Sub New()
|
|
InitializeEgtEnvironment()
|
|
End Sub
|
|
|
|
#End Region ' CONSTRUCTOR
|
|
|
|
#Region "METHODS"
|
|
|
|
Private Sub InitializeEgtEnvironment()
|
|
' Impostazione path radice per i dati
|
|
m_sDataRoot = System.AppDomain.CurrentDomain.BaseDirectory
|
|
If EgtUILib.GetPrivateProfileString(S_DATA, K_DATAROOT, "", m_sDataRoot, m_sDataRoot & "\" & DAT_FILE_NAME) = 0 Then
|
|
m_sDataRoot = System.AppDomain.CurrentDomain.BaseDirectory
|
|
End If
|
|
' Impostazione direttorio di configurazione
|
|
m_sConfigDir = m_sDataRoot & "\" & CONF_DIR
|
|
' Impostazione direttorio per file temporanei
|
|
m_sTempDir = m_sDataRoot & "\" & TEMP_DIR
|
|
' Impostazione path Ini file
|
|
IniFile.m_sIniFile = m_sConfigDir & "\" & INI_FILE_NAME
|
|
|
|
' Leggo e imposto il percorso di KeyGenerator
|
|
m_sKeygenPath = ""
|
|
GetMainPrivateProfileString(S_KEYGENERATOR, K_PATH, "C:\\EgtProg\\KeyGenerator", m_sKeygenPath)
|
|
m_sKeygenDataDir = ""
|
|
GetMainPrivateProfileString(S_KEYGENERATOR, K_DATADIR, "C:\\EgtProg\\KeyGenerator\\Data", m_sKeygenDataDir)
|
|
|
|
' Leggo e imposto la stringa di connessione al DB
|
|
m_sDbConnect = String.Empty
|
|
Dim sDbConnectBuilder As String = String.Empty
|
|
GetMainPrivateProfileString(S_CONNECTION, K_SERVER, "192.168.1.50", sDbConnectBuilder)
|
|
m_sDbConnect &= "Server=" & sDbConnectBuilder
|
|
GetMainPrivateProfileString(S_CONNECTION, K_PORT, "3307", sDbConnectBuilder)
|
|
m_sDbConnect &= ";Port=" & sDbConnectBuilder
|
|
GetMainPrivateProfileString(S_CONNECTION, K_DATABASE, "Topolino", sDbConnectBuilder)
|
|
m_sDbConnect &= ";Database=" & sDbConnectBuilder
|
|
GetMainPrivateProfileString(S_CONNECTION, K_UID, "Pippo", sDbConnectBuilder)
|
|
m_sDbConnect &= ";Uid=" & sDbConnectBuilder
|
|
GetMainPrivateProfileString(S_CONNECTION, K_PWD, "Pluto", sDbConnectBuilder)
|
|
m_sDbConnect &= ";Pwd=" & sDbConnectBuilder
|
|
ManageDb.DbPath = m_sDbConnect
|
|
ManageDb.DbConnection = New MySql.Data.MySqlClient.MySqlConnection(m_sDbConnect)
|
|
|
|
' Verifico istanza
|
|
ManageSingleInstance()
|
|
' Imposto tipo di chiave
|
|
EgtSetLockType(KEY_TYPE.HW)
|
|
' Leggo e imposto chiave di protezione
|
|
Dim sLicFileName As String = String.Empty
|
|
GetMainPrivateProfileString(S_GENERAL, K_LICENCE, LIC_FILE_NAME, sLicFileName)
|
|
Dim sLicFile As String = m_sConfigDir & "\" & sLicFileName
|
|
Dim sKey As String = String.Empty
|
|
EgtUILib.GetPrivateProfileString(S_LICENCE, K_KEY, "", sKey, sLicFile)
|
|
EgtSetKey(sKey)
|
|
' Recupero livello e opzioni della chiave
|
|
Dim bKey As Boolean = EgtGetKeyLevel(823, 19, 1, m_nKeyLevel) And
|
|
EgtGetKeyOptions(823, 19, 1, m_nKeyOptions)
|
|
' Inizializzazione generale di EgtInterface
|
|
m_sLogFile = m_sTempDir & "\" & LOG_FILE_NAME
|
|
Dim sLogMsg As String = "User " & Environment.MachineName & "\" & Environment.UserName & vbLf &
|
|
My.Application.Info.Title.ToString() & " ver. " &
|
|
My.Application.Info.Version.Major.ToString() &
|
|
"." & My.Application.Info.Version.Minor.ToString() &
|
|
(ChrW(97 - 1 + My.Application.Info.Version.Build)).ToString() &
|
|
My.Application.Info.Version.Revision.ToString()
|
|
EgtInit(0, m_sLogFile, sLogMsg)
|
|
EgtSetTempDir(m_sTempDir)
|
|
EgtSetIniFile(IniFile.m_sIniFile)
|
|
' Leggo e imposto livello utilizzatore
|
|
m_nUserLevel = Math.Min(m_nKeyLevel, GetMainPrivateProfileInt(S_GENERAL, K_USERLEVEL, 1))
|
|
' Info su opzioni chiave
|
|
EgtOutLog("KeyOptions : " & bKey.ToString() & " " & m_nKeyOptions.ToString())
|
|
End Sub
|
|
|
|
Private Sub ManageSingleInstance()
|
|
Dim bCreated As Boolean
|
|
Try
|
|
m_objMutex = New Mutex(False, "Global\LicenceManager", bCreated)
|
|
Catch
|
|
bCreated = False
|
|
End Try
|
|
If not bCreated Then
|
|
' porto in primo piano la prima istanza
|
|
Dim bFound As Boolean = False
|
|
' processi del programma a 32 bit
|
|
Dim localProc As Process() = Process.GetProcessesByName("LicenceManager32")
|
|
For Each p As Process In localProc
|
|
If p.Id <> Process.GetCurrentProcess().Id Then
|
|
bFound = True
|
|
ShowWindow(p.MainWindowHandle, 1)
|
|
Exit For
|
|
End If
|
|
Next
|
|
' esco dal programma
|
|
End
|
|
End If
|
|
End Sub
|
|
|
|
Friend Function GetKeyOption(nKeyOpt As KEY_OPT) As Boolean
|
|
Return ((m_nKeyOptions And nKeyOpt) <> 0)
|
|
End Function
|
|
|
|
Friend Sub Close()
|
|
' Terminazione generale di EgtInterface
|
|
EgtExit()
|
|
' Rilascio mutex
|
|
If Not IsNothing(m_objMutex) Then m_objMutex.Close()
|
|
End Sub
|
|
|
|
#End Region ' METHODS
|
|
|
|
End Class
|