Skip to content

Instantly share code, notes, and snippets.

@Buthrakaur
Last active June 22, 2023 00:42
Show Gist options
  • Save Buthrakaur/bb19610a06c550430860 to your computer and use it in GitHub Desktop.
Save Buthrakaur/bb19610a06c550430860 to your computer and use it in GitHub Desktop.
RoundhousE script hash calculator to fix already executed script in UP folder without RH complaining about the script change
Param(
[Parameter(Mandatory = $true)]
[string]$file
)
#port of RoundhousE WindowsFileSystemAccess.get_file_encoding
function getFileEncoding($file){
$enc = [System.Text.Encoding]::Default
$buffer = gc $file -Encoding Byte
if ($buffer[0] -eq 0xef -and $buffer[1] -eq 0xbb -and $buffer[2] -eq 0xbf){
$enc = [System.Text.Encoding]::UTF8
}
elseif ($buffer[0] -eq 0xfe -and $buffer[1] -eq 0xff){
$enc = [System.Text.Encoding]::Unicode
}
elseif ($buffer[0] -eq 0 -and $buffer[1] -eq 0 -and $buffer[2] -eq 0xfe -and $buffer[3] -eq 0xff){
$enc = [System.Text.Encoding]::UTF32
}
elseif ($buffer[0] -eq 0x2b -and $buffer[1] -eq 0x2f -and $buffer[2] -eq 0x76){
$enc = [System.Text.Encoding]::UTF7
}
return $enc;
}
$enc = getFileEncoding $file
$fileContents = [System.IO.File]::ReadAllText($file, $enc).Replace("'", "''")#Replace is RH WTF "feature"
$bytes = [System.Text.Encoding]::UTF8.GetBytes($fileContents)
$md5 = [System.Security.Cryptography.MD5]::Create()
[convert]::ToBase64String($md5.ComputeHash($bytes))
INSERT INTO xxx_rh_run(id, version_id, script_name, text_hash, one_time_script,
entry_date, modified_date, entered_by)
VALUES (xxx_rh_runid.NEXTVAL, 0, 'xxx.sql', 'xxx', 1, SYSDATE, SYSDATE, 'manual');
UPDATE xxx_rh_run
SET text_hash = 'xxx'
WHERE script_name = 'xxx'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment