diff --git a/Snap2HTML/Models.cs b/Snap2HTML/Models.cs
index 0a38880..d514e04 100644
--- a/Snap2HTML/Models.cs
+++ b/Snap2HTML/Models.cs
@@ -15,6 +15,15 @@ namespace Snap2HTML
public bool openInBrowser { get; set; }
public bool linkFiles { get; set; }
public string linkRoot { get; set; }
+
+ public SnapSettings()
+ {
+ this.skipHiddenItems = true;
+ this.skipSystemItems = true;
+ this.openInBrowser = false;
+ this.linkFiles = false;
+ this.linkRoot = "";
+ }
}
diff --git a/Snap2HTML/ReadMe.txt b/Snap2HTML/ReadMe.txt
index 7975440..3fe84f8 100644
--- a/Snap2HTML/ReadMe.txt
+++ b/Snap2HTML/ReadMe.txt
@@ -99,9 +99,9 @@
Starts the program with the given root path already set
- Full: Snap2HTMl.exe [-path:"root folder path"] [-outfile:"filename"]
+ Full: Snap2HTMl.exe -path:"root folder path" -outfile:"filename"
[-link:"link to path"] [-title:"page title"]
- [-hidden] [-system]
+ [-hidden] [-system] [-silent]
-path:"root folder path" - The root path to load.
Example: -path:"c:\temp"
@@ -113,23 +113,26 @@
-link:"link to path" - The path to link files to.
Example: -link:"c:\temp"
- -title:"page title" - Set the page title
+ -title:"page title" - Set the page title. If omitted, title
+ is generated based on path.
- -hidden - Include hidden items
-
+ -hidden - Include hidden items
+
-system - Include system items
-silent - Run without showing the window (only
if both -path and -outfile are used)
-
- Notes: Using -path and -outfile will cause the program to automatically
- start generating the snapshot, and quit when done!
+ Notes: When both -path and -outfile are specified, the program will
+ automatically start generating the snapshot, and quit when done.
Always surround paths and filenames with quotes ("")!
- Do not include the [sqaure brackets] when you write your command
- line. (Sqaure brackets signify optional command line parameters)
+ In silent mode, in case or error the program will just quit
+ without telling why.
+
+ Do not include the [square brackets] when you write your command
+ line. (Square brackets signify optional command line parameters)
--- Template Design ---------------------------------------------------------
@@ -229,6 +232,8 @@
v2.11 (2020-04-18)
Fixed a threading issue that caused the program to hang on some systems
+ v2.12 (2020-04-)
+
--- End User License Agreement -----------------------------------------------
diff --git a/Snap2HTML/frmMain.cs b/Snap2HTML/frmMain.cs
index 839375e..0be1632 100644
--- a/Snap2HTML/frmMain.cs
+++ b/Snap2HTML/frmMain.cs
@@ -11,8 +11,8 @@ namespace Snap2HTML
{
public partial class frmMain : Form
{
- private string outFile = ""; // set when automating via command line
private bool initDone = false;
+ private bool runningAutomated = false;
public frmMain()
{
@@ -65,40 +65,63 @@ namespace Snap2HTML
var arguments = new Arguments(splitCommandLine);
// first test for single argument (ie path only)
- if (splitCommandLine.Length == 2 && !arguments.Exists("path"))
- {
- if (System.IO.Directory.Exists(splitCommandLine[1]))
- {
+ if( splitCommandLine.Length == 2 && !arguments.Exists( "path" ) )
+ {
+ if( System.IO.Directory.Exists( splitCommandLine[1] ) )
+ {
SetRootPath( splitCommandLine[1] );
- }
- }
+ }
+ }
- var autoRun = false;
-
- if (arguments.IsTrue("hidden")) chkHidden.Checked = true;
- if (arguments.IsTrue("system")) chkSystem.Checked = true;
- if( arguments.Exists( "path" ) )
+ var settings = new SnapSettings();
+ if( arguments.Exists( "path" ) && arguments.Exists( "outfile" ) )
{
- // note: relative paths not handled
- string path = arguments.Single( "path" );
- if( !System.IO.Directory.Exists( path ) ) path = Environment.CurrentDirectory + System.IO.Path.DirectorySeparatorChar + path;
+ this.runningAutomated = true;
- if( System.IO.Directory.Exists( path ) )
- {
- SetRootPath( path );
+ settings.rootFolder = arguments.Single( "path" );
+ settings.outputFile = arguments.Single( "outfile" );
+
+ // First validate paths
+ if( !System.IO.Directory.Exists( settings.rootFolder ) )
+ {
+ if( !arguments.Exists( "silent" ) )
+ {
+ MessageBox.Show( "Input path does not exist: " + settings.rootFolder, "Automation Error", MessageBoxButtons.OK, MessageBoxIcon.Error );
+ }
+ Application.Exit();
+ }
+ if( !System.IO.Directory.Exists( System.IO.Path.GetDirectoryName(settings.outputFile) ) )
+ {
+ if( !arguments.Exists( "silent" ) )
+ {
+ MessageBox.Show( "Output path does not exist: " + System.IO.Path.GetDirectoryName( settings.outputFile ), "Automation Error", MessageBoxButtons.OK, MessageBoxIcon.Error );
+ }
+ Application.Exit();
+ }
+
+ // Rest of settings
+
+ settings.skipHiddenItems = !arguments.Exists( "hidden" );
+ settings.skipSystemItems = !arguments.Exists( "system" );
+ settings.openInBrowser = false;
+
+ settings.linkFiles = false;
+ if( arguments.Exists( "link" ) )
+ {
+ settings.linkFiles = true;
+ settings.linkRoot = arguments.Single( "link" );
+ }
+
+ settings.title = "Snapshot of " + settings.rootFolder;
+ if( arguments.Exists( "title" ) )
+ {
+ settings.title = arguments.Single( "title" );
+ }
- // if outfile is also given, start generating snapshot
- if (arguments.Exists("outfile"))
- {
- autoRun = true;
- outFile = arguments.Single("outfile");
- cmdCreate.PerformClick();
- }
- }
}
// keep window hidden in silent mode
- if( arguments.IsTrue( "silent" ) && autoRun )
+ if( arguments.IsTrue( "silent" ) && this.runningAutomated )
{
Visible = false;
}
@@ -107,24 +130,17 @@ namespace Snap2HTML
Opacity = 100;
}
- // run link/title after path, since path automatically updates title
- if( arguments.Exists( "link" ) )
+ if( this.runningAutomated )
{
- chkLinkFiles.Checked = true;
- txtLinkRoot.Text = arguments.Single( "link" );
- txtLinkRoot.Enabled = true;
+ StartProcessing( settings );
}
- if( arguments.Exists( "title" ) )
- {
- txtTitle.Text = arguments.Single( "title" );
- }
}
private void frmMain_FormClosing( object sender, FormClosingEventArgs e )
{
if( backgroundWorker.IsBusy ) e.Cancel = true;
- if( outFile == "" ) // don't save settings when automated through command line
+ if( !this.runningAutomated ) // don't save settings when automated through command line
{
Snap2HTML.Properties.Settings.Default.WindowLeft = this.Left;
Snap2HTML.Properties.Settings.Default.WindowTop = this.Top;
@@ -152,57 +168,25 @@ namespace Snap2HTML
private void cmdCreate_Click(object sender, EventArgs e)
{
- // ensure source path format
- txtRoot.Text = System.IO.Path.GetFullPath( txtRoot.Text );
- if (txtRoot.Text.EndsWith(@"\")) txtRoot.Text = txtRoot.Text.Substring(0, txtRoot.Text.Length - 1);
- if( Utils.IsWildcardMatch( "?:", txtRoot.Text, false ) ) txtRoot.Text += @"\"; // add backslash to path if only letter and colon eg "c:"
-
- // add slash or backslash to end of link (in cases where it is clearthat we we can)
- if( !txtLinkRoot.Text.EndsWith( @"/" ) && txtLinkRoot.Text.ToLower().StartsWith( @"http" ) ) // web site
+ // ask for output file
+ string fileName = new System.IO.DirectoryInfo( txtRoot.Text + @"\" ).Name;
+ char[] invalid = System.IO.Path.GetInvalidFileNameChars();
+ for (int i = 0; i < invalid.Length; i++)
{
- txtLinkRoot.Text += @"/";
- }
- if( !txtLinkRoot.Text.EndsWith( @"\" ) && Utils.IsWildcardMatch( "?:*", txtLinkRoot.Text, false ) ) // local disk
- {
- txtLinkRoot.Text += @"\";
+ fileName = fileName.Replace(invalid[i].ToString(), "");
}
- // get output file
- if( outFile == "" )
- {
- string fileName = new System.IO.DirectoryInfo( txtRoot.Text + @"\" ).Name;
- char[] invalid = System.IO.Path.GetInvalidFileNameChars();
- for (int i = 0; i < invalid.Length; i++)
- {
- fileName = fileName.Replace(invalid[i].ToString(), "");
- }
-
- saveFileDialog1.DefaultExt = "html";
- if( !fileName.ToLower().EndsWith( ".html" ) ) fileName += ".html";
- saveFileDialog1.FileName = fileName;
- saveFileDialog1.Filter = "HTML files (*.html)|*.html|All files (*.*)|*.*";
- saveFileDialog1.InitialDirectory = System.IO.Path.GetDirectoryName(txtRoot.Text);
- if (saveFileDialog1.ShowDialog() != DialogResult.OK) return;
- }
- else // command line
- {
- saveFileDialog1.FileName = outFile;
- }
+ saveFileDialog1.DefaultExt = "html";
+ if( !fileName.ToLower().EndsWith( ".html" ) ) fileName += ".html";
+ saveFileDialog1.FileName = fileName;
+ saveFileDialog1.Filter = "HTML files (*.html)|*.html|All files (*.*)|*.*";
+ saveFileDialog1.InitialDirectory = System.IO.Path.GetDirectoryName(txtRoot.Text);
+ saveFileDialog1.CheckPathExists = true;
+ if (saveFileDialog1.ShowDialog() != DialogResult.OK) return;
if( !saveFileDialog1.FileName.ToLower().EndsWith( ".html" ) ) saveFileDialog1.FileName += ".html";
- // make sure output path exists
- if( !System.IO.Directory.Exists( System.IO.Path.GetDirectoryName( saveFileDialog1.FileName ) ) )
- {
- MessageBox.Show( "The output folder does not exists...\n\n" + System.IO.Path.GetDirectoryName( saveFileDialog1.FileName ), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error );
- return;
- }
-
// begin generating html
- Cursor.Current = Cursors.WaitCursor;
- this.Text = "Snap2HTML (Working... Press Escape to Cancel)";
- tabControl1.Enabled = false;
-
var settings = new SnapSettings()
{
rootFolder = txtRoot.Text,
@@ -214,8 +198,33 @@ namespace Snap2HTML
linkFiles = chkLinkFiles.Checked,
linkRoot = txtLinkRoot.Text,
};
- backgroundWorker.RunWorkerAsync(argument: settings);
+ StartProcessing(settings);
+ }
+ private void StartProcessing(SnapSettings settings)
+ {
+ // ensure source path format
+ settings.rootFolder = System.IO.Path.GetFullPath( settings.rootFolder );
+ if( settings.rootFolder.EndsWith( @"\" ) ) settings.rootFolder = settings.rootFolder.Substring( 0, settings.rootFolder.Length - 1 );
+ if( Utils.IsWildcardMatch( "?:", settings.rootFolder, false ) ) settings.rootFolder += @"\"; // add backslash to path if only letter and colon eg "c:"
+
+ // add slash or backslash to end of link (in cases where it is clear that we we can)
+ if( settings.linkFiles )
+ {
+ if( !settings.linkRoot.EndsWith( @"/" ) && settings.linkRoot.ToLower().StartsWith( @"http" ) ) // web site
+ {
+ settings.linkRoot += @"/";
+ }
+ if( !settings.linkRoot.EndsWith( @"\" ) && Utils.IsWildcardMatch( "?:*", settings.linkRoot, false ) ) // local disk
+ {
+ settings.linkRoot += @"\";
+ }
+ }
+
+ Cursor.Current = Cursors.WaitCursor;
+ this.Text = "Snap2HTML (Working... Press Escape to Cancel)";
+ tabControl1.Enabled = false;
+ backgroundWorker.RunWorkerAsync( argument: settings );
}
private void backgroundWorker_ProgressChanged( object sender, ProgressChangedEventArgs e )
@@ -233,7 +242,7 @@ namespace Snap2HTML
this.Text = "Snap2HTML";
// Quit when finished if automated via command line
- if( outFile != "" )
+ if( this.runningAutomated )
{
Application.Exit();
}
diff --git a/Snap2HTML/frmMain_BackgroundWorker.cs b/Snap2HTML/frmMain_BackgroundWorker.cs
index 164d5cc..befc9f3 100644
--- a/Snap2HTML/frmMain_BackgroundWorker.cs
+++ b/Snap2HTML/frmMain_BackgroundWorker.cs
@@ -75,7 +75,7 @@ namespace Snap2HTML
sbTemplate.Replace( "[NUM FILES]", totFiles.ToString() );
sbTemplate.Replace( "[NUM DIRS]", totDirs.ToString() );
sbTemplate.Replace( "[TOT SIZE]", totSize.ToString() );
- if( chkLinkFiles.Checked )
+ if( settings.linkFiles )
{
sbTemplate.Replace( "[LINK FILES]", "true" );
sbTemplate.Replace( "[LINK ROOT]", settings.linkRoot.Replace( @"\", "/" ) );