Skip to content
⌘ NSIS Forum Archive

Writing license text to file

23 posts

Ippi#

Writing license text to file

Is there any way to write a license text to file during installation (e.g. ->"License.txt") in a multilanguage installer (provided that I have a LangString and a LicenseLangString with corresponding source file name)?
bholliger#
Hi Ippi!

As far as I can see, just write the content of the variable $(MUILicense) with FileOpen, FileWrite to a file.

This should work.

Have a nice day!

Cheers

Bruno
glory_man#
Re: Writing license text to file

Originally posted by Ippi
Is there any way to write a license text to file during installation (e.g. ->"License.txt") in a multilanguage installer (provided that I have a LangString and a LicenseLangString with corresponding source file name)?
What are you want to do?
Ippi#
Re: Re: Writing license text to file

Originally posted by bholliger
As far as I can see, just write the content of the variable $(MUILicense) with FileOpen, FileWrite to a file.
Thanks, Bruno, I'll try this method today. Actually, I'm confused by the statement about the LicenseLangString from the NSIS manual: "Does the same as LangString only it loads the string from a text/RTF file and defines a special LangString that can be used only by LicenseData".

Originally posted by glory_man
What are you want to do?
Sorry if I was unclear.
I want to copy to destination location only one of the licenses included with my multilanguage installer - the one that corresponds to selected language. Also I want to rename the license file to "License.txt" while copying (writing?).

Of course, I can do something like multiple "IntCmp $LANGUAGE ${LANG_language} ..." and "File /oname=License.txt "${_language_LICENSE_FILE_}"", but I was looking for more elegant solution.
bholliger#
Hi Ippi!

Yes, this will do the job:


ClearErrors
FileOpen $0 $INSTDIR\license.txt w
IfErrors done
FileWrite $0 "$(MUILicense)"
FileClose $0
done:
Cheers

Bruno
Ippi#
Hi, Bruno!

It does not work really as it should.
It writes only first 1022 bytes of license text, prepending the license data with 0x01 byte (1023 bytes total).

🙁
glory_man#
Yoy can use following code
!include "LogicLib.nsh"
...
LangString name ${LANG_ENGLISH} "eng_name"
LangString name ${LANG_RUSSIAN} "rus_name"
LangString name ${LANG_FRENCH} "fr_name"
...
;copy license file - somewhere in section
${Switch} $LANGUAGE
${Case} ${LANG_ENGLISH}
File "/oname=license.txt" "eng_lic.txt"
${Break}
${Case} ${LANG_RUSSIAN}
File "/oname=license.txt" "rus_lic.txt"
${Break}
${Case} ${LANG_FRENCH}
File "/oname=license.txt" "fr_lic.txt"
${Break}
${EndSwitch}
Ippi#
Originally posted by glory_man
Yoy can use following code
It's exactly what I meant by
Of course, I can do something like multiple "IntCmp $LANGUAGE ${LANG_language} ..." and "File /oname=License.txt "${_language_LICENSE_FILE_}"", but I was looking for more elegant solution.
slightly brushed by LogicLib macroses 🙂
glory_man#
What about this code:

LangString name ${LANG_ENGLISH} "lic_eng.txt"
LangString name ${LANG_RUSSIAN} "lic_rus.txt"

LicenseLangString MUILicense ${LANG_ENGLISH} "lic_eng.txt"
LicenseLangString MUILicense ${LANG_RUSSIAN} "lic_rus.txt"

.....

ClearErrors
FileOpen $0 license.txt w
FileOpen $3 $(name) r
IfErrors done
read:
FileRead $3 $1
IfErrors readfin
Push $1
Pop $1
FileWrite $0 "$1"
goto read
readfin:
FileClose $0
done:
....
Is this
more elegant solution
🙂?
bholliger#
Hi glory_man!

I might be wrong, but I think the file $(name) is not present at runtime. Except you have all the files in the same directory as the installer. Is this the case?

Have a nice day!

Cheers

Bruno
Ippi#
Originally posted by glory_man
[B]What about this code:[/B
bholliger is right, there are no unpacked license files at runtime on a target system.

"File /oname=License.txt $(name)" also does not work (actually, this approach was the first I've tried some days ago 😉)
glory_man#
So, i think easest way is use something like this:
Setoutpath $PLUGINSDIR
File /r "lic\*"
CopyFiles /SILENT "$PLUGINSDIR\$(name)" "PATH\license.txt"
i.e. unpack license file.
Comm@nder21#
nope, that won't work as stated earlier: licence text is parsed on compile time, not on runtime... no license files are present in $PLUGINSDIR.

what i did to solve it is quite easy:
LangString name [...]
SetOutPath "$INSTDIR\licenses"
File "ger_lic.txt"
File "eng_lic.txt"
[...]
Rename "$INSTDIR\licenses\$(name)" "$INSTDIR\license.txt"
RMDir /r "$INSTDIR\licenses" 
basically: extract all files, rename the chosen one to the correct name, delete the rest.
Ippi#
Originally posted by Comm@nder21
extract all files, rename the chosen one to the correct name, delete the rest.
No, thanks 🙂 I'd rather use the dumb ${Switch}...${Case} method 🙄
Ippi#
2 NSIS developers

Why the LicenseLangString is so special that it cannot be written back to file? Look how people are suffering from this 😁
glory_man#
Originally posted by Comm@nder21
nope, that won't work as stated earlier: licence text is parsed on compile time, not on runtime... no license files are present in $PLUGINSDIR.
My example worked.
Move your licenses in to "lic" folder.
Following code extract them in to the PLUGINSDIR

Setoutpath $PLUGINSDIR
File /r "lic\*"
After that just copy file with $(name). After installation temporary files will be deleted.

Originally posted by Ippi
I'd rather use the dumb ${Switch}...${Case} method
🙂
Что за пользователи пошли - то не этак, это не так.
😁 😁 😁
Comm@nder21#
yes, this will work but does not differ very much from my method 🙂 except of the folder the licenses are extracted to on runtime 🙂
Ippi#
Originally posted by glory_man
Что за пользователи пошли - то не этак, это не так.
😁 😁 😁
I don't like the glory_man-Comm@nder21 (🙂) approach because it unnecessarily burdens the CPU, HDD/file system, anti-viral software and still not so elegant as that hypothetic method I've expected to find 😁
glory_man#
Originally posted by Comm@nder21
yes, this will work but does not differ very much from my method 🙂 except of the folder the licenses are extracted to on runtime 🙂
😁 😁 😁
You doesn't need to remember which licenses must be extracted. You can add new license file, and all that you need to do is add one LangString.
🙂 😉 🙂
glory_man#
2 Ippi

Also you can use macro like this:
!macro addlicense language licname folder var1name var2name
!insertmacro MUI_LANGUAGE "${language}"
LangString ${var1name} '"$$""{LANG_${language}"}' "${licname}"
LicenseLangString ${var2name} '"$$""{LANG_${language}"}' "${folder}\${licname}"
!macroend
After that add language, langstring and license using macro, like this code:
!insertmacro addlicense ENGLISH "historyeng.txt" "lic" name MUILicense
!insertmacro addlicense RUSSIAN "historyeng.txt" "lic" name MUILicense
!insertmacro addlicense FRENCH "historyfr.txt" "lic" name MUILicense
Code to extract of license stay previous.

ADD: Is this solution not elegant? 🙂
Ippi#
Originally posted by glory_man
Code to extract of license stay previous.
Just the extraction code embarrasses me, not the declaration part 😉
glory_man#
Originally posted by Ippi
Just the extraction code embarrasses me, not the declaration part 😉
I think extraction of few files of some kilobytes will not make heavy CPU load.

and
2 NSIS developers
Originally posted by Ippi
Why the LicenseLangString is so special that it cannot be written back to file? Look how people are suffering from this 😁