Skip to content

Commit

Permalink
Extemd metadata change detection
Browse files Browse the repository at this point in the history
  • Loading branch information
t0815 committed Oct 30, 2023
1 parent 06b0612 commit 95e6f49
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
10 changes: 7 additions & 3 deletions MyCBZ/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using Win_CBZ.Tasks;
using System.Security.Policy;
using Win_CBZ.Models;
using System.Windows.Input;

namespace Win_CBZ
{
Expand Down Expand Up @@ -1887,7 +1888,7 @@ private void BtnRemoveMetaData_Click(object sender, EventArgs e)
{
if (Program.ProjectModel != null && Program.ProjectModel.MetaData != null)
{
if (Program.ProjectModel.MetaData.HasValues() && Program.ProjectModel.Exists()) {
if ((Program.ProjectModel.MetaData.HasValues() || Program.ProjectModel.MetaData.HasRemovedValues()) && Program.ProjectModel.Exists()) {
if (ApplicationMessage.ShowConfirmation("Are you sure you want to remove existing Metadata from Archive?", "Remove existing Meta-Data") == DialogResult.Yes)
{
RemoveMetaData();
Expand Down Expand Up @@ -1915,12 +1916,15 @@ private void RemoveMetadataRowBtn_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow row in MetaDataGrid.SelectedRows)
{
int index = Program.ProjectModel.MetaData.Remove(row.Index);

/*
if (row.Cells[0].Value != null)
{
var key = row.Cells[0].Value.ToString();
Program.ProjectModel.MetaData.Remove(key);
}
} */
}
}
}
Expand Down Expand Up @@ -2136,7 +2140,7 @@ private void MetaDataEntryChanged(object sender, MetaDataEntryChangedEvent e)
r.Selected = false;
}

MetaDataGrid.Rows.Add(e.Entry.Key, e.Entry.Value);
MetaDataGrid.Rows.Add(e.Entry.Key, e.Entry.Value, "");

if (e.Entry.Key == "" && e.Entry.Value == null)
{
Expand Down
46 changes: 43 additions & 3 deletions MyCBZ/Models/MetaData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ internal class MetaData

public List<String> CustomDefaultProperties { get; set; }

private List<String> RemovedKeys { get; set; }

public List<String> ProtectedKeys { get; }

public String MetaDataFileName { get; set; }
Expand Down Expand Up @@ -107,6 +109,7 @@ public MetaData(bool createDefault = false)
Values = new BindingList<MetaDataEntry>();
PageIndex = new BindingList<MetaDataEntryPage>();
ProtectedKeys = new List<string>(ProtectedProperties);
RemovedKeys = new List<string>();

Document = new XmlDocument();

Expand Down Expand Up @@ -329,10 +332,11 @@ public bool HasValues()
{
foreach (var defaultEntry in Defaults)
{
if (defaultEntry.Key == entry.Key)
if (defaultEntry.Key.ToLower().Equals(entry.Key.ToLower()))
{
keyChanged = false;
defaultValueChanged = !defaultEntry.Value.Equals(entry.Value);
break;
}
}

Expand All @@ -346,6 +350,11 @@ public bool HasValues()
return false;
}

public bool HasRemovedValues()
{
return RemovedKeys.Count > 0;
}

public String ValueForKey(String key)
{
foreach (MetaDataEntry entry in Values)
Expand Down Expand Up @@ -376,6 +385,11 @@ public int Add(MetaDataEntry entry)
{
Values.Add(HandleNewEntry(entry.Key, entry.Value));

if (RemovedKeys.IndexOf(entry.Key) > -1)
{
RemovedKeys.Remove(entry.Key);
}

return Values.Count - 1;
}

Expand All @@ -385,6 +399,11 @@ public int Add(String key, String value = null)

Values.Add(newEntry);

if (RemovedKeys.IndexOf(key) > -1)
{
RemovedKeys.Remove(key);
}

OnMetaDataEntryChanged(new MetaDataEntryChangedEvent(MetaDataEntryChangedEvent.ENTRY_NEW, Values.Count - 1, newEntry));

return Values.Count - 1;
Expand All @@ -401,6 +420,11 @@ public int Remove(String key)

if (success)
{
if (RemovedKeys.IndexOf(key) == -1)
{
RemovedKeys.Add(key);
}

OnMetaDataEntryChanged(new MetaDataEntryChangedEvent(MetaDataEntryChangedEvent.ENTRY_DELETED, index, entry));

return index;
Expand All @@ -417,7 +441,12 @@ public int Remove(int index)
if (entry != null)
{
Values.RemoveAt(index);


if (RemovedKeys.IndexOf(entry.Key) == -1)
{
RemovedKeys.Add(entry.Key);
}

OnMetaDataEntryChanged(new MetaDataEntryChangedEvent(MetaDataEntryChangedEvent.ENTRY_DELETED, index, entry));

return index;
Expand All @@ -434,6 +463,11 @@ public int Remove(MetaDataEntry entry)

if (success)
{
if (RemovedKeys.IndexOf(entry.Key) == -1)
{
RemovedKeys.Add(entry.Key);
}

OnMetaDataEntryChanged(new MetaDataEntryChangedEvent(MetaDataEntryChangedEvent.ENTRY_DELETED, index, entry));

return index;
Expand Down Expand Up @@ -507,7 +541,7 @@ protected void HandlePageMetaData(XmlNode pageNodes)
{
pageMeta.SetAttribute(attrib.Name, attrib.Value);
} catch (Exception) {
MessageLogger.Instance.Log(LogMessageEvent.LOGMESSAGE_TYPE_WARNING, "Failed to read page->" + attrib.Name + " from ComicInfo.xml");
MessageLogger.Instance.Log(LogMessageEvent.LOGMESSAGE_TYPE_WARNING, "Failed to read value from index for Pages->" + attrib.Name + " from ComicInfo.xml");
}
}

Expand Down Expand Up @@ -686,6 +720,7 @@ public void Free()
if (InputStream != null) {
if (InputStream.CanRead) {
InputStream.Close();
InputStream.Dispose();
}
}

Expand All @@ -698,6 +733,11 @@ public void Free()
{
MetaDataReader.Dispose();
}

RemovedKeys.Clear();
Defaults.Clear();
Values.Clear();
PageIndex.Clear();
}

protected virtual void OnMetaDataEntryChanged(MetaDataEntryChangedEvent e)
Expand Down

0 comments on commit 95e6f49

Please sign in to comment.