Skip to content
Permalink
Browse files

Multiple Updates

• Replaced all millisecond functions with a different naming convention
• Made invertCaseStr independent
• Updated winInfo to return information, rather than display and out to the clipboard
• Added db class
  • Loading branch information...
Masonjar13 committed Aug 12, 2018
1 parent 3c2999e commit 6b85a87d502571ef9b527bab6f7ec57b3a347b9b
Showing with 158 additions and 4 deletions.
  1. +136 −0 Lib/db.ahk
  2. +3 −0 Lib/hToMs.ahk
  3. +1 −1 Lib/invertCaseStr.ahk
  4. +3 −0 Lib/mToMs.ahk
  5. +3 −0 Lib/msToH.ahk
  6. +3 −0 Lib/msToM.ahk
  7. +3 −0 Lib/msToS.ahk
  8. +3 −0 Lib/sToMs.ahk
  9. +3 −3 Lib/winInfo.ahk
@@ -0,0 +1,136 @@
class db {

; meta

__new(filePath:=""){
if(filePath)
this.setPath:=filePath
splitPath,% this.setPath,,sDir
if(!fileExist(sDir))
fileCreateDir,% sDir
this.file:=fileOpen(this.setPath,"rw -rwd","UTF-8")
return this
}

__delete(){
this.file.close()
}

; public

listKeys(){
keyList:=[]
this.file.seek(3,0)
while(!this.file.atEOF){
this.file.seek(dataLen,1)
varSetCapacity(keyStr,4,0)
offset:=this.file.pos
keyLen:=this.file.readUInt() ; read key len
dataLen:=this.file.readUInt() ; read data len
this.file.rawRead(keyStr,keyLen) ; read key
varSetCapacity(keyStr,-1)
if(keyStr)
keyList.push(keyStr)
}
return keyList
}

get(key){
varSetCapacity(dataStr,4,0)
offset:=this._findKey(key)
if(offset=-1)
return
this.file.seek(offset,0)
keyLen:=this.file.readUInt()
dataLen:=this.file.readUInt()
this.file.seek(keyLen,1)
this.file.rawRead(dataStr,dataLen)
this.b64d(nStr,dataStr)
return nStr
}

put(key,str,overwrite:=0){
if(this._findKey(key) != "-1"){ ; check for/replace existing entry
if(overwrite)
this.remove(key)
else
return -1
}
this.b64e(nStr,str)
this.file.seek(0,2)
this.file.writeUInt(strLen(key)*2) ; key len
this.file.writeUInt(strLen(nStr)*2) ; data len
this.file.rawWrite(key,strLen(key)*2) ; key
this.file.rawWrite(nStr,strLen(nStr)*2) ; data
}

remove(key){
tFile:=fileOpen(tFilePath:=a_temp . "\" . a_tickCount,"w -rwd","UTF-8")
this.file.seek(3,0)
tFile.seek(3,0)

while(!this.file.atEOF){
keyLen:=this.file.readUInt()
dataLen:=this.file.readUInt()

this.file.rawRead(keyStr,keyLen)
varSetCapacity(keyStr,-1)
varSetCapacity(dataLen,-1)

if(key=keyStr){
this.file.seek(dataLen,1)
continue
}
this.file.rawRead(dataStr,dataLen)
;tfile.rawWrite(keyLen . dataLen . keyStr . dataStr,keyLen + dataLen + 8)
tFile.writeUInt(keyLen)
tFile.writeUInt(dataLen)
tFile.rawWrite(keyStr,keyLen)
tFile.rawWrite(dataStr,dataLen)
}
tFile.seek(0)
tFile.close()
this.file.close()
fileMove,% tFilePath,% this.setPath,1
this.file:=fileOpen(this.setPath,"rw -rwd","UTF-8")
}

; private

_findKey(key){
this.file.seek(3,0)

while(!this.file.atEOF && key!=keyStr){
this.file.seek(dataLen,1)
offset:=this.file.pos
keyLen:=this.file.readUInt() ; read key len
dataLen:=this.file.readUInt() ; read data len
this.file.rawRead(keyStr,keyLen) ; read key
varSetCapacity(keyStr,-1)
}
return key=keyStr?offset:-1
}

; b64e, b64d by SKAN + modified by lifeweaver; strPutVar by lifeweaver; https://autohotkey.com/boards/viewtopic.php?p=49863#p49863
b64e(byRef outData,byRef inData ){
inDataLen:=this.strPutVar(inData,inData,"UTF-8") - 1
dllCall("Crypt32.dll\CryptBinaryToStringW","UInt",&inData,"UInt",inDataLen,"UInt",1,"UInt",0,"UIntP",tChars,"CDECL Int")
varSetCapacity(outData,req:=tChars * (a_isUnicode?2:1),0)
dllCall("Crypt32.dll\CryptBinaryToStringW","UInt",&inData,"UInt",inDataLen,"UInt",1,"Str",outData,"UIntP",req,"CDECL Int")
return tChars
}

b64d(byRef outData,byRef inData){
dllCall("Crypt32.dll\CryptStringToBinaryW","UInt",&inData,"UInt",strLen(inData),"UInt",1,"UInt",0,"UIntP",bytes,"Int",0,"Int",0,"CDECL Int")
varSetCapacity(outData,req:=bytes * (a_isUnicode?2:1),0)
dllCall("Crypt32.dll\CryptStringToBinaryW","UInt",&inData,"UInt",strLen(inData),"UInt",1,"Str",outData,"UIntP",req,"Int",0,"Int",0,"CDECL Int")
outData:=strGet(&outData,"cp0")
return bytes
}

strPutVar(string,byRef var,encoding){
varSetCapacity(var,strPut(string,encoding)
* ((encoding="utf-16"||encoding="cp1200")?2:1))
return strPut(string,&var,encoding)
}
}
@@ -0,0 +1,3 @@
hToMs(h){
return h*3.6e+6
}
@@ -1,5 +1,5 @@
invertCaseStr(str){
loop,parse,str
nStr.=invertCaseChr(a_loopField)
nStr.=asc(a_loopField)>96?chr(asc(a_loopField)-32):chr(asc(a_loopField)+32)
return nStr
}
@@ -0,0 +1,3 @@
mToMs(m){
return m*0.6e+5
}
@@ -0,0 +1,3 @@
msToH(ms){
return round(ms/3.6e+6,2)
}
@@ -0,0 +1,3 @@
msToM(ms){
return round(ms/0.6e+5,2)
}
@@ -0,0 +1,3 @@
msToS(ms){
return round(ms/0.1e+4,2)
}
@@ -0,0 +1,3 @@
sToMs(s){
return s*0.1e+4
}
@@ -1,10 +1,10 @@
winInfo(winName="A"){
winInfo(winName:="A"){
winGet,awp,processName,% winName
winGet,awpid,PID,% winName
winGetTitle,awn,ahk_pid %awpid%
winGetPos,awx,awy,aww,awh,ahk_pid %awpid%
winGetClass,awc,% winName
winGet,awhwnd,ID,% winName
winGet,awcl,controlList,% winName
clipboard:="Window Name: " awn "`nW/H: " aww "x" awh "`nX/Y: " awx "," awy "`nClass: " awc "`nProcess: " awp "`nPID: " awpid "`nControl List:`n" awcl
tool("Window Info saved to clipboard")
return:="Window Name: " . awn . "`nW/H: " . aww . "x" . awh . "`nX/Y: " . awx . "," . awy . "`nClass: " . awc . "`nProcess: " . awp . "`nPID: " . awpid . "`nHWND: " . awhwnd . "`nControl List:`n" . awcl
}

0 comments on commit 6b85a87

Please sign in to comment.
You can’t perform that action at this time.