Example #1
0
        private string CheckProcessRun(VersionBo version)
        {
            string NomProc   = "";
            var    key       = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"SOFTWARE\WinperUpdate\" + ambiente);
            var    DirWinper = key.GetValue("DirWinper") == null ? "" : key.GetValue("DirWinper").ToString();

            key.Close();
            string query = "SELECT ExecutablePath, Name FROM Win32_Process";
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);

            foreach (ManagementObject item in searcher.Get())
            {
                object path        = item["ExecutablePath"];
                object processname = item["Name"];
                if (path != null && processname != null)
                {
                    Utils.RegistrarLog("CheckProcessRun.log", processname + " : " + path + " : DirWinper " + DirWinper + " : (" + new FileInfo(path.ToString()).Directory.FullName + ")");
                    Utils.RegistrarLog("CheckProcessRun.log", (version.Componentes.Exists(vercomp => vercomp.Name.Equals(processname.ToString(), StringComparison.OrdinalIgnoreCase))).ToString());
                    Utils.RegistrarLog("CheckProcessRun.log", (path.ToString().Replace(processname.ToString(), "").Equals(DirWinper, StringComparison.OrdinalIgnoreCase)).ToString());

                    if (version.Componentes.Exists(vercomp => vercomp.Name.Equals(processname.ToString(), StringComparison.OrdinalIgnoreCase)) &&
                        new FileInfo(path.ToString()).Directory.FullName.Equals(DirWinper))
                    {
                        NomProc += processname + " \n";
                    }
                }
            }

            return(NomProc);
        }
Example #2
0
        private void btnInstalar_Click(object sender, EventArgs e)
        {
            try
            {
                string dirTmp = Path.GetTempPath();
                dirTmp += dirTmp.EndsWith("\\") ? "" : "\\";
                dirTmp += "WinPer\\" + ambiente + "\\";

                string server = Utils.GetSetting("server");
                string port   = Utils.GetSetting("port");

                for (int i = 0; i < treeModulos.Nodes.Count; i++)
                {
                    string[] token = treeModulos.Nodes[i].Text.Split(new Char[] { ' ' });

                    var    version = new VersionBo();
                    string json    = Utils.StrSendMsg(server, int.Parse(port), "getversion#" + token[2] + "#");
                    version = JsonConvert.DeserializeObject <VersionBo>(json);

                    if (version != null)
                    {
                        string ProcRun = CheckProcessRun(version);
                        if (!string.IsNullOrEmpty(ProcRun))
                        {
                            MessageBox.Show(string.Format("Los siguientes procesos se deben cerrar para proceder con la actualización de Winper:\n\n{0}", ProcRun), "AVISO", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            return;
                        }
                        string dirComponentes = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\WinperSetupUI\\" + version.Release;
                        var    form           = new Instalar();
                        string fileInstalador = dirTmp + version.Release + "\\" + version.Instalador;
                        int    exitCode       = -1;
                        if (File.Exists(fileInstalador))
                        {
                            Utils.blockMenu = true;
                            this.Close();
                            form.ambiente = ambiente;
                            form.Show();

                            string Command = fileInstalador;

                            Process myProcess = new Process();
                            myProcess.StartInfo.FileName              = Command;
                            myProcess.StartInfo.Arguments             = string.Format("/DIR=\"{0}\" /VERYSILENT /SUPPRESSMSGBOXES /NORESTART /NOCANCEL", dirComponentes);
                            myProcess.StartInfo.WindowStyle           = ProcessWindowStyle.Normal;
                            myProcess.StartInfo.RedirectStandardError = true;
                            myProcess.StartInfo.UseShellExecute       = false;

                            myProcess.Start();
                            myProcess.WaitForExit();
                            exitCode = myProcess.ExitCode;
                        }
                        form.Close();

                        if (exitCode == 0)
                        {
                            Progreso.Show();
                            Progreso.Text = "Instalando";
                            bwCopia.RunWorkerAsync(version);
                        }
                        else
                        {
                            Utils.blockMenu = false;
                            MessageBox.Show("Instalación de WinPer cancelada.", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                }
            }catch (Exception ex)
            {
                MessageBox.Show(string.Format("Ocurrió un error inesperado.\n\n{0}. Revise Instalar_ERROR.log", ex.Message), "EXCEPCION CONTROLADA", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Utils.RegistrarLog("Instalar_ERROR.log", ex.ToString());
            }
        }
Example #3
0
        private void frmVersiones_Load(object sender, EventArgs e)
        {
            this.Text = this.Text + " Ambiente " + ambiente;

            Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"SOFTWARE\WinperUpdate");
            string nroLicencia = key.GetValue("Licencia").ToString();

            key.Close();

            Microsoft.Win32.RegistryKey keya = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"SOFTWARE\WinperUpdate\" + ambiente);
            string version = keya.GetValue("Version") == null ? "" : keya.GetValue("Version").ToString();
            string status  = keya.GetValue("Status") == null ? "": keya.GetValue("Status").ToString();

            keya.Close();

            keyv       = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"SOFTWARE\WinperUpdate\" + ambiente);
            directorio = keyv.GetValue("DirWinper").ToString();
            keyv.Close();

            if (string.IsNullOrEmpty(version))
            {
                lblTitulo.Text      = "Usted se encuentra Actualizado";
                lblSubtitulo.Text   = "Usted ya tiene la última versión liberada de WINPER. Pronto le informaremos de nuevas actualizaciones";
                btnInstalar.Enabled = false;
                return;
            }
            if (status.ToLower().Equals("updated"))
            {
                lblTitulo.Text      = "Usted se encuentra Actualizado";
                lblSubtitulo.Text   = "Usted ya tiene la última versión liberada de WINPER. El detalle de esta versión se muestra a continuación:";
                btnInstalar.Enabled = false;
            }
            else
            {
                lblTitulo.ForeColor = Color.Red;
                lblTitulo.Text      = "Actualización requerida";
                lblSubtitulo.Text   = "Usted no tiene la última versión liberada de WINPER (" + version + "). Para actualizarla favor dar click en el botón Instalar ...";
            }

            treeModulos.Nodes.Clear();
            treeModulos.Nodes.Add("Winper V " + version);

            string server = Utils.GetSetting("server");
            string port   = Utils.GetSetting("port");

            try
            {
                if (!string.IsNullOrEmpty(nroLicencia))
                {
                    string json    = Utils.StrSendMsg(server, int.Parse(port), "checklicencia#" + nroLicencia + "#");
                    var    cliente = JsonConvert.DeserializeObject <ClienteBo>(json);
                    if (cliente != null)
                    {
                        var release = new VersionBo();
                        json    = Utils.StrSendMsg(server, int.Parse(port), "getversion#" + version + "#");
                        release = JsonConvert.DeserializeObject <VersionBo>(json);

                        if (release.Componentes != null)
                        {
                            string modulo = "";
                            foreach (var componente in release.Componentes)
                            {
                                if (!modulo.Equals(componente.Modulo))
                                {
                                    modulo = componente.Modulo;
                                    treeModulos.Nodes[0].Nodes.Add(modulo);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ocurrio un error durante la conexión con el servidor central.", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Utils.RegistrarLog("FrmVersionesLoad.log", ex.ToString());
            }
        }
Example #4
0
        private void treeModulos_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            string server = Utils.GetSetting("server");
            string port   = Utils.GetSetting("port");

            string modulo = e.Node.Text;

            var padre = e.Node.Parent;

            if (padre == null)
            {
                string[] token = modulo.Split(new Char[] { ' ' });

                var    version = new VersionBo();
                string json    = Utils.StrSendMsg(server, int.Parse(port), "getversion#" + token[2] + "#");
                version = JsonConvert.DeserializeObject <VersionBo>(json);

                listView1.Clear();

                listView1.Columns.Add("Número", 80, HorizontalAlignment.Left);
                listView1.Columns.Add("Fecha", 120, HorizontalAlignment.Left);
                listView1.Columns.Add("Comentario", 290, HorizontalAlignment.Left);

                if (version != null)
                {
                    var item = new ListViewItem(version.Release);
                    item.SubItems.Add(version.FechaFmt);
                    item.SubItems.Add(version.Comentario);

                    listView1.Items.Add(item);
                }
            }
            else
            {
                string[] token = padre.Text.Split(new Char[] { ' ' });

                var    version = new VersionBo();
                string json    = Utils.StrSendMsg(server, int.Parse(port), "getversion#" + token[2] + "#");
                version = JsonConvert.DeserializeObject <VersionBo>(json);

                listView1.Clear();

                listView1.Columns.Add("Nombre", 120, HorizontalAlignment.Left);
                listView1.Columns.Add("Fecha", 120, HorizontalAlignment.Left);
                listView1.Columns.Add("Versión", 70, HorizontalAlignment.Left);
                listView1.Columns.Add("Comentario", 290, HorizontalAlignment.Left);

                if (version != null)
                {
                    foreach (var componente in version.Componentes.Where(x => x.Modulo.Equals(modulo)))
                    {
                        var item = new ListViewItem(componente.Name);
                        item.SubItems.Add(componente.DateCreateFmt);
                        item.SubItems.Add(componente.Version);
                        item.SubItems.Add(componente.Comentario);

                        listView1.Items.Add(item);
                    }
                }
            }
        }