Archive: How do i get path like "file:///E:/Redist/dllname.dll"


How do i get path like "file:///E:/Redist/dllname.dll"
  i want to get a file's path in the following mode:

file:///E:/Redist/dllname.dll

is it possible in nsis?

Thank you:p


presuming you already have the file's regular path in e.g. $0

!include "MUI2.nsh"

OutFile "test.exe"

!include "StrFunc.nsh" ; string functions header
${StrRep} ; Initialize the string replacement function

Section
StrCpy $0 "c:\whatever\file.txt" ; presume this is your input
${StrRep} $1 $0 "\" "/" ; replace backslash with slash
StrCpy $2 "file://$1" ; stick file:// in frot
MessageBox MB_OK "***91;$0***93;$\r$\n***91;$1***93;$\r$\n***91;$2***93;"
SectionEnd

!insertmacro MUI_LANGUAGE "English"

Originally posted by Animaether
presuming you already have the file's regular path in e.g. $0
!include "MUI2.nsh"


>OutFile "test.exe"

>!include "StrFunc.nsh" ; string functions header
>${StrRep} ; Initialize the string replacement function

>Section
StrCpy$0 "c:\whatever\file.txt" ; presume this is your input
${StrRep} $1 $0 "\" "/" ; replace backslash with slash
StrCpy $2 "file://$1" ; stick file:// in frot
MessageBox MB_OK "***91;$0***93;$\r$\n***91;$1***93;$\r$\n***91;$2***93;"
>SectionEnd

>!insertmacro MUI_LANGUAGE "English"
thanks very much. It works like a charm:p

Note that with this solution, you might get problem with special characters in path that don't fit the URL encoding scheme..

You might want to use the System plugin instead and use the UrlCreateFromPath function from shlwapi.dll


I do wish you'd give an example... anybody who refers to the System plugin should, actually. It's magic to most of us lowly users :)

(
the docs for the function are here:

http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx

pszPath [in] | LPCTSTR | A null-terminated string of maximum length INTERNET_MAX_URL_LENGTH that contains the MS-DOS path.
suggests a System plugin format of 't' followed by the string...

pszUrl [out] | LPTSTR | A buffer used to return the URL.
suggests a System plugin format of 'p' (pointer to a buffer which should be allocated first) used for output...

pcchUrl [in, out] | LPDWORD | The length of pszUrl.
Suggests a System plugin format of 'i' with ${NSIS_MAX_STRLEN} as its length for input presumably.

dwReserved [in] | DWORD | Reserved. Set this parameter to NULL.
Suggests we can leave that one out.

Yet suffice to say that the following does not work. Probably a 'simple' mistake somewhere.

  StrCpy$0 "c:\whatever\file.txt"


System::Alloc ${NSIS_MAX_STRLEN}
Pop $1

System
::Call "shlwapi::UrlCreateFromPath(t r0, p.r1, i ${NSIS_MAX_STRLEN} r2)"
MessageBox MB_OK "***91;$0***93;***91;$1***93;***91;$2***93;"

System::Free $1
>

I'm not very good with System either
However after a little try, based on the GetUserName example in System.html, I came up with


    StrCpy $0 "c:\whatever\file.txt"
System::Call "shlwapi::UrlCreateFromPath(t r0, t .r1, *i ${NSIS_MAX_STRLEN} r2, i0)"
MessageBox MB_OK "***91;$0***93;***91;$1***93;***91;$2***93;"

cool.. that at least does what it's supposed to %)

I guess the t vs p makes.. sense.. of sorts.. if System ends up allocating a buffer of its own there. no idea why it would be *i instead of just plain i for the length, though. *squints at the System plugin some more*


it's __inout LPDWORD pcchUrl, so you need a pointer to DWORD

everywhere you see a TCHAR string (LPTSTR or LPCTSTR) use 't' (so you will be compatible with Unicode NSIS)

and you forgot the dwReserved argument (NULL)


"it's __inout LPDWORD pcchUrl, so you need a pointer to DWORD"

aha... okay, makes sense too

And yes, I forgot the null.. should be fine without, but I suppose technically a ", n" should be added?