On 26/06/07, Glenn Linderman <[EMAIL PROTECTED]> 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.

Reply via email to