Old 10th August 2018, 22:06   #1
r2du-soft
Senior Member
 
r2du-soft's Avatar
 
Join Date: Nov 2013
Location: Iran
Posts: 273
Question Read file and write to another file

hi
i read a text file and write that test file strings to a variable

HTML Code:
Unicode True

!include "CharToASCII.nsh"
!include "Base64.nsh"

!include x64.nsh

Var X

Section

ClearErrors
FileOpen $4 "C:\A.txt" r
Read_Try:
IfErrors Read_Try_Closed
FileReadUTF16LE $4 $5
StrCpy $X $X$5
Goto Read_Try
Read_Try_Closed:
FileClose $4
MessageBox MB_Ok "$X"
;----------------------------
ClearErrors
FileOpen $4 "C:\B.txt" w
IfErrors done
FileWriteUTF16LE $4 "$0"
FileClose $4
done:

SectionEnd
But the A.txt file is large...
also i use the: nsis-3.03-strlen_8192.zip file but my string is larger than 8192 bytes
now i need read the all of the text file string in variable,how can do this?


is second question i want know is possible read a exe file informations with FileOpen in variable and after that create empty a exe file and write that variable string (exe bytes) to empty exe file ?
i do this work with FileOpen but after write in the new empty exe file,that exe file not runned!
r2du-soft is offline   Reply With Quote
Old 10th August 2018, 22:37   #2
r2du-soft
Senior Member
 
r2du-soft's Avatar
 
Join Date: Nov 2013
Location: Iran
Posts: 273
Question Read file and write to another file

hi
i read a text file and write that test file strings to a variable

HTML Code:
Unicode True

!include "CharToASCII.nsh"
!include "Base64.nsh"

!include x64.nsh

Var X

Section

ClearErrors
FileOpen $4 "C:\A.txt" r
Read_Try:
IfErrors Read_Try_Closed
FileReadUTF16LE $4 $5
StrCpy $X $X$5
Goto Read_Try
Read_Try_Closed:
FileClose $4
MessageBox MB_Ok "$X"
;----------------------------
ClearErrors
FileOpen $4 "C:\B.txt" w
IfErrors done
FileWriteUTF16LE $4 "$0"
FileClose $4
done:

SectionEnd
But the A.txt file is large...
also i use the: nsis-3.03-strlen_8192.zip file but my string is larger than 8192 bytes
now i need read the all of the text file string in variable,how can do this?


is second question i want know is possible read a exe file informations with FileOpen in variable and after that create empty a exe file and write that variable string (exe bytes) to empty exe file ?
i do this work with FileOpen but after write in the new empty exe file,that exe file not runned!
r2du-soft is offline   Reply With Quote
Old 10th August 2018, 23:39   #3
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,928
If you want to go past the NSIS string limit then you must do all the work yourself with the system plug-in, you cannot use the built-in instructions like StrCpy. You could probably do it line by line if no single line is longer than the limit.

To read/write .exe and other binary files you must read/write single bytes, you cannot parse them as text.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 11th August 2018, 12:31   #4
r2du-soft
Senior Member
 
r2du-soft's Avatar
 
Join Date: Nov 2013
Location: Iran
Posts: 273
i search about system plug-in
but just see this sample..

https://nsis-dev.github.io/NSIS-Foru.../t-204832.html

but i tested that and not give result
r2du-soft is offline   Reply With Quote
Old 11th August 2018, 19:19   #5
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,928
A normal text editor that supports large files will use a file mapping, it will not put the entire thing in memory all at once. If you need that or not depends on how large it actually is. You cannot expect that every system will be able to allocate hundreds of megabytes in a continuous buffer.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Reply
Go Back   Winamp & SHOUTcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump