read persian text file with using inetc plugin in nsis - nsis

I have many text file with persian text: "سلام"
now I want to read the text file and write to the variable directly
i use from the inetc plugin sample this:
Unicode true
Section
;test_Unicode_BE_BOM.txt:
inetc::get /NOCANCEL /TOSTACK /SILENT "http://update.nodmarket.com/Persian_Text_Files/test_Unicode_BE_BOM.txt" /END
Pop $R0
Pop $R1
MessageBox MB_OK "$R1"
;test_Utf8_BOM.txt
inetc::get /NOCANCEL /TOSTACK /SILENT "http://update.nodmarket.com/Persian_Text_Files/test_Utf8_BOM.txt" /END
Pop $R0
Pop $R1
MessageBox MB_OK "$R1"
;test_Unicode_LE_BOM.txt
inetc::get /NOCANCEL /TOSTACK /SILENT "http://update.nodmarket.com/Persian_Text_Files/test_Unicode_LE_BOM.txt" /END
Pop $R0
Pop $R1
MessageBox MB_OK "$R1"
SectionEnd
but after show i see this text in messagebox:
inetc plugin and source page:
what is the problem?
why i see the broken persian text after read from inetc plugin?
when i use the code
Unicode true
Section
MessageBox MB_OK|MB_RIGHT|MB_RTLREADING "سلام"
SectionEnd
i see "سلام" in messagebox successful
but i think inetc plugin Ruins Persian words!

INetC does not really support Unicode conversion on the fly.
If you need full control you have to download the file to a temporary directory and then read it with NSIS file instructions.
InitPluginsDir
inetc::get /NOCANCEL /SILENT "http://update.nodmarket.com/Persian_Text_Files/test_Unicode_LE_BOM.txt" "$PluginsDir\test.txt" /END
Pop $0
${If} $0 == "OK"
FileOpen $1 "$PluginsDir\test.txt" r
FileReadUTF16LE $1 $2
FileClose $1
MessageBox mb_ok $2
${EndIf}
I uploaded a new version of INetC to the wiki for you with limited UTF-8 and UTF-16LE support (BOM required).
inetc::get /NOCANCEL /TOSTACKCONV /SILENT "http://update.nodmarket.com/Persian_Text_Files/test_Utf8_BOM.txt" /END ; v1.0.5.3+ required for /TOSTACKCONV to support BOM detection.
Pop $R0
Pop $R1
MessageBox MB_OK "$R0:$R1"
Putting Unicode text in a .nsi file works because the NSIS compiler supports Unicode but text returned by a plug-in has its text handling inside the plug-in and it might not support Unicode.

Related

nsis - remove pinned icon from taskbar on uninstall

I'm working on an app for a company and they requested that if the app is pinned to the taskbar, when uninstalling the app should be unpinned. If I just delete the icon from quicklaunch\user pinned\taskbar then it leaves a blank icon on the taskbar.
I need to somehow actually unpin it. The only thing I've come across is installing winshell plugin (http://nsis.sourceforge.net/WinShell_plug-in) and then calling IStartMenuPinnedList::RemoveFromList (https://msdn.microsoft.com/en-us/library/windows/desktop/bb774817(v=vs.85).aspx)
I'd rather not install a plugin if I don't need to. Does anyone have any suggestions?
NSIS does not have native support for this interface so you have to use a plug-in. If you want to avoid that 3rd-party plug-in (written by me) then you can use the System plug-in instead:
!include "LogicLib.nsh"
!include "Win\COM.nsh" ; NSIS v3+
!macro UnpinShortcut lnkpath
Push $0
Push $1
!insertmacro ComHlpr_CreateInProcInstance ${CLSID_StartMenuPin} ${IID_IStartMenuPinnedList} r0 ""
${If} $0 P<> 0
System::Call 'SHELL32::SHCreateItemFromParsingName(ws, p0, g "${IID_IShellItem}", *p0r1)' "${lnkpath}"
${If} $1 P<> 0
${IStartMenuPinnedList::RemoveFromList} $0 '(r1)'
${IUnknown::Release} $1 ""
${EndIf}
${IUnknown::Release} $0 ""
${EndIf}
Pop $1
Pop $0
!macroend
Section Uninstall
!insertmacro UnpinShortcut "$SMPrograms\MyApp.lnk"
Delete "$SMPrograms\MyApp.lnk"
SectionEnd

Load the content of the embedded file into RichEdit control on the custom license page

Requirements / use case:
I have a requirement to implement custom license page in NSIS. The page should look like this: .
On the page I have RichEdit control which has to display the content of a eula.rtf file. This file is available at the compile time and I cannot distribute it separately from the installer, so it has to be somehow embedded into it.
Currently I am using NSIS 2.46 and MUI2. Here is how I create RichEdit control:
nsDialogs::CreateControl /NOUNLOAD "RichEdit20A" ${WS_VISIBLE}|${WS_CHILD}|${WS_TABSTOP}|${WS_VSCROLL}|${ES_MULTILINE}|${ES_WANTRETURN} ${WS_EX_STATICEDGE} 1.32u 56.62u 295.54u 63.38u ""
Pop $hCtl_test_rtLicense
Problem description:
I know that the default MUI2 license page makes use of LicenseData and/or LicenseLangString. As far as I know, in this case the .rtf file is embedded into the installer. Unfortunately I cannot figure out how to load the content from the embedded .rtf file into my RichEdit control, even though I looked through the License.nsh coming with NUI2 and through the NSIS source code as well.
And unfortunately the plugins and scripts I found (LoadRtf plugin, NsRichEdit plugin, this script and one or two more) can only load .rtf file into the RichEdit control at runtime.
Question:
How to load the content from the embedded .rtf file into the RichEdit on the custom page?
If it is not possible, is there any other way to implement my requirement?
The only thing I could think of is wrapping my current installer into another thin NSIS installer which would silently deploy the .rtf file alongside with the current installer. This feels very messy, so I would rather not do that..
The only way to do this is at run-time. To use one of the solutions you linked to you would just extract the .rtf file and call the plugin:
InitPluginsDir ; Initialize $PluginsDir, it is deleted automatically when installer quits
File "/oname=$PluginsDir\lic.rtf" "MyLicense.rtf"
# Call plugin here passing in "$PluginsDir\lic.rtf" as the file to load
Or if you don't want to use 3rd-party plugins:
Page Custom MyPage
Page InstFiles
!include LogicLib.nsh
!include nsDialogs.nsh
!define SF_RTF 2
!define EM_STREAMIN 1097
Function LoadRichRtf
System::Store S
Pop $0 ; hwnd
Pop $1 ; path to rtf
FileOpen $1 $1 r
System::Get "(i, i .R0, i .R1, i .R2)iss"
Pop $2
System::Call "*(*i 0, i 0, k r2)i.r3"
System::Call "USER32::SendMessage(ir0, i${EM_STREAMIN}, i${SF_RTF}, ir3)i.s"
loop:
Pop $0
StrCmp $0 "callback1" 0 done
System::Call 'KERNEL32::ReadFile(ir1, iR0, iR1, iR2, i0)'
Push 0 # callback's return value
System::Call "$2"
Goto loop
done:
System::Free $2
System::Free $3
FileClose $1
System::Store L
FunctionEnd
Var hCtl_test_rtLicense
Function MyPage
nsDialogs::Create 1018
Pop $0
nsDialogs::CreateControl /NOUNLOAD "RichEdit20A" ${WS_VISIBLE}|${WS_CHILD}|${WS_TABSTOP}|${WS_VSCROLL}|${ES_MULTILINE}|${ES_WANTRETURN} ${WS_EX_STATICEDGE} 1.32u 56.62u 295.54u 63.38u ""
Pop $hCtl_test_rtLicense
File "/oname=$PluginsDir\lic.rtf" "c:\some\local\path\License_en_US.rtf"
Push "$PluginsDir\lic.rtf"
Push $hCtl_test_rtLicense
Call LoadRichRtf
nsDialogs::Show
FunctionEnd

NSIS Get file version of EXE that is UPX Compressed

I have been using a little NSIS script for a few years that grabs the version of the EXE so I can display it in the installers welcome text.
I got the script here: http://nsis.sourceforge.net/Invoking_NSIS_run-time_commands_on_compile-time
!define File "C:\MyFile.exe"
OutFile "GetVersion.exe"
SilentInstall silent
Section
## Get file version
GetDllVersion "${File}" $R0 $R1
IntOp $R2 $R0 / 0x00010000
IntOp $R3 $R0 & 0x0000FFFF
IntOp $R4 $R1 / 0x00010000
IntOp $R5 $R1 & 0x0000FFFF
StrCpy $R1 "$R2.$R3.$R4.$R5"
## Write it to a !define for use in main script
FileOpen $R0 "$EXEDIR\Version.txt" w
FileWrite $R0 '!define Version "$R1"'
FileClose $R0
SectionEnd
Recently I started using UPX to compress the EXE of the application.
Now that it is UPX compressed, the file version script no longer works, I'm guessing due to non standard header layout.
How can I read the file version from a UPX compressed EXE?
UPDATE: This is closed now but I discovered later this is likely to do with some kind of elevated permissions issue and running the command over a mapped drive.
Even when using UPX --ultra-brute test.exe the version information block did not get compressed when I tried. Are you using special UPX switches? Have you tried --keep-resource=%resourceid%?
If you are using NSIS v3 you can use !getdllversion to get the version at compile-time without having to use !system.

NSISdl could not open file during download

I'm using NSIS to create an installer which will install files from a web server. I'm using the NSISdl plugin to download the files but they are not downloading, it just says Download Failed: failed to open file.
This is the section which is doing the download, could I be missed something here.
Section "Aquiva"
; Set output path to the installation directory.
SetOutPath $INSTDIR
;Include files from this location, and copy that to the current
;out path
NSISdl::download http://41.78.239.158/Aquiva.exe
Pop $R0 ;Get the return value
StrCmp $R0 "success" +3
MessageBox MB_OK "Download failed: $R0"
Quit
SectionEnd ; end the section
You should use inetc for this purpose:
inetc::get "http://41.78.239.158/Aquiva.exe" "$EXEDIR\Aquiva.exe"
pop $R0
DetailPrint "Result: $R0"
You can get it here
If you insist on using NSISdl, your problem is probably due to not specifying the destination file, try this:
NSISdl::download http://41.78.239.158/Aquiva.exe "$INSTDIR\Aquiva.exe"
pop $R0
...

x64.nsh not working

I have encountered a piece of code in the web...
I have 64.nsh in my machine and as an example I have included in my code the following:
${If} ${RunningX64}
MessageBox MB_OK "running on x64"
${EndIf}
And it returns:
!insertmacro:
_If !insertmacro: macro "_If" requires 4 parameter(s), passed 2!
Could you help?
Thanks in advance!
Having the file on your system is not enough, you need to include the file in your code:
!include "x64.nsh"
${If} ${RunningX64}
MessageBox MB_OK "running on x64"
${EndIf}

Resources