Skip to content

Commit bca9996

Browse files
authored
Merge pull request #4 from Laim/dev-branch
Version 3.0
2 parents 56a5189 + 54221d2 commit bca9996

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+3036
-2345
lines changed

HELP.md

Lines changed: 22 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -67,50 +67,33 @@ Here are some examples that shows how to use it:
6767
**Use snapshot from**: "http://www.example.com/snapshot.html"
6868

6969
# Command Line
70-
You can automate Snap2HTML by starting it from the command line with the
71-
following options:
72-
73-
## Simple
74-
Snap2HTMl.exe "c:\path\to\root\folder"
75-
76-
**Note**: Starts the program with the given root path already set
77-
78-
## Full
79-
80-
Snap2HTMl.exe -path:"root folder path" -outfile:"filename" [-link:"link to path"] [-title:"page title"] [-hidden] [-system] [-silent]
81-
82-
### Paramters
83-
84-
-path:"root folder path" - The root path to load.
85-
86-
**Example**: -path:"c:\temp"
87-
88-
-outfile:"filename" - The filename to save the snapshot as. Don't forget the html extension!
89-
90-
**Example**: -outfile:"c:\temp\out.html"
91-
92-
-link:"link to path" - The path to link files to.
93-
94-
**Example**: -link:"c:\temp"
95-
96-
-title:"page title" - Set the page title. If omitted, title is generated based on path.
97-
98-
-hidden - Include hidden items
99-
100-
-system - Include system items
101-
102-
-silent - Run without showing the window (only if both -path and -outfile are used)
70+
Starting with Snap2HTML-NG version 3, the Command Line process has completely changed and been split out to it's own application.
71+
72+
## Usage:
73+
Snap2HTML-NG.CLI [options]
74+
75+
## Options:
76+
-path: [Required] The directory you want to scan
77+
-output: [Required] The directory where you want to save the file, including the filename unless using -randomize
78+
-link: [Optional] The directory where you want to link files in the html file
79+
-title: [Optional] The title of the file which appears at the top of the html file
80+
-hidden [Optional] Hides Hidden files from the scan, default is TRUE
81+
-system [Optional] Hides System files from the scan, default is TRUE
82+
-help, -h [Optional] Shows this information
83+
-pattern [Optional] Search pattern to only return certain files, default is *
84+
-randomize [Optional] Generates a random file name instead of needing to specify one in -output
85+
86+
## Examples:
87+
Snap2HTML-NG.CLI -path:"C:\Users\%username%\Downloads" -output:"C:\Users\%username%\Desktop\Downloads.html"
88+
Snap2HTML-NG.CLI -path:"C:\Users\%username%\Pictures" -output:"C:\Users\%username%\Desktop" -randomize
89+
Snap2HTML-NG.CLI -path:"C:\Users\%username%\Downloads" -output:"C:\Users\%username%\Desktop" -link:"C:\Users\%username%\Downloads" -randomize
90+
Snap2HTML-NG.CLI -path:"C:\Users\%username%\Downloads" -output:"C:\Users\%username%\Desktop" -link:"C:\Users\%username%\Downloads" -randomize -pattern:"*.mp4"
91+
Snap2HTML-NG.CLI -path:"C:\Users\%username%\Videos" -output:"C:\Users\%username%\Desktop\videos.html" -link:"C:\Users\%username%\Videos" -pattern:"*.mp4" -title:"Home Videos"
10392

10493
**Notes**:
10594

106-
When both -path and -outfile are specified, the program will automatically start generating the snapshot, and quit when done.
107-
10895
Always surround paths and filenames with quotes ("")!
10996

110-
In silent mode, in case or error the program will just quit without telling why.
111-
112-
Do not include the [square brackets] when you write your command line. (Square brackets signify optional command line parameters)
113-
11497
# Template Design
11598
If you know html and javascript you may want to have a look at the file "template.html" in the application folder. This is the base for the output, and you can modify it with your own enhancements and design changes.
11699

File renamed without changes.

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,16 @@ This is some of the changes so far.
3939
- Writable Directory Path Textbox
4040
- Project upgraded to .NET Framework 4.8
4141
- Drag and Drop Optimization
42+
- Major code base rewrite
43+
- CLI split out to allow scheduling of snapshots
44+
- User Settings changed to allow scheduling
45+
- Command Line removed from GUI entirely
46+
- Updater (Off by default, unless Preview Build)
47+
- Much more; see Release Notes
4248

4349
## Privacy Notice
4450

45-
Snap2HTML-NG does not connect to the internet. It does not phone home, check for updates, submit telemetry, spy on you or any other crap like that. It simply doesn't do anything behind your back and any data related to the program is yours. As it should be.
51+
Snap2HTML-NG does not connect to the internet. It does not phone home, submit telemetry, spy on you or any other crap like that. It simply doesn't do anything behind your back and any data related to the program is yours. As it should be.
52+
53+
### Updates
54+
As of Version 3.0, there is a setting to auto check for updates. This does not download any updates automatically and is disabled by default (preview builds have it enabled). The above privacy notice still stands otherwise.

Snap2HTML-NG.CLI/App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
5+
</startup>
6+
</configuration>

Snap2HTML-NG.CLI/Program.cs

Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
using Snap2HTMLNG.Shared.Builder;
2+
using Snap2HTMLNG.Shared.Models;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Diagnostics;
6+
using System.IO;
7+
using System.Reflection;
8+
using Snap2HTMLNG.Shared.CLI;
9+
10+
namespace Snap2HTMLNG.CLI
11+
{
12+
internal class Program
13+
{
14+
15+
private static bool _validationCheck = false;
16+
static void Main(string[] args)
17+
{
18+
19+
#if DEBUG
20+
// Information
21+
CommandLine.WriteDebug($" THIS IS A PREVIEW BUILD.");
22+
// New Lines
23+
Console.WriteLine("");
24+
#endif
25+
26+
List<CommandLineModel> normalizedArgs = CommandLine.CommandLineSplit(args);
27+
28+
if(normalizedArgs.Exists(x => x.Name == "help"))
29+
{
30+
HelpInformation();
31+
return;
32+
}
33+
34+
InitialValidation(normalizedArgs);
35+
36+
// Check if the initial validation checks have passed
37+
if(_validationCheck)
38+
{
39+
string rootDirectory = normalizedArgs.Find(x => x.Name == "path").Value;// + @"\";
40+
string saveDirectory = normalizedArgs.Find(x => x.Name == "output").Value;
41+
42+
// Check if the user has requested a randomized file name and set if they have
43+
if(normalizedArgs.Exists(x =>x.Name == "randomize"))
44+
{
45+
CommandLine.WriteInformation($"Randomized file name requested...");
46+
47+
string randomFileName = $"{Guid.NewGuid()}.html";
48+
49+
saveDirectory = $@"{saveDirectory}\{randomFileName}";
50+
51+
CommandLine.WriteInformation($"Randomized file set to {randomFileName}");
52+
53+
CommandLine.WriteInformation($"Output path is now: {saveDirectory}");
54+
55+
}
56+
57+
// Validate that the Scan Path actually exists
58+
if (!Directory.Exists(rootDirectory))
59+
{
60+
CommandLine.WriteError($"Your scan path {rootDirectory} does not exist or Snap2HTML-NG does not have access.");
61+
return;
62+
}
63+
64+
// Check if the Save location actually exists
65+
if (!Directory.Exists(Path.GetDirectoryName(saveDirectory)))
66+
{
67+
CommandLine.WriteError($"Your save path {saveDirectory} does not exist or Snap2HTML-NG does not have access.");
68+
return;
69+
}
70+
71+
// Check if the rest of the settigns have been passed and assign
72+
bool skipHidden = !normalizedArgs.Exists(x => x.Name == "hidden"); // if found, do not skip
73+
bool skipSystem = !normalizedArgs.Exists(x => x.Name == "system"); // if found, do not skip
74+
75+
// Check if the user wants to link files to the root which allows them to be easily selected when viewing in a browser
76+
bool linkFilesToRoot = false;
77+
string linkDirectory = "";
78+
if (normalizedArgs.Exists(x => x.Name == "link"))
79+
{
80+
linkFilesToRoot = true;
81+
linkDirectory = normalizedArgs.Find(x => x.Name == "link").Value;
82+
}
83+
84+
string title = $"Snapshot of {saveDirectory}";
85+
if (normalizedArgs.Exists(x => x.Name == "title"))
86+
{
87+
title = normalizedArgs.Find(x => x.Name == "title").Value;
88+
}
89+
90+
string searchPattern = "*"; // default is all
91+
if (normalizedArgs.Exists(x => x.Name == "pattern"))
92+
{
93+
searchPattern = normalizedArgs.Find(x => x.Name == "pattern").Value;
94+
}
95+
96+
#if DEBUG
97+
foreach (var normalizedArg in normalizedArgs)
98+
{
99+
CommandLine.WriteDebug($"Name: {normalizedArg.Name}, Value: {normalizedArg.Value}");
100+
}
101+
#endif
102+
// Create the settings model and assign the relevant information to each property
103+
UserSettingsModel usm = new UserSettingsModel
104+
{
105+
RootDirectory = rootDirectory,
106+
Title = title,
107+
OutputFile = saveDirectory,
108+
SkipHiddenItems = skipHidden,
109+
SkipSystemItems = skipSystem,
110+
OpenInBrowserAfterCapture = false, // this will always be false in console mode
111+
LinkFiles = linkFilesToRoot,
112+
LinkRoot = linkDirectory,
113+
SearchPattern = searchPattern
114+
};
115+
116+
DataBuilder.Build(usm, ApplicationInformation().ProductName, ApplicationInformation().ProductVersion);
117+
118+
119+
Console.ReadKey();
120+
}
121+
}
122+
123+
124+
/// <summary>
125+
/// Checks if the user has passed through any arguments, as well as if they have included the two REQUIRED arguments
126+
/// </summary>
127+
/// <param name="normalizedArgs">
128+
/// <see cref="List{T}"/> of arguments using <see cref="CommandLineModel"/>
129+
/// </param>
130+
static void InitialValidation(List<CommandLineModel> normalizedArgs)
131+
{
132+
// Check if we have included any arguments at all, otherwise exit out.
133+
if (normalizedArgs.Count == 0)
134+
{
135+
CommandLine.WriteError("No arguments have been supplied that are recognized. Use -h for help.");
136+
_validationCheck = false;
137+
return;
138+
}
139+
140+
// Check if we have included the REQUIRED argument -path:, otherwise exit out.
141+
if (!normalizedArgs.Exists(x => x.Name == "path"))
142+
{
143+
CommandLine.WriteError("You are missing the required argument '-path:'. Use -h for help.");
144+
_validationCheck = false;
145+
return;
146+
}
147+
148+
// Check if we have included the REQUIRED argument -output:, otherwise exit out.
149+
if (!normalizedArgs.Exists(x => x.Name == "output"))
150+
{
151+
CommandLine.WriteError("You are missing the required argument '-output:'. Use -h for help.");
152+
_validationCheck = false;
153+
return;
154+
}
155+
156+
_validationCheck = true;
157+
}
158+
159+
/// <summary>
160+
/// Returns Help information for using the Command Line
161+
/// </summary>
162+
static void HelpInformation()
163+
{
164+
Console.ForegroundColor = ConsoleColor.White;
165+
166+
// Information
167+
Console.WriteLine(" Application Information");
168+
Console.WriteLine($" {ApplicationInformation().ProductName} v{ApplicationInformation().ProductVersion}");
169+
170+
// New Lines
171+
Console.WriteLine("");
172+
173+
// Description
174+
Console.WriteLine(" Description:");
175+
Console.WriteLine(" Help information for Snap2HTML-NG.CLI");
176+
177+
// New Lines
178+
Console.WriteLine("");
179+
180+
// Usage
181+
Console.WriteLine(" Usage:");
182+
Console.WriteLine(" Snap2HTML-NG.CLI [options]");
183+
184+
// New Lines
185+
Console.WriteLine("");
186+
187+
// Options
188+
Console.WriteLine(" Options:");
189+
Console.WriteLine(" -path: [Required] The directory you want to scan");
190+
Console.WriteLine(" -output: [Required] The directory where you want to save the file, including the filename unless using -randomize");
191+
Console.WriteLine(" -link: [Optional] The directory where you want to link files in the html file");
192+
Console.WriteLine(" -title: [Optional] The title of the file which appears at the top of the html file");
193+
Console.WriteLine(" -hidden [Optional] Hides Hidden files from the scan, default is TRUE");
194+
Console.WriteLine(" -system [Optional] Hides System files from the scan, default is TRUE");
195+
Console.WriteLine(" -help, -h [Optional] Shows this information");
196+
Console.WriteLine(" -pattern [Optional] Search pattern to only return certain files, default is *");
197+
Console.WriteLine(" -randomize [Optional] Generates a random file name instead of needing to specify one in -output");
198+
199+
// New Lines
200+
Console.WriteLine("");
201+
202+
// Examples
203+
Console.WriteLine(" Examples:");
204+
Console.WriteLine($" Snap2HTML-NG.CLI -path:\"C:\\Users\\{Environment.UserName}\\Downloads\" -output:\"C:\\Users\\{Environment.UserName}\\Desktop\\Downloads.html\" ");
205+
Console.WriteLine($" Snap2HTML-NG.CLI -path:\"C:\\Users\\{Environment.UserName}\\Pictures\" -output:\"C:\\Users\\{Environment.UserName}\\Desktop\" -randomize ");
206+
Console.WriteLine($" Snap2HTML-NG.CLI -path:\"C:\\Users\\{Environment.UserName}\\Downloads\" -output:\"C:\\Users\\{Environment.UserName}\\Desktop\" -link:\"C:\\Users\\{Environment.UserName}\\Downloads\" -randomize ");
207+
Console.WriteLine($" Snap2HTML-NG.CLI -path:\"C:\\Users\\{Environment.UserName}\\Downloads\" -output:\"C:\\Users\\{Environment.UserName}\\Desktop\" -link:\"C:\\Users\\{Environment.UserName}\\Downloads\" -randomize -pattern:\"*.mp4\"");
208+
Console.WriteLine($" Snap2HTML-NG.CLI -path:\"C:\\Users\\{Environment.UserName}\\Videos\" -output:\"C:\\Users\\{Environment.UserName}\\Desktop\\videos.html\" -link:\"C:\\Users\\{Environment.UserName}\\Videos\" -pattern:\"*.mp4\" -title:\"Home Videos\"");
209+
210+
}
211+
212+
/// <summary>
213+
/// Gets the application information using <see cref="FileVersionInfo"/> and <see cref="Assembly"/>
214+
/// </summary>
215+
/// <returns>
216+
/// <see cref="FileVersionInfo"/>
217+
/// </returns>
218+
static FileVersionInfo ApplicationInformation()
219+
{
220+
// Get product name etc.
221+
Assembly assembly = Assembly.GetExecutingAssembly();
222+
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
223+
224+
return fvi;
225+
}
226+
}
227+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("Snap2HTML-NG.CLI")]
9+
[assembly: AssemblyDescription("Console App for Snap2HTML-NG")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("Laim McKenzie")]
12+
[assembly: AssemblyProduct("Snap2HTML-NG.CLI")]
13+
[assembly: AssemblyCopyright("Copyright © Laim McKenzie 2023")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("84648b91-e4d2-42f2-8949-2b86530aa8bb")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("3.0.0.0")]
36+
[assembly: AssemblyFileVersion("3.0.0.0")]

0 commit comments

Comments
 (0)