Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Script for Making Foobar Library Portable on USB Drives (Read 11175 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Script for Making Foobar Library Portable on USB Drives

I love that Foobar .96 has an option for a portable install, but there are problems with the library also being on a USB drive.  The library requires absolute paths to the files, and doesn't handle the changing drive letters on USB drives.  However using the old DOS SUBST command, it is possible to set up a fixed drive letter assignment for your music library on your USB drive.

I wrote the vb script:
' TARGETDRIVE-- This is an open drive letter where your USB drive can be persistently mounted on
'              each computer on which you will use this script.  In Foobar you will point your
'              Library to this drive to set the absolute paths to your media.
' SUBDIR--      Your probably won't choose to change this value, but it would allow you to map a
'              subdirectory of your USB drive as the root of TARGETDRIVE.
' FOOBARRELATIVEPATH-- This string is the relative path from the working directory of this script
'              to the foobar executable.  If you put this script in the directory containing the
'              foobar folder, this should work fine.   
'************************************************************

Const TARGETDRIVE = "U:"
Const SUBDIR = "\"
Const FOOBARRELATIVEPATH="foobar2000\foobar2000.exe"

'************************************************************
Dim WshShell, FSO, sCmd, sCurrDrive, iResult
Set WshShell= Wscript.Createobject("Wscript.Shell")
Set FSO= Wscript.Createobject("Scripting.FileSystemObject")

sCurrDrive = FSO.GetDriveName(Wscript.ScriptFullName)

'delete substituted drives on the target drive letter-- won't affect mounted or real drives.
WshShell.Run "%comspec% /c if exist " & TARGETDRIVE & " subst " & TARGETDRIVE & " /d", 0, True

'Substitute USB drive/directory as target drive
sCmd = "%comspec% /c subst " & TARGETDRIVE & " """ & sCurrDrive & SUBDIR & """"
iResult = WshShell.Run(sCmd, 0, True)

If iResult > 0 Then
   iResult = MsgBox("Error creating substitute drive " & TARGETDRIVE & ", launch Foobar?", vbYesNo + vbInformation, "Drive Substitution")
   If iResult = vbNo Then Wscript.Quit
End If

' Run Foobar, and then delete subst drive letter when it exits
' (the two are done as one command line, so that Wscript can exit leaving behind only a
' hidden Cmd window to delete the drive letter when the program exits-  much less memory.)
sCmd = "%comspec% /c """ & FOOBARRELATIVEPATH & """&&subst " & TARGETDRIVE & " /d"
WshShell.Run sCmd, 0, False
---------------------------------------------------------------------


Regards,

Gnat

Script for Making Foobar Library Portable on USB Drives

Reply #1
My install is portable, I set my usb hard drive to M: in windows vista and it remembers it each time I connect. I connect to three different computers and all act the same. I don't have to use any script or anything just make sure you install foobar to that drive. You shouldn't have problems, I don't.

Script for Making Foobar Library Portable on USB Drives

Reply #2
What if you connect your usb hard drive to a pc, where M: isn't available any more?

@gnat:
Though i read your post carefully i don't understand how it really works and what you have to do to get it working.
Does it change the usb hard drive letter to U: ?

Script for Making Foobar Library Portable on USB Drives

Reply #3
just posting to say thanks for this. very handy.

as i don't have access to disk management on some pcs that i use, setting a permanent letter for my drive isn't always an option. but this is working fine for me.

would be nice if support for relative paths was part of foobar itself though. not just for music but for custom button images etc.

Script for Making Foobar Library Portable on USB Drives

Reply #4
What if you connect your usb hard drive to a pc, where M: isn't available any more?

What gnat's script does is creating a virtual U: drive referring to the actual USB drive. Which doesn't address the problem if U: is not available anymore... But U: is a quite good bet.
If you put this in a batch file, it'll do the trick too. There's an ugly shell window in the back when foobar runs though... you can get rid of it using utilities like hstart but I haven't found anything really simple.

Code: [Select]
@echo off

rem Set virtual drive letter to be used by foobar ; should always be free, at least from mounted & free drives
set _newdrive=Y:
rem Set relative path to foobar executable from the root of your USB drive
set _fb2krelpath=Install\fb2k\foobar2000.exe

:start
set _curdrive=%cd:~0,3%

if exist %_newdrive% (
rem if newdrive letter already used for a virtual drive we can remove it, use it and restore afterwards.
for /f "usebackq tokens=1,2 delims==> " %%a IN (`subst`) DO if %%~da==%_newdrive% set _olddrive=%%b

subst /d %_newdrive%

if exist %_newdrive% (
echo "%_newdrive% deja utilise !"
pause
goto end
)
)

subst %_newdrive% %_curdrive%

%_newdrive%/%_fb2krelpath%

subst /d %_newdrive%
if exist %_olddrive% subst %_newdrive% %_olddrive%

:end
set _curdrive=
set _olddrive=
set _newdrive=
set _fb2krelpath=

exit
This script does exactly what gnat's does. Except if Y: is used as a virtual drive already, it replaces it by our USB drive and puts it back to its original value when foobar is closed down.

If we don't care about doing that - and thus want to leave Y: referring to the USB drive even after having closed foobar - we can shorten the script and get reduce the shell window appearance to a short blink when launching foobar.
Code: [Select]
@echo off

rem Set virtual drive letter to be used by foobar ; should always be free, at least from mounted & free drives
set _newdrive=Y:
rem Set relative path to foobar executable from the root of your USB drive
set _fb2krelpath=Install\fb2k\foobar2000.exe

:start
set _curdrive=%cd:~0,3%

if exist %_newdrive% (
subst /d %_newdrive%

if exist %_newdrive% (
echo "%_newdrive% already in use !"
pause
goto end
)
)

subst %_newdrive% %_curdrive%

start "foo" /b %_newdrive%/%_fb2krelpath%

:end
set _curdrive=
set _olddrive=
set _newdrive=
set _fb2krelpath=


Script for Making Foobar Library Portable on USB Drives

Reply #5
would be nice if support for relative paths was part of foobar itself though. not just for music but for custom button images etc.


oh yes, that would be great. my main problem is that the custom album art image which you can set in the properties needs an absolute path.

Script for Making Foobar Library Portable on USB Drives

Reply #6
Why use driveletters?

Just mount your USB-Drive(s) to a empty NTFS-Folder e.g. "c:\media\drive01". Everytime you attach your drive it will be mounted to this path. The only one driveletter will be C:
.halverhahn

Script for Making Foobar Library Portable on USB Drives

Reply #7
Everytime you attach your drive it will be mounted to this path.


i think you're missing the point about this being portable. whilst what you say would work, you'd have to manually set that up on each new pc you use. and it requires admin rights and access to disk management which isn't always possible on pcs which are not yours.

Script for Making Foobar Library Portable on USB Drives

Reply #8
Excuse me but, how do you use this 'VB script' you've written? Also, what are the implications for different versions of windows?

Why hasn't anybody written a plug in for relative paths in foobar? It is open source isn't it?


Script for Making Foobar Library Portable on USB Drives

Reply #9
Save the script as "filename.vbs" and double-click-it. If nothing happens use this command: "cscript filename.vbs"

foobar is not open source

Script for Making Foobar Library Portable on USB Drives

Reply #10
Doesn't work for me. In CMS I get Error: invalid character. Which script should I use? When should I use it? Where from etc?

Script for Making Foobar Library Portable on USB Drives

Reply #11
You copy the last line with dashes, didn't you?
Try harder

PS put the script on your USB and run it

Script for Making Foobar Library Portable on USB Drives

Reply #12
You copy the last line with dashes, didn't you?
Try harder

PS put the script on your USB and run it


I've copied everything from the first post. Changed the textfile to .vbs. It won't run from windows explorer (Microsoft Script Host shows an error) so I run it from the cms. Now for some reason when I run it, it just opens the .vbs in notepad. I have Vista :s

drayfuss

Script for Making Foobar Library Portable on USB Drives

Reply #13
the script runs fine for me on both vista and xp. are you sure you only copied just the script?

Code: [Select]
' TARGETDRIVE-- This is an open drive letter where your USB drive can be persistently mounted on
' each computer on which you will use this script. In Foobar you will point your
' Library to this drive to set the absolute paths to your media.
' SUBDIR-- Your probably won't choose to change this value, but it would allow you to map a
' subdirectory of your USB drive as the root of TARGETDRIVE.
' FOOBARRELATIVEPATH-- This string is the relative path from the working directory of this script
' to the foobar executable. If you put this script in the directory containing the
' foobar folder, this should work fine.
'************************************************************

Const TARGETDRIVE = "U:"
Const SUBDIR = "\"
Const FOOBARRELATIVEPATH="foobar2000\foobar2000.exe"

'************************************************************
Dim WshShell, FSO, sCmd, sCurrDrive, iResult
Set WshShell= Wscript.Createobject("Wscript.Shell")
Set FSO= Wscript.Createobject("Scripting.FileSystemObject")

sCurrDrive = FSO.GetDriveName(Wscript.ScriptFullName)

'delete substituted drives on the target drive letter-- won't affect mounted or real drives.
WshShell.Run "%comspec% /c if exist " & TARGETDRIVE & " subst " & TARGETDRIVE & " /d", 0, True

'Substitute USB drive/directory as target drive
sCmd = "%comspec% /c subst " & TARGETDRIVE & " """ & sCurrDrive & SUBDIR & """"
iResult = WshShell.Run(sCmd, 0, True)

If iResult > 0 Then
iResult = MsgBox("Error creating substitute drive " & TARGETDRIVE & ", launch Foobar?", vbYesNo + vbInformation, "Drive Substitution")
If iResult = vbNo Then Wscript.Quit
End If

' Run Foobar, and then delete subst drive letter when it exits
' (the two are done as one command line, so that Wscript can exit leaving behind only a
' hidden Cmd window to delete the drive letter when the program exits- much less memory.)
sCmd = "%comspec% /c """ & FOOBARRELATIVEPATH & """&&subst " & TARGETDRIVE & " /d"
WshShell.Run sCmd, 0, False

Script for Making Foobar Library Portable on USB Drives

Reply #14
Thanks for the help mate. You were right, I hadn't just copied the script. I had all those dashes at the end and then some.

Sorry for being a noob. I'm a flash/javascript coder - never really dealt with this stuff before.

Cheers,

drayfuss

Script for Making Foobar Library Portable on USB Drives

Reply #15
One other question...if people are going through the trouble of writing scripts to mount drives...why doesn't anybody just write a foobar plugin for relative directories? Is it that difficult?

drayfuss

 

Script for Making Foobar Library Portable on USB Drives

Reply #16
There will be no need for that with next big foobar release.


Script for Making Foobar Library Portable on USB Drives

Reply #18
The foobar2000 Beta 1 of the next version has just been released...

No mention of relative paths. On what authority is this rumour?

Cheers,
Drayfuss

Script for Making Foobar Library Portable on USB Drives

Reply #19
My guess is that "the next big release" will be 0.9.7, which the recent beta was not.

Script for Making Foobar Library Portable on USB Drives

Reply #20
On what authority is this rumour?
Words from Case are as reliable as words from Peter. It's coming. Patience.

Script for Making Foobar Library Portable on USB Drives

Reply #21
Is developer accepting suggestions for making library portable?
If so, can someone post link to point in the direction.