33using System . IO ;
44using System . Windows . Forms ;
55using CommandLine . Utility ;
6+ using Snap2HTMLNG . Shared . Settings ;
67using Snap2HTMLNG . Shared . Utils ;
78
89namespace Snap2HTMLNG
@@ -73,49 +74,48 @@ private void frmMain_Shown(object sender, EventArgs e)
7374 }
7475 }
7576
76- var settings = new Model . SnapSettings ( ) ;
7777 if ( arguments . Exists ( "path" ) && arguments . Exists ( "outfile" ) )
7878 {
7979 this . runningAutomated = true ;
8080
81- settings . rootFolder = arguments . Single ( "path" ) ;
82- settings . outputFile = arguments . Single ( "outfile" ) ;
81+ var rootFolder = arguments . Single ( "path" ) ;
82+ var outputFile = arguments . Single ( "outfile" ) ;
8383
8484 // First validate paths
85- if ( ! Directory . Exists ( settings . rootFolder ) )
85+ if ( ! Directory . Exists ( rootFolder ) )
8686 {
8787 if ( ! arguments . Exists ( "silent" ) )
8888 {
89- MessageBox . Show ( "Input path does not exist: " + settings . rootFolder , "Automation Error" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
89+ MessageBox . Show ( "Input path does not exist: " + rootFolder , "Automation Error" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
9090 }
9191 Application . Exit ( ) ;
9292 }
93- if ( ! Directory . Exists ( Path . GetDirectoryName ( settings . outputFile ) ) )
93+ if ( ! Directory . Exists ( Path . GetDirectoryName ( outputFile ) ) )
9494 {
9595 if ( ! arguments . Exists ( "silent" ) )
9696 {
97- MessageBox . Show ( "Output path does not exist: " + Path . GetDirectoryName ( settings . outputFile ) , "Automation Error" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
97+ MessageBox . Show ( "Output path does not exist: " + Path . GetDirectoryName ( outputFile ) , "Automation Error" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
9898 }
9999 Application . Exit ( ) ;
100100 }
101101
102102 // Rest of settings
103103
104- settings . skipHiddenItems = ! arguments . Exists ( "hidden" ) ;
105- settings . skipSystemItems = ! arguments . Exists ( "system" ) ;
106- settings . openInBrowser = false ;
104+ bool skipHiddenItems = ! arguments . Exists ( "hidden" ) ;
105+ bool skipSystemItems = ! arguments . Exists ( "system" ) ;
106+ bool openInBrowser = false ;
107107
108- settings . linkFiles = false ;
108+ bool linkFiles = false ;
109109 if ( arguments . Exists ( "link" ) )
110110 {
111- settings . linkFiles = true ;
112- settings . linkRoot = arguments . Single ( "link" ) ;
111+ linkFiles = true ;
112+ string linkRoot = arguments . Single ( "link" ) ;
113113 }
114114
115- settings . title = "Snapshot of " + settings . rootFolder ;
115+ string title = "Snapshot of " + rootFolder ;
116116 if ( arguments . Exists ( "title" ) )
117117 {
118- settings . title = arguments . Single ( "title" ) ;
118+ title = arguments . Single ( "title" ) ;
119119 }
120120
121121 }
@@ -132,7 +132,7 @@ private void frmMain_Shown(object sender, EventArgs e)
132132
133133 if ( this . runningAutomated )
134134 {
135- StartProcessing ( settings ) ;
135+ StartProcessing ( ) ;
136136 }
137137 }
138138
@@ -189,55 +189,77 @@ private void cmdCreate_Click(object sender, EventArgs e)
189189
190190 if ( ! saveFileDialog1 . FileName . ToLower ( ) . EndsWith ( ".html" ) ) saveFileDialog1 . FileName += ".html" ;
191191
192- // begin generating html
193- var settings = new Model . SnapSettings ( )
192+ // Declare the user settings nodes that are available in UserSettings.xml (see Shared.UserSettings.xml)
193+ string [ ] nodes = {
194+ "RootFolder" ,
195+ "Title" ,
196+ "OutputFile" ,
197+ "SkipHiddenItems" ,
198+ "SkipSystemItems" ,
199+ "OpenInBrowserAfterCapture" ,
200+ "LinkFiles" ,
201+ "LinkRoot" ,
202+ "SearchPattern"
203+ } ;
204+
205+ // Declare our actual values to be saved to the nodes
206+ string [ ] values =
194207 {
195- rootFolder = txtRoot . Text ,
196- title = txtTitle . Text ,
197- outputFile = saveFileDialog1 . FileName ,
198- skipHiddenItems = ! chkHidden . Checked ,
199- skipSystemItems = ! chkSystem . Checked ,
200- openInBrowser = chkOpenOutput . Checked ,
201- linkFiles = chkLinkFiles . Checked ,
202- linkRoot = txtLinkRoot . Text ,
203- searchPattern = txtSearchPattern . Text ,
208+ txtRoot . Text ,
209+ txtTitle . Text ,
210+ saveFileDialog1 . FileName ,
211+ chkHidden . Checked . ToString ( ) ,
212+ chkSystem . Checked . ToString ( ) ,
213+ chkOpenOutput . Checked . ToString ( ) ,
214+ chkLinkFiles . Checked . ToString ( ) ,
215+ txtLinkRoot . Text ,
216+ txtSearchPattern . Text
204217 } ;
205218
206- StartProcessing ( settings ) ;
219+ // Write the settings to the SettingsFile // TODO: Do I need to move this so we can run from schedule multiple different times? I think so.
220+ XmlConfigurator . Write ( nodes , values ) ;
221+
222+ // begin generating html
223+ StartProcessing ( ) ;
207224 }
208225 }
209226
210- private void StartProcessing ( Model . SnapSettings settings )
227+ private void StartProcessing ( )
211228 {
212229 // ensure source path format
213- settings . rootFolder = Path . GetFullPath ( settings . rootFolder ) ;
214- if ( settings . rootFolder . EndsWith ( @"\" ) ) settings . rootFolder = settings . rootFolder . Substring ( 0 , settings . rootFolder . Length - 1 ) ;
215- if ( Legacy . IsWildcardMatch ( "?:" , settings . rootFolder , false ) ) settings . rootFolder += @"\" ; // add backslash to path if only letter and colon eg "c:"
230+ var rootFolder = Path . GetFullPath ( XmlConfigurator . Read ( "RootFolder" ) ) ;
231+
232+ if ( rootFolder . EndsWith ( @"\" ) ) rootFolder = rootFolder . Substring ( 0 , rootFolder . Length - 1 ) ;
233+ if ( Legacy . IsWildcardMatch ( "?:" , rootFolder , false ) ) rootFolder += @"\" ; // add backslash to path if only letter and colon eg "c:"
216234
217235 // add slash or backslash to end of link (in cases where it is clear that we we can)
218- if ( settings . linkFiles )
236+
237+
238+ bool linkFiles = bool . Parse ( XmlConfigurator . Read ( "LinkFiles" ) ) ;
239+ string linkRoot = XmlConfigurator . Read ( "LinkRoot" ) ;
240+ if ( linkFiles )
219241 {
220- if ( ! settings . linkRoot . EndsWith ( @"/" ) )
242+ if ( ! linkRoot . EndsWith ( @"/" ) )
221243 {
222- if ( settings . linkRoot . ToLower ( ) . StartsWith ( @"http" ) || settings . linkRoot . ToLower ( ) . StartsWith ( @"https" ) ) // web site
244+ if ( linkRoot . ToLower ( ) . StartsWith ( @"http" ) || linkRoot . ToLower ( ) . StartsWith ( @"https" ) ) // web site
223245 {
224- settings . linkRoot += @"/" ;
246+ linkRoot += @"/" ;
225247 }
226- if ( Legacy . IsWildcardMatch ( "?:*" , settings . linkRoot , false ) ) // local disk
248+ if ( Legacy . IsWildcardMatch ( "?:*" , linkRoot , false ) ) // local disk
227249 {
228- settings . linkRoot += @"\" ;
250+ linkRoot += @"\" ;
229251 }
230- if ( settings . linkRoot . StartsWith ( @"\\" ) ) // unc path
252+ if ( linkRoot . StartsWith ( @"\\" ) ) // unc path
231253 {
232- settings . linkRoot += @"\" ;
254+ linkRoot += @"\" ;
233255 }
234256 }
235257 }
236258
237259 Cursor . Current = Cursors . WaitCursor ;
238- this . Text = "Snap2HTML (Working... Press Escape to Cancel)" ;
260+ Text = "Snap2HTML (Working... Press Escape to Cancel)" ;
239261 tabCtrl . Enabled = false ;
240- backgroundWorker . RunWorkerAsync ( argument : settings ) ;
262+ backgroundWorker . RunWorkerAsync ( ) ;
241263 }
242264
243265 private void backgroundWorker_ProgressChanged ( object sender , ProgressChangedEventArgs e )
0 commit comments