Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO.Compression;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Collections;
- using System.Xml;
- using System.Net;
- using System.Net.NetworkInformation;
- using System.Net.Sockets;
- /*
- _____ _ _____ _ _
- | __ \ (_) / ___(_) | |
- | | \/_ _ __ _ _ __ __ _ _ __ __ _ _ __ _ \ `--. _ ___| |_ ___ _ __ ___ __ _ ___
- | | __| | | |/ _` | '__/ _` | '_ \ / _` | '__| | `--. \ / __| __/ _ \ '_ ` _ \ / _` / __|
- | |_\ \ |_| | (_| | | | (_| | |_) | (_| | | | | /\__/ / \__ \ || __/ | | | | | (_| \__ \
- \____/\__,_|\__,_|_| \__,_| .__/ \__,_|_| |_| \____/|_|___/\__\___|_| |_| |_|\__,_|___/
- | |
- |_|
- Powered By Luck | First compile 05/05/2016
- */
- namespace ConsoleApplication1
- {
- class Program
- {
- /*Classe de verificacao de processos*/
- public static int verificaProcesso()
- {
- string sysmocom = "SysmoCom";//Nome do processo a ser descoberto
- string ftpserver = "FTPServ";
- string sysmovs = "sysmovs";
- int processo = 0;
- try
- {
- var processss = from proc in System.Diagnostics.Process.GetProcesses() orderby proc.ProcessName ascending select proc;
- System.Threading.Thread.Sleep(10000);
- Console.WriteLine("\n\n Verificando processos abertos.... \n\n");
- foreach (var item in processss)//Lista todos processos
- {
- // Console.WriteLine(item.ProcessName);
- if (item.ProcessName == sysmocom){processo = 1;} else if (item.ProcessName == ftpserver) { processo = 1; }else if(item.ProcessName == sysmovs) {
- Console.WriteLine("Sysmo S1 Está aberto! \n Fechando...");
- Process.Start("taskkill", "/F /IM "+ sysmovs + ".exe");
- }
- }
- }
- catch{}
- return processo;
- }
- public static string localIPAddress()
- {
- IPHostEntry host;
- string localIP = "";
- host = Dns.GetHostEntry(Dns.GetHostName());
- foreach (IPAddress ip in host.AddressList)
- {
- localIP = ip.ToString();
- string[] temp = localIP.Split('.');
- if (ip.AddressFamily == AddressFamily.InterNetwork && temp[0] == "192") { break; } else {localIP = null;}
- }
- return localIP;
- }
- static void Main(string[] args)
- {
- // System.IO.File.Copy(@"\\192.168.1.249\completo\versao.xml", "c:\\sysmovs\\", true);
- string ultimoUp = "";
- XmlDocument xml = new XmlDocument();
- xml.Load(@"\\192.168.1.249\completo\atualizacaosysmo\versao.xml");
- XmlNodeList xnList = xml.SelectNodes("/config/versao");
- foreach (XmlNode xn in xnList){ultimoUp = xn["ultimoUp"].InnerText;}
- Console.WriteLine("\nData atualizacao Update: {0} \n", ultimoUp);
- string diaUp = ultimoUp.Substring(0, 2);
- string mesUp = ultimoUp.Substring(3, 2);
- string anoUp = ultimoUp.Substring(6, 4);
- string diaUpOld = "";
- string mesUpOld = "";
- string anoUpOld = "";
- int verifica = 0;
- int temporizador = 5;//temporizador da finalização do update
- string versao = "1.0";
- //Console.WriteLine("Dia {0} Mes {1} Ano {2}", diaUp, mesUp, anoUp);
- if (File.Exists(@"c:\sysmovs\versao.xml"))
- {
- Console.WriteLine("Verifica data");
- string ultimoUpOld = "";
- XmlDocument xmlold = new XmlDocument();
- xmlold.Load(@"c:\sysmovs\versao.xml");
- XmlNodeList xnListold = xmlold.SelectNodes("/config/versao");
- foreach (XmlNode xns in xnListold) { ultimoUpOld = xns["ultimoUp"].InnerText; }
- Console.WriteLine("data Ultimo Update: {0} ", ultimoUpOld);
- diaUpOld = ultimoUpOld.Substring(0, 2);
- mesUpOld = ultimoUpOld.Substring(3, 2);
- anoUpOld = ultimoUpOld.Substring(6, 4);
- // Console.WriteLine("Dia {0} Mes {1} Ano {2}", diaUp, mesUp, anoUp);
- }
- else {
- Console.WriteLine("Não tem copiando...");
- System.IO.File.Copy(@"\\192.168.1.249\completo\atualizacaosysmo\versao.xml", @"C:\sysmovs\versao.xml", true);
- Console.WriteLine("Verifica data");
- string ultimoUpOld = "";
- XmlDocument xmlold = new XmlDocument();
- xmlold.Load(@"c:\sysmovs\versao.xml");
- XmlNodeList xnListold = xmlold.SelectNodes("/config/versao");
- foreach (XmlNode xns in xnListold) { ultimoUpOld = xns["ultimoUp"].InnerText; }
- Console.WriteLine("data Ultimo Update: {0} ", ultimoUpOld);
- diaUpOld = ultimoUpOld.Substring(0, 2);
- mesUpOld = ultimoUpOld.Substring(3, 2);
- anoUpOld = ultimoUpOld.Substring(6, 4);
- verifica = 1;
- }
- DateTime date1 = new DateTime(Int32.Parse(anoUp), Int32.Parse(mesUp), Int32.Parse(diaUp), 0, 0, 0);
- DateTime date2 = new DateTime(Int32.Parse(anoUpOld), Int32.Parse(mesUpOld), Int32.Parse(diaUpOld), 0, 0, 0);
- int result = DateTime.Compare(date1, date2);
- //Verifica relacao entre datas
- if (verifica == 0) {
- Console.WriteLine("Entrou1");
- string relationship;
- if (result < 0) {
- relationship = "é mais antigo que"; Environment.Exit(0);
- }
- else {
- if (result == 0){
- Console.WriteLine("Entrou2");
- if (verifica == 1) {
- Console.WriteLine("Primeiro Update com o Sysmo atualizador");
- }else{
- Console.WriteLine("Entrou3");
- relationship = "Seu S1 Já está atualizado.";
- Console.WriteLine(relationship);
- System.Threading.Thread.Sleep(5000); Environment.Exit(0); Console.WriteLine("{0} {1} {2}", date1, relationship, date2);
- }
- }
- else { relationship = "é mais novo que"; Console.WriteLine("{0} {1} {2}", date1, relationship, date2);}
- }
- }
- Console.ResetColor();
- Console.WriteLine("=================Sysmo S1 Atualizador {0}=============",versao);
- Type stypez = typeof(ConsoleColor);
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine(" _____ _ _____ _ _ ");
- Console.WriteLine(@"| __ \ (_) / ___(_) | | ");
- Console.WriteLine(@"| | \/_ _ __ _ _ __ __ _ _ __ __ _ _ __ _ \ `--. _ ___| |_ ___ _ __ ___ __ _ ___ ");
- Console.WriteLine(@"| | __| | | |/ _` | '__/ _` | '_ \ / _` | '__| | `--. \ / __| __/ _ \ '_ ` _ \ / _` / __|");
- Console.WriteLine(@"| |_\ \ |_| | (_| | | | (_| | |_) | (_| | | | | /\__/ / \__ \ || __/ | | | | | (_| \__ \");
- Console.WriteLine(@" \____/\__,_|\__,_|_| \__,_| .__/ \__,_|_| |_| \____/|_|___/\__\___|_| |_| |_|\__,_|___/");
- Console.WriteLine(" | | ");
- Console.WriteLine(" |_| ");
- Console.ResetColor();
- Console.WriteLine("=================Sysmo S1 Atualizador {0}=============", versao);
- Type stype1 = typeof(ConsoleColor);
- Console.ForegroundColor = ConsoleColor.White;
- //Console.WriteLine("Nenhuma nova atualização encontrada.");
- Console.WriteLine("Encontramos uma nova atualização de seu sistema\n\n {0} ",ultimoUp);
- Type stype2 = typeof(ConsoleColor);
- Console.ForegroundColor = ConsoleColor.Red;
- Console.BackgroundColor = ConsoleColor.White;
- System.Threading.Thread.Sleep(2000);
- Console.WriteLine("NÃO FECHE ESTA JANELA ESTAMOS ATUALIZANDO SEU SYSMO S1\n\n");
- Console.ResetColor();
- Console.WriteLine("Começando processo de update");
- string fileName = "versoes.zip";
- string sourcePath = @"\\192.168.1.249\completo\atualizacaosysmo";
- string targetPath = @"C:\Users\Public\";
- string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
- string destFile = System.IO.Path.Combine(targetPath, fileName);
- string sysmofolder = @"c:\sysmovs\";
- FileInfo tamanho = new FileInfo(sourcePath.ToString() + "\\" + fileName.ToString());
- Console.WriteLine("Tamanho da atualização {0} MB", ((tamanho.Length) / 1024) / 1024);//verifica o tamanho do update
- while (verificaProcesso() == 1) {
- DateTime dateTime = DateTime.Now;
- Console.WriteLine(dateTime);
- string sub = dateTime.ToString().Substring(0, 2);
- string subh = dateTime.ToString().Substring(11,2);
- int h = Int32.Parse(subh);
- int d = Int32.Parse(sub);
- int senha = d * h;
- Type stype = typeof(ConsoleColor);
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("\n\nEstá aberto o sysmocom ou FTPServer\n Verifique por favor!\n\n SENHA: " + senha);
- System.Threading.Thread.Sleep(5000);
- }
- Console.ResetColor();
- if (!System.IO.Directory.Exists(targetPath))
- {
- Console.WriteLine("Criando diretorio (" + targetPath + ")");
- System.IO.Directory.CreateDirectory(targetPath);
- }
- Console.WriteLine("\n----------------------------------------------------------\n");
- Console.WriteLine("Aguarde Estamos copiando a atualização... ("+fileName+")");
- Console.WriteLine("\n----------------------------------------------------------\n");
- System.IO.File.Copy(sourceFile, destFile, true);
- FileInfo arquivo = new FileInfo(destFile);
- while (arquivo.Length < tamanho.Length) { Console.WriteLine("Tamanho da atualização {0} MB", ((arquivo.Length) / 1024) / 1024); }//verifica o tamanho do update
- if (!System.IO.Directory.Exists(sysmofolder)){Console.WriteLine("Criando diretorio (" + sysmofolder + ")"); System.IO.Directory.CreateDirectory(sysmofolder); }
- Console.WriteLine("Descompatando atualização em "+ sysmofolder);
- System.IO.Compression.ZipArchive archive = ZipFile.OpenRead(targetPath + fileName);
- //Extrair arquivos
- foreach (ZipArchiveEntry entry in archive.Entries) { Console.WriteLine("Instalando atualização {0}", entry); entry.ExtractToFile(Path.Combine(sysmofolder, entry.FullName), true); }
- Console.WriteLine("Atualizando Versao.xml");
- System.IO.File.Copy(@"\\192.168.1.249\completo\atualizacaosysmo\versao.xml", @"C:\sysmovs\versao.xml", true);//ataulizando versoes
- Console.ResetColor();
- Type typez = typeof(ConsoleColor);
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("\n\n=================================\n \n Atualização Concluida com sucesso \n\n ================================= ");
- try
- {
- string Ip = localIPAddress();//localIPAddress(); Pega o Ip da maquina
- string finalIp = Ip.Substring(10, 3);
- Console.WriteLine(finalIp);
- int ipFinal = Int32.Parse(finalIp);
- if (ipFinal == 100)
- {
- Console.WriteLine("Abrindo FTP SERVER E SYSMOCOM.");
- try{ Process.Start(@"c:\sysmovs\FTPServ.exe");}
- catch{ Console.WriteLine("FTPServ Não encontrado");}
- try{ Process.Start(@"c:\sysmovs\SysmoCom.exe");}
- catch{ Console.WriteLine("SysmoCom Não encontrado");}
- }
- Console.WriteLine("Continuando instalação.");
- }
- catch { Console.WriteLine("Este computador é cliente."); }
- for (int i = temporizador; i >= 0; i--)
- {
- Console.WriteLine("Finalizando em Instalação em {0}", i);
- System.Threading.Thread.Sleep(2000);
- }
- Environment.Exit(0);//Fecha o Console
- //Console.ReadKey(); Precione uma tecla para continuar
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement