Documentation on virtual folders - c++

I am looking for documentation for the Windows API on how to make virtual folders. I am going to make sort of my own file system and would like to have an icon under "Computer" for that file system. I have seen other programs which has this type of solution like programs which allows me to explore a Linux file system under in the Explorer program. Much like the same solution I am going to make. I am yet to find any documentation on how to do this, or am I searching for the wrong stuff? Thanks.

You are looking for a Shell Namespace Extension. An entry Point for documentation is Creating Shell Data Source Objects and Extending the Shell Namespace.
An example of a almost complete Project can be found on codeplex: An almost complete Namespace Extension Sample
Also in the Windows SDK 7, there is an example of using the Shell ExtensionNamespace (can be found in the folder "Microsoft SDKs\Windows\v7.1\Samples\winui\shell\shellextensibility\explorerdataprovider"). In this Folder you will also find a document which describes the programming model (Using the System Folder View.doc).
If you really want to create a "real" file System Driver, you might want to look at this SO article:
Creating a File System "Driver" which mainly referes to the Ext2 file system driver project.

Related

Embedding project folders(lua) into exe

I searching for a long time how to embed project files like folders (with lua scripts and images) into exe.
Basically i have some folders which are needed to run my game and i want to hide them somehow. Because now they are opened and can be easy edited by everyone.
I saw method in which folders have been changed to .dll file to protect them.
Using visual studio 2013.
I'll be very thankful for an answer.
You can use PhysicsFS, which allows to map a hierarchical filesystem to an archive. From the project page: "It is intended for use in video games, and the design was somewhat inspired by Quake 3's file subsystem." It's used by some open-source Lua frameworks (for example, Love2d), so you may check how they implemented the integration and access.
This doesn't guarantee full protection (nothing does), but it will at least make it more difficult for the users to make changes to those resources you want to protect.

Running a process inside a virtual file system?

What I'm trying to achieve is to run a program, which thinks a folder exists within its own folder while actually the folder is somewhere else on the system.
So my program would launch a process and say to the process: Folder A which is at C:\A is within your own directory at C:\Program Files (x86)\SomeProgram\A
So the "virtual" directory would only be visible to that process.
I'm using Qt to program my program, so if there are any Qt functions I could use that would be great (in relation to portability). However, plan C++ or any windows-bound API's would be fine.
I was thinking about NTFS junctions or symbolic links but I would have no idea how to create either of those in C++, let alone bind them to a specific process.
Thanks in advance!
EDIT:
In relation to the above, I've found this question: https://superuser.com/questions/234422/does-windows7-support-symbolic-links-folder-shortcuts. However, it only shows how to perform the required actions from the command-line and it wouldn't be process bound.
EDIT 2:
Some extra information: I'm trying to create a virtual directory that is made up of a couple of other directories but then merged (I'm using a priority system to decide which files "win" from other files). These merged directories would then appear to the target process as one directory containing the merged files.
I think I'm going to stick with Window's mklink command. It seems to suit my needs the best.
What I'm going to do is use QFile::link() on all operating systems that aren't Windows, and QProcess with mklink on windows. This should work on every operating system.
For a good example look here: https://stackoverflow.com/a/21013935/979732
Such tasks are accomplished by use of a filesystem filter driver. The driver intercepts OS requests going to the filesystem and lets you insert your own virtual files and directories into the existing directory on the disk. Filter driver can be an overkill for your particular task, though.
Detours approach mentioned in comments requires system-wide hooking of file APIs and will slowdown the whole system(filesystem filter driver is attached to one disk and it's a documented approach, so it's faster and more robust).

c++ find main operation system directory

I am trying to create file in main directory of operation system(for example Windows in my "c" disk) using c++.
Is there any better way than iterating all disks and search for "Windows" folder? Also its similar in mac and linux?
In Windows, you can call GetWindowsDirectory function (link). In Linux and Mac (I think), there's no such thing as main system directory.
However, as David noted, you should not put any files there:
This function is provided primarily for compatibility with legacy applications. New applications should store code in the Program Files folder and persistent data in the Application Data folder in the user's profile. For more information, see ShGetFolderPath.

Is it possible to add a version number to a file that will be visible in Properties/Details in windows explorer

I have an unmanaged C++ project where I am writing data to a custom file format that I have defined.
What I would like to know is if there is a way to add a header that is compatible with Windows Explorer so that a version number will be displayed, as in the example below showing a Windows font.
The purpose of this is so that non-tech savvy users could simply right click and identify the version of the file, without having to open it in Notepad etc.
Any help would be appreciated.
Tom
You cannot achieve this for a file in general. But if your file format stores a version information, you can teach the Windows Explorer to display it.
You have to write a Shell Extension for the Explorer, that can extract arbitrary information out of your files. This extension must be installed on the target computer and registered in the registry.
An excellent guide on how to write and register Shell Extensions can be found here on CodeProject. (Part VIII should cover what you need)
The version information comes from VERSIONINFO resource, attached to a binary file, such as .EXE or .DLL. So it is easy to link such resource into your build target, this resource is also editable.
However, this is limited to the binary executable files, and you cannot attach this resource information to arbitrary files (as you wanted), including such as text files.
In VC just go to menu Project->AddResource and pick Version.

Find out the mime type and associated applications with Qt

How can I find out a mime-type or content-type of a given file?
I cannot use the suffix because the file could be renamed.
Possible additions would be categorizing them as jpg, gif, png and so on are image files and can be opened by editing applications, which has been set in the OS.
Thank you in advance.
What platform? On *nix, you should refer to how the program file does it, which is based on a few heuristics including checks of the first few bytes of a file (many file formats start with a fixed header, including many image formats).
If you're on Windows, the *nix file command is probably still instructive, even if you can't reuse its code as directly. There may also be some better solution in the Windows APIs (I'm not a Windows programmer).
This could help, it is with C# but I think you can get the idea.
http://kseesharp.blogspot.com/2008/04/c-get-mimetype-from-file-name.html
You can use some sort of class for acccesing Windows Registry from qt or using the Windows API directly from qt.
I am not a qt programmer.
You can't, not from within Qt.
However, if all you want is to show a file with the correct application, you can use QDesktopServices::openUrl(), which wraps open (Windows/OSX) and xdg-open (Unix). The URL may also be a local file (in that case, use QUrl::fromLocalFile() to construct the URL).
For categorizing image files. For Qt and just only for image files.
QByteArray imageFormat = QImageReader::imageFormat(fileName); //Where fileName - path to your file
Further mapping imageFormat to mime-type is not complicable
It doesn't look like Qt offers that capability yet. However, you may want to look into the libmagic library which does what the file and other similar commands do. Assuming the library is maintained properly it will include new MIME types as time passes. From what I can tell it is part of the file tool suite. Under a Debian system do something like this:
sudo apt-get install libmagic-dev
to get the development library and use #include to make use of it.