Visual Basic .NET
Visual Basic .NET
This page serves as a brief VB.net documentation with focus on Oni-related aspects.
Projects
- Simple Converter GUI (for OniSplit)
- TRAM setup assistant
Basic knowledge
- Q: How can I use functions from another class?
- A: First condition: The function must be a "Shared" one. For example "Shared Function GetApp()". Second condition: in the target code, the class must be written beforehand (for example "Oni.GetApp" whereby "Oni" is the source class's name).
Code snippets
Common functions that are shared among VB.net projects should have their own class.
That way, the functions don't need be rewritten each time and it helps to keep the code more clear.
Class Oni
Functions in this class:
- GetApp - returns app path (type string)
- GetAE - returns AE home path (type string) (e.g. C:\Oni)
- GetXSI - returns Mod Tool path (type string) (e.g. C:\Softimage\Softimage_Mod_Tool_7.5\Application\bin)
- GetOniSplit - outputs an array with (0) as path (type string) and (1) as version (type string)
Imports System.IO ' for files and directories
Imports Microsoft.Win32 ' for registry keys
Public Class Oni
Shared Function GetApp()
Return Application.StartupPath().ToString()
End Function
Shared Function ReadRegStr(RootKey, Key, Value, RegType)
Dim oCtx, oLocator, oReg, oInParams, oOutParams
oCtx = CreateObject("WbemScripting.SWbemNamedValueSet")
oCtx.Add("__ProviderArchitecture", RegType)
oLocator = CreateObject("Wbemscripting.SWbemLocator")
oReg = oLocator.ConnectServer("", "root\default", "", "", , , , oCtx).Get("StdRegProv")
oInParams = oReg.Methods_("GetStringValue").InParameters
oInParams.hDefKey = RootKey
oInParams.sSubKeyName = Key
oInParams.sValueName = Value
oOutParams = oReg.ExecMethod_("GetStringValue", oInParams, , oCtx)
ReadRegStr = oOutParams.sValue
End Function
Shared Function GetAE()
Dim OS_bitness As Integer
Dim WshShell = CreateObject("WScript.Shell")
If InStr(WshShell.RegRead("HKLM\HARDWARE\DESCRIPTION\System\CentralProcessor\0\Identifier"), "64") > 0 Then
OS_bitness = 64
Else
OS_bitness = 32
End If
Const HKEY_LOCAL_MACHINE = &H80000002
Return ReadRegStr(HKEY_LOCAL_MACHINE, _
"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{B67333BB-1CF9-4EFD-A40B-E25B5CB4C8A7}}_is1", _
"InstallLocation", _
OS_bitness)
End Function
Shared Function GetXsi()
Dim oRegKey As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\\Softimage\\SOFTIMAGE Application")
Dim XsiDir As String
Dim FoundXsi As Boolean = False
Dim Arr = oRegKey.GetSubKeyNames
For Each n In Arr
If InStr(n, "Softimage_Mod_Tool_7.5|Application|bin") > 0 Then
XsiDir = Replace(n, "|", "\")
If Directory.Exists(XsiDir) = True Then
Return XsiDir
FoundXsi = True
End If
End If
Next
If FoundXsi = False Then
Return ""
End If
oRegKey.Close()
End Function
Shared Function GetOniSplit() As String()
Dim OSpath As String = ""
Dim FSO = CreateObject("Scripting.FileSystemObject")
If File.Exists(Application.StartupPath().ToString & "\OniSplit.exe") Then
OSpath = Application.StartupPath().ToString & "\OniSplit.exe"
Return New String() {OSpath, FSO.GetFileVersion(OSpath)}
ElseIf File.Exists(GetAE() & "AE\Tools\OniSplit.exe") Then
OSpath = GetAE() & "AE\Tools\OniSplit.exe"
Return New String() {OSpath, FSO.GetFileVersion(OSpath)}
Else
Return New String() {"", ""}
End If
End Function
End Class