.386
.MODEL FLAT,STDCALL
locals
jumps

UNICODE = 0

include         win32.inc
includelib      import32.lib

IDC_STATIC      equ     -1
IDD_DIALOG1     equ     103
IDD_DIALOG2     equ     104
IDI_ICON        equ     105
IDC_EDIT1       equ     1000
IDC_EDIT2       equ     1001
IDC_EDIT3       equ     1002
IDC_EDIT4       equ     1003
IDC_EDIT5       equ     1004
IDC_EDIT6       equ     1005
IDC_EDIT7       equ     1006
IDC_EDIT8       equ     1007
IDC_EDIT9       equ     1008
IDC_EDIT10      equ     1009
IDC_EDIT11      equ     1010
IDC_EDIT12      equ     1011
IDC_EDIT13      equ     1012
IDC_EDIT14      equ     1013

IDC_TEXT1       equ     3000
IDC_TEXT2       equ     3001
IDC_TEXT3       equ     3002
IDC_TEXT4       equ     3003
IDC_TEXT5       equ     3004
IDC_TEXT6       equ     3005
IDC_TEXT7       equ     3006
IDC_TEXT8       equ     3007
IDC_TEXT9       equ     3008
IDC_TEXT10      equ     3009
IDC_TEXT11      equ     3010
IDC_TEXT12      equ     3011

ICON_SMALL      equ     0
IDDEC           equ     2000
IDINC           equ     2001
IDEXIT		equ	2003
IDHLP           equ     2002

IDM_ABO         equ     4001
IDM_EXIT	equ	4002

.DATA

hInst           dd ?
hIcon           dd ?

fmat1           db "%lu", 0             ; Unsigned decimal long.
fmat2           db "%lX", 0             ; Hexadecimal long.

msg             MSGSTRUCT <?>
pnt             PAINTSTRUCT <?>
rect            RECT <>
DlgWidth        dd ?
DlgHeight       dd ?
DesktopRect     RECT <>

cdrive          db 'a:\', 0
ddrive          db 'a'

DriveType       dd 0
Tot_clust       dd 0
Free_clust      dd 0
BytesPSect      dd 0
SectPClust      dd 0
vol_filenames   equ 16
vol_filename    db vol_filenames dup(0)
vol_filesys     dd 0
vol_Maxfilelen  dd 0
vol_serial      dd 0
vol_Names       equ 16
vol_Name        db vol_Names dup(0)

net_Names       dd 32
net_Name        db 32 dup(0)
numbuff         db 64 dup(0)

TypeTab         dd offset nullst
                dd offset nullst
                dd offset TypeID2
                dd offset TypeID3
                dd offset TypeID4
                dd offset TypeID5
                dd offset TypeID6

TypeID2         db ' (Removable)', 0,0,0,0
TypeID3         db ' (Fixed)', 0,0,0,0,0,0,0,0
TypeID4         db ' (Network)', 0,0,0,0,0,0
TypeID5         db ' (CD-ROM)', 0,0,0,0,0,0,0
TypeID6         db ' (RamDisk)', 0,0,0,0,0,0

nullst          db 16 dup(0)

.CODE
;----------------------------------------------------------------------
main:
        mov eax, offset jjj

        call    GetModuleHandle, NULL
        mov     hInst, eax
        call    DialogBoxParamA, hInst, IDD_DIALOG1, 0, offset DlgProc, 0
        call    ExitProcess
;----------------------------------------------------------------------

DlgProc PROC hwnd:DWORD, wmsg:DWORD, wparam:DWORD, lparam:DWORD

        mov     eax, wmsg
        cmp     ax, WM_DESTROY
        je      wmdestroy
        cmp     ax, WM_CLOSE
        je      wmdestroy
        cmp     ax, WM_COMMAND
        je      wmcommand
        cmp     ax, WM_INITDIALOG
        je      initdlg
        cmp     ax, WM_PAINT
        je      paint
        xor     eax,eax
        ret
;----------------------------------------------------------------------
wmdestroy:
        call EndDialog, hwnd, 0
        call ExitProcess
        ret
;----------------------------------------------------------------------
wmcommand:
	cmp	wparam, IDEXIT
	je	wmdestroy
	cmp     wparam, IDINC
        jne     noinc                          ; Increment drive
        call    GetDlgItem, hwnd, IDDEC
        call    EnableWindow, eax, true        ; Enable DEC Button

        mov     al, byte ptr [offset cdrive]
        mov     byte ptr [offset ddrive], al
lb_1:
        inc     byte ptr [offset cdrive]
        cmp     byte ptr [offset cdrive], 'z'
        jbe     notou1
        mov     al, byte ptr [offset ddrive]
        mov     byte ptr [offset cdrive], al    ; Restore to last value
        call    GetDlgItem, hwnd, IDINC
        call    EnableWindow, eax, false       ; Disable INC Button
        ret
notou1:
        call    GetDriveTypeA, offset cdrive
        cmp     eax, 1
        jbe     lb_1
        call    GetDriveI, hwnd              ; Show drive info
        ret
;----------------------------------------------------------------------
noinc:
        cmp     wparam, IDDEC
        jne     nodec                          ; Decrement drive
        call    GetDlgItem, hwnd, IDINC
        call    EnableWindow, eax, true        ; Enable INC Button

        mov     al, byte ptr [offset cdrive]
        mov     byte ptr [offset ddrive], al
lb_2:
        dec     byte ptr [offset cdrive]
        cmp     byte ptr [offset cdrive], 'a'
        jae     notou2
        mov     al, byte ptr [offset ddrive]
        mov     byte ptr [offset cdrive], al

        call    GetDlgItem, hwnd, IDDEC
        call    EnableWindow, eax, false       ; Disable DEC Button
        ret
notou2:
        call    GetDriveTypeA, offset cdrive
        cmp     eax, 1
        jbe     lb_2
        call GetDriveI, hwnd
        ret
nodec:
        cmp     wparam, IDM_ABO
        jne     nohlp

        call    GetModuleHandle, NULL          ; Get the handle to our app
        call    DialogBoxParamA, eax, IDD_DIALOG2, hwnd, offset DlgProc2, 0

nohlp:
        cmp     wparam, IDM_EXIT
        jne     noext
        jmp     wmdestroy
noext:
        xor     eax, eax
        ret


;---------------------------------------; Center dialog, put icon
initdlg:
;	call    LoadIcon, hInst, IDI_ICON
;	mov     hIcon, eax
        call    GetWindowRect, hwnd, offset rect           ; Get DlgRect
        call    GetDesktopWindow
        call    GetWindowRect, eax, offset DesktopRect     ; Get Desktop rect

        mov     eax, rect.rcBottom
        sub     eax, rect.rcTop
        mov     DlgHeight, eax                  ; Dialog box height
        mov     eax, rect.rcRight
        sub     eax, rect.rcLeft
        mov     DlgWidth, eax                   ; Dialog box width
        mov     ebx, DesktopRect.rcBottom
        sub     ebx, DlgHeight
        shr     ebx, 1                          ; ebx = Start y
        mov     ecx, DesktopRect.rcRight
        sub     ecx, DlgWidth
        shr     ecx, 1                          ; ecx = Start x

        call    MoveWindow, hwnd, ecx, ebx, DlgWidth, DlgHeight, 0   ; Centre
        call    GetDriveI, hwnd              ; Get drive info
        ret
;----------------------------------------------------------------------
paint:
        call    BeginPaint, hwnd, offset pnt

;    push hIcon                         ; Icon Handle
;    push 204                            ; Start Y
;    push 10                             ; Start X
;    push eax                            ; The hDc (returned by BeginPaint)
;    call DrawIcon                       ; Draw it

	call    EndPaint, hwnd, offset pnt
	ret
DlgProc endp

;----------------------------------------------------------------------

DlgProc2 PROC	hwnd:DWORD, wmsg:DWORD, wparam:DWORD, lparam:DWORD

        mov     eax, wmsg
        cmp     ax, WM_DESTROY
        je      wmdestroy2
        cmp     ax, WM_CLOSE
        je      wmdestroy2
        cmp     ax, WM_COMMAND
        je      wmcommand2
        cmp     ax, WM_INITDIALOG
        je      initdlg2
        cmp     ax, WM_PAINT
        je      paint2
        xor     eax,eax
        ret
;----------------------------------------------------------------------
wmdestroy2:
        call    EndDialog, hwnd, 0
        ret
paint2:
        call	BeginPaint, hwnd, offset pnt
        call    EndPaint, hwnd, offset pnt
        ret
initdlg2:
        call    GetWindowRect, hwnd, offset rect                  ; Get DlgRect
        call    GetDesktopWindow
        call    GetWindowRect, eax, offset DesktopRect     ; Get Desktop rect

        mov     eax, rect.rcBottom
        sub     eax, rect.rcTop
        mov     DlgHeight, eax                  ; Dialog box height
        mov     eax, rect.rcRight
        sub     eax, rect.rcLeft
        mov     DlgWidth, eax                   ; Dialog box width
        mov     ebx, DesktopRect.rcBottom
        sub     ebx, DlgHeight
        shr     ebx, 1                          ; ebx = Start y
        mov     ecx, DesktopRect.rcRight
        sub     ecx, DlgWidth
        shr     ecx, 1                          ; ecx = Start x

        call MoveWindow, hwnd, ecx, ebx, DlgWidth, DlgHeight, 0   ; Centre
        ret
wmcommand2:
        cmp     wparam, IDOK
        jne     nook
        jmp     wmdestroy2
nook:
        ret
DlgProc2 endp

;----------------------------------------------------------------------

GetDriveI proc hDlg:dword

        call    SetDlgItemTextA, hDlg, IDC_EDIT1, offset cdrive       ; Drive let
        call    GetDriveTypeA, offset cdrive
        cmp     eax, 1
        jbe     notva
        mov     DriveType, eax
        call    jprintf, offset numbuff, offset fmat1, DriveType
        mov     esi, offset numbuff
fend1:
        lodsb
        or      al, al
        jnz     fend1
        dec     esi                             ; Overwrite 0
        mov     edi, esi                        ; edi ->
        mov     esi, DriveType
        cmp     esi, 6
        ja      nocand
        mov     esi, dword ptr [offset TypeTab + esi*4]
        mov     ecx, 16
        rep     movsb

        mov     eax, true
        cmp     DriveType, 4
        je      isnetw
        mov     eax, false
isnetw:
        push    eax                            ; For EnableWindow (true\false)
        call    GetDlgItem, hwnd, IDC_TEXT12
        push    eax
        call    EnableWindow                   ; Enable/Disable Network path

nocand:
        call    SetDlgItemTextA, hDlg, IDC_EDIT8, offset numbuff      ; Type ID
        push    offset Tot_clust
        push    offset Free_clust
        push    offset BytesPSect
        push    offset SectPClust
        push    offset cdrive
        call    GetDiskFreeSpaceA              ; Get free disk space

        call    jprintf, offset numbuff, offset fmat1, SectPClust
        call    SetDlgItemTextA, hDlg, IDC_EDIT2, offset numbuff      ; Sect/cluster
        call    jprintf, offset numbuff, offset fmat1, BytesPSect
        call    SetDlgItemTextA, hDlg, IDC_EDIT3, offset numbuff      ; Bytes/Sect
        call    jprintf, offset numbuff, offset fmat1, Free_clust
        call    SetDlgItemTextA, hDlg, IDC_EDIT4, offset numbuff      ; Free clusts
        call    jprintf, offset numbuff, offset fmat1, Tot_clust
        call    SetDlgItemTextA, hDlg, IDC_EDIT5, offset numbuff      ; Tot clusters

jjj:
        mov eax, Tot_clust
        cdq
        imul    SectPClust
        imul    BytesPSect
        call    PutBytes
        call    SetDlgItemTextA, hDlg, IDC_EDIT13, offset numbuff      ; Tot space

        mov     eax, Free_clust
        cdq
        imul    SectPClust
        imul    BytesPSect
        call    PutBytes
        call    SetDlgItemTextA, hDlg, IDC_EDIT14, offset numbuff      ; Free space


;----------------------------------------------------------------------
        push    vol_filenames
        push    offset vol_filename
        push    offset vol_filesys
        push    offset vol_Maxfilelen
        push    offset vol_serial
        push    vol_Names
        push    offset vol_Name
        push    offset cdrive
        call    GetVolumeInformationA

        call    jprintf, offset numbuff, offset fmat1, vol_Maxfilelen
        call    SetDlgItemTextA, hDlg, IDC_EDIT6, offset numbuff      ; Max fn len
        call    jprintf, offset numbuff, offset fmat2, vol_filesys
        call    SetDlgItemTextA, hDlg, IDC_EDIT7, offset numbuff      ; Filesys flgs
        call    jprintf, offset numbuff, offset fmat2, vol_serial
        call    SetDlgItemTextA, hDlg, IDC_EDIT10, offset numbuff     ; Serial Num
        call    SetDlgItemTextA, hDlg, IDC_EDIT11, offset vol_filename; FileSys
        call    SetDlgItemTextA, hDlg, IDC_EDIT9, offset vol_Name     ; Volume

;----------------------------------------------------------------------
        push    offset net_Names
        push    offset net_Name
        push    1
        push    offset cdrive
        call    WNetGetUniversalNameA

        mov     esi, dword ptr [offset net_Name]
        or      esi, esi
        jnz     nonet1
        mov     esi, offset nullst
nonet1:
        call    SetDlgItemTextA, hDlg, IDC_EDIT12, esi                ; Network Path
notva:
        ret
GetDriveI endp
;----------------------------------------------------------------------------;
PutBytes proc
        or      edx, edx
        jnz     isbig3		; If > 4Gig
        cmp     eax, 1024	; > 1k?
        jae     isbig1
        call    jprintf, offset numbuff, offset fmat1, eax
        ret
isbig1:
        cmp     eax, 1024*1024
        jae     isbig2
        mov     si, 'bK'
dok:
        mov     ecx, 1024
        mov     ebx, 1000
        idiv    ecx
        mov     ecx, eax	; ecx = Integer, edx = MOD
        mov     eax, edx
        cdq
        imul    ebx
        mov     ebx, 1024
        idiv    ebx		; eax = Frac
        push    esi
        push    eax
        call    jprintf, offset numbuff, offset fmat1, ecx
        pop     eax
        call    fendnum
        mov     byte ptr [edi], '.'
        inc     edi
        cmp     eax, 100
        jae     okl1
        mov byte ptr [edi], '0'
        inc     edi
        cmp     eax, 10
        jae     okl1
        mov     byte ptr [edi], '0'
        inc     edi
okl1:
        call    jprintf, edi, offset fmat1, eax
        call    fendnum
        pop     esi
        mov     byte ptr [edi], ' '
        mov     word ptr [edi + 1], si
        mov     byte ptr [edi + 3], 0
        ret
isbig2:
        cmp     eax, 1024*1024*1024
        jae     isbig3
        mov     ecx, 1024
        idiv    ecx
        cdq
        mov     si, 'bM'
        jmp     dok
isbig3:
        mov     ecx, 1024 * 1024
        idiv    ecx
        cdq
        mov     si, 'bG'
        jmp     dok
PutBytes endp
;----------------------------------------------------------------------------;
fendnum  proc
        mov     edi, offset numbuff
lopfs:
        cmp     byte ptr [edi], 0
        je      fouio
        inc     edi
        jmp     lopfs
fouio:
        ret
fendnum  endp

jprintf proc p1:dword, p2:dword, p3:dword
        push    p3
        push    p2
        push    p1
        call    _wsprintfA
        add     esp, 12
        ret
jprintf endp
;----------------------------------------------------------------------
ends
    end main
