diff --git a/extrator/src/extratorTXT.cpp b/extrator/src/extratorTXT.cpp index d2ffeb3..3b1bf2c 100644 --- a/extrator/src/extratorTXT.cpp +++ b/extrator/src/extratorTXT.cpp @@ -10,6 +10,7 @@ **************************************************************************/ #include "extratorTXT.h" +#include ExtratorTXT::ExtratorTXT(){ listeners = new list(); @@ -61,15 +62,14 @@ void ExtratorTXT::setFilePath(char* path){ } void ExtratorTXT::initialize(){ - file = new lavidlib::File(filePath); - try{ - file_io = new lavidlib::FileIO(file->getPath(), FileIO::MODE_READ); - bff_reader = new BufferedReader(file_io); - }catch(Exception &ex){ + ifs_.open(this->filePath, std::ifstream::in); + + if(!(ifs_.is_open() && ifs_.good())) { finish = true; Logging::instance()->writeLog("extratorTXT.cpp : Arquivo de texto não encontrado."); throw ExtratorException("Falha ao abrir o arquivo de texto! Verifique se o mesmo existe."); } + this->Start(); } @@ -79,26 +79,19 @@ bool ExtratorTXT::isFinished(){ void ExtratorTXT::Run(){ PRINTL(util::_INFO, "Extraindo Texto...\n"); - int line_index = 0; - bool hasNext = true; - string line; - - while (hasNext) { - try{ - line = bff_reader->readLine(); - if (line.length() > 0){ - notifyListeners((unsigned char*) line.c_str()); + + int line_index = 0; + string current_line; + + while (ifs_.good()) { + getline(ifs_, current_line, '\n'); + + if (current_line.length() != 0) { + notifyListeners((unsigned char*) current_line.c_str()); line_index++; } - }catch (EOFException &ex){ - if(line_index == 0) - notifyListeners((unsigned char*)"ARQUIVO_INVALIDO"); - hasNext = false; - }catch (...){ - Logging::instance()->writeLog("extratorTXT.cpp : Erro durante a leitura do arquivo de texto."); - throw ExtratorException("Falha desconhecida na leitura do arquivo. Tente novamente."); - } } + finish = true; notifyEndExtraction(line_index); } diff --git a/extrator/src/include/extratorTXT.h b/extrator/src/include/extratorTXT.h index 4160e8a..4a79e59 100644 --- a/extrator/src/include/extratorTXT.h +++ b/extrator/src/include/extratorTXT.h @@ -14,6 +14,8 @@ #include "listenerTXT.h" #include "extratorException.h" +#include + using namespace jthread; using namespace std; @@ -73,8 +75,10 @@ public: void Run(); private: - list *listeners; - void encodingfiletoUTF8(); + void encodingfiletoUTF8(); + + list *listeners; + ifstream ifs_; }; #endif /* EXTRATORTXT_H */ diff --git a/renderer/src/renderer.cpp b/renderer/src/renderer.cpp index 3a9148d..263e515 100644 --- a/renderer/src/renderer.cpp +++ b/renderer/src/renderer.cpp @@ -1,4 +1,5 @@ #include "renderer.h" +#include Renderer::Renderer(char* path_Contents, char* id) { this->pathOutVideo = path_Contents; @@ -94,33 +95,32 @@ void Renderer::exportGlosa() { if(glosaQueue.empty()) throw lavidlib::RuntimeException("Fila de glosas vazia!"); - int glosaSize; char* glosaBff; string glosaCpy = glosaQueue.front(); //Pega quem estiver na frente da fila - glosaSize = strlen(glosaCpy.c_str())+1; - glosaBff = new char[glosaSize]; + int size = glosaCpy.length() + 1; + glosaBff = new char[size]; strcpy(glosaBff, glosaCpy.c_str()); - try { - cSocket->write(glosaBff, glosaSize); //Envia a glosa formatada p/ o player + cSocket->write(glosaBff, size); //Envia a glosa formatada p/ o player + usleep(1500); }catch(lavidlib::IOException &ex){ - throw lavidlib::RuntimeException(ex.getMessage().c_str()); + throw lavidlib::RuntimeException("Erro ao enviar glosa"); } - char* received = new char[3]; //Mensagem de confirmação de recebimento da glosa: "OK\0" + static char received[3]; //Mensagem de confirmação de recebimento da glosa: "OK\0" do { try { - cSocket->read(received, 3); //Aguarda a confirmação - }catch(lavidlib::IOException &ex){ - throw lavidlib::RuntimeException(ex.getMessage().c_str()); + cSocket->receive(received, 3); //Aguarda a confirmação + }catch(lavidlib::Exception &ex){ + throw lavidlib::RuntimeException("Não foram recebidas respostas do player"); } }while(strcmp(received, OK_FLAG) != 0); //Verifica se é a confirmação correta glosaQueue.pop(); //Se o envio foi bem sucedido, remove a glosa da fila delete [] glosaBff; - delete [] received; + // delete [] received; } void Renderer::waitScreenShots() { @@ -154,10 +154,11 @@ void Renderer::initialize() { executeServerScript(); try{ connectToUnityPlayer(); + this->Start(); }catch(lavidlib::RuntimeException &ex){ throw lavidlib::RuntimeException(ex.getMessage().c_str()); } - this->Start(); + } void Renderer::Run() { -- libgit2 0.21.2