You are here

Custom Code for Launcher - Solved

11 posts / 0 new
Last post
vf2nsr
vf2nsr's picture
Offline
Last seen: 7 years 6 months ago
Developer
Joined: 2010-02-13 17:10
Custom Code for Launcher - Solved

I am looking to create a custom.nsh file to handle some things in a launcher. I Know that he PortableApps Launcher has part of the feature but I need to disable it for speed sake. Here is what I have so far but does not seem to accomplish what I am wanting.

!macro CustomCodePost
${Segment[Unload]}
    # The following attempt at a custom code was created by Patrick Powell
	# Who is a PorableApps Developer whose current list of apps is located at https://portableapps.com/node/30620
	# This code was created in an attempt to clean up files after disabling CleanTemp in the PortableApps Launcher.ini file
	# for rednotebook.  This hopes to help speed up the launcher for the app as well as to reduce clutter of the Data Directory
	${If} ${FileExists} "$INSTDIR\Data\rn-tmp*.html " #looks for files
		Delete "$INSTDIR\Data\rn-tmp*.html" #Deletes all files which cleans the clutter
		CopyFiles /SILENT "$INSTDIR\App\DefaultData\rn-tmp*.html "$INSTDIR\Data" #replaces files with the Default files #Copies the default files back to data dir
	${EndIf}
	!macroend

I know that the comments are unneeded.
Basically on exit I want to delete some files then move some from a directory to another one. So what am I missing/doing wrong?

Chris Morgan
Chris Morgan's picture
Offline
Last seen: 8 years 10 months ago
Joined: 2007-04-15 21:08
Not $INSTDIR

Never use $INSTDIR. It has no meaning in PAL. $EXEDIR is what you meant, but you shouldn't use $EXEDIR\Data here either; $DataDirectory is what you need. Same for $EXEDIR\App—use $AppDirectory.

I am a Christian and a developer and moderator here.

“A soft answer turns away wrath, but a harsh word stirs up anger.” – Proverbs 15:1

Gord Caswell
Gord Caswell's picture
Offline
Last seen: 5 months 4 days ago
DeveloperModerator
Joined: 2008-07-24 18:46
Remove Brackets

Remove the [ ] Brackets.

Also, do you need to copy over the DefaultData temp files? I thought they were recreated by every launch anyway.

vf2nsr
vf2nsr's picture
Offline
Last seen: 7 years 6 months ago
Developer
Joined: 2010-02-13 17:10
correct

Forgot that about the default data. As for the [Brackets] do you mean in the Segment are?

Also should I be doing this in Post hook or Unload hook...told you I was WAY a newbie to NSIS Was trying to do it myself with out having to always bother others to do it for me

“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” Dr. Seuss

Gord Caswell
Gord Caswell's picture
Offline
Last seen: 5 months 4 days ago
DeveloperModerator
Joined: 2008-07-24 18:46
comments

Re: defaultdata - to clarify, I meant why have the temp files in default at all? I understood that there were recreated by the base app every run. But that could be me misunderstanding you.

For the custom file you have above, it should be ${SegmentUnload}

I would keep it in unload, but that's just me. Chris might have a better suggestion.

It's not a bad start at the custom stuff. I started just like you, not long ago.

[EDIT] Also, remove the line "!macro CustomCodePost"

vf2nsr
vf2nsr's picture
Offline
Last seen: 7 years 6 months ago
Developer
Joined: 2010-02-13 17:10
Making all suggested changes

Launcher will not generate gives me following in log file (I only am showing the errors

!include: error in script: "C:\Users\Aztec\Desktop\RedNotebookPortable\App\AppInfo\Launcher\Custom.nsh" on line 1
!include: error in script: "Segments.nsh" on line 122
Error in script "Z:\PortableApps\PortableApps.comLauncher\Other\Source\PortableApps.comLauncher.nsi" on line 140 -- aborting creation process

And this is using the remove brackets as Gord said

So Line 1 is now:
${SegmentUnload}

“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” Dr. Seuss

Gord Caswell
Gord Caswell's picture
Offline
Last seen: 5 months 4 days ago
DeveloperModerator
Joined: 2008-07-24 18:46
Segmentfile

Line 1 should be

${SegmentFile}

Line 2 is empty

Start with the rest at line 3

vf2nsr
vf2nsr's picture
Offline
Last seen: 7 years 6 months ago
Developer
Joined: 2010-02-13 17:10
appears

to not like the * variable. Do I need to define what it does the variable I mean?

“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” Dr. Seuss

Chris Morgan
Chris Morgan's picture
Offline
Last seen: 8 years 10 months ago
Joined: 2007-04-15 21:08
Like this

At present, your code should be roughly the following:

${SegmentFile}

${SegmentUnload}
    ${If} ${FileExists} "$DataDirectory\rn-tmp*.html"
        Delete "$DataDirectory\rn-tmp*.html"
        CopyFiles /SILENT "$AppDirectory\DefaultData\rn-tmp*.html "$DataDirectory"
    ${EndIf}
!macroend

I am a Christian and a developer and moderator here.

“A soft answer turns away wrath, but a harsh word stirs up anger.” – Proverbs 15:1

vf2nsr
vf2nsr's picture
Offline
Last seen: 7 years 6 months ago
Developer
Joined: 2010-02-13 17:10
thought It did

But yours works mine does not....sort of. The copy file is not writing htem back to data directory which is ok I guess as Gord pointed out the files w ill automatically get written back on launch anyways

Now I need to figure where my error was Knowing me I am sure I typo somewhere

“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” Dr. Seuss

vf2nsr
vf2nsr's picture
Offline
Last seen: 7 years 6 months ago
Developer
Joined: 2010-02-13 17:10
I need a new tag here

Please add tag of TYPO KING

Apparently I had some sort of typo going on.

I removed the copy as it was not needed...FYI here is completed and WORKING code

${SegmentFile}

${SegmentUnload}
    # The following attempt at a custom code was created by Patrick Powell
	# Who is a PorableApps Developer whose current list of apps is located at https://portableapps.com/node/30620
	# This code was created in an attempt to clean up files after disabling CleanTemp in the PortableApps Launcher.ini file
	# for rednotebook.  This hopes to help speed up the launcher for the app as well as to reduce clutter of the Data Directory
	 ${If} ${FileExists} "$DataDirectory\rn-tmp*.html" #looks for files
		 Delete "$DataDirectory\rn-tmp*.html" #Deletes all files which cleans the clutter
	${EndIf}
	!macroend  	

To think only took me 3 hours to write a 5 minute code

BTW I was using the PortableApp Launcher manual, the NSIS manual and Google trying to resolve this myself. Sad

“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” Dr. Seuss

Log in or register to post comments