From 9057738d431bd2d8f0b7d2a87c4fa7f7950bd5ed Mon Sep 17 00:00:00 2001 From: ezequiel Date: Wed, 7 Oct 2015 11:33:52 -0300 Subject: [PATCH] Nova versão do update --- Makefile | 8 ++++---- include/util.h | 13 ++++--------- install/inno setup/user_install.iss | 14 +++++++------- plugin/corePlugin.cpp | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------- plugin/corePlugin.h | 11 ++++++++--- src/util.cpp | 124 +--------------------------------------------------------------------------------------------------------------------------- update/include/checkVersion.h | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ update/include/janelaAtualizacao.h | 22 ++++++++++++++++++++++ update/src/checkVersion.cpp | 182 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ update/src/util.cpp | 1 - 10 files changed, 345 insertions(+), 179 deletions(-) create mode 100644 update/include/checkVersion.h create mode 100644 update/src/checkVersion.cpp diff --git a/Makefile b/Makefile index 1beba91..72a6fdf 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ ############################################################################ # Includes -CFLAGS = -I C:\Python27\include -I include -I "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include" +CFLAGS = -I C:\Python27\include -I include -I update\include -I "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include" # Link com as libs utilizadas LFLAGS = -link C:\Python27\libs\python27.lib @@ -23,10 +23,10 @@ OUT = testLibras # Arquivos de implementação -FILES = src\pyTradutor.cpp src\pyClip.cpp src\util.cpp +FILES = src\pyTradutor.cpp src\pyClip.cpp update\src\checkVersion.cpp #Headers -INCLUDES = include\pyTradutor.h include\pyClip.h include\util.h +INCLUDES = include\pyTradutor.h include\pyClip.h update\include\checkVersion.h CLEAN_OBJ = del -q *.obj @@ -40,7 +40,7 @@ all: $(FILES) $(INCLUDES) src\testLibras.cpp #Gera dll na arquitetura x86 plugin-x86: $(FILES) $(INCLUDES) IF NOT EXIST plugin\Plugin-x86 mkdir plugin\Plugin-x86 - $(CC) -Feplugin\Plugin-x86\CorePlugin -LD plugin\corePlugin.cpp $(FILES) -I plugin\corePlugin.h -clr $(CFLAGS) $(LFLAGS) + $(CC) -Feplugin\Plugin-x86\CorePlugin -LD plugin\corePlugin.cpp $(FILES) -I plugin\corePlugin.h -EHsc $(CFLAGS) $(LFLAGS) $(CLEAN_OBJ) #Gera dll na arquitetura x64 diff --git a/include/util.h b/include/util.h index df1917f..182693f 100644 --- a/include/util.h +++ b/include/util.h @@ -1,6 +1,5 @@ #using #using -#using #include #include @@ -9,12 +8,11 @@ using namespace std; using namespace System; -using namespace System::ComponentModel; + using namespace System::Net; using namespace System::IO; using namespace System::Xml; -using namespace System::Threading; -using namespace System::IO::Compression; + @@ -35,13 +33,10 @@ using namespace System::IO::Compression; Util(); bool downloading; - static bool saveNewXmlVersion(string playerVersion,string dictionaryVersion); - static string Download(DownloadProgressChangedEventHandler^ dpch ,string url, string fileName); + static bool checkNet(void); static vector checkVersion(bool atualize); - static bool extractZip(string zipFile, string outPath); - static bool backup(void); - static bool restore(void); + }; diff --git a/install/inno setup/user_install.iss b/install/inno setup/user_install.iss index de87f19..7413088 100644 --- a/install/inno setup/user_install.iss +++ b/install/inno setup/user_install.iss @@ -26,7 +26,7 @@ DisableDirPage=yes DefaultGroupName={#MyAppName} OutputBaseFilename=vlibras_desktop_win_2.0.0 DisableProgramGroupPage=yes -OutputDir="C:\Users\ezequiel\Desktop\vlibras_desktop_win_2.0.0" +OutputDir="C:\Users\ezequiel\Desktop\vlibras_installer_2.0.0" SetupIconFile="C:\Users\ezequiel\Desktop\user_install\icons\icon_vlibras.ico" Compression=lzma SolidCompression=yes @@ -43,8 +43,8 @@ Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{ Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; OnlyBelowVersion: 0,6.1 [Files] -Source: "C:\Users\ezequiel\Desktop\vc_redist.x86.exe"; DestDir: "{tmp}"; Flags: ignoreversion deleteafterinstall; -Source: "C:\Users\ezequiel\Desktop\dotNetFx40_Client_x86.exe"; DestDir: "{tmp}"; Flags: ignoreversion deleteafterinstall; +;Source: "C:\Users\ezequiel\Desktop\vc_redist.x86.exe"; DestDir: "{tmp}"; Flags: ignoreversion deleteafterinstall; +;Source: "C:\Users\ezequiel\Desktop\dotNetFx40_Client_x86.exe"; DestDir: "{tmp}"; Flags: ignoreversion deleteafterinstall; Source: "C:\Users\ezequiel\Desktop\user_install\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs @@ -58,10 +58,10 @@ 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}\dotNetFx40_Client_x86.exe; Flags: runhidden; Parameters: /q /norestart; StatusMsg: Instalando .NET Framework 4.5 -Filename: {tmp}\vc_redist.x86.exe; Flags: runhidden; Parameters: /q /norestart; StatusMsg: Instalando Visual C++ ... -Filename: {sd}\vlibras-libs\required\user_install.bat; Flags: runhidden; StatusMsg: Instalando dependências... -Filename: {sd}\vlibras-libs\update\vlibras-up.exe; Parameters: silence; StatusMsg: Instalando atualização... +;Filename: {tmp}\dotNetFx40_Client_x86.exe; Flags: runhidden; Parameters: /q /norestart; StatusMsg: Instalando .NET Framework 4.5 +;Filename: {tmp}\vc_redist.x86.exe; Flags: runhidden; Parameters: /q /norestart; StatusMsg: Instalando Visual C++ ... +Filename: {sd}\vlibras-libs\required\user_install.bat; Flags: runhidden; StatusMsg: Finalizando Instalação... +Filename: {sd}\vlibras-libs\update\vlibrasCheckUp.exe; Flags: runhidden; Parameters: /q /norestart; StatusMsg: Instalando atualização... diff --git a/plugin/corePlugin.cpp b/plugin/corePlugin.cpp index d79c9df..fe0f109 100644 --- a/plugin/corePlugin.cpp +++ b/plugin/corePlugin.cpp @@ -5,22 +5,22 @@ #define EXPORT_API __declspec(dllimport) #endif - +#include #include "corePlugin.h" + extern "C" { - - - + EXPORT_API int coreInitialize() { //Objeto usado para traduzir tradutor = new PyTradutor(); + checkversion = new CheckVersion(); check =0; //Objeto usado para copiar texto da área de transferência @@ -41,14 +41,69 @@ EXPORT_API int coreUpdateInstall_player() { - System::Diagnostics::Process::Start("C:\\vlibras-libs\\update\\vlibras-up.exe"); + + char szPath[] = "C:\\vlibras-libs\\update\\vlibras-up.exe"; + string params = "C:\\vlibras-libs\\update\\vlibras-up.exe "; + params.append(checkversion->playerUrl); + params.append(" installer "); + params.append(checkversion->playerVersionFull); + PROCESS_INFORMATION pif; //Gives info on the thread and.. + //..process for the new process + STARTUPINFO si; //Defines how to start the program + + ZeroMemory(&si,sizeof(si)); //Zero the STARTUPINFO struct + si.cb = sizeof(si); //Must set size of structure + + BOOL bRet = CreateProcess( + szPath, //Path to executable file + (LPSTR)params.c_str(), //Command string - not needed here + NULL, //Process handle not inherited + NULL, //Thread handle not inherited + FALSE, //No inheritance of handles + 0, //No special flags + NULL, //Same environment block as this prog + NULL, //Current directory - no separate path + &si, //Pointer to STARTUPINFO + &pif); //Pointer to PROCESS_INFORMATION + + + + CloseHandle(pif.hProcess); //Close handle to process + CloseHandle(pif.hThread); + return 1; } EXPORT_API int coreUpdateInstall_dict() { - System::Diagnostics::Process::Start("C:\\vlibras-libs\\update\\vlibras-up.exe"); + char szPath[] = "C:\\vlibras-libs\\update\\vlibras-up.exe"; + string params = "C:\\vlibras-libs\\update\\vlibras-up.exe "; + params.append(checkversion->dictUrl.c_str()); + params.append(" dictionary "); + params.append(checkversion->dictVersionFull); + PROCESS_INFORMATION pif; //Gives info on the thread and.. + //..process for the new process + STARTUPINFO si; //Defines how to start the program + + ZeroMemory(&si,sizeof(si)); //Zero the STARTUPINFO struct + si.cb = sizeof(si); //Must set size of structure + + BOOL bRet = CreateProcess( + szPath, //Path to executable file + (LPSTR)params.c_str(), //Command string - not needed here + NULL, //Process handle not inherited + NULL, //Thread handle not inherited + FALSE, //No inheritance of handles + 0, //No special flags + NULL, //Same environment block as this prog + NULL, //Current directory - no separate path + &si, //Pointer to STARTUPINFO + &pif); //Pointer to PROCESS_INFORMATION + + CloseHandle(pif.hProcess); //Close handle to process + CloseHandle(pif.hThread); + return 1; } @@ -56,33 +111,10 @@ EXPORT_API int coreUpdateCheck() { + + checkversion->checkRefresh(); - - vector updates = Util::checkVersion(false); - if(updates.size()>2) - { - - switch (updates.size()) - { - case 3: - if(updates[0]=="playerVersion") - { - return 1; - } - else if(updates[0]=="dictionaryVersion") - { - return 2; - } - break; - case 6: - return 1; - - break; - } - - } else if(updates.size()==1) - return -1; - return 0; + return checkversion->vstatus; } EXPORT_API int coreFinalize() diff --git a/plugin/corePlugin.h b/plugin/corePlugin.h index 9ff7ae6..5c15713 100644 --- a/plugin/corePlugin.h +++ b/plugin/corePlugin.h @@ -3,6 +3,8 @@ VLibras: Plugin para integração com Unity Bruno santos +Ezequiel Silva +ezequielsilva@lavid.ufpb.br VLibras-Core 2015 */ @@ -10,8 +12,8 @@ VLibras-Core /** * \file corePlugin.h -* \authors Bruno Santos -* \date Janeiro 2015 +* \authors Bruno Santos, Ezequiel Silva +* \date Janeiro 2015 / Outubro 2015 */ #ifndef _COREPLUGIN_H #define _COREPLUGIN_H @@ -19,8 +21,9 @@ VLibras-Core #include "pyClip.h" #include "pyTradutor.h" +#include "checkVersion.h" #include -#include "Util.h" + using namespace std; @@ -32,6 +35,8 @@ extern "C" //Usado para copiar texto da área de transferência PyClip clipboard; + //Usado para verificar se existe atualização + CheckVersion *checkversion; //Inicializa Objetos EXPORT_API int coreInitize(void); diff --git a/src/util.cpp b/src/util.cpp index 5d6dc76..d47f7d8 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -20,23 +20,7 @@ string Util::clrStringTostring(String^ strIn) return stlString; } - void DownloadProgressCallback(Object^ sender, - DownloadProgressChangedEventArgs^ e) - { - // Displays the operation identifier, and the transfer progress. - Console::WriteLine("{0} downloaded {1} of {2} bytes. {3} % complete...", - (String ^)e->UserState, - e->BytesReceived, - e->TotalBytesToReceive, - e->ProgressPercentage); - } - - void DownloadFileCallBack2(Object^ sender, AsyncCompletedEventArgs^ args) - { - cout<<"Terminou de baixar"<< endl; - - } - + bool Util::checkNet() { @@ -175,112 +159,6 @@ vector Util::localVersion() } -string Util::Download(DownloadProgressChangedEventHandler^ dpch ,string url, string fileName) -{ - try - { - myWebClient = gcnew WebClient(); - Uri^ uri = gcnew Uri(gcnew String(url.c_str())); - myWebClient->DownloadProgressChanged += dpch; - myWebClient->DownloadFileCompleted += gcnew AsyncCompletedEventHandler( DownloadFileCallBack2 ); - String^ outPath = gcnew String(("c:\\vlibras-libs\\update\\"+fileName).c_str()); - myWebClient->DownloadFileAsync(uri, outPath); - }catch (Exception^ e) - { - return "FALHA"; - } - - return "OK"; - } - - - - bool Util::saveNewXmlVersion(string playerVersion,string dictionaryVersion) - { - - XmlDocument^ xmlDocLocal; - XmlNodeList^ filesLocal; - vector updates; - try - { - xmlDocLocal = (gcnew XmlDocument()); - //xml version local - StreamReader^ readerLocal = gcnew StreamReader("c:\\vlibras-libs\\update\\updateVersion.xml"); - - String^ responseLocal = readerLocal->ReadToEnd(); - - xmlDocLocal->LoadXml(responseLocal); - - filesLocal = xmlDocLocal->GetElementsByTagName("version"); - - if(!playerVersion.empty()) - filesLocal[0]["playerVersion"]->InnerText = gcnew String(playerVersion.c_str()); - - if(!dictionaryVersion.empty()) - filesLocal[0]["dictionaryVersion"]->InnerText = gcnew String(dictionaryVersion.c_str()); - - - // Cleanup the streams and the response. - readerLocal->Close(); - - xmlDocLocal->Save("c:\\vlibras-libs\\update\\updateVersion.xml"); - }catch(Exception^ e) - { - - } - - return true; - } - - - bool Util::extractZip(string zipFile, string outPath) - { - try - { - String^ zipPath = gcnew String(zipFile.c_str()); - String^ extractPath = gcnew String(outPath.c_str()); - ZipFile::ExtractToDirectory(zipPath, extractPath); - - }catch(Exception^ e) - { - return false; - } - - return true; - } - -bool Util::backup() -{ - CHAR nome_atual[] = "c:\\vlibras-libs"; - // novo nome do diretório - CHAR nome_novo[] = "c:\\vlibras-libs-BK"; - - // renomear o diretório - if(MoveFile(nome_atual, nome_novo)){ - - } - else{ - return false; - } - return true; -} -bool Util::restore() -{ - CHAR nome_atual[] = "c:\\vlibras-libs-BK"; - // novo nome do diretório - CHAR nome_novo[] = "c:\\vlibras-libs"; - - // renomear o diretório - if(MoveFile(nome_atual, nome_novo)){ - return true; - } - else{ - return false; - //GetLastError() << endl; - } - return true; -} - diff --git a/update/include/checkVersion.h b/update/include/checkVersion.h new file mode 100644 index 0000000..2bdd393 --- /dev/null +++ b/update/include/checkVersion.h @@ -0,0 +1,53 @@ +//***************************************************************** +/* +VLibras: Verificação de atualização + + +Ezequiel Silva +ezequielsilva@lavid.ufpb.br +VLibras-Core +2015 +*/ +//***************************************************************** + +/** +* \file checkVersion.h +* \Ezequiel Silva +* \date Outubro 2015 +*/ + + + +#include +#include +#include +#include +#include + +#pragma comment(lib, "urlmon.lib") +using namespace std; + + class CheckVersion +{ + +private: + void checkLocal(); + void checkApi(); + void reset(); +public: + long playerVersion = -1; + long dictVersion = -1; + long localPlayerVersion = -1; + long localDictVersion = -1; + string playerVersionFull = ""; + string dictVersionFull = ""; + string playerUrl = ""; + string dictUrl = ""; + string dictCallVersion ="0.0.0_0.0.0"; + int vstatus = -1; + + CheckVersion(); + void checkRefresh(); + + +}; \ No newline at end of file diff --git a/update/include/janelaAtualizacao.h b/update/include/janelaAtualizacao.h index cf77593..309bd4f 100644 --- a/update/include/janelaAtualizacao.h +++ b/update/include/janelaAtualizacao.h @@ -1,3 +1,25 @@ +//***************************************************************** +/* +VLibras: Atualização + + +Ezequiel Silva +ezequielsilva@lavid.ufpb.br +VLibras-Core +2015 +*/ +//***************************************************************** + +/** +* \file checkVersion.h +* \Ezequiel Silva +* \date Outubro 2015 +*/ + +// ############### NÃO USADO ################### + + + #include #using diff --git a/update/src/checkVersion.cpp b/update/src/checkVersion.cpp new file mode 100644 index 0000000..0fccd07 --- /dev/null +++ b/update/src/checkVersion.cpp @@ -0,0 +1,182 @@ + + +#include "checkVersion.h" + +using namespace std; + + + + CheckVersion::CheckVersion() + { + //reset(); + } + + void CheckVersion::checkRefresh() + { + reset(); + checkLocal(); + checkApi(); + if(!(localDictVersion == -1 || dictVersion == -1 || localPlayerVersion == -1 || playerVersion == -1)) + { + vstatus = 0; + if(localDictVersion < dictVersion && localPlayerVersion < playerVersion) + vstatus=1; + else if(localPlayerVersion < playerVersion) + vstatus = 1; + else if(localDictVersion < dictVersion) + vstatus = 2; + } + else + vstatus = -1; + + } + + + + +void find_and_replace(string& source, string const& find, string const& replace) +{ + for(string::size_type i = 0; (i = source.find(find, i)) != string::npos;) + { + source.replace(i, find.length(), replace); + i += replace.length(); + } +} + + +void CheckVersion::checkLocal() +{ + + int result = 0; + string line; + ifstream myfile ("c:\\vlibras-libs\\update\\updateVersion.xml"); + + if (myfile.is_open()) + { + while ( getline(myfile,line) ) + { + if(strstr(line.c_str(),"")) + { + string version; + int ia = line.find("")+19; + int ib = line.find("")-23; + version = line.substr(ia,ib); + dictCallVersion = version; + find_and_replace(version,".",""); + find_and_replace(version,"_",""); + find_and_replace(version," ",""); + localDictVersion = atoi(version.c_str()); + } + else if(strstr(line.c_str(),"")) + { + string version; + int ia = line.find("")+15; + int ib = line.find("")-19; + version = line.substr(ia,ib); + find_and_replace(version,".",""); + find_and_replace(version,"_",""); + find_and_replace(version," ",""); + localPlayerVersion = atoi(version.c_str()); + } + + } + + myfile.close(); + + } + + + } + +void CheckVersion::checkApi() +{ + +cout << "dictCallVersion ====> " << dictCallVersion<< endl; +string url = "http://vlibras.lavid.ufpb.br/api/dicionario/"; +url.append(dictCallVersion); +url.append("?type=windows"); + HRESULT hr = URLDownloadToFile ( NULL, _T(url.c_str()), _T("c:\\vlibras-libs\\update\\netVersion.xml"), 0, NULL ); + if(SUCCEEDED(hr)){ + + string line; + ifstream myfile ("c:\\vlibras-libs\\update\\netVersion.xml"); + if (myfile.is_open()) + { + while ( getline(myfile,line) ) + { + if(strstr(line.c_str(),"")) + { + string version; + int ia = line.find("")+19; + int ib = line.find("")-23; + version = line.substr(ia,ib); + dictVersionFull = version; + find_and_replace(version,".",""); + find_and_replace(version,"_",""); + find_and_replace(version," ",""); + dictVersion = atoi(version.c_str()); + } + else if(strstr(line.c_str(),"")) + { + string version; + int ia = line.find("")+15; + int ib = line.find("")-19; + version = line.substr(ia,ib); + playerVersionFull = version; + find_and_replace(version,".",""); + find_and_replace(version,"_",""); + find_and_replace(version," ",""); + playerVersion = atoi(version.c_str()); + + } + else if(strstr(line.c_str(),"")) + { + string version; + int ia = line.find("")+11; + int ib = line.find("")-15; + version = line.substr(ia,ib); + playerUrl = version; + } + else if(strstr(line.c_str(),"")) + { + string version; + int ia = line.find("")+15; + int ib = line.find("")-19; + version = line.substr(ia,ib); + dictUrl = version; + } + } + myfile.close(); + } + + + } + +} + + +void CheckVersion::reset() + { + playerVersion = -1; + dictVersion = -1; + localPlayerVersion = -1; + localDictVersion = -1; + playerUrl = ""; + dictUrl = ""; + vstatus = -1; + } + +//return +// -1 se erro +//0 se não necessita de atualização +// 1 se tiver para player +// 2 se dicionario + + + + + + + + + diff --git a/update/src/util.cpp b/update/src/util.cpp index 329b24c..a879f53 100644 --- a/update/src/util.cpp +++ b/update/src/util.cpp @@ -108,7 +108,6 @@ vector Util::checkVersion(bool atualize) String^ playerVersion = files[0]["playerVersion"]->InnerText; String^ dictionaryVersion = files[0]["dictionaryVersion"]->InnerText; - MessageBox(0, "version local "+(gcnew String(localversion[1].c_str()))+" \n Server Version : "+playerVersion,"MessageBox caption", MB_OK); if(String::Compare( playerVersion, gcnew String(localversion[1].c_str()))) { updates.push_back("playerVersion"); -- libgit2 0.21.2