Can a shell namespace extension displaying a form receive/pass files to IFileDialogs? - windows

I'd like to show a shell namespace extension in the new (since Windows Vista) IFileOpenDialog and IFileSaveDialog.
These dialogs can apparently display a custom form like the built-in Homegroup screen:
On this form I'd like to show internal files stored in a database (with various other options).
My question is: is it possible to pass the files that the users selects on my custom form to the IFileOpenDialog?
And is it possible to let the user select a location in the database, then receive the files from the IFileSaveDialog and store them in the database?
Important! I understand that this would be possible if I implemented virtual folders and files with my shell namespace extension. But is it possible to have my own Form embedded into the shell and in the same time pass and receive files to/from the dialogs?
If it is possible, what methods do I need to implement in my shell extension to catch the dialog open/save events?

Related

Register a thumbnail handler for a folder, rather than a specific file type

I need to write a thumbnail handler for all the files under a given folder. This folder is a mounting point for a virtual file system (using Callback File System), and the files are actually not present physically on the local machine (they're stored in the cloud), so if I let the default thumbnail handler do its work, it will try to download the whole files from the server... which is obviously not what I want.
But now I just realized that a thumbnail handler must be registered per file type:
Registration of a thumbnail handler is based on standard file associations.
(from the documentation)
I don't want to register it per file type, because I don't want to change the behavior for files that are not in my virtual folder. Is there a way for my handler to be called for all the files in my virtual folder, and only them?
I see two ways for you to go.
The simple way: Register your own thumbnail handler and let it work on all files. When you don't support IInitializeWithStream but only IInitializeWithItem or IInitializeWithFile you can check if the item/file is in your virtual file system. If so you can return a thumbnail and otherwise return an error.
The problem with this approach is that only one thumbnail provider can be registered per file type.
The hard way: You can write a shell namespace extension. These can be used to display virtual folders, which can be customized in many ways. This is another way to do what you already did using cbfs, but it is restricted to Explorer only. It would add another way to display your virtual folders.
The shell namespace extension will only work for it's own virtual folder. If you mapped your virtual folders to a drive letter and the user opens that drive in Explorer (and not the shell namespace extension's virtual folder), the user would see regular Explorer view of the files, not your shell namespace extension.
Also: Documentation for shell namespace extensions is a pain, there is not much available. I wrote my own shell namespace extension and every time my objects where queried for an IID I traced that and learned a bit more. I saw that my extension is queried for IID_IThumbnailHandlerFactory, I also saw IIDs like IID_IExtractIconA or IID_IContextMenu, but I did not see IID_IThumbnailProvider, nor did I see IID_IExtractImage. This suggests that you cannot have your own IThumbnailProvider directly attached to the objects you create for the virtual folder, but it could also be that I just missed to set some flag somewhere else so that Explorer does not even try to query me.

Windows API hook, custom save as file dialog to save directly to webserver via POST

I want to write a custom save as dialog that is hooked into the File -> "Save As" of most Windows program. This custom dialog will allow the user to enter their username, password, destination folder and uploads the file to the web server via a POST. If the user clicks cancel, it will call the original file dialog.
I've been reading up about Windows API hooking and this is vaguely how I think I would approach this:
Intercept "Save As"
Display my custom dialog, return some temporary path on the drive
Let the program write file to the temporary path, assume it calls WINAPI CreateFile(...) for now
Read the temporary file and upload to web server
Clean up temporary file
But I still can't get my head around the steps required to pull this off. Assuming I can intercept the "Save As" and CreateFile function, how do I detect the CreateFile was called from a "Save As" and not just any random file creation? I can think of a hack where I keep track of the time difference of when the File dialog got open and CreateFile got called.
My alternative solution is to use the existing file dialog and create a special folder on the disk, that is constantly monitored. When a file gets written there it will call an external program that uploads the file. I haven't looked into how to do this yet. I suspect this is easier.
UPDATE
As a first baby step, I wrote a .NET task tray application that allows the user to enter their login details and a folder to monitor. Whenever a file gets dropped in there there it will upload to the web server. So far it seems to work. Now I just need to figure out how to add a nice shortcut to the left pane of the file dialog. Once that's done I think I got a solution I'm happy with.
There is no need to hook or patch anything. Create a shell namespace extension that supports IStorage::CreateStream and implements it by returning a stream that POSTs its data to the Web server. The user can then choose to save the file to your namespace extension in order to upload the file.
Hooking the standard save dialog requires you to inject a DLL into every running process and have it replace the import stub of the the Win32 API GetSaveFileName() function in the process's PE header (something anti-virus and anti-malware apps are not likely to be happy about).
Then there is the new-style save dialog that was introduced in Vista using the new IFileSaveDialog COM interface instead of GetSaveFileName(). For that, you would have to uninstall and replace Microsoft's default FileDialog COM object with a custom implementation.
That does not count custom-made save dialogs, which you are not likely to hook.
If, by some miracle, you can hook the dialog and have it return a custom path of your own creation, you don't need to hook CreateFile() itself, Just monitor the folder that you create for your purposes. Place it where it is unlikely that any other app (or user) besides you will write files to. You can create a custom subfolder in the user's or system'ss AppData folder for that purpose. You can use SHGetSpecialFolderPath() and/or SHGetKnownFolderPath() to find those folders.
The tricky part will be detecting when the file is finished being written to and has been closed. You will have to monitor the folder for changes, such as with ReadDirectoryChangesW() or SHChangeNotifyRegister(), and periodically open new/modified files for exclusive access. If a file is still open by someone else, you won't be able to open it yourself. But once you do open it, you can do whatever you want with it.

Shell namespace extension adding barricade

I implemented namespace extension using default shell view in Windows XP.
Everything works fine, but I want add barricade (A Description of Protected Folders - also applicable to Windows XP).
Is possible this using documented/undocumented functions (SFVM messages), or this feature is hard-coded ?
If you fill all data for your extension view yourself, then you can read contents of hidden (or any other) folders on your own and display them straightaway, or hide if it needs to.
Your extension uses its own namespace, which is not controlled by the built-in shell protection options.
P.S. Starting from Windows 7+ it should not be a problem.

Coerce Windows to show a thumbnail for my custom file type

I want to use the windows OpenFileDialog class in C# to browse files for my application. I would then like the files to show up with previews in Windows' "thumbnails" view.
Is there a simple way to make this happen? I'm thinking there should be a way to encode the files so that Windows simply reads and displays the thumbnail information, even though it's an unsupported file type?
I know Windows Vista has a different interface (IThumbnailProvider as opposed to IExtractImage) than Windows XP, but I need it to work across platforms.
Thanks!
/ Jakob
You have to write a Shell Extension Handler Thumbnail Image Extractor. This is unmanaged c++ code that extracts the image from your custom filetype to display within explorer shell. You can find more about Shell Extension Handlers at the following link:
Creating Shell Extension Handlers

Replacing the explorer pane in windows?

When a user puts in a CD and autoruns, I want to "browse" the CD but I want to do some extra processing of the disk contents. If I wanted to replace the ListView in windows explorer with one of my own, how would I start? What terms should I search for to find out how to do this. I want to get the treeview part that explorer provides, and all the shell interaction, I just want to hide the extra extension on the end of the file names (.pgp) and show the icons for the files as if they weren't encrypted.
I think your best option is use a Shell Namespace extension like the GMail Drive shell
see this links
An almost complete Namespace Extension Sample
Create Namespace Extensions for Windows Explorer with the .NET Framework
Tips in Writing Namespace Extensions (I) - Implements Subfolder
Tips in Writing Namespace Extensions (II) - Implement Create and Delete Object Operations
Bye.

Resources