From 95e4b2e649cc7ccbd3293621c3f2f024259ac760 Mon Sep 17 00:00:00 2001 From: ezequiel Date: Mon, 5 Oct 2015 16:01:27 -0300 Subject: [PATCH] Adciona vlibras update e faz modificações --- Makefile | 17 +++++++++++------ icon/icon_vlibras.ico | Bin 370070 -> 0 bytes include/util.h | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ install/inno setup/user_install.iss | 38 +++++++++++++++++++++++++++++--------- install/inno setup/user_install2.iss | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ plugin/corePlugin.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- plugin/corePlugin.h | 17 ++++++++++++++--- plugin/testPlugin.cpp | 21 +++++++++++++++++---- src/util.cpp | 287 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ translate.log | 0 update/Makefile | 45 +++++++++++++++++++++++++++++++++++++++++++++ update/include/janelaAtualizacao.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ update/include/util.h | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ update/src/janelaAtualizacao.cpp | 151 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ update/src/util.cpp | 287 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ update/update-icon.ico | Bin 0 -> 99678 bytes update/vlibrasUpdate.cpp | 172 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 17 files changed, 1268 insertions(+), 24 deletions(-) create mode 100644 include/util.h create mode 100644 install/inno setup/user_install2.iss create mode 100644 src/util.cpp create mode 100644 translate.log create mode 100644 update/Makefile create mode 100644 update/include/janelaAtualizacao.h create mode 100644 update/include/util.h create mode 100644 update/src/janelaAtualizacao.cpp create mode 100644 update/src/util.cpp create mode 100644 update/update-icon.ico create mode 100644 update/vlibrasUpdate.cpp diff --git a/Makefile b/Makefile index 3bdf3f8..1beba91 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,14 @@ ############################## MAKEFILE VLIBRAS ############################ # # # Bruno Santos # -# brunosantos@lavid.ufpb.br # +# brunosantos@lavid.ufpb.br # +# Ezequiel Silva # +# ezequielsilva@lavid.ufpb.br # # # ############################################################################ # Includes -CFLAGS = -I C:\Python27\include -I include +CFLAGS = -I C:\Python27\include -I 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 @@ -17,11 +19,14 @@ CC = cl # Nome do arquivo de saída OUT = testLibras + + + # Arquivos de implementação -FILES = src\pyTradutor.cpp src\pyClip.cpp +FILES = src\pyTradutor.cpp src\pyClip.cpp src\util.cpp #Headers -INCLUDES = include\pyTradutor.h include\pyClip.h +INCLUDES = include\pyTradutor.h include\pyClip.h include\util.h CLEAN_OBJ = del -q *.obj @@ -29,13 +34,13 @@ HOME = %homepath% #Gera executável testLibras all: $(FILES) $(INCLUDES) src\testLibras.cpp - $(CC) -Fe$(OUT) -EHsc src\testLibras.cpp $(FILES) $(CFLAGS) $(LFLAGS) + $(CC) -Fe$(OUT) -clr src\testLibras.cpp $(FILES) $(CFLAGS) $(LFLAGS) $(CLEAN_OBJ) #Gera dll na arquitetura x86 plugin-x86: $(FILES) $(INCLUDES) IF NOT EXIST plugin\Plugin-x86 mkdir plugin\Plugin-x86 - $(CC) -Feplugin\Plugin-x86\CorePlugin -EHsc -LD plugin\corePlugin.cpp $(FILES) -I plugin\corePlugin.h $(CFLAGS) $(LFLAGS) + $(CC) -Feplugin\Plugin-x86\CorePlugin -LD plugin\corePlugin.cpp $(FILES) -I plugin\corePlugin.h -clr $(CFLAGS) $(LFLAGS) $(CLEAN_OBJ) #Gera dll na arquitetura x64 diff --git a/icon/icon_vlibras.ico b/icon/icon_vlibras.ico index ee9aefe..0632ae2 100644 Binary files a/icon/icon_vlibras.ico and b/icon/icon_vlibras.ico differ diff --git a/include/util.h b/include/util.h new file mode 100644 index 0000000..df1917f --- /dev/null +++ b/include/util.h @@ -0,0 +1,51 @@ +#using +#using +#using + +#include +#include +#include + + +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; + + + + + + + + public ref class Util { + + private: + static string clrStringTostring(String^ strIn); + static vector localVersion(void); + + public: + static bool down; + static WebClient^ myWebClient; + + 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 2f8d498..de87f19 100644 --- a/install/inno setup/user_install.iss +++ b/install/inno setup/user_install.iss @@ -1,13 +1,17 @@ ;################### INSTALADOR VLIBRAS WINDOWS ###################### ;# Bruno Santos # -;# brunosantos@lavid.ufpb.br # +;# brunosantos@lavid.ufpb.br # +;# Ezequiel Silva # +;# ezequielsilva@lavid.ufpb.br # ;##################################################################### #define MyAppName "VLibras" #define MyAppVersion "beta" #define MyAppPublisher "LAViD" #define MyAppURL "http://vlibrasplayer.lavid.ufpb.br" -#define MyAppExeName "Playerx86.exe" +#define MyAppExeName "VlibrasPlayer.exe" + + [Setup] AppId={{9AA2CD86-F136-47FA-9EFE-474057F0C45F} @@ -20,14 +24,16 @@ AppUpdatesURL={#MyAppURL} DefaultDirName={sd}\vlibras-libs DisableDirPage=yes DefaultGroupName={#MyAppName} +OutputBaseFilename=vlibras_desktop_win_2.0.0 DisableProgramGroupPage=yes -OutputDir="C:\Users\bruno\Desktop\output" -OutputBaseFilename=VLibras Installer -SetupIconFile="C:\Users\bruno\Desktop\user_install\icons\icon_vlibras.ico" +OutputDir="C:\Users\ezequiel\Desktop\vlibras_desktop_win_2.0.0" +SetupIconFile="C:\Users\ezequiel\Desktop\user_install\icons\icon_vlibras.ico" Compression=lzma SolidCompression=yes -WizardImageFile = "C:\Users\bruno\Desktop\user_install\icons\avatar.bmp" -WizardSmallImageFile = "C:\Users\bruno\Desktop\user_install\icons\small2.bmp" +WizardImageFile = "C:\Users\ezequiel\Desktop\user_install\icons\avatar.bmp" +WizardSmallImageFile = "C:\Users\ezequiel\Desktop\user_install\icons\player.bmp" + + [Languages] Name: "brazilianportuguese"; MessagesFile: "compiler:Languages\BrazilianPortuguese.isl" @@ -37,7 +43,12 @@ Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{ Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; OnlyBelowVersion: 0,6.1 [Files] -Source: "C:\Users\bruno\Desktop\user_install\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs +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 + + + [Icons] Name: "{group}\{#MyAppName}"; Filename: "{app}\Player\{#MyAppExeName}"; IconFilename: "{app}\icons\icon_vlibras.ico" @@ -47,5 +58,14 @@ 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: {sd}\vlibras-libs\required\user_install.bat; Flags: runhidden +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... + + + + + + diff --git a/install/inno setup/user_install2.iss b/install/inno setup/user_install2.iss new file mode 100644 index 0000000..5b1e38a --- /dev/null +++ b/install/inno setup/user_install2.iss @@ -0,0 +1,51 @@ +;################### INSTALADOR VLIBRAS WINDOWS ###################### +;# Bruno Santos # +;# brunosantos@lavid.ufpb.br # +;##################################################################### + +#define MyAppName "VLibras" +#define MyAppVersion "beta" +#define MyAppPublisher "LAViD" +#define MyAppURL "http://vlibrasplayer.lavid.ufpb.br" +#define MyAppExeName "Playerx86.exe" + +[Setup] +AppId={{84B73167-EF7F-42BB-9CCD-E1A8E2C53659} +AppName={#MyAppName} +AppVersion={#MyAppVersion} +AppPublisher={#MyAppPublisher} +AppPublisherURL={#MyAppURL} +AppSupportURL={#MyAppURL} +AppUpdatesURL={#MyAppURL} +DefaultDirName={pf}\vlibras-libs +DisableDirPage=yes +DefaultGroupName={#MyAppName} +DisableProgramGroupPage=yes +OutputDir="C:\Users\ezequiel\Desktop\output" +OutputBaseFilename=VLibras Installer +SetupIconFile="C:\Users\ezequiel\vlibras-libs\icons\icon_vlibras.ico" +Compression=lzma +SolidCompression=yes +WizardImageFile = "C:\Users\ezequiel\vlibras-libs\icons\avatar.bmp" +WizardSmallImageFile = "C:\Users\ezequiel\vlibras-libs\icons\small2.bmp" + +[Languages] +Name: "brazilianportuguese"; MessagesFile: "compiler:Languages\BrazilianPortuguese.isl" + +[Tasks] +Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}" +Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; OnlyBelowVersion: 0,6.1 + +[Files] +Source: "C:\vlibras-libs\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs + +[Icons] +Name: "{group}\{#MyAppName}"; Filename: "{app}\Player\{#MyAppExeName}"; IconFilename: "{app}\icons\icon_vlibras.ico" +Name: "{group}\{cm:ProgramOnTheWeb,{#MyAppName}}"; Filename: "{#MyAppURL}" +Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}" +Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\Player\{#MyAppExeName}"; Tasks: desktopicon; IconFilename: "{app}\icons\icon_vlibras.ico" +Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\{#MyAppName}"; Filename: "{app}\Player\{#MyAppExeName}"; Tasks: quicklaunchicon; IconFilename: "{app}\icons\icon_vlibras.ico" + +[Run] +Filename: {app}\vlibras-libs\required\user_install.bat; Flags: runhidden + diff --git a/plugin/corePlugin.cpp b/plugin/corePlugin.cpp index fb742b5..d79c9df 100644 --- a/plugin/corePlugin.cpp +++ b/plugin/corePlugin.cpp @@ -5,18 +5,27 @@ #define EXPORT_API __declspec(dllimport) #endif + #include "corePlugin.h" + + extern "C" { + + + + + EXPORT_API int coreInitialize() { //Objeto usado para traduzir tradutor = new PyTradutor(); + check =0; //Objeto usado para copiar texto da área de transferência clipboard.bdragOn(); - + return 1; } @@ -24,11 +33,58 @@ { //Copia área de transferência para input char *input = clipboard.clip(); - + //Retorna a tradução do texto para glosa return tradutor->convertStringToGlosa(input); } + + EXPORT_API int coreUpdateInstall_player() + { + System::Diagnostics::Process::Start("C:\\vlibras-libs\\update\\vlibras-up.exe"); + return 1; + } + + + EXPORT_API int coreUpdateInstall_dict() + { + System::Diagnostics::Process::Start("C:\\vlibras-libs\\update\\vlibras-up.exe"); + return 1; + } + + + + EXPORT_API int coreUpdateCheck() + { + + + 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; + } + EXPORT_API int coreFinalize() { clipboard.bdragOff(); diff --git a/plugin/corePlugin.h b/plugin/corePlugin.h index 847ff7e..9ff7ae6 100644 --- a/plugin/corePlugin.h +++ b/plugin/corePlugin.h @@ -16,10 +16,11 @@ VLibras-Core #ifndef _COREPLUGIN_H #define _COREPLUGIN_H -#include + #include "pyClip.h" #include "pyTradutor.h" #include +#include "Util.h" using namespace std; @@ -27,18 +28,28 @@ extern "C" { //Usado para traduzir português para glosa PyTradutor *tradutor; - + int check; //Usado para copiar texto da área de transferência PyClip clipboard; + //Inicializa Objetos EXPORT_API int coreInitize(void); //Faz tradução de Português para glosa EXPORT_API char* coreExecute(void); - + + //faz atualização player + EXPORT_API int coreUpdateInstall_player(void); + + //faz atualização dicionário + EXPORT_API int coreUpdateInstall_dict(void); + //check atualização + EXPORT_API int coreUpdateCheck(void); //Libera Objetos utilizados EXPORT_API int coreFinalize(void); + + } #endif \ No newline at end of file diff --git a/plugin/testPlugin.cpp b/plugin/testPlugin.cpp index aaed4ce..834ba48 100644 --- a/plugin/testPlugin.cpp +++ b/plugin/testPlugin.cpp @@ -12,6 +12,8 @@ metodo2 execute; typedef int (WINAPI*metodo3)(); metodo3 finalize; +typedef int (WINAPI*metodo4)(); +metodo4 update; int main(int argc, char *argv[]) { @@ -27,19 +29,30 @@ int main(int argc, char *argv[]) initialize=(metodo1)GetProcAddress((HMODULE)hDLL, "coreInitialize"); execute=(metodo2)GetProcAddress((HMODULE)hDLL, "coreExecute"); finalize=(metodo3)GetProcAddress((HMODULE)hDLL, "coreFinalize"); + update=(metodo4)GetProcAddress((HMODULE)hDLL, "coreUpdate"); //Executa coreInitialize int init = initialize(); cout <<"return initialize: " << init < +#include "util.h" + + + +Util::Util(){ + //downloading = true; + //downloading = down; +} + +string Util::clrStringTostring(String^ strIn) +{ + + char cStr[256]; + + + sprintf(cStr, "%s", strIn); + string stlString(cStr); + + 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() +{ + + try + { + + WebRequest^ request = WebRequest::Create( "http://vlibras.lavid.ufpb.br" ); + + // If required by the server, set the credentials. + //request->Credentials = CredentialCache::DefaultCredentials; + + // Get the response. + HttpWebResponse^ response = dynamic_cast(request->GetResponse()); + + if (response->StatusDescription == "OK"){ + + return true; + } + return false; + response->Close(); + } + catch ( WebException^ e ) + { + return false; + } + +} + + +vector Util::checkVersion(bool atualize) +{ + XmlDocument^ xmlDoc; + XmlNodeList^ files; + XmlDocument^ xmlDocLocal; + XmlNodeList^ filesLocal; + vector updates; + vector localversion = localVersion(); + try + { + xmlDoc = (gcnew XmlDocument()); + xmlDocLocal = (gcnew XmlDocument()); + + + string url = "http://vlibras.lavid.ufpb.br/api/dicionario/"+localversion[3]+"?type=windows"; + WebRequest^ request = WebRequest::Create( gcnew String(url.c_str())); + // If required by the server, set the credentials. + request->Credentials = CredentialCache::DefaultCredentials; + // Get the response. + HttpWebResponse^ response = dynamic_cast(request->GetResponse()); + if (!(response->StatusDescription == "OK")) + goto erro; + // Get the stream containing content returned by the server. + Stream^ dataStream = response->GetResponseStream(); + // Open the stream using a StreamReader for easy access. + StreamReader^ reader = gcnew StreamReader( dataStream ); + // Read the content. + String^ responseFromServer = reader->ReadToEnd(); + xmlDoc->LoadXml(responseFromServer); + files = xmlDoc->GetElementsByTagName("version"); + + long numitems = files->Count; + + + + //for (int i=0;i0) + { + String^ playerVersion = files[0]["playerVersion"]->InnerText; + String^ dictionaryVersion = files[0]["dictionaryVersion"]->InnerText; + + if(String::Compare( playerVersion, gcnew String(localversion[1].c_str()))) + { + updates.push_back("playerVersion"); + updates.push_back(clrStringTostring(playerVersion)); + updates.push_back(clrStringTostring(files[0]["playerUrl"]->InnerText)); + } + if(String::Compare(dictionaryVersion,gcnew String(localversion[3].c_str()))) + { + updates.push_back("dictionaryVersion"); + updates.push_back(clrStringTostring(dictionaryVersion)); + updates.push_back(clrStringTostring(files[0]["dictionaryUrl"]->InnerText)); + } + + //if(atualize) + //saveNewXmlVersion(playerVersion,dictionaryVersion); + + } + + erro: + // Cleanup the streams and the response. + reader->Close(); + dataStream->Close(); + }catch(Exception^ e) + { + updates.push_back("faill"); + return updates; + } + + return updates; +} + + +vector Util::localVersion() +{ + 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"); + + updates.push_back("playerVersion"); + String^ playerVersion = filesLocal[0]["playerVersion"]->InnerText; + updates.push_back(clrStringTostring(playerVersion)); + updates.push_back("dictionaryVersion"); + String^ dictionaryVersion = filesLocal[0]["dictionaryVersion"]->InnerText; + updates.push_back(clrStringTostring(dictionaryVersion)); + + // Cleanup the streams and the response. + readerLocal->Close(); + }catch(Exception^ e) + { + return updates; + } + + return updates; +} + + +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; +} + + + + + \ No newline at end of file diff --git a/translate.log b/translate.log new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/translate.log diff --git a/update/Makefile b/update/Makefile new file mode 100644 index 0000000..43af671 --- /dev/null +++ b/update/Makefile @@ -0,0 +1,45 @@ +############################## MAKEFILE VLIBRAS ############################ +# # +# Bruno Santos # +# brunosantos@lavid.ufpb.br # +# Ezequiel Silva # +# ezequielsilva@lavid.ufpb.br # # +# # +############################################################################ + +# Includes +CFLAGS = -I include + +# Link com as libs utilizadas +#LFLAGS = -link C:\Python27\libs\python27.lib + +# Compilador Nativo +CC = cl + +# Nome do arquivo de saída +OUT = vlibras-up + +# Arquivos de implementação +FILES = src\util.cpp src\janelaAtualizacao.cpp + +#Headers +INCLUDES = include\util.h include\janelaAtualizacao.h + +CLEAN_OBJ = del -q *.obj + +HOME = %homepath% + +#Gera executável testLibras +all: $(FILES) $(INCLUDES) + $(CC) -Fe$(OUT) -clr vlibrasUpdate.cpp $(FILES) $(CFLAGS) + $(CLEAN_OBJ) + + + + +#Limpa arquivos objetos e executáveis criados +clean: + del -q *.exe *.obj + rm -rf doc + + diff --git a/update/include/janelaAtualizacao.h b/update/include/janelaAtualizacao.h new file mode 100644 index 0000000..cf77593 --- /dev/null +++ b/update/include/janelaAtualizacao.h @@ -0,0 +1,44 @@ +#include + +#using +#using +#using + + +using namespace System::Windows::Forms; +using namespace System; +using namespace System::Drawing; +using namespace System::ComponentModel; +using namespace std; + +public ref class JanelaAtualizacao : public Form +{ + private: + + bool downloading; + RichTextBox^ richTextBox1; + Label^ lbInformacao; + Label^ topo; + int vez=0; + Bitmap^ animatedImage; + String^ informacao; + void btOKevent(Object^ sender, EventArgs^ e); + void XFormClosing(Object^ sender, FormClosingEventArgs^ e); + + public: + static ProgressBar^ progressBar1; + static Label^ lbInfDownload; + Button^ btOK; + JanelaAtualizacao(); + + void initializeComponent(); + void setInfoWhite(String^ info); + void setInfoGreen(String^ info); + void setInfoRed(String^ info); + void start(); + void EnableButton(); + + + +}; + diff --git a/update/include/util.h b/update/include/util.h new file mode 100644 index 0000000..df1917f --- /dev/null +++ b/update/include/util.h @@ -0,0 +1,51 @@ +#using +#using +#using + +#include +#include +#include + + +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; + + + + + + + + public ref class Util { + + private: + static string clrStringTostring(String^ strIn); + static vector localVersion(void); + + public: + static bool down; + static WebClient^ myWebClient; + + 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/update/src/janelaAtualizacao.cpp b/update/src/janelaAtualizacao.cpp new file mode 100644 index 0000000..7fa91e6 --- /dev/null +++ b/update/src/janelaAtualizacao.cpp @@ -0,0 +1,151 @@ +#include "janelaAtualizacao.h" +#include "Util.h" + + +JanelaAtualizacao::JanelaAtualizacao() +{ + initializeComponent(); +} + +void JanelaAtualizacao::initializeComponent() +{ + + this->downloading = true; + this->Size = System::Drawing::Size(500, 250); + this->progressBar1 = (gcnew ProgressBar()); + this->btOK = (gcnew Button()); + this->lbInfDownload = (gcnew Label()); + this->lbInformacao = (gcnew Label()); + this->Name = "Vlibras-Desktop-Update"; + this->Text = "Atualização - Vlibras-Desktop"; + this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedDialog; + this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen; + //this->ControlBox = false; + this->MaximizeBox = false; + this->BackColor = Drawing::Color::White; + //this->MinimizeBox = false; + //this->BackgroundImage = Image::FromFile("c:\\vlibras-libs\\image\\background.png"); + //this->Opacity = 0.97; + Drawing::Icon^ IC = gcnew Drawing::Icon("c:\\vlibras-libs\\icons\\icon_vlibras.ico"); + this->Icon = IC; + this->SuspendLayout(); + //this->FormBorderStyle = ::FormBorderStyle::None; + this->FormClosing += gcnew FormClosingEventHandler(this, &JanelaAtualizacao::XFormClosing); + + // progressBar1 + // + this->progressBar1->Location = Point(7, 85); + this->progressBar1->Name = "progressBar1"; + this->progressBar1->Size = System::Drawing::Size(470, 30); + //this->progressBar1->TabIndex = 0; + this->progressBar1->Minimum = 0; + this->progressBar1->Maximum = 100; + //this->progressBar1->Style = ProgressBarStyle::Marquee; + //progressBar1->Visible = false; + //progressBar1->Enabled = false; + // + + // + this->lbInformacao->Location = Point(7, 15); + this->lbInformacao->Name = "label"; + this->lbInformacao->Size = System::Drawing::Size(470, 23); + this->lbInformacao->BackColor = Drawing::Color::Transparent; + //this->lbInformacao->ForeColor=Drawing::Color::White; + + // + this->lbInfDownload->Location = Point(7, 120); + this->lbInfDownload->Name = "labelDownload"; + this->lbInfDownload->Size = System::Drawing::Size(470, 23); + this->lbInfDownload->BackColor = Drawing::Color::Transparent; + //this->lbInfDownload->Font = gcnew System::Drawing::Font("Arial", 12); + //this->lbInfDownload->ForeColor=Drawing::Color::White; + + + // btOK + // + + this->btOK->Location = Point(390, this->Bottom-80); + this->btOK->Name = "btOK"; + this->btOK->Size = System::Drawing::Size(80, 30); + this->btOK->TabIndex = 1; + this->btOK->Text = "OK"; + this->btOK->UseVisualStyleBackColor = true; + this->btOK->Click += gcnew EventHandler(this, &JanelaAtualizacao::btOKevent); + //this->btOK + // + + // + //this->Controls->Add(this->topo); + this->Controls->Add(this->lbInformacao); + this->Controls->Add(this->lbInfDownload); + this->Controls->Add(this->progressBar1); + this->Controls->Add(this->btOK); + this->btOK->Enabled = false; + //this->Controls->Add(this->richTextBox1); + + //this->ResumeLayout(false); + +} + +void JanelaAtualizacao::setInfoWhite(String^ info) +{ + this->lbInformacao->Location = Point(7, 20); + this->lbInformacao->Font = gcnew System::Drawing::Font("Serif", 12); + this->lbInformacao->Text = info; + //this->lbInformacao->ForeColor=Drawing::Color::White; + this->lbInformacao->TextAlign = ContentAlignment::MiddleCenter; + +} + +void JanelaAtualizacao::setInfoGreen(String^ info) +{ + this->lbInformacao->Location = Point(7, 75); + this->lbInformacao->Font = gcnew System::Drawing::Font("Arial", 15); + this->lbInformacao->Text = info; + this->lbInformacao->ForeColor=Drawing::Color::Green; + this->lbInformacao->TextAlign = ContentAlignment::MiddleCenter; + +} +void JanelaAtualizacao::setInfoRed(String^ info) +{ + this->lbInformacao->Location = Point(7, 75); + this->lbInformacao->Font = gcnew System::Drawing::Font("Arial", 15); + this->lbInformacao->Text = info; + this->lbInformacao->ForeColor=Drawing::Color::Red; + this->lbInformacao->TextAlign = ContentAlignment::MiddleCenter; + +} + + + + +void JanelaAtualizacao::btOKevent(Object^ sender, EventArgs^ e) +{ + + this->Close(); + +} + + + +void JanelaAtualizacao::start() +{ + +} + + +void JanelaAtualizacao::EnableButton() +{ + btOK->Enabled = true; +} + + +void JanelaAtualizacao::XFormClosing(Object^ sender, FormClosingEventArgs^ e) +{ + +} + + + + + \ No newline at end of file diff --git a/update/src/util.cpp b/update/src/util.cpp new file mode 100644 index 0000000..329b24c --- /dev/null +++ b/update/src/util.cpp @@ -0,0 +1,287 @@ +#include +#include "util.h" + + + +Util::Util(){ + //downloading = true; + //downloading = down; +} + +string Util::clrStringTostring(String^ strIn) +{ + + char cStr[256]; + + + sprintf(cStr, "%s", strIn); + string stlString(cStr); + + 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() +{ + + try + { + + WebRequest^ request = WebRequest::Create( "http://vlibras.lavid.ufpb.br" ); + + // If required by the server, set the credentials. + //request->Credentials = CredentialCache::DefaultCredentials; + + // Get the response. + HttpWebResponse^ response = dynamic_cast(request->GetResponse()); + + if (response->StatusDescription == "OK"){ + + return true; + } + return false; + response->Close(); + } + catch ( WebException^ e ) + { + return false; + } + +} + + +vector Util::checkVersion(bool atualize) +{ + XmlDocument^ xmlDoc; + XmlNodeList^ files; + XmlDocument^ xmlDocLocal; + XmlNodeList^ filesLocal; + vector updates; + vector localversion = localVersion(); + try + { + xmlDoc = (gcnew XmlDocument()); + xmlDocLocal = (gcnew XmlDocument()); + + + string url = "http://vlibras.lavid.ufpb.br/api/dicionario/"+localversion[3]+"?type=windows"; + WebRequest^ request = WebRequest::Create( gcnew String(url.c_str())); + // If required by the server, set the credentials. + request->Credentials = CredentialCache::DefaultCredentials; + // Get the response. + HttpWebResponse^ response = dynamic_cast(request->GetResponse()); + if (!(response->StatusDescription == "OK")) + goto erro; + // Get the stream containing content returned by the server. + Stream^ dataStream = response->GetResponseStream(); + // Open the stream using a StreamReader for easy access. + StreamReader^ reader = gcnew StreamReader( dataStream ); + // Read the content. + String^ responseFromServer = reader->ReadToEnd(); + xmlDoc->LoadXml(responseFromServer); + files = xmlDoc->GetElementsByTagName("version"); + + long numitems = files->Count; + + + + //for (int i=0;i0) + { + 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"); + updates.push_back(clrStringTostring(playerVersion)); + updates.push_back(clrStringTostring(files[0]["playerUrl"]->InnerText)); + } + if(String::Compare(dictionaryVersion,gcnew String(localversion[3].c_str()))) + { + updates.push_back("dictionaryVersion"); + updates.push_back(clrStringTostring(dictionaryVersion)); + updates.push_back(clrStringTostring(files[0]["dictionaryUrl"]->InnerText)); + } + + //if(atualize) + //saveNewXmlVersion(playerVersion,dictionaryVersion); + + } + + erro: + // Cleanup the streams and the response. + reader->Close(); + dataStream->Close(); + }catch(Exception^ e) + { + return updates; + } + + return updates; +} + + +vector Util::localVersion() +{ + 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"); + + updates.push_back("playerVersion"); + String^ playerVersion = filesLocal[0]["playerVersion"]->InnerText; + updates.push_back(clrStringTostring(playerVersion)); + updates.push_back("dictionaryVersion"); + String^ dictionaryVersion = filesLocal[0]["dictionaryVersion"]->InnerText; + updates.push_back(clrStringTostring(dictionaryVersion)); + + // Cleanup the streams and the response. + readerLocal->Close(); + }catch(Exception^ e) + { + return updates; + } + + return updates; +} + + +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; +} + + + + + \ No newline at end of file diff --git a/update/update-icon.ico b/update/update-icon.ico new file mode 100644 index 0000000..5dbdea4 Binary files /dev/null and b/update/update-icon.ico differ diff --git a/update/vlibrasUpdate.cpp b/update/vlibrasUpdate.cpp new file mode 100644 index 0000000..a8670aa --- /dev/null +++ b/update/vlibrasUpdate.cpp @@ -0,0 +1,172 @@ + +#include +#include "util.h" +#include "janelaAtualizacao.h" +#include + +using namespace std; +using namespace System::Threading; +using namespace System::Windows::Forms; + +void atualizarProgresbar(Object^ sender, DownloadProgressChangedEventArgs^ e){ + + JanelaAtualizacao::progressBar1->Value= e->ProgressPercentage; + int kbr = e->BytesReceived/1024; + int kbtotal = e->TotalBytesToReceive/1024; + JanelaAtualizacao::lbInfDownload->Text = gcnew String(kbr+" kb ("+kbr/1024+" MB) Baixado de "+kbtotal+" kb ("+kbtotal/1024+" MB) | "+ e->ProgressPercentage+"%"); + + +} + + +public ref class UpdateBack +{ + JanelaAtualizacao^ j; + bool isSilence; + String^ playerVersion; + String^ dictionaryVersion; + +public: + UpdateBack(JanelaAtualizacao^ jan,bool __isSilence) + { + j = jan; + isSilence = __isSilence; + } + void start() + { + j->setInfoWhite("Estabelecendo conexão com o servidor..."); + //JanelaAtualizacao::progressBar1->Style = ProgressBarStyle::Marquee; + + + if(Util::checkNet()) + { + j->setInfoWhite("Verificando versão..."); + + vector versions = Util::checkVersion(true); + if(versions.size()>2) + { + + switch (versions.size()) + { + case 3: + if(versions[0]=="playerVersion") + { + installPlayer(versions[2],versions[1]); + } + else if(versions[0]=="dictionaryVersion") + { + installDicionario(versions[2],versions[1]); + + } + break; + case 6: + // if(versions[3]=="dictionaryVersion") + // { + // installDicionario(versions[5],versions[4]); + // //Util::extractZip() + // } + if(versions[0]=="playerVersion") + { + installPlayer(versions[2],versions[1]); + } + + break; + } + + } + else + { + JanelaAtualizacao::progressBar1->Visible = false; + j->setInfoGreen("Você já está com a versão mais atualizada!"); + j->EnableButton(); + } + + }else + { + JanelaAtualizacao::progressBar1->Visible = false; + j->setInfoRed("Não foi possível estabelecer conexão com o servidor!"); + + } + + if(isSilence) + j->Close(); + j->EnableButton(); + + } + + void installDicionario(string url, string version) + { + //JanelaAtualizacao::progressBar1->Style = ProgressBarStyle::Continuous; + //JanelaAtualizacao::progressBar1->Value=0; + Util::Download(gcnew DownloadProgressChangedEventHandler(atualizarProgresbar),url,"vlibrasDicionario.zip"); + j->setInfoWhite("Baixando nova versão do dicionário VLibras "); + while(JanelaAtualizacao::progressBar1->Value<100); + + j->setInfoWhite("Extraindo arquivos..."); + + //Sleep(3000); + Util::extractZip("C:\\vlibras-libs\\update\\vlibrasDicionario.zip","C:\\vlibras-libs\\Player\\VLibrasPlayer_Data\\Bundles"); + JanelaAtualizacao::progressBar1->Visible = false; + j->setInfoGreen("Atualização feita com sucesso!"); + Util::saveNewXmlVersion("",version); + j->EnableButton(); + } + + void installPlayer(string url, string version) + { + //j->EnableButton(); + //JanelaAtualizacao::progressBar1->Style = ProgressBarStyle::Continuous; + //JanelaAtualizacao::progressBar1->Value=0; + Util::Download(gcnew DownloadProgressChangedEventHandler(atualizarProgresbar),url,"vlibrasInstaller.exe"); + j->setInfoWhite("Baixando nova versão do Vlibras..."); + while(JanelaAtualizacao::progressBar1->Value<100); + + + + String^ installer = gcnew String("C:\\vlibras-libs\\update\\"); + installer+="vlibrasInstaller.exe"; + //Process::Start(installer); + System::Diagnostics::Process^ vlibrasinstall = gcnew System::Diagnostics::Process(); + vlibrasinstall->StartInfo->FileName = installer; + vlibrasinstall->StartInfo->Arguments = " /SILENT /SUPPRESSMSGBOXES /NORESTART "; + vlibrasinstall->Start(); + Util::saveNewXmlVersion(version,""); + j->Close(); + + } +}; + +[STAThread] +int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow) +{ + UpdateBack^ updateBack; + JanelaAtualizacao^ updateView = gcnew JanelaAtualizacao(); + + if(__argv[1] != NULL) + { + char* silen = "silence"; + if(*__argv[1] == *silen) + updateBack = gcnew UpdateBack(updateView,true); + else + updateBack = gcnew UpdateBack(updateView,false); + } + else + updateBack = gcnew UpdateBack(updateView,false); + + Application::EnableVisualStyles(); + + //Thread^ t2 = gcnew Thread(gcnew ThreadStart(updateView, &JanelaAtualizacao::start)); + //t2->Start(); + + Thread^ t3 = gcnew Thread(gcnew ThreadStart(updateBack, &UpdateBack::start)); + t3->Start(); + + + updateView->ShowDialog(); + t3->Abort(); + + //Application::Run(updateView); + + return 0; + } + -- libgit2 0.21.2