Commit 86e082399eecd672ced786702b38fd12b3bfadb6
1 parent
b0af91bd
Exists in
master
Finalizada versao 4.0.0
Showing
7 changed files
with
375 additions
and
39 deletions
Show diff stats
install/inno setup/user_install.iss
| @@ -15,7 +15,6 @@ | @@ -15,7 +15,6 @@ | ||
| 15 | 15 | ||
| 16 | [Setup] | 16 | [Setup] |
| 17 | AppId= {{84B73167-EF7F-42BB-9CCD-E1A8E2C53659-vlibras} | 17 | AppId= {{84B73167-EF7F-42BB-9CCD-E1A8E2C53659-vlibras} |
| 18 | - | ||
| 19 | AppName={#MyAppName} | 18 | AppName={#MyAppName} |
| 20 | AppVersion={#MyAppVersion} | 19 | AppVersion={#MyAppVersion} |
| 21 | AppPublisher={#MyAppPublisher} | 20 | AppPublisher={#MyAppPublisher} |
| @@ -46,6 +45,7 @@ Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescrip | @@ -46,6 +45,7 @@ Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescrip | ||
| 46 | [Files] | 45 | [Files] |
| 47 | 46 | ||
| 48 | Source: "python-2.7.9.msi"; DestDir: "{tmp}"; Flags: ignoreversion deleteafterinstall; | 47 | Source: "python-2.7.9.msi"; DestDir: "{tmp}"; Flags: ignoreversion deleteafterinstall; |
| 48 | +Source: "configureEnvironmentVariables.exe"; DestDir: "{tmp}"; Flags: ignoreversion deleteafterinstall; | ||
| 49 | Source: "user_install\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs; | 49 | Source: "user_install\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs; |
| 50 | Source: "required\*"; DestDir: "{tmp}\required"; Flags: ignoreversion recursesubdirs createallsubdirs deleteafterinstall | 50 | Source: "required\*"; DestDir: "{tmp}\required"; Flags: ignoreversion recursesubdirs createallsubdirs deleteafterinstall |
| 51 | 51 | ||
| @@ -58,10 +58,20 @@ Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\Player\{#MyAppExeName}"; | @@ -58,10 +58,20 @@ Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\Player\{#MyAppExeName}"; | ||
| 58 | Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\{#MyAppName}"; Filename: "{app}\Player\{#MyAppExeName}"; Tasks: quicklaunchicon; IconFilename: "{app}\icons\icon_vlibras.ico" | 58 | Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\{#MyAppName}"; Filename: "{app}\Player\{#MyAppExeName}"; Tasks: quicklaunchicon; IconFilename: "{app}\icons\icon_vlibras.ico" |
| 59 | 59 | ||
| 60 | [Run] | 60 | [Run] |
| 61 | - | 61 | +Filename: {tmp}\configureEnvironmentVariables.exe ; Flags: runhidden; StatusMsg: Definindo variáveis de ambiente... |
| 62 | Filename: msiexec ; Flags: runhidden; Parameters: /i {tmp}\python-2.7.9.msi /passive; StatusMsg: Instalando python-2.7.9... | 62 | Filename: msiexec ; Flags: runhidden; Parameters: /i {tmp}\python-2.7.9.msi /passive; StatusMsg: Instalando python-2.7.9... |
| 63 | Filename: {tmp}\required\user_install.bat; Flags: runhidden; StatusMsg: Instalando dependências... | 63 | Filename: {tmp}\required\user_install.bat; Flags: runhidden; StatusMsg: Instalando dependências... |
| 64 | 64 | ||
| 65 | +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... | ||
| 66 | +Filename: pip ; Flags: runhidden; Parameters: install {tmp}\required\PyYAML-3.11-cp27-none-win32.whl; StatusMsg: Instalando PyYAML... | ||
| 67 | +Filename: pip ; Flags: runhidden; Parameters: install {tmp}\required\numpy-1.9.2+mkl-cp27-none-win32.whl; StatusMsg: Instalando numpy... | ||
| 68 | +Filename: pip ; Flags: runhidden; Parameters: install {tmp}\required\six-1.9.0-py2.py3-none-any.whl; StatusMsg: Instalando six... | ||
| 69 | +Filename: pip ; Flags: runhidden; Parameters: install {tmp}\required\pyparsing-2.0.3-py2-none-any.whl; StatusMsg: Instalando pyparsing... | ||
| 70 | +Filename: pip ; Flags: runhidden; Parameters: install {tmp}\required\pytz-2014.10-py2.py3-none-any.whl; StatusMsg: Instalando pytz... | ||
| 71 | +Filename: pip ; Flags: runhidden; Parameters: install {tmp}\required\python_dateutil-2.4.0-py2.py3-none-any.whl; StatusMsg: Instalando python_dateutil... | ||
| 72 | +Filename: pip ; Flags: runhidden; Parameters: install {tmp}\required\matplotlib-1.4.3-cp27-none-win32.whl; StatusMsg: Instalando matplotlib... | ||
| 73 | +Filename: pip ; Flags: runhidden; Parameters: install {tmp}\required\nltk-3.0.2-py2.py3-none-any.whl; StatusMsg: Instalando nltk... | ||
| 74 | +Filename: pip ; Flags: runhidden; Parameters: install {tmp}\required\future-0.14.3-py2-none-any.whl; StatusMsg: Instalando future... | ||
| 65 | 75 | ||
| 66 | 76 | ||
| 67 | 77 | ||
| @@ -101,8 +111,11 @@ begin | @@ -101,8 +111,11 @@ begin | ||
| 101 | 111 | ||
| 102 | if CurStep = ssDone then | 112 | if CurStep = ssDone then |
| 103 | begin | 113 | begin |
| 114 | + FileCopy(ExpandConstant('{app}\nltk_data\hunpos.py'), ExpandConstant('{sd}\Python27\Lib\site-packages\nltk\tag\hunpos.py'), False); | ||
| 115 | + FileCopy(ExpandConstant('{app}\nltk_data\data.py'), ExpandConstant('{sd}\Python27\Lib\site-packages\nltk\data.py'), False); | ||
| 116 | + FileCopy(ExpandConstant('{app}\nltk_data\nltk_tgrep.py'), ExpandConstant('{sd}\Python27\Lib\site-packages\nltk_tgrep.py'), False); | ||
| 104 | DelTree('C:\vlibras-libs', True, True, True); | 117 | DelTree('C:\vlibras-libs', True, True, True); |
| 105 | - //chama o instalador baixado | 118 | + |
| 106 | if not ShellExec('', ExpandConstant('{app}\update\bin\DicionarioUp.exe'), '', '', SW_SHOW, ewNoWait, ErrorCode) then | 119 | if not ShellExec('', ExpandConstant('{app}\update\bin\DicionarioUp.exe'), '', '', SW_SHOW, ewNoWait, ErrorCode) then |
| 107 | begin | 120 | begin |
| 108 | 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); | 121 | 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); |
plugin/corePlugin.cpp
| 1 | 1 | ||
| 2 | +/** | ||
| 3 | +* \file corePlugin.cpp | ||
| 4 | +* \author Ezequiel Silva | ||
| 5 | +* \ email eseveriano@gmail.com | ||
| 6 | +* \date outubro 2015 / modified março 2016 | ||
| 7 | +*/ | ||
| 8 | + | ||
| 2 | #if _MSC_VER | 9 | #if _MSC_VER |
| 3 | #define EXPORT_API __declspec(dllexport) | 10 | #define EXPORT_API __declspec(dllexport) |
| 4 | #else | 11 | #else |
| @@ -19,7 +26,7 @@ using namespace std; | @@ -19,7 +26,7 @@ using namespace std; | ||
| 19 | { | 26 | { |
| 20 | //Objeto usado para traduzir | 27 | //Objeto usado para traduzir |
| 21 | tradutor = new PyTradutor(); | 28 | tradutor = new PyTradutor(); |
| 22 | - update = new PyVlibrasUpdate(); | 29 | + update = new VlibrasUpdate(); |
| 23 | //Objeto usado para copiar texto da área de transferência | 30 | //Objeto usado para copiar texto da área de transferência |
| 24 | clipboard.bdragOn(); | 31 | clipboard.bdragOn(); |
| 25 | 32 | ||
| @@ -55,31 +62,8 @@ using namespace std; | @@ -55,31 +62,8 @@ using namespace std; | ||
| 55 | EXPORT_API int coreUpdateCheck() | 62 | EXPORT_API int coreUpdateCheck() |
| 56 | { | 63 | { |
| 57 | 64 | ||
| 58 | - string line_in_str; | ||
| 59 | - ifstream file_version; | ||
| 60 | - int return_int = -1; | ||
| 61 | - try | ||
| 62 | - { | ||
| 63 | - update->checkExe("c:\\VLibras\\update\\bin\\checkVersion.exe","check"); | ||
| 64 | - | ||
| 65 | - clock_t time_end; | ||
| 66 | - time_end = clock() + 3000 * CLOCKS_PER_SEC/1000; | ||
| 67 | - while (clock() < time_end); | ||
| 68 | - | ||
| 69 | - | ||
| 70 | - file_version.open("c:\\VLibras\\update\\version\\version.txt"); | 65 | + return update->checkExe(); |
| 71 | 66 | ||
| 72 | - getline(file_version, line_in_str); | ||
| 73 | - file_version.close(); | ||
| 74 | - return_int = atoi(line_in_str.c_str()); | ||
| 75 | - | ||
| 76 | - return return_int; | ||
| 77 | - } | ||
| 78 | - catch (exception e) | ||
| 79 | - { | ||
| 80 | - return -1; | ||
| 81 | - } | ||
| 82 | - return return_int; | ||
| 83 | } | 67 | } |
| 84 | 68 | ||
| 85 | EXPORT_API int coreFinalize() | 69 | EXPORT_API int coreFinalize() |
plugin/corePlugin.h
| @@ -10,18 +10,14 @@ VLibras-Core | @@ -10,18 +10,14 @@ VLibras-Core | ||
| 10 | */ | 10 | */ |
| 11 | //***************************************************************** | 11 | //***************************************************************** |
| 12 | 12 | ||
| 13 | -/** | ||
| 14 | -* \file corePlugin.h | ||
| 15 | -* \authors Bruno Santos, Ezequiel Silva | ||
| 16 | -* \date Janeiro 2015 / Outubro 2015 | ||
| 17 | -*/ | 13 | + |
| 18 | #ifndef _COREPLUGIN_H | 14 | #ifndef _COREPLUGIN_H |
| 19 | #define _COREPLUGIN_H | 15 | #define _COREPLUGIN_H |
| 20 | 16 | ||
| 21 | 17 | ||
| 22 | #include "pyClip.h" | 18 | #include "pyClip.h" |
| 23 | #include "pyTradutor.h" | 19 | #include "pyTradutor.h" |
| 24 | -#include "pyVlibrasUpdate.h" | 20 | +#include "vlibrasUpdate.h" |
| 25 | #include <fstream> | 21 | #include <fstream> |
| 26 | #include <string> | 22 | #include <string> |
| 27 | 23 | ||
| @@ -38,7 +34,7 @@ extern "C" | @@ -38,7 +34,7 @@ extern "C" | ||
| 38 | PyClip clipboard; | 34 | PyClip clipboard; |
| 39 | 35 | ||
| 40 | //Usado para verificar se existe atualização | 36 | //Usado para verificar se existe atualização |
| 41 | - PyVlibrasUpdate *update; | 37 | + VlibrasUpdate *update; |
| 42 | 38 | ||
| 43 | //Inicializa Objetos | 39 | //Inicializa Objetos |
| 44 | EXPORT_API int coreInitize(void); | 40 | EXPORT_API int coreInitize(void); |
update/include/vlibrasUpdate.h
| @@ -7,7 +7,7 @@ VLibras-Core group at LAViD, Federal University of Paraiba | @@ -7,7 +7,7 @@ VLibras-Core group at LAViD, Federal University of Paraiba | ||
| 7 | //***************************************************************** | 7 | //***************************************************************** |
| 8 | 8 | ||
| 9 | /** | 9 | /** |
| 10 | -* \file pyVlibrasUpdate.h | 10 | +* \file vlibrasUpdate.h |
| 11 | * \authors Ezequiel Silva | 11 | * \authors Ezequiel Silva |
| 12 | * \date Setembro 2015 | 12 | * \date Setembro 2015 |
| 13 | */ | 13 | */ |
| @@ -24,6 +24,7 @@ class VlibrasUpdate | @@ -24,6 +24,7 @@ class VlibrasUpdate | ||
| 24 | 24 | ||
| 25 | public: | 25 | public: |
| 26 | int install(char* strFunct, char* strstrParams); | 26 | int install(char* strFunct, char* strstrParams); |
| 27 | + int checkExe(); | ||
| 27 | 28 | ||
| 28 | }; | 29 | }; |
| 29 | 30 |
| @@ -0,0 +1,147 @@ | @@ -0,0 +1,147 @@ | ||
| 1 | + | ||
| 2 | +/* | ||
| 3 | +* \author Ezequiel Silva | ||
| 4 | +* \ email eseveriano@gmail.com | ||
| 5 | +* \date março 2016 | ||
| 6 | +*/ | ||
| 7 | + | ||
| 8 | +#include <time.h> | ||
| 9 | +#include <fstream> | ||
| 10 | +#include <string> | ||
| 11 | +#include <cstdlib> | ||
| 12 | +#include <IOSTREAM> | ||
| 13 | +#include <windows.h> | ||
| 14 | +#include <thread> | ||
| 15 | +using namespace std; | ||
| 16 | + | ||
| 17 | +HINSTANCE hDLL1; | ||
| 18 | +char* pPathTempJson; | ||
| 19 | +char* pPathVlibrasJson; | ||
| 20 | +int codDownload = -1; | ||
| 21 | + | ||
| 22 | +//Assinatura do método itd_downloadfile utilizado na dll | ||
| 23 | +typedef int (WINAPI*download)(char * arg1, char * arg2); | ||
| 24 | +download itd_downloadfile; | ||
| 25 | + | ||
| 26 | +//ofstream versionFileCheck; | ||
| 27 | + | ||
| 28 | + | ||
| 29 | + | ||
| 30 | +//usado para representar as versoes tanto da api quanto local | ||
| 31 | +typedef struct Versions | ||
| 32 | +{ | ||
| 33 | + char versionDicionario[7]={'0','0','0','0','0','0','\0'}; | ||
| 34 | + char versionPlayer[4]={'0','0','0','\0'}; | ||
| 35 | +} Version; | ||
| 36 | + | ||
| 37 | +// usado para carregar os jsons de versoes | ||
| 38 | +Version loadVersion(char* pPathTempJson) | ||
| 39 | +{ | ||
| 40 | + Version version; | ||
| 41 | + string line_in_str; | ||
| 42 | + ifstream file_versionApi; | ||
| 43 | + | ||
| 44 | + int i; | ||
| 45 | + try | ||
| 46 | + { | ||
| 47 | + file_versionApi.open(pPathTempJson); | ||
| 48 | + while ( getline (file_versionApi, line_in_str) ) | ||
| 49 | + { | ||
| 50 | + if(strstr(line_in_str.c_str(), "playerVersion")){ | ||
| 51 | + i = 0; | ||
| 52 | + for (char & c : line_in_str) | ||
| 53 | + if(isdigit(c)) | ||
| 54 | + version.versionPlayer[i++]=c; | ||
| 55 | + version.versionPlayer[i]='\0'; | ||
| 56 | + } | ||
| 57 | + else if(strstr(line_in_str.c_str(), "dictionaryVersion")){ | ||
| 58 | + | ||
| 59 | + i = 0; | ||
| 60 | + for (char & c : line_in_str) | ||
| 61 | + if(isdigit(c)) | ||
| 62 | + version.versionDicionario[i++]=c; | ||
| 63 | + version.versionDicionario[i]='\0'; | ||
| 64 | + } | ||
| 65 | + } | ||
| 66 | + file_versionApi.close(); | ||
| 67 | + } | ||
| 68 | + catch (exception e) | ||
| 69 | + { | ||
| 70 | + cout<<"-1"<<endl; | ||
| 71 | + } | ||
| 72 | + return version; | ||
| 73 | +} | ||
| 74 | + | ||
| 75 | +void downloadFileJson(){ | ||
| 76 | + | ||
| 77 | + codDownload = itd_downloadfile("http://vlibras.lavid.ufpb.br/api/dicionario/0.0.0_0.0.0?type=json",pPathTempJson); | ||
| 78 | +} | ||
| 79 | + | ||
| 80 | + | ||
| 81 | + | ||
| 82 | +int main(){ | ||
| 83 | + | ||
| 84 | + //versionFileCheck.open ("c:\\VLibras\\update\\version\\version.txt"); | ||
| 85 | + | ||
| 86 | + pPathTempJson ="C:\\VLibras\\update\\download\\VLibrasVersionApi.json"; | ||
| 87 | + pPathVlibrasJson = "c:\\VLibras\\version.json"; | ||
| 88 | + //Carrega a dll | ||
| 89 | + hDLL1 = LoadLibrary("c:\\VLibras\\update\\plugins\\itdownload.dll"); | ||
| 90 | + //Relaciona método local com o método implementado na dll | ||
| 91 | + itd_downloadfile=(download)GetProcAddress((HMODULE)hDLL1, "itd_downloadfile"); | ||
| 92 | + | ||
| 93 | + if (hDLL1){ | ||
| 94 | + | ||
| 95 | + //faz download do json de versao | ||
| 96 | + thread tDownloadFileJson(downloadFileJson); | ||
| 97 | + | ||
| 98 | + clock_t time_end; | ||
| 99 | + time_end = clock() + 3000 * CLOCKS_PER_SEC/1000; | ||
| 100 | + while (clock() < time_end){ | ||
| 101 | + if(codDownload != -1) | ||
| 102 | + break; | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + if(codDownload == -1 ){ | ||
| 106 | + cout<<"-1"<<endl; | ||
| 107 | + goto fim; | ||
| 108 | + } | ||
| 109 | + tDownloadFileJson.join(); | ||
| 110 | + | ||
| 111 | + //verifica se existe os dois arquivos de versao | ||
| 112 | + if(!ifstream(pPathTempJson) || !ifstream(pPathVlibrasJson) || (codDownload > 0 )){ | ||
| 113 | + | ||
| 114 | + cout<<"-1"<<endl; | ||
| 115 | + goto fim; | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + Version versionApi = loadVersion(pPathTempJson); | ||
| 119 | + Version versionLocal = loadVersion(pPathVlibrasJson); | ||
| 120 | + | ||
| 121 | + // compara as versoes (return '0' para nao tem attualizacao, '1' para player e '2' para dicionario) | ||
| 122 | + if(atoi(versionApi.versionPlayer)> atoi(versionLocal.versionPlayer)) | ||
| 123 | + cout<<"1"<<endl; | ||
| 124 | + //versionFileCheck << "1"; | ||
| 125 | + else if(atoi(versionApi.versionDicionario)> atoi(versionLocal.versionDicionario)) | ||
| 126 | + cout<<"2"<<endl; | ||
| 127 | + //versionFileCheck << "2"; | ||
| 128 | + else | ||
| 129 | + cout<<"0"<<endl; | ||
| 130 | + //versionFileCheck << "0"; | ||
| 131 | + } | ||
| 132 | + else | ||
| 133 | + cout<<"-1"<<endl; | ||
| 134 | + //versionFileCheck << "-1"; | ||
| 135 | + | ||
| 136 | + | ||
| 137 | + fim: | ||
| 138 | + | ||
| 139 | + | ||
| 140 | + //versionFileCheck.close(); | ||
| 141 | + | ||
| 142 | + //Libera dll | ||
| 143 | + FreeLibrary((HMODULE)hDLL1); | ||
| 144 | + return 1; | ||
| 145 | + | ||
| 146 | +} | ||
| 147 | + |
| @@ -0,0 +1,69 @@ | @@ -0,0 +1,69 @@ | ||
| 1 | + | ||
| 2 | +/** | ||
| 3 | +* \file configureEnvironmentVariable.cpp | ||
| 4 | +* \author Ezequiel Silva | ||
| 5 | +* \ email eseveriano@gmail.com | ||
| 6 | +* \date Março 2016 | ||
| 7 | +*/ | ||
| 8 | + | ||
| 9 | +#include <string> | ||
| 10 | +#include <stdio.h> | ||
| 11 | + | ||
| 12 | +using namespace std; | ||
| 13 | + | ||
| 14 | + | ||
| 15 | +int main(int argc, char *argv[]){ | ||
| 16 | + | ||
| 17 | + char str[4096]; | ||
| 18 | + str[0]=0; | ||
| 19 | + //pega o valor da variável de ambiente PATH | ||
| 20 | + FILE *fp = _popen("echo %PATH%","r"); | ||
| 21 | + char buf[1024]; | ||
| 22 | + // concatena todos os valores | ||
| 23 | + while (fgets(buf, 1024, fp)) { | ||
| 24 | + strcat(str,buf); | ||
| 25 | + } | ||
| 26 | + //guarda todos os itens que serao novamente setado na variável PATH | ||
| 27 | + string path=""; | ||
| 28 | + | ||
| 29 | + char * pch; | ||
| 30 | + //cada item da variável | ||
| 31 | + char item[1024]; | ||
| 32 | + | ||
| 33 | + // inicio da verificação se existe algum item da variável relacionado com VLIBRAS | ||
| 34 | + pch = strtok (str,";"); | ||
| 35 | + while (pch != NULL) | ||
| 36 | + { | ||
| 37 | + strcpy(item,pch); | ||
| 38 | + if(!strstr(path.c_str(),item)) | ||
| 39 | + { if(!(strstr(item,"vlibras") || strstr(item,"VLibras") || strstr(item,"Python27"))) | ||
| 40 | + { | ||
| 41 | + path.append(pch); | ||
| 42 | + path.append(";"); | ||
| 43 | + } | ||
| 44 | + } | ||
| 45 | + pch = strtok (NULL, ";"); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + /*######FIM VERIFICAÇÂO######*/ | ||
| 49 | + | ||
| 50 | + // variáveis de ambiente a serem setadas | ||
| 51 | +system("SETX PATH_VLIBRAS %HOMEDRIVE%\\VLibras /M"); | ||
| 52 | +system("SETX AELIUS_DATA %PATH_VLIBRAS%\\aelius_data /M"); | ||
| 53 | +system("SETX NLTK_DATA %PATH_VLIBRAS%\\nltk_data /M"); | ||
| 54 | +system("SETX HUNPOS_TAGGER %PATH_VLIBRAS%\\bin\\hunpos-tag.exe /M"); | ||
| 55 | +system("SETX TRANSLATE_DATA %PATH_VLIBRAS%\\translate\\data /M"); | ||
| 56 | +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"); | ||
| 57 | + | ||
| 58 | +string pathFinal="SETX \"PATH\" \""; | ||
| 59 | +pathFinal.append("%PYTHONPATH%;"); | ||
| 60 | +pathFinal.append(path); | ||
| 61 | +pathFinal.append("\" /M"); | ||
| 62 | +system(pathFinal.c_str()); | ||
| 63 | + | ||
| 64 | +/*FIM SETA VARIÁVEIS DE AMBIENTE*/ | ||
| 65 | + | ||
| 66 | +fclose(fp); | ||
| 67 | + | ||
| 68 | + return 0; | ||
| 69 | +} |
update/src/vlibrasUpdate.cpp
| 1 | 1 | ||
| 2 | /** | 2 | /** |
| 3 | * \file vlibrasUpdate.cpp | 3 | * \file vlibrasUpdate.cpp |
| 4 | -* \authors Ezequiel Silva | ||
| 5 | -* \date outubro 2015 | 4 | +* \author Ezequiel Silva |
| 5 | +* \ email eseveriano@gmail.com | ||
| 6 | +* \date outubro 2015 / modified março 2016 | ||
| 6 | */ | 7 | */ |
| 7 | 8 | ||
| 8 | #include "vlibrasUpdate.h" | 9 | #include "vlibrasUpdate.h" |
| 10 | +#include <string> | ||
| 11 | +#include <iostream> | ||
| 12 | +#include <windows.h> | ||
| 13 | +#include <stdio.h> | ||
| 14 | +#pragma warning( disable : 4800 ) | ||
| 15 | +#define BUFSIZE 4096 | ||
| 16 | +HANDLE g_hChildStd_OUT_Rd = NULL; | ||
| 17 | +HANDLE g_hChildStd_OUT_Wr = NULL; | ||
| 18 | +HANDLE g_hChildStd_ERR_Rd = NULL; | ||
| 19 | +HANDLE g_hChildStd_ERR_Wr = NULL; | ||
| 9 | 20 | ||
| 21 | +using namespace std; | ||
| 22 | + | ||
| 23 | +int CreateChildProcess(void); | ||
| 24 | +string ReadFromPipe(); | ||
| 25 | + | ||
| 26 | + | ||
| 27 | + | ||
| 28 | +int VlibrasUpdate::checkExe() | ||
| 29 | +{ | ||
| 30 | + SECURITY_ATTRIBUTES sa; | ||
| 31 | + | ||
| 32 | + // Set the bInheritHandle flag so pipe handles are inherited. | ||
| 33 | + sa.nLength = sizeof(SECURITY_ATTRIBUTES); | ||
| 34 | + sa.bInheritHandle = TRUE; | ||
| 35 | + sa.lpSecurityDescriptor = NULL; | ||
| 36 | + // Create a pipe for the child process's STDERR. | ||
| 37 | + if ( ! CreatePipe(&g_hChildStd_ERR_Rd, &g_hChildStd_ERR_Wr, &sa, 0) ) { | ||
| 38 | + return -1; | ||
| 39 | + } | ||
| 40 | + // Ensure the read handle to the pipe for STDERR is not inherited. | ||
| 41 | + if ( ! SetHandleInformation(g_hChildStd_ERR_Rd, HANDLE_FLAG_INHERIT, 0) ){ | ||
| 42 | + return -1; | ||
| 43 | + } | ||
| 44 | + // Create a pipe for the child process's STDOUT. | ||
| 45 | + if ( ! CreatePipe(&g_hChildStd_OUT_Rd, &g_hChildStd_OUT_Wr, &sa, 0) ) { | ||
| 46 | + return -1; | ||
| 47 | + } | ||
| 48 | + // Ensure the read handle to the pipe for STDOUT is not inherited | ||
| 49 | + if ( ! SetHandleInformation(g_hChildStd_OUT_Rd, HANDLE_FLAG_INHERIT, 0) ){ | ||
| 50 | + return -1; | ||
| 51 | + } | ||
| 52 | + // Create the child process. | ||
| 53 | + int result_pross = CreateChildProcess(); | ||
| 54 | + | ||
| 55 | + if(result_pross == -1) | ||
| 56 | + return -1; | ||
| 57 | + | ||
| 58 | + // Read from pipe that is the standard output for child process. | ||
| 59 | + string result = ReadFromPipe(); | ||
| 60 | + | ||
| 61 | + return atoi(result.c_str()); | ||
| 62 | + | ||
| 63 | + | ||
| 64 | +} | ||
| 10 | 65 | ||
| 11 | int VlibrasUpdate::install(char* strFunct, char* strstrParams) | 66 | int VlibrasUpdate::install(char* strFunct, char* strstrParams) |
| 12 | { | 67 | { |
| @@ -47,7 +102,78 @@ int VlibrasUpdate::install(char* strFunct, char* strstrParams) | @@ -47,7 +102,78 @@ int VlibrasUpdate::install(char* strFunct, char* strstrParams) | ||
| 47 | return -1; | 102 | return -1; |
| 48 | } | 103 | } |
| 49 | 104 | ||
| 50 | - return 0; | 105 | + return -1; |
| 106 | + | ||
| 107 | +} | ||
| 108 | + | ||
| 109 | + | ||
| 110 | + | ||
| 111 | +// Create a child process that uses the previously created pipes | ||
| 112 | +// for STDERR and STDOUT. | ||
| 113 | +int CreateChildProcess(){ | ||
| 114 | + // Set the text I want to run | ||
| 115 | + char szCmdline[]="c:\\VLibras\\update\\bin\\checkVersion.exe"; | ||
| 116 | + PROCESS_INFORMATION piProcInfo; | ||
| 117 | + STARTUPINFO siStartInfo; | ||
| 118 | + bool bSuccess = FALSE; | ||
| 119 | + | ||
| 120 | + // Set up members of the PROCESS_INFORMATION structure. | ||
| 121 | + ZeroMemory( &piProcInfo, sizeof(PROCESS_INFORMATION) ); | ||
| 122 | + | ||
| 123 | + // Set up members of the STARTUPINFO structure. | ||
| 124 | + // This structure specifies the STDERR and STDOUT handles for redirection. | ||
| 125 | + ZeroMemory( &siStartInfo, sizeof(STARTUPINFO) ); | ||
| 126 | + siStartInfo.cb = sizeof(STARTUPINFO); | ||
| 127 | + siStartInfo.hStdError = g_hChildStd_ERR_Wr; | ||
| 128 | + siStartInfo.hStdOutput = g_hChildStd_OUT_Wr; | ||
| 129 | + siStartInfo.dwFlags |= STARTF_USESTDHANDLES; | ||
| 51 | 130 | ||
| 131 | + // Create the child process. | ||
| 132 | + bSuccess = CreateProcess(NULL, | ||
| 133 | + szCmdline, // command line | ||
| 134 | + NULL, // process security attributes | ||
| 135 | + NULL, // primary thread security attributes | ||
| 136 | + TRUE, // handles are inherited | ||
| 137 | + CREATE_NO_WINDOW, // creation flags | ||
| 138 | + NULL, // use parent's environment | ||
| 139 | + NULL, // use parent's current directory | ||
| 140 | + &siStartInfo, // STARTUPINFO pointer | ||
| 141 | + &piProcInfo); // receives PROCESS_INFORMATION | ||
| 142 | + CloseHandle(g_hChildStd_ERR_Wr); | ||
| 143 | + CloseHandle(g_hChildStd_OUT_Wr); | ||
| 144 | + // If an error occurs, exit the application. | ||
| 145 | + if ( ! bSuccess ) { | ||
| 146 | + return -1; | ||
| 147 | + } | ||
| 148 | + return 1; | ||
| 149 | +} | ||
| 150 | + | ||
| 151 | +// Read output from the child process's pipe for STDOUT | ||
| 152 | +// and write to the parent process's pipe for STDOUT. | ||
| 153 | +// Stop when there is no more data. | ||
| 154 | +string ReadFromPipe() { | ||
| 155 | + DWORD dwRead; | ||
| 156 | + CHAR chBuf[BUFSIZE]; | ||
| 157 | + bool bSuccess = FALSE; | ||
| 158 | + std::string out = "", err = ""; | ||
| 159 | + for (;;) { | ||
| 160 | + bSuccess=ReadFile( g_hChildStd_OUT_Rd, chBuf, BUFSIZE, &dwRead, NULL); | ||
| 161 | + if( ! bSuccess || dwRead == 0 ) break; | ||
| 162 | + | ||
| 163 | + std::string s(chBuf, dwRead); | ||
| 164 | + out += s; | ||
| 165 | + } | ||
| 166 | + dwRead = 0; | ||
| 167 | + for (;;) { | ||
| 168 | + bSuccess=ReadFile( g_hChildStd_ERR_Rd, chBuf, BUFSIZE, &dwRead, NULL); | ||
| 169 | + if( ! bSuccess || dwRead == 0 ) break; | ||
| 170 | + | ||
| 171 | + std::string s(chBuf, dwRead); | ||
| 172 | + err += s; | ||
| 173 | + | ||
| 174 | + } | ||
| 175 | + | ||
| 176 | + return out; | ||
| 177 | + | ||
| 52 | } | 178 | } |
| 53 | 179 |