Specific Folder save & read - c++

I'm developing a game for mi Advance Algorithm class, but I'm having a problem with the read and save. I want to save the "fields" on a .txt file but on a specific folder in my solution. I want to create 1 file per field, and I want to read all the .txt files on that specific folder when I load the solution. The user must not send any address for saving or reading, that must be done by default by the program. I'm actually using this :
FILE* arch =fopen("Tableros.tbl","wt");
if(arch==NULL)return;
Same thing for reading. But I can only read one file, and I want to detect or read all .txt on that specific folder. Any ideas or functions that can help?
I'm using visual studio 2010 c++.

Use GetCurrentDirectory() function to retrieve current process directory. Then use search in the directory (FindFirstFile(), FindNextFile() and other) to detect and read all files in cycle.

Related

how can I get the original file type after user modification using PE header in legacy driver

I have developed a legacy driver to allow and block the transfer of specific files from hard disk to external devices. This works fine.
The issue I face is that, here the user is able to modify the file name and file file type.
How can I find the original file type and file name modified by user ?
Is it possible to find the original file type using portable executable header ?
(Files type for example .pdf,.txt)
During my research I found that they are able to find original file type.How do they find the original file type. Similar has been done by " http://checkfiletype.com/"
Thanks in advance. Can you provide any solution for this.
This game had a name.
The name of the game is "last one who moves wins"
I will gladly exfiltrate files by base85 encoding them and dropping that as content in an allowed type.
Your users will no doubt come up with other clever ways.
Now if you were doing this for virus control I'd say just examine file contents and if it looks like an executable say no. The first two characters of an executable file are always MZ.

get modified files after given timestamp in windows file system in Cpp code

Is there any way that I can get modified files/folders after a given timestamp in windows file system? I don't want to traverse entire file system and check which file/folder is modified in my code. Does windows provide any API which returns modified files/folders after a given time stamp ?
No, there is no direct WinAPI to accomplish this.
I'd suggest traversing only through certain folders (exclude folders like Windows, ProgramData) etc. Traverse only through the folders that make sense. ex: Users.
Why? Because the system files in Windows and such folders are accessed very frequently and are modified after system updates. Unless you're keen to see when the system files were modified, I'd say the data is going to be irrelevant and of no meaning.

how to give a version to mdb files

I am using a .mdb file as a database for a dialog based application. For the each Release I want to give a version to the mdb file if there are more entries added. using C++ i want to read the version and display it in the application.
Can you please tell me if it is possible to give a version to mdb file ?
You can add a table to MDB and track releases there. If MDB should change release number automatically after some data changes, you can use Data Macro (this is for Access 2010+)
You can create a custom property:
db.CreateProperty("VersionId", dbText, "1.0.0")
then add this to the database, but there is no way to read this without opening the database file.
There is no easy way to do that and its probably best to do it as a db.property like #Gustav proposed.
If for some reason it is important to have a version information that you can read without opening the file as access file there are still some options:
There is the Windows Shell Property System that I think allows you to add Properties to every File/Folder.
You could change the Creation Date for the file to fit your need.
You could perhaps even read/change the file content itself in a binary stream if you research it thouroughly enough.
and you can of course have an external .txt (or .ver or whatever) file that you update automatically from the db.property whenever you open the db.

Deploying text files in c++

I have encountered a problem when deploying a game I made in C++. I will try and be as specific as possible.I did research this thoroughly on Google and I also asked a former programming teacher and he recommended I post to this site. I created a game in C++ and inside the source folder I had added 3 text files named: "SavedGame1.txt" "SavedGame2.txt" and "SavedGame3.txt". I built a save function that when triggered, it writes the information such as player name, class, hitpoints, mana, etc to the text file so it can be read back later in my continue function. When I run it in Visual Studio (I am using Visual Studio 2010 by the way), it will write to the text file like desired and read back from the text file. After I deploy the game, it will read from the text files if they have data in them before I deploy the game, but the problem is after deployment, it will not write to the text files. This makes my save game function worthless. I found a way around this by creating a directory upon running my deployed game and then creating the save game text files in the directory, but then I face the issue of having to run the game in Admin mode or else it will not write to the text files. Can anyone tell me what I can do to get it to write to the text files so that the user does not have to be in Admin mode to use the save function.
You can do the following:-
1) When you deploy your text files, create a folder under the ApplicationData folder for that specific user.
2) Deploy your text files to this folder
3) Read and write to the files in the above folder when required
The ApplicationData folder stores the application specific data of the user and is always accessible (even for non admin users)
In C++ you get the ApplicationData folder like this (pointing you to another answer on SO: ApplicationData

Opening an existing .doc file using ofstream in C++

Assuming I have a file with .doc extension in Windows platform, how can I open the the file for outputting its contents on the screen using the ofstream object in C++? I am aware that the object can be used to open files in text and binary modes. But I would like to know if a .doc (or even .pdf) file can be opened and its contents read.
I've never actually done this before, but after reading up on it, I think I might have a suggestion. The .docx format is actually just XML that is zipped up. After unzipping, the file is located at word/document.xml. Doing this in a program is where it gets fun.
Two options: If you're using C++ CLR (.NET) then Microsoft has an SDK for you. It should make it pretty easy to open Office documents.
Otherwise if you're just using regular C++, you might have to do some extra work.
Open the file and unzip it using a library like zlib
Find the document.xml file inside
Parse the XML document. You'll probably want to use some kind of XML parsing library for this. You'll have to look up the specs for the XML to figure out how to get the text you want.
C++ std library has ifstream class that can be used to read simple text files, and for read binary files too.
It is up to you to interpret these bytes in the file. To proper interpret the binary file you need to know the format of the file.
If you think of MS Word files then I would start from here: http://en.wikipedia.org/wiki/Office_Open_XML to understand MS Word 2007 format.
You might find the Boost Iostreams library ( http://www.boost.org/doc/libs/1_52_0/libs/iostreams/doc/home.html ) somehow useful if you want to make some filter by yourself.