-
Notifications
You must be signed in to change notification settings - Fork 0
/
fileio.asm
162 lines (108 loc) · 3.54 KB
/
fileio.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
; #########################################################################
ofCallBack proc dwCookie:DWORD,pbBuff:DWORD,cb:DWORD,pcb:DWORD
invoke ReadFile,dwCookie,pbBuff,cb,pcb,NULL
mov eax, 0
ret
ofCallBack endp
; #########################################################################
sfCallBack proc dwCookie:DWORD,pbBuff:DWORD,cb:DWORD,pcb:DWORD
invoke WriteFile,dwCookie,pbBuff,cb,pcb,NULL
mov eax, 0
ret
sfCallBack endp
; #########################################################################
StreamFileIn proc hEdit:DWORD,lpszFileName:DWORD
LOCAL hFile :DWORD
LOCAL fSiz :DWORD
LOCAL ofs :OFSTRUCT
LOCAL est :EDITSTREAM
LOCAL buffer[32]:BYTE
LOCAL aval[8]:BYTE
invoke OpenFile,lpszFileName,ADDR ofs,OF_READ
mov hFile, eax
mov est.dwCookie, eax
mov est.dwError, 0
mov eax, offset ofCallBack
mov est.pfnCallback, eax
invoke SendMessage,hEdit,EM_STREAMIN,SF_TEXT,ADDR est
invoke GetFileSize,hFile,NULL
mov fSiz, eax
invoke CloseHandle,hFile
szText OpenMsg,"Opened at "
szText OpenByt," bytes"
mov buffer[0], 0
invoke szCatStr,ADDR buffer,ADDR OpenMsg
invoke dwtoa,fSiz,ADDR aval
invoke szCatStr,ADDR buffer,ADDR aval
invoke szCatStr,ADDR buffer,ADDR OpenByt
invoke SendMessage,hStatus,SB_SETTEXT,3,ADDR buffer
invoke SendMessage,hEdit,EM_SETMODIFY,0,0
mov eax, 0
ret
StreamFileIn endp
; #########################################################################
StreamFileOut proc hEdit:DWORD,lpszFileName:DWORD
LOCAL hFile :DWORD
LOCAL fSiz :DWORD
LOCAL ofs :OFSTRUCT
LOCAL est :EDITSTREAM
LOCAL buffer[32]:BYTE
LOCAL aval[8]:BYTE
invoke GetWindowTextLength,hEdit
mov fSiz, eax
szText CloseMsg,"Saved at "
szText CloseByt," bytes"
mov buffer[0], 0
invoke szCatStr,ADDR buffer,ADDR CloseMsg
invoke dwtoa,fSiz,ADDR aval
invoke szCatStr,ADDR buffer,ADDR aval
invoke szCatStr,ADDR buffer,ADDR CloseByt
szText sfTest,"Test"
invoke SendMessage,hStatus,SB_SETTEXT,3,ADDR buffer
invoke OpenFile,lpszFileName,ADDR ofs,OF_CREATE
mov hFile, eax
mov est.dwCookie, eax
mov est.dwError, 0
mov eax, offset sfCallBack
mov est.pfnCallback, eax
invoke SendMessage,hEdit,EM_STREAMOUT,SF_TEXT,ADDR est
invoke CloseHandle,hFile
invoke SendMessage,hEdit,EM_SETMODIFY,0,0
mov eax, 0
ret
StreamFileOut endp
; ########################################################################
MergeFile proc hEdit:DWORD
LOCAL poz :DWORD
LOCAL hFile :DWORD
LOCAL hMem :DWORD
LOCAL ln :DWORD
LOCAL br :DWORD
LOCAL Cr :CHARRANGE
jmp @F
szTitleM db "Merge File",0
szFilterM db "All files",0,"*.*",0,
"Text files",0,"*.TEXT",0,0
@@:
mov szFileName[0],0
invoke GetFileName,hWnd,ADDR szTitleM,ADDR szFilterM
cmp szFileName[0],0 ;<< zero if cancel pressed in dlgbox
je @F
invoke CreateFile,ADDR szFileName,
GENERIC_READ,
FILE_SHARE_READ,
NULL,OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL
mov hFile, eax
invoke GetFileSize,hFile,NULL
mov ln, eax
stralloc ln
mov hMem, eax
invoke ReadFile,hFile,hMem,ln,ADDR br,NULL
invoke SendMessage,hEdit,EM_REPLACESEL,0,hMem
strfree hMem
@@:
ret
MergeFile endp
; #########################################################################