From: Perl R. <pe...@co...> - 2007-06-26 17:57:22
|
Hi all, I'm using Win32::GUI::BitmapInline and I have just one problem with it: the requirement that my script have write access to the current directory. Here's my question: could I simply modify the code in the BitmapInline.pm file (located in "C:\Perl\site\lib\Win32\GUI") so that write access to the current directory is not a requirement? Consider the following code in BitmapInline.pm: sub new { my($class, $data) = @_; open(BMP, ">~$$.tmp") or return undef; binmode(BMP); print BMP MIME::Base64::decode($data); close(BMP); my $B = new Win32::GUI::Bitmap("~$$.tmp"); unlink("~$$.tmp"); return $B; } Could I simply change the 2nd, 6th, and 7th lines in the subroutine so that my script will write to the root of the C:\ drive (as an example) instead of the current directory (see below)? sub new { my($class, $data) = @_; open(BMP, ">C:\\~$$.tmp") or return undef; binmode(BMP); print BMP MIME::Base64::decode($data); close(BMP); my $B = new Win32::GUI::Bitmap("C:\\~$$.tmp"); unlink("C:\\~$$.tmp"); return $B; } If this change will work, would it require me to re-compile Perl or do anything else special? Thanks, Rob |
From: Robert M. <rob...@us...> - 2007-06-26 21:02:54
|
On 26/06/07, Glenn Linderman <pe...@ne...> wrote: > On approximately 6/26/2007 10:57 AM, came the following characters from > the keyboard of Perl Rob: > > > I'm using Win32::GUI::BitmapInline and I have just one problem with > > it: the requirement that my script have write access to the current > > directory. Here's my question: could I simply modify the code in the > > BitmapInline.pm file (located in "C:\Perl\site\lib\Win32\GUI") so that > > write access to the current directory is not a requirement? Consider > > the following code in BitmapInline.pm: > > > > sub new { > > my($class, $data) = @_; > > open(BMP, ">~$$.tmp") or return undef; > > binmode(BMP); > > print BMP MIME::Base64::decode($data); > > close(BMP); > > my $B = new Win32::GUI::Bitmap("~$$.tmp"); > > unlink("~$$.tmp"); > > return $B; > > } > > > > Could I simply change the 2^nd , 6^th , and 7^th lines in the > > subroutine so that my script will write to the root of the C:\ drive > > (as an example) instead of the current directory (see below)? > > > > sub new { > > my($class, $data) = @_; > > open(BMP, ">C:\\~$$.tmp") or return undef; > > binmode(BMP); > > print BMP MIME::Base64::decode($data); > > close(BMP); > > my $B = new Win32::GUI::Bitmap("C:\\~$$.tmp"); > > unlink("C:\\~$$.tmp"); > > return $B; > > > > } > > > > If this change will work, would it require me to re-compile Perl or do > > anything else special? I think it would work fine for you, but it's not a great solution. > Code like that should work... but you will have to reapply it each time > you install or upgrade Win32::GUI. Indeed. If you were to implement a solution that worked generally, then we could apply it to the core distribution, and everyone could benefit. (There's an outstanding bug report about this) > If you used $ENV{'TEMP'} instead, and make the filename > ~$$_bitmapinline.tmp (or something along that line) I'd change my > recommendation, although too long of a name might not be acceptable on > old versions of Win9x. Personally I'd use File::Temp if it is installed on the users system, falling back to the current directory (or perhaps $ENV{TEMP} or $ENV{TMP} if they exist). File::Temp goes to a lot of trouble to find a writable directory in a suitable (system specific) tmp location. > On the other hand, if it is possible to avoid writing the temporary > file, that would be an even better solution. I think it would be, > although I haven't figured out all the details. It's certainly doable, but significantly harder - it'd require some XS stuff to be written either in Win32::GUI::Bitmap or Win32::GUI::BitmapInline. If no one else wants to look into this I'll get around to it eventually, but not anytime soon. Regards, Rob. |
From: Robert M. <rob...@us...> - 2007-08-09 19:15:10
|
On 26/06/07, Robert May wrote: > On 26/06/07, Glenn Linderman wrote: > > On 6/26/2007 10:57 AM, Perl Rob wrote: > > > > > I'm using Win32::GUI::BitmapInline and I have just one problem with > > > it: the requirement that my script have write access to the current > > > directory. > > Indeed. If you were to implement a solution that worked generally, > then we could apply it to the core distribution, and everyone could > benefit. (There's an outstanding bug report about this) That's tracker number: 1586643 http://sourceforge.net/tracker/index.php?func=detail&aid=1586643&group_id=16572&atid=116572 > Personally I'd use File::Temp if it is installed on the users system, > falling back to the current directory (or perhaps $ENV{TEMP} or > $ENV{TMP} if they exist). File::Temp goes to a lot of trouble to find > a writable directory in a suitable (system specific) tmp location. Turns out File::Temp is only in the Core Perl distribution since 5.8.? an d we need a solution that works with 5.6.1 So I'm using File::Spec->tmpdir() to get a writable tmp directory. While I'm at it I'm going to make the module thread-safe (it's currently possible to use it from 2 threads, and get the same tmp filename in each case - that would cause problems. I'll also add some tests. I've got a trial version available - anyone interested in having a copy and trying it out - I've only got very limited access to machines where I don't have write permissions in all the directories? If so, drop me a note. > > On the other hand, if it is possible to avoid writing the temporary > > file, that would be an even better solution. I think it would be, > > although I haven't figured out all the details. > > It's certainly doable, but significantly harder - it'd require some XS > stuff to be written either in Win32::GUI::Bitmap or > Win32::GUI::BitmapInline. I keep forgetting that we have Win32::GUI::DIBitmap in the distribution now. What do people think about the overhead of pulling in Win32::GUI::DIBitmap in order to avoid having to write a temporary file? Regards, Rob. |
From: Robert M. <rob...@us...> - 2008-01-13 20:38:12
|
On 09/08/2007, Robert May <rob...@us...> wrote: > On 26/06/07, Robert May wrote: > > On 26/06/07, Glenn Linderman wrote: > > > On 6/26/2007 10:57 AM, Perl Rob wrote: > > > > > > > I'm using Win32::GUI::BitmapInline and I have just one problem with > > > > it: the requirement that my script have write access to the current > > > > directory. > > That's tracker number: 1586643 > http://sourceforge.net/tracker/index.php?func=detail&aid=1586643&group_id=16572&atid=116572 > > So I'm using File::Spec->tmpdir() to get a writable tmp directory. > > While I'm at it I'm going to make the module thread-safe (it's > currently possible to use it from 2 threads, and get the same tmp > filename in each case - that would cause problems. > > I'll also add some tests. I've just committed changes to deal with this to CVS - it'll be in the next release. Rob. |
From: Quatmann <and...@we...> - 2007-09-04 15:00:28
|
no recompiling is needed, just change the module .. but, to have your script act equal on other systems, where bitmapinline.pm is not patched, just change the working directory in your script to s.th. writeable for everyone before the construction of bitmapinline (I did it that way and it works fine) i.e.: chdir("c:\\temp"); return newIcon Win32::GUI::BitmapInline( q( /<ICONCODE>/ ) ); -- View this message in context: http://www.nabble.com/Modify-the-behavior-of-Win32%3A%3AGUI%3A%3ABitmapInline-tf3983848.html#a12479900 Sent from the perl-win32-gui-users mailing list archive at Nabble.com. |