From 86e082399eecd672ced786702b38fd12b3bfadb6 Mon Sep 17 00:00:00 2001 From: ezequiel Date: Thu, 17 Mar 2016 04:28:34 -0300 Subject: [PATCH] Finalizada versao 4.0.0 --- install/inno setup/user_install.iss | 19 ++++++++++++++++--- plugin/corePlugin.cpp | 34 +++++++++------------------------- plugin/corePlugin.h | 10 +++------- update/include/vlibrasUpdate.h | 3 ++- update/src/checkVersion.cpp | 147 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ update/src/configureEnvironmentVariables.cpp | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ update/src/vlibrasUpdate.cpp | 132 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 7 files changed, 375 insertions(+), 39 deletions(-) create mode 100644 update/src/checkVersion.cpp create mode 100644 update/src/configureEnvironmentVariables.cpp diff --git a/install/inno setup/user_install.iss b/install/inno setup/user_install.iss index 37c22bd..9d652eb 100644 --- a/install/inno setup/user_install.iss +++ b/install/inno setup/user_install.iss @@ -15,7 +15,6 @@ [Setup] AppId= {{84B73167-EF7F-42BB-9CCD-E1A8E2C53659-vlibras} - AppName={#MyAppName} AppVersion={#MyAppVersion} AppPublisher={#MyAppPublisher} @@ -46,6 +45,7 @@ Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescrip [Files] Source: "python-2.7.9.msi"; DestDir: "{tmp}"; Flags: ignoreversion deleteafterinstall; +Source: "configureEnvironmentVariables.exe"; DestDir: "{tmp}"; Flags: ignoreversion deleteafterinstall; Source: "user_install\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs; Source: "required\*"; DestDir: "{tmp}\required"; Flags: ignoreversion recursesubdirs createallsubdirs deleteafterinstall @@ -58,10 +58,20 @@ Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\Player\{#MyAppExeName}"; Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\{#MyAppName}"; Filename: "{app}\Player\{#MyAppExeName}"; Tasks: quicklaunchicon; IconFilename: "{app}\icons\icon_vlibras.ico" [Run] - +Filename: {tmp}\configureEnvironmentVariables.exe ; Flags: runhidden; StatusMsg: Definindo variáveis de ambiente... Filename: msiexec ; Flags: runhidden; Parameters: /i {tmp}\python-2.7.9.msi /passive; StatusMsg: Instalando python-2.7.9... Filename: {tmp}\required\user_install.bat; Flags: runhidden; StatusMsg: Instalando dependências... +Filename: python ; Flags: runhidden; Parameters: {tmp}\required\pip-6.0.8-py2.py3-none-any.whl/pip install {tmp}\required\pip-6.0.8-py2.py3-none-any.whl; StatusMsg: Instalando Pip... +Filename: pip ; Flags: runhidden; Parameters: install {tmp}\required\PyYAML-3.11-cp27-none-win32.whl; StatusMsg: Instalando PyYAML... +Filename: pip ; Flags: runhidden; Parameters: install {tmp}\required\numpy-1.9.2+mkl-cp27-none-win32.whl; StatusMsg: Instalando numpy... +Filename: pip ; Flags: runhidden; Parameters: install {tmp}\required\six-1.9.0-py2.py3-none-any.whl; StatusMsg: Instalando six... +Filename: pip ; Flags: runhidden; Parameters: install {tmp}\required\pyparsing-2.0.3-py2-none-any.whl; StatusMsg: Instalando pyparsing... +Filename: pip ; Flags: runhidden; Parameters: install {tmp}\required\pytz-2014.10-py2.py3-none-any.whl; StatusMsg: Instalando pytz... +Filename: pip ; Flags: runhidden; Parameters: install {tmp}\required\python_dateutil-2.4.0-py2.py3-none-any.whl; StatusMsg: Instalando python_dateutil... +Filename: pip ; Flags: runhidden; Parameters: install {tmp}\required\matplotlib-1.4.3-cp27-none-win32.whl; StatusMsg: Instalando matplotlib... +Filename: pip ; Flags: runhidden; Parameters: install {tmp}\required\nltk-3.0.2-py2.py3-none-any.whl; StatusMsg: Instalando nltk... +Filename: pip ; Flags: runhidden; Parameters: install {tmp}\required\future-0.14.3-py2-none-any.whl; StatusMsg: Instalando future... @@ -101,8 +111,11 @@ begin if CurStep = ssDone then begin + FileCopy(ExpandConstant('{app}\nltk_data\hunpos.py'), ExpandConstant('{sd}\Python27\Lib\site-packages\nltk\tag\hunpos.py'), False); + FileCopy(ExpandConstant('{app}\nltk_data\data.py'), ExpandConstant('{sd}\Python27\Lib\site-packages\nltk\data.py'), False); + FileCopy(ExpandConstant('{app}\nltk_data\nltk_tgrep.py'), ExpandConstant('{sd}\Python27\Lib\site-packages\nltk_tgrep.py'), False); DelTree('C:\vlibras-libs', True, True, True); - //chama o instalador baixado + if not ShellExec('', ExpandConstant('{app}\update\bin\DicionarioUp.exe'), '', '', SW_SHOW, ewNoWait, ErrorCode) then begin MsgBox('O VLibras foi instalado com sucesso, porém o Dicionário não foi instalado. Você poderá utilizar o VLibras Sem o Dicioário. Tente atualizar o programa para que o Dicionário seja instalado. ', mbError, MB_OK); diff --git a/plugin/corePlugin.cpp b/plugin/corePlugin.cpp index 86c5723..0dd9d67 100644 --- a/plugin/corePlugin.cpp +++ b/plugin/corePlugin.cpp @@ -1,4 +1,11 @@ +/** +* \file corePlugin.cpp +* \author Ezequiel Silva +* \ email eseveriano@gmail.com +* \date outubro 2015 / modified março 2016 +*/ + #if _MSC_VER #define EXPORT_API __declspec(dllexport) #else @@ -19,7 +26,7 @@ using namespace std; { //Objeto usado para traduzir tradutor = new PyTradutor(); - update = new PyVlibrasUpdate(); + update = new VlibrasUpdate(); //Objeto usado para copiar texto da área de transferência clipboard.bdragOn(); @@ -55,31 +62,8 @@ using namespace std; EXPORT_API int coreUpdateCheck() { - string line_in_str; - ifstream file_version; - int return_int = -1; - try - { - update->checkExe("c:\\VLibras\\update\\bin\\checkVersion.exe","check"); - - clock_t time_end; - time_end = clock() + 3000 * CLOCKS_PER_SEC/1000; - while (clock() < time_end); - - - file_version.open("c:\\VLibras\\update\\version\\version.txt"); + return update->checkExe(); - getline(file_version, line_in_str); - file_version.close(); - return_int = atoi(line_in_str.c_str()); - - return return_int; - } - catch (exception e) - { - return -1; - } - return return_int; } EXPORT_API int coreFinalize() diff --git a/plugin/corePlugin.h b/plugin/corePlugin.h index 606da87..7bec421 100644 --- a/plugin/corePlugin.h +++ b/plugin/corePlugin.h @@ -10,18 +10,14 @@ VLibras-Core */ //***************************************************************** -/** -* \file corePlugin.h -* \authors Bruno Santos, Ezequiel Silva -* \date Janeiro 2015 / Outubro 2015 -*/ + #ifndef _COREPLUGIN_H #define _COREPLUGIN_H #include "pyClip.h" #include "pyTradutor.h" -#include "pyVlibrasUpdate.h" +#include "vlibrasUpdate.h" #include #include @@ -38,7 +34,7 @@ extern "C" PyClip clipboard; //Usado para verificar se existe atualização - PyVlibrasUpdate *update; + VlibrasUpdate *update; //Inicializa Objetos EXPORT_API int coreInitize(void); diff --git a/update/include/vlibrasUpdate.h b/update/include/vlibrasUpdate.h index 3344484..b9ba752 100644 --- a/update/include/vlibrasUpdate.h +++ b/update/include/vlibrasUpdate.h @@ -7,7 +7,7 @@ VLibras-Core group at LAViD, Federal University of Paraiba //***************************************************************** /** -* \file pyVlibrasUpdate.h +* \file vlibrasUpdate.h * \authors Ezequiel Silva * \date Setembro 2015 */ @@ -24,6 +24,7 @@ class VlibrasUpdate public: int install(char* strFunct, char* strstrParams); + int checkExe(); }; diff --git a/update/src/checkVersion.cpp b/update/src/checkVersion.cpp new file mode 100644 index 0000000..6aa8228 --- /dev/null +++ b/update/src/checkVersion.cpp @@ -0,0 +1,147 @@ + +/* +* \author Ezequiel Silva +* \ email eseveriano@gmail.com +* \date março 2016 +*/ + +#include +#include +#include +#include +#include +#include +#include +using namespace std; + +HINSTANCE hDLL1; +char* pPathTempJson; +char* pPathVlibrasJson; +int codDownload = -1; + +//Assinatura do método itd_downloadfile utilizado na dll +typedef int (WINAPI*download)(char * arg1, char * arg2); +download itd_downloadfile; + +//ofstream versionFileCheck; + + + +//usado para representar as versoes tanto da api quanto local +typedef struct Versions +{ + char versionDicionario[7]={'0','0','0','0','0','0','\0'}; + char versionPlayer[4]={'0','0','0','\0'}; +} Version; + +// usado para carregar os jsons de versoes +Version loadVersion(char* pPathTempJson) +{ + Version version; + string line_in_str; + ifstream file_versionApi; + + int i; + try + { + file_versionApi.open(pPathTempJson); + while ( getline (file_versionApi, line_in_str) ) + { + if(strstr(line_in_str.c_str(), "playerVersion")){ + i = 0; + for (char & c : line_in_str) + if(isdigit(c)) + version.versionPlayer[i++]=c; + version.versionPlayer[i]='\0'; + } + else if(strstr(line_in_str.c_str(), "dictionaryVersion")){ + + i = 0; + for (char & c : line_in_str) + if(isdigit(c)) + version.versionDicionario[i++]=c; + version.versionDicionario[i]='\0'; + } + } + file_versionApi.close(); + } + catch (exception e) + { + cout<<"-1"< 0 )){ + + cout<<"-1"< atoi(versionLocal.versionPlayer)) + cout<<"1"< atoi(versionLocal.versionDicionario)) + cout<<"2"< +#include + +using namespace std; + + +int main(int argc, char *argv[]){ + + char str[4096]; + str[0]=0; + //pega o valor da variável de ambiente PATH + FILE *fp = _popen("echo %PATH%","r"); + char buf[1024]; + // concatena todos os valores + while (fgets(buf, 1024, fp)) { + strcat(str,buf); + } + //guarda todos os itens que serao novamente setado na variável PATH + string path=""; + + char * pch; + //cada item da variável + char item[1024]; + + // inicio da verificação se existe algum item da variável relacionado com VLIBRAS + pch = strtok (str,";"); + while (pch != NULL) + { + strcpy(item,pch); + if(!strstr(path.c_str(),item)) + { if(!(strstr(item,"vlibras") || strstr(item,"VLibras") || strstr(item,"Python27"))) + { + path.append(pch); + path.append(";"); + } + } + pch = strtok (NULL, ";"); + } + + /*######FIM VERIFICAÇÂO######*/ + + // variáveis de ambiente a serem setadas +system("SETX PATH_VLIBRAS %HOMEDRIVE%\\VLibras /M"); +system("SETX AELIUS_DATA %PATH_VLIBRAS%\\aelius_data /M"); +system("SETX NLTK_DATA %PATH_VLIBRAS%\\nltk_data /M"); +system("SETX HUNPOS_TAGGER %PATH_VLIBRAS%\\bin\\hunpos-tag.exe /M"); +system("SETX TRANSLATE_DATA %PATH_VLIBRAS%\\translate\\data /M"); +system("SETX PYTHONPATH %HOMEDRIVE%\\Python27;%HOMEDRIVE%\\Python27\\Scripts;%HOMEDRIVE%\\Python27\\Lib\\site-packages;%PATH_VLIBRAS%;%PATH_VLIBRAS%\\bin;%PATH_VLIBRAS%\\translate\\src;%PATH_VLIBRAS%\\Clipboard;%PATH_VLIBRAS%\\update;%PATH_VLIBRAS%\\nltk_data;%PATH_VLIBRAS%\\Aelius /M"); + +string pathFinal="SETX \"PATH\" \""; +pathFinal.append("%PYTHONPATH%;"); +pathFinal.append(path); +pathFinal.append("\" /M"); +system(pathFinal.c_str()); + +/*FIM SETA VARIÃVEIS DE AMBIENTE*/ + +fclose(fp); + + return 0; +} diff --git a/update/src/vlibrasUpdate.cpp b/update/src/vlibrasUpdate.cpp index 3f87ea8..1051b77 100644 --- a/update/src/vlibrasUpdate.cpp +++ b/update/src/vlibrasUpdate.cpp @@ -1,12 +1,67 @@ /** * \file vlibrasUpdate.cpp -* \authors Ezequiel Silva -* \date outubro 2015 +* \author Ezequiel Silva +* \ email eseveriano@gmail.com +* \date outubro 2015 / modified março 2016 */ #include "vlibrasUpdate.h" +#include +#include +#include +#include +#pragma warning( disable : 4800 ) +#define BUFSIZE 4096 +HANDLE g_hChildStd_OUT_Rd = NULL; +HANDLE g_hChildStd_OUT_Wr = NULL; +HANDLE g_hChildStd_ERR_Rd = NULL; +HANDLE g_hChildStd_ERR_Wr = NULL; +using namespace std; + +int CreateChildProcess(void); +string ReadFromPipe(); + + + +int VlibrasUpdate::checkExe() +{ + SECURITY_ATTRIBUTES sa; + + // Set the bInheritHandle flag so pipe handles are inherited. + sa.nLength = sizeof(SECURITY_ATTRIBUTES); + sa.bInheritHandle = TRUE; + sa.lpSecurityDescriptor = NULL; + // Create a pipe for the child process's STDERR. + if ( ! CreatePipe(&g_hChildStd_ERR_Rd, &g_hChildStd_ERR_Wr, &sa, 0) ) { + return -1; + } + // Ensure the read handle to the pipe for STDERR is not inherited. + if ( ! SetHandleInformation(g_hChildStd_ERR_Rd, HANDLE_FLAG_INHERIT, 0) ){ + return -1; + } + // Create a pipe for the child process's STDOUT. + if ( ! CreatePipe(&g_hChildStd_OUT_Rd, &g_hChildStd_OUT_Wr, &sa, 0) ) { + return -1; + } + // Ensure the read handle to the pipe for STDOUT is not inherited + if ( ! SetHandleInformation(g_hChildStd_OUT_Rd, HANDLE_FLAG_INHERIT, 0) ){ + return -1; + } + // Create the child process. + int result_pross = CreateChildProcess(); + + if(result_pross == -1) + return -1; + + // Read from pipe that is the standard output for child process. + string result = ReadFromPipe(); + + return atoi(result.c_str()); + + +} int VlibrasUpdate::install(char* strFunct, char* strstrParams) { @@ -47,7 +102,78 @@ int VlibrasUpdate::install(char* strFunct, char* strstrParams) return -1; } - return 0; + return -1; + +} + + + +// Create a child process that uses the previously created pipes +// for STDERR and STDOUT. +int CreateChildProcess(){ + // Set the text I want to run + char szCmdline[]="c:\\VLibras\\update\\bin\\checkVersion.exe"; + PROCESS_INFORMATION piProcInfo; + STARTUPINFO siStartInfo; + bool bSuccess = FALSE; + + // Set up members of the PROCESS_INFORMATION structure. + ZeroMemory( &piProcInfo, sizeof(PROCESS_INFORMATION) ); + + // Set up members of the STARTUPINFO structure. + // This structure specifies the STDERR and STDOUT handles for redirection. + ZeroMemory( &siStartInfo, sizeof(STARTUPINFO) ); + siStartInfo.cb = sizeof(STARTUPINFO); + siStartInfo.hStdError = g_hChildStd_ERR_Wr; + siStartInfo.hStdOutput = g_hChildStd_OUT_Wr; + siStartInfo.dwFlags |= STARTF_USESTDHANDLES; + // Create the child process. + bSuccess = CreateProcess(NULL, + szCmdline, // command line + NULL, // process security attributes + NULL, // primary thread security attributes + TRUE, // handles are inherited + CREATE_NO_WINDOW, // creation flags + NULL, // use parent's environment + NULL, // use parent's current directory + &siStartInfo, // STARTUPINFO pointer + &piProcInfo); // receives PROCESS_INFORMATION + CloseHandle(g_hChildStd_ERR_Wr); + CloseHandle(g_hChildStd_OUT_Wr); + // If an error occurs, exit the application. + if ( ! bSuccess ) { + return -1; + } + return 1; +} + +// Read output from the child process's pipe for STDOUT +// and write to the parent process's pipe for STDOUT. +// Stop when there is no more data. +string ReadFromPipe() { + DWORD dwRead; + CHAR chBuf[BUFSIZE]; + bool bSuccess = FALSE; + std::string out = "", err = ""; + for (;;) { + bSuccess=ReadFile( g_hChildStd_OUT_Rd, chBuf, BUFSIZE, &dwRead, NULL); + if( ! bSuccess || dwRead == 0 ) break; + + std::string s(chBuf, dwRead); + out += s; + } + dwRead = 0; + for (;;) { + bSuccess=ReadFile( g_hChildStd_ERR_Rd, chBuf, BUFSIZE, &dwRead, NULL); + if( ! bSuccess || dwRead == 0 ) break; + + std::string s(chBuf, dwRead); + err += s; + + } + + return out; + } -- libgit2 0.21.2