Skip to content

Commit

Permalink
more bugfixing... error in page index update func
Browse files Browse the repository at this point in the history
  • Loading branch information
t0815 committed Oct 29, 2023
1 parent 7727f9e commit 1cfaa65
Show file tree
Hide file tree
Showing 7 changed files with 215 additions and 129 deletions.
134 changes: 67 additions & 67 deletions MyCBZ/Forms/MainForm.Designer.cs

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions MyCBZ/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,24 @@ private void PageChanged(object sender, PageChangedEvent e)

if (e.OldValue != null)
{
int backupIndex = -1;
if (ComboBoxApplyPageAdjustmentsTo.Items.IndexOf(((Page)e.OldValue).Name) > -1)
{
if (ComboBoxApplyPageAdjustmentsTo.Items.IndexOf(e.Page.Name) > -1)
{
backupIndex = ComboBoxApplyPageAdjustmentsTo.Items.IndexOf(e.Page.Name);
string backupName = ComboBoxApplyPageAdjustmentsTo.Items[backupIndex].ToString();

ComboBoxApplyPageAdjustmentsTo.Items[backupIndex] = Program.ProjectModel.MakeNewRandomId();
}

ComboBoxApplyPageAdjustmentsTo.Items[ComboBoxApplyPageAdjustmentsTo.Items.IndexOf(((Page)e.OldValue).Name)] = e.Page.Name;

if (backupIndex > -1)
{
ComboBoxApplyPageAdjustmentsTo.Items[backupIndex] = ((Page)e.OldValue).Name;

}
}
}

Expand Down
60 changes: 30 additions & 30 deletions MyCBZ/Forms/MainForm.resx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAABu
CgAAAk1TRnQBSQFMAgEBAwEAA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@@
<metadata name="OpenImagesDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>297, 60</value>
</metadata>
<data name="CompatInfoText.Text" xml:space="preserve">
<value>Most CBZ-Readers ignore the ComicInfo Page-Index and rely on filename ordering instead. If enabled, any renaming options are ignored and the files are automatically renamed according to their index. The Page with Type 'FrontCover' should be at index 1.</value>
</data>
<metadata name="SmallIconsImages.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>1118, 21</value>
</metadata>
<data name="SmallIconsImages.ImageStream" mimetype="application/x-microsoft.net.object.binary.base64">
<value>
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAAK
AwAAAk1TRnQBSQFMAgEBAgEAAUABDAFAAQwBEAEAARABAAT/ARkBAAj/AUIBTQE2BwABNgMAASgDAAFA
AwABEAMAAQEBAAEYBgABDCEAA/cD2QPEA78D0gPtA/6lAAP+A7kDLA8lA38D/RIAA+cBUgFUAVUD+g8A
A7gBtgK4bwAD+wOGBiUDSQOrA60DfwYlA0QD4wwAA+YDUAMlA30D+gYAA/0DtAMrAyUDumkAA/4DYwkl
A5sGAAPfCSUDRAP9BgAD5wwlA0YD+gMAA7QMJQG2ArhmAAPUDCUDmwYAA98MJQN/A/4DAAPoAzUMJQN9
A7QDKwklAysDuGYAA4YMJQObBgAD3w8lA+0GAAPzAzUbJQO0aQADSQMlA9EG3wPuBgAD+QnfA38DJQPS
CQAD4AM1EiUDKwO0A/1pAAMpAyUD+xsAA60DJQO/DAAD8wM1DyUDtG8AAzIDJQP7GwADqwMlA8QJAAP9
A7QDKw8lA30D+mwAA1sDJQOEBpsDzwYAA+4JmwNJAyUD2QkAA7QYJQNGA/ppAAOiDCUDmwYAA98MJQMs
A/cDAAP9A7QDKwklAysDNQwlA30D+mYAA+gMJQObBgAD3wwlA7kGAAHKAssPJQO0A/MDNQwlAVIBVAFV
ZgAD/wPAAy0GJQOEBvsD0QklA4YD/gYAA/YDdgYlAysDtAP9AwAD4AM1BiUDUAPnbAADwBglA2MD+w8A
A3YDJQO0DAAD8wM1AyUD5m8AA/8D6AOiA1sDMgMpA0kDhgPUA/4SAAP2AcoCywP9DwAD6APn/wAqAAFC
AU0BPgcAAT4DAAEoAwABQAMAARADAAEBAQABAQUAAYAXAAP/AQAB+AEPAv8EAAHgAQcB4wHnBAABwAED
AcEBgwQAAoEBgAGBBAABgQKAAQEEAAGBAYABwAEDBAABgQGAAeABAwQAAY8B+AHwAQ8EAAGPAfgB4AEH
BAABgQGAAeABAwQAAYECgAEBBAACgQGAAQEEAAGAAQEBgAGBBAAB4AEDAeMBwwQAAeABBwHjAecEAAT/
BAAL
</value>
</data>
<metadata name="LogMessageImageList.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>453, 60</value>
</metadata>
Expand All @@ -478,7 +505,7 @@
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAAAQ
DAAAAk1TRnQBSQFMAgEBBAEAAcgBDAHIAQwBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
DAAAAk1TRnQBSQFMAgEBBAEAAdgBDAHYAQwBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
AwABQAMAASADAAEBAQABCAYAAQgYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA
AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5
AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA
Expand Down Expand Up @@ -530,33 +557,6 @@
ASABwAHjAZ4BPAHGASMBggFAAYYBcQG8ATwB4gEnAYEBgAGeAXkBvAE8AeIBBwGBAYABngF5AZ8B+AHy
AQ8BggFgAZ4BOQGcATgB+AGPAYQBIAGeATkBjAE5AfgBnwGAAQEBngE5AYQBIQH8AT8BgAEBAYYBIQHh
AYMB/gE/AeABAwHAAQMB4AEHAf4BPwHgAQcB8AEPCP8L
</value>
</data>
<data name="CompatInfoText.Text" xml:space="preserve">
<value>Most CBZ-Readers ignore the ComicInfo Page-Index and rely on filename ordering instead. If enabled, any renaming options are ignored and the files are automatically renamed according to their index. The Page with Type 'FrontCover' should be at index 1.</value>
</data>
<metadata name="SmallIconsImages.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>1118, 21</value>
</metadata>
<data name="SmallIconsImages.ImageStream" mimetype="application/x-microsoft.net.object.binary.base64">
<value>
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1l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AAeABBwHjAecEAAT/
BAAL
</value>
</data>
<metadata name="SaveArchiveDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
Expand Down
4 changes: 2 additions & 2 deletions MyCBZ/Models/MetaData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,11 @@ public void RebuildPageMetaData(List<Page> pages)
}
}

public void UpdatePageIndexMetaDataEntry(String name, Page page)
public void UpdatePageIndexMetaDataEntry(Page page, String oldName, String newName)
{
foreach (MetaDataEntryPage entry in PageIndex)
{
if (entry.GetAttribute(MetaDataEntryPage.COMIC_PAGE_ATTRIBUTE_IMAGE).Equals(page.Name))
if (entry.GetAttribute(MetaDataEntryPage.COMIC_PAGE_ATTRIBUTE_IMAGE).Equals(oldName))
{
entry.SetAttribute(MetaDataEntryPage.COMIC_PAGE_ATTRIBUTE_IMAGE, page.Name)
.SetAttribute(MetaDataEntryPage.COMIC_PAGE_ATTRIBUTE_TYPE, page.ImageType)
Expand Down
8 changes: 7 additions & 1 deletion MyCBZ/Models/MetaDataEntryPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@ public MetaDataEntryPage()

public MetaDataEntryPage SetAttribute(String name, String value)
{
Attributes.Add(name, value);
try
{
Attributes.Add(name, value);
} catch (Exception e)
{
Attributes[name] = value;
}

return this;
}
Expand Down
85 changes: 67 additions & 18 deletions MyCBZ/Models/Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,19 @@ public Page(Page sourcePage)
ImageEntry = sourcePage.ImageEntry;
ImageStream = sourcePage.ImageStream;
IsMemoryCopy = sourcePage.IsMemoryCopy;
ImageStreamMemoryCopy = sourcePage.ImageStreamMemoryCopy;
//ImageStreamMemoryCopy = sourcePage.ImageStreamMemoryCopy;

if (ImageStream != null)
{
if (ImageStream.CanRead)
{
sourcePage.ImageStream.Position = 0;

ImageStreamMemoryCopy = new MemoryStream();
sourcePage.ImageStream.CopyTo(ImageStreamMemoryCopy);
IsMemoryCopy = true;
}
}

Changed = sourcePage.Changed;
ReadOnly = sourcePage.ReadOnly;
Expand Down Expand Up @@ -419,29 +431,66 @@ protected void RequestTemporaryFile(String destination = null)

FileInfo tempFileInfo = new FileInfo(TempPath);

FileStream localFile = File.OpenRead(LocalPath);
try
if (!IsMemoryCopy)
{
FileStream ImageStream = File.Open(TempPath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
FileStream localFile = File.OpenRead(LocalPath);
try
{
localFile.CopyTo(ImageStream);
} catch (Exception ewr)

FileStream CopyImageStream = File.Open(TempPath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
try
{
localFile.CopyTo(CopyImageStream);
}
catch (Exception ewr)
{
throw ewr;
}
finally
{
CopyImageStream.Close();
CopyImageStream.Dispose();
}
}
catch (Exception e)
{
throw ewr;
} finally
{
ImageStream.Close();
ImageStream.Dispose();
throw e;
}

} catch (Exception e)
{
throw e;
} finally
finally
{
localFile.Close();
localFile.Dispose();
}
} else
{
localFile.Close();
localFile.Dispose();
try
{

FileStream CopyImageStream = File.Open(TempPath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
try
{
ImageStreamMemoryCopy.CopyTo(CopyImageStream);
}
catch (Exception ewr)
{
throw ewr;
}
finally
{
CopyImageStream.Close();
CopyImageStream.Dispose();
}


}
catch (Exception e)
{
throw e;
}
finally
{

}
}

}
Expand Down
38 changes: 27 additions & 11 deletions MyCBZ/Models/ProjectModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ internal class ProjectModel

private bool ContinuePipelineForIndexBuilder;

private bool IgnorePageNameDuplicates = false;

public long TotalSize { get; set; }

private System.IO.Compression.ZipArchive Archive { get; set; }
Expand Down Expand Up @@ -1344,18 +1346,21 @@ public void RestoreOriginalNamesProc()
}

[MethodImpl(MethodImplOptions.Synchronized)]
public void RenamePage(Page page, String name, bool isRestored = false)
public void RenamePage(Page page, String name, bool ignoreDuplicates = false)
{
if (name == null || name == "")
{
throw new PageException(page, "Failed to rename page ['" + page.Name + "'] with ID [" + page.Id + "]! The new name must not be NULL.");
}

foreach (Page existingPage in Pages)
if (!ignoreDuplicates)
{
if (existingPage.Name.ToLower().Equals(name.ToLower()))
foreach (Page existingPage in Pages)
{
throw new PageDuplicateNameException(page, "Failed to rename page ['" + page.Name + "'] with ID [" + page.Id + "]! A different page with the same name already exists at Index " + existingPage.Index + ".");
if (existingPage.Name.ToLower().Equals(name.ToLower()))
{
throw new PageDuplicateNameException(page, "Failed to rename page ['" + page.Name + "'] with ID [" + page.Id + "]! A different page with the same name already exists at Index " + existingPage.Index + ".");
}
}
}

Expand All @@ -1369,7 +1374,7 @@ public void RenamePage(Page page, String name, bool isRestored = false)
}

[MethodImpl(MethodImplOptions.Synchronized)]
public String PageScriptRename(Page page)
public String PageScriptRename(Page page, bool ignoreDuplicates = false)
{
string oldName = page.Name;
string newName = page.Name;
Expand Down Expand Up @@ -1404,7 +1409,7 @@ public String PageScriptRename(Page page)

try
{
RenamePage(page, newName);
RenamePage(page, newName, ignoreDuplicates);
} catch (PageDuplicateNameException) {
return oldName;
}
Expand Down Expand Up @@ -1646,7 +1651,7 @@ public void RunRenameScriptsForPages()
{
if (CompatibilityMode || RenamerExcludes.IndexOf(page.Name) == -1)
{
RenamePageScript(page);
RenamePageScript(page, IgnorePageNameDuplicates);

OnTaskProgress(new TaskProgressEvent(page, page.Index + 1, Pages.Count));

Expand Down Expand Up @@ -1709,6 +1714,7 @@ protected void SaveArchiveProc()

RenameStoryPagePattern = "{page}.{ext}";
RenameSpecialPagePattern = "{page}.{ext}";
IgnorePageNameDuplicates = true;

try
{
Expand All @@ -1720,6 +1726,7 @@ protected void SaveArchiveProc()

} finally
{
IgnorePageNameDuplicates = false;
RenameStoryPagePattern = restoreOriginalPatternPage;
RenameSpecialPagePattern = restoreOriginalPatternSpecialPage;
}
Expand Down Expand Up @@ -1795,6 +1802,7 @@ protected void SaveArchiveProc()
}
catch (Exception efile)
{
page.Compressed = false;
MessageLogger.Instance.Log(LogMessageEvent.LOGMESSAGE_TYPE_ERROR, "Error compressing File [" + page.TempPath + "] to Archive [" + efile.Message + "]");
}
finally
Expand Down Expand Up @@ -1890,10 +1898,18 @@ protected void SaveArchiveProc()
}

[MethodImpl(MethodImplOptions.Synchronized)]
public void RenamePageScript(Page page)
public void RenamePageScript(Page page, bool ignoreDuplicates = false)
{
String newName = PageScriptRename(page);
MetaData.UpdatePageIndexMetaDataEntry(newName, page);
String oldName = page.Name;
String newName = PageScriptRename(page, ignoreDuplicates);

try
{
MetaData.UpdatePageIndexMetaDataEntry(page, oldName, newName);
} catch (Exception ex)
{
MessageLogger.Instance.Log(LogMessageEvent.LOGMESSAGE_TYPE_WARNING, "Error updating PageIndex for page [" + newName + "]. " + ex.Message);
}
}


Expand Down Expand Up @@ -1950,7 +1966,7 @@ protected void SetDirectoryAccessControl(ref DirectoryInfo directoryInfo)
directoryInfo.SetAccessControl(dSecurity);
}

protected String MakeNewRandomId()
public String MakeNewRandomId()
{
return RandomProvider.Next().ToString("X");
}
Expand Down

0 comments on commit 1cfaa65

Please sign in to comment.