Skip to content

Commit 67cac75

Browse files
committed
Critical file locking fix...
Fix error validating empty tags
1 parent eedcf04 commit 67cac75

File tree

8 files changed

+136
-27
lines changed

8 files changed

+136
-27
lines changed

MyCBZ/App.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
<applicationSettings>
6262
<Win_CBZ.Win_CBZSettings>
6363
<setting name="Version" serializeAs="String">
64-
<value>0.13.63b</value>
64+
<value>0.13.64b</value>
6565
</setting>
6666
<setting name="RenamerPlaceholders" serializeAs="Xml">
6767
<value>

MyCBZ/Data/DataValidation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public static bool ValidateTags(ref ArrayList unknownTagsList, bool showError =
9292
unknownTagsList = new ArrayList();
9393
}
9494

95-
if (tagEntry != null && validTags.Count > 0)
95+
if (tagEntry != null && tagEntry.Value != null && tagEntry.Value.Length > 0 && validTags.Count > 0)
9696
{
9797
String[] tags = tagEntry.Value.Split(',').Select(s => s.Trim()).ToArray();
9898
foreach (String tag in tags)

MyCBZ/Models/Page.cs

Lines changed: 99 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -418,16 +418,32 @@ protected void RequestTemporaryFile(String destination = null)
418418
}
419419

420420
FileInfo tempFileInfo = new FileInfo(TempPath);
421-
FileStream ImageStream = File.Open(TempPath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
422-
FileStream localFile = File.OpenRead(LocalPath);
423-
424-
localFile.CopyTo(ImageStream);
425421

426-
ImageStream.Close();
427-
localFile.Close();
422+
FileStream localFile = File.OpenRead(LocalPath);
423+
try
424+
{
425+
FileStream ImageStream = File.Open(TempPath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
426+
try
427+
{
428+
localFile.CopyTo(ImageStream);
429+
} catch (Exception ewr)
430+
{
431+
throw ewr;
432+
} finally
433+
{
434+
ImageStream.Close();
435+
ImageStream.Dispose();
436+
}
428437

429-
ImageStream.Dispose();
430-
localFile.Dispose();
438+
} catch (Exception e)
439+
{
440+
throw e;
441+
} finally
442+
{
443+
localFile.Close();
444+
localFile.Dispose();
445+
}
446+
431447
}
432448
}
433449
}
@@ -468,6 +484,7 @@ public void DeleteTemporaryFile()
468484
if (ImageStream != null)
469485
{
470486
ImageStream.Close();
487+
ImageStream.Dispose();
471488
}
472489

473490
File.Delete(TempPath);
@@ -596,21 +613,89 @@ public String CreateLocalWorkingCopy(String destination = null)
596613
FileInfo copyFileInfo = new FileInfo(destination);
597614
if (ImageStream != null)
598615
{
616+
if (ImageStream.CanSeek && ImageStream.Position == copyFileInfo.Length)
617+
{
618+
ImageStream.Seek(0, SeekOrigin.Begin);
619+
}
620+
599621
if (ImageStream.CanRead)
600622
{
623+
601624
FileStream localCopyStream = copyFileInfo.Open(FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read);
602-
603-
ImageStream.CopyTo(localCopyStream);
604-
localCopyStream.Close();
625+
try
626+
{
627+
ImageStream.CopyTo(localCopyStream);
628+
} catch (Exception ce) {
629+
throw ce;
630+
} finally
631+
{
632+
localCopyStream.Close();
633+
localCopyStream.Dispose();
634+
}
635+
636+
} else
637+
{
638+
if (LocalPath != null)
639+
{
640+
FileStream localCopyStream = copyFileInfo.Open(FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read);
641+
try
642+
{
643+
FileStream destinationStream = File.Create(destination);
644+
645+
try
646+
{
647+
localCopyStream.CopyTo(destinationStream);
648+
} catch (Exception fwe)
649+
{
650+
throw fwe;
651+
} finally
652+
{
653+
destinationStream.Close();
654+
destinationStream.Dispose();
655+
}
656+
657+
}
658+
catch (Exception ce)
659+
{
660+
throw ce;
661+
}
662+
finally
663+
{
664+
localCopyStream.Close();
665+
localCopyStream.Dispose();
666+
}
667+
}
605668
}
606669
} else
607670
{
608671
if (LocalPath != null)
609672
{
610673
FileStream localCopyStream = copyFileInfo.Open(FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read);
611-
FileStream destinationStream = File.Create(destination);
612-
613-
localCopyStream.CopyTo(destinationStream);
674+
675+
try
676+
{
677+
FileStream destinationStream = File.Create(destination);
678+
try
679+
{
680+
localCopyStream.CopyTo(destinationStream);
681+
}
682+
catch (Exception fwe)
683+
{
684+
throw fwe;
685+
}
686+
finally
687+
{
688+
destinationStream.Close();
689+
destinationStream.Dispose();
690+
}
691+
} catch (Exception fwe)
692+
{
693+
throw fwe;
694+
} finally
695+
{
696+
localCopyStream.Close();
697+
localCopyStream.Dispose();
698+
}
614699
}
615700
}
616701

MyCBZ/Models/ProjectModel.cs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,7 @@ public void AddImagesProc()
911911
page.Number = realNewIndex + 1;
912912
page.Index = realNewIndex;
913913
page.OriginalIndex = realNewIndex;
914+
page.TemporaryFileId = MakeNewRandomId();
914915
realNewIndex++;
915916
} else
916917
{
@@ -1350,8 +1351,6 @@ public void RenamePage(Page page, String name, bool isRestored = false)
13501351

13511352
OnPageChanged(new PageChangedEvent(page, oldPage, PageChangedEvent.IMAGE_STATUS_RENAMED));
13521353
OnArchiveStatusChanged(new CBZArchiveStatusEvent(this, CBZArchiveStatusEvent.ARCHIVE_FILE_RENAMED));
1353-
1354-
oldPage.Close(true);
13551354
}
13561355

13571356
[MethodImpl(MethodImplOptions.Synchronized)]
@@ -1410,7 +1409,7 @@ public String ValueForPlaceholder(String placeholder, Page page)
14101409
return page.EntryName;
14111410

14121411
case "{ext}":
1413-
return page.FileExtension;
1412+
return page.FileExtension.TrimStart('.');
14141413

14151414
case "{index}":
14161415
return page.Index.ToString();
@@ -1723,6 +1722,7 @@ protected void SaveArchiveProc()
17231722
Thread.BeginCriticalRegion();
17241723
foreach (Page page in Pages)
17251724
{
1725+
String sourceFileName = "";
17261726
try
17271727
{
17281728
if (!page.Deleted)
@@ -1737,9 +1737,33 @@ protected void SaveArchiveProc()
17371737
}
17381738
}
17391739

1740-
page.FreeImage();
1740+
//page.FreeImage(); // Dont delete any temporary files here!
1741+
1742+
if (page.Changed || page.Compressed)
1743+
{
1744+
sourceFileName = page.TempPath;
1745+
try
1746+
{
1747+
FileInfo validateTemporaryFileName = new FileInfo(sourceFileName);
1748+
if (!validateTemporaryFileName.Exists)
1749+
{
1750+
page.CreateLocalWorkingCopy(validateTemporaryFileName.FullName);
1751+
1752+
1753+
}
1754+
} catch (Exception ex)
1755+
{
1756+
1757+
sourceFileName = page.LocalPath;
1758+
1759+
MessageLogger.Instance.Log(LogMessageEvent.LOGMESSAGE_TYPE_WARNING, "Failed to open temporary file! Compressing original file [" + page.LocalPath + "] instead of [" + page.TempPath + "]");
1760+
}
1761+
} else
1762+
{
1763+
sourceFileName = page.LocalPath;
1764+
}
17411765

1742-
updatedEntry = BuildingArchive.CreateEntryFromFile(page.TempPath, page.Name, CompressionLevel);
1766+
updatedEntry = BuildingArchive.CreateEntryFromFile(sourceFileName, page.Name, CompressionLevel);
17431767
if (IsNew)
17441768
{
17451769
page.UpdateImageEntry(updatedEntry, MakeNewRandomId());

MyCBZ/Win_CBZSettings.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MyCBZ/Win_CBZSettings.settings

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<Value Profile="(Default)">%APPDATA%\CBZMage\Temp\</Value>
77
</Setting>
88
<Setting Name="Version" Type="System.String" Scope="Application">
9-
<Value Profile="(Default)">0.13.63b</Value>
9+
<Value Profile="(Default)">0.13.64b</Value>
1010
</Setting>
1111
<Setting Name="RenamerPlaceholders" Type="System.Collections.Specialized.StringCollection" Scope="Application">
1212
<Value Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;

Readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Microsoft Visual Studio [Community] 2022 (64-Bit)
3030

3131
## Latest Release
3232

33-
v0.13.63b released!
33+
v0.13.64b released!
3434

3535
## Third party components
3636

Win_CBZ-Setup/Win_CBZ-Setup.vdproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,15 +434,15 @@
434434
{
435435
"Name" = "8:Microsoft Visual Studio"
436436
"ProductName" = "8:Win_CBZ"
437-
"ProductCode" = "8:{C9BA6C9C-5DF7-44B9-9DB0-5001A1E15BEA}"
438-
"PackageCode" = "8:{1A626B3C-DB59-473B-B143-34684DA639F7}"
437+
"ProductCode" = "8:{15DDBF27-26F5-4532-A542-CA3CD9C18E81}"
438+
"PackageCode" = "8:{0B5D4AE1-7371-4F2D-A900-16FBFE8D0C31}"
439439
"UpgradeCode" = "8:{66FAEF81-1CAE-4971-9E0F-796310EFEA5E}"
440440
"AspNetVersion" = "8:4.0.30319.0"
441441
"RestartWWWService" = "11:FALSE"
442442
"RemovePreviousVersions" = "11:TRUE"
443443
"DetectNewerInstalledVersion" = "11:TRUE"
444444
"InstallAllUsers" = "11:FALSE"
445-
"ProductVersion" = "8:0.13.63"
445+
"ProductVersion" = "8:0.13.64"
446446
"Manufacturer" = "8:Trash_s0Ft"
447447
"ARPHELPTELEPHONE" = "8:"
448448
"ARPHELPLINK" = "8:"

0 commit comments

Comments
 (0)