You are here

MuseScore Portable 2.0.3 Upgrade Code.

9 posts / 0 new
Last post
3D1T0R
3D1T0R's picture
Offline
Last seen: 3 years 4 months ago
Developer
Joined: 2006-12-29 23:48
MuseScore Portable 2.0.3 Upgrade Code.

This started in the Outdated Apps thread, and (rightfully) got deleted from there, as it should have been split off to another thread if it was to continue.

Summary of the discussion so far:

Bart.S: MuseScore
MuseScore 2.0.3 has been released.
It eats some settings on upgrade though. Sad
I'll investigate.

John, maybe you could create a new splash in the meantime:
https://github.com/musescore/MuseScore/blob/2.0.3/mscore/data/splash.png

John T. Haller: Splash
https://portableapps.com/downloads/MuseScorePortable.jpg
Bart.S: Thanks
Thanks for the splash.

I have reported a bug: https://musescore.org/en/node/104936
Maybe they'll fix it soon or I have to create some custom installer code to keep portable paths.

3D1T0R: Try this
This copies the contents of Data\Settings\MuseScore2.ini's [General]:sfPath to [General]:mySoundfontsPath (if [General]:sfPath is present). Is this enough? or do we need to edit the value at all? and/or do we need to remove [General]:sfPath too?

!macro CustomCodePreInstall
	${If} ${FileExists} "$INSTDIR\Data\settings\MuseScore\MuseScore2.ini"
		ReadINIStr $0 "$INSTDIR\Data\settings\MuseScore\MuseScore2.ini" "General" "sfPath"
		StrCmp $0 "" +2
			WriteINIStr "$INSTDIR\Data\settings\MuseScore\MuseScore2.ini" "General" "mySoundfontsPath" '"$0"'
	${EndIf}
!macroend
Bart.S: (Sorry, I forget what exactly this post said, and I the page where I'd looked at it wasn't still open when I went to write this)
Something was said about copying the value may not be enough, and that Bart.S had implemented some "magic", but nothing more specific about it was stated.

Well, here's my reply:

You didn't say what "magic" you'd implemented, and since I'd already started, I kept working on it.

So, after analyzing their source, and a bunch of experimentation, I don't think that just copying it would be a problem, but you're right, we should probably emulate the changes they do in their upgrade code if we can, and I've written a new Other\Source\PortableApps.comInstallerCustom.nsh which does everything their code does, and saves it in the new location.
Also, I think the sfPath shouldn't be removed until the installation is complete (to be safe), so I put that bit in CustomCodePostInstall, and had it check to make sure both sfPath and mySoundfontsPath were present before it would delete it:

!macro CustomCodePreInstall
	${If} ${FileExists} "$INSTDIR\Data\settings\MuseScore\MuseScore2.ini"
		ReadINIStr $0 "$INSTDIR\Data\settings\MuseScore\MuseScore2.ini" "General" "sfPath"
		IfErrors sfPathNotFound

		${WordFind} $0 ";" "#" $1 ; How many folders are there?
		PushSoundFontFolderToStack:
			${WordFind} $0 ";" +$1 $2 ; This is one folder.
			Push $2 ; Push it to the stack.
			IntOp $1 $1 - 1 ; One less to do.
			StrCmp $1 0 0 PushSoundFontFolderToStack ; If there are any left to do, go back and do the next one.

		${WordReplace} "$INSTDIR\App\MuseScore\sound" '\' "/" "+" $3 ; Convert \ to /
		${WordFind} $0 ";" "#" $1 ; We need to know how many folders are there again.
		StrCpy $0 "" ; Clear $0 in preparation to rebuild it.
		PopSoundFontFolderFromStack:
			Pop $2 ; Put one of the folders in $2
			StrCmp $2 $3 +2 ; If $2 is "%PAL:AppDir%\MuseScore\sound", skip next line.
				StrCpy $0 "$0$2;" ; Add it (and a ;) to $0
			IntOp $1 $1 - 1 ; One less to do.
			StrCmp $1 0 0 PopSoundFontFolderFromStack ; If there are any left to do, go back and do the next one.
		StrCpy $0 $0 -1 ; Remove extra ; at end

		${WordFind} $0 ";" "#" $1 ; Now: How many folders are still there?
		IntCmp $1 1 +2 +2 ; If there's only one, skip the next line.
			StrCpy $0 `"$0"` ; Add quotes around $0

		WriteINIStr "$INSTDIR\Data\settings\MuseScore\MuseScore2.ini" "General" "mySoundfontsPath" $0

		sfPathNotFound:
	${EndIf}
!macroend

!macro CustomCodePostInstall
	${If} ${FileExists} "$INSTDIR\Data\settings\MuseScore\MuseScore2.ini"
		ClearErrors
		ReadINIStr $0 "$INSTDIR\Data\settings\MuseScore\MuseScore2.ini" "General" "sfPath"
		ReadINIStr $0 "$INSTDIR\Data\settings\MuseScore\MuseScore2.ini" "General" "mySoundfontsPath"
		IfErrors +2 ; If sfPath or mySoundfontsPath not found, skip next line.
			DeleteINIStr "$INSTDIR\Data\settings\MuseScore\MuseScore2.ini" "General" "sfPath"
	${EndIf}
!macroend

P.S.: I also commented the code pretty heavily to make sure it would be (relatively) easy to follow.

Bart.S
Offline
Last seen: 5 months 4 weeks ago
Developer
Joined: 2008-07-23 07:56
Thanks

I said thanks for the support and didn't add the code because everyone can see it when MuseScore Portable 2.0.3 is released.
For the impatient:

!macro CustomCodePreInstall
	${If} ${FileExists} "$INSTDIR\App\AppInfo\appinfo.ini"
		ReadINIStr $0 "$INSTDIR\MuseScorePortable.ini" "MuseScorePortable" "SettingsDirectory"
		${If} $0 == ""
			StrCpy $0 "Data\settings"
		${EndIf}

		ReadINIStr $1 "$INSTDIR\MuseScorePortable.ini" "MuseScorePortable" "MuseScoreDirectory"
		${If} $1 == ""
			StrCpy $1 "App\MuseScore"
		${EndIf}

		${If} ${FileExists} "$INSTDIR\$0\MuseScore\MuseScore2.ini"
			ReadINIStr $2 "$INSTDIR\$0\MuseScore\MuseScore2.ini" "General" "sfPath"
			ReadINIStr $3 "$INSTDIR\$0\MuseScore\MuseScore2.ini" "General" "mySoundfontsPath"
			${If} $2 != ""
			${AndIf} $3 == ""
				ReadINIStr $4 "$INSTDIR\$0\MuseScorePortableSettings.ini" "MuseScorePortableSettings" "LastDirectory"
				${If} $4 == ""
					StrCpy $4 "$INSTDIR"
				${EndIf}

				${WordReplace} "$4\$1\sound" "\" "/" "+" $5
				${WordReplace} $2 $5 "" "+" $6
				${WordReplace} $6 ";" "" "{}*" $7
				${WordReplace} $7 ";" ";" "+*" $8
				WriteINIStr "$INSTDIR\$0\MuseScore\MuseScore2.ini" "General" "mySoundfontsPath" "$8"
				DeleteINIStr "$INSTDIR\$0\MuseScore\MuseScore2.ini" "General" "sfPath"
			${EndIf}
		${EndIf}
	${EndIf}
!macroend
Bart.S
Offline
Last seen: 5 months 4 weeks ago
Developer
Joined: 2008-07-23 07:56
Grrr, found an issue

I forgot to add the quotes around $8 and MuseScore reads first path only without quotes. Sad
John, if it's not to late replace line 27 by

				WriteINIStr "$INSTDIR\$0\MuseScore\MuseScore2.ini" "General" "mySoundfontsPath" '"$8"'
John T. Haller
John T. Haller's picture
Offline
Last seen: 1 hour 59 min ago
AdminDeveloperModeratorTranslator
Joined: 2005-11-28 22:21
Will do

Will do!

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

3D1T0R
3D1T0R's picture
Offline
Last seen: 3 years 4 months ago
Developer
Joined: 2006-12-29 23:48
Only if more than one folder?

MuseScore only adds quotes to it if there's more than one folder.
Shouldn't we do the same?

~3D1T0R

Bart.S
Offline
Last seen: 5 months 4 weeks ago
Developer
Joined: 2008-07-23 07:56
Hmm,

do the quotes hurt if one folder only? I can't test at the moment.

3D1T0R
3D1T0R's picture
Offline
Last seen: 3 years 4 months ago
Developer
Joined: 2006-12-29 23:48
I'm not sure.

I don't know.
I kind of doubt it, but I didn't think that leaving App\MuseScore\sound should hurt either.
I just thought you were trying to exactly duplicate what MuseScore 2.0.3's built in upgrade code would have done (if it were working correctly).

~3D1T0R

Bart.S
Offline
Last seen: 5 months 4 weeks ago
Developer
Joined: 2008-07-23 07:56
Ok

I'm not sure, but there is a reason for removing MuseScore\sound and using a new ini setting.
I guess the MuseScore developers could tell.
I'm not trying to duplicate MuseScore's built in upgrade code. In fact, I haven't looked at it. Wink

Bart.S
Offline
Last seen: 5 months 4 weeks ago
Developer
Joined: 2008-07-23 07:56
Tested

MuseScore doesn't mind the quotes if one folder only. It saves the folder without quotes after first run to ini.

Log in or register to post comments