Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating/Using New File Extentions.
#1
The Project:
Using XML format to store data in a text file for a program designed in QM, but the file extension is not .xml, instead would be a custom file extension.

Example:
File extension: (.VIG)
Pogram: The Vig Music
Icon: vig.ico

Windows would display the files using the vig.ico
When files open, The Vig Music program would be triggered and data would be executed.
Save and Save As would write data only with the (.VIG) extension.
Open dialogs would only display (.VIG) files

Pretty much the idea is developing something just like how the .qml files work with Quick Macros.
Combining this idea with file menus will allow create programs that look and feel professional.

Thanks,
Jimmy Vig

P.S. QM is the best!
#2
Function FileExtRegister
Code:
Copy      Help
;/
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 0

Function FileExtUnregister
Code:
Copy      Help
;/
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 0

Function FileExtAddVerb
Code:
Copy      Help
;/
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_FAILED

Function FileExtRemoveVerb
Code:
Copy      Help
;/
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 -2

Function FileExtSetDefaultVerb
Code:
Copy      Help
;/
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
#3
Holy cow!

That's about the best thing I've seen. Someday I hope to have about 1/100th the mad skill that Gintaras possesses!

This is going to be so cool to use in programs.

Thanks so much,
Jimmy Vig
#4
Could you give an example of how an executable would use the text stored in a file with a registered extension.

Thanks,
jimmy Vig
#5
Better yet...encrypt the data in the file...then use it in an executable.

I've always wondered about doing this but haven't gotten around to it.

Thanks!
#6
So this is pretty simple. Program just loads up with str.getfile() and then work with that.

The encrypting part, I'll figure out.

Thanks,
Jimmy Vig


Forum Jump:


Users browsing this thread: 1 Guest(s)