1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
bool Network::Download(std::string filename, std::string type)
{
char Exist[16] = "";
send(sock, "Send", 128, 0);
send(sock, filename.c_str(), 128, 0);
send(sock, type.c_str(), 8, 0);
recv(sock, Exist, 64, 0);
if (Exist[0] == 'E')
{
std::ofstream file;
if (type == "Song")
file.open("song.mp3", std::ios::binary | std::ios::trunc);
else if (type == "Text")
file.open("text.txt", std::ios::binary | std::ios::trunc);
else if (type == "Image")
file.open("img.png", std::ios::binary | std::ios::trunc);
else if (type == "List")
file.open("list.txt", std::ios::binary | std::ios::trunc);
else if (type == "Playlist")
file.open("playlist.txt", std::ios::binary | std::ios::trunc);
char lenght[64];
recv(sock, lenght, 64, 0); long long int l = atoi(lenght) + 1;
std::vector<char> v(l);
recv(sock, v.data(), l, 0);
file.write(v.data(), l);
file.close();
}
return true;
} |
Partager