Old 13th November 2006, 18:54   #1
Ippi
Junior Member
 
Join Date: Mar 2003
Location: Ukraine
Posts: 45
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)?
Ippi is offline   Reply With Quote
Old 14th November 2006, 01:33   #2
bholliger
Senior Member
 
Join Date: Jul 2004
Location: Switzerland
Posts: 223
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
bholliger is offline   Reply With Quote
Old 14th November 2006, 08:24   #3
glory_man
Senior Member
 
Join Date: Sep 2004
Location: Mogilev (Belarus)
Posts: 372
Re: Writing license text to file

Quote:
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?
glory_man is offline   Reply With Quote
Old 14th November 2006, 09:58   #4
Ippi
Junior Member
 
Join Date: Mar 2003
Location: Ukraine
Posts: 45
Re: Re: Writing license text to file

Quote:
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".

Quote:
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.
Ippi is offline   Reply With Quote
Old 14th November 2006, 10:07   #5
bholliger
Senior Member
 
Join Date: Jul 2004
Location: Switzerland
Posts: 223
Hi Ippi!

Yes, this will do the job:

code:

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



Cheers

Bruno
bholliger is offline   Reply With Quote
Old 14th November 2006, 16:50   #6
Ippi
Junior Member
 
Join Date: Mar 2003
Location: Ukraine
Posts: 45
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).

Ippi is offline   Reply With Quote
Old 14th November 2006, 17:05   #7
glory_man
Senior Member
 
Join Date: Sep 2004
Location: Mogilev (Belarus)
Posts: 372
Yoy can use following code
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}

glory_man is offline   Reply With Quote
Old 14th November 2006, 17:22   #8
Ippi
Junior Member
 
Join Date: Mar 2003
Location: Ukraine
Posts: 45
Quote:
Originally posted by glory_man
Yoy can use following code
It's exactly what I meant by
Quote:
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
Ippi is offline   Reply With Quote
Old 15th November 2006, 08:27   #9
glory_man
Senior Member
 
Join Date: Sep 2004
Location: Mogilev (Belarus)
Posts: 372
What about this code:
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
Quote:
more elegant solution
?
glory_man is offline   Reply With Quote
Old 15th November 2006, 10:53   #10
bholliger
Senior Member
 
Join Date: Jul 2004
Location: Switzerland
Posts: 223
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
bholliger is offline   Reply With Quote
Old 15th November 2006, 11:26   #11
Ippi
Junior Member
 
Join Date: Mar 2003
Location: Ukraine
Posts: 45
Quote:
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 )
Ippi is offline   Reply With Quote
Old 15th November 2006, 17:09   #12
glory_man
Senior Member
 
Join Date: Sep 2004
Location: Mogilev (Belarus)
Posts: 372
So, i think easest way is use something like this:
code:
Setoutpath $PLUGINSDIR
File /r "lic\*"
CopyFiles /SILENT "$PLUGINSDIR\$(name)" "PATH\license.txt"


i.e. unpack license file.
glory_man is offline   Reply With Quote
Old 15th November 2006, 18:14   #13
Comm@nder21
Major Dude
 
Join Date: Jul 2003
Location: germany, b-w
Posts: 734
Send a message via ICQ to 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:
PHP Code:
LangString name [...]

SetOutPath "$INSTDIR\licenses"
File "ger_lic.txt"
File "eng_lic.txt"
[...]
Rename "$INSTDIR\licenses\$(name)" "$INSTDIR\license.txt"
RMDir /"$INSTDIR\licenses" 
basically: extract all files, rename the chosen one to the correct name, delete the rest.
Comm@nder21 is offline   Reply With Quote
Old 15th November 2006, 21:38   #14
Ippi
Junior Member
 
Join Date: Mar 2003
Location: Ukraine
Posts: 45
Quote:
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 is offline   Reply With Quote
Old 15th November 2006, 22:06   #15
Ippi
Junior Member
 
Join Date: Mar 2003
Location: Ukraine
Posts: 45
2 NSIS developers

Why the LicenseLangString is so special that it cannot be written back to file? Look how people are suffering from this
Ippi is offline   Reply With Quote
Old 16th November 2006, 09:33   #16
glory_man
Senior Member
 
Join Date: Sep 2004
Location: Mogilev (Belarus)
Posts: 372
Quote:
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
code:

Setoutpath $PLUGINSDIR
File /r "lic\*"


After that just copy file with $(name). After installation temporary files will be deleted.

Quote:
Originally posted by Ippi
I'd rather use the dumb ${Switch}...${Case} method

Что за пользователи пошли - то не этак, это не так.
glory_man is offline   Reply With Quote
Old 16th November 2006, 11:00   #17
Comm@nder21
Major Dude
 
Join Date: Jul 2003
Location: germany, b-w
Posts: 734
Send a message via ICQ to 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
Comm@nder21 is offline   Reply With Quote
Old 16th November 2006, 11:12   #18
Ippi
Junior Member
 
Join Date: Mar 2003
Location: Ukraine
Posts: 45
Quote:
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
Ippi is offline   Reply With Quote
Old 16th November 2006, 11:22   #19
glory_man
Senior Member
 
Join Date: Sep 2004
Location: Mogilev (Belarus)
Posts: 372
Quote:
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 is offline   Reply With Quote
Old 16th November 2006, 11:55   #20
glory_man
Senior Member
 
Join Date: Sep 2004
Location: Mogilev (Belarus)
Posts: 372
2 Ippi

Also you can use macro like this:
code:
!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:
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?
glory_man is offline   Reply With Quote
Old 16th November 2006, 12:32   #21
Ippi
Junior Member
 
Join Date: Mar 2003
Location: Ukraine
Posts: 45
Quote:
Originally posted by glory_man
Code to extract of license stay previous.
Just the extraction code embarrasses me, not the declaration part
Ippi is offline   Reply With Quote
Old 17th November 2006, 10:58   #22
glory_man
Senior Member
 
Join Date: Sep 2004
Location: Mogilev (Belarus)
Posts: 372
Quote:
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
Quote:
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
glory_man is offline   Reply With Quote
Old 17th November 2006, 11:11   #23
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
The license string is too large. It's over the 1024 bytes limit of internal strings.

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik 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