08-03-2008, 09:03 PM
Function FileExtRegister
Function FileExtUnregister
Function FileExtAddVerb
Function FileExtRemoveVerb
Function FileExtSetDefaultVerb
;/
function $ext $cls $description $icon [$cmd] [$content_type]
;Adds new file extension.
;QM must be running as administrator.
;Error if fails.
;ext - extension.
;cls - class. Can be any string but must not begin with ".".
;description - eg "Vig File".
;icon - eg "c:\program files\x\x.exe,3".
;cmd - command line, eg "c:\program files\x\x.exe ''%1''". Will be registered as "Open" verb. If you don't use it here, then later you should use FileExtAddVerb.
;content_type - content type, eg "text/xml". Optional.
;EXAMPLE
;FileExtRegister "vig" "vigfile" "Vig File" "shell32.dll,20" "notepad.exe ''%1''"
;
;str s="test"
;s.setfile("$desktop$\test.vig")
;run "$desktop$\test.vig"
int h=HKEY_CLASSES_ROOT
str s
if(ext[0]='.') ext+1
if(!rset(cls "" s.from("." ext) h)) end ES_FAILED
if(!empty(content_type)) rset content_type "Content Type" s h
if(!rset(description "" cls h)) end ES_FAILED
if(!empty(icon)) rset icon "" s.from(cls "\DefaultIcon") h iif(icon[0]='%' REG_EXPAND_SZ REG_SZ)
if(!empty(cmd)) FileExtAddVerb ext "Open" cmd 1; err end _error
SHChangeNotify SHCNE_ASSOCCHANGED 0 0 0Function FileExtUnregister
;/
function $ext
;Removes a file extension. Also removes all its verbs.
;QM must be running as administrator.
;Error if fails.
;ext - extension, eg "vig".
int h=HKEY_CLASSES_ROOT
str s cls
if(ext[0]='.') ext+1
if(!rget(cls "" s.from("." ext) h)) end ES_FAILED
rset "" s h 0 -2
rset "" cls h 0 -2
SHChangeNotify SHCNE_ASSOCCHANGED 0 0 0Function FileExtAddVerb
;/
function $ext $verb $cmd [flags] ;;flags: 1 make default
;Adds a verb (context menu command) to a file extension.
;QM must be running as administrator.
;Error if fails.
;ext - extension, eg "vig".
;verb - verb name, eg "Play".
;cmd - command line, eg "c:\program files\x\x.exe /p ''%1''".
int h=HKEY_CLASSES_ROOT
str s cls
if(ext[0]='.') ext+1
if(!rget(cls "" s.from("." ext) h)) end ES_FAILED
if(flags&1) rset verb "" s.from(cls "\Shell") h
s.from(cls "\Shell\" verb "\Command")
if(!rset(cmd "" s h iif(cmd[0]='%' REG_EXPAND_SZ REG_SZ))) end ES_FAILEDFunction FileExtRemoveVerb
;/
function $ext $verb
;Removes a verb (context menu command) from a file extension.
;QM must be running as administrator.
;Error if fails or the extension does not exist. Not error if the werb does not exist.
;If you remove default verb, later use FileExtSetDefaultVerb to set another default verb.
;ext - extension, eg "vig".
;verb - verb name, eg "Play".
int h=HKEY_CLASSES_ROOT
str s cls
if(ext[0]='.') ext+1
if(!rget(cls "" s.from("." ext) h)) end ES_FAILED
rset "" verb s.from(cls "\Shell") h -2Function FileExtSetDefaultVerb
;/
function $ext $verb
;Sets default verb of a file extension.
;QM must be running as administrator.
;Error if fails.
;ext - extension, eg "vig".
;verb - verb name, eg "Play".
int h=HKEY_CLASSES_ROOT
str s cls
if(ext[0]='.') ext+1
if(!rget(cls "" s.from("." ext) h)) end ES_FAILED
if(!rset(verb "" s.from(cls "\Shell") h)) end ES_FAILED