Commit 15994223e318613af3c97471c285b43467c5c143

Authored by CaioMoraes
1 parent 40849d9f
Exists in Au-ghub/master

Adição das classes BundlesManager e Requirements

Refatoração do código em mais duas classes e adição da extração com
sobreescrita. BundlesManager para download e extração dos pacotes de
sinais e Requirements para verificação e instalação dos requisitos do
VLibras.
@@ -26,9 +26,9 @@ @@ -26,9 +26,9 @@
26 <UpdateUrl>http://150.165.205.137:8080/</UpdateUrl> 26 <UpdateUrl>http://150.165.205.137:8080/</UpdateUrl>
27 <ProductName>VLIBRAS</ProductName> 27 <ProductName>VLIBRAS</ProductName>
28 <PublisherName>LAVID-UFPB</PublisherName> 28 <PublisherName>LAVID-UFPB</PublisherName>
29 - <MinimumRequiredVersion>1.0.0.67</MinimumRequiredVersion> 29 + <MinimumRequiredVersion>1.0.0.82</MinimumRequiredVersion>
30 <OpenBrowserOnPublish>false</OpenBrowserOnPublish> 30 <OpenBrowserOnPublish>false</OpenBrowserOnPublish>
31 - <ApplicationRevision>77</ApplicationRevision> 31 + <ApplicationRevision>94</ApplicationRevision>
32 <ApplicationVersion>1.0.0.%2a</ApplicationVersion> 32 <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
33 <UseApplicationTrust>true</UseApplicationTrust> 33 <UseApplicationTrust>true</UseApplicationTrust>
34 <CreateDesktopShortcut>true</CreateDesktopShortcut> 34 <CreateDesktopShortcut>true</CreateDesktopShortcut>
@@ -86,6 +86,7 @@ @@ -86,6 +86,7 @@
86 <Reference Include="System.Core" /> 86 <Reference Include="System.Core" />
87 <Reference Include="System.IO.Compression" /> 87 <Reference Include="System.IO.Compression" />
88 <Reference Include="System.IO.Compression.FileSystem" /> 88 <Reference Include="System.IO.Compression.FileSystem" />
  89 + <Reference Include="System.Net" />
89 <Reference Include="System.Xml.Linq" /> 90 <Reference Include="System.Xml.Linq" />
90 <Reference Include="System.Data.DataSetExtensions" /> 91 <Reference Include="System.Data.DataSetExtensions" />
91 <Reference Include="Microsoft.CSharp" /> 92 <Reference Include="Microsoft.CSharp" />
@@ -96,6 +97,7 @@ @@ -96,6 +97,7 @@
96 <Reference Include="System.Xml" /> 97 <Reference Include="System.Xml" />
97 </ItemGroup> 98 </ItemGroup>
98 <ItemGroup> 99 <ItemGroup>
  100 + <Compile Include="BundlesManager.cs" />
99 <Compile Include="Form1.cs"> 101 <Compile Include="Form1.cs">
100 <SubType>Form</SubType> 102 <SubType>Form</SubType>
101 </Compile> 103 </Compile>
@@ -104,6 +106,7 @@ @@ -104,6 +106,7 @@
104 </Compile> 106 </Compile>
105 <Compile Include="Program.cs" /> 107 <Compile Include="Program.cs" />
106 <Compile Include="Properties\AssemblyInfo.cs" /> 108 <Compile Include="Properties\AssemblyInfo.cs" />
  109 + <Compile Include="Requirements.cs" />
107 <EmbeddedResource Include="Form1.resx"> 110 <EmbeddedResource Include="Form1.resx">
108 <DependentUpon>Form1.cs</DependentUpon> 111 <DependentUpon>Form1.cs</DependentUpon>
109 </EmbeddedResource> 112 </EmbeddedResource>
BundlesManager.cs 0 → 100644
@@ -0,0 +1,148 @@ @@ -0,0 +1,148 @@
  1 +using System;
  2 +using System.Net;
  3 +using System.IO;
  4 +using System.IO.Compression;
  5 +
  6 +namespace VLIBRAS_II
  7 +{
  8 + static class BundlesManager
  9 + {
  10 +
  11 + public static void ExtractToDirectory(this ZipArchive archive, string destinationDirectoryName, bool overwrite){
  12 + if (!overwrite){
  13 + archive.ExtractToDirectory(destinationDirectoryName);
  14 + return;
  15 + }
  16 + foreach (ZipArchiveEntry file in archive.Entries){
  17 + string completeFileName = Path.Combine(destinationDirectoryName, file.FullName);
  18 + string directory = Path.GetDirectoryName(completeFileName);
  19 + Console.WriteLine("Extraindo "+file.FullName+".");
  20 + if (!Directory.Exists(directory)){
  21 + Directory.CreateDirectory(directory);
  22 + }
  23 +
  24 + if (file.Name != ""){
  25 + file.ExtractToFile(completeFileName, true);
  26 + }
  27 + }
  28 + }
  29 +
  30 + private static bool RemoteFileExists(string url){
  31 + try{
  32 + //Creating the HttpWebRequest
  33 + HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
  34 + //Setting the Request method HEAD
  35 + request.Method = "HEAD";
  36 + request.Timeout = 2000;
  37 + //Getting the Web Response.
  38 + HttpWebResponse response = request.GetResponse() as HttpWebResponse;
  39 + //Returns TURE if the Status code == 200
  40 + return (response.StatusCode == HttpStatusCode.OK);
  41 + }
  42 + catch{
  43 + //Any exception will returns false.
  44 + return false;
  45 + }
  46 + }
  47 +
  48 + //File.Exists(path);
  49 +
  50 + private static bool RemoteIsNewerThanLocal(string url, string path){
  51 + FileInfo sourceFile = new FileInfo(path);
  52 + var request = (HttpWebRequest)WebRequest.Create(url);
  53 + request.Method = "HEAD";
  54 + var response = (HttpWebResponse)request.GetResponse();
  55 + //Console.WriteLine("response.LastModified: "+response.LastModified);
  56 + //Console.WriteLine("sourceFile.LastWriteTime: "+sourceFile.LastWriteTime);
  57 + if(response.LastModified > sourceFile.LastWriteTime){
  58 + return true;
  59 + }else{
  60 + return false;
  61 + }
  62 + }
  63 +
  64 + private static void DownloadFileToPath(string site, string path){
  65 + try{
  66 + WebClient webClient = new WebClient();
  67 + webClient.DownloadFile(site, path);
  68 + }catch(Exception e){
  69 + Console.WriteLine("Erro: {0}", e);
  70 + }
  71 + }
  72 +
  73 + public static int DownloadBundlesPackages(string url, string rootPath, string extractPath){
  74 + //rootPath é o path dos arquivos .zip locais
  75 + //url é o path dos arquivos .zip remotos
  76 + //extractPath é o path da pasta Bundles
  77 + string ext = @".zip";
  78 + int i = 1;
  79 + string remote;
  80 + string local;
  81 + while(true){
  82 + remote = url+i.ToString()+ext;
  83 + local = rootPath+i.ToString()+ext;
  84 + if(!RemoteFileExists(remote)){
  85 + //NECESSÁRIO PARA EVITAR IndexOutOfRange
  86 + i--;
  87 + break;
  88 + }else{
  89 + if(!File.Exists(local)){
  90 + DownloadFileToPath(remote, local);
  91 + }else{
  92 + if(RemoteIsNewerThanLocal(remote, local)){
  93 + DownloadFileToPath(remote, local);
  94 + //DELETA ARQUIVO DE VERIFICAÇÃO PARA QUE HAJA NOVA EXTRAÇÃO
  95 + File.Delete(extractPath + i);
  96 + }
  97 + }
  98 + }
  99 + i++;
  100 + }
  101 + return i;
  102 + }
  103 +
  104 + public static void ExtractBundlesPackages(string rootPath, string extractPath, int qtd){
  105 + string ext = @".zip";
  106 + bool exists = System.IO.Directory.Exists(extractPath);
  107 + if(!exists){
  108 + System.IO.Directory.CreateDirectory(extractPath);
  109 + }
  110 +
  111 + while(qtd > 0){
  112 + if(!File.Exists(extractPath+qtd.ToString())){
  113 + string zip = rootPath+qtd.ToString()+ext;
  114 + Console.WriteLine("Extraindo o arquivo: "+zip);
  115 + ZipFile.ExtractToDirectory(zip, extractPath);
  116 + //CRIA UM ARQUIVO 1(SEM EXTENSÃO), 2, 3... NA PASTA BUNDLES PARA VERIFICAÇÃO DE EXTRAÇÃO PRÉVIA
  117 + //SÓ É CRIADO APÓS EXTRAÇÃO DE TODOS OS ARQUIVOS DE CADA ZIP
  118 + Console.WriteLine("Extração do arquivo "+zip+" concluída.");
  119 + File.Create(extractPath+qtd).Close();
  120 + }
  121 + qtd--;
  122 + }
  123 + }
  124 + //ZipArchive archive = ZipFile.Open(fileAbsolute, ZipArchiveMode.Read, System.Text.Encoding.GetEncoding(System.Globalization.CultureInfo.CurrentCulture.TextInfo.OEMCodePage));
  125 + public static void ExtractBundlesPackagesOverWrite(string rootPath, string extractPath, int qtd){
  126 + string ext = @".zip";
  127 + bool exists = System.IO.Directory.Exists(extractPath);
  128 + if(!exists){
  129 + System.IO.Directory.CreateDirectory(extractPath);
  130 + }
  131 +
  132 + while(qtd > 0){
  133 + if(!File.Exists(extractPath+qtd.ToString())){
  134 + string fileAbsolute = rootPath+qtd.ToString()+ext;
  135 + ZipArchive zip = ZipFile.Open(fileAbsolute, ZipArchiveMode.Read, System.Text.Encoding.GetEncoding(System.Globalization.CultureInfo.CurrentCulture.TextInfo.OEMCodePage));
  136 + Console.WriteLine("Extraindo o arquivo: "+zip);
  137 + //ZipFile.ExtractToDirectory(zip, extractPath);
  138 + ExtractToDirectory(zip, extractPath, true);
  139 + //CRIA UM ARQUIVO 1(SEM EXTENSÃO), 2, 3... NA PASTA BUNDLES PARA VERIFICAÇÃO DE EXTRAÇÃO PRÉVIA
  140 + //SÓ É CRIADO APÓS EXTRAÇÃO DE TODOS OS ARQUIVOS DE CADA ZIP
  141 + Console.WriteLine("Extração do arquivo "+zip+" concluída.");
  142 + File.Create(extractPath+qtd).Close();
  143 + }
  144 + qtd--;
  145 + }
  146 + }
  147 + }
  148 +}
1 using System; 1 using System;
2 -using System.Collections.Generic;  
3 -using System.Linq;  
4 -using System.Threading.Tasks;  
5 -using System.Windows.Forms;  
6 using System.Diagnostics; 2 using System.Diagnostics;
7 -using System.Security.Permissions;  
8 -using Microsoft.Win32;  
9 using System.Net; 3 using System.Net;
10 -using System.Collections; 4 +using Microsoft.Win32;
11 using System.IO; 5 using System.IO;
12 using System.IO.Compression; 6 using System.IO.Compression;
13 7
14 -namespace AU 8 +namespace VLIBRAS_II
15 { 9 {
16 static class Program 10 static class Program
17 { 11 {
18 - public static bool RemoteFileExists(string url){  
19 - try{  
20 - //Creating the HttpWebRequest  
21 - HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;  
22 - //Setting the Request method HEAD  
23 - request.Method = "HEAD";  
24 - //Getting the Web Response.  
25 - HttpWebResponse response = request.GetResponse() as HttpWebResponse;  
26 - //Returns TURE if the Status code == 200  
27 - return (response.StatusCode == HttpStatusCode.OK);  
28 - }  
29 - catch{  
30 - //Any exception will returns false.  
31 - return false;  
32 - }  
33 - }  
34 -  
35 - //File.Exists(path);  
36 -  
37 - public static bool RemoteIsNewerThanLocal(string url, string path){  
38 - FileInfo sourceFile = new FileInfo(path);  
39 - var request = (HttpWebRequest)WebRequest.Create(url);  
40 - request.Method = "HEAD";  
41 - var response = (HttpWebResponse)request.GetResponse();  
42 - //Console.WriteLine("response.LastModified: "+response.LastModified);  
43 - //Console.WriteLine("sourceFile.LastWriteTime: "+sourceFile.LastWriteTime);  
44 - if(response.LastModified > sourceFile.LastWriteTime){  
45 - return true;  
46 - }else{  
47 - return false;  
48 - }  
49 - }  
50 -  
51 - public static void DownloadFileToPath(string site, string path){  
52 - try{  
53 - WebClient webClient = new WebClient();  
54 - webClient.DownloadFile(site, path);  
55 - }catch(Exception e){  
56 - Console.WriteLine("Erro: {0}", e);  
57 - }  
58 - }  
59 static void ResetEnvVar(){ 12 static void ResetEnvVar(){
60 string vLibrasAtual = Environment.GetEnvironmentVariable("PATH_VLIBRAS",EnvironmentVariableTarget.Machine); 13 string vLibrasAtual = Environment.GetEnvironmentVariable("PATH_VLIBRAS",EnvironmentVariableTarget.Machine);
61 string vLibrasNovo = Directory.GetCurrentDirectory(); 14 string vLibrasNovo = Directory.GetCurrentDirectory();
@@ -69,139 +22,113 @@ namespace AU @@ -69,139 +22,113 @@ namespace AU
69 System.Diagnostics.ProcessStartInfo resetProcInfo = new System.Diagnostics.ProcessStartInfo(); 22 System.Diagnostics.ProcessStartInfo resetProcInfo = new System.Diagnostics.ProcessStartInfo();
70 resetProcInfo.FileName = resetPath; 23 resetProcInfo.FileName = resetPath;
71 resetProcInfo.Verb = "runas"; //ADM 24 resetProcInfo.Verb = "runas"; //ADM
  25 + resetProcInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
72 //resetProcInfo.Arguments = comandoUnins; 26 //resetProcInfo.Arguments = comandoUnins;
73 27
74 System.Diagnostics.Process resetProc = new System.Diagnostics.Process(); 28 System.Diagnostics.Process resetProc = new System.Diagnostics.Process();
75 resetProc.StartInfo = resetProcInfo; 29 resetProc.StartInfo = resetProcInfo;
76 resetProc.Start(); 30 resetProc.Start();
77 - resetProc.WaitForExit();  
78 - }  
79 - }  
80 -  
81 - static void desinstalarVLibras(RegistryKey reg){  
82 - //Variáveis para desinstalação  
83 - System.Diagnostics.Process uninsProc = new System.Diagnostics.Process();  
84 - System.Diagnostics.ProcessStartInfo uninsProcInfo = new System.Diagnostics.ProcessStartInfo();  
85 - //uninsProcInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;  
86 - uninsProcInfo.FileName = "cmd.exe";  
87 - string comandoUnins;  
88 - comandoUnins = "/C" + reg.GetValue("QuietUninstallString").ToString().Replace("\"", "");  
89 - uninsProcInfo.Arguments = comandoUnins;  
90 - uninsProc.StartInfo = uninsProcInfo;  
91 - uninsProc.Start();  
92 - uninsProc.WaitForExit();  
93 - }  
94 -  
95 - static void instalarPython(int opSys){  
96 - //Console.WriteLine("Por favor, confirme a instalação do Python 2.7.9");  
97 - string[] buscaPython;  
98 - if(opSys == 64){  
99 - buscaPython = Directory.GetFiles(Directory.GetCurrentDirectory(), "python-2.7.9.amd64.msi", SearchOption.AllDirectories);  
100 - }else{  
101 - buscaPython = Directory.GetFiles(Directory.GetCurrentDirectory(), "python-2.7.9.msi", SearchOption.AllDirectories); 31 + //resetProc.WaitForExit();
102 } 32 }
103 - string pythonPath = buscaPython[0];  
104 - string comandoIns = "/C" + pythonPath;  
105 -  
106 - System.Diagnostics.ProcessStartInfo insProcInfo = new System.Diagnostics.ProcessStartInfo();  
107 - System.Diagnostics.Process insProc = new System.Diagnostics.Process();  
108 -  
109 - insProcInfo.FileName = "cmd.exe";  
110 - insProcInfo.Arguments = comandoIns;  
111 - //insProcInfo.Verb = "runas"; //ADM  
112 -  
113 - insProc.StartInfo = insProcInfo;  
114 - insProc.Start();  
115 - insProc.WaitForExit();  
116 -  
117 } 33 }
118 34
119 [STAThread] 35 [STAThread]
120 static void Main() 36 static void Main()
121 { 37 {
122 -  
123 - //VERFICAÇÃO E DESINSTALAÇÃO DO VLIBRAS DESCONTINUADO  
124 - //Variáveis para verificar se há instalação no registro 38 + //ENDEREÇO DE ONDE SERÃO BAIXADOS OS PACOTES (.ZIP) DE SINAIS (1.ZIP, 2.ZIP E ETC...)
  39 + string url = @"http://150.165.205.137:8080/";
  40 + string dirAtual = Directory.GetCurrentDirectory();
  41 + string[] buscaDeArquivo;
  42 + //Variáveis para verificar se há instalação no registro em lm64 e 32 (local machine x64 e x86)
125 var lm64 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64); 43 var lm64 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
126 var lm32 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32); 44 var lm32 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
127 - RegistryKey reg;  
128 - RegistryKey reg2;  
129 - RegistryKey reg3;  
130 - RegistryKey reg4;  
131 45
132 - bool tentouX64 = false;  
133 - Console.WriteLine("Verificação se há versões descontinuadas do VLibras.");  
134 - //x64  
135 - try{  
136 - reg = lm64.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{84B73167-EF7F-42BB-9CCD-E1A8E2C53659-vlibras}_is1");  
137 - if(reg == null){  
138 - Console.WriteLine("Chave do 64 é nula.");  
139 - Console.WriteLine("UninstallString 64: nenhum.");  
140 - Console.WriteLine("QuietUninstallString 64: nenhum.");  
141 - }else{  
142 - tentouX64 = true;  
143 - Console.WriteLine("Chave: "+reg.ToString());  
144 - Console.WriteLine("UninstallString 64: "+reg.GetValue("UninstallString").ToString().Replace("\"", ""));  
145 - Console.WriteLine("QuietUninstallString 64: "+reg.GetValue("QuietUninstallString").ToString().Replace("\"", ""));  
146 - //desinstalação da versão x64  
147 - Console.WriteLine("Desinstalando a versão descontinuada do VLibras x64. Por favor, aguarde.");  
148 - desinstalarVLibras(reg);  
149 - //Console.WriteLine("Desinstalou a versão descontinuada do VLibras x64.");  
150 - }  
151 - }catch(Exception e){  
152 - Console.WriteLine("Erro x64: {0}",e); 46 +
  47 + //EXTRAÇÃO DO VLIBRAS
  48 + string vlibrasZip = @"VLIBRAS.zip";
  49 + string vlibrasZipAbsolute = dirAtual+@"\"+vlibrasZip;
  50 + ZipArchive archive = ZipFile.Open(vlibrasZipAbsolute, ZipArchiveMode.Read, System.Text.Encoding.GetEncoding(System.Globalization.CultureInfo.CurrentCulture.TextInfo.OEMCodePage));
  51 + if(!File.Exists(dirAtual+@"\"+@"extraido")){
  52 + Console.WriteLine("Extraindo do arquivo: "+vlibrasZip);
  53 + BundlesManager.ExtractToDirectory(archive, dirAtual, true);
  54 + Console.WriteLine("Extração do arquivo "+vlibrasZip+" concluída.");
  55 + File.Create(dirAtual+@"\"+@"extraido").Close();
153 } 56 }
154 57
155 - Console.WriteLine("");  
156 58
157 - //x86  
158 - if(!tentouX64){  
159 - try{  
160 - reg = lm32.OpenSubKey(@"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{84B73167-EF7F-42BB-9CCD-E1A8E2C53659-vlibras}_is1");  
161 - if(reg == null){  
162 - Console.WriteLine("Chave do 32 é nula.");  
163 - Console.WriteLine("UninstallString 32: nenhum.");  
164 - Console.WriteLine("QuietUninstallString 32: nenhum.");  
165 - }else{  
166 - Console.WriteLine("Chave: "+reg.ToString());  
167 - Console.WriteLine("UninstallString 32: "+reg.GetValue("UninstallString").ToString().Replace("\"", ""));  
168 - Console.WriteLine("QuietUninstallString 32: "+reg.GetValue("QuietUninstallString").ToString().Replace("\"", ""));  
169 - //desinstalação da versão x86  
170 - Console.WriteLine("Desinstalando a versão descontinuada do VLibras x86. Por favor, aguarde.");  
171 - desinstalarVLibras(reg);  
172 - //Console.WriteLine("Desinstalou a versão descontinuada do VLibras x86.");  
173 - }  
174 - }catch(Exception e){  
175 - Console.WriteLine("Erro x86: {0}",e);  
176 - } 59 + //EXTRAÇÃO DOS REQUISITOS
  60 + string reqZip = @"requisitos.zip";
  61 + string reqZipAbsolute = dirAtual+@"\"+reqZip;
  62 + archive = ZipFile.Open(reqZipAbsolute, ZipArchiveMode.Read, System.Text.Encoding.GetEncoding(System.Globalization.CultureInfo.CurrentCulture.TextInfo.OEMCodePage));
  63 + if(!File.Exists(dirAtual+@"\"+@"extraidoReq")){
  64 + Console.WriteLine("Extraindo do arquivo: "+reqZip);
  65 + BundlesManager.ExtractToDirectory(archive, dirAtual, true);
  66 + Console.WriteLine("Extração do arquivo "+reqZip+" concluída.");
  67 + File.Create(dirAtual+@"\"+@"extraidoReq").Close();
177 } 68 }
178 69
179 - Console.WriteLine("");  
180 - Console.WriteLine("Verificando se o Python 2.7.9 está instalado");  
181 70
182 - //VERIFICAÇÃO DO INTERPRETADOR PYTHON 71 +
  72 + //VERIFICAÇÃO E DESINSTALAÇÃO DO VLIBRAS DESCONTINUADO
  73 + Console.WriteLine("Verificação se há versões descontinuadas do VLibras.");
183 //x64 74 //x64
184 - try{  
185 - reg = lm64.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{79F081BF-7454-43DB-BD8F-9EE596813232}");  
186 - reg2 = lm64.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{79F081BF-7454-43DB-BD8F-9EE596813233}");  
187 - reg3 = lm32.OpenSubKey(@"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{79F081BF-7454-43DB-BD8F-9EE596813232}");  
188 - reg4 = lm32.OpenSubKey(@"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{79F081BF-7454-43DB-BD8F-9EE596813233}");  
189 - if(reg == null && reg2 == null && reg3 == null && reg4 == null){  
190 - Console.WriteLine("O python 2.7.9 não se encontra instalado. Por confirme a instalação.");  
191 - if(Environment.Is64BitOperatingSystem){  
192 - instalarPython(64);  
193 - }else{  
194 - instalarPython(86);  
195 - }  
196 - }  
197 - }catch(Exception e){  
198 - Console.WriteLine("Erro python: {0}",e); 75 + RegistryKey[] regVLibrasOld = new RegistryKey[2];
  76 + regVLibrasOld[0] = lm64.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{84B73167-EF7F-42BB-9CCD-E1A8E2C53659-vlibras}_is1");
  77 + regVLibrasOld[1] = lm32.OpenSubKey(@"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{84B73167-EF7F-42BB-9CCD-E1A8E2C53659-vlibras}_is1");
  78 + Requirements.Uninstall(regVLibrasOld);
  79 +
  80 +
  81 + //REGISTROS DO PYTHON
  82 + RegistryKey[] regPython = new RegistryKey[4];
  83 + regPython[0] = lm64.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{79F081BF-7454-43DB-BD8F-9EE596813232}");
  84 + regPython[1] = lm64.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{79F081BF-7454-43DB-BD8F-9EE596813233}");
  85 + regPython[2] = lm32.OpenSubKey(@"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{79F081BF-7454-43DB-BD8F-9EE596813232}");
  86 + regPython[3] = lm32.OpenSubKey(@"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{79F081BF-7454-43DB-BD8F-9EE596813233}");
  87 + //VERIFICAÇÃO E INSTALAÇÃO DO PYTHON
  88 + Console.WriteLine("Verificando se o Python 2.7.9 está instalado");
  89 + if(!Requirements.IsInstalled(regPython)){
  90 + //PATHS DE INSTALAÇÃO DO PYTHON
  91 + buscaDeArquivo = Directory.GetFiles(dirAtual, "python-2.7.9.amd64.msi", SearchOption.AllDirectories);
  92 + string pythonPath64 = (buscaDeArquivo.Length > 0)? buscaDeArquivo[0]: @"";
  93 + buscaDeArquivo = Directory.GetFiles(dirAtual, "python-2.7.9.msi", SearchOption.AllDirectories);
  94 + string pythonPath86 = (buscaDeArquivo.Length > 0)? buscaDeArquivo[0]: @""; //O VALOR É 0 MESMO, POIS REALIZOU UMA NOVA BUSCA
  95 + Requirements.InstallAndWait(pythonPath64, pythonPath86);
  96 + }
  97 +
  98 +
  99 + //VERIFICAÇÃO E INSTALAÇÃO DE PYWIN32
  100 + //usa esse arquivo para verificação de instalação do pywin32
  101 + Console.WriteLine("Verificando instalação do Pywin32.");
  102 + RegistryKey[] regPywin32 = new RegistryKey[2];
  103 + regPywin32[0] = lm64.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\pywin32-py2.7");
  104 + regPywin32[1] = lm32.OpenSubKey(@"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\pywin32-py2.7");
  105 + //string pywin32File = @"..\Bundles\pywin32";
  106 + if(Requirements.IsInstalled(regPython) && !Requirements.IsInstalled(regPywin32)){//File.Exists(pywin32File)){
  107 + buscaDeArquivo = Directory.GetFiles(dirAtual, "pywin32-220.win-amd64-py2.7.exe", SearchOption.AllDirectories);
  108 + string pywin32Pathx64 = (buscaDeArquivo.Length > 0)? buscaDeArquivo[0] : @"";
  109 + buscaDeArquivo = Directory.GetFiles(dirAtual, "pywin32-220.win32-py2.7.exe", SearchOption.AllDirectories);
  110 + string pywin32Pathx86 = (buscaDeArquivo.Length > 0)? buscaDeArquivo[0] : @"";
  111 + Requirements.Install(pywin32Pathx64, pywin32Pathx86);
  112 + //File.Create(pywin32File).Close();
  113 + }
  114 +
  115 +
  116 + //VERIFICAÇÃO DA INSTALAÇÃO DO NVDA
  117 + Console.WriteLine("Verificando instalação do NVDA.");
  118 + //REGISTROS DO NDVA
  119 + RegistryKey[] regNVDA = new RegistryKey[3];
  120 + regNVDA[0] = lm64.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\NVDA");
  121 + regNVDA[1] = lm32.OpenSubKey(@"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\NVDA");
  122 + //PATH DO INSTALADOR DO NVDA
  123 + if(!Requirements.IsInstalled(regNVDA)){
  124 + buscaDeArquivo = Directory.GetFiles(dirAtual, "nvda_snapshot_source-master-4d792f0.exe", SearchOption.AllDirectories);
  125 + string NVDApath = (buscaDeArquivo.Length > 0)? buscaDeArquivo[0] : @"";
  126 + Requirements.Install(NVDApath, NVDApath);
199 } 127 }
200 128
201 - Console.WriteLine("");  
202 - Console.WriteLine("Checando as variáveis de ambiente.");  
203 129
204 //CONFIGURAÇÃO DAS VARIÁVEIS DE AMBIENTE 130 //CONFIGURAÇÃO DAS VARIÁVEIS DE AMBIENTE
  131 + Console.WriteLine("Checando as variáveis de ambiente.");
205 try{ 132 try{
206 ResetEnvVar(); 133 ResetEnvVar();
207 }catch(Exception e){ 134 }catch(Exception e){
@@ -209,157 +136,38 @@ namespace AU @@ -209,157 +136,38 @@ namespace AU
209 } 136 }
210 137
211 138
212 - Console.WriteLine("");  
213 //DOWNLOAD DOS SINAIS 139 //DOWNLOAD DOS SINAIS
214 - //BAIXA OS ZIPS DOS SINAIS  
215 - string url = @"http://127.0.0.1:8080/";  
216 - string path = @"..\"; 140 + //BAIXA OS ZIPS DOS SINAIS (1.ZIP, 2.ZIP E ETC...)
  141 + string rootPath = @"..\";
217 string extractPath = @"..\Bundles\"; 142 string extractPath = @"..\Bundles\";
218 - string ext = @".zip";  
219 - int i = 1;  
220 - string remote;  
221 - string local;  
222 - //baixa apenas se for mais recente ou se usuário não possuir cópia  
223 - while(true){  
224 - remote = url+i.ToString()+ext;  
225 - local = path+i.ToString()+ext;  
226 - if(!RemoteFileExists(remote)){  
227 - //NECESSÁRIO PARA EVITAR IndexOutOfRange  
228 - i--;  
229 - break;  
230 - }else{  
231 - if(!File.Exists(local)){  
232 - DownloadFileToPath(remote, local);  
233 - }else{  
234 - if(RemoteIsNewerThanLocal(remote, local)){  
235 - DownloadFileToPath(remote, local);  
236 - //DELETA ARQUIVO DE VERIFICAÇÃO PARA QUE HAJA NOVA EXTRAÇÃO  
237 - File.Delete(extractPath + i);  
238 - }  
239 - }  
240 - }  
241 - i++; 143 + int qtdDeBundles = 0;
  144 + Console.WriteLine("Baixando pacote de sinais.");
  145 + try{
  146 + qtdDeBundles = BundlesManager.DownloadBundlesPackages(url, rootPath, extractPath);
  147 + }catch(Exception e){
  148 + Console.WriteLine("Erro no download do pacote de sinais.");
242 } 149 }
243 150
244 151
245 //EXTRAÇÃO: 152 //EXTRAÇÃO:
246 //EXTRAI APENAS SE NÃO TIVER O ARQUIVO HOMÔNIMO SEM EXTENSÃO NA PASTA SINAIS 153 //EXTRAI APENAS SE NÃO TIVER O ARQUIVO HOMÔNIMO SEM EXTENSÃO NA PASTA SINAIS
247 //SE O CAMINHO DE EXTRAÇÃO NÃO EXISTE, ELE SERÁ CRIADO 154 //SE O CAMINHO DE EXTRAÇÃO NÃO EXISTE, ELE SERÁ CRIADO
248 - bool exists = System.IO.Directory.Exists(extractPath);  
249 - if(!exists){  
250 - System.IO.Directory.CreateDirectory(extractPath);  
251 - }  
252 -  
253 - while(i > 0){  
254 - if(!File.Exists(extractPath+i.ToString())){  
255 - string zip = path+i.ToString()+ext;  
256 - using (ZipArchive archive = ZipFile.Open(zip, ZipArchiveMode.Read, System.Text.Encoding.GetEncoding(System.Globalization.CultureInfo.CurrentCulture.TextInfo.OEMCodePage))){  
257 - foreach (ZipArchiveEntry entry in archive.Entries){  
258 - //POSSO FILTRAR E EXTRAIR APENAS ARQUIVOS QUE TERMINEM COM O VALOR DA STRING  
259 - if (entry.FullName.EndsWith("", StringComparison.OrdinalIgnoreCase))  
260 - {  
261 - entry.ExtractToFile(Path.Combine(extractPath, entry.FullName), true);  
262 - }  
263 - }  
264 - }  
265 - //CRIA UM ARQUIVO 1(SEM EXTENSÃO), 2, 3... NA PASTA BUNDLES PARA VERIFICAÇÃO DE EXTRAÇÃO PRÉVIA  
266 - //SÓ É CRIADO APÓS EXTRAÇÃO DE TODOS OS ARQUIVOS DE CADA ZIP  
267 - File.Create(extractPath+i).Close();  
268 - }  
269 - i--;  
270 - }  
271 -  
272 - //EXTRAI OS BUNDLES  
273 - /*//VERSÃO QUE EXTRAIA TODOS ZIPS NA PASTA SINAIS 155 + Console.WriteLine("Extraindo pacote de sinais.");
274 try{ 156 try{
275 - //ARRAY COM PATHS DOS ZIPS: "C:\...\blabla.zip"  
276 - string[] zipPaths = Directory.GetFiles(Directory.GetCurrentDirectory()+@"\Sinais\", "*.zip", SearchOption.AllDirectories);  
277 -  
278 - //ARRAY COM NOMES DOS ZIPS: "blabla"  
279 - string[] nomeZips = new string[zipPaths.Length];  
280 - for(int i = 0; i < zipPaths.Length; i++){  
281 - int slashIdx = zipPaths[i].LastIndexOf(@"\");  
282 - int extIdx = zipPaths[i].LastIndexOf(@".");  
283 - //Console.WriteLine("path>> "+zipPath);  
284 - //Console.WriteLine("removido a extensão>> "+zipPath.Remove(extIdx, 4));  
285 - //Console.WriteLine("nome do arquivo com extensão>> "+zipPath.Remove(0, slashIdx + 1));  
286 - Console.WriteLine("nome do arquivo sem extensão>> "+zipPaths[i].Remove(extIdx, 4).Remove(0, slashIdx + 1));  
287 - nomeZips[i] = zipPaths[i].Remove(extIdx, 4).Remove(0, slashIdx + 1);  
288 - //Console.WriteLine("nomeZips["+i+"]>> "+ nomeZips[i]);  
289 - }  
290 -  
291 - //EXTRAI UM ARQUIVO: "C:\...\pastaComZip\zipado.zip"  
292 - //EM: "C:\...\pastaComZip\zipado\arquivoQueEstavaEmZipado"  
293 - for(int i = 0; i < nomeZips.Length; i++){  
294 - string extractPath = zipPaths[i]+@"\..\..\..\Bundles\"; //volta duas e cria lá  
295 -  
296 - //SE O CAMINHO DE EXTRAÇÃO NÃO EXISTE, ELE SERÁ CRIADO  
297 - bool exists = System.IO.Directory.Exists(extractPath);  
298 - if(!exists){  
299 - System.IO.Directory.CreateDirectory(extractPath);  
300 - }  
301 - //EXTRAÇÃO DOS ARQUIVOS  
302 - using (ZipArchive archive = ZipFile.Open(zipPaths[i], ZipArchiveMode.Read, System.Text.Encoding.GetEncoding(System.Globalization.CultureInfo.CurrentCulture.TextInfo.OEMCodePage)))  
303 - {  
304 - foreach (ZipArchiveEntry entry in archive.Entries)  
305 - {  
306 - //POSSO FILTRAR E EXTRAIR APENAS ARQUIVOS QUE TERMINEM COM O VALOR DA STRING  
307 - if (entry.FullName.EndsWith("", StringComparison.OrdinalIgnoreCase))  
308 - {  
309 - entry.ExtractToFile(Path.Combine(extractPath, entry.FullName), true);  
310 - }  
311 - }  
312 - }  
313 - }  
314 - //DELETA O ZIP NO FINAL  
315 - for(int i = 0; i < zipPaths.Length; i++){  
316 - if(File.Exists(zipPaths[i])){  
317 - File.Delete(zipPaths[i]);  
318 - }  
319 - } 157 + BundlesManager.ExtractBundlesPackagesOverWrite(rootPath, extractPath, qtdDeBundles);
320 }catch(Exception e){ 158 }catch(Exception e){
321 - Console.WriteLine("ERRO ZipFile: {0}", e); 159 + Console.WriteLine("Erro na extração");
322 } 160 }
323 - */  
324 - /*//VERSÃO QUE CHECAVA UM ARQUIVO DICTIONARY_VERSION.TXT  
325 - try{  
326 - //string dictVer = System.IO.File.ReadAllText(@"dictionary_version.txt");  
327 - string[] dictVer = Directory.GetFiles(Directory.GetCurrentDirectory(), "dictVer.txt", SearchOption.AllDirectories);  
328 - if(dictVer.Length == 0){  
329 - Console.WriteLine("Path de DictVer.txt: null path");  
330 - }else{  
331 - Console.WriteLine("Path de DictVer.txt: " + dictVer[0]);  
332 - }  
333 - if(dictVer.Length == 0){  
334 - string[] buscaBundles = Directory.GetFiles(Directory.GetCurrentDirectory(), "Bundles.zip", SearchOption.AllDirectories);  
335 - string zipPath = buscaBundles[0];  
336 - string extractPath = buscaBundles[0] + @"\..\Bundles\";  
337 161
338 - using (ZipArchive archive = ZipFile.Open(zipPath, ZipArchiveMode.Read, System.Text.Encoding.GetEncoding(System.Globalization.CultureInfo.CurrentCulture.TextInfo.OEMCodePage)))  
339 - {  
340 - foreach (ZipArchiveEntry entry in archive.Entries)  
341 - {  
342 - if (entry.FullName.EndsWith("", StringComparison.OrdinalIgnoreCase))  
343 - {  
344 - entry.ExtractToFile(Path.Combine(extractPath, entry.FullName), true);  
345 - }  
346 - }  
347 - }  
348 - }  
349 - }catch(Exception e){  
350 - Console.WriteLine("ERRO ZipFile: {0}", e);  
351 - }  
352 - */  
353 162
  163 + //CONCLUSÃO
354 Console.WriteLine("Pré-requisitos verificados."); 164 Console.WriteLine("Pré-requisitos verificados.");
355 - //Console.ReadKey();  
356 -  
357 165
358 166
359 //RODA O VLIBRAS 167 //RODA O VLIBRAS
360 try{ 168 try{
361 Process playerProc = new Process(); 169 Process playerProc = new Process();
362 - string[] buscaPlayer = Directory.GetFiles(Directory.GetCurrentDirectory(), "vlibrasPlayer.exe", SearchOption.AllDirectories); 170 + string[] buscaPlayer = Directory.GetFiles(dirAtual, "vlibrasPlayer.exe", SearchOption.AllDirectories);
363 string player = buscaPlayer[0]; 171 string player = buscaPlayer[0];
364 playerProc.StartInfo.FileName = player; 172 playerProc.StartInfo.FileName = player;
365 playerProc.EnableRaisingEvents = true; 173 playerProc.EnableRaisingEvents = true;
@@ -374,6 +182,7 @@ namespace AU @@ -374,6 +182,7 @@ namespace AU
374 Application.SetCompatibleTextRenderingDefault(false); 182 Application.SetCompatibleTextRenderingDefault(false);
375 Application.Run(new Form1()); 183 Application.Run(new Form1());
376 */ 184 */
  185 +
377 } 186 }
378 } 187 }
379 } 188 }
Requirements.cs 0 → 100644
@@ -0,0 +1,97 @@ @@ -0,0 +1,97 @@
  1 +using System;
  2 +using Microsoft.Win32;
  3 +
  4 +namespace VLIBRAS_II
  5 +{
  6 + class Requirements
  7 + {
  8 + public static bool IsInstalled(RegistryKey[] regs){
  9 + foreach(RegistryKey reg in regs){
  10 + if(reg != null){
  11 + return true;
  12 + }
  13 + }
  14 + return false;
  15 + }
  16 +
  17 + public static bool IsInstalled(RegistryKey reg){
  18 + if(reg != null){
  19 + return true;
  20 + }else{
  21 + return false;
  22 + }
  23 + }
  24 +
  25 + public static void Uninstall(RegistryKey[] regs){
  26 + foreach(RegistryKey reg in regs){
  27 + if(IsInstalled(reg)){
  28 + try{
  29 + System.Diagnostics.Process uninsProc = new System.Diagnostics.Process();
  30 + System.Diagnostics.ProcessStartInfo uninsProcInfo = new System.Diagnostics.ProcessStartInfo();
  31 + uninsProcInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
  32 + uninsProcInfo.FileName = "cmd.exe";
  33 + string comandoUnins;
  34 + comandoUnins = "/C" + reg.GetValue("QuietUninstallString").ToString().Replace("\"", "");
  35 + uninsProcInfo.Arguments = comandoUnins;
  36 + uninsProc.StartInfo = uninsProcInfo;
  37 + uninsProc.Start();
  38 + //uninsProc.WaitForExit();
  39 + }catch(Exception e){
  40 + //NOTHING
  41 + }
  42 + }
  43 + }
  44 + }
  45 +
  46 + public static void Install(string pathInstaller64, string pathInstaller86){
  47 + string pathInstaller;
  48 + if(Environment.Is64BitOperatingSystem){
  49 + pathInstaller = pathInstaller64;
  50 + }else{
  51 + pathInstaller = pathInstaller86;
  52 + }
  53 + if(pathInstaller == ""){
  54 + return;
  55 + }
  56 + string comandoIns = "/C" + pathInstaller;
  57 + //Process e Process Information
  58 + System.Diagnostics.ProcessStartInfo insProcInfo = new System.Diagnostics.ProcessStartInfo();
  59 + insProcInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
  60 + System.Diagnostics.Process insProc = new System.Diagnostics.Process();
  61 +
  62 + insProcInfo.FileName = "cmd.exe";
  63 + insProcInfo.Arguments = comandoIns;
  64 + //insProcInfo.Verb = "runas"; //ADM
  65 +
  66 + insProc.StartInfo = insProcInfo;
  67 + insProc.Start();
  68 + //insProc.WaitForExit();
  69 + }
  70 +
  71 + public static void InstallAndWait(string pathInstaller64, string pathInstaller86){
  72 + string pathInstaller;
  73 + if(Environment.Is64BitOperatingSystem){
  74 + pathInstaller = pathInstaller64;
  75 + }else{
  76 + pathInstaller = pathInstaller86;
  77 + }
  78 + if(pathInstaller == ""){
  79 + return;
  80 + }
  81 + string comandoIns = "/C" + pathInstaller;
  82 + //Process e Process Information
  83 + System.Diagnostics.ProcessStartInfo insProcInfo = new System.Diagnostics.ProcessStartInfo();
  84 + insProcInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
  85 + System.Diagnostics.Process insProc = new System.Diagnostics.Process();
  86 +
  87 + insProcInfo.FileName = "cmd.exe";
  88 + insProcInfo.Arguments = comandoIns;
  89 + //insProcInfo.Verb = "runas"; //ADM
  90 +
  91 + insProc.StartInfo = insProcInfo;
  92 + insProc.Start();
  93 + insProc.WaitForExit();
  94 + }
  95 +
  96 + }
  97 +}