Bugfix: UNC paths stopped working since 2.1

This commit is contained in:
rlv-dan 2020-08-09 13:31:17 +02:00
parent a68b36c02e
commit b3476e455a
3 changed files with 35 additions and 4 deletions

View File

@ -65,7 +65,23 @@ namespace Snap2HTML
public string GetFullPath() public string GetFullPath()
{ {
return ( this.Path + "\\" + this.Name ).Replace( "\\\\", "\\" ); string path;
if( this.Path.EndsWith( @"\" ) )
path = this.Path + this.Name;
else
path = this.Path + @"\" + this.Name;
if( path.EndsWith( @"\" ) ) // remove trailing backslash
{
if(!Utils.IsWildcardMatch( @"?:\", path, false )) // except for drive letters
{
path = path.Remove( path.Length - 1 );
}
}
return path;
} }
public string GetProp( string key ) public string GetProp( string key )

View File

@ -211,14 +211,21 @@ namespace Snap2HTML
// add slash or backslash to end of link (in cases where it is clear that we we can) // add slash or backslash to end of link (in cases where it is clear that we we can)
if( settings.linkFiles ) if( settings.linkFiles )
{ {
if( !settings.linkRoot.EndsWith( @"/" ) && settings.linkRoot.ToLower().StartsWith( @"http" ) ) // web site if( !settings.linkRoot.EndsWith( @"/" ) )
{
if( settings.linkRoot.ToLower().StartsWith( @"http" ) ) // web site
{ {
settings.linkRoot += @"/"; settings.linkRoot += @"/";
} }
if( !settings.linkRoot.EndsWith( @"\" ) && Utils.IsWildcardMatch( "?:*", settings.linkRoot, false ) ) // local disk if( Utils.IsWildcardMatch( "?:*", settings.linkRoot, false ) ) // local disk
{ {
settings.linkRoot += @"\"; settings.linkRoot += @"\";
} }
if( settings.linkRoot.StartsWith( @"\\" ) ) // unc path
{
settings.linkRoot += @"\";
}
}
} }
Cursor.Current = Cursors.WaitCursor; Cursor.Current = Cursors.WaitCursor;

View File

@ -86,10 +86,15 @@ namespace Snap2HTML
{ {
sbTemplate.Replace( "[LINK PROTOCOL]", @"file://" ); sbTemplate.Replace( "[LINK PROTOCOL]", @"file://" );
} }
else if( link_root.StartsWith( "//" ) ) // for UNC paths e.g. \\server\path
{
sbTemplate.Replace( "[LINK PROTOCOL]", @"file://///" );
}
else else
{ {
sbTemplate.Replace( "[LINK PROTOCOL]", "" ); sbTemplate.Replace( "[LINK PROTOCOL]", "" );
} }
} }
else else
{ {
@ -355,10 +360,12 @@ namespace Snap2HTML
var subdirs = new Dictionary<string, List<string>>(); var subdirs = new Dictionary<string, List<string>>();
foreach( var dir in content ) foreach( var dir in content )
{ {
// add all folders as keys
subdirs.Add( dir.GetFullPath(), new List<string>() ); subdirs.Add( dir.GetFullPath(), new List<string>() );
} }
if( !subdirs.ContainsKey( content[0].Path ) && content[0].Name != "" ) if( !subdirs.ContainsKey( content[0].Path ) && content[0].Name != "" )
{ {
// ensure that root folder is not missed missed
subdirs.Add( content[0].Path, new List<string>() ); subdirs.Add( content[0].Path, new List<string>() );
} }
foreach( var dir in content ) foreach( var dir in content )
@ -367,6 +374,7 @@ namespace Snap2HTML
{ {
try try
{ {
// for each folder, add its index to its parent folder list of subdirs
subdirs[dir.Path].Add( dirIndexes[dir.GetFullPath()] ); subdirs[dir.Path].Add( dirIndexes[dir.GetFullPath()] );
} }
catch( Exception ex ) catch( Exception ex )
@ -397,7 +405,7 @@ namespace Snap2HTML
result.Append( "" ).Append( dirSize ).Append( "," + lineBreakSymbol ); result.Append( "" ).Append( dirSize ).Append( "," + lineBreakSymbol );
// Add reference to subdirs // Add reference to subdirs
result.Append( "\"" ).Append( String.Join( "*", subdirs[currentDir.GetFullPath()].ToArray() ) ).Append( "\"" + lineBreakSymbol ); // subdirs result.Append( "\"" ).Append( String.Join( "*", subdirs[currentDir.GetFullPath()].ToArray() ) ).Append( "\"" + lineBreakSymbol );
// Finalize // Finalize
result.Append( "])" ); result.Append( "])" );