PC installer desktop shortcut and uninstall confirmation - localization

Currently working with NSIS to create an installer for my PC game, was wondering if there is a way (some default command) to be able to do the 2 following things :
Prompt the user for confirmation when he uninstalls the game (I am currently doing it manually (AKA messagebox) but my problem is that it's always in English (I pretty much want the message to be localized, am wondering if there is a default option to prompt the user that would be localized by default, like the rest of the installer).
Ask to create desktop shortcut (again, I am doing this using the MUI_FINISHPAGE_SHOWREADME_TEXT, but my text isn't localised)
If there are no default ways of doing this what would be the best way to go to be able to localise those two sentences in my installer ?

There is a uninstall confirm page you can use:
!include MUI2.nsh
...
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_LANGUAGE English
You can localize strings by using LangStrings:
!include MUI2.nsh
!insertmacro MUI_PAGE_INSTFILES
!define MUI_FINISHPAGE_SHOWREADME
!define MUI_FINISHPAGE_SHOWREADME_TEXT "$(FinishDeskLnkCheck)"
!define MUI_FINISHPAGE_SHOWREADME_FUNCTION CreateDeskLnk
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_LANGUAGE English
!insertmacro MUI_LANGUAGE Swedish
LangString FinishDeskLnkCheck ${LANG_ENGLISH} "Create Desktop shortcut?"
LangString FinishDeskLnkCheck ${LANG_SWEDISH} "Bork Desktop bork bork?"
Function .onInit
!define MUI_LANGDLL_ALWAYSSHOW
!define MUI_LANGDLL_ALLLANGUAGES
!insertmacro MUI_LANGDLL_DISPLAY
FunctionEnd
; NOTE: Uninstaller langstring names must be prefixed with "un."
LangString ConfirmUninstMsg ${LANG_ENGLISH} "Kill it?"
LangString ConfirmUninstMsg ${LANG_SWEDISH} "Bork it?"
Function TranslateMsgBoxExample
MessageBox MB_YESNO "$(ConfirmUninstMsg)"
FunctionEnd
Function CreateDeskLnk
; CreateShortcut ...
Call TranslateMsgBoxExample
FunctionEnd
The text on the buttons in a MessageBox is going to use the current users UI language and cannot be translated...

Related

GetLocaleInfo in NSIS

I'm trying to get locale infos in NSIS (using this code).
As my system is in french, I'd hope to get a string like "fr-FR", but I'm getting chineese synbols instead :/
Any idea of what I'm doing wrong?
!define LOCALE_ILANGUAGE '0x1' ;System Language Resource ID
!define LOCALE_SLANGUAGE '0x2' ;System Language & Country [Cool]
!define LOCALE_SABBREVLANGNAME '0x3' ;System abbreviated language
!define LOCALE_SNATIVELANGNAME '0x4' ;System native language name [Cool]
!define LOCALE_ICOUNTRY '0x5' ;System country code
!define LOCALE_SCOUNTRY '0x6' ;System Country
!define LOCALE_SABBREVCTRYNAME '0x7' ;System abbreviated country name
!define LOCALE_SNATIVECTRYNAME '0x8' ;System native country name [Cool]
!define LOCALE_IDEFAULTLANGUAGE '0x9' ;System default language ID
!define LOCALE_IDEFAULTCOUNTRY '0xA' ;System default country code
!define LOCALE_IDEFAULTCODEPAGE '0xB' ;System default oem code page
Function getLocale
System::Call 'kernel32::GetSystemDefaultLangID() i .r0'
System::Call 'kernel32::GetLocaleInfoA(i 1024, i ${LOCALE_SNATIVELANGNAME}, t .r1, i ${NSIS_MAX_STRLEN}) i r0'
System::Call 'kernel32::GetLocaleInfoA(i 1024, i ${LOCALE_SNATIVECTRYNAME}, t .r2, i ${NSIS_MAX_STRLEN}) i r0'
System::Call 'kernel32::GetLocaleInfoA(i 1024, i ${LOCALE_SLANGUAGE}, t .r3, i ${NSIS_MAX_STRLEN}) i r0'
MessageBox MB_OK|MB_ICONINFORMATION "Your System LANG Code is: $0. $\r$\nYour system language is: $1. $\r$\nYour system language is: $2. $\r$\nSystem Locale INFO: $3."
FunctionEnd
Same kind of error with these constants:
!define LOCALE_SISO639LANGNAME 0x00000059 ; ISO abbreviated language name, eg "en"
!define LOCALE_SISO3166CTRYNAME 0x0000005A ; ISO abbreviated country/region name, eg "US"
Change GetLocaleInfoA to GetLocaleInfo. NSIS v3 will autodetect the A/W function when the t type parameter is used.
Ansi strings when interpreted as Unicode tends to look like Chinese.

Nexmo VoiceXML not working in language other than en-US

I have a running VoiceXML application that works ok in Nexmo. If I set any language other than en-US the calls want get answered. I just change en xml:lang as in:
<vxml application="/dialogue/root/50b9bab0-9ce8-4d7a-9389-09f06aa8f9ee" version="2.1" xml:lang="es-es">
I have tried in the vxml above and also in the prompt tag. Any language like es-es, es-ES... even en-UK will make my vxml stop working in Nexmo.
I am sure script is OK as I can change en-US female and male voice with en-us-male and en-us-female. That works.
Am I missing something?
(I don't think it makes a difference but I use the great Rivr java library to generated vxml)
for me "fr-ca" doesnt work but "fr-ca-female" does work

How to make TextEdit links clickable

This script is supposed to open a series of web pages in a new browser window, and then open TextEdit with predetermined text and links.
Safari does what it is supposed to.
Text edit opens and pastes the text I want, but the links are not clickable.
I know I could just right click and choose Substitutions> Add Links> myself, but I am trying to automate the entire process.
I appreciate your time and efforts on my behalf! Thank you!
OpenWebPages()
OpenTextEditPage()
to OpenTextEditPage()
-- Create a variable for text
set docText to ""
tell application "TextEdit"
activate
make new document
-- Define the text to be pasted into TextEdit
set docText to docText & "Some text to show in TextEdit." & linefeed & "
My favorite site about coding is http://stackoverflow.com/
My favorite site for paper modeling is http://www.ss42.com/toys.html
My favorite site for inventing is http://www.instructables.com/howto/bubble+machine/
" & linefeed & "Click the links above to improve your mind!" as string
-- Past the above text and links into TextEdit
set the text of the front document to docText & "" as string
tell application "System Events"
tell process "TextEdit"
-- highlight all text
keystroke "a" using command down
-- Think of a clever way to right click and choose Substitutions> Add Links>
-- Or think of another clever way to turn all URLs into links please.
end tell
end tell
end tell
end OpenTextEditPage
to OpenWebPages()
-- Start new Safari window
tell application "Safari"
-- activate Safari and open the StackOverflow AppleScript page
make new document with properties {URL:"http://stackoverflow.com/search?q=applescript"}
-- Yoda is watching you
open location "http://www.ss42.com/pt/Yoda/YodaGallery/yoda-gallery.html"
-- Indoor boomerang
open location "http://www.ss42.com/pt/paperang/paperang.html"
-- Are you a Human ?
open location "http://stackoverflow.com/nocaptcha?s=f5c92674-b080-4cea-9ff2-4fdf1d6d19de"
end tell
end OpenWebPages
According to this question I built this little handler. It takes a path to your rtf-file like makeURLsHyper((path to desktop folder as string) & "TestDoc.rtf") and worked quite fine in my little tests. But it doesn't care about text formatting at this point.
on makeURLsHyper(pathOfRtfFile)
-- converting the given path to a posix path (quoted for later use)
set myRtfPosixPath to quoted form of (POSIX path of pathOfRtfFile)
-- RTF Hyperlink start
set rtfLinkStart to "{\\\\field{\\\\*\\\\fldinst HYPERLINK \""
-- RTF Hyperlink middle
set rtfMiddlePart to "\"}{\\\\fldrslt "
-- RTF Hyperlink end
set rtfLinkEnd to "}}"
-- use sed to convert http-strings to rtf hyperlinks
set newFileContent to (do shell script "sed -i bak -e 's#\\(http[^[:space:]]*\\)#" & rtfLinkStart & "\\1" & rtfMiddlePart & "\\1" & rtfLinkEnd & "#g' " & myRtfPosixPath)
end makeURLsHyper
Have a nice day, Michael / Hamburg

Applescript path to not working in Mountain Lion

This script has been working on 10.7 and older, but in 10.8, it seems it's broken. The line:
set theFilePath to ((path to application support from user domain) as rich text) & "AppFolderName:" & UniqueName as string
set theFileReference to open for access theFilePath with write permission
Worked fine on previous versions, but Apple apparently is preventing it from working properly on Mountain Lion. Is there any other way of getting access to that folder via Apple script in Mountain Lion?
Edit: I've included the entire code of the script that will, within a Mail rule export the entire message to a text file that my program can import. The text file is sent to ~/Library/Application Support/MyProgram/MailImport/
Make sure the directory already exists on your machine, as it does here on mine, and the Apple Script doesn't do any checking for it.
This script does not work when path to application support is in the code, but changing it to path to desktop work fine, meaning there is an issue writing to the application support folder, but the code works.
To test, you can create a new rule in Mail, and have Every Message run the script. You have to put the script in ~/Library/Application Scripts/com.apple.mail/
It will then appear as an option in the rules window. You can right-click a message and select Apply Rules to test the script on an individual message.
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
tell application "Mail"
repeat with eachMessage in theMessages
set sub to subject of eachMessage
set mid to message id of eachMessage
set sen to sender of eachMessage
set recp to ""
repeat with thisRecpt in recipients of eachMessage
set recp to recp & address of thisRecpt & ","
end repeat
set {year:y, month:m, day:d, hours:hh, minutes:mm} to (date sent of eachMessage)
set dat to (y * 10000 + m * 100 + d) as string
set tim to (hh * 100 + mm) as string
set con to content of eachMessage
set TotalString to "<!STDMessageSubject>" & sub & "<!STDMessageSubject>" & "<!STDMessageID>" & mid & "<!STDMessageID>" & "<!STDMessageSender>" & sen & "<!STDMessageSender>" & "<!STDMessageRecipient>" & recp & "<!STDMessageRecipient>" & "<!STDMessageDate>" & dat & "<!STDMessageDate>" & "<!STDMessageTime>" & tim & "<!STDMessageTime>" & "<!STDMessageContent>" & con & "<!STDMessageContent>"
set UniqueName to do shell script "uuidgen"
set theFilePath to ((path to application support from user domain) as rich text) & "MyApplication:MailImport:" & UniqueName as string
set theFileReference to open for access theFilePath with write permission
write TotalString to theFileReference
close access theFileReference
end repeat
end tell
end perform mail action with messages
end using terms from
There's no such thing in applescript as "rich text". It should only be as "text". In addition theFilePath is a string, so in the next line you need to reference it like this... open for access file theFilePath. Notice the word "file". You need that word there to turn the string into a file reference which is what that command requires.
EDIT: Now that I see your entire code I would write it like this. Your problem still may be a sandboxing issue but at the very least you should eliminate any sources of possible coding errors in your script. This will give you the best chance of having a successful script. If it still doesn't work then it probably is a sandboxing issue.
The basic coding issues that I see are that you are telling Mail to perform all of the commands. Mail doesn't know commands such as "path to application support", "do shell script", or how to write to a file. They're applescript commands so you shouldn't tell Mail to perform them. They are not in Mail's applescript dictionary and thus they may be getting confused when Mail tries to perform them. That's certainly the reason that "text" keeps changing to "rich text" as you mention.
So give this a try. If you still have the problem then at least you know that you've done all you can to eliminate sources of errors in your code.
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
tell application "Mail"
repeat with eachMessage in theMessages
set sub to subject of eachMessage
set mid to message id of eachMessage
set sen to sender of eachMessage
set recp to ""
repeat with thisRecpt in recipients of eachMessage
set recp to recp & address of thisRecpt & ","
end repeat
set {year:y, month:m, day:d, hours:hh, minutes:mm} to (date sent of eachMessage)
set dat to (y * 10000 + m * 100 + d) as string
set tim to (hh * 100 + mm) as string
set con to content of eachMessage
set TotalString to "<!STDMessageSubject>" & sub & "<!STDMessageSubject>" & "<!STDMessageID>" & mid & "<!STDMessageID>" & "<!STDMessageSender>" & sen & "<!STDMessageSender>" & "<!STDMessageRecipient>" & recp & "<!STDMessageRecipient>" & "<!STDMessageDate>" & dat & "<!STDMessageDate>" & "<!STDMessageTime>" & tim & "<!STDMessageTime>" & "<!STDMessageContent>" & con & "<!STDMessageContent>"
my writeToFile(TotalString)
end repeat
end tell
end perform mail action with messages
end using terms from
on writeToFile(TotalString)
set UniqueName to do shell script "uuidgen"
set theFilePath to ((path to application support from user domain) as text) & "MyApplication:MailImport:" & UniqueName
set theFileReference to open for access file theFilePath with write permission
write TotalString to theFileReference
close access theFileReference
end writeToFile
EDIT2: try this handler in place of the one in the above code. This may be one way to make the writeToFile handler work because the writing part would happen in a separate process from the applescript. It's worth a try!
on writeToFile(TotalString)
set UniqueName to do shell script "uuidgen"
set theFilePath to ((path to application support from user domain) as text) & "MyApplication:MailImport:" & UniqueName
set theResult to do shell script "echo " & quoted form of TotalString & " > " & quoted form of POSIX path of theFilePath
end writeToFile
EDIT3: if edit2 doesn't work then look here. It seems others have had problems with Mail writing to certain locations and solved it by adding a key to Mail to give it permission.
So it turns out to be a Sandboxing issue. Apple Mail in 10.8 uses a Sandboxed Application Support folder location in general regardless of how hard you try to just get ~/Library/Application Support/, so from an AppleScript within Mail on 10.8
path to application support from user domain
Returns the path
~/Library/Containers/com.apple.mail/Data/Library/Application Support/
From there the MyApplication:MailImport: folders can be created and accessed. Since our actual program that's trying to read the output isn't sandboxed we can just read and access the data from that location for now, as it seems to be working fine.

NSIS works with LangString incorrectly

I have an installer, it builds automatically (on TFS) by using NSIS command line features
"..\..\NSIS\makensis.exe" /DBUILD_NUMBER=28311 /DPRODUCT_LANGUAGE=English "MTService_setup.nsi"
The installer must use language, which specified in PRODUCT_LANGUAGE parameter. I've done it in the following way
!insertmacro MUI_LANGUAGE "${PRODUCT_LANGUAGE}"
When I build installer in such way, the common language of the interface is correct. But it uses default system language for LangString. So, if default system language is not English, it shows LangString on another language in the English installer.
I've tried to change script to avoid command line parameters (for test purposes)
!insertmacro MUI_LANGUAGE "English"
It doesn't work too.
I've tried to change script to
!insertmacro MUI_LANGUAGE "English"
!insertmacro MUI_LANGUAGE "Russian"
Function .onInit
!insertmacro MUI_LANGDLL_DISPLAY
FunctionEnd
It works, but, of course, it shows language selection dialog. I want to use specific ${PRODUCT_LANGUAGE} without any dialog.
So, how can I fix it?
You did not show us your LangString code in your example so it is hard to say what the problem is!
Here is a working example based on code in the MUI readme:
Outfile "test.exe"
Requestexecutionlevel user
!include MUI2.nsh
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE Swedish ;First language is the default if a better match is not found
!insertmacro MUI_LANGUAGE Danish
Function .onInit
StrCpy $language ${LANG_DANISH} ;Always force Danish?
FunctionEnd
Section "Section Name 1" Section1
SectionEnd
Section "Section Name 2" Section2
SectionEnd
LangString DESC_Section1 ${LANG_SWEDISH} "Bork, bork, bork!"
LangString DESC_Section2 ${LANG_SWEDISH} "Aweenda shmure da froog's legs."
LangString DESC_Section1 ${LANG_DANISH} "Danish text here for section 1"
LangString DESC_Section2 ${LANG_DANISH} "...and section 2"
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${Section1} $(DESC_Section1)
!insertmacro MUI_DESCRIPTION_TEXT ${Section2} $(DESC_Section2)
!insertmacro MUI_FUNCTION_DESCRIPTION_END

Resources