You are here

PortableApps.comDocuments Custom Code Update To Fix Bug

3 posts / 0 new
Last post
John T. Haller
John T. Haller's picture
Online
Last seen: 57 min 27 sec ago
AdminDeveloperModeratorTranslator
Joined: 2005-11-28 22:21
PortableApps.comDocuments Custom Code Update To Fix Bug

A few apps are using some custom code for PAL (contained in Custom.nsh) I wrote to determine the PortableApps.com Documents directory when apps are run without the PA.c Platform. There is a bug in this code that I fixed today in the LibreOffice Portable 4.2.1 update (awaiting publisher posting). Here is the fixed code:

ExpandEnvStrings $1 "%PortableApps.comDocuments%"
	${If} $1 == ""
	${OrIfNot} ${FileExists} "$1\*.*"
		${GetParent} $EXEDIR $3
		${GetParent} $3 $1
		${If} $1 == "" ;Be sure we didn't just GetParent on Root
			StrCpy $1 $3
		${EndIf}
		${If} ${FileExists} "$1\Documents\*.*"
			StrCpy $2 "$1\Documents"
		${Else}
			${GetRoot} $EXEDIR $1
			${If} ${FileExists} "$1\Documents\*.*"
				StrCpy $2 "$1\Documents"
			${Else}
				StrCpy $2 "$1"
			${EndIf}
		${EndIf}
		System::Call 'Kernel32::SetEnvironmentVariable(t, t) i("PortableApps.comDocuments", "$2").r0'
	${EndIf}

WHAT'S FIXED: The fix is specifically around when an app is run at the root of the drive (example: X:\AppNamePortable instead of X:\SomePathTo\AppNamePortable) which was causing an invalid path to result when GetParent is called on a variable with the root directory.

AFFECTED APPS: LibreOffice (fixed with the 4.2.1 release), LibreCad, Mp3splt, MPC-HC, PDF-XChangeViewer (dev test), possibly other Dev Test apps.

I've already updated the affected released apps internally and will have them updated with the fix with their next releases. I wanted to post this publicly so other devs can fix any dev test releases with this change.

John T. Haller
John T. Haller's picture
Online
Last seen: 57 min 27 sec ago
AdminDeveloperModeratorTranslator
Joined: 2005-11-28 22:21
All Environment Variables

As an add-on to the above, here's full custom code to interpolate all 4 custom folders (Documents, Videos, Pictures, Music) if they don't exist in their standard location:

${SegmentFile}

${SegmentInit}
	ExpandEnvStrings $1 "%PortableApps.comDocuments%"
	${If} $1 == ""
	${OrIfNot} ${FileExists} "$1\*.*"
		${GetParent} $EXEDIR $3
		${GetParent} $3 $1
		${If} $1 == "" ;Be sure we didn't just GetParent on Root
			StrCpy $1 $3
		${EndIf}
		${If} ${FileExists} "$1\Documents\*.*"
			StrCpy $2 "$1\Documents"
		${Else}
			${GetRoot} $EXEDIR $1
			${If} ${FileExists} "$1\Documents\*.*"
				StrCpy $2 "$1\Documents"
			${Else}
				StrCpy $2 "$1"
			${EndIf}
		${EndIf}
		System::Call 'Kernel32::SetEnvironmentVariable(t, t) i("PortableApps.comDocuments", "$2").r0'
	${EndIf}
	
	ExpandEnvStrings $1 "%PortableApps.comVideos%"
	${If} $1 == ""
	${OrIfNot} ${FileExists} "$1\*.*"
		ExpandEnvStrings $1 "%PortableApps.comDocuments%"
		${If} ${FileExists} "$1\Videos\*.*"
			StrCpy $2 "$1\Videos"
		${Else}
			${GetParent} $EXEDIR $3
			${GetParent} $3 $1
			${If} $1 == "" ;Be sure we didn't just GetParent on Root
				StrCpy $1 $3
			${EndIf}
			${If} ${FileExists} "$1\Videos\*.*"
				StrCpy $2 "$1\Videos"
			${Else}
				${GetRoot} $EXEDIR $1
				${If} ${FileExists} "$1\Videos\*.*"
					StrCpy $2 "$1\Videos"
				${Else}
					StrCpy $2 "$1"
				${EndIf}
			${EndIf}
		${EndIf}
		System::Call 'Kernel32::SetEnvironmentVariable(t, t) i("PortableApps.comVideos", "$2").r0'
	${EndIf}
	
	ExpandEnvStrings $1 "%PortableApps.comPictures%"
	${If} $1 == ""
	${OrIfNot} ${FileExists} "$1\*.*"
		ExpandEnvStrings $1 "%PortableApps.comDocuments%"
		${If} ${FileExists} "$1\Pictures\*.*"
			StrCpy $2 "$1\Pictures"
		${Else}
			${GetParent} $EXEDIR $3
			${GetParent} $3 $1
			${If} $1 == "" ;Be sure we didn't just GetParent on Root
				StrCpy $1 $3
			${EndIf}
			${If} ${FileExists} "$1\Pictures\*.*"
				StrCpy $2 "$1\Pictures"
			${Else}
				${GetRoot} $EXEDIR $1
				${If} ${FileExists} "$1\Pictures\*.*"
					StrCpy $2 "$1\Pictures"
				${Else}
					StrCpy $2 "$1"
				${EndIf}
			${EndIf}
		${EndIf}
		System::Call 'Kernel32::SetEnvironmentVariable(t, t) i("PortableApps.comPictures", "$2").r0'
	${EndIf}
	
	ExpandEnvStrings $1 "%PortableApps.comMusic%"
	${If} $1 == ""
	${OrIfNot} ${FileExists} "$1\*.*"
		ExpandEnvStrings $1 "%PortableApps.comDocuments%"
		${If} ${FileExists} "$1\Music\*.*"
			StrCpy $2 "$1\Music"
		${Else}
			${GetParent} $EXEDIR $3
			${GetParent} $3 $1
			${If} $1 == "" ;Be sure we didn't just GetParent on Root
				StrCpy $1 $3
			${EndIf}
			${If} ${FileExists} "$1\Music\*.*"
				StrCpy $2 "$1\Music"
			${Else}
				${GetRoot} $EXEDIR $1
				${If} ${FileExists} "$1\Music\*.*"
					StrCpy $2 "$1\Music"
				${Else}
					StrCpy $2 "$1"
				${EndIf}
			${EndIf}
		${EndIf}
		System::Call 'Kernel32::SetEnvironmentVariable(t, t) i("PortableApps.comMusic", "$2").r0'
	${EndIf}
!macroend

Sometimes, the impossible can become possible, if you're awesome!

prapper
Offline
Last seen: 3 years 9 months ago
Developer
Joined: 2008-01-24 17:01
pdfx

John T. HallerI've prepped the current version for final release. I'll likely upload it today and post it Monday or Tuesday.

Given the above, I presume there's nothing for me to do here?

It should be "prapped" btw Smile

Log in or register to post comments