Advertisement
julioCCs

INISettings.vb

Apr 18th, 2013
945
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 3.56 KB | None | 0 0
  1. 'https://www.youtube.com/user/GTAScripting
  2. 'http://gtaxscripting.blogspot.com/
  3. 'http://www.facebook.com/GtaIVScripting
  4. 'https://twitter.com/julionib
  5.  
  6. Imports System
  7. Imports System.Drawing
  8. Imports System.Windows.Forms
  9. Imports GTA
  10. Imports System.IO
  11. Imports System.Text
  12.  
  13. Public Class BaseScriptProject
  14.     Inherits Script
  15.  
  16.     Private iniFile As String = ".\Scripts\MyCustomINI.ini"
  17.  
  18.     Private model_name As String
  19.     Private anFloatValue As Double
  20.     Private hkActivate As Keys
  21.     Private infoFromCustomINI As String
  22.  
  23.     Private Function ReadIniString(opt As String, cat As String, def As String) As String
  24.         If Settings.GetValueString(opt, cat, "") = "" Then Settings.SetValue(opt, cat, def)
  25.  
  26.         Return Settings.GetValueString(opt, cat, def)
  27.     End Function
  28.  
  29.     Private Function ReadIniKey(opt As String, cat As String, def As Keys) As Keys
  30.         If Settings.GetValueString(opt, cat, "") = "" Then Settings.SetValue(opt, cat, def)
  31.  
  32.         Return Settings.GetValueKey(opt, cat, def)
  33.     End Function
  34.  
  35.     Public Sub New()
  36.         Me.Interval = 10
  37.  
  38.         model_name = ReadIniString("name_1", "models", "none")
  39.  
  40.         anFloatValue = Double.Parse(ReadIniString("multiplier", "explosion", "1.0"))
  41.  
  42.         hkActivate = ReadIniKey("activate", "hotkeys", Keys.D0)
  43.  
  44.         Settings.Save()
  45.  
  46.         'read custom INI file:
  47.         checkIniExists()
  48.  
  49.         infoFromCustomINI = ReadINI("test", "category", "")
  50.  
  51.         If infoFromCustomINI = "" Then WriteINI("test", "category", "default value")
  52.     End Sub
  53.  
  54.     Private Sub msg(ByVal smsg As String, ByVal duracao As Int32)
  55.         Native.Function.Call("PRINT_STRING_WITH_LITERAL_STRING_NOW", "STRING", smsg, duracao, 1)
  56.     End Sub
  57.  
  58.     Private Sub keyDown(ByVal sender As Object, ByVal e As GTA.KeyEventArgs) Handles MyBase.KeyDown
  59.     End Sub
  60.  
  61.     Private Sub keyUp(ByVal sender As Object, ByVal e As GTA.KeyEventArgs) Handles MyBase.KeyUp
  62.     End Sub
  63.  
  64.     Private Sub general_tick(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Tick
  65.     End Sub
  66.  
  67.     Private Sub console_CMD(ByVal sender As Object, ByVal e As ConsoleEventArgs) Handles MyBase.ConsoleCommand
  68.     End Sub
  69.  
  70.     Private Sub GraphicsEventHandler(ByVal sender As Object, ByVal e As GTA.GraphicsEventArgs) Handles MyBase.PerFrameDrawing
  71.     End Sub
  72.  
  73.     Private Declare Auto Function GetPrivateProfileString Lib "Kernel32" _
  74.         (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As StringBuilder,
  75.          ByVal nSize As Integer, ByVal lpFileName As String) As Integer
  76.  
  77.     Private Declare Auto Function WritePrivateProfileString Lib "Kernel32" _
  78.         (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Integer
  79.  
  80.     Private Function ReadINI(ByVal key_name As String, ByVal section_name As String, ByVal default_value As String) As String
  81.         Const MAX_LENGTH As Integer = 500
  82.         Dim string_builder As New StringBuilder(MAX_LENGTH)
  83.  
  84.         GetPrivateProfileString(section_name, key_name, default_value, string_builder, MAX_LENGTH, iniFile)
  85.  
  86.         Return string_builder.ToString()
  87.     End Function
  88.  
  89.     Private Sub WriteINI(ByVal key_name As String, ByVal section_name As String, ByVal value As String)
  90.         WritePrivateProfileString(section_name, key_name, value, iniFile)
  91.     End Sub
  92.  
  93.     Private Sub checkIniExists()
  94.         If Not File.Exists(iniFile) Then
  95.             File.CreateText(iniFile).Dispose()
  96.  
  97.             Wait(100)
  98.         End If
  99.     End Sub
  100. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement