You are here

Folder not removed in Windows 7

6 posts / 0 new
Last post
Devo
Offline
Last seen: 1 year 1 month ago
Joined: 2007-09-04 14:55
Folder not removed in Windows 7

I was recently looking at the MediaMonkey Portable launcher and noticed that a folder is left at C:\Users\[username]\AppData\Local\ in Windows7. The folder is removed in XP, so obviously something's changed. The settings and everything are moved properly, but an empty folder is left and not removed. I've posted the cleanup code below, but I don't know what's wrong. Can somebody take a look at this?

EDIT: Topic moved to MediaMonkey Launcher topic.

MoveSettingsBack:
		CopyFiles /SILENT "$PROFILE\Local Settings\Application Data\MediaMonkey\*.*" "$SETTINGSDIRECTORY\MediaMonkey"
		Sleep 100
		RMDir /r "$PROFILE\Local Settings\Application Data\MediaMonkey"
		Sleep 100
		Rename "$PROFILE\Local Settings\Application Data\MediaMonkey-BackupByMediaMonkeyPortable" "$PROFILE\Local Settings\Application Data\MediaMonkey"
		Sleep 100
		Delete "$SETTINGSDIRECTORY\MediaMonkey.ini"
		Rename "$PROGRAMDIRECTORY\MediaMonkey.ini" "$SETTINGSDIRECTORY\MediaMonkey.ini"
		Delete "$SETTINGSDIRECTORY\MM.db"
		Rename "$PROGRAMDIRECTORY\MM.db" "$SETTINGSDIRECTORY\MM.db"
		Delete "$SETTINGSDIRECTORY\Scripts.ini"
		Rename "$PROGRAMDIRECTORY\Scripts\Scripts.ini" "$SETTINGSDIRECTORY\Scripts.ini"
		Goto TheEnd
prapper
Offline
Last seen: 3 years 10 months ago
Developer
Joined: 2008-01-24 17:01
At first glance, I would say

At first glance, I would say that all occurrences of -

$PROFILE\Local Settings\Application Data

should be replaced with -

$LOCALAPPDATA

That would go for the rest of the launcher too. HTH.

Devo
Offline
Last seen: 1 year 1 month ago
Joined: 2007-09-04 14:55
Perfect, thanks!

Perfect, thanks!

Devo
Offline
Last seen: 1 year 1 month ago
Joined: 2007-09-04 14:55
@Prapper: I have another question...

@Prapper: I have another question, kind of unrelated. There are actually 2 registry entries created: HKLM/Software/MediaMonkey and HKLM/Software/Winamp. I've taken care of the MediaMonkey entry, but until now have ignored the Winamp entry because it didn't really have any data in it. I'm trying to figure out how to handle it, but I'm not where to manage it in the code, could you take a look at the code and give me a suggestion? Also, if you don't mind, can you make any other suggestions; I'm trying to get this to the point where it can be an online installer.

;Copyright (C) 2004-2009 John T. Haller
;Copyright (C) 2008-2009 Devo

;Website: http://PortableApps.com/Development/test

;This software is OSI Certified Open Source Software.
;OSI Certified is a certification mark of the Open Source Initiative.

;This program is free software; you can redistribute it and/or
;modify it under the terms of the GNU General Public License
;as published by the Free Software Foundation; either version 2
;of the License, or (at your option) any later version.

;This program is distributed in the hope that it will be useful,
;but WITHOUT ANY WARRANTY; without even the implied warranty of
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;GNU General Public License for more details.

;You should have received a copy of the GNU General Public License
;along with this program; if not, write to the Free Software
;Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

!define PORTABLEAPPNAME "MediaMonkey Portable"
!define NAME "MediaMonkeyPortable"
!define APPNAME "MediaMonkey"
!define VER "3.2.0.1294"
!define WEBSITE "PortableApps.com/MediaMonkeyPortable"
!define DEFAULTEXE "MediaMonkey.exe"
!define DEFAULTAPPDIR "MediaMonkey"
!define DEFAULTSETTINGSPATH "settings"

;=== Program Details
Name "${PORTABLEAPPNAME}"
OutFile "..\..\${NAME}.exe"
Caption "${PORTABLEAPPNAME} | PortableApps.com"
VIProductVersion "${VER}"
VIAddVersionKey ProductName "${PORTABLEAPPNAME}"
VIAddVersionKey Comments "Allows ${APPNAME} to be run from a removable drive.  For additional details, visit ${WEBSITE}"
VIAddVersionKey CompanyName "PortableApps.com"
VIAddVersionKey LegalCopyright "John T. Haller"
VIAddVersionKey FileDescription "${PORTABLEAPPNAME}"
VIAddVersionKey FileVersion "${VER}"
VIAddVersionKey ProductVersion "${VER}"
VIAddVersionKey InternalName "${PORTABLEAPPNAME}"
VIAddVersionKey LegalTrademarks "PortableApps.com is a Trademark of Rare Ideas, LLC."
VIAddVersionKey OriginalFilename "${NAME}.exe"
;VIAddVersionKey PrivateBuild ""
;VIAddVersionKey SpecialBuild ""

;=== Runtime Switches
CRCCheck On
WindowIcon Off
SilentInstall Silent
AutoCloseWindow True
RequestExecutionLevel user

; Best Compression
SetCompress Auto
SetCompressor /SOLID lzma
SetCompressorDictSize 32
SetDatablockOptimize On

;=== Include
!include "Registry.nsh"
!include "GetParameters.nsh"
!include "MUI.nsh"

;=== Program Icon
Icon "..\..\App\AppInfo\appicon.ico"

;=== Icon & Stye ===
!define MUI_ICON "..\..\App\AppInfo\appicon.ico"

;=== Languages
!insertmacro MUI_LANGUAGE "English"

LangString LauncherFileNotFound ${LANG_ENGLISH} "${PORTABLEAPPNAME} cannot be started. You may wish to re-install to fix this issue. (ERROR: $MISSINGFILEORPATH could not be found)"
LangString LauncherAlreadyRunning ${LANG_ENGLISH} "Another instance of ${APPNAME} is already running. Please close other instances of ${APPNAME} before launching ${PORTABLEAPPNAME}."
LangString LauncherAskCopyLocal ${LANG_ENGLISH} "${PORTABLEAPPNAME} appears to be running from a location that is read-only. Would you like to temporarily copy it to the local hard drive and run it from there?$\n$\nPrivacy Note: If you say Yes, your personal data within ${PORTABLEAPPNAME} will be temporarily copied to a local drive. Although this copy of your data will be deleted when you close ${PORTABLEAPPNAME}, it may be possible for someone else to access your data later."
LangString LauncherNoReadOnly ${LANG_ENGLISH} "${PORTABLEAPPNAME} can not run directly from a read-only location and will now close."

Var PROGRAMDIRECTORY
Var SETTINGSDIRECTORY
Var ADDITIONALPARAMETERS
Var EXECSTRING
Var PROGRAMEXECUTABLE
Var INIPATH
Var DISABLESPLASHSCREEN
Var ISDEFAULTDIRECTORY
Var SECONDARYLAUNCH
Var FAILEDTORESTOREKEY
Var MISSINGFILEORPATH

Section "Main"
	;=== Check if already running
	System::Call 'kernel32::CreateMutexA(i 0, i 0, t "${NAME}2") i .r1 ?e'
	Pop $0
	StrCmp $0 0 CheckForINI
		StrCpy $SECONDARYLAUNCH "true"

	CheckForINI:
	;=== Find the INI file, if there is one
		IfFileExists "$EXEDIR\${NAME}.ini" "" NoINI
			StrCpy "$INIPATH" "$EXEDIR"
			Goto ReadINI

	ReadINI:
		;=== Read the parameters from the INI file
		ReadINIStr $0 "$INIPATH\${NAME}.ini" "${NAME}" "${APPNAME}Directory"
		StrCpy "$PROGRAMDIRECTORY" "$EXEDIR\$0"
		ReadINIStr $0 "$INIPATH\${NAME}.ini" "${NAME}" "SettingsDirectory"
		StrCpy "$SETTINGSDIRECTORY" "$EXEDIR\$0"

		;=== Check that the above required parameters are present
		IfErrors NoINI

		ReadINIStr $0 "$INIPATH\${NAME}.ini" "${NAME}" "AdditionalParameters"
		StrCpy "$ADDITIONALPARAMETERS" $0
		ReadINIStr $0 "$INIPATH\${NAME}.ini" "${NAME}" "${APPNAME}Executable"
		StrCpy "$PROGRAMEXECUTABLE" $0
		ReadINIStr $0 "$INIPATH\${NAME}.ini" "${NAME}" "DisableSplashScreen"
		StrCpy "$DISABLESPLASHSCREEN" $0

	;CleanUpAnyErrors:
		;=== Any missing unrequired INI entries will be an empty string, ignore associated errors
		ClearErrors

		;=== Correct PROGRAMEXECUTABLE if blank
		StrCmp $PROGRAMEXECUTABLE "" "" CheckForProgramINI
			StrCpy "$PROGRAMEXECUTABLE" "${DEFAULTEXE}"
			Goto CheckForProgramINI
			
	CheckForProgramINI:
		IfFileExists "$PROGRAMDIRECTORY\$PROGRAMEXECUTABLE" FoundProgramEXE NoProgramEXE

	NoINI:
		;=== No INI file, so we'll use the defaults
		StrCpy "$ADDITIONALPARAMETERS" ""
		StrCpy "$PROGRAMEXECUTABLE" "${DEFAULTEXE}"
		StrCpy "$DISABLESPLASHSCREEN" "false"

		IfFileExists "$EXEDIR\App\${DEFAULTAPPDIR}\${DEFAULTEXE}" "" NoProgramEXE
			StrCpy "$PROGRAMDIRECTORY" "$EXEDIR\App\${DEFAULTAPPDIR}"
			StrCpy "$SETTINGSDIRECTORY" "$EXEDIR\Data\${DEFAULTSETTINGSPATH}"
			StrCpy "$ISDEFAULTDIRECTORY" "true"
			Goto FoundProgramEXE

	NoProgramEXE:
		;=== Program executable not where expected
		StrCpy $MISSINGFILEORPATH $PROGRAMEXECUTABLE
		MessageBox MB_OK|MB_ICONEXCLAMATION `$(LauncherFileNotFound)`
		Abort
		
	FoundProgramEXE:
		;=== Check if already running
		StrCmp $SECONDARYLAUNCH "true" CheckForSettings
		FindProcDLL::FindProc "$PROGRAMEXECUTABLE"                 
		StrCmp $R0 "1" WarnAnotherInstance CheckForSettings

	WarnAnotherInstance:
		MessageBox MB_OK|MB_ICONINFORMATION `$(LauncherAlreadyRunning)`
		Abort
	
	CheckForSettings:
		IfFileExists "$SETTINGSDIRECTORY\*.*" SettingsFound
		;=== No settings found
		StrCmp $ISDEFAULTDIRECTORY "true" CopyDefaultSettings
		CreateDirectory $SETTINGSDIRECTORY
		Goto CopyDefaultSettings
	
	CopyDefaultSettings:
		CreateDirectory "$EXEDIR\Data"
		CreateDirectory "$EXEDIR\Data\settings"
		CopyFiles /SILENT $EXEDIR\App\DefaultData\settings\*.* $EXEDIR\Data\settings
		Goto SettingsFound

	SettingsFound:
		StrCmp $DISABLESPLASHSCREEN "true" GetPassedParameters
			;=== Show the splash screen before processing the files
			InitPluginsDir
			File /oname=$PLUGINSDIR\splash.jpg "${NAME}.jpg"	
			newadvsplash::show /NOUNLOAD 1500 200 0 -1 /L $PLUGINSDIR\splash.jpg

	GetPassedParameters:
		;=== Get any passed parameters
		Call GetParameters
		Pop $0
		StrCmp "'$0'" "''" "" LaunchProgramParameters

		;=== No parameters
		StrCpy $EXECSTRING `"$PROGRAMDIRECTORY\$PROGRAMEXECUTABLE"`
		Goto AdditionalParameters

	LaunchProgramParameters:
		StrCpy $EXECSTRING `"$PROGRAMDIRECTORY\$PROGRAMEXECUTABLE" $0`

	AdditionalParameters:
		StrCmp $ADDITIONALPARAMETERS "" RegistryBackup

		;=== Additional Parameters
		StrCpy $EXECSTRING `$EXECSTRING $ADDITIONALPARAMETERS`

	RegistryBackup:
		StrCmp $SECONDARYLAUNCH "true" LaunchAndExit
		;=== Backup the registry
		${registry::KeyExists} "HKEY_CURRENT_USER\Software\MediaMonkey-BackupByMediaMonkeyPortable" $R0
		StrCmp $R0 "0" RestoreTheKey
		${registry::KeyExists} "HKEY_CURRENT_USER\Software\MediaMonkey" $R0
		StrCmp $R0 "-1" RestoreTheKey
		${registry::MoveKey} "HKEY_CURRENT_USER\Software\MediaMonkey" "HKEY_CURRENT_USER\Software\MediaMonkey-BackupByMediaMonkeyPortable" $R0
		Sleep 100
		
	RestoreTheKey:
		IfFileExists "$SETTINGSDIRECTORY\MediaMonkey.reg" "" DetermineLocalInstall
	
		IfFileExists "$WINDIR\system32\reg.exe" "" RestoreTheKey9x
			nsExec::ExecToStack `"$WINDIR\system32\reg.exe" import "$SETTINGSDIRECTORY\MediaMonkey.reg"`
			Pop $R0
			StrCmp $R0 '0' DetermineLocalInstall ;successfully restored key

	RestoreTheKey9x:
		${registry::RestoreKey} "$SETTINGSDIRECTORY\MediaMonkey.reg" $R0
		StrCmp $R0 '0' DetermineLocalInstall ;successfully restored key
		StrCpy $FAILEDTORESTOREKEY "true"
	
	DetermineLocalInstall:
	IfFileExists "$LOCALAPPDATA\MediaMonkey\*.m3u" MoveOriginalSettings LaunchNow
	
	MoveOriginalSettings:
		Rename "$LOCALAPPDATA\MediaMonkey" "$LOCALAPPDATA\MediaMonkey-BackupByMediaMonkeyPortable"
		Sleep 100
		Goto LaunchNow
	
	LaunchNow:
		CopyFiles /SILENT "$SETTINGSDIRECTORY\MediaMonkey.ini" "$PROGRAMDIRECTORY\MediaMonkey.ini"
		CopyFiles /SILENT "$SETTINGSDIRECTORY\MM.db" "$PROGRAMDIRECTORY\MM.db"
		CopyFiles /SILENT "$SETTINGSDIRECTORY\Scripts.ini" "$PROGRAMDIRECTORY\Scripts\Scripts.ini"
		CreateDirectory "$LOCALAPPDATA\MediaMonkey"
		CopyFiles /SILENT "$SETTINGSDIRECTORY\MediaMonkey\*.*" "$LOCALAPPDATA\MediaMonkey"
		Sleep 100
		ExecWait $EXECSTRING
		
	CheckRunning:
		Sleep 1000
		FindProcDLL::FindProc "${DEFAULTEXE}"                  
		StrCmp $R0 "1" CheckRunning
		
		StrCmp $FAILEDTORESTOREKEY "true" SetOriginalKeyBack
		${registry::SaveKey} "HKEY_CURRENT_USER\Software\MediaMonkey" "$SETTINGSDIRECTORY\MediaMonkey.reg" "" $0
		Sleep 100
	
	SetOriginalKeyBack:
		${registry::DeleteKey} "HKEY_CURRENT_USER\Software\MediaMonkey" $R0
		Sleep 100
		${registry::KeyExists} "HKEY_CURRENT_USER\Software\MediaMonkey-BackupByMediaMonkeyPortable" $R0
		StrCmp $R0 "-1" MoveSettingsBack
		${registry::MoveKey} "HKEY_CURRENT_USER\Software\MediaMonkey-BackupByMediaMonkeyPortable" "HKEY_CURRENT_USER\Software\MediaMonkey" $R0
		Sleep 100
		Goto MoveSettingsBack
	
	MoveSettingsBack:
		CopyFiles /SILENT "$LOCALAPPDATA\MediaMonkey\*.*" "$SETTINGSDIRECTORY\MediaMonkey"
		Sleep 100
		RMDir /r "$LOCALAPPDATA\MediaMonkey"
		Sleep 100
		Rename "$LOCALAPPDATA\MediaMonkey-BackupByMediaMonkeyPortable" "$LOCALAPPDATA\MediaMonkey"
		Sleep 100
		Delete "$SETTINGSDIRECTORY\MediaMonkey.ini"
		Rename "$PROGRAMDIRECTORY\MediaMonkey.ini" "$SETTINGSDIRECTORY\MediaMonkey.ini"
		Delete "$SETTINGSDIRECTORY\MM.db"
		Rename "$PROGRAMDIRECTORY\MM.db" "$SETTINGSDIRECTORY\MM.db"
		Delete "$SETTINGSDIRECTORY\Scripts.ini"
		Rename "$PROGRAMDIRECTORY\Scripts\Scripts.ini" "$SETTINGSDIRECTORY\Scripts.ini"
		Goto TheEnd
		
	LaunchAndExit:
		Exec $EXECSTRING
	
	TheEnd:
		${registry::Unload}
		newadvsplash::stop /WAIT
SectionEnd
John T. Haller
John T. Haller's picture
Offline
Last seen: 8 hours 33 min ago
AdminDeveloperModeratorTranslator
Joined: 2005-11-28 22:21
In topic

Let's keep this in the Media Monkey Portable launcher topic as it's not an official/supported app.

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

Devo
Offline
Last seen: 1 year 1 month ago
Joined: 2007-09-04 14:55
I'll move it over there, feel

I'll move it over there, feel free to close this topic.

Log in or register to post comments