Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Speech Link - NewLinkDialog.vb

NewLinkDialog.vb

Caricato da: Totem
Scarica il programma completo

  1. Imports System.Windows.Forms
  2. Imports Microsoft.Win32
  3.  
  4. Public Class NewLinkDialog
  5.     Private Function GetOpenCommandLine(ByVal Extension As String) As String
  6.         Dim RegKey As RegistryKey
  7.  
  8.         RegKey = Registry.ClassesRoot.OpenSubKey(Extension)
  9.         If RegKey Is Nothing Then
  10.             Return Nothing
  11.         End If
  12.  
  13.         Dim AppKeyName As String = RegKey.GetValue("")
  14.         RegKey = Registry.ClassesRoot.OpenSubKey(AppKeyName & "\shell\open\command")
  15.  
  16.         If RegKey Is Nothing Then
  17.             Return Nothing
  18.         End If
  19.  
  20.         Return RegKey.GetValue("")
  21.     End Function
  22.  
  23.     Public ReadOnly Property FileName() As String
  24.         Get
  25.             Return txtFile.Text
  26.         End Get
  27.     End Property
  28.  
  29.     Public ReadOnly Property Arguments() As String
  30.         Get
  31.             Return txtArguments.Text
  32.         End Get
  33.     End Property
  34.  
  35.     Public ReadOnly Property VocalCommand() As String
  36.         Get
  37.             Return txtVocalCommand.Text
  38.         End Get
  39.     End Property
  40.  
  41.     Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
  42.         If Not IO.File.Exists(txtFile.Text) Then
  43.             MessageBox.Show("Questo file non esiste!", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  44.             Exit Sub
  45.         End If
  46.  
  47.         If String.IsNullOrEmpty(txtVocalCommand.Text) Then
  48.             MessageBox.Show("Riempire tutti i campi necessari!", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  49.             Exit Sub
  50.         End If
  51.  
  52.         Me.DialogResult = System.Windows.Forms.DialogResult.OK
  53.         Me.Close()
  54.     End Sub
  55.  
  56.     Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
  57.         Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
  58.         Me.Close()
  59.     End Sub
  60.  
  61.     Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click
  62.         Dim Open As New OpenFileDialog
  63.         Open.Filter = "Applicazioni|*.exe|Tutti i files|*.*"
  64.         If Open.ShowDialog = Windows.Forms.DialogResult.OK Then
  65.             Dim File As String = Open.FileName
  66.  
  67.             If IO.Path.GetExtension(File) = ".exe" Then
  68.                 txtFile.Text = File
  69.             Else
  70.                 Dim CommandLine As String = GetOpenCommandLine(IO.Path.GetExtension(File))
  71.                 Dim Program As String
  72.                 Dim Arguments As String
  73.  
  74.                 If CommandLine Is Nothing Then
  75.                     txtFile.Text = File
  76.                     Exit Sub
  77.                 End If
  78.  
  79.                 Program = CommandLine.Remove(CommandLine.IndexOf(".exe") + 4)
  80.                 Arguments = CommandLine.Remove(0, Program.Length)
  81.                 Program = Program.Replace(Chr(34), "")
  82.                 If Arguments.Split(Chr(34)).Count Mod 2 = 0 Then
  83.                     Arguments = Arguments.Remove(Arguments.IndexOf(Chr(34)), 1)
  84.                 End If
  85.  
  86.                 If IO.File.Exists(Program) Then
  87.                     Arguments = Arguments.Replace("%1", File)
  88.                     Arguments = Arguments.ToLower.Replace("%l", File)
  89.                     txtFile.Text = Program
  90.                     txtArguments.Text = Arguments
  91.                 Else
  92.                     txtFile.Text = File
  93.                 End If
  94.                 End If
  95.         End If
  96.     End Sub
  97. End Class