Imports System.Threading Imports EgtUILib Imports EgtWPFLib5 Public Class MainWindowM #Region "FIELDS" Private m_sDataRoot As String = String.Empty Private m_sConfigDir As String = String.Empty Private m_nDebug As Integer = 0 Private m_objMutex As New Mutex Private m_nInstance As Integer = 0 Private m_nUserLevel As Integer = 1 Private m_nKeyLevel As Integer = 0 Private m_nKeyOptions As UInteger = 0 Private m_sTempDir As String Private m_sMachinesRoot As String Friend ReadOnly Property sMachinesRoot As String Get Return m_sMachinesRoot End Get End Property Private m_sResourcesRoot As String Private m_sTablesRoot As String Private m_sLogFile As String ' Parametri che contengono lista delle lingue disponibili e lingua selezionata Friend m_LanguageList As New List(Of Language) Friend m_SelectedLanguage As Language #End Region ' FIELDS #Region "CONSTRUCTOR" Sub New() InitializeEgtEnvironment() End Sub #End Region ' CONSTRUCTOR #Region "METHODS" Private Sub InitializeEgtEnvironment() '' Abilito drag and drop 'Me.AllowDrop = True '' Title 'Application.Msn.NotifyColleagues(Application.EMITTITLE) ' 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 ' Impostazione path resources dir m_sResourcesRoot = m_sDataRoot & "\" & RES_DIR ' Impostazione direttorio per le macchine If GetMainPrivateProfileString(S_MACH, K_MACHINESDIR, "", m_sMachinesRoot) = 0 Then m_sMachinesRoot = m_sDataRoot & "\" & MACHINES_DFL_DIR End If ' Imposto direttorio per CamAuto SetCamAutoDir(m_sDataRoot & "\" & CAMAUTO_DIR) ' Verifico indice di istanza ManageSingleIstance() ' 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(3279, 18, 1, m_nKeyLevel) And EgtGetKeyOptions(3279, 18, 1, m_nKeyOptions) ' Inizializzazione generale di EgtInterface m_nDebug = GetMainPrivateProfileInt(S_GENERAL, K_DEBUG, 0) m_sLogFile = 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(m_nDebug, m_sLogFile, sLogMsg) ' Leggo direttorio dei messaggi (se manca uso direttorio di configurazione) Dim sMsgDir As String = String.Empty If GetMainPrivateProfileString(S_GENERAL, K_MESSAGESDIR, "", sMsgDir) = 0 Then sMsgDir = m_sConfigDir End If ' Leggo elenco lingue disponibili da file ini Dim nIndex As Integer = 1 Dim ReadLanguage As Language = GetMainPrivateProfileLanguage(S_LANGUAGES, K_LANGUAGE & nIndex) While Not IsNothing(ReadLanguage) m_LanguageList.Add(ReadLanguage) nIndex += 1 ReadLanguage = GetMainPrivateProfileLanguage(S_LANGUAGES, K_LANGUAGE & nIndex) End While ' Leggo file messaggi Dim sMsgName As String = String.Empty GetMainPrivateProfileString(S_GENERAL, K_MESSAGES, "", sMsgName) Dim sMsgFilePath As String = sMsgDir & "\EgalTechIta.txt" For Each Language In m_LanguageList If Language.Name = sMsgName Then m_SelectedLanguage = Language sMsgFilePath = sMsgDir & "\" & Language.FilePath End If Next If Not EgtLoadMessages(sMsgFilePath) Then EgtOutLog("Error in EgtLoadMessages") End If ' Leggo e imposto livello utilizzatore m_nUserLevel = Math.Min(m_nKeyLevel, GetMainPrivateProfileInt(S_GENERAL, K_USERLEVEL, 1)) ' 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) Dim sLuaBaseLib As String = String.Empty GetMainPrivateProfileString(S_LUA, K_BASELIB, "EgtBase", sLuaBaseLib) EgtLuaRequire(sLuaBaseLib) ' imposto IniFile a EgtInterface EgtSetIniFile(m_sIniFile) ' Info su opzioni chiave EgtOutLog("KeyOptions : " & bKey.ToString() & " " & m_nKeyOptions.ToString()) End Sub Private Sub ManageSingleIstance() Dim bCreated As Boolean Try m_objMutex = New Mutex(False, "Global\OmagOFFICE", 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("OmagOFFICER32") 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 ' se non trovati processi a 32 bit provo a 64 bit If Not bFound Then localProc = Process.GetProcessesByName("OmagOFFICER64") For Each p As Process In localProc If p.Id <> Process.GetCurrentProcess().Id Then bFound = True ShowWindow(p.MainWindowHandle, SW.RESTORE) Exit For End If Next End If ' 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 m_objMutex.Close() End Sub #End Region ' METHODS End Class