Preet Sangha
Preet Sangha

Reputation: 65546

How could Visual Studio 2012 be set to use a custom tool to customise the Reading/writing of existing editors?


Update: It appears that VS doesn't have the hooks needed to do what is needed in my use case. However there are a couple of options that could work for other people and as such I'm marking the question as answered but I would love to find a solution that works for me.


We have encrypted files that are routinely kept in encrypted form within source control (TFS). When I want to compare versions I use Beyond Compare and have added the encryption/decryption tool as filtering on the read/write process to allow plain text viewing and editing.

However if I just want to open the file for reading/editing it's a bit tedious using a dummy comparison just to view/edit the file.

As such as I wondering if there is a configuration setting or way in Visual Studio that would allow me to insert a filter on the read/write so that it could display/edit/save files that would otherwise be unreadable.

Edit: *NB: The encryption aspect is just single use case *, I'm actually looking for a generic answer that doesn't require writing an editor to replace the editors within VS that already exist such as the MS supplied XML editor or the custom third party ones.

I have both custom and non custom files that are encrypted. Each file type already has an editor. We have no access to the source for any of these editors. The problem is that the file is encrypted in TFS, and all I need is the filtering on the read and write for all files regardless of editor.

I want to use all the existing features of the installed editors without change. Only the reading and writing need to be customised.

Upvotes: 12

Views: 780

Answers (4)

Mike Beeler
Mike Beeler

Reputation: 4101

There are extensions that will capture events to the current window save for example and what turns out to be document load. ** This is not a custom editor **

check out the following two links:

http://msdn.microsoft.com/en-us/library/dd885244.aspx

and a fairly complete open source addin that works with files when saved (regardless of type)

https://bitbucket.org/s_cadwallader/codemaid/src/7cf1bf6108801f48b85e30d85e1646fbc73ba889/CodeMaid/Integration/Events/RunningDocumentTableEventListener.cs?at=default

which hooks the RDT table to extend the current environment. You would need to adjust from here of course but this should get you going in the right direction.

Upvotes: 1

chue x
chue x

Reputation: 18823

This may not do what you need, since you need to call third party exe. However this answer may be useful for others that have access to source code (or a dll or library).

You could write a file system filter that encrypts/ decrypts the data to and from disk. Note that the driver sits at the OS level, and is outside of Visual Studio.

From the MSDN article File Systems and File System Filter Drivers:

A file system filter driver intercepts requests targeted at a file system or another file system filter driver. By intercepting the request before it reaches its intended target, the filter driver can extend or replace functionality provided by the original target of the request. Examples of File Systems and File System Filter Drivers include anti-virus filters, backup agents, and encryption products.

See this Code Project article for a tutorial: File System Filter Driver Tutorial. The article does not show how to do encryption/ decryption, but shows how to get a simple driver up and running.

Upvotes: 1

Rots
Rots

Reputation: 5586

Here's a potentially hacky way to achieve what you are trying to do, if there is no other easy option.

TFS stores data in a SQL database. Therefore you can theoretically modify the read/edit command that is used to extract the data from TFS and send it to the editor/viewer. This might involve modifying a stored procedure, or putting a trigger in place to modify the data before it is presented to the editor.

You would need to run a Profiler Trace on the TFS database when you click on edit/view or browse to the node in the source control tree. This will help you to figure out what data TFS is accessing and what functions/stored procs/tables etc it used to extract said data.

The same in reverse; you'd need to modify the 'writing' of the data to use your custom tool before putting it in the DB.

SQL has the ability to call CLR code, so you could use your tool if it's written in .NET.

Upvotes: 3

Litch
Litch

Reputation: 696

The easiest way would be to download the 2012 SDK, Microsoft already provide a nice walkthrough on how to implement your custom editor HERE.

The process is:

  • Install the SDK
  • Fire up VS2012; Select New Project -> Other Proj Types -> Visual Studio Package
  • Visual C#, company name, etc...
  • Tick the "Custom Editor" tickbox
  • Fill in the rest of the details

So now you're presented with all the source of a vanilla text editor, and the part you want to hook in to is the IPersistFileFormat::Load() and IPersistFileFormat::Save() functions found under EditorPane.cs and put your encryption/decryption routines in there, thus you'll be left with a text editor with a custom encrypted file format.

Upvotes: 1

Related Questions