Skip to content
This repository has been archived by the owner on Aug 17, 2022. It is now read-only.

Commit

Permalink
refactor applicable strings to resource ids
Browse files Browse the repository at this point in the history
  • Loading branch information
bitRAKE committed Mar 29, 2022
1 parent 019f246 commit 4bf4778
Show file tree
Hide file tree
Showing 15 changed files with 188 additions and 125 deletions.
25 changes: 10 additions & 15 deletions TaskDlgSamples.asm
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
include 'mywin.inc'
include 'mytd.inc'

include 'macro\rstrings.inc'
dummy RSTRING ; zero id


; this is mainly to counter my problems naming stuff
iterate <_file,function,b_id>,\
"CommonButton", Common_Buttons, COMMONBUTTONS,\
Expand Down Expand Up @@ -41,14 +45,11 @@ Main_Window:
enter .FRAME,0
INIT_MY_TD ; copy default structure

lea rax,<_T "TaskDialog Samples (originally by Kenny Kerr)">
mov [.cfg.pszWindowTitle],rax
lea rax,<_T "Pick a sample to try:">
mov [.cfg.pszMainInstruction],rax
lea rax,<_T "Use dialog close button, ESC or Alt-F4 keys to exit a sample.">
mov [.cfg.pszContent],rax
lea rax,<_T 'x86-64 by <a href="https://github.com/bitRAKE">bitRAKE</a> with flat assembler g.'>
mov [.cfg.pszFooter],rax

mov [.cfg.pszWindowTitle],<_R "TaskDialog Samples (originally by Kenny Kerr)">
mov [.cfg.pszMainInstruction],<_R "Pick a sample to try:">
mov [.cfg.pszContent],<_R "Use dialog close button, ESC or Alt-F4 keys to exit a sample.">
mov [.cfg.pszFooter],<_R 'x86-64 by <a href="https://github.com/bitRAKE">bitRAKE</a> with flat assembler g.'>
or [.cfg.dwFlags],TDF_USE_COMMAND_LINKS or TDF_CAN_BE_MINIMIZED or TDF_ENABLE_HYPERLINKS

;: create button array, let TaskDialog know:
Expand Down Expand Up @@ -192,8 +193,6 @@ end namespace


section '.rsrc' resource data readable
include 'macro\stringtable.inc'

IDR_ICON := 0x1FF

directory \
Expand All @@ -211,8 +210,7 @@ resource icons,\
resource group_icons,\
IDR_ICON,LANG_NEUTRAL,main_icon

resource strings,\
1,LANG_NEUTRAL,string_table1
resource_RSTRINGS strings ; generate tables

resource manifests,\
1,LANG_ENGLISH+SUBLANG_DEFAULT,manifest
Expand All @@ -223,9 +221,6 @@ icon main_icon,\
icon_m24,'resource\dip_chip_24x24.ico',\
icon_m16,'resource\dip_chip_16x16.ico'

stringtable string_table1,\ ; ids 00 - 0F
IDS_ZERO,"bitRAKE"

resdata manifest
file 'manifest.xml'
endres
Expand Down
110 changes: 110 additions & 0 deletions macro/rstrings.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@

; TODO: null string hack, LEA use, describe placeholders

define RSTRING 1

virtual at 0
RSTRING.buffer::
end virtual

; need to allow empty string resources for various reasons:
; 0) windows hates zero value resource IDs
; 1) hack for null terminated strings
; 2) placeholder indices, etc ...
struc RSTRING values&
local found,sid,O,r,ri,x,xi
match ,values
; just find array count (sid), and output new null string
virtual RSTRING.buffer
sid = 0
O = 0
while O < $
load ri:2 from O
O = O + ri + ri + 2
sid = sid + 1
end while
dw 0
. = sid
end virtual
else
virtual at 0
du values
xi := $ ; non-zero
load x:$ from 0
end virtual
found = 0
virtual RSTRING.buffer
sid = 0
O = 0
while O < $
load ri:2 from O
ri = ri shl 1
if ri = xi
load r:ri from O+2
if r = x
found = 1
. = sid
break
end if
end if
O = O + ri + 2
sid = sid + 1
end while
if ~ found
. = sid
dw xi shr 1
emit xi:x
end if
end virtual
end match
end struc

macro resource_RSTRINGS folder*,language:LANG_NEUTRAL
local table,bytes,O0,O1,tid,sid,ri,rx
virtual RSTRING.buffer
bytes := $-$$
end virtual
if bytes
RSTRING.where := $ ; error on multiple use
; first scatter table data into lists of 16 strings
O0 = 0
O1 = 0
sid = 0
while O1 < bytes
load ri:2 from RSTRING.buffer:O1
O1 = O1 + ri + ri + 2
; TODO: create labels to make address use possible (ie LEA)
sid = sid + 1

if sid and 0xF = 0 \
| O1 = bytes
load rx:O1-O0 from RSTRING.buffer:O0
repeat 1,tid:(sid+15)shr 4
table.tid dd RVA table.tid.base,O1-O0,0,0
table.tid.base db rx
end repeat
O0 = O1
end if
end while

; generate directory with entry for each table
temp equ folder
repeat (sid + 15) shr 4
temp reequ temp,%,language,table.%
end repeat
match any,temp
resource any
end match
else ; gracefully ignore, maybe wip
display "warning: resource_RSTRINGS w/o RSTRINGS defined.",10
end if
end macro

postpone
virtual RSTRING.buffer
if $ & ~ defined RSTRING.where
display 'Warning: No location for defined resource string data has been specified.',13,10
display 'Use "RSTRING.here {label}" macro in the intended location.',13,10
end if
end virtual
end postpone
17 changes: 0 additions & 17 deletions macro/stringtable.inc

This file was deleted.

17 changes: 5 additions & 12 deletions mytd.inc
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,14 @@ struc TD_BUTTONS line&
local name
struc name.struc
iterate <quoted,id>,line
;: array of TCHAR strings:
align sizeof.TCHAR
label name.%
TCHAR quoted,0
;: build array of TASKDIALOG_BUTTON:
if % = %%
. equ name
if % = 1
align 4
label name:%%
repeat %%
indx %
dd id
dq name.%
end repeat
. equ name
end if
name.sid RSTRING quoted ; id.sid to expose
dd id
dq name.sid
end iterate
end struc
collect _CONST_
Expand Down
28 changes: 21 additions & 7 deletions mywin.inc
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ iterate reg, rcx,rdx,r8,r9,rax,r10,r11
mov [.P#index],reg
end if
; TODO: not implemented
; else match =_R any,arg
; word_id RSTRING any
; if index < 5
; mov reg32.reg,word_id
; else
; mov [.P#index],word_id
; end if
else match =_R any,arg
word_id RSTRING any
if index < 5
mov reg32.reg,word_id
else
mov [.P#index],word_id
end if
else
; REG===REG ignore nops
; immediate:
Expand Down Expand Up @@ -210,4 +210,18 @@ macro lea? line&
end match
end macro

macro mov? line&
match any=,=<values=>,line
local word_id
match =_R V,values
word_id RSTRING V
else
err ; unsupported type
end match
mov any,word_id
else
mov line
end match
end macro

section '.text' code readable executable
30 changes: 12 additions & 18 deletions samples/CommonButton.inc
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ Common_Buttons_Sample:
enter .FRAME,0
INIT_MY_TD ; copy default structure

lea rax,<_T "Common Buttons Sample">
mov [.cfg.pszWindowTitle],rax
mov [.cfg.pszWindowTitle],<_R "Common Buttons Sample">
mov [.cfg.dwCommonButtons],TDCBF_OK_BUTTON or TDCBF_YES_BUTTON or TDCBF_NO_BUTTON or TDCBF_CANCEL_BUTTON or TDCBF_RETRY_BUTTON or TDCBF_CLOSE_BUTTON

lea rax,[.OnButton]
Expand All @@ -27,9 +26,9 @@ Common_Buttons_Sample:
lea r9,[.table]
cmp r8d,.LAST_COMMON
jnc .id_unknown
lea r9,[r9+r8*8]
lea r9,[r9+r8*2]
.id_unknown:
mov r9,[r9]
movzx r9,word [r9]
SendMessageW rcx,TDM_SET_ELEMENT_TEXT,TDE_MAIN_INSTRUCTION,r9
mov eax,S_FALSE ; do not close dialog
leave
Expand All @@ -38,21 +37,16 @@ Common_Buttons_Sample:
xor eax,eax
retn


align sizeof.TCHAR
.unknown TCHAR "Unknown",0
iterate id, <>,OK,Cancel,<>,Retry,<>,Yes,No,Close
iterate id, <>,Ok,Cancel,<>,Retry,<>,Yes,No,Close
if % = 1
align 2
label .table:2
.LAST_COMMON := %%
end if
match ,id
.% equ .unknown
.% RSTRING "Unknown"
else
.% TCHAR `id," clicked",0
.% RSTRING `id," clicked",0
end match
if % = %%
align 8
label .table:8
repeat %%
dq .%
end repeat
.LAST_COMMON := %%
end if
dw .%
end iterate
4 changes: 1 addition & 3 deletions samples/Counter.inc
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ Counter_Sample:
end virtual
enter .FRAME,0
INIT_MY_TD ; copy default structure

lea rax,<_T "Counter Sample">
mov [.cfg.pszWindowTitle],rax
mov [.cfg.pszWindowTitle],<_R "Counter Sample">
;: create button array, let TaskDialog know:
.btns TD_BUTTONS \
"Increment", BUTTON_INCREMENT,\
Expand Down
6 changes: 2 additions & 4 deletions samples/Elevation.inc
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ Elevation_Required_Sample:
enter .FRAME,0
INIT_MY_TD ; copy default structure

lea rax,<_T "Elevation Requied Sample">
mov [.cfg.pszWindowTitle],rax
lea rax,<_T "Just a button with a shield ...">
mov [.cfg.pszContent],rax
mov [.cfg.pszWindowTitle],<_R "Elevation Requied Sample">
mov [.cfg.pszContent],<_R "Just a button with a shield ...">

.btns TD_BUTTONS \
"Admin Stuff", BUTTON_ADMIN_STUFF
Expand Down
10 changes: 4 additions & 6 deletions samples/EnableDisable.inc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
BUTTON_ENABLE := 0x101
BUTTON_DISABLE := 0x102
BUTTON_ENABLE := 0x101
BUTTON_DISABLE := 0x102

RBUTTON_ABLE := 0x103
RBUTTON_ABLE := 0x103

align 16
Enable_Disable_Sample:
Expand All @@ -14,9 +14,7 @@ Enable_Disable_Sample:
enter .FRAME,0
INIT_MY_TD ; copy default structure

lea rax,<_T "Enable/Disable Sample">
mov [.cfg.pszWindowTitle],rax

mov [.cfg.pszWindowTitle],<_R "Enable/Disable Sample">
;: create button array, let TaskDialog know:
.btns TD_BUTTONS \
"Enable", BUTTON_ENABLE,\
Expand Down
Loading

0 comments on commit 4bf4778

Please sign in to comment.