Skip to content

Commit

Permalink
++
Browse files Browse the repository at this point in the history
  • Loading branch information
Ixiko committed Oct 29, 2022
1 parent 5a0fc9f commit de32297
Show file tree
Hide file tree
Showing 173 changed files with 82,596 additions and 1,476 deletions.
2 changes: 1 addition & 1 deletion AHK_V2/Audio.ahk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/************************************************************************
/************************************************************************
* @file: Audio.ahk
* @description: Core Audio APIs, Windows 多媒体设备API
* @author thqby
Expand Down
2 changes: 1 addition & 1 deletion AHK_V2/Base64.ahk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Class Base64 {
Class Base64 {
/**
* Base64编码
* @param Buf Buffer Object has Ptr, Size Property. May contain any binary contents including NUll bytes.
Expand Down
39 changes: 39 additions & 0 deletions AHK_V2/ConfOverride.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
; ----------------------------------------------------------------------------------------------------------------------
; Function .....: ConfOverride
; Description ..: Override a configuration object with data read from an ini configuration file.
; ..............: The configuration object needs to contain separate section objects with key:value pairs. Eg:
; ..............: CONF := {}, CONF.SCRIPT := { a:"value", b:"value" }, CONF.SETTINGS := { c:"value" } and so on...
; ..............: Use the pair __LOCKED:1 to avoid a section being overridden.
; Parameters ...: oConf - Configuration object to be passed byref.
; ..............: sFile - Path to the ini file.
; Return .......: 0 - Error.
; ..............: 1 - Object updated.
; ..............: 2 - Object not updated.
; AHK Version ..: AHK v2 x32/64 Unicode
; Author .......: cyruz - http://ciroprincipe.info
; License ......: WTFPL - http://www.wtfpl.net/txt/copying/
; Changelog ....: Oct. 04, 2022 - v0.1.0 - First version.
; ----------------------------------------------------------------------------------------------------------------------

ConfOverride(&oConf, sFile)
{
If !FileExist(sFile)
Return 0

sIniFile := IniRead(sFile)
Loop Parse, sIniFile, "`n"
{
If oConf.HasOwnProp(A_LoopField)
{
If oConf.%A_LoopField%.HasOwnProp("__LOCKED")
&& oConf.%A_LoopField%.__LOCKED
Continue
sSectionName := A_LoopField
sSectionContent := IniRead(sFile, sSectionName)
Loop Parse, sSectionContent, "`n"
If RegExMatch(A_LoopField, "S)^\s*(\w+)\s*\=\s*(.*)\s*$", &oMatch)
oConf.%sSectionName%.%oMatch.1% := oMatch.2, bUpdated := 1
}
}
Return bUpdated ? 1 : 2
}
34 changes: 34 additions & 0 deletions AHK_V2/CreateDirectoryMap.ahk2
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
CreateDirectoryMap(fso, path){ ; Returns data for all folders & files found (name, path, date created, date last modified, parent folder name, contents within (files/folders)

dir := fso.GetFolder(path) ; Get contents of specified directory

; Create array if subfolders/files exist, else make empty string
(folders := dir.SubFolders) ? folderData := [] : folderData := ""
(files := dir.Files ) ? fileData := [] : fileData := ""

; if subfolders exist, push map of folder data into array
if (IsObject(folderData))
for folder in folders
folderData.Push( Map("Name", folder.Name,
"Path", folder.Path,
"Created", folder.DateCreated,
"Modified", folder.DateLastModified,
"Parent", folder.ParentFolder.Name,
"Contents", CreateDirectoryMap(fso, folder.Path)) ) ; Recurse through all folders found below specified directory

; if files exist, push map of file data into array
if (IsObject(fileData))
for file in files
fileData.Push( Map("Name", file.Name,
"Path", file.Path,
"Created", file.DateCreated,
"Modified", file.DateLastModified,
"Parent", file.ParentFolder.Name) )

return Map("Name", dir.Name, ; string
"Path", path, ; string
"Created", dir.DateCreated, ; string
"Modified", dir.DateLastModified, ; string
"Parent", dir.ParentFolder.Name, ; string
"Contents", Map("Folders", folderData, "Files", fileData)) ; Map with Array of nested Map objects
}
2 changes: 1 addition & 1 deletion AHK_V2/EnableUIAccess.ahk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
EnableUIAccess(ExePath) {
EnableUIAccess(ExePath) {
static CertName := "AutoHotkey"
hStore := DllCall("Crypt32\CertOpenStore", "ptr", 10 ; STORE_PROV_SYSTEM_W
, "uint", 0, "ptr", 0, "uint", 0x20000 ; SYSTEM_STORE_LOCAL_MACHINE
Expand Down
2 changes: 1 addition & 1 deletion AHK_V2/FormatMessage.ahk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FormatMessage(err, module := 0) {
FormatMessage(err, module := 0) {
flags := 0x100 | (module ? 0x800 : 0x1000)
DllCall("FormatMessage", "uint", flags, "ptr", module, "uint", err, "uint", 0, "ptr*", &pstr := 0, "uint", 0, "ptr", 0)
if (pstr) {
Expand Down
63 changes: 63 additions & 0 deletions AHK_V2/GetDefaultIcon.ah2
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#Requires Autohotkey v2.0-beta.7
/**
* Function: GetDefaultIcon(fExt [, getHandle])
* https://docs.microsoft.com/en-us/windows/win32/api/shlwapi/nf-shlwapi-assocquerystringw
*
* Based on a specific use case of the AssocQueryString function.
*
* Searches for and retrieves the default icon for a provided extension and returns
* a handle to the icon to be used in a picture control or the string to the associated icon path.
*
* Params:
* fExt - File extension to work on with optional `.` in front e.g.: ahk or .ahk
* getHandle - instruct the function to either return the handle to a resource or
* the string to the default executable file
*
* Returns:
* - A Handle to an icon resource (Default)
* - A string to the default executable and icon number for the extension
*
* Examples:
* ---ahk
MsgBox GetDefaultIcon("ahk")
MsgBox GetDefaultIcon(".ahk")
* ---
*
* ---ahk
for ext in ["ahk", ".html", ".bat", "vbs", ".dll"]
strings .= GetDefaultIcon(ext, false) '`n'

MsgBox strings
* ---
*/ ; by RaptorX

GetDefaultIcon(fExt, getHandle:=true) {
static ASSOCSTR_DEFAULTICON := 15

fExt := RegExReplace(fExt, "^\.?(.*)$", ".$1")

DllCall "shlwapi.dll\AssocQueryString",
"int", false, ; [in] ASSOCF flags,
"int", ASSOCSTR_DEFAULTICON, ; [in] ASSOCSTR str,
"str", fExt, ; [in] LPCSTR pszAssoc,
"int", false, ; [in, optional] LPCSTR pszExtra,
"ptr", StrOut:=Buffer(65000), ; [out, optional] LPSTR pszOut,
"ptr*", &length:=StrOut.size // 2, ; [in, out] DWORD *pcchOut
"HRESULT"

try
{
app := StrSplit(assocStr:=StrGet(StrOut), ",")
regKey := "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\." fExt "\UserChoice"

if (!hIcon := LoadPicture(app[1], "Icon" app.Has(2) ? app[2] : "", &imgType))
&& (progID := RegRead(regKey,"progID", false))
&& (icon := RegRead("HKCR\" progID "\DefaultIcon"))
{
RegExMatch(icon, "(?<app>.*?),?(?<index>\d+)?$", &matched)
hIcon := LoadPicture(matched.app, "Icon" matched.index, &imgType)
}
}

return getHandle ? (hIcon?? LoadPicture("C:\Windows\system32\shell32.dll", "Icon291", &imgType)) : assocStr
}
2 changes: 1 addition & 1 deletion AHK_V2/SevenZip.ahk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Class SevenZip {
Class SevenZip {
static SevenZipError := Map(32773, "ERROR_DISK_SPACE", 32774, "ERROR_READ_ONLY", 32775, "ERROR_USER_SKIP", 32776, "ERROR_UNKNOWN_TYPE", 32777, "ERROR_METHOD", 32778, "ERROR_PASSWORD_FILE", 32779, "ERROR_VERSION", 32780, "ERROR_FILE_CRC", 32781, "ERROR_FILE_OPEN", 32782, "ERROR_MORE_FRESH", 32783, "ERROR_NOT_EXIST", 32784, "ERROR_ALREADY_EXIST", 32785, "ERROR_TOO_MANY_FILES", 32786, "ERROR_MAKEDIRECTORY", 32787, "ERROR_CANNOT_WRITE", 32788, "ERROR_HUFFMAN_CODE", 32789, "ERROR_COMMENT_HEADER", 32790, "ERROR_HEADER_CRC", 32791, "ERROR_HEADER_BROKEN", 32792, "ERROR_ARC_FILE_OPEN", 32793, "ERROR_NOT_ARC_FILE", 32794, "ERROR_CANNOT_READ", 32795, "ERROR_FILE_STYLE", 32796, "ERROR_COMMAND_NAME", 32797, "ERROR_MORE_HEAP_MEMORY", 32798, "ERROR_ENOUGH_MEMORY", 32799, "ERROR_ALREADY_RUNNING", 32800, "ERROR_USER_CANCEL", 32801, "ERROR_HARC_ISNOT_OPENED", 32802, "ERROR_NOT_SEARCH_MODE", 32803, "ERROR_NOT_SUPPORT", 32804, "ERROR_TIME_STAMP", 32805, "ERROR_TMP_OPEN", 32806, "ERROR_LONG_FILE_NAME", 32807, "ERROR_ARC_READ_ONLY", 32808, "ERROR_SAME_NAME_FILE", 32809, "ERROR_NOT_FIND_ARC_FILE", 32810, "ERROR_RESPONSE_READ", 32811, "ERROR_NOT_FILENAME", 32812, "ERROR_TMP_COPY", 32813, "ERROR_EOF", 32814, "ERROR_ADD_TO_LARC", 32815, "ERROR_TMP_BACK_SPACE", 32816, "ERROR_SHARING", 32817, "ERROR_NOT_FIND_FILE", 32818, "ERROR_LOG_FILE", 32819, "ERROR_NO_DEVICE", 32820, "ERROR_GET_ATTRIBUTES", 32821, "ERROR_SET_ATTRIBUTES", 32822, "ERROR_GET_INFORMATION", 32823, "ERROR_GET_POINT", 32824, "ERROR_SET_POINT", 32825, "ERROR_CONVERT_TIME", 32826, "ERROR_GET_TIME", 32827, "ERROR_SET_TIME", 32828, "ERROR_CLOSE_FILE", 32829, "ERROR_HEAP_MEMORY", 32830, "ERROR_HANDLE", 32831, "ERROR_TIME_STAMP_RANGE", 32832, "ERROR_MAKE_ARCHIVE", 32833, "ERROR_NOT_CONFIRM_NAME", 32834, "ERROR_UNEXPECTED_EOF", 32835, "ERROR_INVALID_END_MARK", 32836, "ERROR_INVOLVED_LZH", 32837, "ERROR_NO_END_MARK", 32838, "ERROR_HDR_INVALID_SIZE", 32839, "ERROR_UNKNOWN_LEVEL", 32840, "ERROR_BROKEN_DATA", 32841, "ERROR_INVALID_PATH", 32842, "ERROR_TOO_BIG", 32843, "ERROR_EXECUTABLE_FILE", 32844, "ERROR_INVALID_VALUE", 32845, "ERROR_HDR_EXPLOIT", 32846, "ERROR_HDR_NO_CRC", 32847, "ERROR_HDR_NO_NAME")
, SevenZipError.Default := "ERROR_UNKNOWN_ERROR"
__New(hwnd := 0, dllpath := "") {
Expand Down
96 changes: 96 additions & 0 deletions AHK_V2/StdoutToVar.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
; ----------------------------------------------------------------------------------------------------------------------
; Function .....: StdoutToVar
; Description ..: Runs a command line program and returns its output.
; Parameters ...: sCmd - Commandline to be executed.
; ..............: sDir - Working directory.
; ..............: sEnc - Encoding used by the target process. Look at StrGet() for possible values.
; Return .......: Command output as a string on success, empty string on error.
; AHK Version ..: AHK v2 x32/64 Unicode
; Author .......: Sean (http://goo.gl/o3VCO8), modified by nfl and by Cyruz
; License ......: WTFPL - http://www.wtfpl.net/txt/copying/
; Changelog ....: Feb. 20, 2007 - Sean version.
; ..............: Sep. 21, 2011 - nfl version.
; ..............: Nov. 27, 2013 - Cyruz version (code refactored and exit code).
; ..............: Mar. 09, 2014 - Removed input, doesn't seem reliable. Some code improvements.
; ..............: Mar. 16, 2014 - Added encoding parameter as pointed out by lexikos.
; ..............: Jun. 02, 2014 - Corrected exit code error.
; ..............: Nov. 02, 2016 - Fixed blocking behavior due to ReadFile thanks to PeekNamedpipe.
; ..............: Apr. 13, 2021 - Code restyling. Fixed deprecated DllCall types.
; ..............: Oct. 06, 2022 - AHK v2 version. Throw exceptions on failure.
; ----------------------------------------------------------------------------------------------------------------------
StdoutToVar(sCmd, sDir:="", sEnc:="CP0") {
If !DllCall( "CreatePipe"
, "PtrP" , &hStdOutRd:=0
, "PtrP" , &hStdOutWr:=0
, "Ptr" , 0
, "UInt" , 0 )
Throw("Error creating pipe.")
If !DllCall( "SetHandleInformation"
, "Ptr" , hStdOutWr
, "UInt" , 1
, "UInt" , 1 )
{
DllCall( "CloseHandle", "Ptr" , hStdOutWr )
DllCall( "CloseHandle", "Ptr" , hStdOutRd )
Throw("Error setting handle information.")
}

PI := Buffer(A_PtrSize == 4 ? 16 : 24, 0)
SI := Buffer(A_PtrSize == 4 ? 68 : 104, 0)
NumPut( "UInt", SI.Size, SI, 0 )
NumPut( "UInt", 0x100, SI, A_PtrSize == 4 ? 44 : 60 )
NumPut( "Ptr", hStdOutWr, SI, A_PtrSize == 4 ? 60 : 88 )
NumPut( "Ptr", hStdOutWr, SI, A_PtrSize == 4 ? 64 : 96 )

If !DllCall( "CreateProcess"
, "Ptr" , 0
, "Str" , sCmd
, "Ptr" , 0
, "Ptr" , 0
, "Int" , True
, "UInt" , 0x08000000
, "Ptr" , 0
, "Ptr" , sDir ? StrPtr(sDir) : 0
, "Ptr" , SI
, "Ptr" , PI )
{
DllCall( "CloseHandle", "Ptr" , hStdOutWr )
DllCall( "CloseHandle", "Ptr" , hStdOutRd )
Throw("Error creating process.")
}

; The write pipe must be closed before reading the stdout.
DllCall( "CloseHandle", "Ptr" , hStdOutWr )

; Before reading, we check if the pipe has been written to, so we avoid freezings.
nAvail := 0, nLen := 0
While DllCall( "PeekNamedPipe"
, "Ptr" , hStdOutRd
, "Ptr" , 0
, "UInt" , 0
, "Ptr" , 0
, "UIntP" , &nAvail
, "Ptr" , 0 ) != 0
{
; If the pipe buffer is empty, sleep and continue checking.
If !nAvail && DllCall( "Sleep", "UInt",100 )
Continue
cBuf := Buffer(nAvail+1)
DllCall( "ReadFile"
, "Ptr" , hStdOutRd
, "Ptr" , cBuf
, "UInt" , nAvail
, "PtrP" , &nLen
, "Ptr" , 0 )
sOutput .= StrGet(cBuf, nLen, sEnc)
}

DllCall( "GetExitCodeProcess"
, "Ptr" , NumGet(PI, 0, "Ptr")
, "UIntP" , &nExitCode:=0 )
DllCall( "CloseHandle", "Ptr" , NumGet(PI, 0, "Ptr") )
DllCall( "CloseHandle", "Ptr" , NumGet(PI, A_PtrSize, "Ptr") )
DllCall( "CloseHandle", "Ptr" , hStdOutRd )

Return { Output: sOutput, ExitCode: nExitCode }
}
2 changes: 1 addition & 1 deletion AHK_V2/WinAPI/Advapi32.ahk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AbortSystemShutdown(lpMachineName) => DllCall('Advapi32\AbortSystemShutdown', 'str', lpMachineName, 'int')
AbortSystemShutdown(lpMachineName) => DllCall('Advapi32\AbortSystemShutdown', 'str', lpMachineName, 'int')
AccessCheck(pSecurityDescriptor, ClientToken, DesiredAccess, GenericMapping, PrivilegeSet, PrivilegeSetLength, GrantedAccess, AccessStatus) => DllCall('Advapi32\AccessCheck', 'ptr', pSecurityDescriptor, 'ptr', ClientToken, 'uint', DesiredAccess, 'ptr', GenericMapping, 'ptr', PrivilegeSet, 'ptr', PrivilegeSetLength, 'ptr', GrantedAccess, 'ptr', AccessStatus, 'int')
AccessCheckAndAuditAlarm(SubsystemName, HandleId, ObjectTypeName, ObjectName, SecurityDescriptor, DesiredAccess, GenericMapping, ObjectCreation, GrantedAccess, AccessStatus, pfGenerateOnClose) => DllCall('Advapi32\AccessCheckAndAuditAlarm', 'str', SubsystemName, 'ptr', HandleId, 'str', ObjectTypeName, 'str', ObjectName, 'ptr', SecurityDescriptor, 'uint', DesiredAccess, 'ptr', GenericMapping, 'int', ObjectCreation, 'ptr', GrantedAccess, 'ptr', AccessStatus, 'ptr', pfGenerateOnClose, 'int')
AccessCheckByType(pSecurityDescriptor, PrincipalSelfSid, ClientToken, DesiredAccess, ObjectTypeList, ObjectTypeListLength, GenericMapping, PrivilegeSet, PrivilegeSetLength, GrantedAccess, AccessStatus) => DllCall('Advapi32\AccessCheckByType', 'ptr', pSecurityDescriptor, 'ptr', PrincipalSelfSid, 'ptr', ClientToken, 'uint', DesiredAccess, 'ptr', ObjectTypeList, 'uint', ObjectTypeListLength, 'ptr', GenericMapping, 'ptr', PrivilegeSet, 'ptr', PrivilegeSetLength, 'ptr', GrantedAccess, 'ptr', AccessStatus, 'int')
Expand Down
2 changes: 1 addition & 1 deletion AHK_V2/WinAPI/Crypt32.ahk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CertAddCRLContextToStore(hCertStore, pCrlContext, dwAddDisposition, ppStoreContext) => DllCall('Crypt32\CertAddCRLContextToStore', 'ptr', hCertStore, 'ptr', pCrlContext, 'uint', dwAddDisposition, 'ptr', ppStoreContext, 'int')
CertAddCRLContextToStore(hCertStore, pCrlContext, dwAddDisposition, ppStoreContext) => DllCall('Crypt32\CertAddCRLContextToStore', 'ptr', hCertStore, 'ptr', pCrlContext, 'uint', dwAddDisposition, 'ptr', ppStoreContext, 'int')
CertAddCRLLinkToStore(hCertStore, pCrlContext, dwAddDisposition, ppStoreContext) => DllCall('Crypt32\CertAddCRLLinkToStore', 'ptr', hCertStore, 'ptr', pCrlContext, 'uint', dwAddDisposition, 'ptr', ppStoreContext, 'int')
CertAddCTLContextToStore(hCertStore, pCtlContext, dwAddDisposition, ppStoreContext) => DllCall('Crypt32\CertAddCTLContextToStore', 'ptr', hCertStore, 'ptr', pCtlContext, 'uint', dwAddDisposition, 'ptr', ppStoreContext, 'int')
CertAddCTLLinkToStore(hCertStore, pCtlContext, dwAddDisposition, ppStoreContext) => DllCall('Crypt32\CertAddCTLLinkToStore', 'ptr', hCertStore, 'ptr', pCtlContext, 'uint', dwAddDisposition, 'ptr', ppStoreContext, 'int')
Expand Down
Loading

0 comments on commit de32297

Please sign in to comment.