News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

WinInet

Started by KoDeR, June 02, 2005, 03:39:32 PM

Previous topic - Next topic

KoDeR

Is it possible to connect size of the file with the progress on the ProgressBar?
(How to get current file size in percents?)
May be here:

.WHILE szBuffer != 0
               invoke InternetReadFile,hUrl,addr Buffer,sizeof Buffer,addr szBuffer
               invoke WriteFile,fHand,addr Buffer,szBuffer,ADDR bwrite,NULL
.ENDW

Tedd

Quote from: KoDeR on June 04, 2005, 11:00:14 AM
I don't understand this :( Is there any API Function for getting filename from url? ::)

See: InternetCrackUrl :wink (in wininet.inc)
No snowflake in an avalanche feels responsible.

KoDeR


typedef struct {
  DWORD dwStructSize;
  LPTSTR lpszScheme;
  DWORD dwSchemeLength;
  INTERNET_SCHEME nScheme;
  LPTSTR lpszHostName;
  DWORD dwHostNameLength;
  INTERNET_PORT nPort;
  LPTSTR lpszUserName;
  DWORD dwUserNameLength;
  LPTSTR lpszPassword;
  DWORD dwPasswordLength;
  LPTSTR lpszUrlPath;
  DWORD dwUrlPathLength;
  LPTSTR lpszExtraInfo;
  DWORD dwExtraInfoLength;
} URL_COMPONENTS,
*LPURL_COMPONENTS;

Members

dwStructSize
    Size of this structure, in bytes.
lpszScheme
    Pointer to a string that contains the scheme name.
dwSchemeLength
    Size of the scheme name, in TCHARs.
nScheme
    INTERNET_SCHEME value that indicates the Internet protocol scheme.
lpszHostName
    Pointer to a string that contains the host name.
dwHostNameLength
    Size of the host name, in TCHARs.
nPort
    Converted port number.
lpszUserName
    Pointer to a string value that contains the user name.
dwUserNameLength
    Size of the user name, in TCHARs.
lpszPassword
    Pointer to a string that contains the password.
dwPasswordLength
    Size of the password, in TCHARs.
lpszUrlPath
    Pointer to a string that contains the URL path.
dwUrlPathLength
    Size of the URL path, in TCHARs.
lpszExtraInfo
    Pointer to a string that contains the extra information (for example, ?something or #something).
dwExtraInfoLength
    Size of the extra information, in TCHARs.

Where is Filename ?



Tedd

It will be the last component after in the string pointed to by lpszUrlPath
So, using dwUrlPathLength to start at the end of that string.. check each character, moving backwards, until you get to the '/' and then move forward one - and that's the start of the filename :wink. You'll probably also have to check just in case there is no '/' so you don't keep scanning past the start of the string (in which case start of the filename is the start of the string.)
No snowflake in an avalanche feels responsible.

KoDeR

So, using dwUrlPathLength to start at the end of that string.. check each character, moving backwards, until you get to the '/' and then move forward one - and that's the start of the filename wink. You'll probably also have to check just in case there is no '/' so you don't keep scanning past the start of the string (in which case start of the filename is the start of the string.)


I've guessed that :8)
But i don't know how to reach character with number NUM in the string STRING :'(
In Delphi it looks so :
while Edit1.Text<>'/' do i:=i-1;
And is it posible to work with Edits and Buttons like that Edit1.Text and etc.

Tedd

(Warning: vomitted code - may not work without a bit of tweaking)

.data?
url_parts db URL_COMPONENTS <?>
.


.code
.
.
mov edi,[url_parts].lpszUrlPath
mov ecx,[url_parts].dwUrlPathLength

@again:
mov al,[edi+ecx]
cmp al,'/'
je @found_it

dec ecx
jmp @again

@found_it:
inc ecx    ;move forward one character
lea eax,[edi+ecx]
;eax points to the filename string

.
.



As for Edit1.Text and such things - these are shortcuts that vb provides for you. You have to do it yourself in asm :P
To get the contents of an edit box, you have to send it a WM_GETTEXT message (and provide some memory for it to put the contents.)
No snowflake in an avalanche feels responsible.

Mark Jones

I was tinkering with a similar idea and came up with this:


.data           ; initialized data
Url         db  "http://heliosstudios.net/temp/winasm.png",0

.data?          ; runtime (uninitialized) data 
filename    dd  ?

.code
    print chr$("URL: ")
    print addr Url
    print chr$(13,10)

    mov edx, offset Url     ; load offset of Url
@@:
    mov al, byte ptr [edx]  ; get a byte into al
    cmp al, 00              ; end of url?
    je @F
    inc edx                 ; search forward
    jmp @B
@@:                         ; now edx points at end of Url
    dec edx                 ; backup one
    mov al, byte ptr [edx]  ; load it
    cmp al, "/"             ; is the last char a "/"?
    jnz @F                  ; if not, leave it alone
    mov byte ptr [edx], 00  ; if so, overwrite it
@@:                         ; we are now at the end of the filename
    dec edx                 ; search backwards one
    mov al, byte ptr [edx]  ; load byte
    cmp al, "/"
    jnz @B                  ; keep looping until the next / is found
    inc edx                 ; move forward one
    mov filename, edx       ; store pointer as filename

    print chr$("Filename: ")
    print dword ptr filename
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

Tedd

Yeah, that should work too :wink and without InternetCrackUrl!! :U

KoDeR: forget about using InternetCrackUrl - if you only want the filename, then it's less work to extract it yourself. Just get the string length and then search backwards :toothy
I'm afraid I suggested that function without looking at exactly what it did ::)
No snowflake in an avalanche feels responsible.

jojo

Instead of WinInet, you might try the simpler UrlMon.DLL:

include   \MASM32\INCLUDE\Urlmon.inc
includelib   \MASM32\lib\Urlmon.lib

UrlBuf   db  "www.google.com",0
AddLoc   db  "C:\mydownloadedstuff.dat",0
...
   invoke URLDownloadToFile,0,ADDR UrlBuf,ADDR AddLoc,0,0