Hi
EDIT: using SFML 1.6
Im strugling a little problem when using HTTP class to download files.
Currently planing to do auto updater to my little project.
I have virtual test server where I run apache www server which hosts files what clients need to update if there is changes in client side. This way I do not need to write update server from scratch.
Client are on W7 and server is on Ubuntu 10.04
But to the problem. When download a file it will have some extra bytes in it and wont work as it should.
For example
dat.exe 274944 on server side (just for dummy test exe)
after download file size is
dat.exe 277811 Because this file is corrupted and cannot be use as it should.
Made some tests and it seems that amount of extra bytes changes time to time.
There must be something that I dont see
code snip from method which is called for update (Shortest 'working' code) stripped loggins and other not relevant lines.
bool cUpdater::bDownloadChangedFiles(const std::string _sFilename, sf::RenderWindow &_APP) {
sf::Http Http;
Http.SetHost("192.168.1.34");
std::string sURI;
std::string sDestination;
sURI = "/" + _sFilename ; // filename which need to update
sf::Http::Request Request;
Request.SetMethod(sf::Http::Request::Get);
Request.SetURI(sURI);
sf::Http::Response Page = Http.SendRequest(Request);
int iFileSize = 0;
iFileSize = Page.GetBody().size() ;
// IS this right way to handle GetBody for 'binary' files
std::string sFileContainer = Page.GetBody();
// just for test
const char * cs = sFileContainer.c_str ();
// quick and dirty save destination
sDestination = "O:\\xth\\data\\"+_sFilename ;
// Open file to write
std::ofstream toFile(sDestination, std::ios::out, std::ios::binary);
// Using put() to write to file
for (int i = 0; i<iFileSize; i++) {
toFile.put(cs[i]);
}
// Tested also write, but same problem
// toFile.write((char*)&sFileContainer, iFileSize);
toFile.close();
return true;
}
Cheers
Amadeus