Skip to content

Commit 420ea07

Browse files
committed
Migration Complete
All runner code migrated to shared class, GUI is still working. Need to modify DataBuilder to NOT read from User Settings when using Console.
1 parent 40634c0 commit 420ea07

File tree

9 files changed

+655
-507
lines changed

9 files changed

+655
-507
lines changed

Snap2HTML-NG.CommandLine/Program.cs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
using Snap2HTMLNG.Shared.Models;
1+
using Snap2HTMLNG.Shared.Builder;
2+
using Snap2HTMLNG.Shared.Models;
23
using System;
34
using System.Collections.Generic;
5+
using System.ComponentModel;
6+
using System.Diagnostics;
47
using System.IO;
8+
using System.Reflection;
9+
using static System.Net.Mime.MediaTypeNames;
510

611
namespace Snap2HTMLNG.CommandLine
712
{
@@ -48,13 +53,23 @@ static void Main(string[] args)
4853
title = normalizedArgs.Find(x => x.Name == "title").Value;
4954
}
5055

51-
// TODO: Migrate the running code in GUI so that we can run this here without
52-
// having to open or have any requirement on having the GUI on the machine
56+
#if DEBUG
57+
foreach (var normalizedArg in normalizedArgs)
58+
{
59+
Console.WriteLine($"Name: {normalizedArg.Name}, Value: {normalizedArg.Value}");
60+
}
61+
#endif
62+
63+
// Get product name etc.
64+
Assembly assembly = Assembly.GetExecutingAssembly();
65+
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
66+
var productName = fvi.ProductName;
67+
var productVersion = fvi.ProductVersion;
68+
69+
// TODO: Need to change DataBuilder.cs in Shared to not read from the settings file and to accept
70+
// data passed through from the commandLine.
71+
DataBuilder.Build(productName, productVersion);
5372

54-
//foreach (var normalizedArg in normalizedArgs)
55-
//{
56-
// Console.WriteLine($"Name: {normalizedArg.Name}, Value: {normalizedArg.Value}");
57-
//}
5873

5974
Console.ReadKey();
6075
}

Snap2HTML-NG.GUI/Forms/frmMain.Designer.cs

Lines changed: 30 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Snap2HTML-NG.GUI/Forms/frmMain.cs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
using System.ComponentModel;
33
using System.IO;
44
using System.Windows.Forms;
5-
using CommandLine.Utility;
65
using Snap2HTMLNG.Shared.Settings;
7-
using Snap2HTMLNG.Shared.Utils;
86

97
namespace 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
{

Snap2HTML-NG.GUI/Forms/frmMain.resx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,6 @@
117117
<resheader name="writer">
118118
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119119
</resheader>
120-
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
121-
<value>17, 17</value>
122-
</metadata>
123120
<metadata name="toolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
124121
<value>565, 17</value>
125122
</metadata>
@@ -889,7 +886,7 @@
889886
Tk7/A74O0x1RaTVQAAAAAElFTkSuQmCC
890887
</value>
891888
</data>
892-
<metadata name="folderBrowserDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
889+
<metadata name="fbdScanDirectory.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
893890
<value>127, 17</value>
894891
</metadata>
895892
<metadata name="saveFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
@@ -898,8 +895,8 @@
898895
<metadata name="backgroundWorker.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
899896
<value>413, 17</value>
900897
</metadata>
901-
<metadata name="toolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
902-
<value>565, 17</value>
898+
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
899+
<value>681, 17</value>
903900
</metadata>
904901
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
905902
<value>

0 commit comments

Comments
 (0)