Advertisement
Robomatics

POV-Ray Distribute Client

Apr 21st, 2013
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 21.02 KB | None | 0 0
  1.  
  2. Imports System.Net.Sockets
  3. Imports System
  4. Imports System.Runtime.InteropServices
  5. Imports System.Security.Principal
  6. Imports System.Security.Permissions
  7. Imports System.IO
  8.  
  9.  
  10. Public Class Form1
  11.  
  12.     Dim jobpath As String = ""
  13.     Dim jobini As String = ""
  14.     Dim povinipath As String = ""
  15.     Dim currentframe As String = ""
  16.     Dim running As Boolean = False
  17.     Dim framez As Integer = 1
  18.     Dim widthz As Integer = 320
  19.     Dim heightz As Integer = 240
  20.     Dim framedone As Boolean = False
  21.     Dim outputimage As String
  22.     Dim outputimagepath As String
  23.     Dim maxframe As Integer
  24.     Dim sourcepath As String = ""
  25.     Dim framestart As TimeSpan
  26.     Dim lastini As String
  27.     Dim copytry As Boolean = False
  28.     Dim networkpath As String = ""
  29.  
  30.     Dim server As String
  31.     Dim publisher As New UdpClient()
  32.     Dim subscriber As New UdpClient()
  33.     Dim mycomputername As String = Environment.MachineName
  34.     Dim mycomputerconnections() As Net.NetworkInformation.NetworkInterface
  35.  
  36.     Dim MCSub As New UdpClient(10100)
  37.  
  38.     'Set Job Path
  39.     Private Sub TBName_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TBName.TextChanged
  40.         jobpath = "C:\POVStorage\" & TBName.Text
  41.     End Sub
  42.  
  43.     'Render Start
  44.     Private Sub renderstart(ByVal rootdir As String)
  45.  
  46.         If running = False Then
  47.             LBLStatus.Text = "Copying"
  48.             If IO.Directory.Exists(jobpath) = False Then
  49.                 'DirectoryCopy(rootdir, jobpath, True)
  50.                 IO.Directory.CreateDirectory(jobpath)
  51.                 My.Computer.FileSystem.CopyDirectory(rootdir, jobpath, FileIO.UIOption.AllDialogs)
  52.             End If
  53.  
  54.             Dim filelist() As String
  55.             filelist = IO.Directory.GetFiles(jobpath)
  56.  
  57.             maxframez()
  58.  
  59.             Dim ini As String = "naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaame"
  60.             For i = 0 To filelist.Count - 1
  61.                 Dim fName As String = filelist(i).Substring(jobpath.Length + 1)
  62.                 If fName.Contains("ini") And fName.Count < ini.Count Then
  63.                     ini = fName
  64.                 End If
  65.             Next
  66.             ini = IO.Path.Combine(jobpath, ini)
  67.             jobini = ini
  68.  
  69.             Dim filelines() As String
  70.             GC.Collect()
  71.             filelines = IO.File.ReadAllLines(ini)
  72.             GC.Collect()
  73.  
  74.             For i = 0 To filelines.Count - 1
  75.                 If filelines(i).Contains("Subset_Start_Frame") Then
  76.                     filelines(i) = "Subset_Start_Frame=" & framez
  77.                 End If
  78.                 If filelines(i).Contains("Subset_End_Frame") Then
  79.                     filelines(i) = "Subset_End_Frame=" & framez
  80.                 End If
  81.                 If filelines(i).Contains("Width") Then
  82.                     filelines(i) = "Width=" & widthz
  83.                 End If
  84.                 If filelines(i).Contains("Height") Then
  85.                     filelines(i) = "Height=" & heightz
  86.                 End If
  87.             Next
  88.  
  89.             GC.Collect()
  90.             IO.File.WriteAllLines(ini, filelines)
  91.             GC.Collect()
  92.  
  93.             framestart = My.Computer.Clock.LocalTime.TimeOfDay
  94.  
  95.             Dim maxstring As Integer = maxframe.ToString.Length
  96.             outputimage = jobini.Substring(0, jobini.Length - 4)
  97.             outputimagepath = outputimage & framez.ToString().PadLeft(maxstring, "0") & ".png"
  98.             If IO.File.Exists(outputimagepath) = True Then
  99.                 IO.File.Delete(outputimagepath)
  100.             End If
  101.  
  102.             running = True
  103.             Process.Start(My.Settings.POVDir, "/RENDER " & ini)
  104.             lastini = ini
  105.         End If
  106.  
  107.         TimerPOV.Enabled = True
  108.     End Sub
  109.  
  110.     'Find EXE, setup initial POV
  111.     Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
  112.         OFDPovEngine.ShowDialog()
  113.     End Sub
  114.     Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OFDPovEngine.FileOk
  115.         My.Settings.POVDir = OFDPovEngine.FileName
  116.  
  117.         Dim mydocz() As String = IO.Directory.GetDirectories(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments))
  118.         Dim povdir As String = ""
  119.         For Each Dir As String In mydocz
  120.             If Dir.ToLower.Contains("pov-ray") Then
  121.                 povdir = Dir
  122.             End If
  123.         Next
  124.  
  125.         If povdir = "" Then
  126.             MsgBox("Unable to Find 'pvengine.ini' Please manually find")
  127.             OFDPovINI.ShowDialog()
  128.             Return
  129.         End If
  130.  
  131.         Dim povvz() As String = IO.Directory.GetDirectories(povdir)
  132.         Dim povv As String = ""
  133.         For Each Dir As String In povvz
  134.             If Dir.ToLower.Contains("v") And Dir.Contains(".") Then
  135.                 povv = Dir
  136.             End If
  137.         Next
  138.  
  139.         If povv = "" Then
  140.             MsgBox("Unable to Find 'pvengine.ini' Please manually find")
  141.             OFDPovINI.ShowDialog()
  142.             Return
  143.         End If
  144.  
  145.         Dim povini As String = IO.Path.Combine(povv & "\ini")
  146.  
  147.         Dim poviniz() As String = IO.Directory.GetFiles(povini)
  148.         For Each file As String In poviniz
  149.             If file.Contains("pvengine.ini") And file.Substring(file.LastIndexOf("\") + 1).Length = 12 Then
  150.                 povinipath = file
  151.             End If
  152.         Next
  153.  
  154.         If povinipath = "" Then
  155.             MsgBox("Unable to Find 'pvengine.ini' Please manually find")
  156.             OFDPovINI.ShowDialog()
  157.             Return
  158.         End If
  159.  
  160.         INIsetup()
  161.  
  162.     End Sub
  163.     Private Sub OFDPovINI_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OFDPovINI.FileOk
  164.         povinipath = OFDPovINI.FileName
  165.         INIsetup()
  166.     End Sub
  167.     Private Sub INIsetup()
  168.  
  169.         Dim filelines() As String
  170.  
  171.         GC.Collect()
  172.         filelines = IO.File.ReadAllLines(povinipath)
  173.         GC.Collect()
  174.         Dim filelinez As New List(Of String)
  175.         For i = 0 To filelines.Count - 1
  176.             filelinez.Add(filelines(i))
  177.         Next
  178.  
  179.         Dim anyoneinstance As Boolean = False
  180.         Dim anyoneinstanceset As Boolean = False
  181.         For i = 0 To filelinez.Count - 1
  182.             If filelinez(i).Contains("[Permitted Input Paths]") Then
  183.                 filelinez(i + 1) = "1=c:\"
  184.             End If
  185.             If filelinez(i).Contains("[Permitted Output Paths]") Then
  186.                 filelinez(i + 1) = "1=c:\"
  187.             End If
  188.             If filelinez(i).Contains("HideNewUserHelp") Then
  189.                 filelinez(i) = "HideNewUserHelp=1"
  190.             End If
  191.  
  192.             If filelinez(i).Contains("RenderCompleteSound") Then
  193.                 filelinez(i) = "RenderCompleteSound=1"
  194.             End If
  195.             If filelinez(i).Contains("OutputFileLocation") Then
  196.                 filelinez(i) = "OutputFileLocation=1"
  197.             End If
  198.             If filelinez(i).Contains("RenderwinClose") Then
  199.                 filelinez(i) = "RenderwinClose=1"
  200.             End If
  201.             If filelinez(i).Contains("ParserErrorSound") Then
  202.                 filelinez(i) = "ParserErrorSound=1"
  203.             End If
  204.             If filelinez(i).Contains("OneInstanceSet") Then
  205.                 filelinez(i) = "OneInstanceSet=1"
  206.                 anyoneinstanceset = True
  207.             End If
  208.             If filelinez(i).Contains("OneInstance=") Then
  209.                 filelinez(i) = "OneInstance=1"
  210.                 anyoneinstance = True
  211.             End If
  212.             If filelinez(i).Contains("ItsAboutTime") Then
  213.                 filelinez(i) = "ItsAboutTime=1500000000"
  214.             End If
  215.  
  216.         Next
  217.  
  218.         If anyoneinstance = False Then
  219.             filelinez.Add("OneInstance=1")
  220.         End If
  221.         If anyoneinstanceset = False Then
  222.             filelinez.Add("OneInstanceSet=1")
  223.         End If
  224.  
  225.         Dim filelined(filelinez.Count - 1) As String
  226.         For i = 0 To filelinez.Count - 1
  227.             filelined(i) = filelinez(i)
  228.         Next
  229.  
  230.         GC.Collect()
  231.         IO.File.WriteAllLines(povinipath, filelined)
  232.         GC.Collect()
  233.  
  234.         'If MsgBox("Windows 7?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
  235.         '    Process.Start(Environment.SystemDirectory & "\netsh.exe", "advfirewall firewall add rule name=""allow PVD"" dir=in program=""" & IO.Directory.GetCurrentDirectory.ToString & "\POVRay Distribute Client.exe" & """ security=authnoencap action=allow")
  236.         '    Process.Start(Environment.SystemDirectory & "\netsh.exe", "advfirewall firewall add rule name=""allow PVD"" dir=out program=""" & IO.Directory.GetCurrentDirectory.ToString & "\POVRay Distribute Client.exe" & """ security=authnoencap action=allow")
  237.         'Else
  238.         '    MsgBox("Then auto-connect may not work unless you open ports manually")
  239.         'End If
  240.  
  241.     End Sub
  242.  
  243.     'Pic Complete Monitor
  244.     Private Sub TimerPOV_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerPOV.Tick
  245.  
  246.         Dim elapsedtime As TimeSpan = My.Computer.Clock.LocalTime.TimeOfDay - framestart
  247.         If elapsedtime.TotalMinutes > 1 Then
  248.             framestart = My.Computer.Clock.LocalTime.TimeOfDay
  249.             Process.Start(My.Settings.POVDir, "/RENDER " & lastini)
  250.  
  251.         End If
  252.  
  253.  
  254.         Dim maxstring As Integer = maxframe.ToString.Length
  255.         outputimage = jobini.Substring(0, jobini.Length - 4)
  256.         outputimagepath = outputimage & framez.ToString().PadLeft(maxstring, "0") & ".png"
  257.         If IO.File.Exists(outputimagepath) = True And FileInUse(outputimagepath) = False Then
  258.             LBLStatus.Text = "Ready"
  259.             If running = True Then
  260.                 Threading.Thread.Sleep(2000)
  261.                 framedone = True
  262.             End If
  263.             running = False
  264.             TimerPOV.Enabled = False
  265.  
  266.         Else
  267.             LBLStatus.Text = "Running"
  268.             running = True
  269.         End If
  270.  
  271.     End Sub
  272.  
  273.     Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
  274.         My.Settings.Save()
  275.     End Sub
  276.  
  277.     'Form Load
  278.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  279.  
  280.         mycomputerconnections = Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces
  281.         TBHostName.Text = mycomputername
  282.         '
  283.         publisher.Client.Blocking = False
  284.         publisher.ExclusiveAddressUse = False
  285.         subscriber.Client.ReceiveTimeout = 100
  286.         subscriber.Client.Blocking = False
  287.         subscriber.ExclusiveAddressUse = False
  288.         MCSub.Client.ReceiveTimeout = 100
  289.         MCSub.Client.Blocking = False
  290.         MCSub.JoinMulticastGroup(Net.IPAddress.Parse("239.80.8.5"), 4)
  291.         MCSub.Client.MulticastLoopback = True
  292.         MCSub.Client.EnableBroadcast = True
  293.  
  294.         If My.Settings.POVDir Is Nothing Or My.Settings.POVDir = "" Then
  295.             MsgBox("POV Directory Not Set, please point to POV Engine.")
  296.             OFDPovEngine.ShowDialog()
  297.         End If
  298.  
  299.         For i = 0 To mycomputerconnections.Length - 1
  300.             CBConnections.Items.Add(mycomputerconnections(i).Name)
  301.         Next
  302.  
  303.         CBConnections.SelectedIndex = My.Settings.Connection
  304.  
  305.         TimerMCSub.Enabled = True
  306.  
  307.     End Sub
  308.  
  309.     'Max Frame
  310.     Private Sub maxframez()
  311.  
  312.         Dim rootdir As String = jobpath
  313.         Dim filelist() As String = IO.Directory.GetFiles(rootdir)
  314.         Dim ini As String = "naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaame"
  315.         For i = 0 To filelist.Count - 1
  316.             Dim fName As String = filelist(i).Substring(rootdir.Length + 1)
  317.             If fName.Contains("ini") And fName.Count < ini.Count Then
  318.                 ini = fName
  319.             End If
  320.         Next
  321.         ini = IO.Path.Combine(rootdir, ini)
  322.  
  323.         Dim filelines() As String
  324.         GC.Collect()
  325.         filelines = IO.File.ReadAllLines(ini)
  326.         GC.Collect()
  327.  
  328.         For i = 0 To filelines.Count - 1
  329.             If filelines(i).Contains("Final_Frame") Then
  330.                 maxframe = filelines(i).Substring(12)
  331.             End If
  332.         Next
  333.  
  334.     End Sub
  335.  
  336.     'UDP Monitor
  337.     Private Sub TimerUDP_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerUDP.Tick
  338.  
  339.         Dim stringz As String = ""
  340.         Dim Receive As String = ""
  341.  
  342.         Try
  343.             Dim ep As System.Net.IPEndPoint = New System.Net.IPEndPoint(System.Net.IPAddress.Any, 0)
  344.             Dim rcvbytes() As Byte = subscriber.Receive(ep)
  345.             Receive = System.Text.Encoding.ASCII.GetString(rcvbytes)
  346.         Catch ex As Exception
  347.         End Try
  348.  
  349.         If Receive <> "" Then
  350.             If Receive.Contains("%PVD%N") = True Then
  351.                 stringz = "%PVD%C"
  352.                 My.Settings.Server = Receive.Substring(6)
  353.                 LBLStatus.Text = "Ready"
  354.             End If
  355.             If Receive.Contains("%PVD%J") Then
  356.  
  357.                 Dim reclines() As String = Receive.Split("%")
  358.                 Dim Jobname As String = reclines(2).Substring(1)
  359.                 networkpath = reclines(3).Substring(1)
  360.                 widthz = reclines(4).Substring(1)
  361.                 heightz = reclines(5).Substring(1)
  362.                 framez = reclines(6).Substring(1)
  363.                 stringz = "%PVD%J" & framez
  364.  
  365.                 If networkpath <> "" Then
  366.                     sourcepath = networkpath & "\" & Jobname
  367.                 Else
  368.                     sourcepath = "\\" & My.Settings.Server & "\POVShare\" & Jobname
  369.                 End If
  370.  
  371.                 TBName.Text = Jobname
  372.                 TBFrame.Text = framez
  373.                 renderstart(sourcepath)
  374.  
  375.             End If
  376.         End If
  377.  
  378.         If stringz = "" And framedone = True Then
  379.             framedone = False
  380.  
  381.             If IO.Directory.Exists(sourcepath & "Images") = False Then
  382.                 IO.Directory.CreateDirectory(sourcepath & "Images")
  383.             End If
  384.  
  385.             Dim destination As String = sourcepath & "Images" & outputimagepath.Substring(outputimagepath.LastIndexOf("\"))
  386.             stringz = "%PVD%F" & framez & "%L" & destination
  387.  
  388.             If copytry = False Then
  389.                 Try
  390.                     TBFiles.Text = destination
  391.                     IO.File.Copy(outputimagepath, destination, True)
  392.  
  393.                 Catch ex As Exception
  394.                     copytry = True
  395.                     TBFiles.BackColor = Color.Black
  396.                     TBFiles.ForeColor = Color.Red
  397.                     TBFiles.Text = jobpath
  398.                 End Try
  399.             End If
  400.  
  401.         End If
  402.  
  403.         If stringz <> "" Then
  404.             Try
  405.                 Dim sendbytes() As Byte = System.Text.Encoding.ASCII.GetBytes(stringz)
  406.                 publisher.Send(sendbytes, sendbytes.Length)
  407.             Catch ex As Exception
  408.             End Try
  409.         End If
  410.  
  411.     End Sub
  412.  
  413.     'Connect
  414.     Private Sub PBConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PBConnect.Click
  415.  
  416.         If TBPortPub.Text Is Nothing Or TBPortPub.Text = "" Then
  417.             MsgBox("PORTA needed.")
  418.             Return
  419.         End If
  420.         If TBPortSub.Text Is Nothing Or TBPortSub.Text = "" Then
  421.             MsgBox("PORTB needed.")
  422.             Return
  423.         End If
  424.  
  425.         Connect()
  426.     End Sub
  427.     Private Sub Connect()
  428.  
  429.         Dim pinger As New Net.NetworkInformation.Ping 'Does it ping?
  430.         Try
  431.             Dim pingreply As Net.NetworkInformation.PingReply = pinger.Send(My.Settings.Server, 1000)
  432.             If pingreply.Status <> Net.NetworkInformation.IPStatus.Success Then
  433.                 MsgBox("Unable to Ping, verify your IP and PLC addresses are correct", MsgBoxStyle.Exclamation)
  434.                 Return
  435.             End If
  436.         Catch ex As Exception
  437.             MsgBox("Ping Error on, verify your IP and PLC addresses are correct", MsgBoxStyle.Exclamation) 'Ping fail so hard that you gotta have further info??
  438.             Return
  439.         End Try
  440.  
  441.         publisher.Client.Dispose()
  442.         publisher = New UdpClient()
  443.         publisher.Client.Blocking = False
  444.         publisher.ExclusiveAddressUse = False
  445.         subscriber.Client.Dispose()
  446.         subscriber = New UdpClient()
  447.         subscriber.Client.ReceiveTimeout = 100
  448.         subscriber.Client.Blocking = False
  449.         subscriber.ExclusiveAddressUse = False
  450.  
  451.         subscriber.Client.Bind(New Net.IPEndPoint(Net.IPAddress.Any, TBPortPub.Text))
  452.  
  453.         publisher.Connect(My.Settings.Server, TBPortSub.Text)
  454.  
  455.         TimerUDP.Enabled = True
  456.         LBLStatus.Text = "Waiting for Connection"
  457.     End Sub
  458.  
  459.     'Directory Copy
  460.     Private Shared Sub DirectoryCopy( _
  461.         ByVal sourceDirName As String, _
  462.         ByVal destDirName As String, _
  463.         ByVal copySubDirs As Boolean)
  464.  
  465.         Dim dir As DirectoryInfo = New DirectoryInfo(sourceDirName)
  466.         Dim dirs As DirectoryInfo() = dir.GetDirectories()
  467.  
  468.         If Not dir.Exists Then
  469.             Throw New DirectoryNotFoundException( _
  470.                 "Source directory does not exist or could not be found: " _
  471.                 + sourceDirName)
  472.         End If
  473.  
  474.         If Not Directory.Exists(destDirName) Then
  475.             Directory.CreateDirectory(destDirName)
  476.         End If
  477.  
  478.         Dim files As FileInfo() = dir.GetFiles()
  479.         For Each file In files
  480.             Dim temppath As String = Path.Combine(destDirName, file.Name)
  481.             file.CopyTo(temppath, True)
  482.         Next file
  483.  
  484.         If copySubDirs Then
  485.             For Each subdir In dirs
  486.                 Dim temppath As String = Path.Combine(destDirName, subdir.Name)
  487.                 DirectoryCopy(subdir.FullName, temppath, copySubDirs)
  488.             Next subdir
  489.         End If
  490.     End Sub
  491.  
  492.     'MCSub
  493.     Private Sub TimerMCSub_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerMCSub.Tick
  494.  
  495.         Dim ep As Net.IPEndPoint = New Net.IPEndPoint(Net.IPAddress.Parse("239.80.8.5"), 10100)
  496.         Try
  497.             Dim rcvbytes() As Byte = MCSub.Receive(ep)
  498.             Dim MCSubRcv As String = System.Text.Encoding.ASCII.GetString(rcvbytes)
  499.  
  500.             If MCSubRcv.Contains("%PVD%MCS") Then
  501.                 Dim rcvlines() As String = MCSubRcv.Split("%")
  502.                 TBServer.Text = rcvlines(3)
  503.                 TBPortPub.Text = rcvlines(4)
  504.                 TBPortSub.Text = rcvlines(5)
  505.                 TimerMCSub.Enabled = False
  506.  
  507.                 Try
  508.                     Dim stringz As String = "%PVD%MCP%" & mycomputername & "%" & TBDescription.Text
  509.                     Dim sendbytes() As Byte = System.Text.Encoding.ASCII.GetBytes(stringz)
  510.                     MCSub.Send(sendbytes, sendbytes.Length, ep)
  511.                 Catch ex As Exception
  512.  
  513.                 End Try
  514.  
  515.                 Connect()
  516.             End If
  517.  
  518.         Catch ex As Exception
  519.         End Try
  520.     End Sub
  521.  
  522.     'Connection Selection
  523.     Private Sub CBConnections_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CBConnections.SelectedIndexChanged
  524.         For i = 0 To mycomputerconnections(CBConnections.SelectedIndex).GetIPProperties.UnicastAddresses.Count - 1
  525.  
  526.             If mycomputerconnections(CBConnections.SelectedIndex).GetIPProperties.UnicastAddresses(i).Address.AddressFamily = Net.Sockets.AddressFamily.InterNetwork Then
  527.  
  528.                 Dim bytez() As Byte = mycomputerconnections(CBConnections.SelectedIndex).GetIPProperties.UnicastAddresses(i).Address.GetAddressBytes
  529.                 Dim AddressString As String = bytez(0) & "." & bytez(1) & "." & bytez(2) & "." & bytez(3)
  530.                 Dim ipep As New Net.IPEndPoint(Net.IPAddress.Parse(AddressString), 10100)
  531.  
  532.                 Try
  533.                     MCSub.Close()
  534.                     MCSub = New Net.Sockets.UdpClient(Net.Sockets.AddressFamily.InterNetwork)
  535.                     MCSub.Client.Blocking = False
  536.                     MCSub.Client.ReceiveTimeout = 100
  537.                     MCSub.ExclusiveAddressUse = False
  538.                     MCSub.Client.MulticastLoopback = True
  539.                     MCSub.EnableBroadcast = True
  540.                     MCSub.Client.Bind(ipep)
  541.                     MCSub.JoinMulticastGroup(Net.IPAddress.Parse("239.80.8.5"), 4)
  542.                     LBConnectStatus.ForeColor = Color.LimeGreen
  543.                     LBConnectStatus.Text = "√"
  544.                     My.Settings.Connection = CBConnections.SelectedIndex
  545.                     My.Settings.Save()
  546.                 Catch ex As Exception
  547.                     LBConnectStatus.ForeColor = Color.Red
  548.                     LBConnectStatus.Text = "X"
  549.                 End Try
  550.  
  551.             End If
  552.  
  553.         Next
  554.     End Sub
  555.  
  556.     Public Function FileInUse(ByVal sFile As String) As Boolean
  557.         Dim thisFileInUse As Boolean = False
  558.         If System.IO.File.Exists(sFile) Then
  559.             Try
  560.                 Using f As New IO.FileStream(sFile, FileMode.Open, FileAccess.ReadWrite, FileShare.None)
  561.                     thisFileInUse = False
  562.                 End Using
  563.             Catch
  564.                 thisFileInUse = True
  565.             End Try
  566.         End If
  567.         Return thisFileInUse
  568.     End Function
  569.  
  570. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement