Hi,
i'm making my own game engine on sdl + opengl i also know that i can manage file for my setting and save game that way (i am on windows)
#include <windows.h>
void ini::setfile(std::string name)
{
name += ".ini";
std::string directory;
char path[1024];
GetModuleFileName(NULL, path, 1024);
directory = path;
size_t found;
found = directory.find_last_of("\\");
directory = directory.substr(0,found+1);
file = directory + name;
}
void ini::write(char *section, char *key, char *value)
{
char filebuf[file.length()];
strcpy(filebuf,file.c_str());
WritePrivateProfileStringA(section, key, value, filebuf);
}
But i can use my game on Linux except that i cant compile cause windows.h is only for windows and i try to use fstream to do the same as WritePrivateProfileStringA(section, key, value, file);
but don't know how to store multiple value in an ordered manner so user can easy edit them (for custom level or other) and i also already ported my encrypted version (so user can't cheat and edit their online save) but i'm not sure if there is a better way or other cause i never use fstream before event if it seam to work on windows i don't know for use on Linux
bool encodetofile(const std::string SIn, const std::string passwd, const string fileName)
{
istringstream In;
string encFileName = fileName + ".enc";
ofstream encFile(encFileName.c_str());
if (!encFile.is_open())return false;
string result;
string passwdCopy(passwd);
int index = 0;
In.str(SIn);
//encrypted using a polyalphabetic cipher.
char c = In.get(); //get first char
while(!In.eof()) // as long as we have something to read
{
encFile.put(c + passwdCopy[index]++);
index++;
index %= passwdCopy.length();
c = In.get(); // get an other char to start again
}
encFile.close();
return true;
}
also if you want to try my code don't use cin >> SIn;
cause space are not ok with it use cin.getline(SIn, 1024); and all will work space and all...
Sorry for my english... lol i'm french. Also never study C++ in my life so if i am doing something wrong please tell me.....