rendered paste bodyvoid load_hiscore()
{
ostringstream filepath;
#ifndef ALLEGRO_LINUX
filepath << "./data/hiscore.dat";
#endif
#ifdef ALLEGRO_LINUX
filepath << getenv("HOME") << "/.openinvaders/hiscore";
#endif
char hiscore_buffer[sizeof(hiscore)];
ifstream hiscorefile;
hiscorefile.open(filepath.str().c_str(),ios::binary);
if(!hiscorefile.read(hiscore_buffer,sizeof(hiscore)))
{
cout << "Error reading highscore file\n";
}
hiscorefile.close();
char *stuff_to_read = new char[sizeof(hiscore)];
int *hiscore2 = new int;
stuff_to_read=hiscore_buffer;
memcpy(hiscore2,stuff_to_read,sizeof(hiscore));
hiscore=*hiscore2;
delete[] stuff_to_read;
delete hiscore2;
}
void save_hiscore()
{
ostringstream filepath;
#ifndef ALLEGRO_LINUX
filepath << "./data/hiscore.dat";
#endif
#ifdef ALLEGRO_LINUX
filepath << getenv("HOME") << "/.openinvaders";
mkdir(filepath.str().c_str(),S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH);
filepath << "/hiscore";
#endif
ofstream hiscorefile;
hiscorefile.open(filepath.str().c_str(),ios::binary);
char *stuff_to_write=new char[sizeof(hiscore)];
int *hiscore2=new int;
*hiscore2=hiscore;
memcpy(stuff_to_write,hiscore2,sizeof(hiscore));
hiscorefile.write(stuff_to_write,sizeof(hiscore));
hiscorefile.close();
delete[] stuff_to_write;
delete hiscore2;
}