Advertisement
Guest User

Ternal

a guest
Apr 29th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 23.35 KB | None | 0 0
  1. #include-once
  2. #Region ##Headers
  3. #include <Array.au3>
  4. #include <Crypt.au3>
  5. #include <File.au3>
  6. #EndRegion ##Headers
  7.  
  8. #Region ##example
  9. ;~ Local $aencryption = "4fxRuvY"
  10. ;~ _Login_CreateUser(@ScriptDir & "\test.cdt", "testuser", "testpw2", $aencryption, True)
  11. ;~ _Login_AskForList(@ScriptDir & "\test.cdt", $aencryption, True)
  12. ;~ _Login_DeleteUser(@ScriptDir & "\test.cdt", "testuser", $aencryption)
  13. ;~ _Login_CheckUserCredentials(@ScriptDir & "\test.cdt", "testuser", "testpw2", $aencryption)
  14. ;~ _Login_ChangePW(@ScriptDir & "\test.cdt", "testuser2", "test", "testpw2", $aencryption)
  15. #EndRegion ##example
  16.  
  17. #Region ##Functions
  18. ; _Login_CreateUser ====================================================================================================================
  19. ; Description ...:  Creates and writes a new user to the file. If the file does not exist it will try to make a new one.
  20. ;                   You have to provide the encryption array.
  21. ;                   For more info please check comments section/ the actual script comments :-)
  22. ; Syntax ........: _Login_CreateUser ($sUsername, $sPassword, $sEncryptionPW, $sFileLocation,[$bCreateNew = False])
  23. ; Parameters ....: $sFileLocation       - a string containing the FULL path to the file.(make sure permissions are sufficient to write there).
  24. ;                  $sUsername           - a string containing the username.(Clear txt.)
  25. ;                  $sPassword           - a string containing the password.(Clear txt.)
  26. ;                  $sEncryptionPW          - a string containing the encryption PW(Clear txt)
  27. ; Return values .: 1 if succes , 0 and sets @error if there is an error
  28. ; Author ........: Ternal
  29. ;
  30. ;@error 1: - Path does not exist($sFileLocation)    -@extended 1 : Bool to make a new path was set to false and path does not exist.
  31. ;                                                                                           -@extended 2 : Could not open file.(In use or permissions?)
  32. ;
  33. ;@error 2: Encryption   PW incorrect                        -@extended 1 :It less then 6 chars or there is a space in it.
  34. ;                                                                                           -@extended 2 : Function failed to decrypt file, PW incorrect or file corrupted.
  35. ;
  36. ;@error 3 :User already exists
  37. ;
  38. ;@error4 :Failed to create user                                 -@extended 1 : In a new file.
  39. ;                                                                                           -@extended 2 :In an existing file.
  40. ;
  41. ; ===============================================================================================================================
  42. Func _Login_CreateUser($sFileLocation, $sUsername, $sPassword, $sEncryptionPW, $bCreateNew = Default)
  43.     If $bCreateNew = Default Then $bCreateNew = False ; parameter setting
  44.     Local $hFile ; declare the var for the filehandle
  45.  
  46.     If Not (FileExists($sFileLocation)) Then ;check if path exists
  47.         If $bCreateNew = False Then Return SetError(1, 1, 0) ; if the Bool to create a new path is not set and the path does not exist return and set error
  48.         $hFile = FileOpen($sFileLocation, 9) ; create new path if it did not exist
  49.         If $hFile = -1 Then Return SetError(1, 2, 0) ; selfexplaining I guess?
  50.         FileClose($hFile) ; close da file to reopen it elsewhere, they told me I should do this asap always.
  51.     EndIf ; end of the things to do when the path does not exist
  52.  
  53.     Local $sInputCombined = $sUsername & $sPassword ; to avoid checking each string seperatly
  54.     If (Not (IsString($sUsername) And IsString($sPassword))) Or StringInStr($sInputCombined, " ") Or StringInStr($sInputCombined, ";") Or StringInStr($sInputCombined, "/") Or StringInStr($sInputCombined, "\") Then Return SetError(2, 0, 0) ; inputchecking
  55.     If StringInStr($sEncryptionPW, " ") Then Return SetError(2, 1, 0) ; inputchecking
  56.     If StringLen($sEncryptionPW) < 6 Then Return SetError(2, 1, 0) ; inputchecking
  57.     Local $aUserlist = _Login_AskForList($sFileLocation, $sEncryptionPW, True)
  58.     If _ArraySearch($aUserlist, $sUsername) > -1 Then Return SetError(3, 0, 0) ; checks if username already exists
  59.     ;If we are still in function by now this means there are no errors given by our inputchecking
  60.  
  61.     Local $aPWHash = _HashPW($sUsername, $sPassword)
  62.     $hFile = FileOpen($sFileLocation, 17) ; open the file in binary write mode
  63.     FileSetPos($hFile, 0, 0) ; set pos back to 0( because it was opened in mode 17)
  64.     Local $sEncryptedContent = FileRead($hFile) ; read the file
  65.     Local $iFileSize = BinaryLen($sEncryptedContent)
  66.     If $iFileSize < 4 Then ; file was empty, so we create the first entry.
  67.         LogWrite("_Login_CreateUser", "New Credential file started @ " & $sFileLocation)
  68.         Local $sFirstString = __StringEncrypt(True, $sUsername & ";/;" & $aPWHash[0] & ";/;" & $aPWHash[1] & ";/\;", $sEncryptionPW) ; encrypt the credentials with delimeters
  69.         FileSetPos($hFile, 0, 0) ; set cursor at the start of the file
  70.         FileWrite($hFile, $sFirstString) ; write to the file
  71.         FileFlush($hFile) ; save to disk
  72.         FileSetPos($hFile, 0, 0) ; set cursor at start of file
  73.         Local $sEncryptedContentTest = FileRead($hFile) ; read the data back from file to string. this is to ensure that the Function will not run further if it was saved incorrectly.
  74.         FileClose($hFile) ; close the file for now
  75.         If Not StringInStr(__StringEncrypt(False, $sEncryptedContentTest, $sEncryptionPW), $sUsername & ";/;" & $aPWHash[0] & ";/;" & $aPWHash[1] & ";/\;") Then ; decrypt the file and check if the new credentials are added to it
  76.             LogWrite("_Login_CreateUser", "Failure to write correctly to a new file") ; it came out wrong
  77.             Return SetError(4, 1, 0)
  78.         Else
  79.             Return 1 ; the first credential is in the file... YAAAAY
  80.         EndIf
  81.     Else
  82.         FileClose($hFile) ; close the file to reopen it in overwrite mode.(to make sure everything works correctly, I had some issues with not getting the right cursor pos so I used this out of lazyness)
  83.     EndIf
  84.     FileCopy($sFileLocation, $sFileLocation & ".bak", 9)
  85.  
  86.     Local $aCredentialList = __String2Array(__StringEncrypt(False, $sEncryptedContent, $sEncryptionPW)) ;  convert the encrypted string to arrayformat for easier handling.(array is the standard format to be used).
  87.     Local $iOldSize = UBound($aCredentialList, 1) ; get the current size of the array
  88.     If $iFileSize > 6 And $iOldSize = 0 Then
  89.         Return SetError(2, 2, 0)
  90.     EndIf
  91.     ReDim $aCredentialList[$iOldSize + 1][3] ; resize the array so it can hold one element more.By adding a new row the value of $iOldSize becomes the index of the new row   (0 based array)
  92.     $aCredentialList[$iOldSize][0] = $sUsername ; username in the first column
  93.     $aCredentialList[$iOldSize][1] = $aPWHash[0] ; passwordhash in the second column
  94.     $aCredentialList[$iOldSize][2] = $aPWHash[1] ; salt in the third column
  95.     $sEncryptedContent = __StringEncrypt(True, __Array2String($aCredentialList), $sEncryptionPW) ; encrypt the new array
  96.     $aCredentialList = "" ; get rid of the credentials in plaintext in the memory, it is no longer needed.
  97.     $hFile = FileOpen($sFileLocation, 18) ; open in binary overwritemode
  98.     FileWrite($hFile, $sEncryptedContent) ; write to the file
  99.     FileFlush($hFile) ; write to disk
  100.     FileSetPos($hFile, 0, 0) ; set cursor at start of file
  101.     Local $sEncryptedContent = FileRead($hFile) ; read the file
  102.     FileClose($hFile) ; we are finished
  103.     If Not StringInStr(__StringEncrypt(False, $sEncryptedContent, $sEncryptionPW), $sUsername & ";/;" & $aPWHash[0] & ";/;" & $aPWHash[1] & ";/\;") Then ; decrypt the file and check if the new credentials are added to it
  104.         LogWrite("_Login_CreateUser", "Failure to write correctly to file, or file has been corrupted") ; put :"it came out wrong" in da log
  105.         FileCopy($sFileLocation & ".bak", $sFileLocation, 1)
  106.         FileDelete($sFileLocation & ".bak")
  107.         Return SetError(4, 2, 0)
  108.     Else
  109.         FileDelete($sFileLocation & ".bak")
  110.         Return 1 ; the new user is in the function so I guess its bye bye
  111.     EndIf
  112. EndFunc   ;==>_Login_CreateUser
  113.  
  114. ; _Login_AskForUserList ====================================================================================================================
  115. ; Description ...: Retrieves an Userlist from a previous made credential file
  116. ; Syntax ........: _Login_Query_UserList ($sFileLocation, $sEncryptionPW,[$bUser = True])
  117. ; Parameters ....: $sFileLocation       - a string containing the location of the file
  118. ;                  $sEncryptionPW          - a string containing the encryption PW(Clear txt)
  119. ;                  $bUser               - if true then return userlist, if false return passwordlist, default is userlist
  120. ; Return values .: an array of usernames if succes, empty array or 0 at no succes
  121. ; Author ........: Ternal
  122. ;
  123. ;@error 1: - Path does not exist($sFileLocation)    -@extended 1 : Bool to make a new path was set to false and path does not exist.
  124. ;                                                                                           -@extended 2 : Could not open file.(In use or permissions?)
  125. ; ===============================================================================================================================
  126. Func _Login_AskForList($sFileLocation, $sEncryptionPW, $bUser = Default)
  127.     If Not (FileExists($sFileLocation)) Then Return SetError(1, 1, 0) ; inputchecking
  128.     If $bUser = Default Then $bUser = True
  129.     Local $aReturn[1] ; declare the return array
  130.     If $bUser = True Then
  131.         $bUser = 0 ; get the userlist
  132.     Else
  133.         $bUser = 1 ; get the passwordlist
  134.     EndIf
  135.  
  136.     Local $hFile = FileOpen($sFileLocation, 16) ; open file in binary mode
  137.     If $hFile = -1 Then Return SetError(1, 2, 0) ; inputchecking
  138.     FileSetPos($hFile, 0, 0) ; set cursor at start of file
  139.     Local $sEncryptedContent = FileRead($hFile) ; read the binary file
  140.     Local $aTemp = __String2Array(__StringEncrypt(False, $sEncryptedContent, $sEncryptionPW)) ; put everything decrypted in an array
  141.     If $bUser = 0 Then
  142.         ReDim $aReturn[UBound($aTemp, 1)] ; correct the array size to 1D for usernames
  143.         For $i = 0 To UBound($aTemp, 1) - 1
  144.             $aReturn[$i] = $aTemp[$i][$bUser] ; copy the usernames to the returnarray
  145.         Next
  146.     Else
  147.         ReDim $aReturn[UBound($aTemp, 1)][2] ; correct the array to 2D for pw and salt
  148.         For $i = 0 To UBound($aTemp, 1) - 1
  149.             $aReturn[$i][0] = $aTemp[$i][$bUser] ; copy the  password hashes to the returnarray
  150.             $aReturn[$i][1] = $aTemp[$i][$bUser + 1] ; copy the  salt to the returnarray
  151.         Next
  152.     EndIf
  153.     Return $aReturn
  154. EndFunc   ;==>_Login_AskForList
  155.  
  156. ; _Login_CheckUserCredentials ====================================================================================================================
  157. ; Description ...: Checks wether the given username and password are correct. Please do note this might malfunction when there are duplicate users so beware when creating users please.
  158. ; Syntax ........: _Login_CheckUserCredentials ($sFileLocation, $sUsername, $sPassword, $sEncryptionPW)
  159. ; Parameters ....: $sFileLocation       - a string containing the filelocation
  160. ;                  $sUsername           - a string containing the username to check
  161. ;                  $sPassword           - a string containing the password to check
  162. ;                  $sEncryptionPW           - a string containing the encryption PW(Clear txt)
  163. ; Return values .: An Array with at index 0 usercheck (true is correct , false is incorrect) and index 1 holds the password bool.If the encryption PW is wrong you will get 2x False as well
  164. ; Author ........: Ternal, Additional credits go to jchd for correcting me !!!
  165. ;
  166. ;@error 1: - Path does not exist($sFileLocation)    -@extended 1 : Bool to make a new path was set to false and path does not exist.
  167. ;                                                                                           -@extended 2 : Could not open file.(In use or permissions?)
  168. ; ===============================================================================================================================
  169. Func _Login_CheckUserCredentials($sFileLocation, $sUsername, $sPassword, $sEncryptionPW)
  170.     Local $aReturn[2] = [False, False] ; create return array and set it false
  171.     Local $aUserlist = _Login_AskForList($sFileLocation, $sEncryptionPW, True) ; ask for a list of users
  172.     If @error Then
  173.         Local $error = @error
  174.         Local $extended = @extended
  175.         Return SetError($error, @extended, $aReturn)
  176.     EndIf
  177.  
  178.     Local $iLocationUsername = _ArraySearch($aUserlist, $sUsername, 0, 0, 0, 0, 1, 0) ; search the first column(usernames) non-case sensitive.
  179.     If @error Then Return $aReturn
  180.     If $iLocationUsername > -1 Then ; function returns an integer thats 0 or above so it has found something.
  181.         $aReturn[0] = True ; set username to be true(found it)
  182.     Else ; better luck next time for a correct user :(
  183.         Return $aReturn ; end of the function for this path
  184.     EndIf
  185.     Local $aPWList = _Login_AskForList($sFileLocation, $sEncryptionPW, False) ;still running so we are asking for the passwordhashlist...
  186.     Local $sNewHash = _HashPW($sUsername, $sPassword, $aPWList[$iLocationUsername][1])
  187.     If Not ($aPWList[$iLocationUsername][0] == $sNewHash[0]) Then ; check if the passwordhash at the location where we found the username is the same as the hash generated
  188.         Return $aReturn ; not the same
  189.     Else
  190.         $aReturn[1] = True
  191.         Return $aReturn
  192.     EndIf
  193. EndFunc   ;==>_Login_CheckUserCredentials
  194.  
  195. ; _Login_DeleteUser ====================================================================================================================
  196. ; Description ...: Deletes an user from the file
  197. ; Syntax ........: _Login_DeleteUser($sFileLocation, $sUsername, $sEncryptionPW)
  198. ; Parameters ....: $sFileLocation       - a string containing the filepath
  199. ;                  $sUsername           - a string containing the user to delete
  200. ;                  $sEncryptionPW        - a string containing the encryption PW(Clear txt)
  201. ; Return values .: 1 if succes, 0 on error, 404 if the user is not found.
  202. ; Author ........: Ternal
  203. ;
  204. ;@error 1: - Path does not exist($sFileLocation)    -@extended 1 : Bool to make a new path was set to false and path does not exist.
  205. ;                                                                                           -@extended 2 : Could not open file.(In use or permissions?)
  206. ;
  207. ;@error2: -Failed to get userlist, encryption PW might be wrong or file might be corrupted
  208. ;
  209. ;@error3 / return 404 : -User to delete from userlist was NOT in the userlist.
  210. ; ===============================================================================================================================
  211. Func _Login_DeleteUser($sFileLocation, $sUsername, $sEncryptionPW)
  212.     Local $aUserlist = _Login_AskForList($sFileLocation, $sEncryptionPW, True) ; ask for a list of users
  213.     If @error Then
  214.         Local $error = @error
  215.         Local $extended = @extended
  216.         Return SetError($error, @extended, 0)
  217.     EndIf
  218.     Local $iSearch = _ArraySearch($aUserlist, $sUsername, 0, 0, 0, 0, 1, 0)
  219.     If @error = 3 Then Return SetError(2, 0, 0)
  220.     If $iSearch > -1 Then
  221.         Local $hFile = FileOpen($sFileLocation, 16)
  222.         Local $sEncryptedContent = FileRead($sFileLocation)
  223.         FileClose($hFile)
  224.         Local $aCredentialList = __String2Array(__StringEncrypt(False, $sEncryptedContent, $sEncryptionPW)) ;  convert the encrypted string to arrayformat for easier handling.(array is the standard format to be used).
  225.         _ArrayDelete($aCredentialList, $iSearch)
  226.         $hFile = FileOpen($sFileLocation, 18)
  227.         FileWrite($hFile, __StringEncrypt(True, __Array2String($aCredentialList), $sEncryptionPW))
  228.         FileClose($hFile)
  229.     Else
  230.         Return SetError(3, 0, 404)
  231.     EndIf
  232.     Return 1
  233. EndFunc   ;==>_Login_DeleteUser
  234.  
  235. ; _Login_ChangePW ====================================================================================================================
  236. ; Name ..........: _Login_ChangePW
  237. ; Description ...: Changes the PW for a user, in reality it checks the old credentials, if correct it deletes the old user and recreates a new user with the new password (CALL ME LAZY , Proud of it).
  238. ; Syntax ........: _Login_ChangePW($sFileLocation, $sUsername, $NewPW, $OldPW, $sEncryptionPW)
  239. ; Parameters ....: $sFileLocation       - a string containing the filepath
  240. ;                  $sUsername          - a string containing the user to change pw of
  241. ;                  $NewPW               - a string containing  the new pw in plaintext
  242. ;                  $OldPW               - a string containing  the old pw in plaintext
  243. ;                  $sEncryptionPW        - a string containing the encryption PW(Clear txt)
  244. ; Return values .: 1 if succes, 0 if no succes
  245. ; Author ........: Ternal
  246. ; ===============================================================================================================================
  247. Func _Login_ChangePW($sFileLocation, $sUsername, $NewPW, $OldPW, $sEncryptionPW)
  248.     Local $aCheck = _Login_CheckUserCredentials($sFileLocation, $sUsername, $OldPW, $sEncryptionPW)
  249.     If $aCheck[0] = False Then Return 0
  250.     If $aCheck[1] = False Then Return 0
  251.     _Login_DeleteUser($sFileLocation, $sUsername, $sEncryptionPW)
  252.     _Login_CreateUser($sFileLocation, $sUsername, $NewPW, $sEncryptionPW)
  253.     Return 1
  254. EndFunc   ;==>_Login_ChangePW
  255.  
  256. ; _HashPW ====================================================================================================================
  257. ; Description ...: hashes a PW with salt( almost seems like this is cooking rather then programming ain't it?)
  258. ; Syntax ........: _HashPW($sUsername, $sPlainTextPW[, $sSalt = Default])
  259. ; Parameters ....: $sUsername          - a string containing the user
  260. ;                  $sPlainTextPW        - a string containing the pw
  261. ;                  $sSalt               - [optional] a string that contains the salt of the pw to has, Default is a new random salt of 20 chars.
  262. ; Return values .:  0 on error, array with hash and salt on succes
  263. ; Author ........: Ternal
  264. ; ===============================================================================================================================
  265. Func _HashPW($sUsername, $sPlainTextPW, $sSalt = Default)
  266.     If $sSalt = Default Then $sSalt = __Randomstring(20)
  267.     If Not IsString($sPlainTextPW) Then Return SetError(1, 0, 0)
  268.     If StringLen($sPlainTextPW) < 3 Then Return SetError(2, 0, 0)
  269.     _Crypt_Startup()
  270.     Local $sHash = _Crypt_HashData($sUsername & $sSalt & $sPlainTextPW, $CALG_SHA_512)
  271.     _Crypt_Shutdown()
  272.     Local $aReturn[2] = [$sHash, $sSalt]
  273.     Return $aReturn
  274. EndFunc   ;==>_HashPW
  275.  
  276. ; __Randomstring ====================================================================================================================
  277. ; Description ...: generates a random string of $length
  278. ; Syntax ........: __Randomstring($length)
  279. ; Parameters ....: $length              - integer containing the length of the string to generate
  280. ; Return values .: a random string
  281. ; Author ........: PhilRip
  282. ; Modified ......: 29/03/2009
  283. ; ===============================================================================================================================
  284. Func __Randomstring($length)
  285.     Local $chars = StringSplit("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", "")
  286.     Local $String = ""
  287.     Local $i = 0
  288.     Do
  289.         If $length <= 0 Then ExitLoop
  290.         $String &= $chars[Random(1, $chars[0])]
  291.         $i += 1
  292.     Until $i = $length
  293.     Return $String
  294. EndFunc   ;==>__Randomstring
  295.  
  296. ; __String2Array ====================================================================================================================
  297. ; Name ..........: __String2Array
  298. ; Description ...: Converts a decrypted string to array
  299. ; Syntax ........: __String2Array($sDecryptedString)
  300. ; Parameters ....: $sDecryptedString    - a string containing the decrypted file
  301. ; Return values .: an array of the string
  302. ; Author ........: Ternal
  303. ; ===============================================================================================================================
  304. Func __String2Array($sDecryptedString)
  305.     Local $aColums ; declare an array to hold each column value for each row
  306.     Local $aRows = StringSplit($sDecryptedString, ";/\;", 1) ; ;/\; is the delimiter for rows, this splits up the rows in decrypted file string
  307.     Local $aArray[$aRows[0]][3] ; declare an array big enough to hold all array vars.
  308.     For $i = 1 To $aRows[0]
  309.         $aColums = StringSplit($aRows[$i], ";/;", 1) ; ;/; is the delimiter for cells this splits up the colums per row
  310.         For $j = 1 To $aColums[0]
  311.             $aArray[$i - 1][$j - 1] = $aColums[$j] ; copy the array info, notice the - 1 , this moves the 1based array to a 0 based array
  312.         Next
  313.     Next
  314.     ReDim $aArray[$aRows[0] - 1][3] ; resize to get rid of the 1-based array from stringsplit, this will now be at the end
  315.     Return $aArray
  316. EndFunc   ;==>__String2Array
  317.  
  318. ; __Array2String ====================================================================================================================
  319. ; Name ..........: __Array2String
  320. ; Description ...: preps an array to be put into encryption as a string.
  321. ; Syntax ........: __Array2String($aArray)
  322. ; Parameters ....: $aArray              - an array of credentials
  323. ; Return values .: a string of credentials
  324. ; Author ........: Ternal
  325. ; ===============================================================================================================================
  326. Func __Array2String($aArray)
  327.     Local $sReturn ; declare return string
  328.     For $i = 0 To UBound($aArray, 1) - 1
  329.         For $j = 0 To UBound($aArray, 2) - 1
  330.             $sReturn = $sReturn & $aArray[$i][$j] & ";/;" ; add column delimiters
  331.         Next
  332.         $sReturn = StringTrimRight($sReturn, 3) ; delete the last delimiter
  333.         $sReturn &= ";/\;" ; place a new row delimiter
  334.     Next
  335.     Return $sReturn
  336. EndFunc   ;==>__Array2String
  337.  
  338. ; __StringEncrypt ====================================================================================================================
  339. ; Name ..........: __StringEncrypt
  340. ; Description ...: function found on autoitForum
  341. ; Syntax ........: __StringEncrypt($bEncrypt, $sData, $sPassword)
  342. ; Parameters ....: $bEncrypt            - a boolean value.
  343. ;                  $sData               - a string value.
  344. ;                  $sPassword           - a string value.
  345. ; Return values .: None
  346. ; Author ........: perfaram ?? I forgot the user who made this function, AWFULLY SORRY :/ The person who wrote this deserves all the credits!!
  347. ; ===============================================================================================================================
  348. Func __StringEncrypt($bEncrypt, $sData, $sPassword)
  349.     _Crypt_Startup() ; Start the Crypt library.
  350.     Local $vReturn = ''
  351.     Local $hKey = _Crypt_DeriveKey(StringToBinary($sPassword), $CALG_AES_256)
  352.     If $bEncrypt Then ; If the flag is set to True then encrypt, otherwise decrypt.
  353.         $vReturn = _Crypt_EncryptData($sData, $hKey, $CALG_USERKEY) ; encrypt data
  354.     Else
  355.         $vReturn = BinaryToString(_Crypt_DecryptData($sData, $hKey, $CALG_USERKEY)) ; decrypt data
  356.     EndIf
  357.     _Crypt_DestroyKey($hKey)
  358.     _Crypt_Shutdown() ; Shutdown the Crypt library.
  359.     Return $vReturn
  360. EndFunc   ;==>__StringEncrypt
  361.  
  362. ; LogWrite ====================================================================================================================
  363. ; Name ..........: LogWrite
  364. ; Description ...: Well , in case you were wondering it writes a log file....
  365. ; Syntax ........: LogWrite($sFunction, $sTxt)
  366. ; Parameters ....: $sFunction           - a string containing the function who called the logwrite
  367. ;                  $sTxt                - a string containing whatever you deem logworthy
  368. ; Author ........: Ternal
  369. ; ===============================================================================================================================
  370. Func LogWrite($sFunction, $sTxt)
  371.     Local $sFullString = @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & " " & "function " & $sFunction & " reports:  " & $sTxt ; create a string with a timestamp
  372.     ConsoleWrite($sFullString & @CRLF) ; write it to console(because I am still to lazy to go to the actual map an read the txt file..
  373.     Local $errorFile = @WorkingDir & "\" & @ScriptName & ".log" ; make a logfilepath string
  374.     Local $hFileOpen = FileOpen($errorFile, 9) ; create path/ append to end of file params
  375.     FileWriteLine($hFileOpen, $sFullString & @CRLF) ; write the line
  376.     FileClose($hFileOpen) ; lets close it
  377. EndFunc   ;==>LogWrite
  378. #EndRegion ##Functions
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement