Skip to content

Commit

Permalink
Enhancements for initial release
Browse files Browse the repository at this point in the history
- Fix build script on PowerShell 5.x
- Add progress bar
- Update readme file
  • Loading branch information
DoCode committed Feb 5, 2020
1 parent 3bbd1ce commit 662878b
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 18 deletions.
80 changes: 66 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,80 @@ AutoHotKey automation for RAMMap.

## Installation

TODO: Describe the installation process
The `build.cmd|ps1` scripts provide two capabilities:

- **Download** the latest RAMMap executable (Switch: `-DownloadRamMap`, Default: `false`)
- **Download** the latest AutoHotKey and **compile** the AutoHotKey script into a self contained executable (Switch: `-CompileExecutable`, Default: `true`)

> **Note:** The `build.cmd` is only a wrapper for `build.ps1` script!
The `clean.cmd` only remove the build artifacts from `build.cmd|ps1`!

### Example

Download RAMMap, download AutoHotKey and compile AutoHotKey script to EXE:

```bat
build.cmd|ps1 -DownloadRamMap -CompileExecutable
```

The output is under `_build` directory:

```txt
_build
| rammap-cleanup.exe
| RAMMap.exe
|
\---ahk
| AutoHotkey.chm
| AutoHotkeyA32.exe
| AutoHotkeyU32.exe
| AutoHotkeyU64.exe
| Installer.ahk
| license.txt
| Template.ahk
| WindowSpy.ahk
|
\---Compiler
Ahk2Exe.exe
ANSI 32-bit.bin
readme.txt
Unicode 32-bit.bin
Unicode 64-bit.bin
```

## Usage

TODO: Write usage instructions
> **NOTE:** Needs elevation and runs with administrative privileges.
## Contributing
### Run script

1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request :D
```bat
AutoHotkey.exe src/rammap-cleanup.ahk
```

### Run compiled executable

```bat
_build/rammap-cleanup.exe
```

## History
### Commandline arguments

TODO: Write history
The first argument can be the path to an existing `RAMMap.exe` executable on the machine, e.g.:

## Credits
```bat
AutoHotkey.exe src/rammap-cleanup.ahk C:/Program Files/Sysint/RAMMap.exe
_build_/rammap-cleanup.exe C:/Program Files/Sysint/RAMMap.exe
```

TODO: Write credits
> **NOTE:** If no path to `RAMMap.exe` is specified the AutoHotKey script search under the current
> directory and then search for `RAMMap.exe` in all paths defined in the `PATH` environment variable.
## License
## Contributing

TODO: Write license
1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request :D
6 changes: 3 additions & 3 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Set-ScriptArgs $MyInvocation.BoundParameters $MyInvocation.UnboundArguments
function Get-FileFromUrl([string] $name, [string] $url) {
Log info "Download '$name' from '$url'..."

$fileName = [System.IO.FileInfo]::new($url).Name
$fileName = [System.IO.Path]::GetFileName($url)
$downloadedFile = Join-Path $env:TEMP $fileName

Invoke-WebRequest -Uri $url -Method Get -OutFile $downloadedFile -UseBasicParsing
Expand All @@ -50,7 +50,7 @@ try {

if ($DownloadRamMap) {
$ramMapDownloadUrl = 'https://live.sysinternals.com/RAMMap.exe'
$ramMapFileName = [System.IO.FileInfo]::new($ramMapDownloadUrl).Name
$ramMapFileName = [System.IO.Path]::GetFileName($ramMapDownloadUrl)
New-DirectoryIfNotExists $outputDir

$ramMapDestination = Join-Path $outputDir $ramMapFileName
Expand All @@ -63,7 +63,7 @@ try {
}
}

if ($CompileExecutable) {
if (-not $CompileExecutable.IsPresent -or $CompileExecutable) {
$ahkDownloadUrl = 'https://www.autohotkey.com/download/ahk.zip'
$ahkPath = Join-Path $outputDir 'ahk'
New-DirectoryIfNotExists $ahkPath
Expand Down
33 changes: 32 additions & 1 deletion src/rammap-cleanup.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,29 @@

SetTitleMatchMode RegEx

ExpandToFullPath(file) {
shell := ComObjCreate("WScript.Shell")
exec := shell.Exec(ComSpec " /C where.exe " file)
return % exec.StdOut.ReadAll()
}

GetRamMapExe() {
If (A_Args.Length() > 0) {
ramMapFilePath := A_Args[1]
}
Else {

if (!FileExist(ramMapFilePath)) {
ramMapFilePath := A_ScriptDir . "/RAMMap.exe"
}

if (!FileExist(ramMapFilePath)) {
ramMapFilePath := ExpandToFullPath("RAMMap.exe")
}

ramMapFilePath := StrReplace(ramMapFilePath, "`r")
ramMapFilePath := StrReplace(ramMapFilePath, "`n")
ramMapFilePath := Trim(ramMapFilePath)

If (!FileExist(ramMapFilePath)) {
MsgBox, RAMMap.exe could not be found.
ExitApp, -1
Expand Down Expand Up @@ -145,23 +160,39 @@ If (!WinExist(GetRamMapTitle())) {
ExitApp, -1
}

Progress, p15, Preparing, Cleanup, RAMMap Cleanup

WaitUntilFinished()

Progress, 30, Empty Working Sets

EmptyWorkingSets()
WaitUntilFinished()

Progress, 45, Empty System Working Set

EmptySystemWorkingSet()
WaitUntilFinished()

Progress, 60, Empty Modified Page List

EmptyModifiedPageList()
WaitUntilFinished()

Progress, 75, Empty Standby List

EmptyStandbyList()
WaitUntilFinished()

Progress, 90, Empty Priority0 Standby List

EmptyPriority0StandbyList()
WaitUntilFinished()

Progress, 100, Finishing
Sleep, 2000
Progress, Off

CloseRamMap()
WinWaitClose, GetRamMapTitle(),, 5

Expand Down

0 comments on commit 662878b

Please sign in to comment.