private void LevelsTabControl_SelectedIndexChanged(object sender, EventArgs e) { var ind = LevelsTabControl.SelectedIndex; if (ind == -1) { return; } ActiveGroup = null; ActiveGroupInd = -1; ActiveSub = null; if (ind < LevelTabStart) { ActiveLevel = null; if (LevelsTabControl.SelectedTab == GroupPage) { UpdateTuningEntries(false, false); RenderGroups(); } } else if (ind == LevelsTabControl.TabPages.Count - 1 && LevelsTabControl.TabPages.Count > LevelTabStart) { AddUpgrade(); } else { ActiveLevel = ActiveUpgrades.Upgrades[ind - LevelTabStart]; } UpdateSubsList(); }
private void GroupRemove_Click(object sender, EventArgs e) { if (ActiveGroup == null) { return; } ActiveUpgrades.Groups.Remove(ActiveGroup); ActiveGroup = null; ActiveGroupInd = -1; RenderGroups(); UpdateFile(); }
private void lvGroups_SelectedIndexChanged(object sender, EventArgs e) { if (lvGroups.SelectedItems.Count > 0) { UpgradeGroup group = lvGroups.SelectedItems[0].Tag as UpgradeGroup; if (group != null) { BindingUpgradeGroup(group); } } btngDelete.Enabled = lvGroups.Items.Count > 0; }
/// <summary> /// 选择升级项目的入口程序 /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="DevExpress.XtraEditors.Controls.ButtonPressedEventArgs"/> instance containing the event data.</param> private void txtStartUpApp_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { OpenFileDialog opendlg = new OpenFileDialog(); opendlg.Multiselect = false; opendlg.Title = "选择"; opendlg.Filter = "可执行程序(*.exe)|*.exe"; if (opendlg.ShowDialog() == DialogResult.OK) { txtStartUpApp.Text = Path.GetFileName(opendlg.FileName); txtProduct.Text = Path.GetFileNameWithoutExtension(opendlg.FileName); // 向升级项目中插入启动组的内容 UpgradeGroup group = new UpgradeGroup("StartUp", "${RootPath}"); group.Items.Add(new UpgradeItem(opendlg.FileName)); foreach (ListViewItem item in lvGroups.Items) { UpgradeGroup gr = item.Tag as UpgradeGroup; if (gr != null && gr.Name == "StartUp") { lvGroups.Items.Remove(item); break; } } ListViewItem groupItem = new ListViewItem(group.Name); groupItem.Tag = group; lvGroups.Items.Insert(0, groupItem); BindingUpgradeGroup(group); try { AssemblyName assemblyName = Assembly.ReflectionOnlyLoadFrom(opendlg.FileName).GetName(); txtVersion.Text = assemblyName.Version.ToString(); } catch { UpgradeProject proj = Presenter.UpgradeService.GetUpgradeProject(txtProduct.Text.Trim()); // 从服务器升级数据库中获取新的版本号 if (proj != null) { Version ver = new Version(proj.Version); txtVersion.Text = String.Format("{0}.{1}.{2}.{3}", ver.Major, ver.Minor, ver.Build, ver.Revision + 1); } else { txtVersion.Text = "1.0.0.0"; } } } txtUpgradeUrl.Text = Presenter.UpgradeSetting.UpgradeUrl; txtUpgradeUrl.SelectAll(); txtUpgradeUrl.Focus(); }
public void BindingUpgradeGroup(UpgradeGroup group) { Guard.ArgumentNotNull(group, "Upgrade group."); txtGroupName.Text = group.Name; txtTarget.Text = group.Target; lvItems.Items.Clear(); foreach (UpgradeItem upItem in group.Items) { ListViewItem item = new ListViewItem(upItem.Name, 1); item.Tag = upItem; lvItems.Items.Add(item); } }
public UpgradeProject WrapUpgradeProject() { UpgradeProject proj = new UpgradeProject(); proj.StartUpApp = txtStartUpApp.Text.Trim(); proj.UpgradeServer = txtUpgradeUrl.Text.Trim(); proj.Product = txtProduct.Text.Trim(); proj.Version = txtVersion.Text.Trim(); proj.Description = txtDescription.Text; foreach (ListViewItem item in lvGroups.Items) { UpgradeGroup group = item.Tag as UpgradeGroup; if (group != null) { proj.Groups.Add(group); } } return(proj); }
private void UpdateUpgradeGroup() { if (String.IsNullOrEmpty(txtGroupName.Text) || String.IsNullOrEmpty(txtTarget.Text)) { XtraMessageBox.Show("必须为更新项目组提供一个名称和目标文件夹位置。"); txtGroupName.Focus(); return; } int index = -1; foreach (ListViewItem item in lvGroups.Items) { if (item.Text == txtGroupName.Text) { index = item.Index; lvGroups.Items.Remove(item); break; } } UpgradeGroup group = new UpgradeGroup(txtGroupName.Text.Trim(), txtTarget.Text.Trim()); foreach (ListViewItem item in lvItems.Items) { group.Items.Add(item.Tag as UpgradeItem); } ListViewItem groupItem = new ListViewItem(group.Name, 0); groupItem.Tag = group; if (index != -1) { lvGroups.Items.Insert(index, groupItem); } else { lvGroups.Items.Add(groupItem); } upgradeItemChanged = false; }
private void UpgradeFiles(UpgradeGroup group) { logger.Info(String.Format("准备更新组:{0} ", group.Name)); // 创建更新的目标文件夹 string targetPath = group.Target.IndexOf("${RootPath}") != -1 ? Path.Combine(ROOT_PATH, group.Target.Substring(11, group.Target.Length - 11)) : group.Target; if (!Directory.Exists(targetPath)) { Directory.CreateDirectory(targetPath); } foreach (UpgradeItem item in group.Items) { string srcfile = Path.Combine(upgradePath, item.Name); string tarfile = Path.Combine(targetPath, item.Name); if (!File.Exists(srcfile)) { logger.Info(String.Format("下载 {0} 不成功更新此文件失败", item.Name)); continue; } try { logger.Info(String.Format("删除待更新的旧版本文件 {0}", tarfile)); File.Delete(tarfile); logger.Info(String.Format("更新文件 {0}", item.Name)); File.Move(srcfile, tarfile); logger.Info(String.Format("更新文件 {0} 成功", item.Name)); } catch (Exception ex) { logger.Info(String.Format("更新文件 {0} 失败,错误原因为:", item.Name, ex.Message)); } } logger.Info(String.Format("完成更新组:{0} ", group.Name)); }
private void GroupTree_AfterSelect(object sender, TreeViewEventArgs e) { //select a group, optionally an index var node = GroupTree.SelectedNode; if (node == null) { ActiveGroup = null; ActiveGroupInd = -1; } else { var parent = node.Parent; if (parent == null) { //group only var groupInd = GroupTree.Nodes.IndexOf(node); if (groupInd < ActiveUpgrades.Groups.Count) { ActiveGroup = ActiveUpgrades.Groups[groupInd]; ActiveGroupInd = -1; } } else { var tuningInd = parent.Nodes.IndexOf(node); var groupInd = GroupTree.Nodes.IndexOf(parent); if (groupInd < ActiveUpgrades.Groups.Count) { ActiveGroup = ActiveUpgrades.Groups[groupInd]; ActiveGroupInd = tuningInd; } } } UpdateSelectedGroupItem(); }