Drive detection module Thread last updated on 2003-11-10 12:43:38

Posted by member 80008 on 2003-11-06 20:39:17

Hallo ,

Recently I've coded a small module that checks a given (step.rc) set of drive letters for availability, type and label and hands back the info in form of evars for use in mzscript. Unfortunately I am not an experienced programmer and I may have no time to polish and improve it so I would like to offer the code here. It is really small and simple and I am not sure if it is worth a separate module. However, let me know what you think about it i.e if anybody is interested in it at all. Sorry for posting code here, structrure (and code ;)) may look ugly.

The checking function called OnTimer:
for(ch = 'A'; ch DrivesToCheck), ch))
{
sprintf(root_path, "%c:", ch);
UINT drive_type = GetDriveType(root_path);
sprintf(temp,"DriveType%c",ch);

switch (drive_type)
{
case (DRIVE_FIXED) : result = GetVolumeInformation(root_path, volume_name_buffer, 1024, &volume_serial_number, &maximum_component_length, &file_system_flags, file_system_name, 1024);

if (result){ strcpy(temp2,volume_name_buffer); LSSetVariable(temp,temp2);
}
else
{ LSSetVariable(temp,"HardDrive");
}
break;

case (DRIVE_REMOTE) : LSSetVariable(temp,"NetDisc");
break;

case (DRIVE_REMOVABLE) : result = GetVolumeInformation(root_path, volume_name_buffer, 1024, &volume_serial_number, &maximum_component_length, &file_system_flags, file_system_name, 1024);
if (result){
strcpy(temp2,volume_name_buffer);
LSSetVariable(temp,temp2);
}
else
{ LSSetVariable(temp,"Removeable");
}
break;

case (DRIVE_CDROM) : result = GetVolumeInformation(root_path, volume_name_buffer, 1024, &volume_serial_number, &maximum_component_length, &file_system_flags, file_system_name, 1024);
if (result){ strcpy(temp2,volume_name_buffer); LSSetVariable(temp,temp2);
}
else
{ LSSetVariable(temp,"CD/DVD");
}
break;

case (DRIVE_NO_ROOT_DIR) : LSSetVariable(temp,"NoDrive");
break;

case (DRIVE_UNKNOWN) : LSSetVariable(temp,"unknown");
break;

case (DRIVE_RAMDISK) : LSSetVariable(temp,"RamDrive");
break;

default : {
if (tool->bLogSupport)
LSLog(LOG_DEBUG, szAppName, "Error checking drives!");
}
}
memset(temp,0,255);
memset(temp2,0,255);
}
}
return TRUE;

The exploit in mzscript looks like this (the script is called by !bang defined in LSToolCmd (I called it LSTool):
LSToolTimer 15
LSToolCmd !Update
LSToolCheckDrives ACDEFX

*Script bang !Update
*Script exec !varset label %#DriveTypeE%#
*Script exec |LabelSetText Label7 %[label]
*Script exec !ifEq label "NoDrive" '|LabelHide
label7' else '|LabelShow label7'
*Script exec !varset label %#DriveTypeA%#
*Script exec |LabelSetText Label8 %[label]
*Script exec !ifEq label "NoDrive" '|LabelHide
label8' else '|LabelShow label8'
*Script exec !varset label %#DriveTypeF%#
*Script exec |LabelSetText Label1 %[label]
*Script exec !ifEq label "NoDrive" '|LabelHide
label1' else '|LabelShow label1'
*Script ~bang

Best regards,

R.

Posted by member 182 on 2003-11-09 19:02:25 link

neat!

i'd really like to see this compiled. i can think of a number of uses for it in my own themes :D

Posted by member 80008 on 2003-11-09 20:27:56 link

Thanks psynapse,

I'd have submitted it as a module, but I was stupid and included a lsmail-like window, menu aso. which is not necessary at all and it will take some time to get rid of this parts. If I find a free weekend I'll try.

Posted by member 1413 on 2003-11-10 12:43:38 link

I could definatly use this in my theme, I'd love to see this finished up.