From adf3354910a70bca3aea4b07412dab0574375546 Mon Sep 17 00:00:00 2001 From: Antaniserse Date: Mon, 5 Sep 2016 14:53:32 +0200 Subject: [PATCH] Alternate method of reading text files, to better handle locked files --- CopyToVA.bat | 2 +- VAExtensions/App.vb | 14 +- .../ContextHandlers/ContextHandlerReadCSV.vb | 2 +- .../ContextHandlers/ContextHandlerReadFile.vb | 93 ++++++------ .../ContextHandlers/ContextHandlerReadJSON.vb | 6 +- .../ContextHandlers/ContextHandlerReadRSS.vb | 2 +- .../ContextHandlerReadStdOut.vb | 103 +++++++------ .../ContextHandlers/ContextHandlerReadXML.vb | 138 +++++++++--------- .../ContextHandlers/ContextHandlerShowFile.vb | 108 +++++++------- VAExtensions/Profiles/_test-Profile.html | 83 +++++++++++ 10 files changed, 323 insertions(+), 228 deletions(-) create mode 100644 VAExtensions/Profiles/_test-Profile.html diff --git a/CopyToVA.bat b/CopyToVA.bat index 937b1b2..e29d01a 100644 --- a/CopyToVA.bat +++ b/CopyToVA.bat @@ -3,7 +3,7 @@ echo Copying plugin... xcopy "VAExtensions\bin\Release" "%PROGRAMFILES(x86)%\VoiceAttack\Apps\VAExtensions" /C /F /Y /S /I echo -=-=-=-=-=-=-=-=-=-=-=- echo Copying sample profiles... -xcopy "VAExtensions\Profiles\*.*" "%PROGRAMFILES(x86)%\VoiceAttack\Apps\VAExtensions\Profiles" /C /F /Y +REM xcopy "VAExtensions\Profiles\*.*" "%PROGRAMFILES(x86)%\VoiceAttack\Apps\VAExtensions\Profiles" /C /F /Y echo -=-=-=-=-=-=-=-=-=-=-=- echo Launching VoiceAttack... pause diff --git a/VAExtensions/App.vb b/VAExtensions/App.vb index 599ce0d..308c39b 100644 --- a/VAExtensions/App.vb +++ b/VAExtensions/App.vb @@ -95,7 +95,7 @@ End If End Function - Public Shared Function DownloadTextFile(ByVal url As String) As DownloadedFile + Public Shared Function DownloadFile(ByVal url As String) As DownloadedFile Dim result As New DownloadedFile If Not url.ToLower.StartsWith("http") Then @@ -133,6 +133,18 @@ Return result End Function + Public Shared Function ReadTextFile(ByVal filename As String) As String + Dim content As String = Nothing + + Using fileStream = New IO.FileStream(filename, IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.ReadWrite) + Using textReader = New IO.StreamReader(fileStream) + content = textReader.ReadToEnd() + End Using + End Using + + Return content + End Function + Public Shared Sub ClearCachedFiles() Dim f As DownloadedFile diff --git a/VAExtensions/ContextHandlers/ContextHandlerReadCSV.vb b/VAExtensions/ContextHandlers/ContextHandlerReadCSV.vb index dc61f40..c38463a 100644 --- a/VAExtensions/ContextHandlers/ContextHandlerReadCSV.vb +++ b/VAExtensions/ContextHandlers/ContextHandlerReadCSV.vb @@ -29,7 +29,7 @@ Public Class ContextHandlerReadCSV Select Case m_Context Case ContextFactory.Contexts.LoadCSV Try - newFile = App.DownloadTextFile(m_TextValues(App.KEY_FILE)) + newFile = App.DownloadFile(m_TextValues(App.KEY_FILE)) If newFile.LocalPath.Length = 0 Then m_smallIntValues(App.KEY_ERROR) = ERR_IO m_TextValues(App.KEY_RESULT) = String.Format("Error retrieving File '{0}'.", m_TextValues(App.KEY_FILE)) diff --git a/VAExtensions/ContextHandlers/ContextHandlerReadFile.vb b/VAExtensions/ContextHandlers/ContextHandlerReadFile.vb index 533b609..fa480ed 100644 --- a/VAExtensions/ContextHandlers/ContextHandlerReadFile.vb +++ b/VAExtensions/ContextHandlers/ContextHandlerReadFile.vb @@ -1,52 +1,53 @@ Public Class ContextHandlerReadFile - Inherits ContextHandlerBase - - Public Sub New(ByVal context As ContextFactory.Contexts _ - , ByRef state As Dictionary(Of String, Object) _ - , ByRef smallIntValues As Dictionary(Of String, Nullable(Of Short)) _ - , ByRef textValues As Dictionary(Of String, String) _ - , ByRef intValues As Dictionary(Of String, Nullable(Of Integer)) _ - , ByRef decimalValues As Dictionary(Of String, Nullable(Of Decimal)) _ - , ByRef booleanValues As Dictionary(Of String, Nullable(Of Boolean)) _ - , ByRef extendedValues As Dictionary(Of String, Object)) - - MyBase.New(context, state, smallIntValues, textValues, intValues, decimalValues, booleanValues, extendedValues) - End Sub - - - Public Overrides Function Execute() As Boolean - Dim newFile As DownloadedFile = Nothing - Dim regexPattern As String - - If Not m_TextValues.ContainsKey(App.KEY_FILE) Then - m_smallIntValues(App.KEY_ERROR) = ERR_ARGUMENTS - m_TextValues(App.KEY_RESULT) = String.Format("Unknown file name. Text variable '{0}' not set.", App.KEY_FILE) - Return False - End If - - If m_TextValues.ContainsKey(App.KEY_REGEX) Then - regexPattern = m_TextValues(App.KEY_REGEX) - Else - regexPattern = String.Empty - End If - Try - newFile = App.DownloadTextFile(m_TextValues(App.KEY_FILE)) - If newFile.LocalPath.Length = 0 Then - m_smallIntValues(App.KEY_ERROR) = ERR_IO - m_TextValues(App.KEY_RESULT) = String.Format("Error retrieving File '{0}'.", m_TextValues(App.KEY_FILE)) - Return False - End If + Inherits ContextHandlerBase + + Public Sub New(ByVal context As ContextFactory.Contexts _ + , ByRef state As Dictionary(Of String, Object) _ + , ByRef smallIntValues As Dictionary(Of String, Nullable(Of Short)) _ + , ByRef textValues As Dictionary(Of String, String) _ + , ByRef intValues As Dictionary(Of String, Nullable(Of Integer)) _ + , ByRef decimalValues As Dictionary(Of String, Nullable(Of Decimal)) _ + , ByRef booleanValues As Dictionary(Of String, Nullable(Of Boolean)) _ + , ByRef extendedValues As Dictionary(Of String, Object)) + + MyBase.New(context, state, smallIntValues, textValues, intValues, decimalValues, booleanValues, extendedValues) + End Sub - Dim newFileContent As String = IO.File.ReadAllText(newFile.LocalPath) - m_TextValues(App.KEY_RESULT) = App.LimitResponse(newFileContent, regexPattern) - Catch ex As Exception - m_smallIntValues(App.KEY_ERROR) = ERR_IO - m_TextValues(App.KEY_RESULT) = String.Format("Error loading file content '{0}' ({1}).", m_TextValues(App.KEY_FILE), ex.Message) - End Try - If newFile.IsTemporary Then App.Settings.AddDownloadedFile(newFile) + Public Overrides Function Execute() As Boolean + Dim newFile As DownloadedFile = Nothing + Dim regexPattern As String + + If Not m_TextValues.ContainsKey(App.KEY_FILE) Then + m_smallIntValues(App.KEY_ERROR) = ERR_ARGUMENTS + m_TextValues(App.KEY_RESULT) = String.Format("Unknown file name. Text variable '{0}' not set.", App.KEY_FILE) + Return False + End If + + If m_TextValues.ContainsKey(App.KEY_REGEX) Then + regexPattern = m_TextValues(App.KEY_REGEX) + Else + regexPattern = String.Empty + End If + Try + newFile = App.DownloadFile(m_TextValues(App.KEY_FILE)) + If newFile.LocalPath.Length = 0 Then + m_smallIntValues(App.KEY_ERROR) = ERR_IO + m_TextValues(App.KEY_RESULT) = String.Format("Error retrieving File '{0}'.", m_TextValues(App.KEY_FILE)) + Return False + End If + + 'Dim newFileContent As String = IO.File.ReadAllText(newFile.LocalPath) + Dim newFileContent As String = App.ReadTextFile(newFile.LocalPath) + m_TextValues(App.KEY_RESULT) = App.LimitResponse(newFileContent, regexPattern) + + Catch ex As Exception + m_smallIntValues(App.KEY_ERROR) = ERR_IO + m_TextValues(App.KEY_RESULT) = String.Format("Error loading file content '{0}' ({1}).", m_TextValues(App.KEY_FILE), ex.Message) + End Try + If newFile.IsTemporary Then App.Settings.AddDownloadedFile(newFile) - Return True - End Function + Return True + End Function End Class diff --git a/VAExtensions/ContextHandlers/ContextHandlerReadJSON.vb b/VAExtensions/ContextHandlers/ContextHandlerReadJSON.vb index c77eec1..a357793 100644 --- a/VAExtensions/ContextHandlers/ContextHandlerReadJSON.vb +++ b/VAExtensions/ContextHandlers/ContextHandlerReadJSON.vb @@ -20,7 +20,7 @@ Public Class ContextHandlerReadJSON Dim newFile As DownloadedFile = Nothing Dim regexPattern As String Dim elementPath As String - Dim i As Integer, elementCount As Short + Dim elementCount As Short If Not m_TextValues.ContainsKey(App.KEY_FILE) Then m_smallIntValues(App.KEY_ERROR) = ERR_CONTEXT @@ -40,14 +40,14 @@ Public Class ContextHandlerReadJSON End If Try - newFile = App.DownloadTextFile(m_TextValues(App.KEY_FILE)) + newFile = App.DownloadFile(m_TextValues(App.KEY_FILE)) If newFile.LocalPath.Length = 0 Then m_smallIntValues(App.KEY_ERROR) = ERR_IO m_TextValues(App.KEY_RESULT) = String.Format("Error retrieving File '{0}'.", m_TextValues(App.KEY_FILE)) Return False End If - Dim jobj As Json.Linq.JObject = Json.Linq.JObject.Parse(IO.File.ReadAllText(newFile.LocalPath)) + Dim jobj As Json.Linq.JObject = Json.Linq.JObject.Parse(App.ReadTextFile(newFile.LocalPath)) Dim token As Json.Linq.JToken = jobj.SelectToken(elementPath) If token IsNot Nothing Then diff --git a/VAExtensions/ContextHandlers/ContextHandlerReadRSS.vb b/VAExtensions/ContextHandlers/ContextHandlerReadRSS.vb index b51dc4f..651fdad 100644 --- a/VAExtensions/ContextHandlers/ContextHandlerReadRSS.vb +++ b/VAExtensions/ContextHandlers/ContextHandlerReadRSS.vb @@ -38,7 +38,7 @@ End If Try - newFile = App.DownloadTextFile(m_TextValues(App.KEY_FILE)) + newFile = App.DownloadFile(m_TextValues(App.KEY_FILE)) If newFile.LocalPath.Length = 0 Then m_smallIntValues(App.KEY_ERROR) = ERR_IO m_TextValues(App.KEY_RESULT) = String.Format("Error retrieving File '{0}'.", m_TextValues(App.KEY_FILE)) diff --git a/VAExtensions/ContextHandlers/ContextHandlerReadStdOut.vb b/VAExtensions/ContextHandlers/ContextHandlerReadStdOut.vb index 71019ea..4a179fd 100644 --- a/VAExtensions/ContextHandlers/ContextHandlerReadStdOut.vb +++ b/VAExtensions/ContextHandlers/ContextHandlerReadStdOut.vb @@ -1,54 +1,53 @@ Public Class ContextHandlerReadStdOut - Inherits ContextHandlerBase - - Public Sub New(ByVal context As ContextFactory.Contexts _ - , ByRef state As Dictionary(Of String, Object) _ - , ByRef smallIntValues As Dictionary(Of String, Nullable(Of Short)) _ - , ByRef textValues As Dictionary(Of String, String) _ - , ByRef intValues As Dictionary(Of String, Nullable(Of Integer)) _ - , ByRef decimalValues As Dictionary(Of String, Nullable(Of Decimal)) _ - , ByRef booleanValues As Dictionary(Of String, Nullable(Of Boolean)) _ - , ByRef extendedValues As Dictionary(Of String, Object)) - - MyBase.New(context, state, smallIntValues, textValues, intValues, decimalValues, booleanValues, extendedValues) - End Sub - - - Public Overrides Function Execute() As Boolean - Dim newFile As DownloadedFile = Nothing - Dim regexPattern As String - - If Not m_TextValues.ContainsKey(App.KEY_FILE) Then - m_smallIntValues(App.KEY_ERROR) = ERR_CONTEXT - m_TextValues(App.KEY_RESULT) = String.Format("Unknown file name. Text variable '{0}' not set.", App.KEY_FILE) - Return False - End If - - Try - Dim pName As String = m_TextValues(App.KEY_FILE) - Dim pInfo As ProcessStartInfo - Dim pOutput As String - Dim p As Process - - If Not IO.Path.IsPathRooted(pName) Then - pName = IO.Path.Combine(IO.Path.GetDirectoryName(Reflection.Assembly.GetExecutingAssembly.Location), pName) - End If - pInfo = New ProcessStartInfo(pName) With {.UseShellExecute = False, .CreateNoWindow = True, .RedirectStandardOutput = True} - If Not String.IsNullOrEmpty(m_TextValues(App.KEY_ARGUMENTS)) Then - pInfo.Arguments = m_TextValues(App.KEY_ARGUMENTS) - End If - - p = Process.Start(pInfo) - pOutput = p.StandardOutput.ReadToEnd - p.WaitForExit() - - m_TextValues(App.KEY_RESULT) = App.LimitResponse(pOutput) - Catch ex As Exception - m_smallIntValues(App.KEY_ERROR) = ERR_IO - m_TextValues(App.KEY_RESULT) = String.Format("Error running process '{0}' - {1}.", m_TextValues(App.KEY_FILE), ex.Message) - Return False - End Try - - Return True - End Function + Inherits ContextHandlerBase + + Public Sub New(ByVal context As ContextFactory.Contexts _ + , ByRef state As Dictionary(Of String, Object) _ + , ByRef smallIntValues As Dictionary(Of String, Nullable(Of Short)) _ + , ByRef textValues As Dictionary(Of String, String) _ + , ByRef intValues As Dictionary(Of String, Nullable(Of Integer)) _ + , ByRef decimalValues As Dictionary(Of String, Nullable(Of Decimal)) _ + , ByRef booleanValues As Dictionary(Of String, Nullable(Of Boolean)) _ + , ByRef extendedValues As Dictionary(Of String, Object)) + + MyBase.New(context, state, smallIntValues, textValues, intValues, decimalValues, booleanValues, extendedValues) + End Sub + + + Public Overrides Function Execute() As Boolean + Dim newFile As DownloadedFile = Nothing + + If Not m_TextValues.ContainsKey(App.KEY_FILE) Then + m_smallIntValues(App.KEY_ERROR) = ERR_CONTEXT + m_TextValues(App.KEY_RESULT) = String.Format("Unknown file name. Text variable '{0}' not set.", App.KEY_FILE) + Return False + End If + + Try + Dim pName As String = m_TextValues(App.KEY_FILE) + Dim pInfo As ProcessStartInfo + Dim pOutput As String + Dim p As Process + + If Not IO.Path.IsPathRooted(pName) Then + pName = IO.Path.Combine(IO.Path.GetDirectoryName(Reflection.Assembly.GetExecutingAssembly.Location), pName) + End If + pInfo = New ProcessStartInfo(pName) With {.UseShellExecute = False, .CreateNoWindow = True, .RedirectStandardOutput = True} + If Not String.IsNullOrEmpty(m_TextValues(App.KEY_ARGUMENTS)) Then + pInfo.Arguments = m_TextValues(App.KEY_ARGUMENTS) + End If + + p = Process.Start(pInfo) + pOutput = p.StandardOutput.ReadToEnd + p.WaitForExit() + + m_TextValues(App.KEY_RESULT) = App.LimitResponse(pOutput) + Catch ex As Exception + m_smallIntValues(App.KEY_ERROR) = ERR_IO + m_TextValues(App.KEY_RESULT) = String.Format("Error running process '{0}' - {1}.", m_TextValues(App.KEY_FILE), ex.Message) + Return False + End Try + + Return True + End Function End Class diff --git a/VAExtensions/ContextHandlers/ContextHandlerReadXML.vb b/VAExtensions/ContextHandlers/ContextHandlerReadXML.vb index 0b9921d..654c7f9 100644 --- a/VAExtensions/ContextHandlers/ContextHandlerReadXML.vb +++ b/VAExtensions/ContextHandlers/ContextHandlerReadXML.vb @@ -1,82 +1,82 @@ Public Class ContextHandlerReadXML - Inherits ContextHandlerBase + Inherits ContextHandlerBase - Public Sub New(ByVal context As ContextFactory.Contexts _ - , ByRef state As Dictionary(Of String, Object) _ - , ByRef smallIntValues As Dictionary(Of String, Nullable(Of Short)) _ - , ByRef textValues As Dictionary(Of String, String) _ - , ByRef intValues As Dictionary(Of String, Nullable(Of Integer)) _ - , ByRef decimalValues As Dictionary(Of String, Nullable(Of Decimal)) _ - , ByRef booleanValues As Dictionary(Of String, Nullable(Of Boolean)) _ - , ByRef extendedValues As Dictionary(Of String, Object)) + Public Sub New(ByVal context As ContextFactory.Contexts _ + , ByRef state As Dictionary(Of String, Object) _ + , ByRef smallIntValues As Dictionary(Of String, Nullable(Of Short)) _ + , ByRef textValues As Dictionary(Of String, String) _ + , ByRef intValues As Dictionary(Of String, Nullable(Of Integer)) _ + , ByRef decimalValues As Dictionary(Of String, Nullable(Of Decimal)) _ + , ByRef booleanValues As Dictionary(Of String, Nullable(Of Boolean)) _ + , ByRef extendedValues As Dictionary(Of String, Object)) - MyBase.New(context, state, smallIntValues, textValues, intValues, decimalValues, booleanValues, extendedValues) - End Sub + MyBase.New(context, state, smallIntValues, textValues, intValues, decimalValues, booleanValues, extendedValues) + End Sub - Public Overrides Function Execute() As Boolean - Dim newFile As DownloadedFile = Nothing - Dim regexPattern As String - Dim elementPath As String() - Dim i As Integer, elementCount As Short + Public Overrides Function Execute() As Boolean + Dim newFile As DownloadedFile = Nothing + Dim regexPattern As String + Dim elementPath As String() + Dim i As Integer, elementCount As Short - If Not m_TextValues.ContainsKey(App.KEY_FILE) Then - m_smallIntValues(App.KEY_ERROR) = ERR_CONTEXT - m_TextValues(App.KEY_RESULT) = String.Format("Unknown file name. Text variable '{0}' not set.", App.KEY_FILE) - Return False - End If - - If m_TextValues.ContainsKey(App.KEY_REGEX) Then - regexPattern = m_TextValues(App.KEY_REGEX) - Else - regexPattern = String.Empty - End If - If m_TextValues.ContainsKey(App.KEY_ARGUMENTS) AndAlso Not String.IsNullOrEmpty(m_TextValues(App.KEY_ARGUMENTS)) Then - elementPath = m_TextValues(App.KEY_ARGUMENTS).Split("\"c) - Else - elementPath = {} - End If - If Not m_smallIntValues.ContainsKey(App.KEY_INDEX) OrElse Not m_smallIntValues(App.KEY_INDEX).HasValue OrElse m_smallIntValues(App.KEY_INDEX).Value < 1 Then - elementCount = 1 - Else - elementCount = m_smallIntValues(App.KEY_INDEX).Value - End If - - Try - newFile = App.DownloadTextFile(m_TextValues(App.KEY_FILE)) - If newFile.LocalPath.Length = 0 Then - m_smallIntValues(App.KEY_ERROR) = ERR_IO - m_TextValues(App.KEY_RESULT) = String.Format("Error retrieving File '{0}'.", m_TextValues(App.KEY_FILE)) + If Not m_TextValues.ContainsKey(App.KEY_FILE) Then + m_smallIntValues(App.KEY_ERROR) = ERR_CONTEXT + m_TextValues(App.KEY_RESULT) = String.Format("Unknown file name. Text variable '{0}' not set.", App.KEY_FILE) Return False - End If + End If + + If m_TextValues.ContainsKey(App.KEY_REGEX) Then + regexPattern = m_TextValues(App.KEY_REGEX) + Else + regexPattern = String.Empty + End If + If m_TextValues.ContainsKey(App.KEY_ARGUMENTS) AndAlso Not String.IsNullOrEmpty(m_TextValues(App.KEY_ARGUMENTS)) Then + elementPath = m_TextValues(App.KEY_ARGUMENTS).Split("\"c) + Else + elementPath = {} + End If + If Not m_smallIntValues.ContainsKey(App.KEY_INDEX) OrElse Not m_smallIntValues(App.KEY_INDEX).HasValue OrElse m_smallIntValues(App.KEY_INDEX).Value < 1 Then + elementCount = 1 + Else + elementCount = m_smallIntValues(App.KEY_INDEX).Value + End If - Dim xDoc As Xml.Linq.XDocument = Xml.Linq.XDocument.Load(newFile.LocalPath) - Dim xElement1 As IEnumerable(Of Xml.Linq.XElement) = xDoc.Elements(elementPath(0)) + Try + newFile = App.DownloadFile(m_TextValues(App.KEY_FILE)) + If newFile.LocalPath.Length = 0 Then + m_smallIntValues(App.KEY_ERROR) = ERR_IO + m_TextValues(App.KEY_RESULT) = String.Format("Error retrieving File '{0}'.", m_TextValues(App.KEY_FILE)) + Return False + End If - For i = 1 To elementPath.Length - 1 - xElement1 = From el In xElement1.Elements(elementPath(i)) Select el - Next + Dim xDoc As Xml.Linq.XDocument = Xml.Linq.XDocument.Load(newFile.LocalPath) + Dim xElement1 As IEnumerable(Of Xml.Linq.XElement) = xDoc.Elements(elementPath(0)) - If xElement1 IsNot Nothing AndAlso xElement1.Value IsNot Nothing Then - i = 1 - For Each el As Xml.Linq.XElement In xElement1 - m_TextValues(App.KEY_RESULT) = el.Value - i += 1 - If i > elementCount Then Exit For + For i = 1 To elementPath.Length - 1 + xElement1 = From el In xElement1.Elements(elementPath(i)) Select el Next - m_TextValues(App.KEY_RESULT) = App.LimitResponse(m_TextValues(App.KEY_RESULT), regexPattern) - m_smallIntValues(App.KEY_INDEX) = elementCount + 1S - Else - m_smallIntValues(App.KEY_ERROR) = ERR_ARGUMENTS - m_TextValues(App.KEY_RESULT) = String.Format("Element not found: '{0}'", m_TextValues(App.KEY_ARGUMENTS)) - End If - Catch ex As Exception - m_smallIntValues(App.KEY_ERROR) = ERR_IO - m_TextValues(App.KEY_RESULT) = String.Format("Error reading XML: {0}", ex.Message) - Return False - End Try - If newFile.IsTemporary Then App.Settings.AddDownloadedFile(newFile) - Return True - End Function + If xElement1 IsNot Nothing AndAlso xElement1.Value IsNot Nothing Then + i = 1 + For Each el As Xml.Linq.XElement In xElement1 + m_TextValues(App.KEY_RESULT) = el.Value + i += 1 + If i > elementCount Then Exit For + Next + m_TextValues(App.KEY_RESULT) = App.LimitResponse(m_TextValues(App.KEY_RESULT), regexPattern) + m_smallIntValues(App.KEY_INDEX) = elementCount + 1S + Else + m_smallIntValues(App.KEY_ERROR) = ERR_ARGUMENTS + m_TextValues(App.KEY_RESULT) = String.Format("Element not found: '{0}'", m_TextValues(App.KEY_ARGUMENTS)) + End If + Catch ex As Exception + m_smallIntValues(App.KEY_ERROR) = ERR_IO + m_TextValues(App.KEY_RESULT) = String.Format("Error reading XML: {0}", ex.Message) + Return False + End Try + If newFile.IsTemporary Then App.Settings.AddDownloadedFile(newFile) + + Return True + End Function End Class diff --git a/VAExtensions/ContextHandlers/ContextHandlerShowFile.vb b/VAExtensions/ContextHandlers/ContextHandlerShowFile.vb index f8303c0..64ea5c0 100644 --- a/VAExtensions/ContextHandlers/ContextHandlerShowFile.vb +++ b/VAExtensions/ContextHandlers/ContextHandlerShowFile.vb @@ -1,57 +1,57 @@ Public Class ContextHandlerShowFile - Inherits ContextHandlerBase - - Public Sub New(ByVal context As ContextFactory.Contexts _ - , ByRef state As Dictionary(Of String, Object) _ - , ByRef smallIntValues As Dictionary(Of String, Nullable(Of Short)) _ - , ByRef textValues As Dictionary(Of String, String) _ - , ByRef intValues As Dictionary(Of String, Nullable(Of Integer)) _ - , ByRef decimalValues As Dictionary(Of String, Nullable(Of Decimal)) _ - , ByRef booleanValues As Dictionary(Of String, Nullable(Of Boolean)) _ - , ByRef extendedValues As Dictionary(Of String, Object)) - - MyBase.New(context, state, smallIntValues, textValues, intValues, decimalValues, booleanValues, extendedValues) - End Sub - - - Public Overrides Function Execute() As Boolean - Dim newFile As DownloadedFile = Nothing - Dim textVar As String = Nothing - - If m_Context = ContextFactory.Contexts.ShowFile Then - If Not m_TextValues.ContainsKey(App.KEY_FILE) Then - m_smallIntValues(App.KEY_ERROR) = ERR_CONTEXT - m_TextValues(App.KEY_RESULT) = String.Format("Unknown file name. Text variable '{0}' not set.", App.KEY_FILE) - Return False - End If - - Try - newFile = App.DownloadTextFile(m_TextValues(App.KEY_FILE)) - If newFile.LocalPath.Length = 0 Then - m_smallIntValues(App.KEY_ERROR) = ERR_IO - m_TextValues(App.KEY_RESULT) = String.Format("Error retrieving File '{0}'.", m_TextValues(App.KEY_FILE)) - Return False + Inherits ContextHandlerBase + + Public Sub New(ByVal context As ContextFactory.Contexts _ + , ByRef state As Dictionary(Of String, Object) _ + , ByRef smallIntValues As Dictionary(Of String, Nullable(Of Short)) _ + , ByRef textValues As Dictionary(Of String, String) _ + , ByRef intValues As Dictionary(Of String, Nullable(Of Integer)) _ + , ByRef decimalValues As Dictionary(Of String, Nullable(Of Decimal)) _ + , ByRef booleanValues As Dictionary(Of String, Nullable(Of Boolean)) _ + , ByRef extendedValues As Dictionary(Of String, Object)) + + MyBase.New(context, state, smallIntValues, textValues, intValues, decimalValues, booleanValues, extendedValues) + End Sub + + + Public Overrides Function Execute() As Boolean + Dim newFile As DownloadedFile = Nothing + Dim textVar As String = Nothing + + If m_Context = ContextFactory.Contexts.ShowFile Then + If Not m_TextValues.ContainsKey(App.KEY_FILE) Then + m_smallIntValues(App.KEY_ERROR) = ERR_CONTEXT + m_TextValues(App.KEY_RESULT) = String.Format("Unknown file name. Text variable '{0}' not set.", App.KEY_FILE) + Return False End If - Catch ex As Exception - m_smallIntValues(App.KEY_ERROR) = ERR_IO - m_TextValues(App.KEY_RESULT) = String.Format("Error loading file content '{0}'.", m_TextValues(App.KEY_FILE)) - Return False - End Try - ElseIf m_Context = ContextFactory.Contexts.ShowText Then - If m_TextValues.Count = 0 Then - m_smallIntValues(App.KEY_ERROR) = ERR_ARGUMENTS - m_TextValues(App.KEY_RESULT) = "At least one text value is needed." - Return False - Else - textVar = m_TextValues(m_TextValues.Keys(0)) - End If - End If - - Dim viewer As New TextForm(newFile, textVar) - viewer.ShowDialog() - viewer.Dispose() - If newFile IsNot Nothing AndAlso newFile.IsTemporary Then App.Settings.AddDownloadedFile(newFile) - - Return True - End Function + + Try + newFile = App.DownloadFile(m_TextValues(App.KEY_FILE)) + If newFile.LocalPath.Length = 0 Then + m_smallIntValues(App.KEY_ERROR) = ERR_IO + m_TextValues(App.KEY_RESULT) = String.Format("Error retrieving File '{0}'.", m_TextValues(App.KEY_FILE)) + Return False + End If + Catch ex As Exception + m_smallIntValues(App.KEY_ERROR) = ERR_IO + m_TextValues(App.KEY_RESULT) = String.Format("Error loading file content '{0}'.", m_TextValues(App.KEY_FILE)) + Return False + End Try + ElseIf m_Context = ContextFactory.Contexts.ShowText Then + If m_TextValues.Count = 0 Then + m_smallIntValues(App.KEY_ERROR) = ERR_ARGUMENTS + m_TextValues(App.KEY_RESULT) = "At least one text value is needed." + Return False + Else + textVar = m_TextValues(m_TextValues.Keys(0)) + End If + End If + + Dim viewer As New TextForm(newFile, textVar) + viewer.ShowDialog() + viewer.Dispose() + If newFile IsNot Nothing AndAlso newFile.IsTemporary Then App.Settings.AddDownloadedFile(newFile) + + Return True + End Function End Class diff --git a/VAExtensions/Profiles/_test-Profile.html b/VAExtensions/Profiles/_test-Profile.html new file mode 100644 index 0000000..b30100f --- /dev/null +++ b/VAExtensions/Profiles/_test-Profile.html @@ -0,0 +1,83 @@ + + + + + +_test - VoiceAttack Profile Command Sheet + + + + + + +
_testVoiceAttack Profile Command Sheet
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Spoken CommandKeyboard ShortcutMouse ShortcutButtonDescriptionCategoryActions
backwardRelease W key, Press down S key
forwardRelease S key, Press down W key
leftRelease D key, Press down A key
rightRelease A key, Press down D key
stopRelease W key, Release S key, Release A key, Release D key
+ +