I am trying to change the linker scripts that sam-ba (sam bootloader assistant) is using. The liner scripts are written for samd21j18a by Atmel Corporation (tcl_lib and applet). The samd21e16b Sram is 8 kB and the flash memory is 64 kB, based on the datasheet.
Based on the documentation, I need to change
appletAddr and appletMailboxAddr accordingly in tcl_lib, based on the device selected and the SRAM occupied by the SAM-BA bootloader.
Customizing ASF SAM-BA Applet Linker script for SAMD21E16B and latest ASF. I need to update the sections which are based on the device chosen, and the SRAM size occupied by the SAM-BA bootloader.
Do you have any resources that are helpful to understand this information in the linker scripts for customizing the chip (samd21e16b)?
What are appletAddr and appletMailboxAddr?
How they write sram size:
sram (W!RX) : ORIGIN = 0x20002000, LENGTH = 0x00002000 /* sram, 4K - sizeof(romcodesram) */
tcl_lib:
set cidr_addr 0x41002018
# *****************************************************************************
# CHIP NAME CHIPID_CIDR
# *****************************************************************************
array set devicesList { samd21j18a 0x10010000
samd21j17a 0x10010001
samd21j16a 0x10010002
samd21j15a 0x10010003
samd21g18a 0x10010005
samd21g17a 0x10010006
samd21g16a 0x10010007
samd21g15a 0x10010008
samd21e18a 0x1001000A
samd21e17a 0x1001000B
samd21e16a 0x1001000C
samd21e15a 0x1001000D
}
global target
global commandLineMode
set isValidChipOfBoard 0
set version_mask 0xFFBF00FF
set chipname_list [array names ::devicesList]
set chip_id [format "0x%08x" [TCL_Read_Int $target(handle) $cidr_addr err_code]]
puts "Read device Chip ID at $cidr_addr --- get $chip_id"
set proc_id_masked [format "0x%08x" [expr $chip_id & $version_mask]]
foreach {key value} [array get devicesList] {
set masked_chipId_Cidr [format "0x%08x" [expr $value & $version_mask]]
if {[regexp $proc_id_masked $masked_chipId_Cidr] != 0} {
puts "-I- Found chip : $key (Chip ID : $chip_id)"
set isValidChipOfBoard 1
break
}
}
if { $isValidChipOfBoard == 0 } {
if { $commandLineMode == 1 } {
puts "-E- Invalid device or board!"
} else {
tk_messageBox -title "Invalid chip ID" -message "Can't connect $target(board)\n" -icon error -type ok
}
TCL_Close $target(handle)
exit
}
namespace eval BOARD {
variable sramSize 0x00008000
variable maxBootSize 0
# Vdd Memory 1.8V = 0 / Vdd Memory 3.3V = 1
variable extRamVdd 1
# External SDRAM = 0 / External DDR = 1 External PSRAM = 2 (not used)
variable extRamType 0
# Set bus width (16 or 32)
variable extRamDataBusWidth 16
# DDRAM Model (not used)
variable extDDRamModel 0
}
# Standard applet commands + some SAMD21 specific commands
array set appletCmdSamd21 {
init 0x00
fullErase 0x01
write 0x02
read 0x03
lock 0x04
unlock 0x05
gpnvm 0x06
security 0x07
erasebuffer 0x08
binarypage 0x09
otpRead 0x0a
otpWrite 0x0b
listbadblocks 0x10
tagBlock 0x11
readUniqueID 0x12
eraseBlocks 0x13
batchErase 0x14
pmeccParam 0x15
pmeccBoot 0x16
switchEccMode 0x17
trimffsMode 0x18
eraseRow 0x40
readDeviceID 0x41
readLocks 0x42
readFuses 0x43
eraseApp 0x44
}
set target(board) "samd21_xplained_pro"
################################################################################
## PROCEDURES FOR COMPATIBILITY WITH OLDER SAM-BA VERSIONS AND USER DEFINED
################################################################################
if { [ catch { source "$libPath(extLib)/common/functions.tcl"} errMsg] } {
if {$commandLineMode == 0} {
tk_messageBox -title "File not found" -message "Function file not found:\n$errMsg" -type ok -icon error
} else {
puts "-E- Function file not found:\n$errMsg"
puts "-E- Connection abort"
}
exit
}
array set memoryAlgo {
"SRAM" "::atsamd21_sram"
"Flash" "::atsamd21_flash"
"Peripheral" "::atsamd21_peripheral"
}
################################################################################
## Low Level Initialization
################################################################################
################################################################################
## SRAM : 32k
################################################################################
array set atsamd21_sram {
dftDisplay 0
dftDefault 0
dftAddress 0x20000000
dftSize 0x8000
dftSend "RAM::sendFile"
dftReceive "RAM::receiveFile"
dftScripts ""
}
################################################################################
## FLASH : 256k
################################################################################
array set atsamd21_flash {
dftDisplay 1
dftDefault 1
dftAddress 0x00000
dftSize 0x40000
dftSend "FLASH::SendFileNoLock"
dftReceive "FLASH::ReceiveFile"
dftScripts "::atsamd21_flash_scripts"
}
array set atsamd21_flash_scripts {
"Read Device ID" "FLASH::ReadDeviceID"
"Read Lock Fuses" "FLASH::ReadLocks"
"Unlock All" "FLASH::UnlockAll"
"Set Lock Bit 00" "FLASH::SetLock 0"
"Set Lock Bit 01" "FLASH::SetLock 1"
"Set Lock Bit 02" "FLASH::SetLock 2"
"Set Lock Bit 03" "FLASH::SetLock 3"
"Set Lock Bit 04" "FLASH::SetLock 4"
"Set Lock Bit 05" "FLASH::SetLock 5"
"Set Lock Bit 06" "FLASH::SetLock 6"
"Set Lock Bit 07" "FLASH::SetLock 7"
"Set Lock Bit 08" "FLASH::SetLock 8"
"Set Lock Bit 09" "FLASH::SetLock 9"
"Set Lock Bit 10" "FLASH::SetLock 10"
"Set Lock Bit 11" "FLASH::SetLock 11"
"Set Lock Bit 12" "FLASH::SetLock 12"
"Set Lock Bit 13" "FLASH::SetLock 13"
"Set Lock Bit 14" "FLASH::SetLock 14"
"Set Lock Bit 15" "FLASH::SetLock 15"
"Invalidate application" "FLASH::EraseRow 32"
"Erase application area" "FLASH::EraseApp"
"Read Fuses" "FLASH::ReadFuses"
"Set Security Bit" "FLASH::SetSecurity"
}
set FLASH::appletAddr 0x20002000
set FLASH::appletMailboxAddr 0x20002040
set FLASH::appletFileName "$libPath(extLib)/$target(board)/applet-flash-samd21j18a.bin"
# Initialize FLASH
if {[catch {FLASH::Init} dummy_err]} {
if {$commandLineMode == 0} {
tk_messageBox -title "FLASH init" -message "Failed to initialize FLASH access" -icon error -type ok
} else {
puts "-E- Error during FLASH initialization"
puts "-E- Connection abort"
}
# Close link
TCL_Close $target(handle)
exit
} else {
#retrieve additionnal parameters from the Init function
set appletAddrArgvps [expr $FLASH::appletMailboxAddr + 0x18]
set appletAddrArgvnp [expr $FLASH::appletMailboxAddr + 0x1c]
set appletAddrArgvasp [expr $FLASH::appletMailboxAddr + 0x20]
set flashPageSize [TCL_Read_Int $target(handle) $appletAddrArgvps]
set flashNbPage [TCL_Read_Int $target(handle) $appletAddrArgvnp]
set flashAppStartPage [TCL_Read_Int $target(handle) $appletAddrArgvasp]
puts "flashPageSize [format "0x%08x" $flashPageSize]"
puts "flashNbPage [format "%d" $flashNbPage]"
puts "flashAppStartPage [format "%d" $flashAppStartPage]"
puts "-I- FLASH initialized"
}
################################################################################
array set atsamd21_peripheral {
dftDisplay 0
dftDefault 0
dftAddress 0x40000000
dftSize 0x10000000
dftSend ""
dftReceive ""
dftScripts ""
}
#===============================================================================
# proc FLASH::ReadDeviceID
#===============================================================================
proc FLASH::ReadDeviceID { } {
global target
variable appletMailboxAddr
set dummy_err 0
# Mailbox is 32 word long (add variable here if you need read/write more data)
set appletAddrCmd [expr $appletMailboxAddr]
set appletAddrStatus [expr $appletMailboxAddr + 0x04]
set appletAddrArgv0 [expr $appletMailboxAddr + 0x08]
set appletAddrArgv1 [expr $appletMailboxAddr + 0x0c]
set appletAddrArgv2 [expr $appletMailboxAddr + 0x10]
set appletAddrArgv3 [expr $appletMailboxAddr + 0x14]
# Init the ping pong algorithm: the buffer is active
set bufferAddress $GENERIC::appletBufferAddress
# Write the Cmd op code in the argument area
if {[catch {TCL_Write_Int $target(handle) $::appletCmdSamd21(readDeviceID) $appletAddrCmd} dummy_err] } {
error "Error Writing Applet command ($dummy_err)"
}
# Write the buffer address in the argument area
if {[catch {TCL_Write_Int $target(handle) $bufferAddress $appletAddrArgv0} dummy_err] } {
error "[format "0x%08x" $dummy_err]"
}
# Launch the applet Jumping to the appletAddr
if {[catch {set result [GENERIC::Run $::appletCmdSamd21(readDeviceID)]} dummy_err]} {
error "Applet readDeviceID command has not been launched ($dummy_err)"
}
puts "buffer address [format "0x%08x" $bufferAddress]"
puts "Device ID :"
set addr [expr $bufferAddress]
# Return the error code returned by the applet
if {[catch {set data [TCL_Read_Int $target(handle) $addr]} dummy_err] } {
error "Error reading the buffer containing Device ID"
}
puts [format "0x%08x" $data]
}
#===============================================================================
# proc FLASH::ReadFuses
#===============================================================================
proc FLASH::ReadFuses { } {
global target
variable appletMailboxAddr
set dummy_err 0
# Mailbox is 32 word long (add variable here if you need read/write more data)
set appletAddrCmd [expr $appletMailboxAddr]
set appletAddrStatus [expr $appletMailboxAddr + 0x04]
set appletAddrArgv0 [expr $appletMailboxAddr + 0x08]
set appletAddrArgv1 [expr $appletMailboxAddr + 0x0c]
# Init the ping pong algorithm: the buffer is active
set bufferAddress $GENERIC::appletBufferAddress
# Write the Cmd op code in the argument area
if {[catch {TCL_Write_Int $target(handle) $::appletCmdSamd21(readFuses) $appletAddrCmd} dummy_err] } {
error "Error Writing Applet command ($dummy_err)"
}
# Write the buffer address in the argument area
if {[catch {TCL_Write_Int $target(handle) $bufferAddress $appletAddrArgv0} dummy_err] } {
error "[format "0x%08x" $dummy_err]"
}
# Launch the applet Jumping to the appletAddr
if {[catch {set result [GENERIC::Run $::appletCmdSamd21(readFuses)]} dummy_err]} {
error "Applet readDeviceID command has not been launched ($dummy_err)"
}
puts "buffer address [format "0x%08x" $bufferAddress]"
puts "Fuses :"
set i 0
set addr [expr $bufferAddress]
while {$i < [expr 2]} {
# Return the error code returned by the applet
if {[catch {set data [TCL_Read_Int $target(handle) $addr]} dummy_err] } {
error "Error reading the buffer containing Device ID"
}
incr addr +4
incr i +1
puts [format "0x%08x" $data]
}
}
#===============================================================================
# proc FLASH::ReadLocks
#===============================================================================
proc FLASH::ReadLocks { } {
global target
variable appletMailboxAddr
set dummy_err 0
# Mailbox is 32 word long (add variable here if you need read/write more data)
set appletAddrCmd [expr $appletMailboxAddr]
set appletAddrStatus [expr $appletMailboxAddr + 0x04]
set appletAddrArgv0 [expr $appletMailboxAddr + 0x08]
set appletAddrArgv1 [expr $appletMailboxAddr + 0x0c]
set appletAddrArgv2 [expr $appletMailboxAddr + 0x10]
set appletAddrArgv3 [expr $appletMailboxAddr + 0x14]
# Init the ping pong algorithm: the buffer is active
set bufferAddress $GENERIC::appletBufferAddress
# Write the Cmd op code in the argument area
if {[catch {TCL_Write_Int $target(handle) $::appletCmdSamd21(readLocks) $appletAddrCmd} dummy_err] } {
error "Error Writing Applet command ($dummy_err)"
}
# Write the buffer address in the argument area
if {[catch {TCL_Write_Int $target(handle) $bufferAddress $appletAddrArgv0} dummy_err] } {
error "[format "0x%08x" $dummy_err]"
}
# Launch the applet Jumping to the appletAddr
if {[catch {set result [GENERIC::Run $::appletCmdSamd21(readLocks)]} dummy_err]} {
error "Applet readDeviceID command has not been launched ($dummy_err)"
}
puts "buffer address [format "0x%08x" $bufferAddress]"
puts "Lock status :"
set addr [expr $bufferAddress]
# Return the error code returned by the applet
if {[catch {set data [TCL_Read_Short $target(handle) $addr]} dummy_err] } {
error "Error reading the buffer containing Device ID"
}
puts [format "0x%4x" $data]
}
#===============================================================================
# proc FLASH::SetLock
#===============================================================================
proc FLASH::SetLock { lockbit } {
global target
variable appletMailboxAddr
set dummy_err 0
# Mailbox is 32 word long (add variable here if you need read/write more data)
set appletAddrCmd [expr $appletMailboxAddr]
set appletAddrStatus [expr $appletMailboxAddr + 0x04]
set appletAddrArg_value [expr $appletMailboxAddr + 0x08]
if {$lockbit > [expr 16]} {
error "Wrong lock bit number"
}
set writemask [expr 1 << $lockbit ]
# Write the Cmd op code in the argument area
if {[catch {TCL_Write_Int $target(handle) $::appletCmdSamd21(lock) $appletAddrCmd} dummy_err] } {
error "Error Writing Applet command ($dummy_err)"
}
# Write value in the argument area
if {[catch {TCL_Write_Int $target(handle) [expr $lockbit] $appletAddrArg_value} dummy_err] } {
error "[format "0x%08x" $dummy_err]"
}
# Launch the applet Jumping to the appletAddr
if {[catch {set result [GENERIC::Run $::appletCmdSamd21(lock)]} dummy_err]} {
error "Applet lock command has not been launched ($dummy_err)"
}
puts "Region locked"
}
#===============================================================================
# proc FLASH::UnlockAll
#===============================================================================
proc FLASH::UnlockAll { } {
global target
variable appletMailboxAddr
set dummy_err 0
# Mailbox is 32 word long (add variable here if you need read/write more data)
set appletAddrCmd [expr $appletMailboxAddr]
set appletAddrStatus [expr $appletMailboxAddr + 0x04]
set appletAddrArg_value [expr $appletMailboxAddr + 0x08]
set lockbit 0
while { $lockbit < [expr 16]} {
set writemask [expr 1 << $lockbit ]
# Write the Cmd op code in the argument area
if {[catch {TCL_Write_Int $target(handle) $::appletCmdSamd21(unlock) $appletAddrCmd} dummy_err] } {
error "Error Writing Applet command ($dummy_err)"
}
# Write value in the argument area
if {[catch {TCL_Write_Int $target(handle) [expr $lockbit] $appletAddrArg_value} dummy_err] } {
error "[format "0x%08x" $dummy_err]"
}
# Launch the applet Jumping to the appletAddr
if {[catch {set result [GENERIC::Run $::appletCmdSamd21(unlock)]} dummy_err]} {
error "Applet lock command has not been launched ($dummy_err)"
}
puts "Region ($lockbit) unlocked"
incr lockbit +1
}
}
#===============================================================================
# proc FLASH::SetSecurity
#===============================================================================
proc FLASH::SetSecurity { } {
global target
variable appletMailboxAddr
set dummy_err 0
# Mailbox is 32 word long (add variable here if you need read/write more data)
set appletAddrCmd [expr $appletMailboxAddr]
set appletAddrStatus [expr $appletMailboxAddr + 0x04]
set appletAddrArg_param [expr $appletMailboxAddr + 0x08]
# Write the Cmd op code in the argument area
if {[catch {TCL_Write_Int $target(handle) $::appletCmdSamd21(security) $appletAddrCmd} dummy_err] } {
error "Error Writing Applet command ($dummy_err)"
}
# Write the param value in the argument area
if {[catch {TCL_Write_Int $target(handle) 1 $appletAddrArg_param} dummy_err] } {
error "[format "0x%08x" $dummy_err]"
}
puts "About to launch set security bit procedure ..."
# Launch the applet Jumping to the appletAddr
if {[catch {set result [GENERIC::Run $::appletCmdSamd21(security)]} dummy_err]} {
error "Applet security command has not been launched ($dummy_err)"
} else {
puts "Part is secured"
}
}
#===============================================================================
# proc FLASH::SendFileNoLock
#===============================================================================
proc FLASH::SendFileNoLock { name addr } {
variable flashSize
variable flashLockRegionSize
variable flashNumbersLockBits
variable appletBufferAddress
global commandLineMode
if { [catch {set f [open $name r]}] } {
puts "-E- Can't open file $name"
return -1
}
fconfigure $f -translation binary
#First Step check the locked sector
set dummy_err 0
set rewrite 0
set size [file size $name]
set dest [expr $addr & [expr $flashSize - 1]]
set first_page [expr $dest / $::flashPageSize]
puts "File size : $size"
puts "Flash size : $flashSize Flash page size : $::flashPageSize First page : $first_page"
puts "Dest : $dest"
if { $first_page < $::flashAppStartPage } {
if {$commandLineMode == 0} {
set answer [tk_messageBox -title "Attempt to write monitor area"\
-message " Writing to the monitor area is forbidden, write operation aborted "\
-icon error \
-type ok]
}
return -1
}
if {[catch {GENERIC::Write $dest $size $f 0} dummy_err] } {
puts "-E- Generic::Write returned error ($dummy_err)"
close $f
return -1
}
close $f
}
#===============================================================================
# proc FLASH::EraseRow
#===============================================================================
proc FLASH::EraseRow { flashrow } {
global target
variable appletMailboxAddr
set dummy_err 0
# Mailbox is 32 word long (add variable here if you need read/write more data)
set appletAddrCmd [expr $appletMailboxAddr]
set appletAddrStatus [expr $appletMailboxAddr + 0x04]
set appletAddrArg_param [expr $appletMailboxAddr + 0x08]
if {$flashrow > [expr 1024]} {
error "Wrong flash region number"
}
if {[catch {TCL_Write_Int $target(handle) $::appletCmdSamd21(eraseRow) $appletAddrCmd} dummy_err] } {
error "Error Writing Applet command ($dummy_err)"
}
# Write the param value in the argument area
if {[catch {TCL_Write_Int $target(handle) [expr $flashrow] $appletAddrArg_param} dummy_err] } {
error "[format "0x%08x" $dummy_err]"
}
# Launch the applet Jumping to the appletAddr
if {[catch {set result [GENERIC::Run $::appletCmdSamd21(eraseRow)]} dummy_err]} {
error "Applet eraseRow command has not been launched ($dummy_err)"
}
puts "Flash memory row erased."
}
#===============================================================================
# proc FLASH::EraseApp
#===============================================================================
proc FLASH::EraseApp { } {
global target
variable appletMailboxAddr
set dummy_err 0
# Mailbox is 32 word long (add variable here if you need read/write more data)
set appletAddrCmd [expr $appletMailboxAddr]
set appletAddrStatus [expr $appletMailboxAddr + 0x04]
set appletAddrArg_start_row [expr $appletMailboxAddr + 0x08]
set appletAddrArg_end_row [expr $appletMailboxAddr + 0x0c]
# Write the Cmd op code in the argument area
if {[catch {TCL_Write_Int $target(handle) $::appletCmdSamd21(eraseApp) $appletAddrCmd} dummy_err] } {
error "Error Writing Applet command ($dummy_err)"
}
set start [expr $::flashAppStartPage/4]
set end [expr $::flashNbPage/4]
# Write the starting row number in the argument area
if {[catch {TCL_Write_Int $target(handle) [expr $start] $appletAddrArg_start_row} dummy_err] } {
error "[format "0x%08x" $dummy_err]"
}
# Write the ending row number in the argument area
if {[catch {TCL_Write_Int $target(handle) [expr $end] $appletAddrArg_end_row} dummy_err] } {
error "[format "0x%08x" $dummy_err]"
}
puts "Start row: [format "0x%08x" $start]"
puts "End row: [format "0x%08x" $end]"
# Launch the applet Jumping to the appletAddr
if {[catch {set result [GENERIC::Run $::appletCmdSamd21(eraseApp)]} dummy_err]} {
error "Applet eraseApp command has not been launched ($dummy_err)"
}
puts "Application area erased"
}
Applets:
/*------------------------------------------------------------------------------
* Linker script for running in internal SRAM on the SAMD21J18
*----------------------------------------------------------------------------*/
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
OUTPUT_ARCH(arm)
/* Memory Spaces Definitions */
MEMORY
{
romcodesram (W!RX) : ORIGIN = 0x20000000, LENGTH = 0x2000
sram (W!RX) : ORIGIN = 0x20002000, LENGTH = 0x00002000 /* sram, 4K - sizeof(romcodesram) */
}
SECTIONS
{
/* startup code in the .isr_vector */
.text :
{
. = ALIGN(4);
_stext = .;
KEEP(*(.isr_vector .isr_vector.*))
*(.mailbox)
*(.text .text.*)
*(.rodata .rodata.*)
*(.ramfunc .ramfunc.*)
*(.glue_7)
*(.glue_7t)
*(.gcc_except_table)
*(.rodata .rodata*)
*(.gnu.linkonce.r.*)
. = ALIGN(4);
_etext = .;
} > sram
/* data */
.data :
{
. = ALIGN(4);
_sidata = .;
_sdata = .;
*(.data)
*(.data.*)
. = ALIGN(4);
_edata = .;
} > sram
.bss (NOLOAD) : {
_szero = .;
*(.bss)
. = ALIGN(4);
_ezero = .;
} >sram
/* Stack in SRAM */
_sstack = 0x20003FF0;
/DISCARD/ : { *(.note.gnu.*) }
}
. = ALIGN(4);
end = .;
long time listener, first time caller,
I have a need to create a Powershell script (ver 2 or lower) that:
-continually monitors one specific directory for new/changed files
-logs the file that was created with a date/time stamp in a log file that's:
--created on a daily basis with the name of "log Date/Time.txt"
-renames the file, appending the date/time
-logs that it renamed it
-maps a drive with a specific username/password combo
-moves it from dirA to dirB (the mapped drive is dirB)
-logs that it moved it
-unmaps the drive
-if for whatever reason it stopped running and we start it back up, it'll rename, maps the drive, move, unmap the drive, and log all files in dirA to dirB
In it's current form, I've stripped the Mapping of the dir out to troubleshoot it moving the file on a local drive just to keep from troubleshooting a network drive.
I've been staring at this for over a week and am tired of hitting my head against the desk. Can someone PLEASE put me out of my misery and let me know what I've done wrong?
THANK YOU in advance!
I've honestly tried SO many combos, different routines, I don't even know what to put here.
In the box below, I've put the main part of the script that isn't working correctly It renames the files as they come in, but doesn't move them.
$rename = $_.Name.Split(".")[0] + "_" + ($_.CreationTime | Get-Date -Format MM.dd.yyy) + "_" + ($_.CreationTime | Get-Date -Format hh.mm.ss) + ".log"
Write-Output "File: '$name' exists at: $source - renaming existing file first" >> $scriptlog
Rename-Item $_ -NewName $rename
Wait-Event -Timeout 3
Move-Item "$_($_.Directory)$name" -destination $destination
Write-Output "File: '$name' moved to $destination on $date" >> $scriptlog
Whole code available below:
#Log Rename/Move script
$userName = "copyuser"
$newpass = Read-Host -Prompt 'Type the new Password'
$password = ConvertTo-SecureString -String $newpass -AsPlainText -Force
$PathToMonitor = "C:\Users\Administrator\Desktop\FolderA"
$destination = "C:\Users\Administrator\Desktop\FolderB"
$scriptlog = "C:\Users\Administrator\Desktop\ScriptLogs\" + [datetime]::Today.ToString('MM-dd-yyy') + "_TransferLog.txt"
$FileSystemWatcher = New-Object System.IO.FileSystemWatcher
$FileSystemWatcher.Path = $PathToMonitor
$FileSystemWatcher.IncludeSubdirectories = $false
$FileSystemWatcher.EnableRaisingEvents = $true
$dateTime = [datetime]::Today.ToString('MM-dd-yyy') + " " + [datetime]::Now.ToString('HH:mm:ss')
Write-Output "*******************************************************************************************" >> $scriptLog
Write-Output "*********************Starting Log Move Script $dateTime**********************" >> $scriptLog
Write-Output "*******************************************************************************************" >> $scriptLog
$Action = {
$details = $event.SourceEventArgs
$Name = $details.Name
$FullPath = $details.FullPath
$OldFullPath = $details.OldFullPath
$OldName = $details.OldName
$ChangeType = $details.ChangeType
$Timestamp = $event.TimeGenerated
$text = "{0} was {1} at {2}" -f $FullPath, $ChangeType, $Timestamp
Write-Output "" >> $scriptlog
Write-Output $text >> $scriptlog
switch ($ChangeType)
{
'Changed' { "CHANGE"
Get-ChildItem -path $FullPath -Include *.log | % {
$rename = $_.Name.Split(".")[0] + "_" + ($_.CreationTime | Get-Date -Format MM.dd.yyy) + "_" + ($_.CreationTime | Get-Date -Format hh.mm.ss) + ".log"
Write-Output "File: '$name' exists at: $source - renaming existing file first" >> $scriptlog
Rename-Item $_ -NewName $rename
Wait-Event -Timeout 3
Move-Item "$_($_.Directory)$name" -destination $destination
Write-Output "File: '$name' moved to $destination on $date" >> $scriptlog
}
}
'Created' { "CREATED"
Get-ChildItem -path $FullPath -Include *.log | % {
$rename = $_.Name.Split(".")[0] + "_" + ($_.CreationTime | Get-Date -Format MM.dd.yyy) + "_" + ($_.CreationTime | Get-Date -Format hh.mm.ss) + ".log"
Write-Output "File: '$name' exists at: $source - renaming existing file first" >> $scriptlog
Rename-Item $_ -NewName $rename
Wait-Event -Timeout 3
Move-Item "$($_.Directory)$rename" -Destination $destination
Write-Output "File: '$name' moved to $destination on $date" >> $scriptlog
}
}
'Deleted' { "DELETED"
}
'Renamed' {
}
default { Write-Output $_ >> $scriptlog}
}
}
$handlers = . {
Register-ObjectEvent -InputObject $FileSystemWatcher -EventName Changed -Action $Action -SourceIdentifier FSChange
Register-ObjectEvent -InputObject $FileSystemWatcher -EventName Created -Action $Action -SourceIdentifier FSCreate
}
Write-Output "Watching for changes to $PathToMonitor" >> $scriptlog
try
{
do
{
Wait-Event -Timeout 1
Write-host "." -NoNewline
} while ($true)
}
finally
{
# EndScript
Unregister-Event -SourceIdentifier FSChange
Unregister-Event -SourceIdentifier FSCreate
$handlers | Remove-Job
$FileSystemWatcher.EnableRaisingEvents = $false
$FileSystemWatcher.Dispose()
write-output "Event Handler disabled." >> $scriptlog
}
Well, I found my issue. A dumb issue if I look at it and think about it. It was how I was calling the current directory containing the file(s) to move after being renamed.
Move-Item "$_($_.Directory)$name" -destination $destination
The issue in the above code is the "$($.Directory). It needs to be:
Move-Item -path $PathToMonitor$name -destination $destination
Other things may work, and may be better, but at least that fixes the moving after naming issue I was having.
Now onto adding the Mapping Drive and other stuff that's needed to fully finish what I need.
If I think about it, I'll post my entire code when done for anyone else it can help in the future.
I having trouble parsing out a GFF file. I am using the code below as a one liner. I am obtaining an output filtered based on column 1 ($1) but when I add the additional filter of greater than 5000 but less than 150000, awk does not filter out my file appropriately. I am misunderstanding something and I am not quite sure what it is.
awk '{ $1 = "s10";
$4 >= 50000 && $4 <=150000;
print $1"\t"$2"\t"$3"\t"$4"\t"$5"\t"$6""\t"$7"\t"$8"\t"$9}' infile > outfile
input
S03 GeneWise mRNA 7000 84000 40.00 - . ID=NA;Source=NA;Function="NA";
S07 GeneWise CDS 80450 96070 . - 0 Parent=NA;
S10 GeneWise mRNA 96000 105032 50.00 - . ID=NA;Source=NA;Function="NA";
S10 GeneWise CDS 43800 76000 . - 0 Parent=NA;
S10 GeneWise mRNA 175032 190540 41.11 + . ID=NA;Source=NA;Function="NA";
S11 GeneWise CDS 3700 15000 . + 0 Parent=NA;
S15 GeneWise mRNA 18055 25000 40.00 - . ID=S15;Source=NA;Function="NA";
output i am obtaining with the error
S10 GeneWise mRNA 96000 105032 50.00 - . ID=NA;Source=NA;Function="NA";
S10 GeneWise CDS 43800 76000 . - 0 Parent=NA;
S10 GeneWise mRNA 175032 190540 41.11 + . ID=NA;Source=NA;Function="NA";
expected output
S10 GeneWise mRNA 96000 105032 50.00 - . ID=NA;Source=NA;Function="NA";
This is the correct form for the conditional. However, there is only one matching record for it:
$ awk '
$1 == "S10" && $4 >= 50000 && $4 <=150000 {
print $1"\t"$2"\t"$3"\t"$4"\t"$5"\t"$6"\t"$7"\t"$8"\t"$9
}' file
S10 GeneWise mRNA 96000 105032 50.00 - . ID=NA;Source=NA;Function="NA";
unless you want records with $1 == "S10" || $4 $4 >= 50000 && $4 <=150000 ie. using logical OR) but that would bring one extra record:
awk '
$1 == "S10" || $4 >= 50000 && $4 <=150000 {
print $1"\t"$2"\t"$3"\t"$4"\t"$5"\t"$6"\t"$7"\t"$8"\t"$9
}' file
S07 GeneWise CDS 80450 96070 . - 0 Parent=NA;
S10 GeneWise mRNA 96000 105032 50.00 - . ID=NA;Source=NA;Function="NA";
S10 GeneWise CDS 43800 76000 . - 0 Parent=NA;
S10 GeneWise mRNA 175032 190540 41.11 + . ID=NA;Source=NA;Function="NA";
Better form of the first:
$ awk '
BEGIN { OFS="\t" } # define OFS to \t
$1 == "S10" && $4 >= 50000 && $4 <=150000 {
$1=$1 # rebuild the record
print # output
}' file
I am adding a breakpoint in lldb like so:
(lldb) breakpoint set -s MyApp --func-regex .
(lldb) breakpoint command add 1
Enter your debugger command(s). Type 'DONE' to end.
> p __PRETTY_FUNCTION__
> continue
> DONE
(lldb) process attach --name MyApp --waitfor
(lldb) continue
My goal is to print each of the methods called in the my app. The results looks like:
(lldb) p __PRETTY_FUNCTION__
(const char [26]) $0 = "void $__lldb_expr(void *)"
(lldb) continue
Process 96238 resuming
Command #1 'continue' continued the target.
(lldb) p __PRETTY_FUNCTION__
(const char [47]) $1 = "-[AppDelegate($__lldb_category) $__lldb_expr:]"
(lldb) continue
Process 96238 resuming
Command #1 'continue' continued the target.
(lldb) p __PRETTY_FUNCTION__
(const char [47]) $2 = "-[AppDelegate($__lldb_category) $__lldb_expr:]"
(lldb) continue
Process 96238 resuming
Command #1 'continue' continued the target.
(lldb) p __PRETTY_FUNCTION__
(const char [47]) $3 = "-[AppDelegate($__lldb_category) $__lldb_expr:]"
(lldb) continue
Process 96238 resuming
Command #1 'continue' continued the target.
(lldb) p __PRETTY_FUNCTION__
(const char [47]) $4 = "-[AppDelegate($__lldb_category) $__lldb_expr:]"
(lldb) continue
The question is how do I remove the $__lldb_category and the $__lldb_expr: with the actual values of the method name and it's selectors?
I would use lldb commands to print this information, for instance:
(lldb) frame info
frame #0: 0x0000000100018dc7 Sketch`main(argc=1, argv=0x00007fff5fbff628) + 55 at SKTMain.m:17
would do what you want I think. If you want more or less info, you can also tailor the output of frame info as described here:
http://lldb.llvm.org/formats.html
In my installer's License page, I want to use a Hyperlink instead of text box. Link will be having the address of my webpage containing the License agreement.
I have already hid the text box, now the problem is adding the link. I want to add something like this:
click here to read License agreement.
I tried using Linker plugin as well as NSD_createlink but in both case the installer crashes.
How can I make it work ?
EDIT:
I am trying to make the link of ID 1006 only.
Following is my code, now its not crashing but neither is it working.
; For license page.
Function LicensePageShow
nsResize::Set $mui.LicensePage.TopText 120 180 250u 200u
;LogSet on
Call GetDateTime
Pop $dt
logex::Write "$dt In LicensePageShow "
GetDlgItem $0 $HWNDPARENT 1036
ShowWindow $0 ${SW_HIDE}
GetDlgItem $0 $HWNDPARENT 1045
ShowWindow $0 ${SW_HIDE}
GetDlgItem $0 $HWNDPARENT 1035
ShowWindow $0 ${SW_HIDE}
/* Hiding default License text box */
FindWindow $R0 `#32770` `` $HWNDPARENT
GetDlgItem $R0 $R0 1000
nsResize::Set $R0 0 0 0 0
ShowWindow $R0 ${SW_HIDE}
/* The License page Text */
FindWindow $0 "#32770" "" $HWNDPARENT
GetDlgItem $0 $0 1006
Linker::link /NOUNLOAD $0 "http://www.google.com"
FindWindow $R0 `#32770` `` $HWNDPARENT
GetDlgItem $R0 $R0 1038
ShowWindow $R0 ${SW_HIDE}
FindWindow $R0 `#32770` `` $HWNDPARENT
GetDlgItem $R0 $R0 1040
nsResize::Set $R0 50 80 300u 20u
System::Call '*(i,i,i,i)i.r1'
FindWindow $0 "#32770" "" $HWNDPARENT
GetDlgItem $2 $0 0x40A
System::Call 'USER32::GetWindowRect(ir2,ir1)'
System::Call 'USER32::MapWindowPoints(i0,ir0,ir1,i1)'
System::Call '*$1(i.r6,i.r7)'
System::Call 'USER32::GetClientRect(ir2,ir1)'
System::Call '*$1(i,i,i.r8,i.r9)'
IntOp $9 $9 + 3 ;padding
IntOp $7 $7 - $9
GetDlgItem $2 $0 0x3EE
System::Call 'USER32::GetClientRect(ir2,ir1)'
System::Call '*$1(i,i,i.r3,i.r4)'
System::Free $1
IntOp $4 $4 - $9 ;reduce size of label
System::Call 'USER32::SetWindowPos(ir2,i,i,i,ir3,ir4,i6)'
System::Call 'USER32::CreateWindowEx(i0,t "Button",t "Let Setup modify your browser settings",i ${__NSD_CheckBox_STYLE},ir6,ir7,ir8,ir9,ir0,i666,i0,i0)i.r2'
SendMessage $0 ${WM_GETFONT} 0 0 $0
SendMessage $2 ${WM_SETFONT} $0 1
${If} $Revisit == "false" ; If its Visited for first time
${NSD_SetState} $2 1 ;check it]
${Else} ; If user clicked back button on directory page
${NSD_SetState} $2 $checkboxstate
${endIf}
/* to Reposition the checkbox */
FindWindow $R0 `#32770` `` $HWNDPARENT
GetDlgItem $R0 $R0 666
;ShowWindow $R0 ${SW_HIDE}
;nsResize::Set $R0 50 120 300 20
System::Call 'USER32::SetWindowPos(i, i, i, i, i, i, i) b ($R0, 0, 50, 210, 300, 20, 0)'
FindWindow $R0 `#32770` `` $HWNDPARENT
GetDlgItem $R0 $R0 1034
;ShowWindow $R0 ${SW_HIDE}
;nsResize::Set $R0 50 120 300 20
System::Call 'USER32::SetWindowPos(i, i, i, i, i, i, i) b ($R0, 0, 50, 150, 300, 20, 0)'
FindWindow $R0 `#32770` `` $HWNDPARENT
GetDlgItem $R0 $R0 1035
;ShowWindow $R0 ${SW_HIDE}
;nsResize::Set $R0 50 120 300 20
System::Call 'USER32::SetWindowPos(i, i, i, i, i, i, i) b ($R0, 0, 50, 170, 300, 20, 0)'
; Set transparent backgrounds.
FindWindow $mui.LicensePage "#32770" "" $HWNDPARENT
SetCtlColors $mui.LicensePage 0xFFFFFF transparent
!insertmacro SetTransparent $mui.LicensePage 1040
!insertmacro SetTransparent $mui.LicensePage 1000
;!insertmacro SetTransparent $mui.LicensePage 1006
!insertmacro SetTransparent $mui.LicensePage 1034
!insertmacro SetTransparent $mui.LicensePage 1035
!insertmacro SetTransparent $mui.LicensePage 666
; Refresh controls.
Call RefreshParentControls
GetDlgItem $0 $HWNDPARENT 1045
ShowWindow $0 ${SW_HIDE}
FunctionEnd
Long story short: Linker plug-in works fine, quoted code not.
What are you trying to do with this code?
GetDlgItem $2 $0 0x3EE
System::Call 'USER32::GetClientRect(ir2,ir1)'
System::Call '*$1(i,i,i.r3,i.r4)'
System::Free $1
IntOp $4 $4 - $9 ;reduce size of label
System::Call 'USER32::SetWindowPos(ir2,i,i,i,ir3,ir4,i6)'
System::Call 'USER32::CreateWindowEx(i0,t "Button",t "Let Setup modify your browser settings",i ${__NSD_CheckBox_STYLE},ir6,ir7,ir8,ir9,ir0,i666,i0,i0)i.r2'
SendMessage $0 ${WM_GETFONT} 0 0 $0
SendMessage $2 ${WM_SETFONT} $0 1
0x3EE Hex is 1006 Dec - are you trying to resize this control, reposition or what?
This code is definitely wrong (when I used it my installer has crashed).
You should NOT use CreateWindowEx messages in NSIS (there are many troubles with it), always create control with ResHacker.
Can you post your script (snippet is enough).
I think you made something wrong - why do you need to hide a text box? And which one?
Correct syntax of this plug-in is:
FindWindow $0 "#32770" "" $HWNDPARENT
GetDlgItem $0 $0 1006
Linker::link /NOUNLOAD $0 "http://www.unsigned-softworks.sk/"
where 1006 is ID of your control which is transformed into link.
This control is usually text (STATIC).
Did you add your own control on dialog (e.g. using ResHacker) or which control id are you trying to switch into link?