Downloading torrents from firefox on 64-bit Vista

Specific support for Deluge on Microsoft Windows OS
apocryph

Downloading torrents from firefox on 64-bit Vista

Post by apocryph »

Hello:
I just switched to Deluge from Azureus, and I want to thank the developers for their excellent work. Azureus does have a couple of neat features lacking in Deluge, but it seems with each new Azureus release things become more clumsy and unreliable, not to mention memory-hungry.

My configuration is this:
* deluged and Deluge web UI running on my dedicated Ubuntu Hardy (8.04) 64-bit seedbox
* deluge GTK client running on my Windows Vista 64-bit laptop, connecting to the daemon on my seedbox

I find and download torrents on my laptop using Firefox 3.x, which unfortunately is only available as a 32-bit application. This created problems when trying to get firefox to launch Deluge with downloaded torrents. When I told Firefox to run C:\Program Files\Deluge\deluge.cmd to open torrent files, it wouldn't work, and would instead pop up a message box titled "StartX" with the message "Failed to run the program, Error267, The directory name is invalid."

I poked around a bit with Process Explorer and found that, long story short, the 32-bit firefox was invoking a 32-bit cmd.exe command processor, which was looking for Deluge in "Program Files (x86)" thanks to the annoying redirection feature in 64-bit versions of Windows. I came up with a fix that involves wrapping deluge.cmd in another batch file, which I call deluge32.cmd:

Code: Select all

@echo off
rem Wrapper around deluge.cmd which will ensure the 64-bit command processor is used even if this batch file is invoked with the 32-bit
rem command processor
rem 
rem Use with 32-bit firefox on 64-bit windows with 64-bit deluge.  Any other use is completely untested
set DELUGEDIR=C:\Program Files\Deluge

%windir%\sysnative\cmd.exe /c "%DELUGEDIR%\deluge.cmd" %*
This simple batch file forces the deluge.cmd script to be processed by the 64-bit cmd.exe, even if it's invoked from 32-bit windows. So, I configured Firefox to open torrent files with my deluge32.cmd script instead, and now it works great.

From my poking around on the forums, it seems there's been trouble with Deluge on 64-bit windows for some time now. I would like to suggest to the developers that the default Windows file association for torrent files should be a wrapper script like the above, otherwise any 32-bit application that attempts to launch a torrent file will have this problem.
phuzz
Member
Member
Posts: 25
Joined: Sat Mar 22, 2008 2:22 pm

Re: Downloading torrents from firefox on 64-bit Vista

Post by phuzz »

Nice one, that works great :)
markybob
Compulsive Poster
Compulsive Poster
Posts: 1230
Joined: Thu May 24, 2007 11:27 pm
Location: Chicago, IL, USA
Contact:

Re: Downloading torrents from firefox on 64-bit Vista

Post by markybob »

apocryph wrote:Hello:
I just switched to Deluge from Azureus, and I want to thank the developers for their excellent work. Azureus does have a couple of neat features lacking in Deluge, but it seems with each new Azureus release things become more clumsy and unreliable, not to mention memory-hungry.

My configuration is this:
* deluged and Deluge web UI running on my dedicated Ubuntu Hardy (8.04) 64-bit seedbox
* deluge GTK client running on my Windows Vista 64-bit laptop, connecting to the daemon on my seedbox

I find and download torrents on my laptop using Firefox 3.x, which unfortunately is only available as a 32-bit application. This created problems when trying to get firefox to launch Deluge with downloaded torrents. When I told Firefox to run C:\Program Files\Deluge\deluge.cmd to open torrent files, it wouldn't work, and would instead pop up a message box titled "StartX" with the message "Failed to run the program, Error267, The directory name is invalid."

I poked around a bit with Process Explorer and found that, long story short, the 32-bit firefox was invoking a 32-bit cmd.exe command processor, which was looking for Deluge in "Program Files (x86)" thanks to the annoying redirection feature in 64-bit versions of Windows. I came up with a fix that involves wrapping deluge.cmd in another batch file, which I call deluge32.cmd:

Code: Select all

@echo off
rem Wrapper around deluge.cmd which will ensure the 64-bit command processor is used even if this batch file is invoked with the 32-bit
rem command processor
rem 
rem Use with 32-bit firefox on 64-bit windows with 64-bit deluge.  Any other use is completely untested
set DELUGEDIR=C:\Program Files\Deluge

%windir%\sysnative\cmd.exe /c "%DELUGEDIR%\deluge.cmd" %*
This simple batch file forces the deluge.cmd script to be processed by the 64-bit cmd.exe, even if it's invoked from 32-bit windows. So, I configured Firefox to open torrent files with my deluge32.cmd script instead, and now it works great.

From my poking around on the forums, it seems there's been trouble with Deluge on 64-bit windows for some time now. I would like to suggest to the developers that the default Windows file association for torrent files should be a wrapper script like the above, otherwise any 32-bit application that attempts to launch a torrent file will have this problem.
this will be in our next release. thanks
GFree
New User
New User
Posts: 5
Joined: Wed Dec 10, 2008 10:44 am

Re: Downloading torrents from firefox on 64-bit Vista

Post by GFree »

I'm also running Vista 64-bit, but I can't seem to get your script to work. For one thing, my error message differs from yours:

Failed to run the program, Error:2, The system cannot find the file specified.

Also, %windir%\sysnative\cmd.exe doesn't run because there ISN'T a sysnative folder! Where did yours come from?

I tried replacing sysnative with System32 and then SysWOW64, but neither of them worked. Could you please double-check your script and if possible, provide a clear set of steps for getting this to work? I don't want to have to wait for Deluge 1.0.7 before I can use Firefox directly with my torrents. :D
markybob
Compulsive Poster
Compulsive Poster
Posts: 1230
Joined: Thu May 24, 2007 11:27 pm
Location: Chicago, IL, USA
Contact:

Re: Downloading torrents from firefox on 64-bit Vista

Post by markybob »

GFree wrote:I'm also running Vista 64-bit, but I can't seem to get your script to work. For one thing, my error message differs from yours:

Failed to run the program, Error:2, The system cannot find the file specified.

Also, %windir%\sysnative\cmd.exe doesn't run because there ISN'T a sysnative folder! Where did yours come from?

I tried replacing sysnative with System32 and then SysWOW64, but neither of them worked. Could you please double-check your script and if possible, provide a clear set of steps for getting this to work? I don't want to have to wait for Deluge 1.0.7 before I can use Firefox directly with my torrents. :D
actually, i just tried to package 1.0.7, and i couldnt get this to work in my tests, either. for unrelated reasons, we're waiting until tomorrow to package it, so hopefully there'll be a fix for this before then. i honestly dont know much about windows, which is why deluge's windows client isnt as good as our linux client....and we sure could use the help.
riverfr0zen
New User
New User
Posts: 5
Joined: Fri Dec 05, 2008 10:11 am

Re: Downloading torrents from firefox on 64-bit Vista

Post by riverfr0zen »

Explanation of sysnative: http://www.tipandtrick.net/2008/how-to- ... 4-windows/

Anyway, the following is working well for me now. First, the solution (based on apocryph's solution), and then I will explain:
[EDIT: Please note that this is based on 1.0.6 -- didn't realize 1.0.7 is out already -- maybe the issue is already fixed there? Haven't had a chance to try it yet]

1) Change the previously created deluge32.cmd so it now contains this:

Code: Select all

@echo off
rem Wrapper around deluge.cmd which will ensure the 64-bit command processor is used even if this batch file is invoked with the 32-bit
rem command processor
rem
rem Use with 32-bit firefox on 64-bit windows with 64-bit deluge.  Any other use is completely untested
set DELUGEDIR=C:\Program Files\Deluge

%windir%\sysnative\cmd.exe /c "%DELUGEDIR%\Scripts\deluge-from-app.cmd" %*
2) Now, create a new file in the Scripts directory, deluge-from-app.cmd, containing the following:

Code: Select all

@echo off
set PATH=%CD%;%PROGRAMFILES%\deluge;%PROGRAMFILES%\deluge\Lib\site-packages\deluge-1.0.6-py2.5-win32.egg\deluge;%PROGRAMFILES%\deluge\Lib\site-packages\deluge-1.0.6-py2.5-win32.egg\deluge\lib;%PROGRAMFILES%\deluge\Lib\site-packages\deluge-1.0.6-py2.5-win32.egg\deluge\share;%PROGRAMFILES%\deluge\Lib\site-packages\deluge-1.0.6-py2.5-win32.egg\deluge\etc;%PATH%;

set PYTHONPATH=%PROGRAMFILES%\deluge\Lib;%PROGRAMFILES%\deluge\DLLs;%PROGRAMFILES%\deluge\Lib\site-packages;%PROGRAMFILES%\deluge\Lib\site-packages\deluge-1.0.6-py2.5-win32.egg\deluge;%PROGRAMFILES%\deluge\Lib\site-packages\deluge-1.0.6-py2.5-win32.egg\deluge-1.0.6-py2.5-win32.egg;

set FOLDER=%PROGRAMFILES%\deluge\scripts && cd %PROGRAMFILES%\deluge\scripts

%WINDIR%\StartX.exe /b /D "%FOLDER%" "%PROGRAMFILES%\deluge\scripts\deluge.exe @QUOTE@%1@QUOTE@"
EXIT
Note: Each of the 3 'set' variable lines above are single lines (hopefully the formatting won't break them up when you copy and paste, but just in case ...)

Ok, so that's basically it. Now tell firefox to open files with deluge32.cmd, and you should be set. So now the explanation -- but before I go on, I must admit it has been nearly a decade since I've done anything of significance on Windows, including shell scripting, so I'm not pretending like I *really* know what's going on here :) That being said:

Basically, apocryph's solution seemed to work for me initially, but later it seemed to be on-and-off. It would work sometimes, and others not. What I came to realize was that it *would* work if Deluge had previously been opened (and closed, daemon and all) via the Start Menu option during the Windows logon session. Don't ask me why, I have no real idea. My suspicion is some env vars got defined on the system when it was opened via the Start Menu.

This made me look at deluge.cmd in the main directory -- since deluge32.cmd was simply invoking it via the correct 64-bit shell. True enough, if you ran deluge.cmd directly from the 64-bit shell, it flaked out. So basically, the solution was simply to copy the last couple of lines from deluge.cmd in the main dir, and put it into deluge-from-app.cmd under Scripts (there are other deluge[N].cmd files in Scripts, so I just named it like this to avoid confusion). Then, I lazily copied the environment vars settings from Scripts/deluge.cmd (this is the file that is called by the Start Menu shortcut), and dumped them at the top.

That's pretty much it -- you could probably get a lot more elegant, if you want only one .cmd file for everything to use, but this is basically the quick hack, and it's working quite sweetly for me.
Mindzai
Member
Member
Posts: 47
Joined: Sat Oct 04, 2008 5:06 pm
Location: England

Re: Downloading torrents from firefox on 64-bit Vista

Post by Mindzai »

I also get

Failed to run the program, Error:2, The system cannot find the file specified.

on WinXP 32bit using Deluge 1.07
GFree
New User
New User
Posts: 5
Joined: Wed Dec 10, 2008 10:44 am

Re: Downloading torrents from firefox on 64-bit Vista

Post by GFree »

I can confirm the problem still exists in 1.0.7. I'll try the wrapper script again and see if anything changes.

EDIT: I still can't get the script to work. I've put the deluge32.cmd in the main Deluge folder and deluge-from-app.cmd in Scripts, and am telling firefox to run deluge32.app when I open a torrent file.

EDIT: I've modified the script slightly to get it to run from Firefox, but it now insists on showing the connection manager. If I delete the deulge folder from my Users folder (ie. start with no config) and launch Deluge manually (ie. 64-bit), it works fine, but the 32 bit version spawn the manager as well.
Last edited by GFree on Tue Dec 23, 2008 1:32 am, edited 1 time in total.
riverfr0zen
New User
New User
Posts: 5
Joined: Fri Dec 05, 2008 10:11 am

Re: Downloading torrents from firefox on 64-bit Vista

Post by riverfr0zen »

Upgraded to 1.0.7, and the fix I outlined above still works for me.

Edit: @Gfree -- are you telling Firefox to run deluge32.cmd or deluge32.app? Should be deluge32.cmd
GFree
New User
New User
Posts: 5
Joined: Wed Dec 10, 2008 10:44 am

Re: Downloading torrents from firefox on 64-bit Vista

Post by GFree »

Ok, I'm going to remove my changes and go back to what your scripts have riverfr0zen, so that I can walk through my problems. One thing though - since 1.0.7 is out, I did a find+replace on your second script to change all occurrences of 1.0.6 to 1.0.7..

(BTW, was running deluge32.cmd)

Well, I ran firefox and deluge didn't pop up. But I did have this in the deluge.log file in my Users folder:

Code: Select all

[INFO    ] 12:07:33 main:85 Deluge ui 1.0.7
[DEBUG   ] 12:07:33 main:86 options: {'config': None, 'logfile': 'deluge.log', 'ui': None}
[DEBUG   ] 12:07:33 main:87 args: ['C:\\Users\\NICHOL~1\\AppData\\Local\\Temp\\devede3.11b-setup.exe.4435033.TPB-8.torrent']
Traceback (most recent call last):
  File "C:\Program Files\deluge\scripts\deluge-script.py", line 7, in <module>
    load_entry_point('deluge==1.0.7', 'console_scripts', 'deluge')()
  File "C:\Program Files\Deluge\lib\site-packages\deluge\main.py", line 89, in start_ui
    from deluge.ui.ui import UI
  File "C:\Program Files\Deluge\lib\site-packages\deluge\ui\ui.py", line 26, in <module>
    import deluge.configmanager
  File "C:\Program Files\Deluge\lib\site-packages\deluge\configmanager.py", line 26, in <module>
    import gobject
  File "C:\Program Files\Deluge\lib\site-packages\gtk-2.0\gobject\__init__.py", line 30, in <module>
    from gobject.constants import *
  File "C:\Program Files\Deluge\lib\site-packages\gtk-2.0\gobject\constants.py", line 22, in <module>
    from _gobject import type_from_name
ImportError: DLL load failed: The specified module could not be found.
I made sure to delete the Deluge folder from my Users folder before running this test, so that things could start fresh and limit problems.

EDIT: I just noticed something. In your scripts you refer to "site-packages\deluge-1.0.7-py2.5-win32.egg". This doesn't exist anymore, the new path appears to simply be "site-packages". I'll try changing these paths and see what happens.
Post Reply