Enable Javascript


Last Arduino/ESP project (click to open)
Ster inactiefSter inactiefSter inactiefSter inactiefSter inactief
 

Artikelindex

frmDbInit

frmDbInit:
Test of er al een NAW draait, of de database aanwezig is, welke DLL moet worden klaargezet.
De Function AppPath() staat in Module Diversen.


Een nogal eenvoudig window

  • FormBorderStyle=None
  • Startposition=CenterScreen
  • Label1.Text="NAW: Init..."
  • Button1.Visible=False
  • Button1.Text="OK"

Project NAW - frmDbInit.vb


Imports System.Management

Public Class frmDbInit
Private Const cnstFile = "NAW.s3db"
Private Const cnstPath = "\Database\"

Private Sub frmDbInit_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Show()
Dim apps As Process() = Process.GetProcessesByName("NAW")
If apps.Length > 1 Then ' draait al?
Me.Label1.Text = "NAW: Already activated"
Me.Button1.Visible = True
ElseIf Not FileDB() Then ' DB ok ?
MsgBox(DbPath & DbFile & " ???", MsgBoxStyle.Critical, "ERROR")
End
Else ' DLL klaarzetten en Form NAW openen
Dim dll As String = "System.Data.SQLite." & Choose(CPU, "x86", "AMD64", "IA64") & ".dll"
If IO.File.Exists(AppPath & dll) Then
IO.File.Copy(AppPath & dll, "System.Data.SQLite.dll", True)
Else
MsgBox(AppPath & dll & " ???", MsgBoxStyle.Critical, "ERROR")
        Close()
End If
frmNAW.Show()
Me.Close()
End If
End Sub

Private Function FileDB() As Boolean
' '' DB-path/file test 
AppPath = GetAppPath().ToLower.Replace("file:\", "")
    DbPath = AppPath.Substring(0, AppPath.LastIndexOf("\")) & cnstPath
    AppPath = AppPath & "\"
DbFile = cnstFile
If Not IO.File.Exists(DbPath & DbFile) Then Return False ' geen DB
ConnectionString = "Data Source=" & DbPath & DbFile
Return True
End Function

Private Function CPU() As Integer
' '' Return:  1=x86, 2=AMD64, 3=IA64 (Intel Itanium)
' '' 32 of 64 bits installatie
Dim arch As String = System.Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE")
Dim archWOW As String = System.Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432")
Dim installatie As String = ""
Dim c As String = GetCpuArch() 'processor
If archWOW IsNot Nothing AndAlso archWOW <> "" AndAlso archWOW.Contains("64") OrElse arch.Contains("64") Then
installatie = "x64"
If c = "x64" Then
Return 2
ElseIf c = "Itanium" Then
Return 3
End If
End If
Return 1
End Function

Private Function GetCpuArch() As String
Dim scope As New ManagementScope()
Dim query As New ObjectQuery("SELECT Architecture FROM Win32_Processor")
Dim search As New ManagementObjectSearcher(scope, query)
Dim results As ManagementObjectCollection = search.[Get]()
Dim e As ManagementObjectCollection.ManagementObjectEnumerator = results.GetEnumerator()
    e.MoveNext()
Dim arch As UShort = CUShort(e.Current("Architecture"))
Select Case arch
Case 0
Return "x86"
Case 1
Return "MIPS"
Case 2
Return "Alpha"
Case 3
Return "PowerPC"
Case 6
Return "Itanium"
Case 9
Return "x64"
Case Else
Return "Unknown Architecture (WMI ID " & arch.ToString() & ")"
End Select
End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' '' afbreken
Me.Close()
End Sub

End Class