The MASM Forum

Projects => MasmBasic & the RichMasm IDE => Topic started by: clamicun on September 03, 2017, 11:24:54 PM

Title: Copy into Files$
Post by: clamicun on September 03, 2017, 11:24:54 PM
jj bom dia,

store_file exists

mov hMem,alloc(5000000)
INVOKE CreateFile,offset store_file,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0 
mov filehandle,eax   
INVOKE GetFileSize,filehandle,0 
mov myfilesize,eax
INVOKE  ReadFile,filehandle,hMem,myfilesize,offset BytesRead,0   
INVOKE CloseHandle,filehandle

Is there a possibility to get the content of hMem into Files$ before free hMem   ?
Title: Re: Copy into Files$
Post by: clamicun on September 03, 2017, 11:45:08 PM
One more question...

Let esi = "C:\"
GetFolders esi   
mov dirs_found,eax
mov eax, ustr$(dirs_found)
Store offset store_file,Files$()

Is there a possibility to write eax=dirs_found somewhere into store_file ?
Preferably as first line. 

Excuse the many questions.
Title: Re: Copy into Files$
Post by: jj2007 on September 04, 2017, 02:26:28 AM
Quote from: clamicun on September 03, 2017, 11:24:54 PMIs there a possibility to get the content of hMem into Files$ before free hMem  ?

The part before is easy:

include \masm32\MasmBasic\MasmBasic.inc         ; download (http://masm32.com/board/index.php?topic=94.0)
hMem   dd ?
store_file      db "stored_temp.txt", 0

  Init
  FileWrite offset store_file, "Hello"  ; make sure it exists
  Let hMem=FileRead$(offset store_file)
  Inkey "[", hMem, "]"
EndOfCode


But I assume you want to insert a line before the Store "MyFiles.txt", Files$(), right?

include \masm32\MasmBasic\MasmBasic.inc         ; download (http://masm32.com/board/index.php?topic=94.0)
  Init
  GetFolders "\Masm32\Examples"
  xchg eax, ecx                         ; save the count
  Insert Files$(0)
  Let Files$(0)=Str$("GetFolders() found %i folders in \Masm32\Examples", ecx)
  Store "ExampleFolders.txt", Files$()
  Inkey Str$("%i folders found. Wanna see them (y)?", ecx)
  If_ eax=="y" Then ShEx "ExampleFolders.txt"   ; opens Notepad etc
EndOfCode
Title: Re: Copy into Files$
Post by: clamicun on September 04, 2017, 05:00:35 AM
beautiful,
thanks a lot.

Let esi="MasmBasic is great"

Title: Re: Copy into Files$
Post by: clamicun on September 04, 2017, 06:09:35 AM
Think I was a bit too fast with "beautiful".

This is perfect.

include \masm32\MasmBasic\MasmBasic.inc         ; download
  Init
  GetFolders "C:\"
  xchg eax, ecx                         ; save the count
  Insert Files$(0)
  Let Files$(0)=Str$("%i", ecx)
  Store "Folders_C.txt", Files$()
  EndOfCode

But this is not what I meant.

hMem   dd ?
store_file      db "Folders_C.txt", 0
  Init
  ;FileWrite offset store_file, "Hello"  ; make sure it exists
  Let hMem=FileRead$(offset store_file)
  Inkey "[", hMem, "]"
EndOfCode

But...
Read the existing "Folders_C.txt and mov the content into Files$ for further use.
Something like...

mov hMem,alloc(5000000)
INVOKE CreateFile,offset store_file,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0 
mov filehandle,eax   
INVOKE GetFileSize,filehandle,0 
mov myfilesize,eax
INVOKE  ReadFile,filehandle,hMem,myfilesize,offset BytesRead,0   
INVOKE CloseHandle,filehandle

Now I have the storefile in hMem and want to get it into MasmBasics Files$ 

Title: Re: Copy into Files$
Post by: jj2007 on September 04, 2017, 08:49:34 AM
As shown in my first reply, Let hMem=FileRead$(filename$) can load content. But filename$ seems to be a folder name here, so what content do you want to load?

Of course, you can do something like this (project attached):

include \masm32\MasmBasic\MasmBasic.inc         ; download (http://masm32.com/board/index.php?topic=94.0)
  Init
  Dim content$()
  GetFiles \Masm32\Examples\*.asm|*.rc
  For_ ecx=0 To eax-1
        mov esi, Files$(ecx)
        Let content$(ecx)="Content of "+esi+cfm$(":\n")+FileRead$(esi)
  Next
  Insert content$(0)
  Let content$(0)=Str$("%i files found", ecx-1)
  Store "ContentExamplesAsmRC.txt", content$()
  Inkey content$(0), " - open as text(y)?"
  If_ eax=="y" Then Launch "\Masm32\MasmBasic\RichMasm.exe ContentExamplesAsmRC.txt#Content of"
EndOfCode


But this stores the contents of files, not folders (what is the content of folders??).

P.S.: Attention, the content$() array in the example above can quickly become really huge. The ..\examples asm and rc files are harmless, but C:\ cannot work...! If you plan to write gigabytes of content to disk, you need to wrtite sequentially.
Title: Re: Copy into Files$
Post by: clamicun on September 04, 2017, 07:09:35 PM
jj,
excuse me.
I seem to be quite ununderstandable.

store_file db "stored_Folders.txt",0
I have a file "stored_Folders.txt (it exists).

I open the file and read it into memory.

mov hMem,alloc(5000000)
INVOKE CreateFile,offset store_file,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0
mov filehandle,eax   
INVOKE GetFileSize,filehandle,0
mov myfilesize,eax
INVOKE  ReadFile,filehandle,hMem,myfilesize,offset BytesRead,0   
INVOKE CloseHandle,filehandle

Now I have the storefile in hMem.

This might be the same  in one line ?
Let esi=FileRead$("stored_Folders.txt")

FileRead$ stores the content where ?

How can I get the content of hMem into Files$ or some other array to use it ?
Title: Re: Copy into Files$
Post by: jj2007 on September 04, 2017, 07:22:06 PM
Let esi means content goes to buffer to which esi points. Same for Let content$(ct)=whatever
Title: Re: Copy into Files$
Post by: clamicun on September 04, 2017, 09:23:17 PM
yes I know.

Let hMem=FileRead$(offset store_file)
or
Let esi=FileRead$(offset store_file)

hMem or esi have the adress of the string.

This is my one and only problem.
How can I get the content of hMem or esi back  into Files$ or some other array ! to use it like this ?

xor ecx,ecx
.repeat
INVOKE lstrcpy,offset somewhere,Files$(ecx) ; (or other array)   
inc ecx
do something
.until

StringToArray ??

If I am on your nerves leave it.
I 'll find out.
Title: Re: Copy into Files$
Post by: jj2007 on September 05, 2017, 01:23:48 AM
Quote from: clamicun on September 04, 2017, 09:23:17 PMHow can I get the content of hMem or esi back  into Files$ or some other array ! to use it like this ?

You assign it directly to an array element:

Dim some$()
...
Let some$(123)=FileRead$(filename)  ; assign content
...
Print some$(123)  ; use it
Title: Re: Copy into Files$
Post by: clamicun on September 05, 2017, 10:12:07 PM
Well jj,
seems that we won't get together on this topic.

And anyway ... I will give up on MasmBasic - at least for a while.
The following prooves that I have't got any idea what it does.

This works....
include \masm32\MasmBasic\MasmBasic.inc
   
Init      

Dim A$()      ; first array
Dim B$()      ; second array
For_ ecx=0 To 9      ; ten loops
Let A$(ecx)=Str$("String A %i", ecx)      ; fill with more or less...
Let B$(ecx)=Str$("String B %i", ecx)           ; ... meaningful stuff
Next
ArrayMerge A$(), B$()                             ; A$(): 10xA, then 10xB; array B$() gets erased
For_ ecx=0 To 19                             ; twenty loops
PrintLine Str$("Element %_i\t", ecx), A$(ecx)
Next
Inkey
Exit debug   
end start       

This doesn't....
include \masm32\MasmBasic\MasmBasic.inc

.code
start:    

Dim A$()      ; first array
Dim B$()      ; second array
For_ ecx=0 To 9      ; ten loops
Let A$(ecx)=Str$("String A %i", ecx)      ; fill with more or less...
Let B$(ecx)=Str$("String B %i", ecx)           ; ... meaningful stuff
Next
ArrayMerge A$(), B$()                             ; A$(): 10xA, then 10xB; array B$() gets erased
For_ ecx=0 To 19                             ; twenty loops
PrintLine Str$("Element %_i\t", ecx), A$(ecx)
Next
Inkey
Exit debug   
end start     

Problemereignisname:   APPCRASH
  Anwendungsname:   jj2.exe
  Anwendungsversion:   0.0.0.0
  Anwendungszeitstempel:   59ae8f1c
  Fehlermodulname:   ntdll.dll
  Fehlermodulversion:   6.1.7601.23864
  Fehlermodulzeitstempel:   595fa4f4
  Ausnahmecode:   c0000005
  Ausnahmeoffset:   00052a0e
  Betriebsystemversion:   6.1.7601.2.1.0.256.1
  Gebietsschema-ID:   1031
  Zusatzinformation 1:   0a9e
  Zusatzinformation 2:   0a9e372d3b4ad19135b953a78882e789
  Zusatzinformation 3:   0a9e
  Zusatzinformation 4:   0a9e372d3b4ad19135b953a78882e789

Since 2 years I thought

.code
start:
end start

is the same as

Init
end start
Title: Re: Copy into Files$
Post by: jj2007 on September 05, 2017, 11:37:13 PM
Quote from: clamicun on September 05, 2017, 10:12:07 PMSince 2 years I thought

.code
start:
end start

is the same as

Init
end start

Not exactly. The Init macro initialises several important things, inter alia it loads a global variable with the process heap required by the Dim statements. That's why Dim crashes without Init.

Rem - the Init macro inserts at least the following two lines:
.code
start: call MbBufferInit
- using Init is optional; it declares the code section, the start label, and preloads some strings (CrLf$, Tb$ etc.);
  however, the check for these preloaded strings will be performed in the first Print or Let statement, too.
- use Init tc [, con/key/box] to install a Structured Exception Handler with Try/Catch (\MasmBasic\details).


So this will work without crashes:.code
start: call MbBufferInit
Title: Re: Copy into Files$
Post by: clamicun on September 06, 2017, 12:48:32 AM
Many many thanks for all your patience
Title: Re: Copy into Files$
Post by: jj2007 on September 06, 2017, 01:21:58 AM
No problem, such feedback is important for me. Still, I'd like to understand better what are your goals here...
Title: Re: Copy into Files$
Post by: clamicun on September 06, 2017, 10:37:40 AM
This is part of my "private" Searchprogram".
Better than all professioals. Ultrasearch, Wisesearch haha...

You pick the folder and the filetype
xor ecx,ecx
push ecx                                                                      ;lstrcpy changes ecx
INVOKE lstrcpy,offset path_file_type,Files$(ecx)              ;Verzeichnis 0
INVOKE lstrcat,offset path_file_type,offset slash              ;+ slash
INVOKE lstrcpy,offset current_path,offset path_file_type  ;Verzeichnis in current_path für LoadListView
INVOKE lstrcat,offset path_file_type,offset file_type         ;FileType *.xxx anhängen 

(I probably could do this directly with Files$ ?)

INVOKE FindFirstFile,offset path_file_type,offset wfd
"
"
Get the data you need (size, time, attribute, path) for LoadListView

GetFiles is usually faster, but GetFolders has the advantage that you have to do it only once, if you search for different filetypes in the same folder.

GetFiles you have to do every time for a different filetype
GetFiles C:\Windows\*.txt  GetFiles C:\Windows\*.exe ....

The problem always is C:\ ... can take a while.

So the idea is to store the folders of C:\ in the storefile  and read it into an array if you need it.
That is faster than to count the folders again.

Seems this does it.

Dim folderarray$()
Let esi=FileRead$("Folders_C.txt") 
StringToArray esi,folderarray$()

And do the same as above
INVOKE lstrcpy,offset path_file_type,folderarray$(ecx)
INVOKE lstrcat,offset path_file_type,offset slash             ;+ slash
INVOKE lstrcat,offset path_file_type,offset file_type         ;FileType *.xxx anhängen

Of course you have to renew the storefile once in a while.

 
Title: Re: Copy into Files$
Post by: jj2007 on September 06, 2017, 10:57:36 AM
Quote from: clamicun on September 06, 2017, 10:37:40 AM
GetFiles you have to do every time for a different filetype
GetFiles C:\Windows\*.txt  GetFiles C:\Windows\*.exe ....

You don't need that:

include \masm32\MasmBasic\MasmBasic.inc         ; download (http://masm32.com/board/index.php?topic=94.0)
  Init
  GfNoRecurse=1                 ; for this test, don't dive into subfolders
  GetFiles C:\Windows\System32\a*.exe|b*.dll|*.scr      ; use the "or" character to separate search masks
  For_ ecx=0 To eax-1           ; print the results
       PrintLine Str$(GfSize(ecx)), Tb$, GfDate$(ecx), Spc2$, GfTime$(ecx), Tb$, Files$(ecx)
  Next
EndOfCode


Output (a*.exe, b*.dll, all screen savers):38912   14.07.2009  03:14:11    C:\Windows\System32\AdapterTroubleshooter.exe
172224  21.08.2013  22:06:34    C:\Windows\System32\appverif.exe
20992   14.07.2009  03:14:12    C:\Windows\System32\ARP.EXE
24064   14.07.2009  03:14:12    C:\Windows\System32\at.exe
29184   14.07.2009  03:14:12    C:\Windows\System32\AtBroker.exe
16384   14.07.2009  03:14:12    C:\Windows\System32\attrib.exe
50176   07.07.2017  16:51:57    C:\Windows\System32\auditpol.exe
668160  21.11.2010  04:23:53    C:\Windows\System32\autochk.exe
679424  21.11.2010  04:23:48    C:\Windows\System32\autoconv.exe
658944  21.11.2010  04:23:53    C:\Windows\System32\autofmt.exe
144768  21.11.2010  04:24:28    C:\Windows\System32\basecsp.dll
740864  21.11.2010  04:23:54    C:\Windows\System32\batmeter.dll
82944   07.07.2017  17:11:12    C:\Windows\System32\bcrypt.dll
249352  12.05.2016  15:04:55    C:\Windows\System32\bcryptprimitives.dll
34304   14.07.2009  03:14:59    C:\Windows\System32\bidispl.dll
171520  14.07.2009  03:14:59    C:\Windows\System32\BioCredProv.dll
19456   21.11.2010  04:24:01    C:\Windows\System32\bitsperf.dll
10752   14.07.2009  03:14:59    C:\Windows\System32\bitsprx2.dll
10240   14.07.2009  03:14:59    C:\Windows\System32\bitsprx3.dll
9216    14.07.2009  03:14:59    C:\Windows\System32\bitsprx4.dll
18432   14.07.2009  03:14:59    C:\Windows\System32\bitsprx5.dll
10240   14.07.2009  03:14:59    C:\Windows\System32\bitsprx6.dll
744960  14.06.2016  17:21:18    C:\Windows\System32\blackbox.dll
21584   14.07.2009  03:26:15    C:\Windows\System32\BOOTVID.DLL
41984   04.07.2012  23:14:34    C:\Windows\System32\browcli.dll
10752   21.11.2010  04:24:00    C:\Windows\System32\browseui.dll
66560   14.07.2009  03:15:00    C:\Windows\System32\btpanui.dll
64000   14.07.2009  03:15:00    C:\Windows\System32\BWContextHandler.dll
10752   14.07.2009  03:15:00    C:\Windows\System32\BWUnpairElevated.dll
878592  21.11.2010  04:25:09    C:\Windows\System32\Bubbles.scr
221184  21.11.2010  04:25:09    C:\Windows\System32\Mystify.scr
413696  21.11.2010  04:25:14    C:\Windows\System32\PhotoScreensaver.scr
220672  21.11.2010  04:25:09    C:\Windows\System32\Ribbons.scr
10240   14.07.2009  03:14:09    C:\Windows\System32\scrnsave.scr
293888  21.11.2010  04:25:09    C:\Windows\System32\ssText3d.scr


QuoteSo the idea is to store the folders of C:\ in the storefile  and read it into an array if you need it.
That is faster than to count the folders again.

Seems this does it.

Dim folderarray$()
Let esi=FileRead$("Folders_C.txt") 
StringToArray esi,folderarray$()

And do the same as above
INVOKE lstrcpy,offset path_file_type,folderarray$(ecx)
INVOKE lstrcat,offset path_file_type,offset slash             ;+ slash
INVOKE lstrcat,offset path_file_type,offset file_type         ;FileType *.xxx anhängen

Of course you have to renew the storefile once in a while.

Reasonable idea :t

Dim folderarray$()
Let esi=FileRead$("Folders_C.txt") 
StringToArray esi,folderarray$()


can be replaced by
Recall "Folders_C.txt", folderarray$()