private void CreateConfigFiles() { ConfigDS config = new ConfigDS(); config.Tables["LocalConfig"].Rows.Add("SICAS", "SICAS", "SICAS.exe", "2.0.0.0", "SICAS Versión 2.0", "images\\SICASSplash,jpg", "v2.0.0.0"); config.Tables["LocalConfig"].AcceptChanges(); config.Tables["FTPSettings"].Rows.Add(1, "SICAS", "SICASftp", "ibdibnnesems", "/AppRepository"); config.Tables["FTPSettings"].AcceptChanges(); config.Tables["HttpSettings"].Rows.Add(1, "http://*****:*****@casco.com.mx", "casco1", 2525); config.Tables["EmailSettings"].AcceptChanges(); DataSet ds = new DataSet(); ds.ReadXml(System.Environment.CurrentDirectory + "\\Config.xml"); ds.WriteXml(System.Environment.CurrentDirectory + "\\dsCfg.xml"); config.WriteXml(System.Environment.CurrentDirectory + "\\Config.xml"); MessageBox.Show("Done!"); }
private void InitData() { // 设置系统列表 ConfigDS.GetInstance().LoadConfig(_configPath); cmbSys.ValueMember = "SysCode"; cmbSys.DisplayMember = "SysName"; cmbSys.DataSource = ConfigDS.SysList.SysInfoDic; cmbSys.SelectedValue = ConfigDS.SysList.SelectSys; // 初始化数据库 dbTarget.SetDefaultDB(); dbCompara.SetDefaultDB(); }
private void btnCompara_Click(object sender, System.EventArgs e) { // 校验 string selectSys = Util.ConvertType <string>(cmbSys.SelectedValue); if (selectSys.IsEmpty()) { MsgBox.Warning("请选择系统!"); return; } if (!dbTarget.TestDB(false)) { MsgBox.Warning("目标数据库信息不正确!"); return; } if (!dbCompara.TestDB(false)) { MsgBox.Warning("对比数据库信息不正确!"); return; } // 保存配置信息 ConfigDS.SysList.SelectSys = selectSys; ConfigDS.GetInstance().SaveConfig(_configPath); dbTarget.SaveConfig(); dbCompara.SaveConfig(); if (dbTarget.DB == dbCompara.DB && !MsgBox.YesNo("数据库相同,是否继续比较?", false)) { return; } // 对比 SysTablePrefix sysInfo = ConfigDS.SysList.GetSysTablePrefix(selectSys); Compara(new SettingInfo { InFilter = sysInfo.InFilter, NotFilter = sysInfo.NotFilter, TargetDB = new ExtDBInfo(dbTarget.DB), ComparaDB = new ExtDBInfo(dbCompara.DB) }); }
/// <summary> /// Encrypta archivos /// </summary> private void DoCrypt() { //cryp files string xmlFile = System.Environment.CurrentDirectory + "\\Config.xml"; string cryptFile = System.Environment.CurrentDirectory + "\\CryptConfig.xml"; string decryptFile = System.Environment.CurrentDirectory + "\\DecryptConfig.xml"; string decryptXmlFile = System.Environment.CurrentDirectory + "\\DecryptedXMLFile.xml"; //CryptHelper.EncryptFile(xmlFile, cryptFile); //CryptHelper.DecryptFile(cryptFile, decryptFile); ConfigDS config = new ConfigDS(); config.ReadXml(CryptHelper.DecryptFile(cryptFile)); config.WriteXml(decryptXmlFile); MemoryStream ms = CryptHelper.EncryptFile(xmlFile); StreamReader sr = new StreamReader(ms); string text = sr.ReadToEnd(); MessageBox.Show(text); this.Close(); }
/// <summary> /// Ejecuta la actualización de la aplicación /// No necesita parametros, todo lo toma de los archivos de configuración /// </summary> public void AppUpdate() { ConfigDS config = new ConfigDS(); config.ReadXml(System.Environment.CurrentDirectory + "\\Config.xml"); ConfigDS.LocalConfigDataTable localConfig = config.LocalConfig; ConfigDS.WebServiceSettingsDataTable webService = config.WebServiceSettings; ConfigDS.FTPSettingsDataTable FTPSettings = config.FTPSettings; ConfigDS.HttpSettingsDataTable HttpSettings = config.HttpSettings; ConfigDS.VersionControlDataTable VersionControl = config.VersionControl; Utils.WSUrl = webService.Rows[0]["Url"].ToString(); AutoUpWebService.AutoUpdaterWS ws = new AutoUpWebService.AutoUpdaterWS(); int app_ID = Convert.ToInt32(localConfig.Rows[0]["App_ID"].ToString()); string user = webService.Rows[0]["User"].ToString(); string pwd = webService.Rows[0]["Pwd"].ToString(); string currentVersion = ws.CurrentVersion(app_ID, user, pwd); string localVersion = localConfig.Rows[0]["CurrentVersion"].ToString(); // Si current mayor que local if (String.Compare(currentVersion, localVersion) > 0) { // Hay actualización // Informar a la UI // Obtener la información de la actualización // AppInfo DataSet ds = ws.AppInfo(app_ID, currentVersion, user, pwd); // Get Table DataTable dt = ds.Tables[0]; // Set vars string packageLocation = dt.Rows[0]["PackageLocation"].ToString(); string packageDestination = System.Environment.CurrentDirectory + "\\" + currentVersion + ".zip"; string packageFolder = System.Environment.CurrentDirectory + "\\" + currentVersion; if (packageLocation.Contains("ftp://")) { // Es FTP // Descargar Utils.FTPDownload( packageLocation, packageDestination, FTPSettings.Rows[0]["User"].ToString(), FTPSettings.Rows[0]["Pwd"].ToString()); } else if (packageLocation.Contains("http://")) { // Es HTTP // Descargar Utils.HTTPDownload( packageLocation, packageDestination, HttpSettings.Rows[0]["User"].ToString(), HttpSettings.Rows[0]["Pwd"].ToString()); } // Crear directorio if (!Directory.Exists(packageFolder)) { Directory.CreateDirectory(packageFolder); } // Extraer archivos ZipFile zip = ZipFile.Read(System.Environment.CurrentDirectory + "\\" + currentVersion + ".zip"); foreach (ZipEntry ze in zip) { ze.Extract(packageFolder, ExtractExistingFileAction.OverwriteSilently); } // Guardar los cambios de control de versiones config.VersionControl.Rows.Add( dt.Rows[0]["App_ID"].ToString(), currentVersion, currentVersion, dt.Rows[0]["MainFile"].ToString(), dt.Rows[0]["Comments"].ToString()); config.VersionControl.AcceptChanges(); // Guardar los cambios de configuración local config.LocalConfig.Rows[0]["MainFile"] = dt.Rows[0]["MainFile"].ToString(); config.LocalConfig.Rows[0]["CurrentVersion"] = currentVersion; config.LocalConfig.Rows[0]["AppPath"] = currentVersion; config.LocalConfig.AcceptChanges(); config.WriteXml("Config.xml"); //Borrar el zip zip.Dispose(); if (File.Exists(System.Environment.CurrentDirectory + "\\" + currentVersion + ".zip")) { File.Delete(System.Environment.CurrentDirectory + "\\" + currentVersion + ".zip"); } // Iniciar programa principal Process.Start(packageFolder + "\\" + localConfig.Rows[0]["MainFile"].ToString()); // Salir this.Close(); } else { // No hay actualización // Iniciar programa principal Process.Start(System.Environment.CurrentDirectory + "\\" + localConfig.Rows[0]["AppPath"].ToString() + "\\" + localConfig.Rows[0]["MainFile"].ToString()); // Salir this.Close(); } }
/// <summary> /// Ejecuta la actualización de la aplicación /// No necesita parametros, todo lo toma de los archivos de configuración /// </summary> public void AppUpdate() { string AppFolder = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\SICAS\\"; // Cargar el archivo de configuracion encriptado en un DataSet ConfigDS config = new ConfigDS(); config.ReadXml(CryptHelper.DecryptFile(System.Environment.CurrentDirectory + "\\aupcfg.xml")); // Obtener las tablas del DataSet ConfigDS.LocalConfigDataTable localConfig = config.LocalConfig; ConfigDS.WebServiceSettingsDataTable webService = config.WebServiceSettings; ConfigDS.FTPSettingsDataTable FTPSettings = config.FTPSettings; ConfigDS.HttpSettingsDataTable HttpSettings = config.HttpSettings; ConfigDS.VersionControlDataTable VersionControl = config.VersionControl; // Directorio y aplicacion string currentdirectory = AppFolder + "\\" + localConfig.Rows[0]["AppPath"].ToString(); string mainFile = currentdirectory + "\\" + localConfig.Rows[0]["MainFile"].ToString(); // Obtener el ID de la aplicación int app_ID = Convert.ToInt32(localConfig.Rows[0]["App_ID"].ToString()); AutoUpWebService.AutoUpdaterWS ws = null; string currentVersion = "", user = "", pwd = ""; bool IsOK = false; foreach (DataRow dr in webService.Rows) { try { // Configurar la dirección remota del servicio web Utils.WSUrl = dr["Url"].ToString(); // Obtener las credencianciales del servicio web user = dr["User"].ToString(); pwd = dr["Pwd"].ToString(); ws = new AutoUpWebService.AutoUpdaterWS(); // Obtener la versión actual del servidor currentVersion = ws.CurrentVersion(app_ID, user, pwd); IsOK = true; break; } catch { continue; } } if (!IsOK) { Utils.Log("No se puede resolver servicio web"); Directory.SetCurrentDirectory(currentdirectory); Process.Start(mainFile); return; } // Obtener la versión local actual string localVersion = localConfig.Rows[0]["CurrentVersion"].ToString(); // Si current mayor que local if (String.Compare(currentVersion, localVersion) > 0) { // Hay actualización // Obtener la información de la actualización // AppInfo DataSet ds = ws.AppInfo(app_ID, currentVersion, user, pwd); // Get Table DataTable dt = ds.Tables[0]; // Set vars string packageLocation = dt.Rows[0]["PackageLocation"].ToString(); string packageDestination = AppFolder + "\\" + currentVersion + ".zip"; string packageFolder = AppFolder + "\\" + currentVersion; string imageUrl = dt.Rows[0]["ImageUrl"].ToString(); if (packageLocation.Contains("ftp://")) { // Es FTP // Descargar Utils.FTPDownload( packageLocation, packageDestination, FTPSettings.Rows[0]["User"].ToString(), FTPSettings.Rows[0]["Pwd"].ToString()); } else if (packageLocation.Contains("http://")) { // Es HTTP // Descargar Utils.HTTPDownload( packageLocation, packageDestination, HttpSettings.Rows[0]["User"].ToString(), HttpSettings.Rows[0]["Pwd"].ToString()); } //// Descargar la imagen //Utils.HTTPDownload(imageUrl, "AppImage", // HttpSettings.Rows[0]["User"].ToString(), // HttpSettings.Rows[0]["Pwd"].ToString()); // Crear directorio if (!Directory.Exists(packageFolder)) { Directory.CreateDirectory(packageFolder); } // Extraer archivos ZipFile zip = ZipFile.Read(AppFolder + "\\" + currentVersion + ".zip"); foreach (ZipEntry ze in zip) { ze.Extract(packageFolder, ExtractExistingFileAction.OverwriteSilently); } // Guardar los cambios de control de versiones config.VersionControl.Rows.Add( dt.Rows[0]["App_ID"].ToString(), currentVersion, currentVersion, dt.Rows[0]["MainFile"].ToString(), dt.Rows[0]["Comments"].ToString()); config.VersionControl.AcceptChanges(); // Guardar los cambios de configuración local config.LocalConfig.Rows[0]["MainFile"] = dt.Rows[0]["MainFile"].ToString(); config.LocalConfig.Rows[0]["CurrentVersion"] = currentVersion; config.LocalConfig.Rows[0]["AppPath"] = currentVersion; config.LocalConfig.AcceptChanges(); CryptHelper.EncryptFile(CryptHelper.DataSetAsStream(config), "aupcfg.xml"); //Borrar el zip zip.Dispose(); if (File.Exists(AppFolder + "\\" + currentVersion + ".zip")) { File.Delete(AppFolder + "\\" + currentVersion + ".zip"); } // Iniciar programa principal Directory.SetCurrentDirectory(AppFolder + "\\" + localConfig.Rows[0]["AppPath"].ToString()); Process.Start(packageFolder + "\\" + localConfig.Rows[0]["MainFile"].ToString()); } else { // No hay actualización // Iniciar programa principal Directory.SetCurrentDirectory(currentdirectory); Process.Start(mainFile); } }