Commit 2fc2bf6591f1fd78453d4459dc6888c3aca08b15
1 parent
ae7acdd5
Exists in
Au-ghub/master
python portatil e fixes
adicao do python, fix de loop no download/extracao do python, download da lista de sinais
Showing
4 changed files
with
87 additions
and
25 deletions
Show diff stats
BundlesManager.cs
... | ... | @@ -3,8 +3,7 @@ using System.Net; |
3 | 3 | using System.IO; |
4 | 4 | using System.IO.Compression; |
5 | 5 | |
6 | -namespace AtualizadorVLibras | |
7 | -{ | |
6 | +namespace AtualizadorVLibras{ | |
8 | 7 | |
9 | 8 | public class TimeoutWebClient : WebClient{ |
10 | 9 | protected override WebRequest GetWebRequest(Uri address){ |
... | ... | @@ -14,8 +13,7 @@ namespace AtualizadorVLibras |
14 | 13 | } |
15 | 14 | } |
16 | 15 | |
17 | - static class BundlesManager | |
18 | - { | |
16 | + static class BundlesManager{ | |
19 | 17 | //timeout para verificação de existência e data de última verificação dos pacotes |
20 | 18 | static int timeout = 2000; |
21 | 19 | |
... | ... | @@ -96,13 +94,13 @@ namespace AtualizadorVLibras |
96 | 94 | } |
97 | 95 | |
98 | 96 | public static int DownloadBundlesPackages(string url, string rootPath, string extractPath){ |
99 | - //rootPath é o path dos arquivos .zip locais | |
100 | - //url é o path dos arquivos .zip remotos | |
101 | - //extractPath é o path da pasta Bundles | |
102 | - string ext = @".zip"; | |
103 | - int i = 1; | |
104 | - string remote; | |
105 | - string local; | |
97 | + //rootPath é o path dos arquivos .zip locais | |
98 | + //url é o path dos arquivos .zip remotos | |
99 | + //extractPath é o path da pasta Bundles | |
100 | + string ext = @".zip"; | |
101 | + int i = 1; | |
102 | + string remote; | |
103 | + string local; | |
106 | 104 | while(true){ |
107 | 105 | Console.WriteLine("Verificando arquivo "+i+" zip dos pacotes de sinais."); |
108 | 106 | remote = url+i.ToString()+ext; |
... | ... | @@ -132,7 +130,7 @@ namespace AtualizadorVLibras |
132 | 130 | public static void DownloadListaSinais(string url){ |
133 | 131 | string sinais = "sinais.txt"; |
134 | 132 | string remote = url+sinais; |
135 | - string local = @"Player\vlibrasPlayer_Data\Resources\"+sinais; | |
133 | + string local = @"..\Bundles\"+sinais; | |
136 | 134 | if(RemoteFileExists(remote)){ |
137 | 135 | if(!File.Exists(local) || RemoteIsNewerThanLocal(remote, local)){ |
138 | 136 | DownloadFileToPath(remote, local); |
... | ... | @@ -140,8 +138,8 @@ namespace AtualizadorVLibras |
140 | 138 | } |
141 | 139 | } |
142 | 140 | /*public static void ExtractBundlesPackages(string rootPath, string extractPath, int qtd){ |
143 | - string ext = @".zip"; | |
144 | - bool exists = System.IO.Directory.Exists(extractPath); | |
141 | + string ext = @".zip"; | |
142 | + bool exists = System.IO.Directory.Exists(extractPath); | |
145 | 143 | if(!exists){ |
146 | 144 | System.IO.Directory.CreateDirectory(extractPath); |
147 | 145 | } |
... | ... | @@ -160,6 +158,35 @@ namespace AtualizadorVLibras |
160 | 158 | } |
161 | 159 | }*/ |
162 | 160 | |
161 | + public static void DownloadFileIfNewer(string remote, string local, string fileName){ | |
162 | + if(RemoteFileExists(remote+fileName) && (!File.Exists(local+fileName) || RemoteIsNewerThanLocal(remote+fileName, local+fileName))){ | |
163 | + DownloadFileToPath(remote+fileName, local+fileName); | |
164 | + if(File.Exists(local+fileName.Remove(fileName.Length-4))){ | |
165 | + File.Delete(local+fileName.Remove(fileName.Length-4)); | |
166 | + } | |
167 | + } | |
168 | + } | |
169 | + public static void ExtractZip(string remote, string local, string extractPath, string fileName){ | |
170 | + if(!File.Exists(local+fileName.Remove(fileName.Length-4))){ | |
171 | + bool dirExists = System.IO.Directory.Exists(extractPath); | |
172 | + if(!dirExists){ | |
173 | + System.IO.Directory.CreateDirectory(extractPath); | |
174 | + } | |
175 | + try{ | |
176 | + if(!File.Exists(extractPath+fileName.Remove(fileName.Length-4))){ | |
177 | + ZipArchive zip = ZipFile.Open(local+fileName, ZipArchiveMode.Read, System.Text.Encoding.GetEncoding(System.Globalization.CultureInfo.CurrentCulture.TextInfo.OEMCodePage)); | |
178 | + ExtractToDirectory(zip, extractPath, true); | |
179 | + File.Create(extractPath+fileName.Remove(fileName.Length-4)).Close(); | |
180 | + } | |
181 | + }catch(Exception e){ | |
182 | + Console.WriteLine("Ocorreu um erro durante a extraçao: {0}\nPressione uma tecla para continuar.",e); | |
183 | + Console.ReadKey(); | |
184 | + DownloadFileIfNewer(remote, local, fileName); | |
185 | + ExtractZip(remote, local, extractPath, fileName); | |
186 | + } | |
187 | + } | |
188 | + } | |
189 | + | |
163 | 190 | //ZipArchive archive = ZipFile.Open(fileAbsolute, ZipArchiveMode.Read, System.Text.Encoding.GetEncoding(System.Globalization.CultureInfo.CurrentCulture.TextInfo.OEMCodePage)); |
164 | 191 | public static void ExtractBundlesPackagesOverWrite(string url, string rootPath, string extractPath, int qtd){ |
165 | 192 | string ext = @".zip"; | ... | ... |
Program.cs
... | ... | @@ -36,7 +36,9 @@ namespace AtualizadorVLibras |
36 | 36 | static void Main() |
37 | 37 | { |
38 | 38 | //ENDEREÇO DE ONDE SERÃO BAIXADOS OS PACOTES (.ZIP) DE SINAIS (1.ZIP, 2.ZIP E ETC...) |
39 | - string url = @"http://atualizacao.vlibras.lavid.ufpb.br/windows/"; | |
39 | + //string url = @"http://atualizacao.vlibras.lavid.ufpb.br/windows/"; | |
40 | + //string url = @"http://127.0.0.1:8000/"; | |
41 | + string url = @"http://192.168.25.121:8089/"; | |
40 | 42 | //string url = @"http://179.185.184.75:8080/"; |
41 | 43 | |
42 | 44 | string dirAtual = Directory.GetCurrentDirectory(); |
... | ... | @@ -119,7 +121,7 @@ namespace AtualizadorVLibras |
119 | 121 | |
120 | 122 | //VERIFICAÇÃO E INSTALAÇÃO DO PYTHON |
121 | 123 | //REGISTROS DO PYTHON |
122 | - try{ | |
124 | + /*try{ | |
123 | 125 | RegistryKey[] regPython = new RegistryKey[4]; |
124 | 126 | regPython[0] = lm64.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{9DA28CE5-0AA5-429E-86D8-686ED898C665}"); |
125 | 127 | regPython[1] = lm32.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{9DA28CE5-0AA5-429E-86D8-686ED898C665}"); |
... | ... | @@ -137,7 +139,7 @@ namespace AtualizadorVLibras |
137 | 139 | }catch(Exception e){ |
138 | 140 | Console.WriteLine("Erro: {0}\nAperte alguma tecla para continuar.", e); |
139 | 141 | Console.ReadKey(); |
140 | - } | |
142 | + }*/ | |
141 | 143 | |
142 | 144 | |
143 | 145 | /* |
... | ... | @@ -188,7 +190,7 @@ namespace AtualizadorVLibras |
188 | 190 | |
189 | 191 | //INSTALAÇÃO DOS MÓDULOS DO PYTHON |
190 | 192 | //Tem que ser depois da configuração das variáveis de ambiente |
191 | - Console.WriteLine("Instalando os módulos de python."); | |
193 | + /*Console.WriteLine("Instalando os módulos de python."); | |
192 | 194 | try{ |
193 | 195 | if(instalouPython){ |
194 | 196 | //instalação forçada de módulos |
... | ... | @@ -197,14 +199,34 @@ namespace AtualizadorVLibras |
197 | 199 | Requirements.InstallWheels(false); |
198 | 200 | } |
199 | 201 | }catch(Exception e){ |
200 | - Console.WriteLine("Erro na instalação de módulos do python {0}\nAperte alguma tecla para continuar.", e); | |
202 | + Console.WriteLine("Erro na instalação de módulos do python {0}.\nAperte alguma tecla para continuar.", e); | |
203 | + Console.ReadKey(); | |
204 | + }*/ | |
205 | + | |
206 | + string rootPath = @"..\"; | |
207 | + string extractPath = @"..\Python\"; | |
208 | + //PYTHON PORTÁTIL | |
209 | + //Download | |
210 | + Console.WriteLine("Baixando cópia portátil do python."); | |
211 | + try{ | |
212 | + BundlesManager.DownloadFileIfNewer(url, rootPath, "python.zip"); | |
213 | + }catch{ | |
214 | + Console.WriteLine("Erro no download do python. Aperte alguma tecla para continuar."); | |
215 | + Console.ReadKey(); | |
216 | + } | |
217 | + //Extração | |
218 | + Console.WriteLine("Extraindo cópia portátil do python."); | |
219 | + try{ | |
220 | + BundlesManager.ExtractZip(url, rootPath, extractPath, "python.zip"); | |
221 | + }catch{ | |
222 | + Console.WriteLine("Erro no extração do python. Aperte alguma tecla para continuar."); | |
201 | 223 | Console.ReadKey(); |
202 | 224 | } |
203 | 225 | |
204 | 226 | //CRIAÇÃO DO ATALHO DO VLIBRAS |
205 | 227 | Console.WriteLine("Criação do atalho do vlibras."); |
206 | 228 | try{ |
207 | - Requirements.criaAtalho(); | |
229 | + Requirements.criaAtalho(@"..\Python\python.exe"); | |
208 | 230 | }catch(Exception e){ |
209 | 231 | Console.WriteLine("Erro na instalação de módulos do python {0}\nAperte alguma tecla para continuar.", e); |
210 | 232 | Console.ReadKey(); |
... | ... | @@ -213,8 +235,7 @@ namespace AtualizadorVLibras |
213 | 235 | |
214 | 236 | //DOWNLOAD DOS SINAIS |
215 | 237 | //BAIXA OS ZIPS DOS SINAIS (1.ZIP, 2.ZIP E ETC...) |
216 | - string rootPath = @"..\"; | |
217 | - string extractPath = @"..\Bundles\"; | |
238 | + extractPath = @"..\Bundles\"; | |
218 | 239 | int qtdDeBundles = 0; |
219 | 240 | Console.WriteLine("Baixando pacote de sinais."); |
220 | 241 | try{ |
... | ... | @@ -224,13 +245,13 @@ namespace AtualizadorVLibras |
224 | 245 | Console.ReadKey(); |
225 | 246 | } |
226 | 247 | |
227 | - | |
228 | 248 | //EXTRAÇÃO: |
229 | 249 | //EXTRAI APENAS SE NÃO TIVER O ARQUIVO HOMÔNIMO SEM EXTENSÃO NA PASTA SINAIS |
230 | 250 | //SE O CAMINHO DE EXTRAÇÃO NÃO EXISTE, ELE SERÁ CRIADO |
231 | 251 | Console.WriteLine("Extraindo pacote de sinais."); |
232 | 252 | //try{ |
233 | 253 | BundlesManager.ExtractBundlesPackagesOverWrite(url, rootPath, extractPath, qtdDeBundles); |
254 | + BundlesManager.DownloadListaSinais(url); | |
234 | 255 | /*}catch(Exception e){ |
235 | 256 | Console.WriteLine("Erro na extração: {0}", e); |
236 | 257 | Console.ReadKey(); | ... | ... |
Requirements.cs
... | ... | @@ -46,11 +46,12 @@ namespace AtualizadorVLibras |
46 | 46 | } |
47 | 47 | |
48 | 48 | //CRIA ATALHO |
49 | - public static void criaAtalho(){ | |
49 | + public static void criaAtalho(string pathPython2){ | |
50 | 50 | //string driveAtual = @"%HOMEPATH%\..\.."; |
51 | 51 | //string pathPython2 = driveAtual+@"Python27\python.exe"; |
52 | 52 | //string pathPython2 = Environment.GetEnvironmentVariable("PYTHONPATH", EnvironmentVariableTarget.Machine); |
53 | - string pathPython2 = GetRegistroPythonPath(); | |
53 | + | |
54 | + //string pathPython2 = GetRegistroPythonPath(); | |
54 | 55 | int idx = pathPython2.IndexOf(@";"); |
55 | 56 | //pathPython2 = pathPython2.Remove(idx, pathPython2.Length - idx); |
56 | 57 | //pathPython2 = "\""+pathPython2 + "\\python.exe\""; |
... | ... | @@ -82,6 +83,7 @@ namespace AtualizadorVLibras |
82 | 83 | //Console.ReadKey(); |
83 | 84 | } |
84 | 85 | |
86 | + //NÃO VAI SER MAIS UTILIZADO DEVIDO AO PYTHON PORTÁTIL | |
85 | 87 | public static string GetRegistroPythonPath(){ |
86 | 88 | var lm64 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64); |
87 | 89 | var lm32 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32); |
... | ... | @@ -125,6 +127,7 @@ namespace AtualizadorVLibras |
125 | 127 | } |
126 | 128 | } |
127 | 129 | |
130 | + //NÃO VAI SER MAIS UTILIZADO DEVIDO AO PYTHON PORTÁTIL | |
128 | 131 | //INSTALA, SE NECESSÁRIO, OS MÓDULOS DO PYTHON |
129 | 132 | public static void InstallWheels(bool force){ |
130 | 133 | /*var cr64 = RegistryKey.OpenBaseKey(RegistryHive.ClassesRoot, RegistryView.Registry64); |
... | ... | @@ -324,6 +327,7 @@ namespace AtualizadorVLibras |
324 | 327 | insProc.Start(); |
325 | 328 | insProc.WaitForExit(); |
326 | 329 | } |
330 | + | |
327 | 331 | //qn - instalação sem interface, passive instalação passiva |
328 | 332 | public static void InstallAndWait(string pathInstaller64, string pathInstaller86, string args){ |
329 | 333 | string pathInstaller; | ... | ... |
... | ... | @@ -0,0 +1,10 @@ |
1 | +enviar: | |
2 | + VLIBRAS.zip | |
3 | + requisitos.zip | |
4 | +servidor: | |
5 | + #.zip (bundles) | |
6 | + python.zip (portátil) | |
7 | + sinais.txt | |
8 | +últimas mudanças: | |
9 | + Clipboarb\clipboard.py passou para Python\clipboard.py | |
10 | + sinais.txt agora se encontra em Bundles\ | |
0 | 11 | \ No newline at end of file | ... | ... |