From a622e419a19bb26cb9c958aae3eeefb8cf56b3e3 Mon Sep 17 00:00:00 2001 From: rlv-dan Date: Tue, 28 Apr 2020 19:12:04 +0200 Subject: [PATCH] Get ful path from model on-the-fly to reduce memory consumsion --- Snap2HTML/Models.cs | 7 +++++-- Snap2HTML/frmMain_BackgroundWorker.cs | 10 +++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Snap2HTML/Models.cs b/Snap2HTML/Models.cs index ba64e85..0a38880 100644 --- a/Snap2HTML/Models.cs +++ b/Snap2HTML/Models.cs @@ -47,15 +47,18 @@ namespace Snap2HTML this.Path = path; this.Properties = new Dictionary(); this.Files = new List(); - this.FullPath = ( this.Path + "\\" + this.Name ).Replace( "\\\\", "\\" ); } public string Name { get; set; } public string Path { get; set; } - public string FullPath { get; set; } public Dictionary Properties { get; set; } public List Files { get; set; } + public string GetFullPath() + { + return ( this.Path + "\\" + this.Name ).Replace( "\\\\", "\\" ); + } + public string GetProp( string key ) { if( this.Properties.ContainsKey( key ) ) diff --git a/Snap2HTML/frmMain_BackgroundWorker.cs b/Snap2HTML/frmMain_BackgroundWorker.cs index 13d323e..164d5cc 100644 --- a/Snap2HTML/frmMain_BackgroundWorker.cs +++ b/Snap2HTML/frmMain_BackgroundWorker.cs @@ -346,14 +346,14 @@ namespace Snap2HTML var dirIndexes = new Dictionary(); for( var i = 0; i < content.Count; i++ ) { - dirIndexes.Add( content[i].FullPath, ( i + startIndex ).ToString() ); + dirIndexes.Add( content[i].GetFullPath(), ( i + startIndex ).ToString() ); } // Build a lookup table with subfolder IDs for each folder var subdirs = new Dictionary>(); foreach( var dir in content ) { - subdirs.Add( dir.FullPath, new List() ); + subdirs.Add( dir.GetFullPath(), new List() ); } if( !subdirs.ContainsKey( content[0].Path ) && content[0].Name != "" ) { @@ -365,7 +365,7 @@ namespace Snap2HTML { try { - subdirs[dir.Path].Add( dirIndexes[dir.FullPath] ); + subdirs[dir.Path].Add( dirIndexes[dir.GetFullPath()] ); } catch( Exception ex ) { @@ -380,7 +380,7 @@ namespace Snap2HTML { result.Append( "D.p([" + lineBreakSymbol ); - var sDirWithForwardSlash = currentDir.FullPath.Replace( @"\", "/" ); + var sDirWithForwardSlash = currentDir.GetFullPath().Replace( @"\", "/" ); result.Append( "\"" ).Append( Utils.MakeCleanJsString( sDirWithForwardSlash ) ).Append( "*" ).Append( "0" ).Append( "*" ).Append( currentDir.GetProp( "Modified" ) ).Append( "\"," + lineBreakSymbol ); long dirSize = 0; @@ -395,7 +395,7 @@ namespace Snap2HTML result.Append( "" ).Append( dirSize ).Append( "," + lineBreakSymbol ); // Add reference to subdirs - result.Append( "\"" ).Append( String.Join( "*", subdirs[currentDir.FullPath].ToArray() ) ).Append( "\"" + lineBreakSymbol ); // subdirs + result.Append( "\"" ).Append( String.Join( "*", subdirs[currentDir.GetFullPath()].ToArray() ) ).Append( "\"" + lineBreakSymbol ); // subdirs // Finalize result.Append( "])" );