Advertisement
SemlerPDX

AVCS_SaveToFile - Save VoiceAttack variables to file

Aug 14th, 2020
1,108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 6.76 KB | None | 0 0
  1. ' Save File System Inline-Function for VoiceAttack -  Save Variables to Text File (or Delete)
  2. '  by SemlerPDX Apr2020
  3. '  VETERANS-GAMING.COM
  4.  
  5.  
  6. Imports Microsoft.VisualBasic
  7. Imports System
  8. Imports System.Text
  9. Imports System.Collections
  10. Imports System.Collections.Generic
  11. Imports System.Data
  12. Imports System.Drawing
  13. Imports System.Diagnostics
  14. Imports System.Windows.Forms
  15. Imports System.Linq
  16. Imports System.Xml.Linq
  17. Imports System.Threading.Tasks
  18.  
  19. Public Class VAInline
  20.     dim entryDeleted as boolean
  21.     dim entryChanged as boolean
  22.     dim entryAdded as boolean
  23.     dim deleteVariable as boolean
  24.     dim requestVarName as string
  25.     dim requestVarValue as string
  26.     dim contents() as string
  27.     dim entry() as string
  28.     dim entryFinal as string
  29.     dim saveFinal as string
  30.     dim contentsFinal as new List(of string)
  31.    
  32.    
  33.     Public Sub Main()
  34.                
  35.         'Check and Set Delete Parameter Variables
  36.         if VA.GetBoolean("AVCS_SFS_DELETE_saved") IsNot nothing
  37.             deleteVariable = VA.GetBoolean("AVCS_SFS_DELETE_saved")
  38.         else
  39.             deleteVariable = false
  40.         end if
  41.        
  42.         'Check and Set Requested Name Parameter Variables
  43.         if VA.GetText("~change_request_var_name") IsNot nothing
  44.             requestVarName = VA.GetText("~change_request_var_name")
  45.             'VA.WriteToLog(requestVarName)
  46.         end if
  47.        
  48.         'Check and Set Requested Value Parameter Variables
  49.         if VA.GetText("~change_request_var_value") IsNot nothing
  50.             requestVarValue = VA.GetText("~change_request_var_value")
  51.             'VA.WriteToLog(requestVarValue)
  52.         end if
  53.        
  54.         if VA.GetText("~save_file") IsNot nothing
  55.             if VA.GetText("~save_file").Contains(requestVarName)
  56.                        
  57.                 'Split contents of save file into single lines separated by the newline
  58.                 if VA.GetText("~save_file").Contains(vbNewLine)
  59.                     contents = VA.GetText("~save_file").Split(new string() {Environment.NewLine},StringSplitOptions.None)
  60.                    
  61.                     'File contains this request somewhere, go through each line to find it
  62.                     for each line as string in contents
  63.                        
  64.                         if not(line = "")
  65.                             if (deleteVariable)
  66.                                 'Add any lines not containing delete request to new list
  67.                                 if (line.Contains(requestVarName))
  68.                                     entryDeleted = true
  69.                                 else
  70.                                     contentsFinal.Add(line)
  71.                                 end if
  72.                             else
  73.                                 'If this line contains the requested variable
  74.                                 if(line.Contains (requestVarName))
  75.                                     'Split this line and compare value to change request
  76.                                     entry = line.Split("=")
  77.                                
  78.                                     'if ((not(entry(1).Contains(requestVarValue))) or (not(entry(1).StartsWith(requestVarValue))))
  79.                                     if ((not(entry(1).Contains(requestVarValue))) or (not(entry(1).StartsWith(requestVarValue))) or (not(entry(1).EndsWith(requestVarValue))))
  80.                                         entry(1) = entry(1).Replace(entry(1),requestVarValue)
  81.                                         entryChanged = true
  82.                                     end if
  83.                                     'Add each entry to new list if changed or not
  84.                                     entryFinal = entry(0) + "=" + entry(1)
  85.                                     contentsFinal.Add(entryFinal)
  86.                                 else
  87.                                     contentsFinal.Add(line)
  88.                                 end if
  89.                             end if
  90.                         end if
  91.                    
  92.                     next 'loop around to next line
  93.                 else
  94.                     'If the save file is one line containing this entry
  95.                     dim line as string = VA.GetText("~save_file")
  96.                     if not(line = "")
  97.                         'Split this line and compare value to change request
  98.                         entry = line.Split("=")
  99.                         if not(entry(1).Contains(requestVarValue))
  100.                             entry(1) = entry(1).Replace(entry(1),requestVarValue)
  101.                             entryChanged = true
  102.                         end if
  103.                         'Add entry to new list if changed or not
  104.                         entryFinal = entry(0) + "=" + entry(1)
  105.                         contentsFinal.Add(entryFinal)
  106.                     end if
  107.                 end if
  108.                 '------------------------------------------------------------------------------------------
  109.                 '--end of check where file contains requested var already and has one or more lines-----------
  110.                 '------------------------------------------------------------------------------------------
  111.             else
  112.                 'Else (if) file does NOT contain RequestVarName
  113.                 if not(deleteVariable)
  114.                     'Split contents of save file into single lines separated by the newline
  115.                     if VA.GetText("~save_file").Contains(vbNewLine)
  116.                         contents = VA.GetText("~save_file").Split(new string() {Environment.NewLine},StringSplitOptions.None)
  117.                         'Add each line to the final list, and the new request at the end
  118.                         for each line as string in contents
  119.                             if not(line = "")
  120.                                 contentsFinal.Add(line)
  121.                             end if
  122.                         next
  123.                         'Moved this out of the above if not .Add portion above, otherwise many duplicates added?
  124.                         entryFinal = requestVarName + "=" + requestVarValue
  125.                         contentsFinal.Add(entryFinal)
  126.                         'entryChanged = true  (disabled June)
  127.                         entryAdded = true
  128.                     else
  129.                         'If the save file is one line
  130.                         dim line as string = VA.GetText("~save_file")
  131.                         if not(line = "")
  132.                             'If that one line has contents (not containing requested var name)
  133.                             contentsFinal.Add(line)
  134.                         end if
  135.                         'Enter new requested save variable to contents
  136.                         entryFinal = requestVarName + "=" + requestVarValue
  137.                         contentsFinal.Add(entryFinal)
  138.                         'entryChanged = true  (disabled June - changed to Added)
  139.                         entryAdded = true
  140.                     end if
  141.                 end if
  142.                 '------------------------------------------------------------------------------------------
  143.                 '--end of check where file does not contain requested var already and has one or more lines---
  144.                 '------------------------------------------------------------------------------------------
  145.             end if
  146.         else
  147.             'If ~save_file is 'nothing' then add the request
  148.             if not (deleteVariable)
  149.                 entryFinal = requestVarName + "=" + requestVarValue
  150.                 contentsFinal.Add(entryFinal)
  151.                 entryChanged = true
  152.             end if
  153.         '----------------------------------------------------------------------------------------------------
  154.         '--end of redundant check where file does not contain any lines yet or is somehow non-existent---------
  155.         '----------------------------------------------------------------------------------------------------
  156.         end if
  157.        
  158.         'Tranform new list back into string with newline placeholders for VA.proxy SetText
  159.         if not(contentsFinal.ToString() = "")
  160.             'Remove duplicate lines added through the line-by-line re-assembly above
  161.             contentsFinal = contentsFinal.Distinct().ToList()
  162.             saveFinal = ""
  163.             for each newline as string in contentsFinal
  164.                 saveFinal = newline + "(/n)" + saveFinal
  165.             next
  166.         else
  167.             if VA.GetText("~save_file") IsNot nothing
  168.                 saveFinal = VA.GetText("~save_file")
  169.             else
  170.                 saveFinal = ""
  171.             end if
  172.         end if
  173.        
  174.         VA.SetText("~save_file", saveFinal)
  175.        
  176.         if(entryDeleted)
  177.             VA.SetBoolean("~entry_deleted", true)
  178.         end if
  179.        
  180.         if(entryChanged)
  181.             VA.SetBoolean("~entry_changed", true)
  182.         end if
  183.        
  184.         if(entryAdded)
  185.             VA.SetBoolean("~entry_added", true)
  186.         end if
  187.    
  188.     End Sub
  189. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement