Commit 8e705e33398792fd08d1564aa113e8e97c2673e0
1 parent
74d4a889
Exists in
master
Adiciona pasta update
Showing
12 changed files
with
935 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,35 @@ |
1 | +############################## MAKEFILE VLIBRAS ############################ | |
2 | +# # | |
3 | +# Ezequiel Silva # | |
4 | +# ezequielsilva@lavid.ufpb.br # # | |
5 | +# # | |
6 | +############################################################################ | |
7 | + | |
8 | + | |
9 | +# Compilador Nativo | |
10 | +CC = cl | |
11 | + | |
12 | +OUTPLAYER = vlibrasPlayerUp | |
13 | +OUTDICT = vlibrasDictUp | |
14 | +OUTWRITE = writeSucess | |
15 | + | |
16 | + | |
17 | + | |
18 | +CLEAN_OBJ = del -q *.obj | |
19 | + | |
20 | + | |
21 | +#Gera executável | |
22 | +all: | |
23 | + | |
24 | + $(CC) -Fe$(OUTPLAYER) -EHsc vlibrasPlayerInstall.cpp | |
25 | + $(CC) -Fe$(OUTDICT) -EHsc vlibrasDictInstall.cpp | |
26 | + $(CC) -Fe$(OUTWRITE) -EHsc writeSucessInstall.cpp | |
27 | + $(CLEAN_OBJ) | |
28 | + | |
29 | + | |
30 | +#Limpa arquivos objetos e executáveis criados | |
31 | +clean: | |
32 | + del -q *.exe *.obj | |
33 | + rm -rf doc | |
34 | + | |
35 | + | ... | ... |
... | ... | @@ -0,0 +1,31 @@ |
1 | +//***************************************************************** | |
2 | +/* | |
3 | + | |
4 | +Copyright (c) 2015 Ezequiel Silva | |
5 | +VLibras-Core group at LAViD, Federal University of Paraiba | |
6 | +*/ | |
7 | +//***************************************************************** | |
8 | + | |
9 | +/** | |
10 | +* \file pyVlibrasUpdate.h | |
11 | +* \authors Ezequiel Silva | |
12 | +* \date Setembro 2015 | |
13 | +*/ | |
14 | +#ifndef _PHVLIBRASUPDATE_H | |
15 | +#define _PHVLIBRASUPDATE_H | |
16 | + | |
17 | +#include <windows.h> | |
18 | + | |
19 | +/** \brief Classe para execução do Vlibras Update. | |
20 | +* | |
21 | +*/ | |
22 | +class PyVlibrasUpdate | |
23 | +{ | |
24 | + | |
25 | + public: | |
26 | + int install(char* strFunct, char* strstrParams); | |
27 | + void checkExe(char* strFunct, char* strstrParams); | |
28 | + | |
29 | +}; | |
30 | + | |
31 | +#endif | |
0 | 32 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,103 @@ |
1 | + | |
2 | +/** | |
3 | +* \file pyVlibrasUpdate.cpp | |
4 | +* \authors Ezequiel Silva | |
5 | +* \date outubro 2015 | |
6 | +*/ | |
7 | + | |
8 | +#include "pyVlibrasUpdate.h" | |
9 | + | |
10 | + | |
11 | +void PyVlibrasUpdate::checkExe(char* strFunct, char* strstrParams) | |
12 | +{ | |
13 | + | |
14 | + STARTUPINFO StartupInfo; | |
15 | + PROCESS_INFORMATION ProcessInfo; | |
16 | + char Args[4096]; | |
17 | + char *pEnvCMD = NULL; | |
18 | + char *pDefaultCMD = "CMD.EXE"; | |
19 | + ULONG rc; | |
20 | + | |
21 | + memset(&StartupInfo, 0, sizeof(StartupInfo)); | |
22 | + StartupInfo.cb = sizeof(STARTUPINFO); | |
23 | + StartupInfo.dwFlags = STARTF_USESHOWWINDOW; | |
24 | + StartupInfo.wShowWindow = SW_HIDE; | |
25 | + | |
26 | + Args[0] = 0; | |
27 | + | |
28 | + pEnvCMD = getenv("COMSPEC"); | |
29 | + | |
30 | + if(pEnvCMD){ | |
31 | + | |
32 | + strcpy(Args, pEnvCMD); | |
33 | + } | |
34 | + else{ | |
35 | + strcpy(Args, pDefaultCMD); | |
36 | + } | |
37 | + | |
38 | + // "/c" option - Do the command then terminate the command window | |
39 | + strcat(Args, " /c "); | |
40 | + //the application you would like to run from the command window | |
41 | + strcat(Args, strFunct); | |
42 | + strcat(Args, " "); | |
43 | + //the parameters passed to the application being run from the command window. | |
44 | + strcat(Args, strstrParams); | |
45 | + | |
46 | + if (!CreateProcess( NULL, Args, NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, &StartupInfo, &ProcessInfo)) | |
47 | + { | |
48 | + return; | |
49 | + } | |
50 | + | |
51 | + WaitForSingleObject(ProcessInfo.hProcess, INFINITE); | |
52 | + if(!GetExitCodeProcess(ProcessInfo.hProcess, &rc)) | |
53 | + rc = 0; | |
54 | + | |
55 | + CloseHandle(ProcessInfo.hThread); | |
56 | + CloseHandle(ProcessInfo.hProcess); | |
57 | + | |
58 | + | |
59 | +} | |
60 | + | |
61 | +int PyVlibrasUpdate::install(char* strFunct, char* strstrParams) | |
62 | +{ | |
63 | + | |
64 | + STARTUPINFO StartupInfo; | |
65 | + PROCESS_INFORMATION ProcessInfo; | |
66 | + char Args[4096]; | |
67 | + char *pEnvCMD = NULL; | |
68 | + char *pDefaultCMD = "CMD.EXE"; | |
69 | + | |
70 | + memset(&StartupInfo, 0, sizeof(StartupInfo)); | |
71 | + StartupInfo.cb = sizeof(STARTUPINFO); | |
72 | + StartupInfo.dwFlags = STARTF_USESHOWWINDOW; | |
73 | + StartupInfo.wShowWindow = SW_HIDE; | |
74 | + | |
75 | + Args[0] = 0; | |
76 | + | |
77 | + pEnvCMD = getenv("COMSPEC"); | |
78 | + | |
79 | + if(pEnvCMD){ | |
80 | + | |
81 | + strcpy(Args, pEnvCMD); | |
82 | + } | |
83 | + else{ | |
84 | + strcpy(Args, pDefaultCMD); | |
85 | + } | |
86 | + | |
87 | + // "/c" option - Do the command then terminate the command window | |
88 | + strcat(Args, " /c "); | |
89 | + //the application you would like to run from the command window | |
90 | + strcat(Args, strFunct); | |
91 | + strcat(Args, " "); | |
92 | + //the parameters passed to the application being run from the command window. | |
93 | + strcat(Args, strstrParams); | |
94 | + | |
95 | + if (!CreateProcess( NULL, Args, NULL, NULL, FALSE,CREATE_NEW_CONSOLE, NULL, NULL, &StartupInfo, &ProcessInfo)) | |
96 | + { | |
97 | + return -1; | |
98 | + } | |
99 | + | |
100 | + return -1; | |
101 | + | |
102 | +} | |
103 | + | ... | ... |
... | ... | @@ -0,0 +1,87 @@ |
1 | +#!/usr/bin/env python | |
2 | +# -*- coding: utf-8 -*- | |
3 | +import wx | |
4 | +from urllib2 import URLError | |
5 | +from urllib2 import HTTPError | |
6 | +import urllib2,os | |
7 | +import random | |
8 | +import time | |
9 | +from wx.lib.pubsub import pub | |
10 | +from threading import Thread | |
11 | + | |
12 | + | |
13 | + | |
14 | +class DownloadFile(): | |
15 | + | |
16 | + def __init__(self,url,nameFile): | |
17 | + self.url = url | |
18 | + self.nameFile = nameFile | |
19 | + self.downloading = True | |
20 | + | |
21 | + def start(self): | |
22 | + | |
23 | + file_name = self.nameFile | |
24 | + try: | |
25 | + u = urllib2.urlopen(self.url) | |
26 | + f = open(file_name, 'wb') | |
27 | + meta = u.info() | |
28 | + file_size = int(meta.getheaders("Content-Length")[0]) | |
29 | + | |
30 | + except: | |
31 | + | |
32 | + return False | |
33 | + | |
34 | + block_sz = 8192 | |
35 | + while self.downloading: | |
36 | + buffer = u.read(block_sz) | |
37 | + if not buffer: | |
38 | + self.downloading = False | |
39 | + f.write(buffer) | |
40 | + | |
41 | + return True | |
42 | + | |
43 | + | |
44 | + | |
45 | +class DownloadFile2(Thread): | |
46 | + | |
47 | + def __init__(self,url,nameFile): | |
48 | + self.url = url | |
49 | + self.nameFile = nameFile | |
50 | + self.downloading = True | |
51 | + Thread.__init__(self) | |
52 | + | |
53 | + | |
54 | + def stop(self): | |
55 | + self.downloading = False | |
56 | + | |
57 | + | |
58 | + def run(self): | |
59 | + | |
60 | + file_name = self.nameFile | |
61 | + try: | |
62 | + u = urllib2.urlopen(self.url) | |
63 | + f = open(file_name, 'wb') | |
64 | + meta = u.info() | |
65 | + file_size = int(meta.getheaders("Content-Length")[0]) | |
66 | + | |
67 | + except : | |
68 | + wx.CallAfter(pub.sendMessage, "erroDeConexao", msg="Falha na conexao") | |
69 | + self.downloading = False; | |
70 | + return False | |
71 | + | |
72 | + | |
73 | + file_size_dl = 0 | |
74 | + block_sz = 8192 | |
75 | + while self.downloading: | |
76 | + buffer = u.read(block_sz) | |
77 | + if not buffer: | |
78 | + break | |
79 | + | |
80 | + file_size_dl += len(buffer) | |
81 | + f.write(buffer) | |
82 | + status = r"%10d [%3.2f%%]" % (file_size_dl, file_size_dl * 100. / file_size) | |
83 | + status = status + chr(8)*(len(status)+1) | |
84 | + | |
85 | + wx.CallAfter(pub.sendMessage, "updateProgress", msg=(file_size_dl * 100. / file_size)) | |
86 | + if (file_size_dl * 100. / file_size) >=100: | |
87 | + wx.CallAfter(pub.sendMessage, "downloadSucess", msg="Download realizado") | ... | ... |
... | ... | @@ -0,0 +1,146 @@ |
1 | +import os.path | |
2 | +import json, zipfile, subprocess,urllib | |
3 | +from os import popen | |
4 | +import sys | |
5 | + | |
6 | +PATH_RESOURCE = 'c:/vlibras-libs/update/' | |
7 | +DICTIONARY_EXTRACT_PATH = 'C:/vlibras-libs/Player/VLibrasPlayer_Data/Bundles' | |
8 | +DICTIONARY_ZIP_PARH = PATH_RESOURCE+'download/vlibras_dicionario.zip' | |
9 | +TXT_DICT_VERSION = PATH_RESOURCE+'version/dictVersion.txt' | |
10 | +TXT_PLAYER_VERSION = PATH_RESOURCE+'version/playerVersion.txt' | |
11 | +JSON_API_VERSION = PATH_RESOURCE+'download/versionApi.json' | |
12 | +URL_REQUEST_API = 'http://vlibras.lavid.ufpb.br/api/dicionario/' | |
13 | +TEXT_CHECK_INSTALL = 'C:/vlibras-libs/installSucess.txt' | |
14 | +INSTALL_PLAYER_PATH = PATH_RESOURCE+'download/Vlibras_Up.exe' | |
15 | +##JSON_API_NAME = PATH_RESOURCE+'download/versionApi.json' | |
16 | +##TEXT_CHECK_INSTALL = 'C:/vlibras-libs/installSucess.txt' | |
17 | +PATH_PLAYER = PATH_RESOURCE+'Player/VlibrasPlayer.exe' | |
18 | + | |
19 | + | |
20 | + | |
21 | +def updateFileDictVersion(version): | |
22 | + try: | |
23 | + txt_local_version = open(TXT_DICT_VERSION, 'w') | |
24 | + txt_local_version.write(version) | |
25 | + txt_local_version.close() | |
26 | + return True | |
27 | + except: | |
28 | + return False | |
29 | + | |
30 | +def checkDictVersion(): | |
31 | + if os.path.isfile(TXT_DICT_VERSION): | |
32 | + arquivoDictVersion = open(TXT_DICT_VERSION,'r') | |
33 | + versionDict = arquivoDictVersion.readline() | |
34 | + arquivoDictVersion.close() | |
35 | + if not os.path.exists(DICTIONARY_EXTRACT_PATH): | |
36 | + os.mkdir(DICTIONARY_EXTRACT_PATH) | |
37 | + return [versionDict,len(os.listdir(DICTIONARY_EXTRACT_PATH))] | |
38 | + else: | |
39 | + return [] | |
40 | + | |
41 | +def checkDictSucess(quant): | |
42 | + return int(quant) < len(os.listdir(DICTIONARY_EXTRACT_PATH)) | |
43 | + | |
44 | +def updateFilePlayerVersion(version): | |
45 | + try: | |
46 | + txt_local_version = open(TXT_PLAYER_VERSION, 'w') | |
47 | + txt_local_version.write(version) | |
48 | + txt_local_version.close() | |
49 | + return True | |
50 | + except: | |
51 | + return False | |
52 | + | |
53 | + | |
54 | +def checkPlayerVersion(): | |
55 | + if os.path.isfile(TXT_PLAYER_VERSION): | |
56 | + arquivoDictPlayer = open(TXT_PLAYER_VERSION,'r') | |
57 | + version = arquivoDictPlayer.readline() | |
58 | + arquivoDictPlayer.close() | |
59 | + return version | |
60 | + else: | |
61 | + return '000' | |
62 | + | |
63 | + | |
64 | +def updateSuccess(): | |
65 | + txt_local_version = open(TEXT_CHECK_INSTALL, 'w') | |
66 | + txt_local_version.write('sucess') | |
67 | + txt_local_version.close() | |
68 | + shutil.move('C:/vlibras-libs/update/bin/vlibrasPlayerUp.exe', "C:/vlibras-libs/update/") | |
69 | + | |
70 | + | |
71 | +def downladFileApi(_url): | |
72 | + try: | |
73 | + | |
74 | + urllib.urlretrieve (_url, JSON_API_VERSION) | |
75 | + | |
76 | + return True | |
77 | + except Exception, e: | |
78 | + print e | |
79 | + return False | |
80 | + | |
81 | +def getUrlDict(): | |
82 | + | |
83 | + try: | |
84 | + my_dict_version = '000000' | |
85 | + dictVersionList = checkDictVersion(); | |
86 | + if(len(dictVersionList) == 2): | |
87 | + my_dict_version = dictVersionList[0].replace(".", "").replace("_", "") | |
88 | + if(not downladFileApi(URL_REQUEST_API+dictVersionList[0]+'?type=json')): | |
89 | + return ['erro'] | |
90 | + else: | |
91 | + if(not downladFileApi(URL_REQUEST_API+'0.0.0_0.0.0?type=json')): | |
92 | + return ['erro'] | |
93 | + | |
94 | + with open(JSON_API_VERSION) as data: | |
95 | + json_data = json.load(data) | |
96 | + | |
97 | + api_dict_version_full = json_data['dictionaryVersion'].encode('utf-8') | |
98 | + api_dict_version = json_data['dictionaryVersion'].encode('utf-8').replace(".", "").replace("_", "") | |
99 | + api_player_version = json_data['playerVersion'].encode('utf-8').replace(".", "") | |
100 | + url_download_player = json_data['playerUrl'].encode('utf-8') | |
101 | + url_download_dict = json_data['dictionaryUrl'].encode('utf-8') | |
102 | + | |
103 | + | |
104 | + if int(api_dict_version) > int(my_dict_version): | |
105 | + return [url_download_dict,api_dict_version_full] | |
106 | + else: | |
107 | + return [] | |
108 | + except: | |
109 | + return ['erro'] | |
110 | + | |
111 | +def getUrlDictPlayer(): | |
112 | + my_dict_version = '000000' | |
113 | + dictVersionList = checkDictVersion() | |
114 | + my_player_version = checkPlayerVersion().replace(".", "").replace("_", "") | |
115 | + if(len(dictVersionList) == 2): | |
116 | + my_dict_version = dictVersionList[0].replace(".", "").replace("_", "") | |
117 | + if(not downladFileApi(URL_REQUEST_API+dictVersionList[0]+'?type=json')): | |
118 | + return ['erro'] | |
119 | + else: | |
120 | + if(not downladFileApi(URL_REQUEST_API+'0.0.0_0.0.0?type=json')): | |
121 | + return ['erro'] | |
122 | + | |
123 | + with open(JSON_API_VERSION) as data: | |
124 | + json_data = json.load(data) | |
125 | + | |
126 | + api_dict_version_full = json_data['dictionaryVersion'].encode('utf-8') | |
127 | + api_dict_version = json_data['dictionaryVersion'].encode('utf-8').replace(".", "").replace("_", "") | |
128 | + api_player_version = json_data['playerVersion'].encode('utf-8').replace(".", "") | |
129 | + api_player_version_full = json_data['playerVersion'].encode('utf-8') | |
130 | + url_download_player = json_data['playerUrl'].encode('utf-8') | |
131 | + url_download_dict = json_data['dictionaryUrl'].encode('utf-8') | |
132 | + | |
133 | + if int(api_player_version) > int(my_player_version): | |
134 | + return [url_download_player,api_player_version_full] | |
135 | + elif int(api_dict_version) > int(my_dict_version): | |
136 | + return [url_download_dict,api_dict_version_full] | |
137 | + else: | |
138 | + return [] | |
139 | + | |
140 | + | |
141 | + | |
142 | + | |
143 | + | |
144 | +if __name__ == '__main__': | |
145 | + print checkDictVersion() | |
146 | + | ... | ... |
... | ... | @@ -0,0 +1,41 @@ |
1 | +# -*- coding: utf-8 -*- | |
2 | +from os import popen | |
3 | +import Util | |
4 | + | |
5 | +PATH_RESOURCE = 'c:/vlibras-libs/update/' | |
6 | +TXT_LOCAL_VERSION = PATH_RESOURCE+'version/version.txt' | |
7 | + | |
8 | + | |
9 | +if __name__ == '__main__': | |
10 | + | |
11 | + listPlayerVersion = Util.getUrlDictPlayer() | |
12 | + txt_local_version = open(TXT_LOCAL_VERSION, 'w') | |
13 | + if len(listPlayerVersion)== 2: | |
14 | + | |
15 | + result = listPlayerVersion[0] | |
16 | + if result.endswith('.exe'): | |
17 | + txt_local_version.write('1') | |
18 | + elif result.endswith('.zip'): | |
19 | + txt_local_version.write('2') | |
20 | + | |
21 | + elif len(listPlayerVersion) == 0: | |
22 | + txt_local_version.write('0') | |
23 | + else: | |
24 | + txt_local_version.write('-1') | |
25 | + | |
26 | + txt_local_version.close() | |
27 | + | |
28 | + print listPlayerVersion | |
29 | + | |
30 | + | |
31 | + | |
32 | + | |
33 | + | |
34 | + | |
35 | + | |
36 | + | |
37 | + | |
38 | + | |
39 | + | |
40 | + | |
41 | + | ... | ... |
... | ... | @@ -0,0 +1,138 @@ |
1 | + | |
2 | +# -*- coding: utf-8 -*- | |
3 | + | |
4 | +import wx | |
5 | +import subprocess | |
6 | +import time | |
7 | +import os.path | |
8 | +from wx.lib.pubsub import pub | |
9 | +from DownloadFile import * | |
10 | +from VlibrasCheckVersion import * | |
11 | +import zipfile | |
12 | +import Util | |
13 | + | |
14 | + | |
15 | + | |
16 | +##PATH_RESOURCE = 'C:/vlibras-libs/update/' | |
17 | +##DICTIONARY_NAME = 'download/vlibras_dicionario.zip' | |
18 | +##INSTALL_PLAYER_NAME = 'download/Vlibras_Up.exe' | |
19 | +##DICTIONARY_EXTRACT_PATH = 'C:/vlibras-libs/Player/VLibrasPlayer_Data/Bundles' | |
20 | +##JSON_LOCAL_NAME = PATH_RESOURCE+'version/version.json' | |
21 | +##JSON_API_NAME = PATH_RESOURCE+'download/versionApi.json' | |
22 | + | |
23 | +class UpdateView(wx.Frame): | |
24 | + | |
25 | + def __init__(self,_listUrlDictVersionFull): | |
26 | + | |
27 | + self.length_dict = 0; | |
28 | + self.listDictVersionDictLength = Util.checkDictVersion() | |
29 | + if self.listDictVersionDictLength == 2: | |
30 | + self.length_dict =listDictVersionDictLength[1] | |
31 | + | |
32 | + self.listUrlDictVersionFull = _listUrlDictVersionFull | |
33 | + | |
34 | + style = wx.SYSTEM_MENU | wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.MINIMIZE_BOX | |
35 | + wx.Frame.__init__(self, None, title='Atualização do VLibras', style=style,size=(480,250)) | |
36 | + self.SetIcon(wx.Icon("c:/vlibras-libs/icons/icon_vlibras.ico", wx.BITMAP_TYPE_ICO)) | |
37 | + self.myPanel = wx.Panel(self, -1) | |
38 | + self.myPanel.SetBackgroundColour('#F5F5F5') | |
39 | + btnCancel = wx.Button(self.myPanel, label="Cancelar",pos=(365, 180), size=(80, 25)) | |
40 | + self.myText = wx.StaticText(self.myPanel, -1, pos=(5,105)) | |
41 | + self.myText.SetForegroundColour('#000000') | |
42 | + self.progress = wx.Gauge(self.myPanel, range=100,pos=(5,80),size=(463,25)) | |
43 | + self.Center() | |
44 | + | |
45 | + # Anexa um evento ao botão | |
46 | + self.Bind(wx.EVT_BUTTON, self.onBtnCancelClick, btnCancel) | |
47 | + self.__close_callback = None | |
48 | + self.Bind(wx.EVT_CLOSE, self._when_closed) | |
49 | + | |
50 | + #registra listeners na classe DownloadFile | |
51 | + pub.subscribe(self.downloadSucess, "downloadSucess") | |
52 | + pub.subscribe(self.erroDeConexao, "erroDeConexao") | |
53 | + pub.subscribe(self.updateProgress, "updateProgress") | |
54 | + self.percentDownload = 0; | |
55 | + | |
56 | + | |
57 | + #inicia o download do arquivo | |
58 | + self.downloadFile = DownloadFile2(listUrlDictVersionFull[0], Util.DICTIONARY_ZIP_PATH) | |
59 | + self.downloadFile.start() | |
60 | + self.myText.SetLabel('Baixando dicionário') | |
61 | + | |
62 | + def erroDeConexao(self, msg): | |
63 | + wx.MessageBox('Ocorreu um erro ao tentar fazer atualização. \n Por favor tente mais tarde.', 'Informação',wx.OK | wx.ICON_INFORMATION) | |
64 | + self.Destroy() | |
65 | + | |
66 | + def register_close_callback(self, callback): | |
67 | + self.__close_callback = callback | |
68 | + | |
69 | + def _when_closed(self, event): | |
70 | + self.OnCloseFrame(event); | |
71 | + | |
72 | + | |
73 | + def onBtnCancelClick(self, event): | |
74 | + self.OnCloseFrame(event); | |
75 | + | |
76 | + | |
77 | + def downloadSucess(self, msg): | |
78 | + self.percentDownload = 100.0 | |
79 | + time.sleep( 2 ) | |
80 | + | |
81 | + with zipfile.ZipFile(Util.DICTIONARY_ZIP_PATH, "r") as z: | |
82 | + z.extractall(Util.DICTIONARY_EXTRACT_PATH) | |
83 | + if Util.checkDictSucess(self.lenght_dict): | |
84 | + self.ShowMessage('Vlibras Atualizado com sucesso!') | |
85 | + Util.updateFileDictVersion(listUrlDictVersionFull[1]) | |
86 | + else: | |
87 | + self.ShowMessageError('Houve um erro ao atualizar dicionário!') | |
88 | + | |
89 | + self.downloadFile.stop() | |
90 | + self.Destroy() | |
91 | + | |
92 | + | |
93 | + def updateProgress(self, msg): | |
94 | + value = msg | |
95 | + self.percentDownload = value | |
96 | + self.progress.SetValue(value) | |
97 | + | |
98 | + def ShowMessage(self, mesagem): | |
99 | + wx.MessageBox(mesagem, 'Informação', | |
100 | + wx.OK | wx.ICON_INFORMATION) | |
101 | + def ShowMessageError(self, mesagem): | |
102 | + wx.MessageBox(mesagem, 'Informação', | |
103 | + wx.OK | wx.ICON_ERROR) | |
104 | + self.downloadFile.stop() | |
105 | + self.Destroy() | |
106 | + | |
107 | + | |
108 | + | |
109 | + | |
110 | + | |
111 | + # monitora a interação do usuário no botão de fechar | |
112 | + def OnCloseFrame(self, event): | |
113 | + if(self.percentDownload>= 100): | |
114 | + self.downloadFile.stop() | |
115 | + self.Destroy() | |
116 | + dialog = wx.MessageDialog(self, message = "Tem certeza que deseja cancelar a atualização?", caption = "Cancelar Atualização", | |
117 | + style = wx.YES_NO | wx.ICON_QUESTION) | |
118 | + response = dialog.ShowModal() | |
119 | + | |
120 | + if (response == wx.ID_YES): | |
121 | + self.downloadFile.stop() | |
122 | + | |
123 | + self.Destroy() | |
124 | + else: | |
125 | + event.StopPropagation() | |
126 | + | |
127 | + | |
128 | + | |
129 | +if __name__ == '__main__': | |
130 | + | |
131 | + listUrlDictVersionFull = Util.getUrlDict() | |
132 | + if len(listUrlDictVersionFull)== 2: | |
133 | + app = wx.App(False) | |
134 | + frame = UpdateView(listUrlDictVersionFull) | |
135 | + frame.register_close_callback(lambda: True) | |
136 | + frame.Show() | |
137 | + app.MainLoop() | |
138 | + | ... | ... |
... | ... | @@ -0,0 +1,152 @@ |
1 | + | |
2 | +# -*- coding: utf-8 -*- | |
3 | + | |
4 | +import wx | |
5 | +import subprocess | |
6 | +import time | |
7 | +import os | |
8 | +from wx.lib.pubsub import pub | |
9 | +from DownloadFile import * | |
10 | +from VlibrasCheckVersion import * | |
11 | +import zipfile | |
12 | +import Util | |
13 | + | |
14 | + | |
15 | +class UpdateView(wx.Frame): | |
16 | + | |
17 | + def __init__(self,_listPlayerVersion): | |
18 | + | |
19 | + self.listPlayerVersion = _listPlayerVersion | |
20 | + | |
21 | + style = wx.SYSTEM_MENU | wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.MINIMIZE_BOX | |
22 | + wx.Frame.__init__(self, None, title='Atualização do VLibras', style=style,size=(480,250)) | |
23 | + # Define o ícone para a janela | |
24 | + self.SetIcon(wx.Icon("c:/vlibras-libs/icons/icon_vlibras.ico", wx.BITMAP_TYPE_ICO)) | |
25 | + self.myPanel = wx.Panel(self, -1) | |
26 | + self.myPanel.SetBackgroundColour('#F5F5F5') | |
27 | + btnCancel = wx.Button(self.myPanel, label="Cancelar",pos=(365, 180), size=(80, 25)) | |
28 | + self.myText = wx.StaticText(self.myPanel, -1, pos=(5,105)) | |
29 | + self.myText.SetForegroundColour('#000000') | |
30 | + self.progress = wx.Gauge(self.myPanel, range=100,pos=(5,80),size=(463,25)) | |
31 | + self.Center() | |
32 | + | |
33 | + # Anexa um evento ao botão | |
34 | + self.Bind(wx.EVT_BUTTON, self.onBtnCancelClick, btnCancel) | |
35 | + self.__close_callback = None | |
36 | + self.Bind(wx.EVT_CLOSE, self._when_closed) | |
37 | + | |
38 | + #registra listeners na classe DownloadFile | |
39 | + pub.subscribe(self.downloadSucess, "downloadSucess") | |
40 | + pub.subscribe(self.erroDeConexao, "erroDeConexao") | |
41 | + pub.subscribe(self.updateProgress, "updateProgress") | |
42 | + self.percentDownload = 0; | |
43 | + | |
44 | + | |
45 | + #inicia o download do arquivo | |
46 | + self.downloadFile = DownloadFile2(listPlayerVersion[0], Util.INSTALL_PLAYER_PATH) | |
47 | + self.downloadFile.start() | |
48 | + self.myText.SetLabel('Baixando atualização do VLibras. Aguarde... ') | |
49 | + | |
50 | + def erroDeConexao(self, msg): | |
51 | + wx.MessageBox('Ocorreu um erro ao tentar baixar atualização. \n Por favor verifique sua conexão e tente novamente.', 'Informação',wx.OK | wx.ICON_INFORMATION) | |
52 | + self.Destroy() | |
53 | + | |
54 | + def register_close_callback(self, callback): | |
55 | + self.__close_callback = callback | |
56 | + | |
57 | + def _when_closed(self, event): | |
58 | + self.OnCloseFrame(event); | |
59 | + | |
60 | + | |
61 | + def onBtnCancelClick(self, event): | |
62 | + self.OnCloseFrame(event); | |
63 | + | |
64 | + | |
65 | + def downloadSucess(self, msg): | |
66 | + self.percentDownload = 100.0 | |
67 | + time.sleep( 5 ) | |
68 | + | |
69 | + self.Hide() | |
70 | + process = subprocess.call(Util.INSTALL_PLAYER_PATH) | |
71 | + time.sleep( 3 ) | |
72 | + if os.path.isfile(Util.TEXT_CHECK_INSTALL): | |
73 | + self.ShowMessage('Vlibras Atualizado com sucesso!') | |
74 | + Util.updateFilePlayerVersion(listPlayerVersion[1]) | |
75 | + subprocess.Popen(Util.PATH_PLAYER) | |
76 | + else: | |
77 | + self.ShowMessageError('O Vlibras não foi atualizado!') | |
78 | + subprocess.Popen(Util.PATH_PLAYER) | |
79 | + self.downloadFile.stop() | |
80 | + self.Destroy() | |
81 | + | |
82 | + | |
83 | + def updateProgress(self, msg): | |
84 | + value = msg | |
85 | + self.percentDownload = value | |
86 | + self.progress.SetValue(value) | |
87 | + | |
88 | + def ShowMessage(self, mesagem): | |
89 | + wx.MessageBox(mesagem, 'Informação', | |
90 | + wx.OK | wx.ICON_INFORMATION) | |
91 | + def ShowMessageError(self, mesagem): | |
92 | + wx.MessageBox(mesagem, 'Informação', | |
93 | + wx.OK | wx.ICON_ERROR) | |
94 | + self.downloadFile.stop() | |
95 | + self.Destroy() | |
96 | + | |
97 | + | |
98 | + | |
99 | + | |
100 | + | |
101 | + # monitora a interação do usuário no botão de fechar | |
102 | + def OnCloseFrame(self, event): | |
103 | + if(self.percentDownload>= 100): | |
104 | + self.downloadFile.stop() | |
105 | + self.Destroy() | |
106 | + dialog = wx.MessageDialog(self, message = "Tem certeza que deseja cancelar a atualização?", caption = "Cancelar Atualização", | |
107 | + style = wx.YES_NO | wx.ICON_INFORMATION) | |
108 | + response = dialog.ShowModal() | |
109 | + | |
110 | + if (response == wx.ID_YES): | |
111 | + self.downloadFile.stop() | |
112 | + time.sleep( 0.5 ) | |
113 | + os.remove(Util.INSTALL_PLAYER_PATH) | |
114 | + self.Destroy() | |
115 | + else: | |
116 | + event.StopPropagation() | |
117 | + | |
118 | + | |
119 | +class ShowInfo(wx.Frame): | |
120 | + | |
121 | + def __init__(self,_mesagem): | |
122 | + self.mesagem = _mesagem | |
123 | + style = wx.SYSTEM_MENU | wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.MINIMIZE_BOX | |
124 | + wx.Frame.__init__(self, None, title='Atualização do VLibras', style=style,size=(480,250)) | |
125 | + def ShowMessage(self): | |
126 | + wx.MessageBox(self.mesagem, 'Informação', | |
127 | + wx.OK | wx.ICON_INFORMATION) | |
128 | + def ShowMessageError(self): | |
129 | + wx.MessageBox(self.mesagem, 'Informação', | |
130 | + wx.OK | wx.ICON_ERROR) | |
131 | + | |
132 | + | |
133 | + | |
134 | +if __name__ == '__main__': | |
135 | + app = wx.App(False) | |
136 | + listPlayerVersion = Util.getUrlDictPlayer() | |
137 | + if os.path.isfile(Util.TEXT_CHECK_INSTALL): | |
138 | + os.remove(Util.TEXT_CHECK_INSTALL) | |
139 | + if len(listPlayerVersion)== 2: | |
140 | + if(listPlayerVersion[0].endswith('.exe')): | |
141 | + frame = UpdateView(listPlayerVersion) | |
142 | + frame.register_close_callback(lambda: True) | |
143 | + frame.Show() | |
144 | + app.MainLoop() | |
145 | + else: | |
146 | + ShowInfo('Ocorreu um erro ao tentar atualizar o VLibras!').ShowMessageError() | |
147 | + | |
148 | + else: | |
149 | + ShowInfo('Atualização não disponível!').ShowMessageError() | |
150 | + | |
151 | + | |
152 | + | ... | ... |
... | ... | @@ -0,0 +1,61 @@ |
1 | + | |
2 | + | |
3 | +#include <windows.h> //include all the basics | |
4 | + //string and other mapping macros | |
5 | + | |
6 | + | |
7 | +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, | |
8 | + LPSTR lpCmdLine, int nShowCmd) | |
9 | +{ | |
10 | + | |
11 | + STARTUPINFO StartupInfo; | |
12 | + PROCESS_INFORMATION ProcessInfo; | |
13 | + char Args[4096]; | |
14 | + char *pEnvCMD = NULL; | |
15 | + char *pDefaultCMD = "CMD.EXE"; | |
16 | + ULONG rc; | |
17 | + | |
18 | + memset(&StartupInfo, 0, sizeof(StartupInfo)); | |
19 | + StartupInfo.cb = sizeof(STARTUPINFO); | |
20 | + StartupInfo.dwFlags = STARTF_USESHOWWINDOW; | |
21 | + StartupInfo.wShowWindow = SW_HIDE; | |
22 | + | |
23 | + Args[0] = 0; | |
24 | + | |
25 | + pEnvCMD = getenv("COMSPEC"); | |
26 | + | |
27 | + if(pEnvCMD){ | |
28 | + | |
29 | + strcpy(Args, pEnvCMD); | |
30 | + } | |
31 | + else{ | |
32 | + strcpy(Args, pDefaultCMD); | |
33 | + } | |
34 | + | |
35 | + // "/c" option - Do the command then terminate the command window | |
36 | + strcat(Args, " /c "); | |
37 | + //the application you would like to run from the command window | |
38 | + strcat(Args, "c:\\Python27\\python.exe"); | |
39 | + strcat(Args, " "); | |
40 | + //the parameters passed to the application being run from the command window. | |
41 | + strcat(Args, "c:\\vlibras-libs\\update\\py\\VlibrasUpdateInstallDict.pyc"); | |
42 | + | |
43 | + if (!CreateProcess( NULL, Args, NULL, NULL, FALSE, | |
44 | + CREATE_NEW_CONSOLE, | |
45 | + NULL, | |
46 | + NULL, | |
47 | + &StartupInfo, | |
48 | + &ProcessInfo)) | |
49 | + { | |
50 | + return GetLastError(); | |
51 | + } | |
52 | + | |
53 | + WaitForSingleObject(ProcessInfo.hProcess, INFINITE); | |
54 | + if(!GetExitCodeProcess(ProcessInfo.hProcess, &rc)) | |
55 | + rc = 0; | |
56 | + | |
57 | + CloseHandle(ProcessInfo.hThread); | |
58 | + CloseHandle(ProcessInfo.hProcess); | |
59 | + | |
60 | + return 0; | |
61 | +} | |
0 | 62 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,61 @@ |
1 | + | |
2 | + | |
3 | +#include <windows.h> //include all the basics | |
4 | + //string and other mapping macros | |
5 | + | |
6 | + | |
7 | +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, | |
8 | + LPSTR lpCmdLine, int nShowCmd) | |
9 | +{ | |
10 | + | |
11 | + STARTUPINFO StartupInfo; | |
12 | + PROCESS_INFORMATION ProcessInfo; | |
13 | + char Args[4096]; | |
14 | + char *pEnvCMD = NULL; | |
15 | + char *pDefaultCMD = "CMD.EXE"; | |
16 | + ULONG rc; | |
17 | + | |
18 | + memset(&StartupInfo, 0, sizeof(StartupInfo)); | |
19 | + StartupInfo.cb = sizeof(STARTUPINFO); | |
20 | + StartupInfo.dwFlags = STARTF_USESHOWWINDOW; | |
21 | + StartupInfo.wShowWindow = SW_HIDE; | |
22 | + | |
23 | + Args[0] = 0; | |
24 | + | |
25 | + pEnvCMD = getenv("COMSPEC"); | |
26 | + | |
27 | + if(pEnvCMD){ | |
28 | + | |
29 | + strcpy(Args, pEnvCMD); | |
30 | + } | |
31 | + else{ | |
32 | + strcpy(Args, pDefaultCMD); | |
33 | + } | |
34 | + | |
35 | + // "/c" option - Do the command then terminate the command window | |
36 | + strcat(Args, " /c "); | |
37 | + //the application you would like to run from the command window | |
38 | + strcat(Args, "c:\\Python27\\python.exe"); | |
39 | + strcat(Args, " "); | |
40 | + //the parameters passed to the application being run from the command window. | |
41 | + strcat(Args, "c:\\vlibras-libs\\update\\py\\VlibrasUpdateInstallPlayer.pyc"); | |
42 | + | |
43 | + if (!CreateProcess( NULL, Args, NULL, NULL, FALSE, | |
44 | + CREATE_NEW_CONSOLE, | |
45 | + NULL, | |
46 | + NULL, | |
47 | + &StartupInfo, | |
48 | + &ProcessInfo)) | |
49 | + { | |
50 | + return GetLastError(); | |
51 | + } | |
52 | + | |
53 | + WaitForSingleObject(ProcessInfo.hProcess, INFINITE); | |
54 | + if(!GetExitCodeProcess(ProcessInfo.hProcess, &rc)) | |
55 | + rc = 0; | |
56 | + | |
57 | + CloseHandle(ProcessInfo.hThread); | |
58 | + CloseHandle(ProcessInfo.hProcess); | |
59 | + | |
60 | + return 0; | |
61 | +} | |
0 | 62 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,61 @@ |
1 | + | |
2 | + | |
3 | +#include <windows.h> //include all the basics | |
4 | + //string and other mapping macros | |
5 | + | |
6 | + | |
7 | +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, | |
8 | + LPSTR lpCmdLine, int nShowCmd) | |
9 | +{ | |
10 | + | |
11 | + STARTUPINFO StartupInfo; | |
12 | + PROCESS_INFORMATION ProcessInfo; | |
13 | + char Args[4096]; | |
14 | + char *pEnvCMD = NULL; | |
15 | + char *pDefaultCMD = "CMD.EXE"; | |
16 | + ULONG rc; | |
17 | + | |
18 | + memset(&StartupInfo, 0, sizeof(StartupInfo)); | |
19 | + StartupInfo.cb = sizeof(STARTUPINFO); | |
20 | + StartupInfo.dwFlags = STARTF_USESHOWWINDOW; | |
21 | + StartupInfo.wShowWindow = SW_HIDE; | |
22 | + | |
23 | + Args[0] = 0; | |
24 | + | |
25 | + pEnvCMD = getenv("COMSPEC"); | |
26 | + | |
27 | + if(pEnvCMD){ | |
28 | + | |
29 | + strcpy(Args, pEnvCMD); | |
30 | + } | |
31 | + else{ | |
32 | + strcpy(Args, pDefaultCMD); | |
33 | + } | |
34 | + | |
35 | + // "/c" option - Do the command then terminate the command window | |
36 | + strcat(Args, " /c "); | |
37 | + //the application you would like to run from the command window | |
38 | + strcat(Args, "c:\\Python27\\python.exe"); | |
39 | + strcat(Args, " "); | |
40 | + //the parameters passed to the application being run from the command window. | |
41 | + strcat(Args, "c:\\vlibras-libs\\update\\py\\writeSucessInstall.pyc"); | |
42 | + | |
43 | + if (!CreateProcess( NULL, Args, NULL, NULL, FALSE, | |
44 | + CREATE_NEW_CONSOLE, | |
45 | + NULL, | |
46 | + NULL, | |
47 | + &StartupInfo, | |
48 | + &ProcessInfo)) | |
49 | + { | |
50 | + return GetLastError(); | |
51 | + } | |
52 | + | |
53 | + WaitForSingleObject(ProcessInfo.hProcess, INFINITE); | |
54 | + if(!GetExitCodeProcess(ProcessInfo.hProcess, &rc)) | |
55 | + rc = 0; | |
56 | + | |
57 | + CloseHandle(ProcessInfo.hThread); | |
58 | + CloseHandle(ProcessInfo.hProcess); | |
59 | + | |
60 | + return 0; | |
61 | +} | |
0 | 62 | \ No newline at end of file | ... | ... |