Leaderboard
Popular Content
Showing content with the highest reputation on 05/07/2021 in all areas
-
Problem: well, you know how when your total path length exceeds 256 characters, bad things start to happen, right? Solution: somewhere in the Developer Chat forum, i suggested that long paths should be supported natively by AutoIt. this is progressing leisurely, and until completed, i re-wrote most of AutoIt core file management functions to support long paths. the concept is to call the unicode versions of the file management functions in kernel32.dll, and use the unicode prefix \\?\ or \\?\UNC\ where needed. in addition it requires some preparation steps, like creating directory structure, listing files to support wildcards, etc. this UDF was created because i needed a convenient way to make my existing scripts support long paths. so basically, the use of every LFN function is identical to the use of its native equivalent (same parameters and return values). for example, use _LFN_DirCreate() instead of DirCreate(). that's it. it works exactly the same, except when it comes to too long paths; it this case the LFN functions work where the native AutoIt functions fail. Note #1: you do not need to specify the unicode prefix. the UDF functions take care of that. this works: _LFN_DirCreate("C:\some\ridiculously\long\path\over\260\characters") you don't need this: _LFN_DirCreate("\\?\C:\some\ridiculously\long\path\over\260\characters") Note #2: _LFN_FileCopy lost its unique flags, and is now utilizing the native function FileCopy. Demonstration: hereunder, as well as the UDF, is a demo script of all of this UDF main functions. download the UDF itself (name it "LFN.au3") and the demo script to the same folder, and run the script. note that after each command the script pauses with a MsgBox, so you can review the results of the operation. do feel free to extend the demo script with more flags combinations. it creates long paths in C:\TEMP\LFN, so it won't be too hard to cleanup later once you are done with your tests. tested on file systems: fixed NTFS, removable NTFS, network ext4 Status: testing phase is complete. this UDF is now in production. enjoy! Latest Updates (release notes): post #39 - UDF v5.2 and demo script post #38 - script converter the script converter is GUI-based, with a clear display of the conversion: original/converted lines displayed side-by-side, tooltip to show the context of the converted lines showing 10 lines before and after: also the icon for the LFN conversion script, if you wish to compile: LFN_Script_Converter_NG.ico hope you appreciate the icon design : Downloads: the UDF: #include-Once ; #INDEX# ======================================================================================================================= ; Title .........: LFN ; AutoIt Version : 3.3.14.2 ; UDF Version ...: 5.2 ; Status ........: Production ; Language ......: English ; Description ...: Standard file management functions rewritten to overcome the MAX_PATH limitation of 256 characters by: ; - prepending the unicode prefix \\?\ or \\?\UNC\ where needed ; - calling kernel32 DLL with the unicode versions of the relevant functions ; - validating directory structure before calling the DLL ; - applying wildcards where not supported by the DLL ; - full compliance of parameters and return values with the equivalent native AutoIt functions: ; -- there may be additional use of @extended or @error when required ; -- there may be additional values that existing parameters can accept ; This UDF was created because: ; - not all of the above conditions are met by the WinAPIEx UDF ; - there was a need for convenient way to make existing scripts support long file names ; Native AutoIt functions that did not find their place in this UDF: ; FileChangeDir - couldn't get it to work. ; FileCreateNTFSLink - not sure what it is and what it does. ; FileCreateShortcut - couldn't get it to work. ; FileGetShortcut - couldn't get FileCreateShortcut to work, so didn't proceed here. ; FileInstall - couldn't get it to work. ; FileOpenDialog - couldn't get it to work with init dir in too long path; but it does set @WorkingDir! ; FileRecycle - not applicable: too long paths can not be put to recycle bin anyway. ; FileRecycleEmpty - not applicable: too long paths can not be put to recycle bin anyway. ; FileSaveDialog - couldn't get it to work with init dir in too long path; but it does set @WorkingDir! ; FileSelectFolder - seems to work as is. ; How To use this UDF: ; - for new scripts: as usual, include this UDF in your script and use its functions. ; - for existing scripts: use the conversion script (downloadable from the AutoIt forum). The conversion will ; replace the native functions calls with their LFN equivalents, and add an #include statement for this UDF ; just after your last #include statement (or at the top of your script if you have no #include statements). ; There is no need to change anything in the parameters or return values. ; Remark on the _LFN_Ini* functions: ; - comments (any text following a semicolon) are preserved. Comment following a Key=Value line are considered ; as part of the value string. ; Dll ...........: kernel32.dll ; Author(s) .....: orbs ; Resources .....: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx ; http://www.geoffchappell.com/studies/windows/win32/kernel32/api/ ; =============================================================================================================================== ; #CURRENT# ===================================================================================================================== ;_LFN_DirCopy ;_LFN_DirCreate ;_LFN_DirGetSize ;_LFN_DirMove ;_LFN_DirRemove ;_LFN_FileClose ;_LFN_FileCopy ;_LFN_FileDelete ;_LFN_FileExists ;_LFN_FileFindFirstFile ;_LFN_FileFindNextFile ;_LFN_FileFlush ;_LFN_FileGetAttrib ;_LFN_FileGetEncoding ;_LFN_FileGetLongName ;_LFN_FileGetPos ;_LFN_FileGetShortName ;_LFN_FileGetSize ;_LFN_FileGetTime ;_LFN_FileGetVersion ;_LFN_FileMove ;_LFN_FileOpen ;_LFN_FileRead ;_LFN_FileReadLine ;_LFN_FileReadToArray ;_LFN_FileSetAttrib ;_LFN_FileSetEnd ;_LFN_FileSetPos ;_LFN_FileSetTime ;_LFN_FileWrite ;_LFN_FileWriteLine ;_LFN_IniDelete ;_LFN_IniRead ;_LFN_IniReadSection ;_LFN_IniReadSectionNames ;_LFN_IniRenameSection ;_LFN_IniWrite ;_LFN_IniWriteSection ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name ..........: _LFN_DirCopy ; Description ...: Copies a directory and all sub-directories and files. ; Syntax.........: _LFN_DirCopy($sSrcPath, $sDstPath[, $iFlag = 0]) ; Parameters ....: $sSrcPath - Path of the source directory (with no trailing backslash). e.g. "C:\Path1" ; $sDstPath - Path of the destination directory (with no trailing backslash). e.g. "C:\Path_Copy" ; $iFlag - [optional] This flag determines whether to overwrite files if they already exist: ; $FC_NOOVERWRITE (0) = (default) do not overwrite existing files ; $FC_OVERWRITE (1) = overwrite existing files ; Constants are defined in FileConstants.au3 ; Return values .: Success - Returns 1 ; Failure - Returns 0 and sets @error to 1 ; Author ........: orbs ; Modified ......: ; Remarks .......: If the destination directory structure doesn't exist, it will be created (if possible). This means that flag 8 ; is assumed, and needs not be specified. ; Overwrite is determined per file, and complies with flag combination. ; NOTE: DirCopy('D:\dir','C:\') will fail, but _LFN_DirCopy('D:\dir','C:\') will succeed. Make of it whatever ; suits you. ; Related .......: ; Dependencies ..: _LFN_DirCreate, _LFN_FileCopy ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _LFN_DirCopy($sSrcPath, $sDstPath, $iFlag = 0) ; preparation $sSrcPath = __LFN_Target_RemoveTrailingBackslash($sSrcPath) $sDstPath = __LFN_Target_RemoveTrailingBackslash($sDstPath) If Not __LFN_Target_IsExistingFolder($sSrcPath) Then Return SetError(1, 0, 0) _LFN_DirCreate($sDstPath) ; main action Local $aFiles = __LFN_FilesListToArray($sSrcPath & '\*') Local $i Local $bOneFail = False For $i = 1 To $aFiles[0] If StringRight($aFiles[$i], 1) = '\' Then _LFN_DirCreate($sDstPath & '\' & __LFN_Target_LastElement_Get(StringTrimRight($aFiles[$i], 1))) If Not _LFN_DirCopy($aFiles[$i], $sDstPath & '\' & __LFN_Target_LastElement_Get(StringTrimRight($aFiles[$i], 1)), $iFlag) Then $bOneFail = True Else If Not _LFN_FileCopy($aFiles[$i], $sDstPath & '\', BitOR($iFlag, 8)) Then $bOneFail = True EndIf Next If $bOneFail Then Return SetError(1, 0, 0) Return 1 EndFunc ;==>_LFN_DirCopy ; #FUNCTION# ==================================================================================================================== ; Name ..........: _LFN_DirCreate ; Description ...: Creates a directory. ; Syntax.........: _LFN_DirCreate($sPath) ; Parameters ....: $sPath - Full path of the directory to create. ; Return values .: Success - Returns 1 ; Failure - Returns 0, sets @error to 1, and sets @extended to the @error returned from DllCall ; Author ........: orbs ; Modified ......: ; Remarks .......: This function will also create all parent directories given in $sPath if they do not already exist. ; Related .......: ; Dependencies ..: ; Link ..........: http://msdn.microsoft.com/en-us/library/windows/desktop/aa363855(v=vs.85).aspx ; Example .......: No ; =============================================================================================================================== Func _LFN_DirCreate($sPath) ; standard procedure Local $hDLL = __LFN_DllOpen() If @error Then Return SetError(1, 0, 0) Local $nFirstElement = 7 ; assuming local drive Local $nNthFound = 0 Local $i $sPath = __LFN_Target_SetUnicodePrefix($sPath) If @extended = 2 Then ; assumption incorrect, it's a UNC path $nFirstElement = 0 For $i = 1 To StringLen($sPath) If StringMid($sPath, $i, 1) = '\' Then $nNthFound += 1 If $nNthFound = 6 Then $nFirstElement = $i EndIf Next EndIf ; main action For $i = $nFirstElement To StringLen($sPath) If StringMid($sPath, $i, 1) = '\' Then DllCall($hDLL, 'bool', 'CreateDirectoryW', 'wstr', StringLeft($sPath, $i), 'struct*', 0) EndIf Next DllCall($hDLL, 'bool', 'CreateDirectoryW', 'wstr', $sPath, 'struct*', 0) If __LFN_Target_IsExistingFolder($sPath) Then Return 1 Return 0 EndFunc ;==>_LFN_DirCreate ; #FUNCTION# ==================================================================================================================== ; Name ..........: _LFN_DirGetSize ; Description ...: Use exactly like the native AutoIt function DirGetSize ; Syntax.........: _LFN_DirGetSize($sPath[, $iFlag = 0]) ; =============================================================================================================================== Func _LFN_DirGetSize($sPath, $iFlag = 0) $sPath = __LFN_Target_SetUnicodePrefix($sPath) Local $result = DirGetSize($sPath, $iFlag) Return SetError(@error, @extended, $result) EndFunc ;==>_LFN_DirGetSize ; #FUNCTION# ==================================================================================================================== ; Name ..........: _LFN_DirMove ; Description ...: Moves a directory and all sub-directories and files. ; Syntax.........: _LFN_DirMove($sSrcPath, $sDstPath[, $iFlag = 0]) ; Parameters ....: $sSrcPath - Path of the source directory (with no trailing backslash). e.g. "C:\Path1" ; $sDstPath - Path of the destination directory (with no trailing backslash). e.g. "C:\Path_Copy" ; $iFlag - [optional] This flag determines whether to overwrite files if they already exist: ; $FC_NOOVERWRITE (0) = (default) do not overwrite existing files ; $FC_OVERWRITE (1) = overwrite existing files ; Constants are defined in FileConstants.au3 ; Return values .: Success - Returns 1 ; Failure - Returns 0 and sets @error to 1 ; Author ........: orbs ; Modified ......: ; Remarks .......: - If the source and destination are on different volumes or UNC paths are used, then a copy+delete operation ; is performed rather than a move. If the 'copy' or 'delete' fails, then depending on the reason of failure, ; there may remain some files either in the source or destination, where not expected. ; - If the destination already exists and the overwrite flag IS specified, then the source directory will be ; moved inside the destination. If a subfolder of the destination folder already exists by the name of the ; source folder, then source files will overwrite destination files if exist. ; - If the destination already exists and the overwrite flag IS NOT specified, the operation fails. ; - Because AutoIt lacks a "_LFN_DirRename" function, use _LFN_DirMove to rename a folder! ; Related .......: ; Dependencies ..: _LFN_FileDelete, _LFN_DirCopy, _LFN_DirRemove ; Link ..........: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365240(v=vs.85).aspx ; Example .......: No ; =============================================================================================================================== Func _LFN_DirMove($sSrcPath, $sDstPath, $iFlag = 0) ; standard procedure Local $hDLL = __LFN_DllOpen() If @error Then Return SetError(1, 0, 0) ; preparation $sSrcPath = __LFN_Target_RemoveTrailingBackslash($sSrcPath) $sDstPath = __LFN_Target_RemoveTrailingBackslash($sDstPath) If Not __LFN_Target_IsExistingFolder($sSrcPath) Then Return SetError(1, 0, 0) If __LFN_FilesExist($sDstPath) Then Switch @extended Case 1 ; file If $iFlag Then ; overwrite => delete file _LFN_FileDelete($sSrcPath) Else Return SetError(1, 0, 0) ; fail EndIf Case 3 ; folder If $iFlag Then ; overwrite => move inside $sDstPath = $sDstPath & '\' & __LFN_Target_LastElement_Get($sSrcPath) Else Return SetError(1, 0, 0) ; fail EndIf EndSwitch EndIf ; main action Local $aRet = DllCall($hDLL, 'bool', 'MoveFileExW', 'wstr', __LFN_Target_SetUnicodePrefix($sSrcPath), 'wstr', __LFN_Target_SetUnicodePrefix($sDstPath), 'dword', 2 + $iFlag) If $aRet[0] = 0 Then If _LFN_DirCopy($sSrcPath, $sDstPath, $iFlag) Then _LFN_DirRemove($sSrcPath, 3) Else Return SetError(1, 0, 0) EndIf EndIf Return 1 EndFunc ;==>_LFN_DirMove ; #FUNCTION# ==================================================================================================================== ; Name ..........: _LFN_DirRemove ; Description ...: Deletes a directory. ; Syntax.........: _LFN_DirRemove($sPath[, $iFlag = 0]) ; Parameters ....: $sPath - Full path of the directory to remove. ; $iFlag - [optional] This flag is a combination of the following values: ; 1 = recurse subfolders ; 2 = clear the Read-only and System attributes to force removal ; Return values .: Success - Returns 1 ; Failure - Returns 0 and sets @error to 1 ; Author ........: orbs ; Modified ......: ; Remarks .......: ; Related .......: ; Dependencies ..: _LFN_FileSetAttrib, _LFN_FileDelete ; Link ..........: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365488(v=vs.85).aspx ; Example .......: No ; =============================================================================================================================== Func _LFN_DirRemove($sPath, $iFlag = 0) ; standard procedure Local $hDLL = __LFN_DllOpen() If @error Then Return SetError(1, 0, 0) $sPath = __LFN_Target_SetUnicodePrefix($sPath) If Not __LFN_Target_IsExistingFolder($sPath) Then Return SetError(1, 0, 0) ; main action If BitAND($iFlag, 1) Then Local $aFiles = __LFN_FilesListToArray($sPath, BitAND($iFlag, 1)) Local $i, $aRet For $i = $aFiles[0] To 1 Step -1 If StringRight($aFiles[$i], 1) = '\' Then If BitAND($iFlag, 2) Then _LFN_FileSetAttrib($aFiles[$i], '-RS') $aRet = DllCall($hDLL, 'bool', 'RemoveDirectoryW', 'wstr', StringTrimRight($aFiles[$i], 1)) If $aRet[0] = 0 Then Return SetError(1, @error, 0) Else If BitAND($iFlag, 2) Then _LFN_FileSetAttrib($aFiles[$i], '-RS') _LFN_FileDelete($aFiles[$i]) EndIf Next EndIf $aRet = DllCall($hDLL, 'bool', 'RemoveDirectoryW', 'wstr', $sPath) If @error Then Return SetError(1, @error, 0) If FileExists($sPath) Then Return SetError(1, 0, 0) Return 1 EndFunc ;==>_LFN_DirRemove ; #FUNCTION# ==================================================================================================================== ; Name ..........: _LFN_FileClose ; Description ...: Use exactly like the native AutoIt function FileClose ; Syntax.........: _LFN_FileClose($hFile) ; =============================================================================================================================== Func _LFN_FileClose($hFile) Local $result = FileClose($hFile) Return SetError(@error, @extended, $result) EndFunc ;==>_LFN_FileClose ; #FUNCTION# ==================================================================================================================== ; Name ..........: _LFN_FileCopy ; Description ...: Use exactly like the native AutoIt function FileCopy ; Syntax ........: _LFN_FileCopy($sSrc, $sDst[, $iFlag = 0]) ; =============================================================================================================================== Func _LFN_FileCopy($sSrc, $sDst, $iFlag = 0) $sSrc = __LFN_Target_SetUnicodePrefix($sSrc) $sDst = __LFN_Target_SetUnicodePrefix($sDst) Local $result = FileCopy($sSrc, $sDst, $iFlag) Return SetError(@error, @extended, $result) EndFunc ;==>_LFN_FileCopy ; #FUNCTION# ==================================================================================================================== ; Name ..........: _LFN_FileDelete ; Description ...: Use exactly like the native AutoIt function FileDelete ; Syntax.........: _LFN_FileDelete($sMask) ; =============================================================================================================================== Func _LFN_FileDelete($sMask) $sMask = __LFN_Target_SetUnicodePrefix($sMask) Local $result = FileDelete($sMask) Return SetError(@error, @extended, $result) EndFunc ;==>_LFN_FileDelete ; #FUNCTION# ==================================================================================================================== ; Name ..........: _LFN_FileExists ; Description ...: Use exactly like the native AutoIt function FileExists ; Syntax.........: _LFN_FileExists($sFile) ; =============================================================================================================================== Func _LFN_FileExists($sFile) $sFile = __LFN_Target_SetUnicodePrefix($sFile) Local $result = FileExists($sFile) Return SetError(@error, @extended, $result) EndFunc ;==>_LFN_FileExists ; #FUNCTION# ==================================================================================================================== ; Name ..........: _LFN_FileFindFirstFile ; Description ...: Use exactly like the native AutoIt function FileFindFirstFile ; Syntax.........: _LFN_FileFindFirstFile($sFile) ; =============================================================================================================================== Func _LFN_FileFindFirstFile($sFile) $sFile = __LFN_Target_SetUnicodePrefix($sFile) Local $result = FileFindFirstFile($sFile) Return SetError(@error, @extended, $result) EndFunc ;==>_LFN_FileFindFirstFile ; #FUNCTION# ==================================================================================================================== ; Name ..........: _LFN_FileFindNextFile ; Description ...: Use exactly like the native AutoIt function FileFindNextFile ; Syntax.........: _LFN_FileFindNextFile($hSearch) ; =============================================================================================================================== Func _LFN_FileFindNextFile($hSearch) Local $result = FileFindNextFile($hSearch) Return SetError(@error, @extended, $result) EndFunc ;==>_LFN_FileFindNextFile ; #FUNCTION# ==================================================================================================================== ; Name ..........: _LFN_FileFlush ; Description ...: Use exactly like the native AutoIt function FileFlush ; Syntax.........: _LFN_FileFlush($hFile) ; =============================================================================================================================== Func _LFN_FileFlush($hFile) Local $result = FileFlush($hFile) Return SetError(@error, @extended, $result) EndFunc ;==>_LFN_FileFlush ; #FUNCTION# ==================================================================================================================== ; Name ..........: _LFN_FileGetAttrib ; Description ...: Use exactly like the native AutoIt function FileGetAttrib ; Syntax.........: _LFN_FileGetAttrib($sTarget) ; =============================================================================================================================== Func _LFN_FileGetAttrib($sTarget) $sTarget = __LFN_Target_SetUnicodePrefix($sTarget) Local $result = FileGetAttrib($sTarget) Return SetError(@error, @extended, $result) EndFunc ;==>_LFN_FileGetAttrib ; #FUNCTION# ==================================================================================================================== ; Name ..........: _LFN_FileGetEncoding ; Description ...: Use exactly like the native AutoIt function FileGetEncoding ; Syntax.........: _LFN_FileGetEncoding($xFile[, $nMode = 1]) ; =============================================================================================================================== Func _LFN_FileGetEncoding($xFile, $nMode = 1) If IsString($xFile) Then $xFile = __LFN_Target_SetUnicodePrefix($xFile) Local $result = FileGetEncoding($xFile, $nMode) Return SetError(@error, @extended, $result) EndFunc ;==>_LFN_FileGetEncoding ; #FUNCTION# ==================================================================================================================== ; Name ..........: _LFN_FileGetLongName ; Description ...: Returns the long path+name of the path+name passed. ; Syntax.........: _LFN_FileGetLongName($sFile[, $iFlag = 0]) ; Parameters ....: $sFile - Full path and file name to convert ; $iFlag - [optional] if 1 file can have relative dir, e.g. "..\file.txt" ; Return values .: Success - Returns the long path+name of the path+name passed. ; Failure - Returns the parameter and sets @error to 1 ; Author ........: orbs ; Modified ......: ; Remarks .......: ; Related .......: ; Dependencies ..: ; Link ..........: http://msdn.microsoft.com/en-us/library/windows/desktop/aa364980(v=vs.85).aspx ; http://msdn.microsoft.com/en-us/library/windows/desktop/aa364963(v=vs.85).aspx ; Example .......: No ; =============================================================================================================================== Func _LFN_FileGetLongName($sFile, $iFlag = 0) Local $aRet Local $sFileFullPath If $iFlag Then $aRet = DllCall('kernel32.dll', 'dword', 'GetFullPathNameW', 'wstr', __LFN_Target_SetUnicodePrefix($sFile), 'dword', 4096, 'wstr', '', 'ptr', 0) If @error Or Not $aRet[0] Then $sFileFullPath = $sFile $sFileFullPath = $aRet[3] Else $sFileFullPath = $sFile EndIf $aRet = DllCall('kernel32.dll', 'dword', 'GetLongPathNameW', _ 'wstr', __LFN_Target_SetUnicodePrefix($sFileFullPath), _ 'wstr', '', _ 'dword', 65536) If $aRet[0] = 0 Then Return SetError(1, $sFile) Return __LFN_Target_UnSetUnicodePrefix($aRet[2]) EndFunc ;==>_LFN_FileGetLongName ; #FUNCTION# ==================================================================================================================== ; Name ..........: _LFN_FileGetPos ; Description ...: Use exactly like the native AutoIt function FileGetPos ; Syntax.........: _LFN_FileGetPos($hFile) ; =============================================================================================================================== Func _LFN_FileGetPos($hFile) Local $result = FileGetPos($hFile) Return SetError(@error, @extended, $result) EndFunc ;==>_LFN_FileGetPos ; #FUNCTION# ==================================================================================================================== ; Name ..........: _LFN_FileGetSize ; Description ...: Use exactly like the native AutoIt function FileGetSize ; Syntax.........: _LFN_FileGetSize($sFile) ; =============================================================================================================================== Func _LFN_FileGetSize($sFile) $sFile = __LFN_Target_SetUnicodePrefix($sFile) Local $result = FileGetSize($sFile) Return SetError(@error, @extended, $result) EndFunc ;==>_LFN_FileGetSize ; #FUNCTION# ==================================================================================================================== ; Name ..........: _LFN_FileGetShortName ; Description ...: Use exactly like the native AutoIt function FileGetShortName ; Syntax.........: _LFN_FileGetShortName($sFile[, $iFlag = 0]) ; =============================================================================================================================== Func _LFN_FileGetShortName($sFile, $iFlag = 0) $sFile = __LFN_Target_SetUnicodePrefix($sFile) Local $result = FileGetShortName($sFile, $iFlag) Local $nError = @error Local $nExtended = @extended $result = __LFN_Target_UnSetUnicodePrefix($result) ; the result is a short name, therefore must not have the unicode prefix. Return SetError($nError, $nExtended, $result) EndFunc ;==>_LFN_FileGetShortName ; #FUNCTION# ==================================================================================================================== ; Name ..........: _LFN_FileGetTime ; Description ...: Use exactly like the native AutoIt function FileGetTime ; Syntax.........: _LFN_FileGetTime($sFile[, $nOption = 0[, $nFormat = 0]]) ; =============================================================================================================================== Func _LFN_FileGetTime($sFile, $nOption = 0, $nFormat = 0) $sFile = __LFN_Target_SetUnicodePrefix($sFile) Local $result = FileGetTime($sFile, $nOption, $nFormat) Return SetError(@error, @extended, $result) EndFunc ;==>_LFN_FileGetTime ; #FUNCTION# ==================================================================================================================== ; Name ..........: _LFN_FileGetVersion ; Description ...: Use exactly like the native AutoIt function FileGetVersion ; Syntax.........: _LFN_FileGetVersion($sFile[, $sField = -1]) ; =============================================================================================================================== Func _LFN_FileGetVersion($sFile, $sField = -1) $sFile = __LFN_Target_SetUnicodePrefix($sFile) Local $sResult If $sField = -1 Then $sResult = FileGetVersion($sFile) Return SetError(@error, @extended, $sResult) Else $sResult = FileGetVersion($sFile, $sField) Return SetError(@error, @extended, $sResult) EndIf EndFunc ;==>_LFN_FileGetVersion ; #FUNCTION# ==================================================================================================================== ; Name ..........: _LFN_FileMove ; Description ...: Use exactly like the native AutoIt function FileMove ; Syntax ........: _LFN_FileMove($sSrc, $sDst[, $iFlag = 0]) ; =============================================================================================================================== Func _LFN_FileMove($sSrc, $sDst, $iFlag = 0) $sSrc = __LFN_Target_SetUnicodePrefix($sSrc) $sDst = __LFN_Target_SetUnicodePrefix($sDst) Local $result = FileMove($sSrc, $sDst, $iFlag) Return SetError(@error, @extended, $result) EndFunc ;==>_LFN_FileMove ; #FUNCTION# ==================================================================================================================== ; Name ..........: _LFN_FileOpen ; Description ...: Use exactly like the native AutoIt function FileOpen ; Syntax.........: _LFN_FileOpen($sFile[, $nMode = 0]) ; =============================================================================================================================== Func _LFN_FileOpen($sFile, $nMode = 0) $sFile = __LFN_Target_SetUnicodePrefix($sFile) Local $result = FileOpen($sFile, $nMode) Return SetError(@error, @extended, $result) EndFunc ;==>_LFN_FileOpen ; #FUNCTION# ==================================================================================================================== ; Name ..........: _LFN_FileRead ; Description ...: Use exactly like the native AutoIt function FileRead ; Syntax.........: _LFN_FileRead($xFile[, $nCount = -1]) ; =============================================================================================================================== Func _LFN_FileRead($xFile, $nCount = -1) If IsString($xFile) Then $xFile = __LFN_Target_SetUnicodePrefix($xFile) Local $result If $nCount < 0 Then $result = FileRead($xFile) Else $result = FileRead($xFile, $nCount) EndIf Return SetError(@error, @extended, $result) EndFunc ;==>_LFN_FileRead ; #FUNCTION# ==================================================================================================================== ; Name ..........: _LFN_FileReadLine ; Description ...: Use exactly like the native AutoIt function FileReadLine ; Syntax.........: _LFN_FileReadLine($xFile[, $nLine = 1]) ; =============================================================================================================================== Func _LFN_FileReadLine($xFile, $nLine = 1) If IsString($xFile) Then $xFile = __LFN_Target_SetUnicodePrefix($xFile) Local $result If $nLine = 1 Then $result = FileReadLine($xFile) Else $result = FileReadLine($xFile, $nLine) EndIf Return SetError(@error, @extended, $result) EndFunc ;==>_LFN_FileReadLine ; #FUNCTION# ==================================================================================================================== ; Name ..........: _LFN_FileReadToArray ; Description ...: Use exactly like the native AutoIt function FileReadToArray ; Syntax.........: _LFN_FileReadToArray($xFile) ; =============================================================================================================================== Func _LFN_FileReadToArray($xFile) If IsString($xFile) Then $xFile = __LFN_Target_SetUnicodePrefix($xFile) Local $result = FileReadToArray($xFile) Return SetError(@error, @extended, $result) EndFunc ;==>_LFN_FileReadToArray ; #FUNCTION# ==================================================================================================================== ; Name ..........: _LFN_FileSetAttrib ; Description ...: Sets or clears attributes of one or more files/directories. ; Syntax.........: _LFN_FileSetAttrib($sTarget, $sAttrib[, $bRecurse = False]) ; Parameters ....: Target - Full path of file(s) to set attributes for (wildcards supported). ; $sAttrib - A string representation of the attributes to set or clear - see Remarks. ; $bRecurse - [optional] Set to True if to recurse subdirectories. ; Return values .: Success - Returns 1 ; Failure - Returns 0 and sets @error: ; 1 - Error opening the kernel32 DLL. ; 2 - The attributes parameter includes an invalid attribute - see Remarks. ; 3 - deprecated (used to be "No files found", but this is not an error, but a legitimate result). ; 4 - At least one file could not have its attributes changed. ; Author ........: orbs ; Modified ......: ; Remarks .......: - The attributes that can be modified with the function are + or -: ; "R" = READONLY ; "A" = ARCHIVE ; "S" = SYSTEM ; "H" = HIDDEN ; "N" = NORMAL ; "O" = OFFLINE ; "T" = TEMPORARY ; Related .......: ; Dependencies ..: ; Link ..........: http://msdn.microsoft.com/en-us/library/aa365535(v=vs.85).aspx ; http://msdn.microsoft.com/en-us/library/gg258117(v=vs.85).aspx ; http://stackoverflow.com/questions/12594403/fasm-if-file-exists-using-getfileattributes-invalid-file-attributes-value ; Example .......: No ; =============================================================================================================================== Func _LFN_FileSetAttrib($sTarget, $sAttrib, $bRecurse = False) ; reversion If Not __LFN_Target_IsMask($sTarget) And _ ; target is a single file or folder StringLen($sTarget) < 260 And _ ; target is short Not $bRecurse Then _ ; no recurse (recurse may breach MAX_PATH limit) Return FileSetAttrib($sTarget, $sAttrib, $bRecurse) ; standard procedure Local $hDLL = __LFN_DllOpen() If @error Then Return SetError(1, 0, 0) ; preparation Local Const $_LFN_FILE_ATTRIBUTE_ARCHIVE = 32 ;(0x20) Local Const $_LFN_FILE_ATTRIBUTE_COMPRESSED = 2048 ;(0x800) Local Const $_LFN_FILE_ATTRIBUTE_DEVICE = 64 ;(0x40) ; not used here Local Const $_LFN_FILE_ATTRIBUTE_DIRECTORY = 16 ;(0x10) Local Const $_LFN_FILE_ATTRIBUTE_ENCRYPTED = 16384 ;(0x4000) ; not used here Local Const $_LFN_FILE_ATTRIBUTE_HIDDEN = 2 ;(0x2) Local Const $_LFN_FILE_ATTRIBUTE_INTEGRITY_STREAM = 32768 ;(0x8000) ; not used here Local Const $_LFN_FILE_ATTRIBUTE_NORMAL = 128 ;(0x80) Local Const $_LFN_FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 8192 ;(0x2000) ; not used here Local Const $_LFN_FILE_ATTRIBUTE_NO_SCRUB_DATA = 131072 ;(0x20000) ; not used here Local Const $_LFN_FILE_ATTRIBUTE_OFFLINE = 4096 ;(0x1000) Local Const $_LFN_FILE_ATTRIBUTE_READONLY = 1 ;(0x1) Local Const $_LFN_FILE_ATTRIBUTE_REPARSE_POINT = 1024 ;(0x400) ; not used here Local Const $_LFN_FILE_ATTRIBUTE_SPARSE_FILE = 512 ;(0x200) ; not used here Local Const $_LFN_FILE_ATTRIBUTE_SYSTEM = 4 ;(0x4) Local Const $_LFN_FILE_ATTRIBUTE_TEMPORARY = 256 ;(0x100) Local Const $_LFN_FILE_ATTRIBUTE_VIRTUAL = 65536 ;(0x10000) ; not used here Local $aAttributes[18][2] = [[0, 0], _ [$_LFN_FILE_ATTRIBUTE_ARCHIVE, 'A'], _ [$_LFN_FILE_ATTRIBUTE_COMPRESSED, 'C'], _ [$_LFN_FILE_ATTRIBUTE_DEVICE, ''], _ [$_LFN_FILE_ATTRIBUTE_DIRECTORY, 'D'], _ [$_LFN_FILE_ATTRIBUTE_ENCRYPTED, ''], _ [$_LFN_FILE_ATTRIBUTE_HIDDEN, 'H'], _ [$_LFN_FILE_ATTRIBUTE_INTEGRITY_STREAM, ''], _ [$_LFN_FILE_ATTRIBUTE_NORMAL, 'N'], _ [$_LFN_FILE_ATTRIBUTE_NOT_CONTENT_INDEXED, ''], _ [$_LFN_FILE_ATTRIBUTE_NO_SCRUB_DATA, ''], _ [$_LFN_FILE_ATTRIBUTE_OFFLINE, 'O'], _ [$_LFN_FILE_ATTRIBUTE_READONLY, 'R'], _ [$_LFN_FILE_ATTRIBUTE_REPARSE_POINT, ''], _ [$_LFN_FILE_ATTRIBUTE_SPARSE_FILE, ''], _ [$_LFN_FILE_ATTRIBUTE_SYSTEM, 'S'], _ [$_LFN_FILE_ATTRIBUTE_TEMPORARY, 'T'], _ [$_LFN_FILE_ATTRIBUTE_VIRTUAL, '']] Local Const $_LFN_INVALID_FILE_ATTRIBUTES = 4294967295 ;(0xFFFFFFFF, also equals -1 for unsigned DWORD) Local $bAttribToSet = True Local $nAttribToSet = 0 Local $nAttribToClear = 0 Local $i, $j For $i = 1 To StringLen($sAttrib) Switch StringUpper(StringMid($sAttrib, $i, 1)) Case '+' $bAttribToSet = True Case '-' $bAttribToSet = False Case 'R', 'A', 'S', 'H', 'N', 'O', 'T' For $j = 1 To UBound($aAttributes) - 1 If $aAttributes[$j][1] = StringUpper(StringMid($sAttrib, $i, 1)) Then If $bAttribToSet Then $nAttribToSet = BitOR($nAttribToSet, $aAttributes[$j][0]) Else $nAttribToClear = BitOR($nAttribToClear, $aAttributes[$j][0]) EndIf EndIf Next Case Else Return SetError(2, 0, 0) EndSwitch Next ; main action Local $aFiles[2] = [1, $sTarget] If Not __LFN_Target_IsExistingFolder($sTarget) Or $bRecurse Then $aFiles = __LFN_FilesListToArray($sTarget, $bRecurse) If __LFN_Target_IsExistingFolder($sTarget) And $bRecurse Then __LFN_ReDim($aFiles, $sTarget & '\') Local $bOneFail = False Local $sOneName = '' Local $aRet, $nAttribToChange For $i = $aFiles[0] To 1 Step -1 $sOneName = $aFiles[$i] If StringRight($sOneName, 1) = '\' Then $sOneName = StringTrimRight($sOneName, 1) $aRet = DllCall($hDLL, 'dword', 'GetFileAttributesW', 'wstr', $sOneName) If @error Or $aRet[0] = $_LFN_INVALID_FILE_ATTRIBUTES Then $bOneFail = True ContinueLoop EndIf $nAttribToChange = $aRet[0] $nAttribToChange = BitOR($nAttribToChange, $nAttribToSet) $nAttribToChange = BitAND($nAttribToChange, BitNOT($nAttribToClear)) If $nAttribToChange = $aRet[0] Then ContinueLoop ; no need to change $aRet = DllCall($hDLL, 'int', 'SetFileAttributesW', 'wstr', $sOneName, 'dword', $nAttribToChange) If @error Or $aRet[0] = 0 Then $bOneFail = True ContinueLoop EndIf Next If $bOneFail Then Return SetError(4, 0, 0) Return 1 EndFunc ;==>_LFN_FileSetAttrib ; #FUNCTION# ==================================================================================================================== ; Name ..........: _LFN_FileSetPos ; Description ...: Use exactly like the native AutoIt function FileSetPos ; Syntax.........: _LFN_FileSetPos($hFile, $nOffset, $nOrigin) ; =============================================================================================================================== Func _LFN_FileSetPos($hFile, $nOffset, $nOrigin) Local $result = FileSetPos($hFile, $nOffset, $nOrigin) Return SetError(@error, @extended, $result) EndFunc ;==>_LFN_FileSetPos ; #FUNCTION# ==================================================================================================================== ; Name ..........: _LFN_FileSetEnd ; Description ...: Use exactly like the native AutoIt function FileSetEnd ; Syntax.........: _LFN_FileSetEnd($hFile) ; =============================================================================================================================== Func _LFN_FileSetEnd($hFile) Local $result = FileSetEnd($hFile) Return SetError(@error, @extended, $result) EndFunc ;==>_LFN_FileSetEnd ; #FUNCTION# ==================================================================================================================== ; Name ..........: _LFN_FileSetTime ; Description ...: Sets the timestamp of one of more files. ; Syntax.........: _LFN_FileSetTime($sTarget, $sTimestamp[, $nType = 0[, $bRecurse = False]]) ; Parameters ....: Target - Full path of file(s) to set timestamp for (wildcards supported). ; $sTimestamp - A string which denotes the new time to set. ; format: "YYYYMMDDhhmmss" (Year, Month, Day, hour (24hr clock), minute, second). ; If an empty string is passed, then the current time is used. ; $nType - [optional] Timestamp to change: ; $FT_MODIFIED (0) = Last modified (default) ; $FT_CREATED (1) = Created ; $FT_ACCESSED (2) = Last accessed ; Constants are defined in FileConstants.au3 ; $bRecurse - [optional] Set to True if to recurse subdirectories. ; Return values .: Success - Returns 1 ; Failure - Returns 0 and sets @error to 1 ; Author ........: orbs ; Modified ......: ; Remarks .......: Using a date earlier than 1980-01-01 will have no effect. ; Trying to change a timestamp on read-only files will result in an error. ; This function fails in the following conditions: ; - Invalid timestamp: string is not all integer or not exactly 14 characters in length ; Related .......: ; Dependencies ..: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _LFN_FileSetTime($sTarget, $sTimestamp, $nType = 0, $bRecurse = False) ; reversion If Not __LFN_Target_IsMask($sTarget) And _ ; target is a single file or folder StringLen($sTarget) < 260 And _ ; target is short Not $bRecurse Then _ ; no recurse (recurse may breach MAX_PATH limit) Return FileSetTime($sTarget, $sTimestamp, $nType, $bRecurse) ; standard procedure Local $hDLL = __LFN_DllOpen() If @error Then Return SetError(1, 0, 0) ; preparation If Not __LFN_FilesExist($sTarget) Then Return SetError(1, 0, 0) If Not StringIsInt($sTimestamp) Or StringLen($sTimestamp) <> 14 Then Return SetError(1, 0, 0) ; - parse parameter Local $sYYYY = StringLeft($sTimestamp, 4) Local $sMM = StringMid($sTimestamp, 5, 2) Local $sDD = StringMid($sTimestamp, 7, 2) Local $sHH = StringMid($sTimestamp, 9, 2) Local $sMN = StringMid($sTimestamp, 11, 2) Local $sSS = StringMid($sTimestamp, 13, 2) ; - enclode time to "System" time format ; = _Date_Time_EncodeSystemTime Local Const $_LFN_tagSYSTEMTIME = 'struct;word Year;word Month;word Dow;word Day;word Hour;word Minute;word Second;word MSeconds;endstruct' Local $tSystemTime_File = DllStructCreate($_LFN_tagSYSTEMTIME) DllStructSetData($tSystemTime_File, 'Month', Number($sMM)) DllStructSetData($tSystemTime_File, 'Day', Number($sDD)) DllStructSetData($tSystemTime_File, 'Year', Number($sYYYY)) DllStructSetData($tSystemTime_File, 'Hour', Number($sHH)) DllStructSetData($tSystemTime_File, 'Minute', Number($sMN)) DllStructSetData($tSystemTime_File, 'Second', Number($sSS)) DllStructSetData($tSystemTime_File, 'MSeconds', 0) ; - convert "System" time format to "UTC System" time format ; = _Date_Time_TzSpecificLocalTimeToSystemTime Local $aRet Local $tUTC = DllStructCreate($_LFN_tagSYSTEMTIME) $aRet = DllCall("kernel32.dll", "ptr", "TzSpecificLocalTimeToSystemTime", "ptr", 0, "ptr", DllStructGetPtr($tSystemTime_File), "struct*", $tUTC) If @error Then Return SetError(1, 0, 0) ; - convert "System" time format to "File" time format ; = _Date_Time_SystemTimeToFileTime Local Const $_LFN_tagFILETIME = 'struct;dword Lo;dword Hi;endstruct' Local $tFileTime_File = DllStructCreate($_LFN_tagFILETIME) $aRet = DllCall($hDLL, 'bool', 'SystemTimeToFileTime', 'struct*', $tUTC, 'struct*', $tFileTime_File) If @error Then Return SetError(1, 0, 0) ; - decide which timestamp to change Local $pCreated = 0 Local $pAccessed = 0 Local $pModified = 0 Switch $nType Case 1 ; "Created" $pCreated = DllStructGetPtr($tFileTime_File) Case 2 ; "Accessed" $pAccessed = DllStructGetPtr($tFileTime_File) Case Else ; "Modified" $pModified = DllStructGetPtr($tFileTime_File) EndSwitch ; main action Local $aFiles = __LFN_FilesListToArray($sTarget, $bRecurse) If @extended = 0 Then Return SetError(1, 0, 0) ; no files found Local $hFile Local $bOneFail = False For $i = $aFiles[0] To 1 Step -1 If StringRight($aFiles[$i], 1) = '\' Then ContinueLoop ; it's a subfolder ; _WinAPI_CreateFile (does not equal FileOpen!) $aRet = DllCall($hDLL, 'handle', 'CreateFileW', 'wstr', $aFiles[$i], 'dword', 0x40000000, 'dword', 0, 'ptr', 0, 'dword', 3, 'dword', 0, 'ptr', 0) $hFile = $aRet[0] ; finally... $aRet = DllCall($hDLL, 'bool', 'SetFileTime', 'handle', $hFile, 'ptr', $pCreated, 'ptr', $pAccessed, 'ptr', $pModified) If $aRet[0] = 0 Then $bOneFail = True EndIf ;_WinAPI_CloseHandle (does not equal FileClose!) $aRet = DllCall($hDLL, 'bool', 'CloseHandle', 'handle', $hFile) Next If $bOneFail Then Return SetError(1, 0, 0) Return 1 EndFunc ;==>_LFN_FileSetTime ; #FUNCTION# ==================================================================================================================== ; Name ..........: _LFN_FileWrite ; Description ...: Use exactly like the native AutoIt function FileWrite ; Syntax.........: _LFN_FileWrite($xFile, $xData) ; =============================================================================================================================== Func _LFN_FileWrite($xFile, $xData) If IsString($xFile) Then $xFile = __LFN_Target_SetUnicodePrefix($xFile) Local $result = FileWrite($xFile, $xData) Return SetError(@error, @extended, $result) EndFunc ;==>_LFN_FileWrite ; #FUNCTION# ==================================================================================================================== ; Name ..........: _LFN_FileWriteLine ; Description ...: Use exactly like the native AutoIt function FileWriteLine ; Syntax.........: _LFN_FileWriteLine($xFile, $xData) ; =============================================================================================================================== Func _LFN_FileWriteLine($xFile, $xData) If IsString($xFile) Then $xFile = __LFN_Target_SetUnicodePrefix($xFile) Local $result = FileWriteLine($xFile, $xData) Return SetError(@error, @extended, $result) EndFunc ;==>_LFN_FileWriteLine ; #FUNCTION# ==================================================================================================================== ; Name ..........: _LFN_IniDelete ; Description ...: Deletes a value from a standard format .ini file. ; Syntax.........: _LFN_IniDelete($sFile, $sSection[, $sKey = '']) ; Parameters ....: $sFile - The filename of the .ini file. ; $sSection - The section name in the .ini file. ; $sKey - [optional] The key name in the .ini file to delete. If the key name is not given the entire ; section is deleted. The Default keyword may also be used which will cause the section to be deleted. ; Return values .: Success - Returns 1 ; Failure - Returns 0 and sets @error to 1 ; Author ........: orbs ; Modified ......: ; Remarks .......: A standard ini file looks like: ; [SectionName] ; Key=Value ; Related .......: ; Dependencies ..: _LFN_FileExists, _LFN_FileReadToArray, _LFN_FileOpen, _LFN_FileWriteLine, _LFN_FileClose, _LFN_FileGetEncoding ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _LFN_IniDelete($sFile, $sSection, $sKey = '') If Not _LFN_FileExists($sFile) Then Return SetError(1, 0, 0) Local $aFileLines = _LFN_FileReadToArray($sFile) If @error Then Return SetError(1, 0, 0) Local $iFirstLineToDelete = -1 Local $iLastLineToDelete = -1 Local $bSectionFound = False Local $iPos = 0 For $i = 0 To UBound($aFileLines) - 1 If StringLeft($aFileLines[$i], 1) = '[' Then If StringLeft($aFileLines[$i], StringLen($sSection) + 2) = '[' & $sSection & ']' Then $bSectionFound = True If $sKey = '' Then $iFirstLineToDelete = $i $iLastLineToDelete = UBound($aFileLines) - 1 EndIf Else If $bSectionFound Then ; entering next section If $sKey = '' Then $iLastLineToDelete = $i - 1 ExitLoop EndIf EndIf Else If $bSectionFound And $sKey <> '' Then $iPos = StringInStr($aFileLines[$i], '=') If $iPos = 0 Then ContinueLoop If StringLeft($aFileLines[$i], $iPos - 1) = $sKey Then $iFirstLineToDelete = $i $iLastLineToDelete = $i EndIf EndIf EndIf Next Local $hFile Local $bError If $iFirstLineToDelete > -1 And $iLastLineToDelete >= $iFirstLineToDelete Then $hFile = _LFN_FileOpen($sFile, 2 + _LFN_FileGetEncoding($sFile)) For $i = 0 To UBound($aFileLines) - 1 If $i >= $iFirstLineToDelete And $i <= $iLastLineToDelete Then ContinueLoop _LFN_FileWriteLine($hFile, $aFileLines[$i]) If @error Then $bError = True ExitLoop EndIf Next _LFN_FileClose($hFile) If $bError Then Return SetError(1, 0, 0) Else Return SetError(1, 0, 0) EndIf Return 1 EndFunc ;==>_LFN_IniDelete ; #FUNCTION# ==================================================================================================================== ; Name ..........: _LFN_IniRead ; Description ...: Reads a value from a standard format .ini file. ; Syntax.........: _LFN_IniRead($sFile, $sSection, $sKey, $xDefaultValue) ; Parameters ....: $sFile - The filename of the .ini file. ; $sSection - The section name in the .ini file. ; $sKey - The key name in the .ini file. ; $xDefaultValue - The default value to return if the requested key is not found. ; Return values .: Success - Returns the requested key value as a string. ; Failure - Returns the default string if the requested key is not found or any error occured. ; Author ........: orbs ; Modified ......: ; Remarks .......: All values returned are converted as a string. ; A standard ini file looks like: ; [SectionName] ; Key=Value ; Related .......: ; Dependencies ..: _LFN_FileExists, _LFN_FileReadToArray ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _LFN_IniRead($sFile, $sSection, $sKey, $xDefaultValue) If Not _LFN_FileExists($sFile) Then Return $xDefaultValue Local $aFileLines = _LFN_FileReadToArray($sFile) If @error Then Return $xDefaultValue Local $bSectionFound = False Local $iPos = 0 For $i = 0 To UBound($aFileLines) - 1 If StringLeft($aFileLines[$i], 1) = '[' Then If StringLeft($aFileLines[$i], StringLen($sSection) + 2) = '[' & $sSection & ']' Then $bSectionFound = True Else If $bSectionFound Then ; entering next section, key not found Return $xDefaultValue ExitLoop EndIf EndIf Else If $bSectionFound Then $iPos = StringInStr($aFileLines[$i], '=') If $iPos = 0 Then ContinueLoop If StringLeft($aFileLines[$i], $iPos - 1) = $sKey Then Return StringTrimLeft($aFileLines[$i], $iPos) EndIf EndIf Next Return $xDefaultValue EndFunc ;==>_LFN_IniRead ; #FUNCTION# ==================================================================================================================== ; Name ..........: _LFN_IniReadSection ; Description ...: Reads all key/value pairs from a section in a standard format .ini file. ; Syntax.........: _LFN_IniReadSection($sFile, $sSection) ; Parameters ....: $sFile - The filename of the .ini file. ; $sSection - The section name in the .ini file. ; Return values .: Success - Returns a 2-D array where element[n][0] is the key and element[n][1] is the value. ; Failure - Returns 0 and sets the @error flag to non-zero if unable to read the section (The INI file may not ; exist or the section may not exist or is empty). ; Author ........: orbs ; Modified ......: ; Remarks .......: A standard ini file looks like: ; [SectionName] ; Key=Value ; The number of elements returned will be in element[0][0]. If an @error occurs, no array is created. ; This function is not impacted by the 32kB limitation. ; Related .......: ; Dependencies ..: _LFN_FileExists, _LFN_FileReadToArray ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _LFN_IniReadSection($sFile, $sSection) If Not _LFN_FileExists($sFile) Then Return SetError(1, 0, 0) Local $aFileLines = _LFN_FileReadToArray($sFile) If @error Then Return SetError(1, 0, 0) Local $aResult[1][2] $aResult[0][0] = 0 Local $bSectionFound = False Local $iPos = 0 For $i = 0 To UBound($aFileLines) - 1 If StringLeft($aFileLines[$i], 1) = '[' Then If StringLeft($aFileLines[$i], StringLen($sSection) + 2) = '[' & $sSection & ']' Then $bSectionFound = True Else If $bSectionFound Then ; entering next section ExitLoop EndIf EndIf Else If $bSectionFound Then $iPos = StringInStr($aFileLines[$i], '=') If $iPos = 0 Then ContinueLoop __LFN_ReDim2D($aResult) $aResult[$aResult[0][0]][0] = StringLeft($aFileLines[$i], $iPos - 1) $aResult[$aResult[0][0]][1] = StringTrimLeft($aFileLines[$i], $iPos) EndIf EndIf Next ReDim $aResult[$aResult[0][0] + 1][2] Return $aResult EndFunc ;==>_LFN_IniReadSection ; #FUNCTION# ==================================================================================================================== ; Name ..........: _LFN_IniReadSectionNames ; Description ...: Reads all sections in a standard format .ini file. ; Syntax.........: _LFN_IniReadSectionNames($sFile) ; Parameters ....: $sFile - The filename of the .ini file. ; Return values .: Success - Returns a 1-D array of all section names in the .ini file. ; Failure - Returns 0 and sets the @error flag to non-zero. ; Author ........: orbs ; Modified ......: ; Remarks .......: A standard ini file looks like: ; [SectionName] ; Key=Value ; The number of elements returned will be in element[0]. If an @error occurs, no array is created. ; Related .......: ; Dependencies ..: _LFN_FileExists, _LFN_FileReadToArray ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _LFN_IniReadSectionNames($sFile) If Not _LFN_FileExists($sFile) Then Return SetError(1, 0, 0) Local $aFileLines = _LFN_FileReadToArray($sFile) If @error Then Return SetError(1, 0, 0) Local $aResult[1] = [0] For $i = 0 To UBound($aFileLines) - 1 If StringLeft($aFileLines[$i], 1) = '[' Then __LFN_ReDim($aResult, StringTrimRight(StringTrimLeft($aFileLines[$i], 1), 1)) Next If $aResult[0] = 0 Then Return SetError(1, 0, 0) ReDim $aResult[$aResult[0] + 1] Return $aResult EndFunc ;==>_LFN_IniReadSectionNames ; #FUNCTION# ==================================================================================================================== ; Name ..........: _LFN_IniRenameSection ; Description ...: Renames a section in a standard format .ini file. ; Syntax.........: _LFN_IniRenameSection($sFile, $sSection, $sNewSection[, $bOverwrite = False]) ; Parameters ....: $sFile - The filename of the .ini file. ; $sSection - The section to be renamed. ; $sNewSection - The new name for the section. ; $bOverwrite - [optional] if a section already exists by the new name, set to True to overwrite it. ; Return values .: Success - Returns 1 ; Failure - Returns 0 and sets @error to non-zero. ; Author ........: orbs ; Modified ......: ; Remarks .......: A standard ini file looks like: ; [SectionName] ; Key=Value ; Related .......: ; Dependencies ..: _LFN_FileExists, _LFN_FileReadToArray, _LFN_FileOpen, _LFN_FileWriteLine, _LFN_FileClose, _LFN_FileGetEncoding ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _LFN_IniRenameSection($sFile, $sSection, $sNewSection, $bOverwrite = False) If $sSection = $sNewSection Then Return 1 If Not _LFN_FileExists($sFile) Then Return SetError(1, 0, 0) Local $aFileLines = _LFN_FileReadToArray($sFile) If @error Then Return SetError(1, 0, 0) Local $bSectionFound = False Local $bNewSectionFound = False Local $iFirstLineToDelete = -1 Local $iLastLineToDelete = -1 For $i = 0 To UBound($aFileLines) - 1 If StringLeft($aFileLines[$i], 1) = '[' Then If StringLeft($aFileLines[$i], StringLen($sSection) + 2) = '[' & $sSection & ']' Then $bSectionFound = True If StringLeft($aFileLines[$i], StringLen($sNewSection) + 2) = '[' & $sNewSection & ']' Then $bNewSectionFound = True $iFirstLineToDelete = $i $iLastLineToDelete = UBound($aFileLines) - 1 Else If $bNewSectionFound Then ; entering next section $iLastLineToDelete = $i - 1 ExitLoop EndIf EndIf EndIf Next If Not $bSectionFound Then Return SetError(1, 0, 0) If $bNewSectionFound And Not $bOverwrite Then Return SetError(1, 0, 0) Local $hFile Local $bError $hFile = _LFN_FileOpen($sFile, 2 + _LFN_FileGetEncoding($sFile)) For $i = 0 To UBound($aFileLines) - 1 If $i >= $iFirstLineToDelete And $i <= $iLastLineToDelete Then ContinueLoop If StringLeft($aFileLines[$i], StringLen($sSection) + 2) = '[' & $sSection & ']' Then $aFileLines[$i] = StringReplace($aFileLines[$i], $sSection, $sNewSection) _LFN_FileWriteLine($hFile, $aFileLines[$i]) If @error Then $bError = True ExitLoop EndIf Next _LFN_FileClose($hFile) If $bError Then Return SetError(1, 0, 0) Return 1 EndFunc ;==>_LFN_IniRenameSection ; #FUNCTION# ==================================================================================================================== ; Name ..........: _LFN_IniWrite ; Description ...: Writes a value to a standard format .ini file. ; Syntax.........: _LFN_IniWrite($sFile, $sSection, $sKey, $xValue) ; Parameters ....: $sFile - The filename of the .ini file. ; $sSection - The section name in the .ini file. ; $sKey - The key name in the .ini file. ; $xValue - The value to write/change. ; Return values .: Success - Returns 1 ; Failure - Returns 0 and sets @error ro 1 ; Author ........: orbs ; Modified ......: ; Remarks .......: A standard ini file looks like: ; [SectionName] ; Key=Value ; - If the file does not already exist, it is created so long as the directory exists. Keys and/or sections are ; added to the end and are not sorted in any way. ; - If you would like to wrap quotes around an ini value, then you need to double up the quotation marks as the ; first set of quotation marks are stripped. For example: ""This is a test"" will produce "This is a test" ; when using IniRead() or such-like. ; - Leading and trailing whitespace is stripped. In order to preserve the whitespace, the string must be quoted. ; For example, " this is a test" will preserve the whitespace but per above, the quotation marks are stripped. ; - Multi-line values are not possible. ; - If you want to use an ini file with Unicode encoding, first create an .ini file by using the FileOpen() ; function with the mode parameter set to a Unicode parameter. ; Related .......: ; Dependencies ..: _LFN_FileExists, _LFN_FileWriteLine, _LFN_FileReadToArray, _LFN_FileOpen, _LFN_FileClose, _LFN_FileGetEncoding ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _LFN_IniWrite($sFile, $sSection, $sKey, $xValue) Local $sValue = String($xValue) $sValue = StringStripWS($sValue, 3) If StringLeft($sValue, 1) = '"' And StringRight($sValue, 1) = '"' Then $sValue = StringTrimLeft(StringTrimRight($sValue, 1), 1) If Not _LFN_FileExists($sFile) Then _LFN_FileWriteLine($sFile, '[' & $sSection & ']') If @error Then Return SetError(1, 0, 0) _LFN_FileWriteLine($sFile, $sKey & '=' & $sValue) If @error Then Return SetError(1, 0, 0) Return 1 EndIf Local $aFileLines = _LFN_FileReadToArray($sFile) If @error Then Return SetError(1, 0, 0) Local $bToDo = -1 ; 0 = replace existing line, 1 = insert line in existing section, 2 = add new section, 3 = add new line at last section Local $bSectionFound = False Local $iLineToInsert = -1 Local $iPos = 0 For $i = 0 To UBound($aFileLines) - 1 If StringLeft($aFileLines[$i], 1) = '[' Then If StringLeft($aFileLines[$i], StringLen($sSection) + 2) = '[' & $sSection & ']' Then $bSectionFound = True Else If $bSectionFound Then ; entering next section, key not found $iLineToInsert = $i $bToDo = 1 ExitLoop EndIf EndIf Else If $bSectionFound Then $iPos = StringInStr($aFileLines[$i], '=') If StringLeft($aFileLines[$i], $iPos - 1) = $sKey Then $aFileLines[$i] = $sKey & '=' & $sValue $bToDo = 0 ExitLoop Else If $i = UBound($aFileLines) - 1 Then $bToDo = 3 EndIf EndIf EndIf Next If Not $bSectionFound Then $bToDo = 2 Local $bError = False Local $hFile Switch $bToDo Case 0 $hFile = _LFN_FileOpen($sFile, 2 + _LFN_FileGetEncoding($sFile)) For $i = 0 To UBound($aFileLines) - 1 _LFN_FileWriteLine($hFile, $aFileLines[$i]) If @error Then $bError = True ExitLoop EndIf Next _LFN_FileClose($hFile) Case 1 While $aFileLines[$iLineToInsert - 1] = '' $iLineToInsert -= 1 WEnd $hFile = _LFN_FileOpen($sFile, 2 + _LFN_FileGetEncoding($sFile)) For $i = 0 To UBound($aFileLines) - 1 If $i = $iLineToInsert Then _LFN_FileWriteLine($hFile, $sKey & '=' & $sValue) If @error Then $bError = True ExitLoop EndIf EndIf _LFN_FileWriteLine($hFile, $aFileLines[$i]) If @error Then $bError = True ExitLoop EndIf Next _LFN_FileClose($hFile) Case 2 _LFN_FileWriteLine($sFile, '[' & $sSection & ']') If @error Then $bError = True _LFN_FileWriteLine($sFile, $sKey & '=' & $sValue) If @error Then $bError = True Case 3 _LFN_FileWriteLine($sFile, $sKey & '=' & $sValue) If @error Then $bError = True Case Else $bError = True EndSwitch If $bError Then Return SetError(1, 0, 0) Return 1 EndFunc ;==>_LFN_IniWrite ; #FUNCTION# ==================================================================================================================== ; Name ..........: _LFN_IniWriteSection ; Description ...: Writes a section to a standard format .ini file. ; Syntax.........: _LFN_IniWriteSection($sFile, $sSection, $xData[, $iFirstEntry = 1]) ; Parameters ....: $sFile - The filename of the .ini file. ; $sSection - The section name in the .ini file. ; $xData - The data to write. The data can either be a string or an array. If the data is a string, then ; each key=value pair must be delimited by @LF. If the data is an array, the array must be 2-D ; and the second dimension must be 2 elements. ; $iFirstEntry - [optional] If an array is passed as data, this specifies the index to start writing from. ; By default, this is 1 so that the return value of IniReadSection() can be used immediately. ; For manually created arrays, this value may need to be different depending on how the array was ; created. This parameter is ignored if a string is passed as data. ; Return values .: Success - Returns 1 ; Failure - Returns 0 and sets @error ro 1 ; Author ........: orbs ; Modified ......: ; Remarks .......: A standard ini file looks like: ; [SectionName] ; Key=Value ; - _LFN_IniWrite Remarks about doubling quotation marks or quoting whitespace are irrelevant here. Data is ; written to the .ini file as is. ; - If the file does not already exist, it is created so long as the directory exists. Keys and/or sections are ; added to the end and are not sorted in any way. ; - If the section being written already exists, its contents will be overwritten. ; - If you want to use an ini file with Unicode encoding, first create an .ini file by using the FileOpen() ; function with the mode parameter set to a Unicode parameter. ; Related .......: ; Dependencies ..: _LFN_FileExists, _LFN_FileReadToArray, _LFN_FileOpen, _LFN_FileWriteLine, _LFN_FileClose, _LFN_FileGetEncoding ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _LFN_IniWriteSection($sFile, $sSection, $xData, $iFirstEntry = 1) Local $sData If IsArray($xData) Then For $i = $iFirstEntry To UBound($xData) - 1 $sData = $sData & $xData[$i][0] & '=' & $xData[$i][1] & @CRLF Next Else $sData = StringReplace($xData, @LF, @CRLF) EndIf If _LFN_FileExists($sFile) Then Local $aFileLines = _LFN_FileReadToArray($sFile) If @error Then Return SetError(1, 0, 0) Local $iFirstLineToDelete = -1 Local $iLastLineToDelete = -1 Local $bSectionFound = False For $i = 0 To UBound($aFileLines) - 1 If StringLeft($aFileLines[$i], 1) = '[' Then If StringLeft($aFileLines[$i], StringLen($sSection) + 2) = '[' & $sSection & ']' Then $bSectionFound = True $iFirstLineToDelete = $i $iLastLineToDelete = UBound($aFileLines) - 1 Else If $bSectionFound Then ; entering next section $iLastLineToDelete = $i - 1 ExitLoop EndIf EndIf EndIf Next Local $hFile Local $bError If $iFirstLineToDelete > -1 And $iLastLineToDelete >= $iFirstLineToDelete Then $hFile = _LFN_FileOpen($sFile, 2 + _LFN_FileGetEncoding($sFile)) For $i = 0 To UBound($aFileLines) - 1 If $i >= $iFirstLineToDelete And $i <= $iLastLineToDelete Then ContinueLoop _LFN_FileWriteLine($hFile, $aFileLines[$i]) If @error Then $bError = True ExitLoop EndIf Next _LFN_FileClose($hFile) If $bError Then Return SetError(1, 0, 0) EndIf EndIf _LFN_FileWriteLine($sFile, '[' & $sSection & ']') If @error Then Return SetError(1, 0, 0) _LFN_FileWriteLine($sFile, $sData) If @error Then Return SetError(1, 0, 0) Return 1 EndFunc ;==>_LFN_IniWriteSection ; #INTERNAL_USE_ONLY# =========================================================================================================== ;__LFN_DllOpen ;__LFN_FileReadable ;__LFN_FilesExist ;__LFN_FilesListToArray ;__LFN_FilesSimilar ;__LFN_FileWritable ;__LFN_ReDim ;__LFN_ReDim2D ;__LFN_Target_IsExistingFile ;__LFN_Target_IsExistingFolder ;__LFN_Target_IsMask ;__LFN_Target_LastElement_Get ;__LFN_Target_LastElement_Trim ;__LFN_Target_RemoveTrailingBackslash ;__LFN_Target_SetUnicodePrefix ;__LFN_Target_UnSetUnicodePrefix ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name ..........: __LFN_DllOpen ; Description ...: Opens "kernel32.dll" unless already opened. ; Syntax.........: __LFN_DllOpen() ; Parameters ....: none ; Return values .: Success - Returns a handle to "kernel32.dll" ; Failure - Returns -1 and sets @error to 1 ; Author ........: orbs ; Modified.......: ; Remarks .......: ; Related .......: ; Dependencies ..: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func __LFN_DllOpen() Local Static $hDLL If $hDLL < 1 Then $hDLL = DllOpen('kernel32.dll') If $hDLL < 1 Then Return SetError(1, 0, -1) Return $hDLL EndFunc ;==>__LFN_DllOpen ; #FUNCTION# ==================================================================================================================== ; Name ..........: __LFN_FileReadable ; Description ...: Checks if a file can be read. ; Syntax.........: __LFN_FileReadable($sFile) ; Parameters ....: $sFile - Full path of a single file to check. ; Return values .: Success - Returns True if the file can be read. ; Failure - Returns False if the file cannot be read. ; Author ........: orbs ; Modified ......: ; Remarks .......: The check is done by opening the file for reading in binary mode and reading the first byte. ; Example: this funtion will return False when checking a PST file currently in use by Microsoft Outlook. ; @error is not used. ; Related .......: ; Dependencies ..: _LFN_FileGetSize, _LFN_FileOpen, _LFN_FileRead, _LFN_FileClose ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func __LFN_FileReadable($sFile) If _LFN_FileGetSize($sFile) = 0 Then Return True Local $hFile = _LFN_FileOpen($sFile, 16) _LFN_FileRead($hFile, 1) Local $nError = @error _LFN_FileClose($hFile) Return ($nError = 0) EndFunc ;==>__LFN_FileReadable ; #FUNCTION# ==================================================================================================================== ; Name ..........: __LFN_FilesExist ; Description ...: Checks if the target exists, and if so, also checks its type (single file, multiple files, or folder). ; Syntax.........: __LFN_FilesExist($sTarget) ; Parameters ....: $sTarget - Full path to check (wildcards supported). ; Return values .: Success - Returns 1 if the target exists, and sets @extended: ; 0 - Target does not exist (therefore can not determine if it is a file or a folder) ; 1 - Target is a single file ; 2 - Target is multiple files ; 3 - Target is a folder ; Failure - Returns 0 ; Author ........: orbs ; Modified ......: ; Remarks .......: If the target is a mask (i.e. contains wildcards): ; - For a success return, it is sufficient that at least one of the files matching the mask exists. ; - It is always considered as "multiple files" (@extended=2), even if only a single match exists. ; @error is not used. ; Related .......: ; Dependencies ..: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func __LFN_FilesExist($sTarget) Local $nResult = 0 Local $nExtended = 0 If __LFN_Target_IsMask($sTarget) Then $nExtended = 2 ; multiple files $sTarget = __LFN_Target_SetUnicodePrefix($sTarget) Local $hSearch = FileFindFirstFile($sTarget) If $hSearch = -1 And Not FileExists($sTarget) Then ; not exist $nResult = 0 Else ; exists $nResult = 1 If $nExtended = 0 Then ; not yet determined if file or folder, but definitely not multiple files If StringInStr(FileGetAttrib($sTarget), 'D') Then ; folder $nExtended = 3 Else ; single file $nExtended = 1 EndIf EndIf EndIf FileClose($hSearch) Return SetExtended($nExtended, $nResult) EndFunc ;==>__LFN_FilesExist ; #FUNCTION# ==================================================================================================================== ; Name ..........: __LFN_FilesListToArray ; Description ...: Creates a list of files. ; Syntax.........: __LFN_FilesListToArray($sMask[, $bRecurse = False]) ; Parameters ....: $sMask - Full path and mask of files to list (wildcards supported). ; $bRecurse - [optional] Set to True if to recurse subdirectories ; Return values .: Success - Returns a 1-D 1-based array of filesystem entries (files & subfolders) with unicode prefix: ; [0] = number of entries ; [1] = 1st entry ; [2] = 2nd entry ; [N] = Nth entry ; The count of files only is returned in @extended. ; Failure - Returns a 1-D array of one element [0] = 0, and sets @error to 1 ; Author ........: orbs ; Modified ......: ; Remarks .......: If the parameter is a folder, the files therein will be listed just as if you had used the * mask. ; Directories are listed with suffix backslash ("\"). ; Related .......: ; Dependencies ..: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func __LFN_FilesListToArray($sMask, $bRecurse = False) Local $aResult[1] = [0] Local $aTemp[1] = [0] Local $nExtended = 0 $sMask = __LFN_Target_SetUnicodePrefix($sMask) Local $sPath = '' Local $sMaskOnly = __LFN_Target_LastElement_Get($sMask) If Not StringInStr($sMaskOnly, '*') And Not StringInStr($sMaskOnly, '?') And StringInStr(FileGetAttrib($sMask), 'D') Then $sPath = $sMask $sMaskOnly = '*' $sMask = $sMask & '\' & $sMaskOnly Else $sPath = __LFN_Target_LastElement_Trim($sMask) EndIf If Not __LFN_FilesExist($sPath) Then Return SetExtended($nExtended, $aResult) Local $hSearch, $sFile, $i ; files $hSearch = FileFindFirstFile($sMask) While True $sFile = FileFindNextFile($hSearch) If @error Then ExitLoop If StringInStr(FileGetAttrib($sPath & '\' & $sFile), 'D') Then __LFN_ReDim($aResult, $sPath & '\' & $sFile & '\') Else __LFN_ReDim($aResult, $sPath & '\' & $sFile) $nExtended += 1 EndIf WEnd FileClose($hSearch) ; folders If $bRecurse Then $hSearch = FileFindFirstFile($sPath & '\*') While True $sFile = FileFindNextFile($hSearch) If @error Then ExitLoop If StringInStr(FileGetAttrib($sPath & '\' & $sFile), 'D') Then $aTemp = __LFN_FilesListToArray($sPath & '\' & $sFile & '\' & $sMaskOnly, $bRecurse) $nExtended += @extended If $aTemp[0] > 0 Then ReDim $aResult[$aResult[0] + 1 + $aTemp[0]] For $i = 1 To $aTemp[0] $aResult[$aResult[0] + $i] = $aTemp[$i] Next $aResult[0] += $aTemp[0] EndIf EndIf WEnd FileClose($hSearch) EndIf Return SetExtended($nExtended, $aResult) EndFunc ;==>__LFN_FilesListToArray ; #FUNCTION# ==================================================================================================================== ; Name ..........: __LFN_FilesSimilar ; Description ...: Checks if two files have the same size and small-enough "Modified" timestamp difference. ; Syntax.........: __LFN_FilesSimilar($sFile1, $sFile2) ; Parameters ....: $sFile1 - first file to check similarity of. ; $sFile2 - second file to check similarity of. ; Return values .: Success - Returns 1 if the files are similar, or 0 otherwise and sets @extended: ; 1 - Difference of the "Modify" timestamp. ; 2 - Difference of size. ; Failure - Returns 0 and sets @error: ; 1 - At least one of the files was not found, or could not get timestamp of At least one of the files. ; 2 - At least one of the files was not found, or could not get size of At least one of the files. ; Author ........: orbs ; Modified ......: ; Remarks .......: ; Related .......: ; Dependencies ..: _LFN_FileGetTime, _LFN_FileGetSize ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func __LFN_FilesSimilar($sFile1, $sFile2) Local $sTime1 = _LFN_FileGetTime($sFile1, 0, 1) If @error Then Return SetError(1, 0, 0) Local $sTime2 = _LFN_FileGetTime($sFile2, 0, 1) If @error Then Return SetError(1, 0, 0) If Abs(Number($sTime1) - Number($sTime2)) > 2 Then Return SetExtended(1, 0) Local $nSize1 = _LFN_FileGetSize($sFile1) If @error Then Return SetError(2, 0, 0) Local $nSize2 = _LFN_FileGetSize($sFile2) If @error Then Return SetError(2, 0, 0) If $nSize1 <> $nSize2 Then Return SetExtended(2, 0) Return 1 EndFunc ;==>__LFN_FilesSimilar ; #FUNCTION# ==================================================================================================================== ; Name ..........: __LFN_FileWritable ; Description ...: Checks if a file can be written to. ; Syntax.........: __LFN_FileWritable($sFile) ; Parameters ....: $sFile - Full path of a single file to check. ; Return values .: Success - Returns True if the file can be written to. ; Failure - Returns False if the file cannot be written to. ; Author ........: KaFu ; Modified ......: orbs ; Remarks .......: ; Related .......: ; Dependencies ..: ; Link ..........: http://www.autoitscript.com/forum/topic/133076-looking-for-a-non-invasive-way-to-check-if-a-file-or-directory-is-writable-deletable-solved/ ; Example .......: No ; =============================================================================================================================== Func __LFN_FileWritable($sFile) Local $aRet = DllCall('kernel32.dll', 'handle', 'CreateFileW', _ 'wstr', __LFN_Target_SetUnicodePrefix($sFile), _ 'dword', 2, _ 'dword', 7, _ 'struct*', 0, _ 'dword', 3, _ 'dword', 0x02000000, _ 'handle', 0) If @error Or $aRet[0] = Ptr(-1) Or $aRet[0] = 0 Then Return False DllCall('kernel32.dll', 'bool', 'CloseHandle', 'handle', $aRet[0]) Return True EndFunc ;==>__LFN_FileWritable ; #FUNCTION# ==================================================================================================================== ; Name ..........: __LFN_ReDim ; Description ...: Applies ReDim on a 1-D array in an efficient way. ; Syntax.........: __LFN_ReDim(ByRef $aArray[, $xData='']) ; Parameters ....: $aArray - The array to ReDim ; $xData - [optional] Data to add to the array ; Return values .: Returns the array after ReDim ; Author ........: guinness ; Modified.......: orbs ; Remarks .......: The returned array probably has empty cells at the end. the value at element [0] is the count of used cells, ; not the count of total cells. To work with the returned array, use element [0] to determine the last used cell ; instead of UBound. ; To truncate the array to used size: ReDim $aArray[$aArray[0]+1] ; Related .......: ; Dependencies ..: ; Link ..........: http://www.autoitscript.com/forum/topic/129689-redim-the-most-efficient-way-so-far-when-you-have-to-resize-an-existing-array/?hl=array+2d ; Example .......: No ; =============================================================================================================================== Func __LFN_ReDim(ByRef $aArray, $xData = '') Local $iNewRealSize = UBound($aArray) If $aArray[0] >= UBound($aArray) - 1 Then ; if used size = real size then must redim, otherwise do nothing $iNewRealSize = Ceiling((UBound($aArray) + 1) * 1.5) ReDim $aArray[$iNewRealSize] EndIf $aArray[0] += 1 ; anyway used size increased If $xData <> '' Then $aArray[$aArray[0]] = $xData EndFunc ;==>__LFN_ReDim ; #FUNCTION# ==================================================================================================================== ; Name ..........: __LFN_ReDim2D ; Description ...: Applies ReDim on a 2-D array in an efficient way. ; Syntax.........: __LFN_ReDim2D(ByRef $aArray[, $xData=''[, $sDelimiter='|']]) ; Parameters ....: $aArray - The array to ReDim ; $xData - [optional] Data to add to the array ; $sDelimiter - [optional] Delimiter to be used to separate data elements to columns ; Return values .: Returns the array after ReDim ; Author ........: orbs ; Modified.......: ; Remarks .......: The returned array probably has empty rows at the end. the value at element [0][0] is the count of used rows, ; not the count of total rows. To work with the returned array, use element [0][0] to determine the last used ; cell instead of UBound. ; To truncate the array to used size: ReDim $aArray[$aArray[0][0]+1][UBound($aArray,2)] ; Related .......: ; Dependencies ..: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func __LFN_ReDim2D(ByRef $aArray, $xData = '', $sDelimiter = '|') Local $iNewRealSize = UBound($aArray) If $aArray[0][0] >= UBound($aArray) - 1 Then ; if used size = real size then must redim, otherwise do nothing $iNewRealSize = Ceiling((UBound($aArray) + 1) * 1.5) ReDim $aArray[$iNewRealSize][UBound($aArray, 2)] EndIf $aArray[0][0] += 1 ; anyway used size increased Local $aElements If $xData <> '' Then $aElements = StringSplit($xData, $sDelimiter) If $aElements[0] > UBound($aArray, 2) Then ReDim $aArray[$iNewRealSize][$aElements[0]] ; need to add columns For $i = 1 To $aElements[0] $aArray[$aArray[0][0]][$i - 1] = $aElements[$i] Next EndIf EndFunc ;==>__LFN_ReDim2D ; #FUNCTION# ==================================================================================================================== ; Name ..........: __LFN_Target_IsExistingFile ; Description ...: Checks if the target is a single file that exists and is not a folder. ; Syntax.........: __LFN_Target_IsExistingFile($sTarget) ; Parameters ....: $sTarget - Full path to check. ; Return values .: True if the target is an existing file. ; False if the target is a mask, a folder, or does not exist. ; Author ........: orbs ; Modified ......: ; Remarks .......: ; Related .......: ; Dependencies ..: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func __LFN_Target_IsExistingFile($sTarget) If __LFN_FilesExist($sTarget) And @extended = 1 Then Return True Return False EndFunc ;==>__LFN_Target_IsExistingFile ; #FUNCTION# ==================================================================================================================== ; Name ..........: __LFN_Target_IsExistingFolder ; Description ...: Checks if the target is a folder that exists. ; Syntax.........: __LFN_Target_IsExistingFolder($sTarget) ; Parameters ....: $sTarget - Full path to check. ; Return values .: True if the target is an existing folder. ; False if the target is a mask, a file, or does not exist. ; Author ........: orbs ; Modified ......: ; Remarks .......: ; Related .......: ; Dependencies ..: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func __LFN_Target_IsExistingFolder($sTarget) If __LFN_FilesExist($sTarget) And @extended = 3 Then Return True Return False EndFunc ;==>__LFN_Target_IsExistingFolder ; #FUNCTION# ==================================================================================================================== ; Name ..........: __LFN_Target_IsMask ; Description ...: Checks if the target is multiple files (includes wildcards). ; Syntax.........: __LFN_Target_IsMask($sTarget) ; Parameters ....: $sTarget - Full path to check (wildcards supported). ; Return values .: True if the target is multiple files. ; False if the target is a single file. ; Author ........: orbs ; Modified ......: ; Remarks .......: If the target is a folder then it is not multiple files, therefore False is returned. ; The target does not have to exist. ; Related .......: ; Dependencies ..: __LFN_Target_LastElement_Get ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func __LFN_Target_IsMask($sTarget) Local $sLastElement = __LFN_Target_LastElement_Get($sTarget) If (StringInStr($sLastElement, '*') Or StringInStr($sLastElement, '?')) Then Return True Return False EndFunc ;==>__LFN_Target_IsMask ; #FUNCTION# ==================================================================================================================== ; Name ..........: __LFN_Target_LastElement_Get ; Description ...: Isolates the last filesystem element of a target - what's after the last backslash ("\") character. ; Syntax.........: __LFN_Target_LastElement_Get($sTarget[, $sDelimiter = '\']) ; Parameters ....: $sTarget - Filesystem element to check (wildcards supported). ; $sDelimiter - Delimiter to determine the last element ; Return values .: A string of the last filesystem element. ; Author ........: orbs ; Modified ......: ; Remarks .......: $sDelimiter MUST be a single character! ; The target does not have to exist. ; The return string does not begin with the leading delimiter. ; Related .......: ; Dependencies ..: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func __LFN_Target_LastElement_Get($sTarget, $sDelimiter = '\') Local $sTargetUnset = __LFN_Target_UnSetUnicodePrefix($sTarget) Local $iPos = StringInStr($sTargetUnset, $sDelimiter, 0, -1) Return StringTrimLeft($sTargetUnset, $iPos) EndFunc ;==>__LFN_Target_LastElement_Get ; #FUNCTION# ==================================================================================================================== ; Name ..........: __LFN_Target_LastElement_Trim ; Description ...: Trims the last filesystem element of a target and returns what's before the last backslash ("\") character. ; Syntax.........: __LFN_Target_LastElement_Trim($sTarget[, $sDelimiter = '\']) ; Parameters ....: $sTarget - Filesystem element to check (wildcards supported). ; $sDelimiter - Delimiter to determine the last element ; Return values .: A string of the target with the last filesystem element stripped from it. ; Author ........: orbs ; Modified ......: ; Remarks .......: $sDelimiter MUST be a single character! ; The target does not have to exist. ; The return string does not end with the trailing delimiter. ; Related .......: ; Dependencies ..: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func __LFN_Target_LastElement_Trim($sTarget, $sDelimiter = '\') Local $sTargetUnset = __LFN_Target_UnSetUnicodePrefix($sTarget) Local $iPos = StringInStr($sTargetUnset, $sDelimiter, 0, -1) Return __LFN_Target_SetUnicodePrefix(StringLeft($sTargetUnset, $iPos - 1)) EndFunc ;==>__LFN_Target_LastElement_Trim ; #FUNCTION# ==================================================================================================================== ; Name ..........: __LFN_Target_RemoveTrailingBackslash ; Description ...: Strips all trailing backslash characters ("\") from the end of the given target path. ; Syntax.........: __LFN_Target_RemoveTrailingBackslash($sTarget) ; Parameters ....: $sTarget - Target path to remove trailing backslash characters from (wildcards supported). ; Return values .: A string of the target path without trailing backslash. ; @extended holds the number of backslash characters removed. ; Author ........: orbs ; Modified ......: ; Remarks .......: The target does not have to exist. ; Related .......: ; Dependencies ..: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func __LFN_Target_RemoveTrailingBackslash($sTarget) Local $nBackslashedRemoved = 0 While StringRight($sTarget, 1) = '\' $sTarget = StringTrimRight($sTarget, 1) $nBackslashedRemoved += 1 WEnd Return SetExtended($nBackslashedRemoved, $sTarget) EndFunc ;==>__LFN_Target_RemoveTrailingBackslash ; #FUNCTION# ==================================================================================================================== ; Name ..........: __LFN_Target_SetUnicodePrefix ; Description ...: Adds the unicode prefix to a given target, unless already present or some conditios are mey - see Remarks. ; Syntax.........: __LFN_Target_SetUnicodePrefix($sTarget) ; Parameters ....: $sTarget - Path to prefix with the unicode prefix ("\\?\" or "\\?\UNC\"). ; Return values .: Returns the parameter with the unicode prefix and sets @extended: ; 1 - $sTarget is on a locally mounted volume (local drive, mapped network drive, etc.) ; 2 - $sTarget is on a network share (UNC path) ; Author ........: orbs ; Modified.......: ; Remarks .......: The unicode prefix is added only if needed. it is not added under these conditions: ; $sTarget already has the unicode prefix ; $sTarget is a drive root ; $sTarget is a relative path ; Related .......: ; Dependencies ..: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func __LFN_Target_SetUnicodePrefix($sTarget) If (StringLeft($sTarget, 4) = '\\?\') Then $sTarget = __LFN_Target_UnSetUnicodePrefix($sTarget) ; remove unicode prefix in case it's a drive root If (StringLen($sTarget) = 2 And StringRight($sTarget, 1) = ':') Or (StringLen($sTarget) = 3 And StringRight($sTarget, 2) = ':\') Then Return $sTarget ; $sTarget is a drive root If StringLeft($sTarget, 2) <> '\\' And StringMid($sTarget, 2, 1) <> ':' Then Return $sTarget ; $sTarget is a relative path ; before adding prefix, embody relative elements "\.." Local $iPos, $iPosPrevBackslash, $sSubstringToReplace While True $iPos = StringInStr($sTarget, '\..') If $iPos = 0 Then ExitLoop $iPosPrevBackslash = $iPos Do $iPosPrevBackslash -= 1 Until StringMid($sTarget, $iPosPrevBackslash, 1) = '\' Or $iPos = 0 $sSubstringToReplace = StringMid($sTarget, $iPosPrevBackslash, $iPos - $iPosPrevBackslash + 3) $sTarget = StringReplace($sTarget, $sSubstringToReplace, '', 1) WEnd ; now add the unicode prefix and return If StringLeft($sTarget, 2) = '\\' Then Return SetExtended(2, '\\?\UNC\' & StringTrimLeft($sTarget, 2)) Else Return SetExtended(1, '\\?\' & $sTarget) EndIf EndFunc ;==>__LFN_Target_SetUnicodePrefix ; #FUNCTION# ==================================================================================================================== ; Name ..........: __LFN_Target_UnSetUnicodePrefix ; Description ...: Removes the unicode prefix from a given target. ; Syntax.........: __LFN_Target_UnSetUnicodePrefix($sTarget) ; Parameters ....: $sTarget - Filesystem element to remove the unicode prefix ("\\?\" or "\\?\UNC\") from. ; Return values .: Returns the parameter without the unicode prefix and sets @extended: ; 0 - The unicode prefix was not found. ; 1 - $sTarget is on a locally mounted volume (local drive, mapped network drive, etc.) ; 2 - $sTarget is on a network share (UNC path) ; Author ........: orbs ; Modified.......: ; Remarks .......: ; Related .......: ; Dependencies ..: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func __LFN_Target_UnSetUnicodePrefix($sTarget) If (StringLeft($sTarget, 8) = '\\?\UNC\') Then Return SetExtended(2, '\\' & StringTrimLeft($sTarget, 8)) If (StringLeft($sTarget, 4) = '\\?\') Then Return SetExtended(1, StringTrimLeft($sTarget, 4)) Return $sTarget EndFunc ;==>__LFN_Target_UnSetUnicodePrefix demo script: #AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 AutoItSetOption('TrayIconDebug',1) #include <Array.au3> ; included only for a call to _ArrayDisplay #include 'LFN.au3' ; INIT ; - declare root of test folder Global $sLFN_Root='C:\TEMP\LFN' ; - declare element of path - create an element (subfolder) of 200 characters in length. two of those, and you're off limit. Global $sLFN_Element='' For $i=1 To 20 $sLFN_Element=$sLFN_Element&'_-_-_-_'&StringFormat('%03d',$i*10) Next ; - declare 3 levels of path lengths: Global $sLFN_L0=$sLFN_Root ; level 0 is the root of the test folder Global $sLFN_L1=$sLFN_L0&'\'&$sLFN_Element ; level 1 is one element deep (total 212 characters) - still OK Global $sLFN_L2=$sLFN_L1&'\'&$sLFN_Element ; level 2 is two elements deep (total 413 characters) - off limit! Global $sLFN_L3=$sLFN_L2&'\'&$sLFN_Element ; level 3 is three elements deep (total 614 characters) - way off limit! ; MAIN ; - prepare folder structure _LFN_DirRemove($sLFN_L0,1) ; delete the 1st test folder to begin blank _LFN_DirRemove($sLFN_L0&'2',1) ; delete the 2nd test folder to begin blank _LFN_DirRemove($sLFN_L0&'3',1) ; delete the 3rd test folder to begin blank MsgBox(0,'Checkpoint','check clear folder now.') _LFN_DirCreate($sLFN_L3) ; create the deepest level L3 ; - file manipulation _LFN_FileWriteLine($sLFN_L3&'\file1.txt','this is a line of text') ; create a file by writing a line to a new file Global $hFile=_LFN_FileOpen($sLFN_L3&'\file1.txt',1) ; do some file manipulation _LFN_FileWriteLine($hFile,'this is a line of text') ; add a line to the file _LFN_FileSetPos($hFile,-14,2) ; beginning of the word "line" _LFN_FileWrite($hFile,'LINE') ; capitalize the word "line" _LFN_FileFlush($hFile) ; apply the change _LFN_FileSetPos($hFile,-4,1) ; back MsgBox(0,'_LFN_FileGetPos',_LFN_FileGetPos($hFile)) MsgBox(0,'_LFN_FileRead (4 chars)',_LFN_FileRead($hFile,4)) ; read the change _LFN_FileSetEnd($hFile) ; truncate the rest of the line _LFN_FileClose($hFile) ; done for now _LFN_FileSetTime($sLFN_L3&'\file1.txt','20011231010203') ; - test file info Global $aFileLines=_LFN_FileReadToArray($sLFN_L3&'\file1.txt') _ArrayDisplay($aFileLines,'_LFN_FileReadToArray') Global $hSearch=_LFN_FileFindFirstFile($sLFN_L3&'\file1.txt') Global $sShortName=_LFN_FileGetShortName($sLFN_L3&'\file1.txt') Global $sLongName=_LFN_FileGetLongName($sShortName) MsgBox(0,'test file information', _ '_LFN_FileExists = '&_LFN_FileExists($sLFN_L3&'\file1.txt')&@CR&@CR& _ '_LFN_FileFindNextFile = '&_LFN_FileFindNextFile($hSearch)&@CR&@CR& _ '_LFN_FileRead (entire file) = '&@CR&_LFN_FileRead($sLFN_L3&'\file1.txt')&@CR&@CR& _ '_LFN_FileReadLine (last line) = '&_LFN_FileReadLine($sLFN_L3&'\file1.txt',-1)&@CR&@CR& _ '_LFN_FileGetSize = '&_LFN_FileGetSize($sLFN_L3&'\file1.txt')&@CR&@CR& _ '_LFN_FileGetTime = '&_LFN_FileGetTime($sLFN_L3&'\file1.txt',0,1)&@CR&@CR& _ '_LFN_FileGetShortName = '&$sShortName&@CR&@CR& _ '_LFN_FileGetLongName (from short name) = '&$sLongName) _LFN_FileClose($hSearch) ; - exe file info _LFN_FileCopy(@AutoItExe,$sLFN_L3) MsgBox(0,'EXE file information', _ '_LFN_FileGetVersion (not specified) = '&_LFN_FileGetVersion($sLFN_L3&'\AutoIt3.exe')&@CR& _ '_LFN_FileGetVersion (empty string) = '&_LFN_FileGetVersion($sLFN_L3&'\AutoIt3.exe','')&@CR& _ '_LFN_FileGetVersion ("FileVersion") = '&_LFN_FileGetVersion($sLFN_L3&'\AutoIt3.exe','FileVersion')&@CR&@CR& _ '_LFN_FileGetEncoding = '&_LFN_FileGetEncoding($sLFN_L3&'\AutoIt3.exe')) ; - file copy, rename, move _LFN_FileCopy($sLFN_L3&'\file1.txt',$sLFN_L2) MsgBox(0,'Checkpoint','file copy L3 -> L2') _LFN_FileMove($sLFN_L2&'\file1.txt',$sLFN_L2&'\renamed1.txt') MsgBox(0,'Checkpoint','file rename L2\file1.txt -> L2\renamed1.txt') _LFN_FileMove($sLFN_L2&'\renamed1.txt',$sLFN_L3) MsgBox(0,'Checkpoint','file move L2\renamed1.txt -> L3') _LFN_FileCopy($sLFN_L3,$sLFN_L2) MsgBox(0,'Checkpoint','file copy L3 -> L2') _LFN_FileDelete($sLFN_L2) MsgBox(0,'Checkpoint','file delete L2') ; - folder copy, rename, move, hide/unhide _LFN_DirCopy($sLFN_L0,$sLFN_L0&'2') MsgBox(0,'Checkpoint','dir copy <L0> -> <L02>') _LFN_DirMove($sLFN_L0,$sLFN_L0&'2',1) MsgBox(0,'Checkpoint','dir move <L0> -> <L02> (inside)') _LFN_DirCopy($sLFN_L0&'2\LFN',$sLFN_L0) MsgBox(0,'Checkpoint','dir copy <L02>\LFN -> <L0>') _LFN_FileSetAttrib($sLFN_L0,'+H') MsgBox(0,'Checkpoint','dir hidden <L0>'&@CR&@CR&'dir attrib: '&_LFN_FileGetAttrib($sLFN_L0)) _LFN_FileSetAttrib($sLFN_L0,'-H') MsgBox(0,'Checkpoint','dir unhidden <L0>'&@CR&@CR&'dir attrib: '&_LFN_FileGetAttrib($sLFN_L0)) ; - folder size Global $aDirSize=_LFN_DirGetSize($sLFN_L0,1) MsgBox(0,'Checkpoint','dir size <L0>: '&@CR&@CR& _ 'Size [bytes] = '&$aDirSize[0]&@CR& _ 'Files count = '&$aDirSize[1]&@CR& _ 'Folders count = '&$aDirSize[2]) ; - ini functions Global $sIniFile1=$sLFN_L3&'\test1.ini' Global $sIniFile2=$sLFN_L3&'\test2.ini' MsgBox(0,'Checkpoint','_LFN_IniWrite (S1K1) = '&_LFN_IniWrite($sIniFile1,'S1','S1K1','""S1V1 inside double-souble-quotes to be stripped""')) MsgBox(0,'Checkpoint','_LFN_IniWriteSection (S2) = '&_LFN_IniWriteSection($sIniFile1,'S2','S2K1= S2V1 with whitespaces NOT to be stripped '&@LF&'S2K2="S2V2 inside double-quotes NOT to be stripped"'&@LF&'S2K3=V3')) MsgBox(0,'Checkpoint','_LFN_IniWrite (S1K2) = '&_LFN_IniWrite($sIniFile1,'S1','S1K2','" S1V2 with quoted whitespaces "')) MsgBox(0,'Checkpoint','_LFN_IniWriteSection (S3) = '&_LFN_IniWriteSection($sIniFile1,'S3','S3K1=V1'&@LF&'S3K2=V2'&@LF&'S3K3=V3')) MsgBox(0,'Checkpoint','_LFN_IniWrite (S1K3) = '&_LFN_IniWrite($sIniFile1,'S1','S1K3','V3')) MsgBox(0,'Checkpoint','_LFN_IniRead (S1K2) = '&_LFN_IniRead($sIniFile1,'S1','S1K2','S1K2: could not read value')) Global $a $a=_LFN_IniReadSection($sIniFile1,'S3') $a[1][1]='"V1 with quotes"' $a[2][1]=' V2 with whitespace ' MsgBox(0,'Checkpoint','_LFN_IniDelete 1:(S3) = '&_LFN_IniDelete($sIniFile1,'S3')) MsgBox(0,'Checkpoint','_LFN_IniWriteSection 2:(S3) = '&_LFN_IniWriteSection($sIniFile2,'S3',$a)) $a=_LFN_IniReadSection($sIniFile1,'S2') MsgBox(0,'Checkpoint','_LFN_IniDelete 1:(S2K2) = '&_LFN_IniDelete($sIniFile1,'S2','S2K2')) MsgBox(0,'Checkpoint','_LFN_IniWriteSection 2:(S2) = '&_LFN_IniWriteSection($sIniFile2,'S2',$a)) MsgBox(0,'Checkpoint','_LFN_IniRenameSection 2:(S2) = '&_LFN_IniRenameSection($sIniFile2,'S2','S2renamed')) Global $aSectionNames=_LFN_IniReadSectionNames($sIniFile2) _ArrayDisplay($aSectionNames,'section names') For $i=1 To $aSectionNames[0] $a=_LFN_IniReadSection($sIniFile2,$aSectionNames[$i]) _ArrayDisplay($a,$aSectionNames[$i]) Next script converter: #NoTrayIcon #Region refs ; http://www.autoitscript.com/forum/topic/135536-how-to-make-the-gui-resizable/ ; https://www.autoitscript.com/wiki/Adding_UDFs_to_AutoIt_and_SciTE ; https://www.autoitscript.com/autoit3/docs/appendix/WinMsgCodes.htm #EndRegion refs #Region AutoIt3Wrapper directives section #AutoIt3Wrapper_Icon=LFN_Script_Converter_NG.ico #AutoIt3Wrapper_UseUpx=N #AutoIt3Wrapper_Res_Fileversion=1.4.0.3 #EndRegion AutoIt3Wrapper directives section #Region include #include <StaticConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #include <ComboConstants.au3> #include <GuiButton.au3> #EndRegion include #Region declare ; declare Global $aFuncs[1] = [0] Global $sScript_File = '' Global $aScriptOrg[1] = [0] Global $aScriptNew[1] = [0] Global $aLineChanged[1][3] Global $iLineChanged = 0 Global $bNeedToInclude = True ; assume the LFN UDF is not alredy included Global $iLineOfLastInclude = 0 ; after this line number, the line to include the LFN UDF will be added Global $tPoint_MainGlobal = DllStructCreate($tagPoint) ; ListView tooltips ; declare and populate possible UDF paths Global $sUDF_Path_MainInclude = RegRead('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\AutoItv3', 'UninstallString') If $sUDF_Path_MainInclude = '' Then $sUDF_Path_MainInclude = RegRead('HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\AutoItv3', 'UninstallString') If $sUDF_Path_MainInclude = '' Then $sUDF_Path_MainInclude = RegRead('HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\AutoItv3', 'UninstallString') If $sUDF_Path_MainInclude <> '' Then $sUDF_Path_MainInclude = StringLeft($sUDF_Path_MainInclude, StringInStr($sUDF_Path_MainInclude, '\', 0, -1) - 1) If $sUDF_Path_MainInclude <> '' Then $sUDF_Path_MainInclude &= '\Include' Global $sUDF_Path_UserInclude = RegRead('HKCU\Software\AutoIt v3\AutoIt', 'Include') ; declare UDF properties Global $sUDF_Name = 'LFN.au3' Global $sUDF = '' Global $sUDF_Version = '' Global $sUDF_AutoItVersion = '' Global $sUDF_FunctionsList = '' ; declare and init preferences Global $bMonospace = False Global $bCreateBackup = True Global $bIncludeUDF = True Global $bConvertFileFindNextFile = False #EndRegion declare #Region build GUI $hGUI = GUICreate('LFN Script Converter', 500, 500, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_MAXIMIZEBOX, $WS_SIZEBOX, $WS_SYSMENU)) GUISetBkColor(0xFEDCBA) $iLine_Y = 25 GUICtrlCreateGroup('UDF', 10, $iLine_Y - 18, 355, 40) RemoveTheme(GUICtrlGetHandle(-1)) GUICtrlSetColor(-1, 0x876543) GUICtrlSetResizing(-1, BitOR($GUI_DOCKTOP, $GUI_DOCKLEFT, $GUI_DOCKSIZE)) GUICtrlCreateLabel('Location:', 20, $iLine_Y, 50, 16) GUICtrlSetResizing(-1, BitOR($GUI_DOCKTOP, $GUI_DOCKLEFT, $GUI_DOCKSIZE)) $gUDF_Path = GUICtrlCreateCombo('Script folder', 75, $iLine_Y - 4, 160, 100, $CBS_DROPDOWNLIST) GUICtrlSetResizing(-1, BitOR($GUI_DOCKTOP, $GUI_DOCKLEFT, $GUI_DOCKSIZE)) If $sUDF_Path_MainInclude <> '' Then GUICtrlSetData(-1, 'AutoIt main include folder') If $sUDF_Path_UserInclude <> '' Then GUICtrlSetData(-1, 'AutoIt user include folder') GUICtrlCreateLabel('Name:', 250, $iLine_Y, 35, 16) GUICtrlSetResizing(-1, BitOR($GUI_DOCKTOP, $GUI_DOCKLEFT, $GUI_DOCKSIZE)) $gUDF_Name = GUICtrlCreateInput($sUDF_Name, 285, $iLine_Y - 2, 70, 18) GUICtrlSetResizing(-1, BitOR($GUI_DOCKTOP, $GUI_DOCKLEFT, $GUI_DOCKSIZE)) $gPref = GUICtrlCreateLabel(Chr(64), 459, $iLine_Y - 4, 20, 20, BitOR($SS_CENTER, $SS_CENTERIMAGE)) GUICtrlSetResizing(-1, BitOR($GUI_DOCKTOP, $GUI_DOCKRIGHT, $GUI_DOCKSIZE)) GUICtrlSetFont(-1, 18, Default, 0, 'Webdings') GUICtrlSetCursor(-1, 0) GUICtrlSetColor(-1, 0x876543) GUICtrlSetTip(-1, 'Preferences') $gPref_Menu_Dummy = GUICtrlCreateDummy() $gPref_Menu = GUICtrlCreateContextMenu($gPref_Menu_Dummy) $gPref_Menu_Monospace = GUICtrlCreateMenuItem('Monospace Font', $gPref_Menu) $gPref_Menu_CreateBackup = GUICtrlCreateMenuItem('Create Backup', $gPref_Menu) If $bCreateBackup Then GUICtrlSetState($gPref_Menu_CreateBackup, $GUI_CHECKED) $gPref_Menu_IncludeUDF = GUICtrlCreateMenuItem('Include UDF', $gPref_Menu) If $bIncludeUDF Then GUICtrlSetState($gPref_Menu_IncludeUDF, $GUI_CHECKED) $gPref_Menu_ConvertFileFindNextFile = GUICtrlCreateMenuItem('Convert FileFindNextFile', $gPref_Menu) If $bConvertFileFindNextFile Then GUICtrlSetState($gPref_Menu_ConvertFileFindNextFile, $GUI_CHECKED) $iLine_Y = 73 GUICtrlCreateGroup('Script', 10, $iLine_Y - 18, 480, 40) RemoveTheme(GUICtrlGetHandle(-1)) GUICtrlSetColor(-1, 0x876543) GUICtrlSetResizing(-1, BitOR($GUI_DOCKTOP, $GUI_DOCKLEFT, $GUI_DOCKRIGHT, $GUI_DOCKHEIGHT)) $gScript_File = GUICtrlCreateInput('', 20, $iLine_Y - 2, 265, 18) GUICtrlSetResizing(-1, BitOR($GUI_DOCKTOP, $GUI_DOCKLEFT, $GUI_DOCKRIGHT, $GUI_DOCKHEIGHT)) $gScript_Select = GUICtrlCreateButton('Browse', 290, $iLine_Y - 3, 60, 20) GUICtrlSetResizing(-1, BitOR($GUI_DOCKTOP, $GUI_DOCKRIGHT, $GUI_DOCKSIZE)) $gScript_Convert = GUICtrlCreateButton('Convert', 355, $iLine_Y - 3, 125, 20, $BS_SPLITBUTTON) GUICtrlSetResizing(-1, BitOR($GUI_DOCKTOP, $GUI_DOCKRIGHT, $GUI_DOCKSIZE)) $gScript_Convert_Menu_Dummy = GUICtrlCreateDummy() $gScript_Convert_Menu = GUICtrlCreateContextMenu($gScript_Convert_Menu_Dummy) $gScript_Convert_Menu_QueryUDF = GUICtrlCreateMenuItem('Query UDF', $gScript_Convert_Menu) $gScript_Convert_Menu_Analyze = GUICtrlCreateMenuItem('Analyze', $gScript_Convert_Menu) $gScript_Convert_Menu_Convert = GUICtrlCreateMenuItem('Convert', $gScript_Convert_Menu) $gLV = GUICtrlCreateListView('Line#|Original|Converted', 10, 100, 480, 370) GUICtrlSetFont(-1, Default, Default, Default, 'Tahoma') $hLV = GUICtrlGetHandle($gLV) _GUICtrlListView_SetColumnWidth($gLV, 0, 50) _GUICtrlListView_SetColumnWidth($gLV, 1, 200) _GUICtrlListView_SetColumnWidth($gLV, 2, 200) GUICtrlSetResizing(-1, $GUI_DOCKBORDERS) GUISetState() ControlFocus('', '', $gScript_File) GUIRegisterMsg($WM_GETMINMAXINFO, "_WM_GETMINMAXINFO") GUIRegisterMsg($WM_SIZE, "_WM_SIZE") GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ; for context menu of split button #EndRegion build GUI ; work with GUI While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_RESTORE, $GUI_EVENT_MAXIMIZE _WM_SIZE($hGUI, -1, -1, -1) Case $GUI_EVENT_MOUSEMOVE SetMousePos() TimerFunc($hLV) Case $gScript_Convert_Menu_QueryUDF If UDF_Query() Then MsgBox(0, 'UDF Info:', _ 'UDF Full Path:' & @TAB & $sUDF & @CR & _ 'UDF Version:' & @TAB & $sUDF_Version & @CR & _ 'AutoIt Version:' & @TAB & $sUDF_AutoItVersion & @CR & _ 'Functions List:' & @TAB & '(' & $aFuncs[0] & ' functions)' & @CR & _ $sUDF_FunctionsList) Case $gScript_Select $sScript_File = FileOpenDialog('Select an AutoIt v3 Script to convert:', @ScriptDir, 'AutoIt v3 Scripts (*.au3)') If Not @error Then GUICtrlSetData($gScript_File, $sScript_File) Call_Analyze() EndIf Case $gScript_Convert_Menu_Analyze Call_Analyze() Case $gScript_Convert, $gScript_Convert_Menu_Convert If Call_Analyze() Then Convert() Case $gPref _ContextMenu_ShowMenu($hGUI, $gPref, $gPref_Menu, -180) Case $gPref_Menu_Monospace $bMonospace = Not $bMonospace If $bMonospace Then GUICtrlSetState($gPref_Menu_Monospace, $GUI_CHECKED) GUICtrlSetFont($gLV, Default, Default, Default, 'Courier New') Else GUICtrlSetState($gPref_Menu_Monospace, $GUI_UNCHECKED) GUICtrlSetFont($gLV, Default, Default, Default, 'Tahoma') EndIf Case $gPref_Menu_CreateBackup $bCreateBackup = Not $bCreateBackup If $bCreateBackup Then GUICtrlSetState($gPref_Menu_CreateBackup, $GUI_CHECKED) Else GUICtrlSetState($gPref_Menu_CreateBackup, $GUI_UNCHECKED) EndIf Case $gPref_Menu_IncludeUDF $bIncludeUDF = Not $bIncludeUDF If $bIncludeUDF Then GUICtrlSetState($gPref_Menu_IncludeUDF, $GUI_CHECKED) Else GUICtrlSetState($gPref_Menu_IncludeUDF, $GUI_UNCHECKED) EndIf Case $gPref_Menu_ConvertFileFindNextFile $bConvertFileFindNextFile = Not $bConvertFileFindNextFile If $bConvertFileFindNextFile Then GUICtrlSetState($gPref_Menu_ConvertFileFindNextFile, $GUI_CHECKED) Else GUICtrlSetState($gPref_Menu_ConvertFileFindNextFile, $GUI_UNCHECKED) EndIf EndSwitch WEnd Func Call_Analyze() If GUICtrlRead($gScript_File) = '' Then MsgBox(16, 'Error!', 'Please select a script file to convert. ', 0, $hGUI) Return False EndIf _GUICtrlListView_DeleteAllItems($gLV) If Not UDF_Query() Then Return False If Analyze() Then For $i = 1 To $iLineChanged GUICtrlCreateListViewItem($aLineChanged[$i][0] & '|' & StringStripWS($aLineChanged[$i][1], 3) & '|' & StringStripWS($aLineChanged[$i][2], 3), $gLV) Next Else MsgBox(64, 'Abort', 'Conversion aborted.' & @CR & @CR & 'No changes need to be made. Script is either already converted or does not use any functions to be converted. ', 0, $hGUI) GUICtrlSetData($gScript_File, '') Return False EndIf Return True EndFunc ;==>Call_Analyze Func UDF_Query() Local $sScript_Path = '' $sUDF_Name = GUICtrlRead($gUDF_Name) If $sUDF_Name = '' Then MsgBox(16, 'Error!', 'Please type the UDF file name. ', 0, $hGUI) Return False EndIf Switch GUICtrlRead($gUDF_Path) Case 'Script folder' $sScript_Path = GUICtrlRead($gScript_File) If $sScript_Path = '' Then $sScript_Path = @ScriptDir Else $sScript_Path = StringLeft($sScript_Path, StringInStr($sScript_Path, '\', 0, -1) - 1) EndIf $sUDF = $sScript_Path & '\' & $sUDF_Name Case 'AutoIt main include folder' $sUDF = $sUDF_Path_MainInclude & '\' & $sUDF_Name Case 'AutoIt user include folder' $sUDF = $sUDF_Path_UserInclude & '\' & $sUDF_Name Case Else MsgBox(16, 'Error!', 'Unknown item in locations list. ', 0, $hGUI) Return False EndSwitch If Not FileExists($sUDF) Then MsgBox(16, 'Error!', 'UDF file not found: ' & @CR & @CR & $sUDF, 0, $hGUI) Return False EndIf $sUDF_Version = 'n/a' $sUDF_AutoItVersion = 'n/a' $sUDF_FunctionsList = '' ReDim $aFuncs[1] $aFuncs[0] = 0 $aUDF = __FileReadToArray($sUDF) Local $bListFuncs = False For $i = 1 To UBound($aUDF) - 1 If StringLeft($aUDF[$i], 19) = '; UDF Version ...: ' Then $sUDF_Version = StringTrimLeft($aUDF[$i], 19) If StringLeft($aUDF[$i], 19) = '; AutoIt Version : ' Then $sUDF_AutoItVersion = StringTrimLeft($aUDF[$i], 19) If $bListFuncs Then If $aUDF[$i] = '; ===============================================================================================================================' Then ExitLoop $aFuncs[0] += 1 ReDim $aFuncs[$aFuncs[0] + 1] $aFuncs[$aFuncs[0]] = StringTrimLeft($aUDF[$i], 6) ; remove the string ";_LFN_" and leave only the native name of the function $sUDF_FunctionsList = $sUDF_FunctionsList & @TAB & $aFuncs[$aFuncs[0]] & @CR EndIf If $aUDF[$i] = '; #CURRENT# =====================================================================================================================' Then $bListFuncs = True Next If $aFuncs[0] = 0 Then MsgBox(16, 'Error!', 'No functions found in the LFN UDF file: ' & @CR & @CR & $sUDF, 0, $hGUI) Return False EndIf Return True EndFunc ;==>UDF_Query Func Analyze() ; init ReDim $aLineChanged[1][3] $aLineChanged[0][0] = 0 $aLineChanged[0][1] = 0 $aLineChanged[0][2] = 0 $iLineChanged = 0 $bNeedToInclude = True $iLineOfLastInclude = 0 ; read existing script to memory $aScriptOrg = __FileReadToArray($sScript_File) ; match size of new array ReDim $aScriptNew[UBound($aScriptOrg)] $aScriptNew[0] = UBound($aScriptNew) - 1 ; in memory, replace functions line-by-line, while searching for the last #include and checking if LFN UDF is not already included For $i = 1 To UBound($aScriptOrg) - 1 If StringInStr($aScriptOrg[$i], '#include ') Then $iLineOfLastInclude = $i If StringInStr($aScriptOrg[$i], $sUDF_Name) Then $bNeedToInclude = False EndIf $aScriptNew[$i] = ReplaceAllFuncs($aScriptOrg[$i]) If @extended Then $iLineChanged += 1 ReDim $aLineChanged[$iLineChanged + 1][3] $aLineChanged[$iLineChanged][0] = $i $aLineChanged[$iLineChanged][1] = $aScriptOrg[$i] $aLineChanged[$iLineChanged][2] = $aScriptNew[$i] EndIf Next ; control #1 - if no changes are required then exit If $iLineChanged = 0 Then Return False ; done analyze Return True EndFunc ;==>Analyze Func Convert() ToolTip('') ; summary report Local $sUDF_IncludeString = '' Local $sText = '' If $bCreateBackup Then $sText = $sText & '- Original file will be backed-up.' & @CR $sText = $sText & '- ' & $iLineChanged & ' lines will be modified.' & @CR If $bNeedToInclude And $bIncludeUDF Then $sText &= '- The statement #include ' If GUICtrlRead($gUDF_Path) = 'Script folder' Then $sUDF_IncludeString = '"' & $sUDF_Name & '"' Else $sUDF_IncludeString = '<' & $sUDF_Name & '>' EndIf $sText &= $sUDF_IncludeString $sText &= ' will be added ' If $iLineOfLastInclude = 0 Then $sText &= 'at the top of the script. ' Else $sText &= 'after line #' & $iLineOfLastInclude & ': ' & @CR & ' ' & $aScriptOrg[$iLineOfLastInclude] EndIf Else $sText &= '- #include statement will not be added.' EndIf If MsgBox(32 + 4, 'Conversion Summary:', $sText & @CR & @CR & 'Continue with the conversion?', 0, $hGUI) <> 6 Then MsgBox(64, 'Abort', 'Conversion aborted. No changes were made. ', 0, $hGUI) Return EndIf ; backup existing script If $bCreateBackup And Not FileCopy($sScript_File, $sScript_File & '.PreLFN_' & @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC & '.au3') Then MsgBox(16, 'Error!', 'Could not create a backup of the script before conversion. ', 0, $hGUI) Return EndIf ; rewrite the script Local $hScriptFile = FileOpen($sScript_File, 2) For $i = 1 To UBound($aScriptNew) - 1 If $bNeedToInclude And $bIncludeUDF And $i = $iLineOfLastInclude + 1 Then FileWriteLine($hScriptFile, '#include ' & $sUDF_IncludeString) If Not FileWriteLine($hScriptFile, $aScriptNew[$i]) Then MsgBox(16, 'Error!', 'Could not write line #' & $i & ' to the script file. ' & @CR & @CR & 'IMPORTANT: to avoid issues, you are advised to revert to the backup copy of your script. ', 0, $hGUI) FileClose($hScriptFile) Return EndIf Next FileClose($hScriptFile) MsgBox(64, 'Done', 'Conversion completed successfully. ', 0, $hGUI) EndFunc ;==>Convert Func ReplaceAllFuncs($sLine) ; isolate LFN UDF internal functions Local $sLineNew = StringReplace($sLine, '__LFN_', '__L!N_') ; revert any LFN UDF current functinos back to their native form $sLineNew = StringReplace($sLineNew, '_LFN_', '') ; convert functions to LFN For $i = 1 To $aFuncs[0] $sLineNew = StringRegExpReplace($sLineNew, "(?<!\w)(" & $aFuncs[$i] & '\(' & ")", '_LFN_' & $aFuncs[$i] & '(') Next ; revert isolation of LFN UDF internal functions $sLineNew = StringReplace($sLineNew, '__L!N_', '__LFN_') ; revert conversion of FileFindNextFile if needed If Not $bConvertFileFindNextFile Then $sLineNew = StringReplace($sLineNew, '_LFN_FileFindNextFile', 'FileFindNextFile') ; return the converted line with indication if it was changed or not If $sLineNew = $sLine Then Return SetExtended(0, $sLineNew) Else Return SetExtended(1, $sLineNew) EndIf EndFunc ;==>ReplaceAllFuncs Func __FileReadToArray($xFile) Return StringSplit(StringStripCR(FileRead($xFile, FileGetSize($xFile))), @LF) EndFunc ;==>__FileReadToArray Func RemoveTheme($hItem) DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", $hItem, "wstr", 0, "wstr", 0) EndFunc ;==>RemoveTheme #Region resizing funcs Func _WM_GETMINMAXINFO($hWnd, $iMsg, $wParam, $lParam) If $hWnd = $hGUI Then $tagMaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam) DllStructSetData($tagMaxinfo, 7, 500) ; min X DllStructSetData($tagMaxinfo, 8, 300) ; min Y Return 0 EndIf EndFunc ;==>_WM_GETMINMAXINFO Func _WM_SIZE($hWnd, $iMsg, $wParam, $lParam) If $hWnd = $hGUI Then $aLVPos = ControlGetPos($hGUI, "", $gLV) If @error Then Return Local $nLV_ColWidth = ($aLVPos[2] - 80) / 2 _GUICtrlListView_SetColumnWidth($gLV, 0, 50) _GUICtrlListView_SetColumnWidth($gLV, 1, $nLV_ColWidth) _GUICtrlListView_SetColumnWidth($gLV, 2, $nLV_ColWidth) EndIf EndFunc ;==>_WM_SIZE #EndRegion resizing funcs #Region ListView tooltip funcs Func TimerFunc($hLV) Local Const $nLinesAround = 10 Local Static $iIndex_old = -1 Local $iIndex = _GUICtrlListView_HitTest($hLV) If HoveringOnHeader($hLV) Or $iIndex[0] < 0 Then $iIndex_old = -1 Return ToolTip('') EndIf If $iIndex[0] = $iIndex_old Then Return Local $iLine = $aLineChanged[$iIndex[0] + 1][0] Local $iLineStart = 1 If $iLine - $nLinesAround > 1 Then $iLineStart = $iLine - $nLinesAround Local $iLineEnd = $iLine + $nLinesAround If UBound($aScriptNew) - 1 < $iLine + $nLinesAround Then $iLineEnd = UBound($aScriptNew) - 1 Local $sTooltip = '' For $i = $iLineStart To $iLineEnd $sTooltip = $sTooltip & $i & '.' & @TAB & $aScriptNew[$i] & @CR Next ; create tooltip ToolTip($sTooltip, Default, Default, 'Line #' & $iLine & ':', Default, 4) $iIndex_old = $iIndex[0] EndFunc ;==>TimerFunc Func SetMousePos() DllStructSetData($tPoint_MainGlobal, 1, MouseGetPos(0)) DllStructSetData($tPoint_MainGlobal, 2, MouseGetPos(1)) EndFunc ;==>SetMousePos Func HoveringOnHeader($hLV) Local $tRect = DllStructCreate($tagRect) Local $aPos = WinGetPos(_GUICtrlListView_GetHeader($hLV)) $aPos[2] = $aPos[0] + $aPos[2] $aPos[3] = $aPos[1] + $aPos[3] If @error Then Return SetError(1, 0, 0) For $i = 1 To 4 DllStructSetData($tRect, $i, $aPos[$i - 1]) Next Return _WinAPI_PtInRect($tRect, $tPoint_MainGlobal) EndFunc ;==>HoveringOnHeader #EndRegion ListView tooltip funcs #Region context menu for split button Func _ContextMenu_ShowMenu($hWnd, $CtrlID, $nContextID, $n_dx = 0) ; Show a menu in a given GUI window which belongs to a given GUI ctrl Local $arPos, $x, $y Local $hMenu = GUICtrlGetHandle($nContextID) $arPos = ControlGetPos($hWnd, "", $CtrlID) $x = $arPos[0] + $n_dx $y = $arPos[1] + $arPos[3] _ContextMenu_ClientToScreen($hWnd, $x, $y) _ContextMenu_TrackPopupMenu($hWnd, $hMenu, $x, $y) EndFunc ;==>_ContextMenu_ShowMenu Func _ContextMenu_ClientToScreen($hWnd, ByRef $x, ByRef $y) ; Convert the client (GUI) coordinates to screen (desktop) coordinates Local $stPoint = DllStructCreate("int;int") DllStructSetData($stPoint, 1, $x) DllStructSetData($stPoint, 2, $y) DllCall("user32.dll", "int", "ClientToScreen", "hwnd", $hWnd, "ptr", DllStructGetPtr($stPoint)) $x = DllStructGetData($stPoint, 1) $y = DllStructGetData($stPoint, 2) ; release Struct not really needed as it is a local $stPoint = 0 EndFunc ;==>_ContextMenu_ClientToScreen Func _ContextMenu_TrackPopupMenu($hWnd, $hMenu, $x, $y) ; Show at the given coordinates (x, y) the popup menu (hMenu) which belongs to a given GUI window (hWnd) DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $x, "int", $y, "hwnd", $hWnd, "ptr", 0) EndFunc ;==>_ContextMenu_TrackPopupMenu Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam) #forceref $hWnd, $Msg, $wParam Local $tNMBHOTITEM = DllStructCreate("hwnd hWndFrom;int IDFrom;int Code;dword dwFlags", $lParam) Local $nNotifyCode = DllStructGetData($tNMBHOTITEM, "Code") Local $hCtrl = DllStructGetData($tNMBHOTITEM, "hWndFrom") Switch $nNotifyCode Case $BCN_DROPDOWN _ContextMenu_ShowMenu($hGUI, $gScript_Convert, $gScript_Convert_Menu) EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY #EndRegion context menu for split button1 point
-
Compile multiple .ico files into one .dll file
nacerbaaziz reacted to Inpho for a topic
So after many weekends of battling with this I finally figured it; then I automated it. This script includes icon sushi (which is used to remove the 256 x 256 elements from each .ico) and RDG (to compile the icons into dll). I had to idiot proof this for when I inevitably forget how to do it. First GUI will ask you to choose a name (among other things) for your .dll file. Next GUI is a drag-and-drop box. Drag-and-drop your .ico files into the box and click Go. Error checking is minimal; it works fine for me but YRMV. I'm no master programmer at all but if this script can help you as much as it helped me then cool. Download: ico2dll.Exe Known issues: .ico's containing any layers larger than 256 x 256 px will be ignored by icon sushi ico2dll only registers one drag-and-drop event so put all your required icons into one folder; then drag-and-drop them into ico2dll Extra info: Basically, the RC.exe that is included with Visual Studio doesn't seem to support 256 x 256 or larger icons when creating a resource-only .dll file. This script uses icon sushi to remove all 256 x 256 elements from your .ico files (if your icon file contains any layers larger than 256 x 256 then you will have to remove those manually through a program like gimp) before compiling them into the .dll. #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=..\ICONS\Capital18-Ethereal-2-Mimetypes-dll.ico #AutoIt3Wrapper_Outfile=ico2dll.Exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #include <GuiEdit.au3> #include <File.au3> #include <Misc.au3> #include <Array.au3> Opt("trayicondebug", 1) $tmp = "C:\ico2dlltemp\" $tmprmv = "C:\ico2dlltemp\rmv\" If FileExists($tmp) Then DirRemove($tmp, 1) Sleep(100) DirCreate($tmprmv) Global $FileName, $ListViewIndexSel = -1, $PathAllExist, $RCFile, $vpath Global $szDrive, $szDir, $szFName, $szExt, $dBox, $iData, $vdata2, $lang, $iData2 Global $TmpDir = @TempDir & "\ResDllGen" Global $TmpDirplusSlash = @TempDir & "\ResDllGen\" Global $Res_List, $Res_Name, $Res_Type, $Res_Path, $StrLenPath, $Bloc, $LangHex If FileExists($TmpDir) Then DirRemove($TmpDir, 1) If FileExists($TmpDirplusSlash) Then DirRemove($TmpDirplusSlash, 1) Sleep(100) DirCreate($TmpDirplusSlash) $rnd = Random(999, 99999, 1) DirCreate(@ScriptDir & "\tools\") DirCreate(@ScriptDir & "\Languages\") FileInstall("aicon.exe", @ScriptDir & "\aicon.exe") FileInstall("aicon.ini", @ScriptDir & "\aicon.ini") FileInstall("brushes", @ScriptDir & "\brushes") FileInstall("Languages\English.lng", @ScriptDir & "\Languages\English.lng") FileInstall("Languages\“ú–{Œê.lng", @ScriptDir & "\Languages\“ú–{Œê.lng") FileInstall("Languages\Default.lng", @ScriptDir & "\Languages\Default.lng") ;FileInstall("G:\autoo\resdll\generator\RDG.exe", @ScriptDir & "\RDG.exe") FileInstall("tools\cvtres.exe", @ScriptDir & "\tools\cvtres.exe") FileInstall("tools\DLLSZ.ico", @ScriptDir & "\tools\DLLSZ.ico") FileInstall("tools\link.exe", @ScriptDir & "\tools\link.exe") FileInstall("tools\mspdb50.dll", @ScriptDir & "\tools\mspdb50.dll") FileInstall("tools\rc.exe", @ScriptDir & "\tools\rc.exe") FileInstall("tools\RCdll.dll", @ScriptDir & "\tools\RCdll.dll") Const $SP = "#~#" Dim $Lang _SelectLanguage() $Res_Gui_2 = GUICreate($lang[22], 390, 470, -1, -1, -1) ; DLL Info $FileVersion_Title = GUICtrlCreateLabel($lang[23] & " :", 110, 8, 171, 28) ; DLL Informations GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif") GUICtrlCreateLabel($lang[24], 15, 60, 125, 20) ; Dll Filename GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $Dll_File_Name = GUICtrlCreateInput($lang[25], 175, 60, 140, 21) ; MyDll GUICtrlCreateLabel(".Dll", 318, 63, 30, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") GUICtrlCreateLabel($lang[26], 16, 92, 130, 20) ; File Version GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $Dll_Ver1 = GUICtrlCreateInput("01", 175, 92, 35, 21, BitOR($ES_AUTOHSCROLL, $ES_NUMBER)) $UpD1 = GUICtrlCreateUpdown(-1) GUICtrlSetLimit(-1, 99, 01) $Dll_Ver2 = GUICtrlCreateInput("00", 220, 92, 35, 21, BitOR($ES_AUTOHSCROLL, $ES_NUMBER)) $UpD2 = GUICtrlCreateUpdown(-1) GUICtrlSetLimit(-1, 99) $Dll_Ver3 = GUICtrlCreateInput("0000", 265, 92, 49, 21, BitOR($ES_AUTOHSCROLL, $ES_NUMBER)) $UpD3 = GUICtrlCreateUpdown(-1) GUICtrlSetLimit(-1, 9999) $Dll_Ver4 = GUICtrlCreateInput("0000", 325, 92, 49, 21, BitOR($ES_AUTOHSCROLL, $ES_NUMBER)) $UpD4 = GUICtrlCreateUpdown(-1) GUICtrlSetLimit(-1, 9999) GUICtrlCreateLabel($lang[27], 16, 127, 150, 20) ; Product Version GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $Dll_PVer1 = GUICtrlCreateLabel("01,00,0000,0000", 175, 130, 90, 20) $Dll_PVer2 = GUICtrlCreateInput("", 265, 127, 110, 21) GUICtrlCreateLabel($lang[28], 16, 165, 150, 20) ; Product Name GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $Dll_Prod_Name = GUICtrlCreateInput($lang[29], 175, 165, 200, 21) ; Name_Of_Your_Product GUICtrlCreateLabel($lang[30], 16, 200, 150, 20) ; Compagny Name GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $Dll_Compagny = GUICtrlCreateInput($lang[31], 175, 200, 200, 21) ; Type_Your_Company GUICtrlCreateLabel($lang[32], 16, 235, 150, 20) ; Legal Copyright GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $Dll_Copyright = GUICtrlCreateInput($lang[33], 175, 235, 200, 21) ; Copyright_(C)_2007-2008 GUICtrlCreateLabel($lang[34], 16, 270, 150, 20) ; File Description GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $Dll_File_Desc = GUICtrlCreateInput($lang[35], 175, 270, 200, 21) ; Type_Your_Description GUICtrlCreateLabel($lang[36], 16, 305, 150, 20) ; Language GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $Dll_Lang = GUICtrlCreateCombo("", 175, 305, 90, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL)) GUICtrlSetData(-1, $lang[37], $lang[38]) ; English|French ; English ; See http://msdn.microsoft.com/en-us/library/aa381058%28VS.85%29.aspx for value. GUICtrlCreateLabel($lang[39], 16, 340, 150, 20) ; File OS GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $Dll_OS = GUICtrlCreateCombo("", 175, 340, 90, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL)) GUICtrlSetData(-1, $lang[40], $lang[41]) ; 0x40004 ; 0x40004 GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlCreateLabel($lang[42], 16, 375, 150, 20) ; File Type GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $Dll_File_Type = GUICtrlCreateCombo("", 175, 375, 90, 25, BitOR($CBS_DROPDOWNLIST, $CBS_AUTOHSCROLL)) GUICtrlSetData(-1, $lang[43], $lang[44]) ; 0x2 ; 0x2 GUICtrlSetState(-1, $GUI_DISABLE) $Btn_OK2 = GUICtrlCreateButton($lang[45], 160, 432, 75, 25) ; OK GUISetState(@SW_SHOW, $Res_Gui_2) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $Btn_OK2 If GUICtrlRead($Dll_File_Name) = $lang[25] Then ; MyDll MsgBox(32 + 8192, $lang[53], $lang[54] & @TAB) ; Dll File Name ; Please, Enter The Name Of Your Dll GUICtrlSetState($Dll_File_Name, $GUI_FOCUS) Else GUICtrlSetData($Dll_File_Name, StringReplace(GUICtrlRead($Dll_File_Name), " ", "_")) SetDllData() GUIDelete($Res_Gui_2) AddIcons() EndIf Case $UpD1, $UpD2, $UpD3, $UpD4 _UpdateVerNum() Case $GUI_EVENT_PRIMARYDOWN _UpdateVerNum() Case $GUI_EVENT_CLOSE TraySetState(2) Exit EndSwitch WEnd Func AddIcons() Global $__aGUIDropFiles = 0, $aDrop_List = 0 Global $txtInput = "Drag and drop your .ico files here" $mGUI = GUICreate("ico2dll", 900, 400, -1, -1, "", $WS_EX_ACCEPTFILES) $dBox = GUICtrlCreateEdit($txtInput, 10, 10, 874, 300) GUICtrlSetState($dBox, $GUI_DROPACCEPTED) $gBut = GUICtrlCreateButton("Go", 10, 320, 75, 25) $eBut = GUICtrlCreateButton("Exit", 810, 320, 75, 25) GUISetState() GUIRegisterMsg($WM_DROPFILES, 'On_WM_DROPFILES') While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE TraySetState(2) DirRemove($tmp, 1) Exit Case $eBut TraySetState(2) DirRemove($tmp, 1) Exit Case $GUI_EVENT_DROPPED GUICtrlSetData($dBox, "") For $i = 1 To $aDrop_List[0] $old = GUICtrlRead($dBox) $new = $old & $aDrop_List[$i] & @CRLF GUICtrlSetData($dBox, $new) Next Case $gBut $check = GUICtrlRead($dBox) If $check = $txtInput Then MsgBox(0, "Error", "You must drag-and-drop some .ico files into the box") ContinueLoop Else $iData = StringSplit($check, @LF) EndIf GUIDelete($mGUI) _MouseTrap(0, 0, 1, 1) CopyTemp() Rmv256() GenDll() _MouseTrap() EndSwitch WEnd EndFunc ;==>AddIcons Func Rmv256() DirCreate($tmprmv) IniWrite(@ScriptDir & "\aicon.ini", "Option", "ListViewMode", "0") IniWrite(@ScriptDir & "\aicon.ini", "Option", "InitialDir", "C:\ico2dlltemp") Global $PID2 = "" $last = "placeholder" $Amow = 100 $hWnd2 = "" $aPID = Run(@ScriptDir & "\aicon.exe") WinWaitActive("@icon sushi", "", 10) $theWinlist = WinList() Do For $i = 1 To $theWinlist[0][0] If $theWinlist[$i][0] <> "" Then $iPID2 = WinGetProcess($theWinlist[$i][1]) If $iPID2 = $aPID Then $hWnd2 = $theWinlist[$i][1] ExitLoop EndIf EndIf Next Until $hWnd2 <> 0 Sleep(1000) Send("{ALT}FO") WinWaitActive("Open Source File(s)", "", 10) Sleep(200) ControlClick("Open Source File(s)", "", 1) Sleep(200) Send("^a{ENTER}") Sleep(200) Do Sleep(200) If WinExists("@icon sushi", "is not a supported file") Then Sleep(200) Send("{ENTER}") EndIf $treeCtrl = ControlGetHandle($hWnd2, "", "[CLASS:TListView; INSTANCE:1]") ControlClick($hWnd2, "", $treeCtrl, "", "", 34, 29) $textCtrl = ControlGetHandle($hWnd2, "", "[CLASS:TPanel; INSTANCE:3]") Until ControlGetText($hWnd2, "", $textCtrl) <> "" Sleep(200) While 1 $textSrch = ControlGetText($hWnd2, "", $textCtrl) If $textSrch = $last Then ExitLoop If StringInStr($textSrch, "256 x 256") Then Send("{ALT}L") Sleep(30) Send("D") Sleep(30) Send("D{ENTER}") Else Send("{DOWN}") EndIf $last = $textSrch WEnd Sleep(200) Send("{ALT}LA") Sleep(200) Send("{ALT}TG") WinWaitActive("Browse for Folder", "", 10) $hnd = WinGetHandle("Browse for Folder") ControlClick($hnd, "", 14145) Sleep(100) Send("ico2dlltemp") Sleep(100) Send("{RIGHT}") Sleep(100) Send("{RIGHT}") Sleep(100) Send("{ENTER}") WinClose($hWnd2) WinWaitClose($hWnd2) EndFunc ;==>Rmv256 Func GenDll() If _GenerateRC() Then $SName = $Dll_File_Name FileInstall("./Tools/cvtres.exe", $TmpDir & "\", 1) FileInstall("./Tools/link.exe", $TmpDir & "\", 1) FileInstall("./Tools/mspdb50.dll", $TmpDir & "\", 1) FileInstall("./Tools/RC.exe", $TmpDir & "\", 1) FileInstall("./Tools/RCdll.dll", $TmpDir & "\", 1) $i = 1 $IdxCount = $vdata2[0] - 2 For $i = 0 To $IdxCount $RC_Res_FilePath = $vdata2[$i + 1] FileCopy($RC_Res_FilePath, $TmpDir & "\", 9) Next RunWait(@ComSpec & ' /c ' & 'rc /r ' & $SName & '.rc', $TmpDir, @SW_HIDE) RunWait(@ComSpec & ' /c ' & 'link /nodefaultlib /dll /machine:ix86 /noentry /out:' & _ $SName & '.dll ' & $SName & '.res', $TmpDir, @SW_HIDE) If FileExists($TmpDir & "\" & $SName & ".dll") Then FileCopy($TmpDir & "\" & $SName & ".dll", "C:\" & $SName & "-" & $rnd & ".dll", 1) MsgBox(0, "Success", "File created successfuly at:" & @CRLF & "C:\" & $SName & "-" & $rnd & ".dll") DirRemove($tmp) DirRemove($TmpDir) Exit Else MsgBox(16 + 8192, $lang[51], $lang[52] & @TAB) ; Error ; Error Creating Dll File Exit EndIf ;ShellExecute($TmpDir) EndIf EndFunc ;==>GenDll Func CopyTemp() $i = 1 For $i = 1 To $iData[0] - 1 $iData2 = StringReplace($iData[$i], @CR, "") FileCopy($iData2, $tmp & $i & ".ico", 9) If @error Then MsgBox(0, "Failed", "Unknown error. Sorry.") Exit EndIf Next EndFunc ;==>CopyTemp Func _CleanInput() _GUICtrlListView_SetItemSelected($Res_List, $ListViewIndexSel, False) $ListViewIndexSel = "" GUICtrlSetData($Res_Name, "") GUICtrlSetData($Res_Type, "ICON") GUICtrlSetData($Res_Path, "") EndFunc ;==>_CleanInput Func _PathLen($PathIn) If StringLen($PathIn) > $StrLenPath Then $StrLenPath = StringLen($PathIn) + 10 GUICtrlSendMsg($Res_List, $LVM_SETCOLUMNWIDTH, 2, $StrLenPath * 5) EndIf EndFunc ;==>_PathLen Func _UpdateVerNum() GUICtrlSetData($Dll_Ver1, StringFormat("%002s", GUICtrlRead($Dll_Ver1))) GUICtrlSetData($Dll_Ver2, StringFormat("%002s", GUICtrlRead($Dll_Ver2))) GUICtrlSetData($Dll_Ver3, StringFormat("%004s", GUICtrlRead($Dll_Ver3))) GUICtrlSetData($Dll_Ver4, StringFormat("%004s", GUICtrlRead($Dll_Ver4))) GUICtrlSetData($Dll_PVer1, StringFormat("%002s", GUICtrlRead($Dll_Ver1)) & "," & _ StringFormat("%002s", GUICtrlRead($Dll_Ver2)) & "," & _ StringFormat("%004s", GUICtrlRead($Dll_Ver3)) & "," & _ StringFormat("%004s", GUICtrlRead($Dll_Ver4))) EndFunc ;==>_UpdateVerNum Func _GenerateRC() $vdata2 = _FileListToArray($tmprmv) $i = 1 For $i = 1 To $vdata2[0] FileCopy($tmprmv & $vdata2[$i], $TmpDir & "\" & $i & ".ico", 9) Next $vdata2 = _FileListToArray($tmprmv) $IdxCount = $vdata2[0] $i = 1 If $IdxCount > 0 Then $RCFile = $TmpDir & "\" & $Dll_File_Name & ".rc" $hRCOut = FileOpen($RCFile, 1) If $hRCOut = -1 Then Return 0 $RC_Res_Type = "ICON" For $i = 1 To $IdxCount FileCopy($tmprmv & $vdata2[$i], $TmpDir & "\" & $i & ".ico", 9) $RC_Res_Name = $i $RC_Res_FilePath = $TmpDir & "\" & $i & ".ico" _PathSplit($RC_Res_FilePath, $szDrive, $szDir, $szFName, $szExt) $RC_Res_File = $szFName & $szExt FileWriteLine($RCFile, $RC_Res_Name & @TAB & $RC_Res_Type & @TAB & '"' & $RC_Res_File & '"') Next FileWriteLine($RCFile, @CRLF & '1 VERSIONINFO' & @CRLF & _ 'FILEVERSION ' & $Dll_PVer1 & @CRLF & _ 'PRODUCTVERSION ' & $Dll_PVer1 & @CRLF & _ 'FILEOS ' & $Dll_OS & @CRLF & _ 'FILETYPE ' & $Dll_File_Type & @CRLF & _ '{' & @CRLF & 'BLOCK "StringFileInfo"' & @CRLF & '{' & @CRLF & _ @TAB & 'BLOCK "' & $Bloc & '"' & @CRLF & @TAB & '{' & @CRLF & _ @TAB & @TAB & 'VALUE "CompanyName", "' & $Dll_Compagny & '"' & @CRLF & _ @TAB & @TAB & 'VALUE "FileDescription", "' & $Dll_File_Desc & '"' & @CRLF & _ @TAB & @TAB & 'VALUE "FileVersion", "' & $Dll_PVer1 & '"' & @CRLF & _ @TAB & @TAB & 'VALUE "InternalName", "' & $Dll_File_Name & '.dll"' & @CRLF & _ @TAB & @TAB & 'VALUE "LegalCopyright", "' & $Dll_Copyright & '"' & @CRLF & _ @TAB & @TAB & 'VALUE "OriginalFilename", "' & $Dll_File_Name & '.dll"' & @CRLF & _ @TAB & @TAB & 'VALUE "ProductName", "' & $Dll_Prod_Name & '"' & @CRLF & _ @TAB & @TAB & 'VALUE "ProductVersion", "' & $Dll_PVer1 & " " & $Dll_PVer2 & '"' & @CRLF & _ @TAB & @TAB & 'VALUE "Comments", ""' & @CRLF & _ @TAB & '}' & @CRLF & '}' & @CRLF & @CRLF & 'BLOCK "VarFileInfo"' & @CRLF & '{' & @CRLF & _ @TAB & 'VALUE "Translation", ' & $LangHex & @CRLF & '}' & @CRLF & '}') FileClose($hRCOut) Return 1 Else Return 0 EndIf EndFunc ;==>_GenerateRC Func On_WM_DROPFILES($hWnd, $iMsg, $wParam, $lParam) ; Credit to ProgAndy for DLL calls #forceref $hWnd, $iMsg, $lParam Local $iSize, $pFileName ; Get number of files dropped Local $aRet = DllCall("shell32.dll", "int", "DragQueryFileW", "hwnd", $wParam, "int", 0xFFFFFFFF, "ptr", 0, "int", 0) ; Reset array to correct size Global $aDrop_List[$aRet[0] + 1] = [$aRet[0]] ; And add item names For $i = 0 To $aRet[0] - 1 $aRet = DllCall("shell32.dll", "int", "DragQueryFileW", "hwnd", $wParam, "int", $i, "ptr", 0, "int", 0) $iSize = $aRet[0] + 1 $pFileName = DllStructCreate("wchar[" & $iSize & "]") DllCall("shell32.dll", "int", "DragQueryFileW", "hwnd", $wParam, "int", $i, "ptr", DllStructGetPtr($pFileName), "int", $iSize) $aDrop_List[$i + 1] = DllStructGetData($pFileName, 1) $pFileName = 0 Next ; Send the count to trigger the drop function in the main loop GUICtrlSendToDummy($dBox, $aDrop_List[0]) EndFunc ;==>On_WM_DROPFILES Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) ;#forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo $hWndListView = $Res_List If Not IsHWnd($Res_List) Then $hWndListView = GUICtrlGetHandle($Res_List) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $NM_DBLCLK ; Sent by a list-view control when the user double-clicks an item with the left mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam) $ListViewIndexSel = DllStructGetData($tInfo, "Index") GUICtrlSetData($Res_Name, _GUICtrlListView_GetItemText($hWndListView, $ListViewIndexSel, 0)) GUICtrlSetData($Res_Type, _GUICtrlListView_GetItemText($hWndListView, $ListViewIndexSel, 1)) GUICtrlSetData($Res_Path, _GUICtrlListView_GetItemText($hWndListView, $ListViewIndexSel, 2)) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func SetDllData() Switch GUICtrlRead($Dll_Lang) Case 'French' Or 'Francais' $Bloc = '040C04B0' $LangHex = '0x040C 0x04B0' Case Else ; 'English' Or 'Anglais' $Bloc = '040904B0' $LangHex = '0x0409 0x04B0' EndSwitch $Dll_File_Name = StringReplace(GUICtrlRead($Dll_File_Name), " ", "_") $Dll_PVer1 = GUICtrlRead($Dll_PVer1) $Dll_PVer2 = GUICtrlRead($Dll_PVer2) $Dll_OS = GUICtrlRead($Dll_OS) $Dll_File_Type = GUICtrlRead($Dll_File_Type) $Dll_Compagny = GUICtrlRead($Dll_Compagny) $Dll_File_Desc = GUICtrlRead($Dll_File_Desc) $Dll_Copyright = GUICtrlRead($Dll_Copyright) $Dll_Prod_Name = GUICtrlRead($Dll_Prod_Name) EndFunc ;==>SetDllData ; Function to select language. Func _SelectLanguage() If StringInStr("040c,080c,0c0c,100c,140c,180c", @OSLang) Then RDG_FR() ; French Language Else RDG_EN() ; English Language EndIf $Lang = StringSplit($Lang, $SP, 1) EndFunc ; English Language. Func RDG_EN() $Lang = "Resource DLL Generator" & $SP $Lang &= "Resource Name" & $SP $Lang &= "Type Name Without Space (Max len 10)" & $SP $Lang &= "Resource Type" & $SP $Lang &= "Choose Resource Type" & $SP $Lang &= "Resource Path" & $SP $Lang &= "Select File First" & $SP $Lang &= "Path Of The Resource File" & $SP $Lang &= "Select Path Of The Resource File First" & $SP $Lang &= "Delete Resource" & $SP $Lang &= "Delete Selected Resource" & $SP $Lang &= "Add Resource" & $SP $Lang &= "Add or Update Resource" & $SP $Lang &= " Name | Type | Path " & $SP $Lang &= "Clic Twice To Edit An Item" & $SP $Lang &= "Exit" & $SP $Lang &= "Exit Program" & $SP $Lang &= "Dll Informations" & $SP $Lang &= "Chose Dll Informations" & $SP $Lang &= "Generate Dll" & $SP $Lang &= "Generate The Dll" & $SP $Lang &= "DLL Info" & $SP $Lang &= "DLL Informations" & $SP $Lang &= "Dll Filename" & $SP $Lang &= "MyDll" & $SP $Lang &= "File Version" & $SP $Lang &= "Product Version" & $SP $Lang &= "Product Name" & $SP $Lang &= "Name_Of_Your_Product" & $SP $Lang &= "Compagny Name" & $SP $Lang &= "Type_Your_Compagny" & $SP $Lang &= "Legal Copyright" & $SP $Lang &= "Copyright_(C)_2007-2008" & $SP $Lang &= "File Description" & $SP $Lang &= "Type_Your_Description" & $SP $Lang &= "Language" & $SP $Lang &= "English|French" & $SP $Lang &= "English" & $SP $Lang &= "File OS" & $SP $Lang &= "0x40004" & $SP $Lang &= "0x40004" & $SP $Lang &= "File Type" & $SP $Lang &= "0x2" & $SP $Lang &= "0x2" & $SP $Lang &= "OK" & $SP $Lang &= "Select file to add In DLL" & $SP $Lang &= "All" & $SP $Lang &= "Select The Destination Of Dll File" & $SP $Lang &= "Succes" & $SP $Lang &= "Dll successfully saved on" & $SP $Lang &= "Error" & $SP $Lang &= "Error Creating Dll File" & $SP $Lang &= "Dll File Name" & $SP $Lang &= "Please, Enter The Name Of Your Dll" EndFunc ; French Language. Func RDG_FR() $Lang = "Ressource DLL Generator" & $SP $Lang &= "Nom de la ressource" & $SP $Lang &= "Tapez le nom sans espace (Max 10 caractères)" & $SP $Lang &= "Type de la ressource" & $SP $Lang &= "Choisissez un type de ressource" & $SP $Lang &= "Chemin de la ressource" & $SP $Lang &= "Choisir d'abord le fichier de ressource" & $SP $Lang &= "Chemin du fichier de ressource" & $SP $Lang &= "Sélectionnez le fichier de ressource" & $SP $Lang &= "Supprime ressource" & $SP $Lang &= "Supprime la ressource sélectionnée." & $SP $Lang &= "Ajoute ressource" & $SP $Lang &= "Ajoute ou met à jour la ressource." & $SP $Lang &= " Nom | Type | Chemin " & $SP $Lang &= "Cliquez deux fois pour éditer une ressource." & $SP $Lang &= "Sortie" & $SP $Lang &= "Sortie du programme." & $SP $Lang &= "Informations Dll" & $SP $Lang &= "Règlez les information de la Dll." & $SP $Lang &= "Générer la Dll" & $SP $Lang &= "Générez la Dll" & $SP $Lang &= "Info DLL" & $SP $Lang &= "Informations DLL" & $SP $Lang &= "Nom de la Dll" & $SP $Lang &= "MaDll" & $SP $Lang &= "Version du fichier" & $SP $Lang &= "Version du produit" & $SP $Lang &= "Nom du produit" & $SP $Lang &= "Nom_de_votre_produit" & $SP $Lang &= "Nom de la société" & $SP $Lang &= "Nom_de_votre_société" & $SP $Lang &= "Copyright légale" & $SP $Lang &= "Copyright_(C)_2007-2008" & $SP $Lang &= "Description du fichier" & $SP $Lang &= "Entrez_votre_description" & $SP $Lang &= "Langue" & $SP $Lang &= "Anglais|Français" & $SP $Lang &= "Français" & $SP $Lang &= "Système de fichiers" & $SP $Lang &= "0x40004" & $SP $Lang &= "0x40004" & $SP $Lang &= "Type de fichiers" & $SP $Lang &= "0x2" & $SP $Lang &= "0x2" & $SP $Lang &= "OK" & $SP $Lang &= "Sélectionnez le fichier à ajouter à la DLL" & $SP $Lang &= "Tout Fichier" & $SP $Lang &= "Sélectionnez la destination de la Dll" & $SP $Lang &= "Succés" & $SP $Lang &= "Dll sauvegardée avec succés sur" & $SP $Lang &= "Erreur" & $SP $Lang &= "Erreur lors de la création de la Dll" & $SP $Lang &= "Nom du fichier Dll" & $SP $Lang &= "Veuillez entrer le nom de la Dll" EndFunc ico2dll.Exe1 point -
Computer Plucker is a fork and a "restoration" of Computer stats utility by @Rogue5099 (link) You can obtain various data about local machine, as from the screenshot. But my goal is not (only) to provide another PC stats tool, but to develop a very basic remote inventory tool, like (a small subset of) the abandoned Spiceworks or the Microsoft SCCM. So this script can be deployed on a machine as a standalone executable (yes you need only ONE file to distribute) , and launching the .EXE it installs itself to a folder (es. c:\autoit\computerplucker) In tools menù you can set two tasks and not only one for creating every week a file.ini with all the data of the machine. another one for creating every week a file.ini with all the data of the machine PLUS uploading a CRYPTED record of the machine in a free mysql DB online For my needs, I am deploying the .exe and schedule the second task, uploading data one time a week. In tools menù you will find also commands for: manual creating the .ini data file to upload the data in crypted records to upload the data in clear text records (for testing..) total uninstall of ComputerPlucker, with a simple security code. many other tasks in not so logical order.. next version I have to tidy the menù... So my plan is to deploy this on my machines, and have the data in a online DB, this DB will be for me only a "cache" for data records to be downloaded (and deleted) by another script. As today the account of this TEST DB is embedded in code, using the "File to Base64 String' Code Generator" by @UEZ (used also for embedding icons and XML task definitions) Local $mysqlhost = "sql11.freemysqlhosting.net" Local $mysqlport = "3306" Local $mysqldb = "sql11403701" Local $mysqluser = "sql11403701" Local $mysqlpsw = "QtL7T9U5GV" The DB is one table of 30 mysql tinytext fields... very simple indeed... You can try to upload data to this DB and access (phpmyadmin or a random mysql browser app) to see the results. Or you can use my ComputerPluckerDBbrowser (see at the end of this post) a script to collect and manage the data. PRIVACY warning: you are uploading data of your PC account and PC data, test as your risk (or test in another account...) I also created a small post in a blog for not so geek friends, and I have a more advanced version of the data browser, you can have more info lookin' here. 😀 Attached you will find the code, and all the necessary includes are at this >link<. ComputerPlucker.EXE is downloadable >HERE< ComputerPluckerDBbrowser.EXE is downloadable >HERE< ComputerPluckerDBbrowser_LITE.au3 ComputerPlucker.au31 point
-
Hotkeys with Timers In Them
argumentum reacted to Xilibre for a topic
Right on, man. Thanks. That's obviously more advanced then the route I thought it would be. Seemed like a smaller project, lol. I'm going to do some reading on this and will touch back.1 point -
Making a Check Box Update A Label
FrancescoDiMuro reacted to TheXman for a topic
Since you haven't read the PM I sent you yet, I will put the gist of it here. The 3 reasons why I ignored you: If someone volunteers their time and expertise to help you, the first thing you should do is show some semblance of appreciation -- especially if you want (or might want) further assistance. Something as simple as thanks will usually suffice. Not doing so, will get you ignored. My name on this forum is TheXman, not "dude". Referring to me as "dude", "bro", "homie", or anything else other than my name, will most likely get you ignored. Since you never know who you are speaking with, it is always better to err on the side of being too formal than too casual. If I can help it, I no longer shoot at moving targets. So I don't play that "But another thing came up" or "one more thing" game. Usually that's just a lazy person's way to try to get others to write their script for them piece-by-piece, step-by-step. Or, it's a sign that the person hasn't fully thought out what it is they want and is trying to do it on the fly. Either way. I'm not going to allow you to waste my time. There are plenty of people on the forum that'll write your scripts for you or play that game, but I'm not one of them. I'm only interested in helping people learn how to help themselves, not to do it for them. If you have a larger goal in mind, then explain what you are trying to accomplish in detail, show what you've tried, and ask for help with whatever is giving you problems. Then, take the time to learn from the advice you are given and continue making progress towards you goal. If you hit another obstacle, then repeat the previous process until you reach your goal. You probably could also benefit by reading the 2 links in my signature that refer to how to get better answers to your technical questions.1 point -
@AnnoyingClown I see what you mean about geckodriver not working. I'm sure there's a workaround. Easiest would be to put the text on the clipboard and then send a Ctrl+V to the element. Another option would be to update the element's value with multiple requests, one for each line. There may be a better option, but it will take some time to investigate.1 point
-
The issue is in line 3914 GUICtrlCreatePic("C:\autoit\ComputerPlucker\NSC_fs_red.jpg", $iCtrls_Left + 10, 145, $iCtrls_Width - 20, 130) ; NSC added This should fix it: GUICtrlCreatePic(@ScriptDir & "\NSC_fs_red.jpg", $iCtrls_Left + 10, 145, $iCtrls_Width - 20, 130) ; NSC added 😉 Btw, very nice GUI design. 👍1 point
-
Hotkeys with Timers In Them
Xilibre reacted to argumentum for a topic
#include <WinAPISys.au3> ; for _WinAPI_Keybd_Event(), _WinAPI_GetKeyState() #include <WinAPIvkeysConstants.au3> ; for $VK_* #Region examples for Shortcut Guide ; https://docs.microsoft.com/en-us/windows/powertoys/ _Send_VirtualKey($VK_LWIN, Default, 2000) ; VK_LWIN ; press, hold 2000 ms., release key Sleep(1000) #EndRegion examples for Shortcut Guide ; https://docs.microsoft.com/en-us/windows/powertoys/ _Send_VirtualKey($VK_LWIN, 1) ; VK_LWIN ; key down ; Left Windows key (Natural keyboard) _Send_VirtualKey($VK_1) ; 1 key ; send key 1 ; run first icon in the Taskbar _Send_VirtualKey($VK_LWIN, 2) ; VK_LWIN ; key up ; Left Windows key (Natural keyboard) Sleep(1000) _Send_VirtualKey($VK_LWIN) ; VK_LWIN ; load Start menu ; Left Windows key (Natural keyboard) Sleep(1000) SetNumLock() ; look at the keyboard light ToolTip("") Func _Send_VirtualKey($iVkey, $bPressDownUp = Default, $iSleep = Default) ; $iSleep in ms. If Not IsInt($iVkey) Then Return ; https://www.autoitscript.com/forum/index.php?showtopic=205790&view=findpost&p=1481401 $bPressDownUp = Int($bPressDownUp) ; https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes Switch $bPressDownUp ; Case 1, 2, 3 ; all good ; 1=down ; 2=up ; 3=1+2 Case Else $bPressDownUp = BitOR(1, 2) EndSwitch $iSleep = Int($iSleep) ; Default = 0 If BitAND($bPressDownUp, 1) Then _WinAPI_Keybd_Event($iVkey, 0) If $iSleep Then Sleep($iSleep) If BitAND($bPressDownUp, 2) Then _WinAPI_Keybd_Event($iVkey, $KEYEVENTF_KEYUP) EndFunc ;==>_Send_VirtualKey Func SetNumLock($bState = Default) ; $bState: True=ON , False=OFF, Default=toggle If $bState <> Default Then ; example from https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-keybd_event Local $iKeyState = _WinAPI_GetKeyState($VK_NUMLOCK) ; 0 or 1 ; false or true If Int($bState) = $iKeyState Then Return SetError(0, $iKeyState, 1) EndIf _WinAPI_Keybd_Event($VK_NUMLOCK, $KEYEVENTF_EXTENDEDKEY) _WinAPI_Keybd_Event($VK_NUMLOCK, $KEYEVENTF_EXTENDEDKEY + $KEYEVENTF_KEYUP) EndFunc ;==>SetNumLock so, ..... friendly AND gave you the right path in your quest. The rest you'll have to research on your own1 point -
This is slightly different to how _Singleton() (Misc.au3) works by Valik, because firstly this function uses the hidden window of an AutoIt executable and secondly it returns the PID of the main executable, not the handle to the object used for synchronization. It should also be noted that $iFlag parameter 2 doesn't exist in this function and if no program exists already _SingletonPID() returns 0. Any suggestions are welcome. Thanks. Function: #include <StringConstants.au3> ; #FUNCTION# ==================================================================================================================== ; Name ..........: _SingletonPID ; Description ...: Enforce a design paradigm where only one instance of the script may be running. ; Syntax ........: _SingletonPID($sOccurenceName[, $iFlag = 0]) ; Parameters ....: $sOccurenceName - String to identify the occurrence of the script. ; $iFlag - [optional] Optional parameters (see below). Default is 0. ; 0 - Exit the script with the exit code -1 if another instance already exists. ; 1 - Return the PID of the initial executable. ; Return values .: Success - 0 (no additional instances exist). ; Failure - The PID of the initial instance. ; Author ........: guinness with initial ideas by Valik for _Singleton() & KaFu for _EnforceSingleInstance(). ; Example .......: Yes ; =============================================================================================================================== Func _SingletonPID($sOccurenceName, $iFlag = 0) Local $hAutoItWnd = WinGetHandle($sOccurenceName) If @error Then Local Const $sUniqName = @AutoItPID & '__' & $sOccurenceName & '__' & @AutoItPID AutoItWinSetTitle($sUniqName) $hAutoItWnd = WinGetHandle($sUniqName) AutoItWinSetTitle($sOccurenceName) ; Append the current AutoIt PID placeholder to the edit control Local Const $hControl = ControlGetHandle($hAutoItWnd, '', 'Edit1') ControlSetText($hAutoItWnd, '', $hControl, ControlGetText($hAutoItWnd, '', $hControl) & @CRLF & _ '|AUTOIT_SINGLETON_PID:' & @AutoItPID & @CRLF) Return 0 EndIf If $iFlag = Default Or $iFlag = 0 Then Exit -1 EndIf ; Get the edit control text and append a default AutoIt PID placeholder, in case it doesn't exist Local Const $sCtrlText = ControlGetText($hAutoItWnd, '', ControlGetHandle($hAutoItWnd, '', 'Edit1')) & @CRLF & _ '|AUTOIT_SINGLETON_PID:0' & @CRLF ; Get the first match and parse as an integer Return Int(StringRegExp($sCtrlText, _ '\|AUTOIT_SINGLETON_PID:(\d+)\R', $STR_REGEXPARRAYMATCH)[0]) EndFunc ;==>_SingletonPID Example 1: #include <MsgBoxConstants.au3> Example() Func Example() If @Compiled Then Local $iSingleton = _SingletonPID('myUniqueName', 1) If Not $iSingleton Then MsgBox($MB_SYSTEMMODAL, 'PID: ' & @AutoItPID, 'This is the first instance of the program running: ' & $iSingleton) Else MsgBox($MB_SYSTEMMODAL, 'PID: ' & @AutoItPID, 'There is another instance running. This PID is: ' & $iSingleton) EndIf Else MsgBox($MB_SYSTEMMODAL, 'PID: ' & @AutoItPID, 'Please compile the code and run the executable twice to see the two different messages.') EndIf EndFunc ;==>Example Example 2: #include <MsgBoxConstants.au3> Example() Func Example() If @Compiled Then Local $iSingleton = _SingletonPID('myUniqueName', 1) If Not $iSingleton Then MsgBox($MB_SYSTEMMODAL, 'PID: ' & @AutoItPID, 'This is the first instance of the program running: ' & $iSingleton) Else MsgBox($MB_SYSTEMMODAL, 'PID: ' & @AutoItPID, 'There is another instance running. This PID is: ' & $iSingleton) ; Wait for the process to close. ProcessWaitClose($iSingleton, 5) ; Reset _SingletonPID() to the current process since the previous one was closed. $iSingleton = _SingletonPID('myUniqueName', 1) MsgBox($MB_SYSTEMMODAL, 'PID: ' & @AutoItPID, 'This is now the first instance of the program running: ' & $iSingleton) EndIf Else MsgBox($MB_SYSTEMMODAL, 'PID: ' & @AutoItPID, 'Please compile the code and run the executable twice to see the two different messages.') EndIf EndFunc ;==>Example1 point
-
^^Because first you run x86 and then compile and run x64. The problem is not with this function. AutoIt has "issue" converting string number to number number. Run this on x64: $blah = DllStructCreate("byte[" & 2147483647 + 2 & "]") ConsoleWrite(DllStructGetSize($blah) & @CRLF) ; it should print 2147483649 if your system configuration supports allocating that much1 point
-
Replace the _IsFullPath() function in ZIP.au3 with this one Func _IsFullPath($sPath) If StringRegExp($sPath, '^([a-zA-Z]\:|\\\\[^\/\\:*?"<>|]+\\[^\/\\:*?"<>|]+)(\\[^\/\\:*?"<>|]+)+$') Then Return True Else Return False EndIf EndFunc ;==>_IsFullPath1 point