sinkir

Au3Lib

Jul 15th, 2018
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.14 KB | None | 0 0
  1. ; ===================================================================================
  2. ; _ _ _ _ _
  3. ; | | | | |_(_) | ___
  4. ; | | | | __| | |/ __|
  5. ; | |_| | |_| | |\__ \
  6. ; \___/ \__|_|_||___/
  7. ;
  8. ; ===================================================================================
  9.  
  10. #include <Crypt.au3>
  11.  
  12. Func sha1($sFile)
  13. _Crypt_Startup() ; To optimize performance start the crypt library.
  14. Local $bHash = _Crypt_HashFile($sFile, $CALG_SHA1) ; Create a hash of the file.
  15. _Crypt_Shutdown()
  16. Return StringReplace(String($bHash), "0x", "")
  17. EndFunc ;==>sha1
  18.  
  19. Func tip($sTxt)
  20. ToolTip($sTxt, 0, 0)
  21. EndFunc ;==>tip
  22.  
  23. Func console($s)
  24. ConsoleWrite($s&Chr(10))
  25. EndFunc
  26.  
  27. ; ===================================================================================
  28. ; _____ _ _ ___
  29. ; | ___(_) | ___ / _ \ _ __ ___ _ __
  30. ; | |_ | | |/ _ \| | | | '_ \ / _ \| '_ \
  31. ; | _| | | | __/| |_| | |_) | __/| | | |
  32. ; |_| |_|_|\___| \___/| .__/ \___||_| |_|
  33. ; |_|
  34. ;
  35. ; ===================================================================================
  36. #include <File.au3>
  37.  
  38. Func initdir($name)
  39. If Not FileExists($name) Then
  40. DirCreate($name);
  41. EndIf
  42. EndFunc ;==>initdir
  43.  
  44. Func stockData($SfilePath, $sTxt);
  45. Local $Hfile = FileOpen($SfilePath, 2)
  46. If $Hfile = -1 Then
  47. _FileCreate($SfilePath)
  48. FileClose($Hfile)
  49. $Hfile = FileOpen($SfilePath, 2)
  50. EndIf
  51. FileWrite($Hfile, $sTxt)
  52. FileClose($Hfile)
  53. EndFunc ;==>stockData
  54.  
  55. Func getData($SfilePath, $nbchar = 1);
  56.  
  57. Local $Hfile = FileOpen($SfilePath)
  58. If $Hfile = -1 Then
  59. _FileCreate($SfilePath)
  60. FileClose($Hfile)
  61. Return "";
  62. EndIf
  63. Local $Cchars = "";
  64. While 1
  65. $Cchars = $Cchars & FileRead($Hfile, 1)
  66. If @error = -1 Then ExitLoop
  67. ;MsgBox(0, "Char read:", $Cchars)
  68. WEnd
  69. FileClose($Hfile)
  70. Return $Cchars
  71. EndFunc ;==>getData
  72.  
  73. Func addData($SfilePath, $sTxt);
  74. Local $Hfile = FileOpen($SfilePath, 1)
  75. If $Hfile = -1 Then
  76. _FileCreate($SfilePath)
  77. FileClose($Hfile)
  78. $Hfile = FileOpen($SfilePath, 2)
  79. EndIf
  80. FileWrite($Hfile, $sTxt)
  81. FileClose($Hfile)
  82. EndFunc ;==>addData
  83.  
  84.  
  85.  
  86. ; ===================================================================================
  87. ; ____ _ ___ _
  88. ; / ___|| |_ _ __ ___ __ _ _ __ ___ |_ _|_ __ (_)
  89. ; \___ \| __| '__|/ _ \ / _` | '_ ` _ \ | || '_ \| |
  90. ; ___) | |_| | | __/| (_| | | | | | || || | | | |
  91. ; |____/ \__|_| \___| \__,_|_| |_| |_|___|_| |_|_|
  92. ; ===================================================================================
  93. #include <WinAPIFiles.au3>
  94.  
  95. Func getIniValue($Ttab, $Skey)
  96. ;ConsoleWrite("===================="&Chr(10))
  97. For $i = 1 To $Ttab[0][0]
  98. ;ConsoleWrite("Key: " & $Ttab[$i][0] & @CRLF & "Value: " & $Ttab[$i][1])
  99. If $Ttab[$i][0] = $Skey Then
  100. Return $Ttab[$i][1]
  101. EndIf
  102. Next
  103. ;ConsoleWrite(Chr(10)&"===================="&Chr(10))
  104. EndFunc ;==>getIniValue
  105.  
  106. Func _StreamIniDelete($sSection = "", $sKey = Default, $sStream = "DEFAULT")
  107. If $sSection = "" Then
  108. ;completely delete ini file stream through winapi (built in filedelete doesn't support it)
  109. Return _WinAPI_DeleteFile(_StreamIniPath($sStream, 1))
  110. Else
  111. Return IniDelete(_StreamIniPath($sStream, 1), $sSection, $sKey)
  112. EndIf
  113. EndFunc ;==>_StreamIniDelete
  114.  
  115. Func _StreamIniRead($sSection, $sKey, $sDefault, $sStream = "DEFAULT")
  116. Return IniRead(_StreamIniPath($sStream, 1), $sSection, $sKey, $sDefault)
  117. EndFunc ;==>_StreamIniRead
  118.  
  119. Func _StreamIniReadSection($sSection, $sStream = "DEFAULT")
  120. Return IniReadSection(_StreamIniPath($sStream, 1), $sSection)
  121. EndFunc ;==>_StreamIniReadSection
  122.  
  123. Func _StreamIniReadSectionNames($sStream = "DEFAULT")
  124. Return IniReadSectionNames(_StreamIniPath($sStream, 1))
  125. EndFunc ;==>_StreamIniReadSectionNames
  126.  
  127. Func _StreamIniRenameSection($sSection, $sNewSection, $iFlag = 0, $sStream = "DEFAULT")
  128. Return IniRenameSection(_StreamIniPath($sStream), $sSection, $sNewSection, $iFlag)
  129. EndFunc ;==>_StreamIniRenameSection
  130.  
  131. Func _StreamIniWrite($sSection, $sKey, $sValue, $sStream = "DEFAULT")
  132. Return IniWrite(_StreamIniPath($sStream), $sSection, $sKey, $sValue)
  133. EndFunc ;==>_StreamIniWrite
  134.  
  135. Func _StreamIniWriteSection($sSection, $vData, $iIndex = 1, $sStream = "DEFAULT")
  136. Return IniWriteSection(_StreamIniPath($sStream), $sSection, $vData, $iIndex)
  137. EndFunc ;==>_StreamIniWriteSection
  138.  
  139. Func _StreamIniPath($sStream = "DEFAULT", $iRead = 0)
  140. Local Static $sBase = ""
  141. Local $sPath = ""
  142.  
  143. If StringLen($sStream) Then
  144. If $sBase = "" Then
  145. If DriveGetFileSystem(StringLeft(@ScriptDir, 2)) = "NTFS" Then
  146. ;current drive is NTFS (supports streams)
  147. $sBase = @ScriptFullPath
  148. Else
  149. ;current drive is not NTFS (no stream support)
  150. ;fallback to regular path
  151. $sBase = @TempDir & "\" & @ScriptName
  152. EndIf
  153. EndIf
  154. If $sBase = @ScriptFullPath Then
  155. $sPath = $sBase & ":" & $sStream
  156. Else
  157. ;create directory if necessary
  158. If Not $iRead And DirGetSize($sBase) = -1 Then DirCreate($sBase)
  159. $sPath = $sBase & "\" & $sStream & ".ini"
  160. EndIf
  161. EndIf
  162.  
  163. Return $sPath
  164. EndFunc ;==>_StreamIniPath
  165.  
  166. ; ===================================================================================
Advertisement
Add Comment
Please, Sign In to add comment