From d1235b1a26a9f9ff25d16a50f42e6196151f2319 Mon Sep 17 00:00:00 2001 From: alcexhim Date: Fri, 24 Jul 2015 12:05:30 -0400 Subject: [PATCH] Skip over impossibly huge files when icon loading, and use block-based File.WriteTo instead of deprecated Save function --- .../Editors/FileSystemEditor.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/CSharp/Engines/WindowsForms/Libraries/UniversalEditor.UserInterface.WindowsForms/Editors/FileSystemEditor.cs b/CSharp/Engines/WindowsForms/Libraries/UniversalEditor.UserInterface.WindowsForms/Editors/FileSystemEditor.cs index 854382af..1da1d070 100644 --- a/CSharp/Engines/WindowsForms/Libraries/UniversalEditor.UserInterface.WindowsForms/Editors/FileSystemEditor.cs +++ b/CSharp/Engines/WindowsForms/Libraries/UniversalEditor.UserInterface.WindowsForms/Editors/FileSystemEditor.cs @@ -118,6 +118,8 @@ namespace UniversalEditor.UserInterface.WindowsForms.Editors TemporaryFileManager.UnregisterTemporaryDirectory(); } + private const int ICON_LOADER_SKIP_THRESHOLD_SIZE = 8388608; + private System.Threading.Thread tIconLoader = null; private void tIconLoader_ThreadStart() { @@ -126,6 +128,9 @@ namespace UniversalEditor.UserInterface.WindowsForms.Editors File file = (lvi.Data as File); if (file == null) continue; + // skip over impossibly huge files of an arbitrary threshold size + if (file.Size > ICON_LOADER_SKIP_THRESHOLD_SIZE) continue; + byte[] data = file.GetData(); if (data == null) continue; @@ -464,13 +469,13 @@ namespace UniversalEditor.UserInterface.WindowsForms.Editors File file = (lvi.Data as File); if (file != null) { - byte[] data = file.GetData(); - if (String.IsNullOrEmpty(file.Name)) { file.Name = "[]"; } - string filePath = TemporaryFileManager.CreateTemporaryFile(file.Name, data); + + string filePath = TemporaryFileManager.CreateTemporaryFile(file.Name); + file.WriteTo(new IO.Writer(new FileAccessor(filePath, true, true, true))); filePaths.Add(filePath); file.Properties["tempfile"] = filePath; @@ -882,7 +887,7 @@ namespace UniversalEditor.UserInterface.WindowsForms.Editors { System.IO.Directory.CreateDirectory(ParentDirectoryName); } - file.Save(FileName); + file.WriteTo(new IO.Writer(new FileAccessor(FileName))); } HostApplication.CurrentWindow.UpdateProgress(false); HostApplication.CurrentWindow.UpdateStatus("Ready");