--------------------------------------------------------------------------
detect.dll 1.0 beta 5                                     //--ruhmkorff--//      
--------------------------------------------------------------------------
Based on LSMail by MrJukes, Vendicator, Jesus_mjjg and ilmcuts.
__________________________________________________________________________

This Litestep module retrieves drive informations as well as internet connection status info
in form of LS-evars, using an internal timer function. It can be used to auto-hide drive-shortcuts, 
auto-display CD- and DVD-titles, auto-hide LSMail or even create an autoplay-on-insert function for single CD/DVDs and much more.

This module is made mainly for scripting i.e it has a skinnable window, but this window only
hosts a small popup-menu for some basic functions. I recommend to use it hidden. A solution 
without window would be preferable, but, as far as I know, the cpu-friendly "OnTimer" 
function requires at least a pseudowindow. So be it ;). Possibly, the window will get more 
functionality in later versions.
You'll need a Litestep version that supports runtime-setting of $evars$. 
A version of wininet.dll (IE 4+) is required for net-check. 

Detect sets following evars (where X = drive letter without ":" and "\"):

$DriveTypeX$
$DriveNameX$
$DriveFSX$
$DriveSerialX$
$DetectFlag$
$Connection$
$ConnectionFlag$
$ConType$
$ConRAS$
$Monitors$
$Display0Name$
$Display0Device$
$DetectLastChange$
$DetectLastStatus$
$DriveList$



$DriveTypeX$    ->   type of volume $DriveType$ = HardDrive,Removable,CD/DVD,RemoteDrive
                     or RamDisk;
                ->   if X = unknown, $DriveTypeX$ = unknown
                ->   if X = no root directory found, $DriveTypeX$ = NoDrive 
                       (= when CDROM-, Floppy-Drive a.s.o. empty)

$DriveNameX$    ->   title of volume
                ->   if no volume title $DriveNameX$ = HardDrive_NoTitle,
                     Removable_NoTitle, CD/DVD_NoTitle RemoteDrive_NoTitle, 
                     RamDisk_NoTitle

                ->   if X = unknown, $DriveNameX$ = unknown

                ->   if X = no root directory found, $DriveNameX$ = NoDrive
$DriveFSX$      ->   file system of volume

                ->   if X = unknown, $DriveFSX$ = NotAvailable
                ->   if X = no root directory found, $DriveFSX$ = NotAvailable

$DriveSerialX$  ->   volume serial number
                ->   if X = unknown, $DriveSerialX$ = 0
                ->   if X = no root directory found, $DriveSerialX$ = 0

$Connection$    ->   $Connection$ = connected if connected (IE4) or name of connection (IE5+)
                     The name of connection should be suitable for evars i.e no blanks and less 
                     than 64 characters.
                ->   $Connection$ = NotAvailable if unable to check connection (IE3, a.s.o)
                ->   $ConType$ = LAN or Modem (if connected)
                ->   $ConRAS$ = RAS or NoRAS
                ->   if not connected, $Connection$ = NoConnection

$ConnectionFlag$->   0 if not connected, 1 if connected

$DetectFlag$    ->   1 or 0, depending if a change in the configuration has
                     occured (1) since last check or not (0).

$Monitors$      ->   number of available Monitors.

$Display0Name$  ->   System name of display (numbers starting with 0)
                     f.e //./DISPLAY1

$Display0Device$->   name of device of display (numbers starting with 0)
                     f.e Ati-Radeon-XX or Nvidia-Riva-XX.

$DetectLastChange$-> drive letter of the last changed drive

$DetectLastStatus$-> number indicating actual status of last changed drive where

                     1 = Hardisk available 
                     2 = Hardisk not available 
                     3 = Remote drive available
                     4 = Remote drive not available
                     5 = Removable drive available
                     6 = Removeable drive not available
                     7 = CD/DVD available
                     8 = CD/DVD not available
                     9 = No drive found
                    10 = Unknown device
                    11 = Floppy 
                    12 = Ramdrive available
                    13 = Ramdrive not available
                   

$DriveList$     -> current logical drives (sequence of drive letters)           

After every check, the command specified by DetectCmd is triggered
for getting an update of your lables or whatever. You can use the DetectFlag
to make commands depending on change.
Please consider that the variables are only available after the first check. If you
use them earlier, you'll get a MessageBox (case you didn't define default evars in step.rc).

Bangs:


!DetectGetDrives                      -> creates evar $drivelist$ with a letter sequence containing current                                                                               valid drives

!DetectCheckDrives                    -> checks drives 

!DetectCheckNet                       -> checks net (even if DetectDisableCheck = true !)

!DetectHide/!DetectShow/!DetectToggle -> visibility

!DetectMove <x> <y>                   -> change position

!DetectSetVar <evar> <value>          -> set any evar by bang

!DetectHook                           -> for LSBox

!DetectCheckDisplay                   -> check display (Monitors), automatic on startup

!DetectFloppy                         -> Floppy is only checked once automatically,
                                         use this bang if you like to check once again.
                                         There is a dummy-entry set for floppy if "A" is
                                         included in "DetectCheckDrives" with the settings and detected
                                         at module start:
                                         $DriveNameA$ = Floppy-A
                                         $DriveTypeA$ = Floppy
                                         $DriveFSA$ = FAT
                                         $DriveSerialA$ = 0

!DetectEject <DriveLetter> <flag>     -> eject/retract drive flag == 1 -> eject
                                                             flag == 0 -> retract

!DetectPopup <x> <y>                  -> Show the popup-menu at position x y.
                                         x y (a drive check is performed before to update it)

!DetectShort <path>                   -> returns the short form of a path fore use with command line
                                         driven programs (I needed this for communication with mplayer).
                                         $dshortpath$ = short but complete path
                                         $dfile$ = the filename only
                                         both are set "0" if no success of function

Settings:


DetectTimer <number>                  -> drive-check time interval in seconds
                                         10 seconds work fine (for me).

DetectX <number>                      -> position X

DetectY <number>                      -> position Y

DetectW <number>                      -> width

DetectH <number>                      -> height

DetectBackBmp <path>                  -> png or bmp

DetectNotificationBmp <path>          -> shown when a change in drive configuration was detected
                                         visible for the time specified in DetectTimer

DetectCmd <command>                   -> bang to be executed after checking

DetectChangeCmd <command>             -> bang to be executed only after a change in configurationn was detected
                                         (this is trigg'd before DetectCmd if both are declared).

DetectCheckDrives <letters>           -> what drives to check (without ":" and "\"), f.e "ACDEXZ", default "CDE"

DetectBackColor <color>

DetectErrorBackColor <color>

DetectStartHidden <true/false> 

DetectAlwaysOnTop <true/false>

DetectDisableCheck <true/false>       -> disable timer triggered checking for drives

DetectNoNetCheck <true/false>         -> disable timer triggerd checking for net, i.e.
                                         it is checked only once at module loading time and 
                                         by manual bang.

DetectAll <true/false>                -> all available volumes will be checked. This requires DriveList enabled
                                         or a manual/script DetectGetDrives.

DetectNoDriveList                     -> disables the timer triggered checkup for available drives (letters). 

DetectMakePretty <true/false>         -> makes $DriveNameX$ looking nicer by usage of 
                                         upper- and lowercase characters and changing "_" to "-".

DetectRMouseCmd                       -> command for righclick on detect button window.

DetectLMouseCmd                       -> command for leftclick on detect button window.





 

(mz)script(s) may look like this:

DetectCmd !update  
DetectChangeCmd !changed

*Script bang !changed

*Script exec !if [%#detectlaststatus%# = "1"][!varset tex "Hardisk-%#detectlastchange%#"][]
*Script exec !if [%#detectlaststatus%# = "2"][!varset tex "NoHardisk-%#detectlastchange%#"][]
*Script exec !if [%#detectlaststatus%# = "3"][!varset  tex "RemoteDrive-%#detectlastchange%#"][]
*Script exec !if [%#detectlaststatus%# = "4"][!varset  tex "NoRemoteDrive-%#detectlastchange%#"][]
*Script exec !if [%#detectlaststatus%# = "5"][!varset tex "RemovableDrive-%#detectlastchange%#"][]
*Script exec !if [%#detectlaststatus%# = "6"][!varset tex "Removable-Empty-%#detectlastchange%#"][]
*Script exec !if [%#detectlaststatus%# = "7"][!varset tex "CD/DVD-%#detectlastchange%#"][]
*Script exec !if [%#detectlaststatus%# = "8"][!varset  tex "CD/DVD-Empty-%#detectlastchange%#"][]
*Script exec !if [%#detectlaststatus%# = "9"][!varset tex "NoDrive-%#detectlastchange%#"][]
*Script exec !if [%#detectlaststatus%# = "10"][!varset tex "Unknown-%#detectlastchange%#"][]
*Script exec !if [%#detectlaststatus%# = "11"][!varset tex "Floppy-%#detectlastchange%#"][]
*Script exec !settip
;!settip sets info-label to text of variable tex
*Script ~bang

*Script bang !Update
        *Script exec !varset labela %#DetectFlag%#
        *Script gotoif ["%{labela}" = "false"] skipp
        *Script exec !PlaySound "C:\WINDOWS\Media\Windows XP-Hardware hinzufgen.wav"
        *Script exec !varset drvpos 525
        
        *Script exec !varset labela %#DriveNameF%#
        *Script exec !varset labelb "Empty"
        *Script exec !varset labelc "CD/DVD"
        *Script exec !LabelSetText labelF %{labela}
        *Script exec !if [%{labela} = "NoDrive"][!LabelHide labelF][!LabelShow labelF]
        *Script exec !if [%{labela} = "CD/DVD_NoInfo"][!LabelSetText labelF %{labelb}][]
        *Script exec !if [%{labela} = "CD/DVD_NoTitle"][!LabelSetText labelF %{labelc}][]
        *Script exec !if [%{labela} = "Removable_NoInfo"][!LabelSetText labelF %{labelc}][]
        *Script exec !if [%{labela} = "Removable_NoTitle"][!LabelSetText labelF %{labelc}][]
        *Script exec !LabelMove labelF %#lrim%# %{drvpos}
        *Script exec !if [%{labela} <> "NoDrive"][!varadd drvpos 25][]
         
        *Script exec !varset labela %#DriveNameG%#
        *Script exec !varset labelb "Empty"
        *Script exec !varset labelc "CD/DVD"
        *Script exec !LabelSetText labelG %{labela}
        *Script exec !if [%{labela} = "NoDrive"][!LabelHide labelG][!LabelShow labelG]
        *Script exec !if [%{labela} = "CD/DVD_NoInfo"][!LabelSetText labelG %{labelb}][]
        *Script exec !if [%{labela} = "CD/DVD_NoTitle"][!LabelSetText labelG %{labelc}][]
        *Script exec !if [%{labela} = "Removable_NoInfo"][!LabelSetText labelG %{labelc}][]
        *Script exec !if [%{labela} = "Removable_NoTitle"][!LabelSetText labelG %{labelc}][]
        *Script exec !LabelMove labelG %#lrim%# %{drvpos}
        *Script exec !if [%{labela} <> "NoDrive"][!varadd drvpos 25][] 

        *Script exec !varset labela %#DriveNameL%#
        *Script exec !varset labelb "Empty"
        *Script exec !varset labelc "Removeable"
        *Script exec !LabelSetText labelL %{labela}
        *Script exec !if [%{labela} = "NoDrive"][!LabelHide labelL][!LabelShow labelL]
        *Script exec !if [%{labela} = "CD/DVD_NoInfo"][!LabelSetText labelL %{labelb}][]
        *Script exec !if [%{labela} = "CD/DVD_NoTitle"][!LabelSetText labelL %{labelc}][]
        *Script exec !if [%{labela} = "Removable_NoInfo"][!LabelSetText labelL %{labelc}][]
        *Script exec !if [%{labela} = "Removable_NoTitle"][!LabelSetText labelL %{labelc}][]
        *Script exec !LabelMove labelL %#lrim%# %{drvpos}
        *Script exec !if [%{labela} <> "NoDrive"][!varadd drvpos 25][]
             
        *Script exec !varset labela %#DriveNameZ%#
        *Script exec !varset labelb "Empty"
        *Script exec !varset labelc "Crypt_Volume"
        *Script exec !LabelSetText labelZ %{labela}
        *Script exec !if [%{labela} = "NoDrive"][!LabelHide labelZ][!LabelShow labelZ]
        *Script exec !if [%{labela} = "HardDrive_NoTitle"][!LabelSetText labelZ %{labelc}][]
        *Script exec !LabelMove labelZ %#lrim%# %{drvpos}
        *Script exec !if [%{labela} <> "NoDrive"][!varadd drvpos 25][] 
          
        *Script exec !varset labela %#Connection%#
        *Script exec !if [%{labela} = "NoConnection"][!LabelHide ma][!LabelShow mail]
        *Script exec !varset drvpos 475
        *Script label skipp
        
*Script ~bang


Known issues:


It is only tested on XP (actually I couldnt even test it on an other computer), and I had also no opportunity to test net-drives, ramdisks, many drives a.s.o. It is a true beta. 
Reports are welcome. 
Nothing dangerous should happen, the module simply utilizes the InternetGetConnectedState(Ex), GetDriveType and GetVolumeInfo WinApi-functions.


Have fun !


Changes:

beta 5..
..Added support for negative, C(center) values for main button and popup position.
..Added DetectLastChange, DetectLastStatus.
..Added DetectChangeCmd.
..Renamed NetDrive to RemoteDrive.
..Check of net connection starts as separate thread now. 
..Added separate bangs for drive- and net-check.
..Changed DetectFlag from "true" and "false" to "1" and "0".
..Added drivelist evar.
..Added left- and rightklick commands, removed default rightclick popup,
  use !detectpopup instead.
..Added !detectshort for 8.3(DOS) filepath retrieval.
..Fixed !detectpopup not showing at mouse position if no X Y parameters were given.
..Changed threading code (replaced CreateThread with _beginthreadex). Please report bugs, leaks.


beta 4..
..Corrected permanent floppy access bug. Sorry for that.
..Added monitor information.
..Added drive eject bang.
..Added popup menu activation by bang.
..Changed from errorbmp to notificationbmp for notification of changes.
..All connection evars set to "NoConnection" if no connection instead of not setting them.

beta 3..
..LSBox hooking fixed.
..Message handling fixed (refresh, revid).
..better menu handling.
..detectflag for changes fixed.
..added DetectMakePretty for drivenames.

beta 2..
..Modernized the module according to newer standards (SafeString not included yet).
..Made the popup menu a little smarter. Drives can be accessed via a submenu if present.
..Did some general code cleanup.
Still needs a some serious work, but I am learning.... 




