private void modifyButton_Click(object sender, EventArgs e) { if (entryList.SelectedItems.Count == 0) { return; } // On récupère l'entrée sélectionnée try { UInt32 id = UInt32.Parse(entryList.SelectedItems[0].SubItems[1].Text); MAP.Entry entryToModify = leMAP.EntryList[id]; // Affichage de la fenêtre de modification DialogResult dr = new SizeModifierForm(entryToModify, leMAP).ShowDialog(this); // Des modifications ? if (dr != DialogResult.Cancel) { // EVO 30 : mise à jour de la ligne uniquement _UpdateSingleEntry(entryList.SelectedItems[0], id); Cursor = Cursors.Default; // EVO 32 StatusBarLogManager.ShowEvent(this, _STATUS_CHANGE_SUCCESS); } } catch (Exception ex) { MessageBoxes.ShowError(this, ex); } }
/// <summary> /// Met à jour une seule entrée dans la liste /// </summary> /// <param name="lvItem">élément de la liste</param> /// <param name="entryId">identifiant de l'entrée mise à jour</param> private void _UpdateSingleEntry(ListViewItem lvItem, uint entryId) { if (lvItem == null) { return; } MAP.Entry entry = leMAP.EntryList[entryId]; lvItem.ForeColor = SystemColors.WindowText; lvItem.SubItems[1].Text = string.Format("{0}", entry.fileId); lvItem.SubItems[2].Text = string.Format("{0}", entry.firstSize); lvItem.SubItems[3].Text = string.Format("{0}", entry.secondSize); lvItem.SubItems[4].Text = string.Format("{0}", entry.address); lvItem.SubItems[5].Text = string.Format("{0}", entry.fileName); // EVO 13 : un fichier dont la taille ne correspond pas est affiché en rouge try { uint actualSize = uint.Parse(lvItem.SubItems[6].Text); if (actualSize != entry.firstSize || actualSize != entry.secondSize) { lvItem.ForeColor = GuiConstants.COLOR_INVALID_ITEM; } } catch (Exception ex) { // Silent exception Exception2.PrintStackTrace(ex); } }
/// <summary> /// Constructeur /// </summary> /// <param name="entryToModify"></param> /// <param name="fileToModify"></param> public SizeModifierForm(MAP.Entry entryToModify, MAP fileToModify) { theEntry = entryToModify; theFile = fileToModify; InitializeComponent(); initializeContents(); }
/// <summary> /// Met à jour la liste des entrées /// </summary> /// <param name="keepSelection">true pour replacer le sélecteur à l'emplacement d'origine, false sinon</param> private void _UpdateEntryList(bool keepSelection) { // Sauvegarde de l'indice sélectionné if (keepSelection) { ListView2.StoreSelectedIndex(entryList); } // Vidage de liste entryList.Items.Clear(); entryCountLabel.Text = _ENTRY_COUNT_START_TEXT; // Utilisation de la clé XML if (!string.IsNullOrEmpty(inputKEYFilePath.Text)) { leMAP.SetFileNamesFromKey(inputKEYFilePath.Text); } // Lecture de la structure foreach (UInt32 anotherKey in leMAP.EntryList.Keys) { MAP.Entry anotherEntry = leMAP.EntryList[anotherKey]; ListViewItem anotherItem = new ListViewItem(string.Format("{0}", anotherEntry.entryNumber + 1)); // EVO 13 : recherche de la taille du fichier sur disque FileInfo fi = null; try { if (anotherEntry.fileName != null) { string actualFileName = Program.ApplicationSettings.TduMainFolder + @"\" + anotherEntry.fileName; fi = new FileInfo(actualFileName); } } catch (Exception ex) { // Erreur silencieuse ici Exception2.PrintStackTrace(ex); } anotherItem.SubItems.Add(string.Format("{0}", anotherEntry.fileId)); anotherItem.SubItems.Add(string.Format("{0}", anotherEntry.firstSize)); anotherItem.SubItems.Add(string.Format("{0}", anotherEntry.secondSize)); anotherItem.SubItems.Add(string.Format("{0}", anotherEntry.address)); anotherItem.SubItems.Add(string.Format("{0}", anotherEntry.fileName)); if (fi != null && fi.Exists) { // EVO 13 : un fichier dont la taille ne correspond pas est affiché en rouge if (fi.Length != anotherEntry.firstSize || fi.Length != anotherEntry.secondSize) { anotherItem.ForeColor = GuiConstants.COLOR_INVALID_ITEM; } anotherItem.SubItems.Add(string.Format("{0}", fi.Length)); } else { anotherItem.SubItems.Add(""); } entryList.Items.Add(anotherItem); } // Nombre d'entrées entryCountLabel.Text = string.Format(_ENTRY_COUNT_TEXT, leMAP.EntryList.Keys.Count); // Restauration de la sélection if (keepSelection) { ListView2.RestoreSelectedIndex(entryList); } }