You are here

How should I handle an application suite with a common directory?

3 posts / 0 new
Last post
nnewton
Offline
Last seen: 3 months 2 weeks ago
Joined: 2007-07-06 02:14
How should I handle an application suite with a common directory?

I am trying to portablise an application suite that consists of three separate applications. Individually, this is no problem, I have done the three launcher.inis and they all run fine as separate PortableApps.

The problem is, all three apps use common directories in \Users\[user]\AppData\Roaming\[AppPublisher]\Common and \ProgramData\[AppPublisher]\Common to store dictionaries, clipboard data and other things, data that can be shared across all three apps in the suite.

I've been trying to think of ways I can just use the standard Launcher.ini to work around this, but none of them seem like they will work.

If I keep all the apps as separate PortableApps and run more than one, then the second one to open will move its common folders and the first app's folders will be backed up, then when they close, depending on which order they are closed it, the common folders may switch apps and the data is still separate. I can't use the WaitForEXEN option as there is no way to create a dependency loop that works.

I could put them all into the a single PortableApp and create separate launchers for each app, this means I only have a single copy of the common folders, but I still get all the rest of the issues from the keeping them separate solution.

Do I have to use the custom code option to determine if the app opening is the first one and only move the common folders then, and if it is the last one to close, move them back? Or is there some feature in the standard launcher that I'm missing?

Is there an existing PortableApp that works like this that I can use as an example? The only one that I can think of that is similar is LibreOffice, but that is a single application that takes parameters to determine what sub-app to open. My case is three distinctly separate apps.

Thanks

Andhika24kd
Offline
Last seen: 4 weeks 5 hours ago
Joined: 2018-06-28 07:13
You may need to use Custom.nsh file

So.. when you open exactly an app and then you close it, you want the data to be saved in 3 different apps altogether? I think using Custom.nsh file is the only alternative I can think of. Something like this should work (not tested):

Var AppPath1
Var AppPath2

Var App1Running
Var App2Running

${SegmentPrePrimary}
	StrCpy "$AppPath1" "$PortableAppsDirectory\AppNamePortable1"
	StrCpy "$AppPath1" "$PortableAppsDirectory\AppNamePortable2"
	; We are using App3 right now, no need to store its path

	${If} ${FileExists} "$APPDATA\PublisherName\Common\*.*"
		; Other apps already running
		; Do something here if needed
	${Else}
		CopyFiles /Silent "$EXEDIR\Data\Common\*.*" "$APPDATA\PublisherName\Common"
	${EndIf}
!macroend

${SegmentPostPrimary}
	; Check if App1 still running
	${If} ${ProcessExists} "AppName1.exe"
		${GetProcessPath} "AppName1.exe" $0
		${If} $0 == "$AppPath1\App\AppName1\AppName1.exe"
			StrCpy "$App1Running" "True"
		${EndIf}
	${EndIf}

	; Copy data to App1 if not running
	${IfNot} "$App1Running" == "True"
		CopyFiles /Silent "$APPDATA\PublisherName\Common\*.*" "$AppPath1\Data\Common"
	${EndIf}

	; Check if App2 still running
	${If} ${ProcessExists} "AppName2.exe"
		${GetProcessPath} "AppName2.exe" $0
		${If} $0 == "$AppPath2\App\AppName2\AppName2.exe"
			StrCpy "$App2Running" "True"
		${EndIf}
	${EndIf}

	; Copy data to App2 if not running
	${IfNot} "$App2Running" == "True"
		CopyFiles /Silent "$APPDATA\PublisherName\Common\*.*" "$AppPath2\Data\Common"
	${EndIf}
	
	; Copy data to App3 (current app)
	CopyFiles /Silent "$APPDATA\PublisherName\Common\*.*" "$EXEDIR\Data\Common"

	; Remove data if App1 and App2 are not running
	${IfNot} "$App1Running" == "True"
	${AndIfNot} "$App2Running" == "True"
		RMDir /r "$APPDATA\PublisherName\Common"
	${EndIf}
!macroend

Don't forget to remove %APPDATA%\PublisherName\Common from [DirectoriesMove] section in AppNamePortable.ini. Good luck!

nnewton
Offline
Last seen: 3 months 2 weeks ago
Joined: 2007-07-06 02:14
Thanks

Thanks for this. The custom code section in the developer docs wasn't particularly clear to me and I wasn't sure where to start.

Your example code perfectly explains to me how to use it

Log in or register to post comments