Recent

Author Topic: Programming a driver for a virtual folder and virtual files?  (Read 1406 times)

Aidex

  • New Member
  • *
  • Posts: 28
Programming a driver for a virtual folder and virtual files?
« on: October 21, 2019, 03:07:25 pm »
Providing virtual folders?
Is it possible to program a driver or provider interface for a virtual folder or virtual drive?
I want to create a virtual Windows folder with virtual files that do not exist on the hard disk.
My program should provide the information about the virtual files (name/size/date) and the file contents when they are requested.
I would be grateful for any tips. Thank you!

To explain my task: Thousands of small files are stored in a database, which no longer exist on the hard disk.
In order to make the stored files usable for the user, not every time all files should be extracted into a real folder first.
Instead, the content of a file should only be retrieved from the database when the file is actually opened by the user.
My problem now is that I don't know any programming approach to offer a virtual folder or virtual disk.
« Last Edit: October 21, 2019, 04:07:11 pm by Aidex »

Thaddy

  • Hero Member
  • *****
  • Posts: 9190
Re: Programming a driver for a virtual folder and virtual files?
« Reply #1 on: October 21, 2019, 03:48:08 pm »
You can do that with Sqlite-vfs but I don't know if the VFS part is already available for FreePascal.

You can also do it with this (fpc compatible) https://torry.net/files/vcl/compress/other/SingleFileDataStorage1.4.1.zip
also related to equus asinus.

Aidex

  • New Member
  • *
  • Posts: 28
Re: Programming a driver for a virtual folder and virtual files?
« Reply #2 on: October 21, 2019, 04:01:20 pm »
Thanks for your answer, but I'm not looking for a data storage or a database.
The database already exists.

Thaddy

  • Hero Member
  • *****
  • Posts: 9190
Re: Programming a driver for a virtual folder and virtual files?
« Reply #3 on: October 21, 2019, 04:06:04 pm »
Yes, but the sourcecode in the link can be used with databases.
But you must probably implement the streaming interfaces for your database.
At least it is a very good and complete example.
« Last Edit: October 21, 2019, 04:08:29 pm by Thaddy »
also related to equus asinus.

PascalDragon

  • Hero Member
  • *****
  • Posts: 674
  • Compiler Developer
Re: Programming a driver for a virtual folder and virtual files?
« Reply #4 on: October 22, 2019, 09:21:58 am »
Providing virtual folders?
Is it possible to program a driver or provider interface for a virtual folder or virtual drive?
I want to create a virtual Windows folder with virtual files that do not exist on the hard disk.
My program should provide the information about the virtual files (name/size/date) and the file contents when they are requested.
I would be grateful for any tips. Thank you!

To explain my task: Thousands of small files are stored in a database, which no longer exist on the hard disk.
In order to make the stored files usable for the user, not every time all files should be extracted into a real folder first.
Instead, the content of a file should only be retrieved from the database when the file is actually opened by the user.
My problem now is that I don't know any programming approach to offer a virtual folder or virtual disk.
What you're looking for are Shell Extensions or more precisely Shell Namespace Extensions. There are some C++ based tutorials available on Code Project (here and here; the example might look old, but not that much has changed since then, it was only extended) that you'll need to reimplement in Object Pascal (though Object Pascal simplifies working with COM classes and implementing them compared to C++ ;) ).

Thaddy

  • Hero Member
  • *****
  • Posts: 9190
Re: Programming a driver for a virtual folder and virtual files?
« Reply #5 on: October 22, 2019, 09:28:43 am »
What you're looking for are Shell Extensions or more precisely Shell Namespace Extensions.
Ah, I remember there was an article in The Delphi Magazine which included sourcecode for exactly that! Shell Namespace Extensions.
Maybe someone that still has the issues (or the USB stick with everything, mine is pushing up daisies) can look it up for us. ( Howardpc?, Detlev? )
Must be one of the higher numbered issues.

Note that if that database is a single table it is possible to write a plain file driver for it without the shell using a record describing all fields and file of Record But a bit of a hack since it is undocumented in FPC, not in Delphi, where it is somewhat documented.
« Last Edit: October 22, 2019, 09:39:04 am by Thaddy »
also related to equus asinus.

Aidex

  • New Member
  • *
  • Posts: 28
Re: Programming a driver for a virtual folder and virtual files?
« Reply #6 on: October 23, 2019, 06:49:16 am »
"Shell Namespace Extensions" is already a very good cue! Thank you! I can google on with that.

Thaddy

  • Hero Member
  • *****
  • Posts: 9190
Re: Programming a driver for a virtual folder and virtual files?
« Reply #7 on: October 23, 2019, 07:09:10 am »
"Shell Namespace Extensions" is already a very good cue! Thank you! I can google on with that.
It is used for example to make zip archives completely transparent to the explorer....
Another - third party - example is TortoiseSvn for which the sourcecode (C++) is available, I think.
But there is Delphi source code available that should work with FPC. I know for sure it was in The Delphi Magazine.
I also seem to remember it is COM interface based, which would make it even easier for intermediate to advanced programmers.
« Last Edit: October 23, 2019, 07:13:47 am by Thaddy »
also related to equus asinus.

PascalDragon

  • Hero Member
  • *****
  • Posts: 674
  • Compiler Developer
Re: Programming a driver for a virtual folder and virtual files?
« Reply #8 on: October 23, 2019, 09:08:29 am »
TortoiseSVN does not provide virtual folders, only icon overlays (which are simpler and better documented).

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7508
Re: Programming a driver for a virtual folder and virtual files?
« Reply #9 on: October 23, 2019, 09:08:08 pm »
Some of the interfaces named in the codeproject article are available in unit shlobj

WayneSherman

  • Jr. Member
  • **
  • Posts: 58
Re: Programming a driver for a virtual folder and virtual files?
« Reply #10 on: October 24, 2019, 02:45:45 am »
Providing virtual folders?
Is it possible to program a driver or provider interface for a virtual folder or virtual drive?
I want to create a virtual Windows folder with virtual files that do not exist on the hard disk.

Dokan is similar to FUSE (Linux file system in user space) but works on Windows
https://dokan-dev.github.io
https://github.com/dokan-dev/dokany

It has a Delphi/FreePascal binding:
https://github.com/dokan-dev/dokan-delphi

Thaddy

  • Hero Member
  • *****
  • Posts: 9190
Re: Programming a driver for a virtual folder and virtual files?
« Reply #11 on: October 24, 2019, 09:54:40 am »
I did know about fuse, but not about Dokan, so I played a little:
Do not use it. The COM based interfaces provided by the Windows OS are way more comfortable and less prone to errors.
But it does do what it says. IOW it works, but it is not a help because its use is extremely more complex than the already provided interfaces.
Oxymoron comes to mind, although the term does not cover such things exactly.
« Last Edit: October 24, 2019, 09:59:43 am by Thaddy »
also related to equus asinus.