Yesterday I was working on making a video game and by accident I deleted the player class with the rm command so I looked around if I could recover the files and I found this
#include <iostream>
#include <string>
#include <cstdlib>
/*
This is a simple program that uses the shell script found at
http://www.linuxforums.org/forum/newbie/69673-not-possible-recover-files-deleted-using-rm.html
For it to work we need the script in /usr/bin/ under the name of rm.sh
Then place this in /usr/bin/ under any name you want.
Hope this helps someone :)
*/
const std::string Rm = "sh /usr/bin/rm.sh";
int main(int argc , char* argv[])
{
int i = 0;
std::string Choice = "";
std::cout << "Using the rm command with following arguments : " << std::endl;
for (i = 0 ; i < argc ; i++)
{
std::cout << argv [i] << " ";
}
std::cout << std::endl;;
std::cout << "Is that okay? (Yes or No)" << std::endl;
std::cin >> Choice;
if (Choice == "Yes" || Choice == "yes")
{
for (i = 1 ; i < argc ; i++)
{
std::string Temp = argv [i];
std::string Command = Rm + " " + Temp;
system (Command.c_str ());
}
}
else
{
std::cout << "Oh!! Okay have a great day :)" << std::endl;
}
return 0;
}
I hope I can at least help someone.
~PS I eventually had to rewrite the player class again lesson learned.
The third time that you delete all your documents you start being more cautious, xP.
Still, git saved me the other day.
I think that the loops are superfluous in both codes.
There was an old thread (by chrisname)about a trash implementation. http://www.cplusplus.com/forum/lounge/15031/ (it derrails several times)
@ne555 Lol. The thread was a nice read. Also thanks for the great idea of using git I am totally making an account now. Maybe I can write a script to update my repository every 5 minutes for me XD. Also I agree 100% the loops are unnecessary I have to admit the idea was half baked.
When something like that happens, it's a good idea to draw the plug immediately and try an undelete utility (using a live CD). If that fails, you can search your disk for a specific string using dd or an already existing tool like foremost.
This is why I use version control for everything: accidentally deleting a file means at most a few dozen patch hunks of changes since my last commit is lost.
If your file is less <= 4096 bytes (i.e., occupies only one block on the hard disk) you might be able to find it with grep if your OS hasn't reallocated the block already.
@darkestfright Yeah I just made a github account I am now using it as much as I can
@chrisname I never knew that I guess I should have just greped around for the file. Anyway I did rewrite the class I have to say the new one is better than the old.
Sometimes a rewrite is a good thing, sometimes it's a bad thing. *derails* Rewriting software can set you behind the competition and reintroduce bugs that you had fixed before, but can also allow you to fix design problems in previous versions. Anyone agree?
The decision to undertake a re-write hinges on a few factors. First, is that program so critical it must be rectified heavily to make it workable? Can end users make do with the minor hiccups? Is that program an important component in the whole working IT system? Is that program related to earning monies for the companies? Is that program non-critical so as to speak? Are there work-around to achieve the same outcome?
So yes re-write is a major undertaking depending on the program complexity. It should not be overlooked leniently.
I was using polymorphism and inheritance so I did not have to rewrite a lot of the functions.
I gave up the project I lost inspiration, it was going to be a galaga clonse but I am tired of clones . So I am working on an original game. Besides the old project had a lot of mistakes.
If you would like to see I have the project on github.
A couple weeks ago my co-worker accidentally did rm -rf in the root directory of our beta server... He noticed after it deleted the boot, bin, and part of etc.