Skip to content
Snippets Groups Projects
Commit 835b38d6 authored by bfsc19's avatar bfsc19 :flushed:
Browse files

feat: adicionada opção de mudar nome do arquivo ao receber

parent fc1da369
Branches
No related tags found
1 merge request!12Resolve "feature corrigindo bugs arquivos e arrumando interface"
......@@ -111,6 +111,7 @@ int client::send_frame_socket(frame *f) {
return 1;
}
// Inicia a transmissao com o servidor
int client::start_transmission() {
cout << "\tIniciando transmissao\n";
......@@ -230,6 +231,7 @@ vector<char> client::read_file(string fileName) {
return fileData;
}
/**
* @brief Send a file through the socket
*
......
......@@ -23,6 +23,7 @@
// include local
#include "conexao.h"
#include "frame.h"
#include "cores.h"
#define FILE_DESTINATION "./received"
......@@ -195,7 +196,7 @@ bool server::create_received_dir() {
}
// create the directory
if (mkdir(FILE_DESTINATION, 0700) == -1) {
if (mkdir(FILE_DESTINATION, 0777) == -1) {
cout << "Erro ao criar o diretorio\n";
return false;
}
......@@ -263,16 +264,22 @@ int server::receive_file_data(string fileName) {
fileDestination.push_back('/');
fileDestination.append(fileName);
cout << BOLDGREEN << "Criando arquivo " << BOLDYELLOW << fileDestination
<< BOLDGREEN << ". Digite novo nome ou enter para continuar: " << RESET;
string newDestination = "";
getline(cin, newDestination);
if(!newDestination.empty() && newDestination != "\n" ) { fileDestination = newDestination; }
cout << YELLOW << "Criando arquivo: " << fileDestination << "\n" << RESET;
// Abre o arquivo para escrita
ofstream file;
file.open(fileDestination, ios::binary);
if (!file.is_open()) {
cout << "Falha ao criar o arquivo. Abortado\n";
cout << RED << "\tFalha ao criar o arquivo. Abortado\n" << RESET;
return 0;
}
cout << "Arquivo criado com sucesso\n";
int lastSeq = 1;
frame *f;
......@@ -282,7 +289,12 @@ int server::receive_file_data(string fileName) {
// Fica tentando receber um frame
f = receive_frame_socket();
if (f == NULL) { return 0; }
if (f == NULL) {
cout << "Erro ao receber dados do arquivo";
file.close();
remove(fileDestination.c_str());
return 0;
}
cout << "Frame recebido\n";
f->imprime(HEX);
......@@ -329,11 +341,11 @@ void server::receive_midia(frame *f) {
if (fileName.size() == 0) { return; }
if ( !receive_file_data(fileName) ) {
cout << "Falha ao receber o arquivo\n";
cout << RED << "\tFalha ao receber o arquivo\n" << RESET;
return;
}
cout << "Arquivo recebido com sucesso\n";
cout << GREEN << "\tArquivo recebido com sucesso\n" << RESET;
}
// Recebe um frame do cliente
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment