Reputation: 1
I have been trying to use NSIS to create an installer for an application. I tried to add my "changelog.md" 's contents to it and so I created a custom page.
I'm a bit new on this and I can't seem to have the .md file's contents to display properly with the right formatting and linebreaks.
All I need to do is to fill up the text control I created with the whole text.
;--------------------------------
;Pages
Function ReadMarkdownFile
; Open the file for reading
FileOpen $R0 "path\Changelog.md" r
${If} $R0 == ""
MessageBox MB_OK|MB_ICONSTOP "Failed to open the file!"
Abort
${EndIf}
; Initialize the variable to store the file contents
StrCpy $0 ""
; Read the file contents line by line
loop:
FileRead $R0 $R1
${If} $R1 == "" ; Reached the end of the file
Goto done
${EndIf}
StrCpy $0 "$0$R1$\r$\n" ; Append the line to the variable with line breaks
Goto loop
done:
FileClose $R0
FunctionEnd
Function myPageCreate
!insertmacro MUI_HEADER_TEXT "App" "LastUpdate"
nsDialogs::Create 1018
Pop $0
${If} $0 == error
Abort
${EndIf}
; Call the function to read the Markdown file
Call ReadMarkdownFile
${NSD_CreateRichEdit} 0 13u 100% -13u ;this is likely the problem
Pop $0
; Set the contents of the RichEdit control
${NSD_SetText} $0 $0
nsDialogs::Show
FunctionEnd
!insertmacro MUI_PAGE_WELCOME
Page custom myPageCreate
!insertmacro MUI_PAGE_LICENSE "${NSISDIR}\Docs\Modern UI\License.txt"
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
;!insertmacro MUI_PAGE_STARTMENU Application $StartMenuFolder
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
;--------------------------------
I have tried multiple solutions (editing a LICENSE page, ${NSD_CreateRichEdit}, ${NSD_CreateText}, among others) but the farthest I've gotten to was getting the text from said file on a single line.
Thanks for any help you can provide.
Upvotes: 0
Views: 166
Reputation: 101764
First off, neither NSIS nor Windows has native markdown support. If you want fancy formatting then you need to use a .rtf file instead.
Your code has many bugs, you cannot put the RichEdit handle and the text in the same variable! (${NSD_SetText} $0 $0
is never correct).
The easy way to display text on a page is to just use a license page (you can have as many pages as you want):
!include nsDialogs.nsh
PageEx license
Caption ": Readme"
LicenseText "Please read me"
LicenseData "${__FILE__}"
PageExEnd
PageEx license
LicenseData "${NSISDIR}\Copying"
PageExEnd
Page Custom myPageCreate
Page Directory
Page InstFiles
Function myPageCreate
nsDialogs::Create 1018
Pop $0
${NSD_CreateRichEdit} 0 13u 100% -13u ""
Pop $1
FileOpen $0 "${NSISDIR}\Copying" r ; A real installer would copy this file to $pluginsdir and read it from there
StrCmp $0 "" done
ClearErrors
loop:
FileRead $0 $2 ; Read one line
IfErrors done
SendMessage $1 ${EM_SETSEL} "" -1
SendMessage $1 ${EM_SETSEL} -1 ""
SendMessage $1 ${EM_REPLACESEL} "" "STR:$2" ; Append the line
Goto loop
done:
FileClose $0
nsDialogs::Show
FunctionEnd
Section
SectionEnd
Upvotes: 0