ef0dc65d9d
- ricompilazione con cambio versione - controllo modalità Visualizzatore (RedaOnly).
212 lines
9.1 KiB
VB.net
212 lines
9.1 KiB
VB.net
Imports System.Threading
|
|
Imports System.Math
|
|
Imports System.IO
|
|
Imports EgtUILib
|
|
Imports EgtWPFLib5
|
|
|
|
Friend Class MainWindowModel
|
|
|
|
#Region "FIELDS"
|
|
|
|
' Mutex che permette di controllare il numero massimo di istanze aperta contemporaneamente
|
|
Private m_objMutex As New Mutex
|
|
' Variabile che indica il numero di istanze aperte del programma
|
|
Friend m_nInstance As Integer = 0
|
|
' Path cartella Data
|
|
Friend m_sDataRoot As String = String.Empty
|
|
|
|
#End Region
|
|
|
|
#Region "CONSTRUCTOR"
|
|
|
|
Sub New()
|
|
' 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
|
|
IniFile.m_sDataRoot = m_sDataRoot
|
|
' Impostazione direttorio di configurazione
|
|
IniFile.m_sConfigDir = m_sDataRoot & "\" & CONF_DIR
|
|
' Impostazione direttorio per file temporanei
|
|
IniFile.m_sTempDir = m_sDataRoot & "\" & TEMP_DIR
|
|
' Impostazione direttorio per risorse programma
|
|
IniFile.m_sResourcesRoot = m_sDataRoot & "\" & RES_DIR
|
|
' Impostazione direttorio scripts lua
|
|
IniFile.m_sScriptsRoot = m_sDataRoot & "\" & SCRIPT_DIR
|
|
' Impostazione direttorio Ini file
|
|
IniFile.m_sIniFile = IniFile.m_sConfigDir & "\" & INI_FILE_NAME
|
|
' Impostazione path Ini file
|
|
EgtWPFLib5.IniFile.m_sIniFile = IniFile.m_sIniFile
|
|
' Impostazione direttorio della cartella Help
|
|
IniFile.m_sHelpDir = m_sDataRoot & "\" & HELP_DIR
|
|
' Impostazione direttorio della cartella Template
|
|
IniFile.m_TemplateDir = m_sDataRoot & "\" & TEMPLATE_DIR
|
|
' Impostazione direttorio della cartella MyProject di default
|
|
IniFile.m_MyProjectDir = m_sDataRoot & "\" & SAVE_DFL_NAMEDIR
|
|
' Verifico indice di istanza
|
|
ManageIstance()
|
|
' Se unica istanza, pulisco direttorio temporaneo
|
|
If GetMainPrivateProfileInt(S_GENERAL, K_INSTANCES, 0) = 1 Then VerifyAndEmptyDir(IniFile.m_sTempDir)
|
|
' 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)
|
|
Dim sNestKey As String = ""
|
|
EgtUILib.GetPrivateProfileString(S_LICENCE, K_NESTKEY, "", sNestKey, sLicFile)
|
|
EgtSetNestKey(sNestKey)
|
|
Dim bNetHwKey As Boolean = (GetPrivateProfileInt(S_GENERAL, K_NETKEY, 0, m_sIniFile) = 1)
|
|
EgtSetNetHwKey(bNetHwKey)
|
|
' Impostazioni per chiave di rete
|
|
Dim bNetKey As Boolean = (GetPrivateProfileInt(S_GENERAL, K_NETKEY, 0, m_sIniFile) = 1)
|
|
EgtSetNetHwKey(bNetKey)
|
|
Dim sLockId As String = ""
|
|
EgtUILib.GetPrivateProfileString(S_LICENCE, K_LOCKID, "", sLockId, sLicFile)
|
|
If Not String.IsNullOrEmpty(sLockId) Then
|
|
EgtSetLockId(sLockId)
|
|
End If
|
|
' Recupero livello e opzioni della chiave
|
|
Dim bKey As Boolean = EgtGetKeyLevel(3279, 2712, 1, IniFile.m_nKeyLevel) And
|
|
EgtGetKeyOptions(3279, 2712, 1, IniFile.m_nKeyOptions)
|
|
' Leggo e imposto livello utilizzatore
|
|
IniFile.m_nUserLevel = Math.Min(IniFile.m_nKeyLevel, GetMainPrivateProfileInt(S_GENERAL, K_USERLEVEL, 1))
|
|
'Inizializzazione generale di EgtInterface
|
|
IniFile.m_nDebug = GetMainPrivateProfileInt(S_GENERAL, K_DEBUG, 0)
|
|
Dim sLogFile As String = IniFile.m_sTempDir & "\" & GENLOG_FILE_NAME.Replace("#", m_nInstance.ToString())
|
|
Dim sLogMsg As String = "User " & Environment.UserName & "\" & Environment.MachineName & " (" & m_nInstance.ToString() & ")" & vbLf &
|
|
My.Application.Info.Description.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(IniFile.m_nDebug, sLogFile, sLogMsg)
|
|
' Carico i messaggi
|
|
OptionModule.ReadMessages()
|
|
' Carico direttorio doors
|
|
GetMainPrivateProfileString(S_DOORS, K_BASEDIR, "", IniFile.m_sDoorsDirPath)
|
|
' Assegno direttorio componenti
|
|
IniFile.m_CompoDir = IniFile.m_sDoorsDirPath & "\Compo"
|
|
' Assegno path file di Default
|
|
IniFile.m_DefaultIniFile = IniFile.m_CompoDir & "\" & DEFAULT_INI_FILE_NAME
|
|
'carico il file dei messaggi
|
|
OptionModule.ReadMessages()
|
|
If Not File.Exists(IniFile.m_DefaultIniFile) Then
|
|
Dim Msg As String = String.Format(EgtMsg(50179), Path.GetDirectoryName(IniFile.m_DefaultIniFile))
|
|
MessageBox.Show(Msg, EgtMsg(50101), MessageBoxButton.OK, MessageBoxImage.Error)
|
|
End
|
|
End If
|
|
'Inizializzo OptionModule
|
|
OptionModule.InitOptionModule()
|
|
' imposto dir font Nfe e font default
|
|
Dim sNfeDir As String = String.Empty
|
|
GetMainPrivateProfileString(S_GEOMDB, K_NFEFONTDIR, "", sNfeDir)
|
|
Dim sDefFont As String = String.Empty
|
|
GetMainPrivateProfileString(S_GEOMDB, K_DEFAULTFONT, "", sDefFont)
|
|
EgtSetFont(sNfeDir, sDefFont)
|
|
' imposto dir di default per libreria Lua e lancio libreria di base
|
|
Dim sLuaLibsDir As String = String.Empty
|
|
GetMainPrivateProfileString(S_LUA, K_LIBSDIR, "", sLuaLibsDir)
|
|
EgtSetLuaLibs(sLuaLibsDir)
|
|
IniFile.m_sLuaLibsDir = sLuaLibsDir
|
|
Dim sLuaBaseLib As String = String.Empty
|
|
GetMainPrivateProfileString(S_LUA, K_BASELIB, "EgtBase", sLuaBaseLib)
|
|
EgtLuaRequire(sLuaBaseLib)
|
|
' Imposto path IniFile
|
|
EgtSetIniFile(IniFile.m_sIniFile)
|
|
' Imposto la modalità di lettura dei file ddf
|
|
|
|
End Sub
|
|
|
|
#End Region
|
|
|
|
#Region "METHODS"
|
|
|
|
''' <summary>
|
|
''' Funzione che permette di gestire il numero di istanze del programma attive contemporaneamente
|
|
''' </summary>
|
|
Private Sub ManageIstance()
|
|
Dim bCreated As Boolean
|
|
Try
|
|
m_objMutex = New Mutex(False, "Global\EgtDOORCreator", bCreated)
|
|
Catch
|
|
bCreated = False
|
|
End Try
|
|
If bCreated Then
|
|
' Prima istanza
|
|
m_nInstance = 1
|
|
' Aggiorno stato istanze attive
|
|
WriteMainPrivateProfileString(S_GENERAL, K_INSTANCES, m_nInstance.ToString)
|
|
Else
|
|
' Leggo il massimo numero di istanze ammesse
|
|
Dim nMaxInst As Integer = GetMainPrivateProfileInt(S_GENERAL, K_MAXINST, 1)
|
|
nMaxInst = Max(1, Min(nMaxInst, 32))
|
|
' Cerco il primo indice di istanza libero (max 32)
|
|
Dim nTmp As Integer = GetMainPrivateProfileInt(S_GENERAL, K_INSTANCES, 0)
|
|
m_nInstance = 1
|
|
Dim nMask As Integer = 1
|
|
While (nTmp And nMask) <> 0 And m_nInstance <= m_nInstance
|
|
m_nInstance += 1
|
|
nMask *= 2
|
|
End While
|
|
' Se l'indice supera il massimo
|
|
If m_nInstance > nMaxInst 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("EgtDOORCreatorR32")
|
|
For Each p As Process In localProc
|
|
If p.Id <> Process.GetCurrentProcess().Id Then
|
|
bFound = True
|
|
ShowWindow(p.MainWindowHandle, SW.SHOWMAXIMIZED)
|
|
Exit For
|
|
End If
|
|
Next
|
|
' se non trovati processi a 32 bit provo a 64 bit
|
|
If Not bFound Then
|
|
localProc = Process.GetProcessesByName("EgtDOORCreatorR64")
|
|
For Each p As Process In localProc
|
|
If p.Id <> Process.GetCurrentProcess().Id Then
|
|
bFound = True
|
|
ShowWindow(p.MainWindowHandle, SW.SHOWMAXIMIZED)
|
|
Exit For
|
|
End If
|
|
Next
|
|
End If
|
|
' esco dal programma
|
|
End
|
|
End If
|
|
' Aggiorno stato istanze attive
|
|
nTmp += (1 << (m_nInstance - 1))
|
|
WriteMainPrivateProfileString(S_GENERAL, K_INSTANCES, nTmp.ToString())
|
|
End If
|
|
End Sub
|
|
|
|
''' <summary>
|
|
''' Funzione che cancella tutti i file in un direttorio o lo crea se non esiste
|
|
''' </summary>
|
|
Private Sub VerifyAndEmptyDir(sDir As String)
|
|
Try
|
|
Dim dir As DirectoryInfo = New DirectoryInfo(sDir)
|
|
If dir.Exists() Then
|
|
For Each file In dir.GetFiles()
|
|
Try
|
|
file.Delete()
|
|
Catch ex As Exception
|
|
End Try
|
|
Next
|
|
Else
|
|
dir.Create()
|
|
End If
|
|
Catch ex As Exception
|
|
End Try
|
|
End Sub
|
|
|
|
#End Region
|
|
|
|
End Class
|