Skip to content

Commit

Permalink
Merge pull request #9 from martinsmith1968/feature/saved-window-posit…
Browse files Browse the repository at this point in the history
…ion-history

Feature/saved window position history
  • Loading branch information
martinsmith1968 authored Jan 16, 2020
2 parents 9fc103c + a8a21dd commit 6dcb9b5
Show file tree
Hide file tree
Showing 18 changed files with 838 additions and 62 deletions.
4 changes: 4 additions & 0 deletions Docs/releasenotes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes

## v1.6.5 - 2020-01-15

- Support History of Saved Window Positions

## v1.6.4 - 2020-01-08

- Added command line build command for setup exe
Expand Down
1 change: 0 additions & 1 deletion Docs/todo.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# To Do

- Support History of Saved Window Positions
- Support History of Saved Desktop Icon Positions
- Add icons to other context menu items

Expand Down
14 changes: 12 additions & 2 deletions Lib/ArrayUtils.ahk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
;--------------------------------------------------------------------------------
; AutoSort - Sort array (from: https://autohotkey.com/boards/viewtopic.php?f=6&t=3790&p=20122)
AutoSort(Arr)
; SortArray - Sort array (from: https://autohotkey.com/boards/viewtopic.php?f=6&t=3790&p=20122)
SortArray(Arr)
{
t:=Object()

Expand All @@ -13,6 +13,16 @@ AutoSort(Arr)
return Arr
}

ReverseArray(arr)
{
newArr := []

for k, v in arr
newArr.Insert(1, v)

return newArr
}

;--------------------------------------------------------------------------------
; IndexOf - Find the index of an array item
IndexOf(array, item)
Expand Down
64 changes: 64 additions & 0 deletions Lib/HashingFunctions.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
; From : https://github.com/jNizM/AHK_Scripts/tree/master/src/hash_checksum

; ===============================================================================================================================
; Adler-32 is a checksum algorithm
; ===============================================================================================================================

Adler32(str)
{
a := 1, b := 0
loop, parse, str
b := Mod(b + (a := Mod(a + Asc(A_LoopField), 0xFFF1)), 0xFFF1)
return Format("{:#x}", (b << 16) | a)
}

; ===============================================================================================================================
; In cryptography, SHA-1 (Secure Hash Algorithm 1) is a cryptographic hash function
; ===============================================================================================================================

SHA1(string, case := 0)
{
static SHA_DIGEST_LENGTH := 20
hModule := DllCall("LoadLibrary", "Str", "advapi32.dll", "Ptr")
, VarSetCapacity(SHA_CTX, 136, 0), DllCall("advapi32\A_SHAInit", "Ptr", &SHA_CTX)
, DllCall("advapi32\A_SHAUpdate", "Ptr", &SHA_CTX, "AStr", string, "UInt", StrLen(string))
, DllCall("advapi32\A_SHAFinal", "Ptr", &SHA_CTX, "UInt", &SHA_CTX + 116)
loop % SHA_DIGEST_LENGTH
o .= Format("{:02" (case ? "X" : "x") "}", NumGet(SHA_CTX, 115 + A_Index, "UChar"))
return o, DllCall("FreeLibrary", "Ptr", hModule)
}

; ===============================================================================================================================
; The MD5 algorithm is a widely used hash function producing a 128-bit hash value
; ===============================================================================================================================

MD5(string, case := 0)
{
static MD5_DIGEST_LENGTH := 16
hModule := DllCall("LoadLibrary", "Str", "advapi32.dll", "Ptr")
, VarSetCapacity(MD5_CTX, 104, 0), DllCall("advapi32\MD5Init", "Ptr", &MD5_CTX)
, DllCall("advapi32\MD5Update", "Ptr", &MD5_CTX, "AStr", string, "UInt", StrLen(string))
, DllCall("advapi32\MD5Final", "Ptr", &MD5_CTX)
loop % MD5_DIGEST_LENGTH
o .= Format("{:02" (case ? "X" : "x") "}", NumGet(MD5_CTX, 87 + A_Index, "UChar"))
return o, DllCall("FreeLibrary", "Ptr", hModule)
}

; ===============================================================================================================================
; CRC32 Implementation in AutoHotkey
; ===============================================================================================================================

CRC32(str)
{
static table := []
loop 256 {
crc := A_Index - 1
loop 8
crc := (crc & 1) ? (crc >> 1) ^ 0xEDB88320 : (crc >> 1)
table[A_Index - 1] := crc
}
crc := ~0
loop, parse, str
crc := table[(crc & 0xFF) ^ Asc(A_LoopField)] ^ (crc >> 8)
return Format("{:#x}", ~crc)
}
154 changes: 154 additions & 0 deletions Lib/IOClasses.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
#include Lib\IOUtils.ahk

;--------------------------------------------------------------------------------
; FileNameParser - Class to parse a file into its parts
class FileNameParser
{
_FullFileName :=

__New(fullFileName)
{
this.FullFileName := fullFileName
}

FullFileName
{
get
{
return this._FullFileName
}
set
{
this._FullFileName := value
}
}

Drive
{
get
{
fileName := this.FullFileName
SplitPath, fileName,,,,, drive

return drive
}
}

Directory
{
get
{
fileName := this.FullFileName
SplitPath, fileName,, directory

return directory
}
}

FileName
{
get
{
fileName := this.FullFileName
SplitPath, fileName, fileName

return fileName
}
}

Extension
{
get
{
fileName := this.FullFileName
SplitPath, fileName,,, extension

return extension
}
}

FileNameNoExt
{
get
{
fileName := this.FullFileName
SplitPath, fileName,,,, fileNameNoExt

return fileNameNoExt
}
}
}

;--------------------------------------------------------------------------------
; DataFile - Class to represent a data file with a well formed name
class DataFile extends FileNameParser
{
__New(fullFileName)
{
base.__New(fullFileName)
}

Content
{
get
{
return FileReadContent(this.FullFileName)
}
}

ContentLines
{
get
{
return FileReadContentLines(this.FullFileName)
}
}

LineCount
{
get
{
return this.ContentLines.length()
}
}

CRC32
{
get
{
hash := CRC32(this.Content)

return hash
}
}

Adler32
{
get
{
hash := Adler32(this.Content)

return hash
}
}

SHA1
{
get
{
hash := SHA1(this.Content)

return hash
}
}

MD5
{
get
{
hash := MD5(this.Content)

return hash
}
}
}
41 changes: 39 additions & 2 deletions Lib/IOUtils.ahk
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include Lib\StringUtils.ahk
#include Lib\HashingFunctions.ahk

;--------------------------------------------------------------------------------
; CombinePaths - Append path2 to path1, ensuring the correct delimiters are in place
Expand All @@ -9,11 +10,11 @@ CombinePaths(path1, path2)

;--------------------------------------------------------------------------------
; CombinePaths - Append multiple paths together, ensuring the correct delimiters are in place
CombinePathA(paths*)
CombineAllPaths(paths*)
{
newPath :=

Loop, %path%
For index, path in paths
{
if (newPath = "")
{
Expand All @@ -28,6 +29,19 @@ CombinePathA(paths*)
return newPath
}

;--------------------------------------------------------------------------------
; SetFileExtension - Set the extension on a filename
SetFileExtension(fileName, extension)
{
pos := InStr(fileName, ".", false, -1)
if (pos)
fileName := SubStr(fileName, 1, pos)

fileName := EnsureEndsWith(fileName, ".") . extension

return fileName
}

;--------------------------------------------------------------------------------
; FileExists - Determines if a file exists
FileExists(fileName)
Expand All @@ -49,3 +63,26 @@ FolderExists(folderName)

return exists
}

;--------------------------------------------------------------------------------
; FileReadContent - Read the entire contents of a file into a variable
FileReadContent(fileName)
{
FileRead, content, %fileName%

return content
}

;--------------------------------------------------------------------------------
; FileReadContentLines - Read every line of a file into an array
FileReadContentLines(fileName)
{
lines := []

Loop, Read, %fileName%
{
lines.push(A_LoopReadLine)
}

return lines
}
Loading

0 comments on commit 6dcb9b5

Please sign in to comment.