Re: Cross-platform open document
by CountZero (Bishop) on Feb 28, 2010 at 09:18 UTC
|
Windows cheats: it links the file-extension (everything after the last dot in the file name) to a program that is supposed to be able to do something with this "type" of file.Have you ever tried to add .xls to an HTML-file and then double-click on it? (go ahead try it -- I will wait) Funny, isn't? It proves that the knowledge how to open a file is not only in the registry but also in the programs themselves, hence there is no single place to collate this information. The well-known notepad.exe program knows how to open (for a very limited definition of "open") almost every type of file, but it can only do something useful with text-type files. Some files can be more reliably recognized from their headers: our #!/usr/bin/perl springs to mind, or the magic bytes in some files.
CountZero A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
| [reply] [d/l] [select] |
Re: Cross-platform open document
by afoken (Chancellor) on Feb 28, 2010 at 06:19 UTC
|
No, and there can't be one, because not all OS store such information.
If you think of Linux: There is no central repository for such information. It depends on the desktop environment you use. And of all possible desktop environments, only a few have some kind of repository. Of course, not all desktop environments store the required information in the same place and in the same structure.
Alexander
--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
| [reply] |
|
|
adamk++ for making the impossible possible with File::HomeDir. I should've read the question more thouroughly - my answer was about the directories to store My Images, My Music etc., not programs to open such files.
| [reply] |
|
|
But how do those OS achieve the magic of double-clicking?
| [reply] |
|
|
each in their own way that they choose, obviously :)
| [reply] |
Re: Cross-platform open document
by stefbv (Priest) on Feb 28, 2010 at 10:10 UTC
|
Linux uses MIME types, see Internet media type
On my system (Slackware 13.0) there is a MIME database in /usr/share/mime
Update:
"GNU/Linux" systems with GNOME or KDE, use MIME types to determine the type of the file and from the system and user preferences choose the application used to open that file, if a mapping if defined for that particular type of file.
| [reply] |
|
|
To be precise: No, Linux does not use MIME types.
Linux is "just" an operating system kernel. The userland tools around it do not use the MIME types, either. The Free Desktop Project uses MIME types, so desktop environments like Gnome and KDE that use that standard can use the shared MIME database. But as I already said, not every desktop environment uses that standard or the database.
Oh, and there is no information in /usr/share/mime about which application is able to open a resource (file) with any given MIME type. Just look at /usr/share/mime/text/html.xml. If /usr/share/mime was the right place to look at, I should be able to find the name of my prefered browser in that file. But there is no application listed at all, and that is not the purpose of this database.
Alexander
--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
| [reply] |
|
|
True, not "Linux" but "GNU/Linux" as a generic name for the entire system, more specifically those systems with GNOME or KDE.
Of course CLI tools doesn't need and can't use MIME, that is only for graphical desktop interface apps.
The database is for "looking up the correct MIME type..."
The user preferences (such as a user's preferred application for
handling files of a particular type) are stored in the home dir of the
user.
"There is no information in /usr/share/mime about which application is able to open a resource (file) with any given MIME type."
Not entirely true, from the link you provided:
"It may be used to store static information, such as that files of a certain type may be viewed with a particular application."
Regards, Stefan
| [reply] |
|
|