Apr 25, 2013 01:40 PM
(This post was last modified: Apr 28, 2013 12:25 AM by McDork.)
INI Filesystem
So, here is my INI File system. I'm not going to spend ages explaining it - I'm tired.
The system allows easy file creation, edition and removal. The natives are designed to the best of my ability to be bug-free and of course, efficient. I made this so it would be easier for me to create files in my projects! :)
Functions (Click to View)
The INI VB code:
Code
Module ini
Function iniGet(ByVal file As String, ByVal key As String) As String
If (System.IO.File.Exists(file) = False) Then
MsgBox("iniGet Error: Unable to open file to read")
Return vbNullString
Exit Function
End If
Dim OpenFile As New System.IO.StreamReader(file)
Dim tmpKey As String = vbNullString
Dim tmpData As String = vbNullString
Dim tmpLine As String = ""
While OpenFile.Peek <> -1
tmpLine = OpenFile.ReadLine()
If (strFind(tmpLine, "=") <> 0 Or strFind(tmpLine, "=") <> -1) Then
If (tmpLine = "") Then
MsgBox("iniGet Read Blankspace. Cannot continue.")
OpenFile.Close()
Return vbNullString
Exit Function
End If
tmpKey = Microsoft.VisualBasic.Left(tmpLine, strFind(tmpLine, "="))
If (tmpKey = key) Then
Dim tmpRevLen As Integer = Microsoft.VisualBasic.Len(tmpLine) - (strFind(tmpLine, "=") + 1)
tmpData = Microsoft.VisualBasic.Right(tmpLine, tmpRevLen)
OpenFile.Close()
Return tmpData
Exit Function
End If
End If
End While
OpenFile.Close()
Return vbNullString
End Function
Function iniSet(ByVal file As String, ByVal key As String, ByVal data As String)
If (System.IO.File.Exists(file) = False) Then
Return -1
Exit Function
End If
Dim tmpKey As String
Dim tmpData As String
Dim tmpLine As String = ""
Dim tmpFileContent As String
Dim tmpFile As New System.IO.StreamReader(file)
tmpFileContent = tmpFile.ReadToEnd()
tmpFile.Close()
Dim OpenFile As New System.IO.StreamReader(file)
If (Microsoft.VisualBasic.Val(iniGet(file, key)) <> -1) Then
While OpenFile.Peek() <> -1
tmpLine = OpenFile.ReadLine()
If (strFind(tmpLine, "=") <> -1) Then
tmpKey = Microsoft.VisualBasic.Left(tmpLine, strFind(tmpLine, "="))
If (tmpKey = key) Then
Dim tmpRevLen As Integer = Microsoft.VisualBasic.Len(tmpLine) - (strFind(tmpLine, "=") + 1)
tmpData = tmpKey & "=" & Microsoft.VisualBasic.Right(tmpLine, tmpRevLen)
OpenFile.Close()
Dim OpenFileWrite As New System.IO.StreamWriter(file)
OpenFileWrite.Write("")
tmpFileContent = Microsoft.VisualBasic.Strings.Replace(tmpFileContent, tmpData, key & "=" & data)
OpenFileWrite.Write(tmpFileContent)
OpenFileWrite.Close()
Return 1
Exit Function
End If
End If
End While
End If
'Else
OpenFile.Close()
Dim _OpenFile As New System.IO.StreamWriter(file, True)
_OpenFile.WriteLine(key & "=" & data)
_OpenFile.Close()
Return 1
Exit Function
End Function
Function strFind(ByVal haystack As String, ByVal needle As String)
Return Microsoft.VisualBasic.Strings.InStr(haystack, needle) - 1
End Function
Function CreateFile(ByVal file As String)
If (System.IO.File.Exists(file)) Then
Return 0
Exit Function
End If
Dim CreatedFile As FileStream = System.IO.File.Create(file)
CreatedFile.Close()
Return 1
End Function
Function GetLineFromString(ByVal str As String)
For I = 0 To Microsoft.VisualBasic.Len(str) - 1
If (str(I) = Environment.NewLine) Then
GetLineFromString = Microsoft.VisualBasic.Left(str, I)
Exit Function
End If
Next
Return -1
End Function
Function DeleteFile(ByVal file As String)
If (System.IO.File.Exists(file)) Then
System.IO.File.Delete(file)
Else
Return 0
Exit Function
End If
Return 1
End Function
End Module
'MCDORK - hackforums.net 2013 - DO NOT DISTRIBUTE.Hope you enjoy! If you have any questions, please post here :)
I'm not all that protective, but please make sure you keep my name at the bottom of it! :)
I’ll have what she’s having


![[Image: 3269089713e50d48e50e4d5bb760fb95.png]](https://gyazo.com/3269089713e50d48e50e4d5bb760fb95.png)
