In Windows 7 theres a possibility for getting file's previous versions like in the below image:
Is there any way to retrieve file's previous version by code? because I couldn't find any API.
Thanks advanced! =]
There are several tags listed with this question. So it is unclear if a strictly c/c++ approach is desired, or if scripting etc will work. In any case...
Here are some links that will hopefully point in the right direction:
On the MSDN site, there is documentation and example code referring
to shadow
copy
API.
Here is a Link to the
concept
of shadow copy service.
Here is a description of how you can command line, or program
script to recover
files from shadow copy.
Using the API link above with the structures found
here
will provide you with a way to get information about a particular
file, volume etc.
Finally, Here is a link talking about the Volrest utility from
Windows Server 2003 Resource Kit
tools, including
information on how you can "see a list of available previous
versions of [a] folder".
So after some searching, and thanks to #ryyker and #Ben directions I was able to find out the answer:
For example for file: C:\SomeFolder\SomeFile.exe
From cmd (run as administrator):
vssadmin list shadows for=C:\
For programmatic solution you can run it with:
CreateProcessW(NULL,L"cmd.exe /c \"vssadmin list shadows for=C:\\ > C:\\someTmpFile.txt\"",...);
Read and parse the created file.
Here above you get a list of shadow copies (kind of "Previous versions" containers).
Refer to the appropriate "Shadow Copy Volume" row (the version you want) and append the remaining file path after the volume name:
\\ Previous version path = \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy3\SomeFolder\SomeFile.exe"
wchar_t* prevPath = L"\\\\?\\GLOBALROOT\\Device\\HarddiskVolumeShadowCopy3\\SomeFolder\\SomeFile.exe";
Now you can read the file with the well known WIN32API functions CreateFile and ReadFile. (Create and Read file example from MSDN: EXAMPLE)
Make sure to use the UNICODE versions of that functions as the ASCII version may lack support of "\?\" paths.
Good luck! =]
Related
I have following scenario:
The main software I wrote uses a database created by a simulator. This database is around 10 GB big at the moment, so I want to keep only one copy of that data per system.
Assuming I have following projects:
Main Software using the data, located at /SimData
DLL using the data for debugging, searching for data at /SimData
Debugging tool to parse the image database, searching for the data at /SimData
Since I do not want to have all those programs have their own copy of SimData (not only to decrease place used, but also to ensure that all Simulation data used is always up to date for all programs).
I created for the DLL and Debugging Utility a link named SimData to MainSoftware/SimData, but when opening a file with "SimData\MyFile.data" it cannot find it, only the MainSoftware with the ACTUAL SimData folder can find it.
How can I use the MainSoftware/SimData folder without setting absolute paths?
This is on Windows 7 x64
I agree with Peter about adding the DB location as a configurable parameter. A common place to store that is in the registry.
however, If you want to create links that will be recognized by your software, try hardlinks. . fsutil should do the trick as described here.
You need a way to configure the database location. You could use an INI or other configuration file, or a registry setting, or a command-line input, or an environment variable. Or You could write your program to search a directory hierarchy... for example, if the various modules are usually siblings of each other in your directory tree, you could search for SimData/MyFile.data, ../SimData/MyFile.data, ../../MainSoftware/SimData/Myfile.data, and use the first one found.
Which answer is the "right one" depends on your situation.
We have a resource.dll that we are splitting into a Language Neutral Resource.dll and a Language specific Resource.dll.mui using the MUIRCT tool within the Windows SDK.
Unfortunately the LN file doesnt have any copyright, company, or version information (when viewed from Explorer\Properties\Details tab) and when dropping this assembly into VS it clearly doesnt have a version block. Does anyone know how to correctly version a Language Neutral file post execution of the MUIRCT.exe?
Hope that makes sense, let me know if you require any more information.
Ok so finally managed to understand where I was going wrong - Thanks to Hans for pointing me in the direction of the resource configuration file.
Turns out that the resource configuration file can contain two sub elements - "localizedResources" which allows customization of which resource types go into the .mui file and also a "neutralResources" element which allows customization of which resources types to go into the Language Neutral file.
In our resource configuration file, the "neutralResources" element was empty - To fix my issue I simply had to add the correct resource typeNameID (which is #16 for the version resource) into this element! The end result is the version block is in the LN file and all the properties\Details information are visible!
I have a C++ function foo_bar inside the source code file lib.cpp.
I am using a revision control tool (CVS for Windows) and I need to compare foo_bar between two different revisions of lib.cpp, is there any suitable tool for my need?
The tool should be able to properly locate foo_bar inside the two revisions because for example in one revision foo_bar is at the top of the file while in a different revision it is at the bottom of the file.
I am using Visual Studio but it is not integrated with CVS.
Thank you.
You can do it with Araxis Merge. Open two revisions of lib.cpp and add Synchronization Link pointing to foo_bar in both revisions. On the other hand you can use any file comparison tool. Just paste two versions of foo_bar and compare them.
This is called a "diff tool". The one that comes with VS sucks, as does WinDiff.
See this question for some opinions on the best such tools:
https://stackoverflow.com/questions/12625/best-diff-tool
http://www.prestosoft.com/edp_examdiff.asp seems a good tool and I have had no problems with it.
According to answer on my question, you hesitate about if diff tools could locate changes in particular functions.
Well, in 95% free tools (like examdiff) do it very well. Also try plugins listed there:
http://social.msdn.microsoft.com/forums/en-US/vssourcecontrol/thread/96cf363c-5324-475e-b249-85117a98c443
http://tortoisesvn.net/downloads.html has a merge-tool which I think is very good.
Here is how to configure to use together with Visual Studio:
http://jeffhandley.com/archive/2010/03/08/tortoisemerge.aspx
I'm aware that you are using CVS and Tortoise is SVN but the merge-tool in tortoise is very good!
I would like to parse the menu structure for Gnome Panels (the standard Gnome Desktop application launcher) and it's KDE equivalent using c/c++ function calls. That is, I'd like a list of what the base menu categories and submenu are installed in a given machine. I would like to do with using fairly simple c/c++ function calls (with NO shelling out please).
I understand that these menus are in the standard xdg format.
I understand that this menu structure is stored in xml files such as:
/home/user/.config/menus/applications.menu
I've looked here: http://www.freedesktop.org/wiki/Specifications/menu-spec?action=show&redirect=Standards%2Fmenu-spec but all they offer is the standard and some shell files to insert item entries (I don't want shell scripts, I don't want installation, I definitely don't want to create a c-library from the XDG specification. I want to find the existing menu structure). I've looked here: http://library.gnome.org/admin/system-admin-guide/stable/menustructure-13.html.en for more notes on these structures. None of this gives me a good idea of how determine the menu structures using a c/c++ program.
The actual gnome menu structures seem to be a horrifically hairy things - they don't seem to show the menu structure but to give an XML-coded description of all the changes that the menus have gone through since installation. I assume gnome panels parses these file so there's a function buried somewhere to do this but I've yet to find where that function is after scanning library.gnome.org for a couple of days. I've scanned the Nautilus source code as well but Panels seem to exist elsewhere or are burried well.
Thanks in advance
After much painful research... it seems the most stable approach is to take the gnome menu parsing code, rip it of the tar ball and use it locally.
The version I used is here:
http://download.gnome.org/sources/gnome-menus/2.28/gnome-menus-2.28.0.1.tar.gz
This code loudly proclaims that it shouldn't treated as any kind of API so one is forced to, as I said rip it of the gnome tree and keep a local copy for one's own application (gather than dynamically linking to a library).
The KDE version of the menu-parsing code seems like it could be used more transportably but actually depends heavily on KDE's virtual file system. As far as I can tell, the code gnome works stand-alone. The test-file can serve as a template for doing your own parsing.
I am currently developing/hacking an image analyzing/transforming tool.
The filters therein will be loaded at runtime using dlopen&co.
My question is where do *nix tools usually put plugins (*.so files) when installed?
bin/program
lib/program/plugins/thisandthat.so
maybe?
Secondly how do I use it and where do I put it during development without installing it. (this is probably the tricky part)
I want to avoid shell-scripts if possible.
thanks in regard
Ronny
Usually /usr/lib/programmname should be a good spot
During development I'd create a command line paramter to specify the plugin search path and just leave the plugins in the build-dir for example.
Consider:
/usr/lib/program/*.so
A good guide for choosing is Filesystem Hierarchy Standard.
Most Linux distribuitions use this standard.
Here is a very short summary.
Place application binary in:
/usr/bin/progname, /usr/local/bin/progname or /opt/progname
Place plugins or library files in:
/usr/lib/progname, /usr/local/lib/progname or /opt/progname/lib
Place host configuration for the application in:
/etc/progname or /etc/opt/progname
Place user configuration in:
$HOME/.progname
Place application manual page in:
/usr/shar/man/man1/
There is separate hierachy for /var. As an example use /var/log/progname for logging.
In responce to caf's comment. I find it very usefull to choose target directory at compile time. Using a $PREFIX also makes it easy to separate devellopment build's from shippment.
Most use /usr/progname, /usr/lib/progname and /etc/progname
Do not forget:
$HOME/.program/
The layout seems sensible. You can, for instance, look in current directory, look up environment variable or command line switch during development. It depends on the details of your development environment and workflow.