22using System . ComponentModel ;
33using System . IO ;
44using System . Windows . Forms ;
5- using CommandLine . Utility ;
65using Snap2HTMLNG . Shared . Settings ;
7- using Snap2HTMLNG . Shared . Utils ;
86
97namespace Snap2HTMLNG
108{
@@ -36,7 +34,9 @@ private void frmMain_Load(object sender, EventArgs e)
3634 }
3735 else
3836 {
39- SetRootPath ( "" ) ;
37+ // If the root path isn't valid, just set it to the current directory
38+ // instead of making it null
39+ SetRootPath ( Directory . GetCurrentDirectory ( ) ) ;
4040 }
4141
4242 txtLinkRoot . Enabled = chkLinkFiles . Checked ;
@@ -70,31 +70,33 @@ private void LoadUserSettings()
7070 txtSearchPattern . Text = XmlConfigurator . Read ( "SearchPattern" ) ;
7171 }
7272
73+ /// <summary>
74+ /// If the user closes the GUI, ensure that we kill the background worker
75+ /// </summary>
7376 private void frmMain_FormClosing ( object sender , FormClosingEventArgs e )
7477 {
7578 if ( backgroundWorker . IsBusy ) e . Cancel = true ;
7679 }
7780
7881 private void cmdBrowse_Click ( object sender , EventArgs e )
7982 {
80- folderBrowserDialog1 . RootFolder = Environment . SpecialFolder . Desktop ; // this makes it possible to select network paths too
81- folderBrowserDialog1 . SelectedPath = txtRoot . Text ;
83+ fbdScanDirectory . RootFolder = Environment . SpecialFolder . Desktop ; // this makes it possible to select network paths too
84+ fbdScanDirectory . SelectedPath = txtRoot . Text ;
8285
83- if ( folderBrowserDialog1 . ShowDialog ( ) == DialogResult . OK )
86+ if ( fbdScanDirectory . ShowDialog ( ) == DialogResult . OK )
8487 {
85- txtRoot . Text = folderBrowserDialog1 . SelectedPath ;
88+ txtRoot . Text = fbdScanDirectory . SelectedPath ;
8689 }
8790 }
8891
8992 private void cmdCreate_Click ( object sender , EventArgs e )
9093 {
9194 if ( SetRootPath ( txtRoot . Text ) )
9295 {
93-
9496 // Check if the search pattern starts with an astrix or not
9597 if ( ! txtSearchPattern . Text . StartsWith ( "*" ) )
9698 {
97- string tmp = txtSearchPattern . Text ;
99+ // We need to have an astrix at the start, so amend the pattern if it doesn't have it
98100 txtSearchPattern . Text = $ "*{ txtSearchPattern . Text } ";
99101 }
100102
@@ -106,10 +108,11 @@ private void cmdCreate_Click(object sender, EventArgs e)
106108 fileName = fileName . Replace ( invalid [ i ] . ToString ( ) , "" ) ;
107109 }
108110
111+ // Ask the user where they want to save the file to.
109112 saveFileDialog1 . DefaultExt = "html" ;
110113 if ( ! fileName . ToLower ( ) . EndsWith ( ".html" ) ) fileName += ".html" ;
111114 saveFileDialog1 . FileName = fileName ;
112- saveFileDialog1 . Filter = "HTML files (*.html)|*.html|All files (*.*)|*.* " ;
115+ saveFileDialog1 . Filter = "HTML files (*.html)|*.html" ;
113116 saveFileDialog1 . InitialDirectory = Path . GetDirectoryName ( txtRoot . Text ) ;
114117 saveFileDialog1 . CheckPathExists = true ;
115118 if ( saveFileDialog1 . ShowDialog ( ) != DialogResult . OK ) return ;
@@ -157,11 +160,10 @@ private void StartProcessing()
157160 var rootFolder = Path . GetFullPath ( XmlConfigurator . Read ( "RootFolder" ) ) ;
158161
159162 if ( rootFolder . EndsWith ( @"\" ) ) rootFolder = rootFolder . Substring ( 0 , rootFolder . Length - 1 ) ;
160- if ( Helpers . IsWildcardMatch ( "?:" , rootFolder , false ) ) rootFolder += @"\" ; // add backslash to path if only letter and colon eg "c:"
163+ if ( Shared . Utils . Legacy . Helpers . IsWildcardMatch ( "?:" , rootFolder , false ) ) rootFolder += @"\" ; // add backslash to path if only letter and colon eg "c:"
161164
162165 // add slash or backslash to end of link (in cases where it is clear that we we can)
163166
164-
165167 bool linkFiles = bool . Parse ( XmlConfigurator . Read ( "LinkFiles" ) ) ;
166168 string linkRoot = XmlConfigurator . Read ( "LinkRoot" ) ;
167169 if ( linkFiles )
@@ -172,7 +174,7 @@ private void StartProcessing()
172174 {
173175 linkRoot += @"/" ;
174176 }
175- if ( Helpers . IsWildcardMatch ( "?:*" , linkRoot , false ) ) // local disk
177+ if ( Shared . Utils . Legacy . Helpers . IsWildcardMatch ( "?:*" , linkRoot , false ) ) // local disk
176178 {
177179 linkRoot += @"\" ;
178180 }
@@ -191,7 +193,7 @@ private void StartProcessing()
191193
192194 private void backgroundWorker_ProgressChanged ( object sender , ProgressChangedEventArgs e )
193195 {
194- toolStripStatusLabel1 . Text = e . UserState . ToString ( ) ;
196+ lblStatus . Text = e . UserState . ToString ( ) ;
195197 }
196198
197199 private void backgroundWorker_RunWorkerCompleted ( object sender , RunWorkerCompletedEventArgs e )
@@ -278,11 +280,11 @@ private void DragDropHandler(object sender, DragEventArgs e)
278280 if ( Directory . Exists ( path ) )
279281 {
280282 txtRoot . Text = path ;
281- toolStripStatusLabel1 . Text = $ "Set Root Path to { path } ";
283+ lblStatus . Text = $ "Set Root Path to { path } ";
282284 }
283285 else
284286 {
285- toolStripStatusLabel1 . Text = "Path does not exist or is invalid." ;
287+ lblStatus . Text = "Path does not exist or is invalid." ;
286288 }
287289 }
288290 }
@@ -318,7 +320,7 @@ private bool SetRootPath(string path)
318320 {
319321 if ( Directory . Exists ( path ) )
320322 {
321- toolStripStatusLabel1 . Text = "" ;
323+ lblStatus . Text = "" ;
322324
323325 if ( initDone )
324326 {
@@ -330,7 +332,7 @@ private bool SetRootPath(string path)
330332 }
331333 else
332334 {
333- toolStripStatusLabel1 . Text = "Root path is invalid!" ;
335+ lblStatus . Text = "Root path is invalid!" ;
334336
335337 if ( initDone )
336338 {
0 commit comments