diff --git a/DLL/CommandLine.XML b/DLL/CommandLine.XML new file mode 100644 index 0000000..ff550c6 --- /dev/null +++ b/DLL/CommandLine.XML @@ -0,0 +1,1390 @@ + + + + CommandLine + + + + + Provides base properties for creating an attribute, used to define rules for command line parsing. + + + + + Initializes a new instance of the class. + + + + + Initializes a new instance of the class. + Validating and . + + Short name of the option. + Long name of the option. + + + + Initializes a new instance of the class. Validating + and . This constructor accepts a as short name. + + Short name of the option. + Long name of the option. + + + + Gets a short name of this command line option. You can use only one character. + + + + + Gets long name of this command line option. This name is usually a single english word. + + + + + Gets or sets the option's mutually exclusive set. + + + + + Gets or sets a value indicating whether a command line option is required. + + + + + Gets or sets mapped property default value. + + + + + Gets or sets mapped property meta value. + + + + + Gets or sets a short description of this command line option. Usually a sentence summary. + + + + + Models an option specification. + + + + + Initializes a new instance of the class. + The default long name will be inferred from target property. + + + + + Initializes a new instance of the class. + + The short name of the option.. + + + + Initializes a new instance of the class. + + The long name of the option. + + + + Initializes a new instance of the class. + + The short name of the option. + The long name of the option or null if not used. + + + + Helper factory method for testing purpose. + + An instance. + + + + Models an option that can accept multiple values as separated arguments. + + + + + Initializes a new instance of the class. + The default long name will be inferred from target property. + + + + + Initializes a new instance of the class. + + The short name of the option. + + + + Initializes a new instance of the class. + + The long name of the option. + + + + Initializes a new instance of the class. + + The short name of the option. + The long name of the option or null if not used. + + + + Indicates the instance method that must be invoked when it becomes necessary show your help screen. + The method signature is an instance method with no parameters and + return value. + + + + + Initializes a new instance of the class. + Although it is possible, it is strongly discouraged redefine the long name for this option + not to disorient your users. It is also recommended not to define a short one. + + + + + Initializes a new instance of the class + with the specified short name. Use parameter less constructor instead. + + The short name of the option. + + It's highly not recommended change the way users invoke help. It may create confusion. + + + + + Initializes a new instance of the class + with the specified long name. Use parameter less constructor instead. + + The long name of the option or null if not used. + + It's highly not recommended change the way users invoke help. It may create confusion. + + + + + Initializes a new instance of the class. + Allows you to define short and long option names. + + The short name of the option. + The long name of the option or null if not used. + + It's highly not recommended change the way users invoke help. It may create confusion. + + + + + Returns always false for this kind of option. + This behaviour can't be changed by design; if you try set + an will be thrown. + + + + + Models an option that can accept multiple values. + Must be applied to a field compatible with an interface + of instances. + + + + + Initializes a new instance of the class. + The default long name will be inferred from target property. + + + + + Initializes a new instance of the class. + + The short name of the option. + + + + Initializes a new instance of the class. + + The long name of the option or null if not used. + + + + Initializes a new instance of the class. + + The short name of the option. + The long name of the option or null if not used. + + + + Initializes a new instance of the class. + + The short name of the option or null if not used. + The long name of the option or null if not used. + Values separator character. + + + + Gets or sets the values separator character. + + + + + Indicates that the property can receive an instance of type . + + + + + Models a list of command line arguments that are not options. + Must be applied to a field compatible with an interface + of instances. + + To map individual values use instead . + + + + Initializes a new instance of the class. + + A type that implements . + Thrown if is null. + + + + Gets or sets the maximum element allow for the list managed by type. + If lesser than 0, no upper bound is fixed. + If equal to 0, no elements are allowed. + + + + + Gets the concrete type specified during initialization. + + + + + Maps a single unnamed option to the target property. Values will be mapped in order of Index. + This attribute takes precedence over with which + can coexist. + + It can handle only scalar values. Do not apply to arrays or lists. + + + + Initializes a new instance of the class. + + The _index of the option. + + + + Gets the position this option has on the command line. + + + + + Utility extension methods for System.Char. + + + + + Utility extension methods for System.String. + + + + + Gets or sets the assembly from which to pull information. Setter provided for testing purpose. + + + + + Encapsulates property writing primitives. + + + + + Utility extension methods for query target capabilities. + + + + + Maps unnamed options to property using and . + + + + + Initializes a new instance of the class. Used for unit testing purpose. + + Option short name. + Option long name. + + + + Initializes a new instance of the class. + It is internal rather than private for unit testing purpose. + + Initial internal capacity. + Parser settings instance. + + + + Helper method for testing purpose. + + An argument enumerator instance. + The next input value. + + + + Provides means to format an help screen. + You can assign it in place of a instance. + + + + + Initializes a new instance of the class. + + + + + Initializes a new instance of the class + specifying the sentence builder. + + + A instance. + + + + + Initializes a new instance of the class + specifying heading string. + + An heading string or an instance of . + Thrown when parameter is null or empty string. + + + + Initializes a new instance of the class + specifying the sentence builder and heading string. + + A instance. + A string with heading or an instance of . + + + + Initializes a new instance of the class + specifying heading and copyright strings. + + A string with heading or an instance of . + A string with copyright or an instance of . + Thrown when one or more parameters are null or empty strings. + + + + Initializes a new instance of the class + specifying heading and copyright strings. + + A instance. + A string with heading or an instance of . + A string with copyright or an instance of . + Thrown when one or more parameters are null or empty strings. + + + + Initializes a new instance of the class + specifying heading and copyright strings. + + A string with heading or an instance of . + A string with copyright or an instance of . + The instance that collected command line arguments parsed with class. + Thrown when one or more parameters are null or empty strings. + + + + Initializes a new instance of the class + specifying heading and copyright strings. + + A instance. + A string with heading or an instance of . + A string with copyright or an instance of . + The instance that collected command line arguments parsed with class. + Thrown when one or more parameters are null or empty strings. + + + + Occurs when an option help text is formatted. + + + + + Gets or sets the heading string. + You can directly assign a instance. + + + + + Gets or sets the copyright string. + You can directly assign a instance. + + + + + Gets or sets the maximum width of the display. This determines word wrap when displaying the text. + + The maximum width of the display. + + + + Gets or sets a value indicating whether the format of options should contain dashes. + It modifies behavior of method. + + + + + Gets or sets a value indicating whether to add an additional line after the description of the option. + + + + + Gets the instance specified in constructor. + + + + + Creates a new instance of the class using common defaults. + + + An instance of class. + + The instance that collected command line arguments parsed with class. + + + + Creates a new instance of the class using common defaults. + + + An instance of class. + + The instance that collected command line arguments parsed with class. + A delegate used to customize the text block for reporting parsing errors. + If true the output style is consistent with verb commands (no dashes), otherwise it outputs options. + + + + Creates a new instance of the class using common defaults, + for verb commands scenario. + + + An instance of class. + + The instance that collected command line arguments parsed with class. + The verb command invoked. + + + + Supplies a default parsing error handler implementation. + + The instance that collects parsed arguments parsed and associates + to a property of type . + The instance. + + + + Converts the help instance to a . + + This instance. + The that contains the help screen. + + + + Adds a text line after copyright and before options usage strings. + + A instance. + Thrown when parameter is null or empty string. + + + + Adds a text line at the bottom, after options usage string. + + A instance. + Thrown when parameter is null or empty string. + + + + Adds a text block with options usage string. + + The instance that collected command line arguments parsed with class. + Thrown when parameter is null. + + + + Adds a text block with options usage string. + + The instance that collected command line arguments parsed with the class. + The word to use when the option is required. + Thrown when parameter is null. + Thrown when parameter is null or empty string. + + + + Adds a text block with options usage string. + + The instance that collected command line arguments parsed with the class. + The word to use when the option is required. + The maximum length of the help documentation. + Thrown when parameter is null. + Thrown when parameter is null or empty string. + + + + Builds a string that contains a parsing error message. + + An options target instance that collects parsed arguments parsed with the + associated to a property of type . + Number of spaces used to indent text. + The that contains the parsing error message. + + + + Returns the help screen as a . + + The that contains the help screen. + + + + The OnFormatOptionHelpText method also allows derived classes to handle the event without attaching a delegate. + This is the preferred technique for handling the event in a derived class. + + Data for the event. + + + + Models an abstract sentence builder. + + + + + Gets a string containing word 'option'. + + The word 'option'. + + + + Gets a string containing the word 'and'. + + The word 'and'. + + + + Gets a string containing the sentence 'required option missing'. + + The sentence 'required option missing'. + + + + Gets a string containing the sentence 'violates format'. + + The sentence 'violates format'. + + + + Gets a string containing the sentence 'violates mutual exclusiveness'. + + The sentence 'violates mutual exclusiveness'. + + + + Gets a string containing the error heading text. + + The error heading text. + + + + Creates the built in sentence builder. + + The built in sentence builder. + + + + Models an english sentence builder, currently the default one. + + + + + Gets a string containing word 'option' in english. + + The word 'option' in english. + + + + Gets a string containing the word 'and' in english. + + The word 'and' in english. + + + + Gets a string containing the sentence 'required option missing' in english. + + The sentence 'required option missing' in english. + + + + Gets a string containing the sentence 'violates format' in english. + + The sentence 'violates format' in english. + + + + Gets a string containing the sentence 'violates mutual exclusiveness' in english. + + The sentence 'violates mutual exclusiveness' in english. + + + + Gets a string containing the error heading text in english. + + The error heading text in english. + + + + Models the copyright part of an help text. + You can assign it where you assign any instance. + + + + + Initializes a new instance of the class + specifying author and year. + + The company or person holding the copyright. + The year of coverage of copyright. + Thrown when parameter is null or empty string. + + + + Initializes a new instance of the class + specifying author and copyrightYears. + + The company or person holding the copyright. + The copyrightYears of coverage of copyright. + Thrown when parameter is null or empty string. + Thrown when parameter is not supplied. + + + + Initializes a new instance of the class + specifying symbol case, author and copyrightYears. + + The case of the copyright symbol. + The company or person holding the copyright. + The copyrightYears of coverage of copyright. + Thrown when parameter is null or empty string. + Thrown when parameter is not supplied. + + + + Initializes a new instance of the class. + + + + + Initializes a new instance of the class + with an assembly attribute, this overrides all formatting. + + The attribute which text to use. + + + + Gets the default copyright information. + Retrieved from , if it exists, + otherwise it uses as copyright holder with the current year. + If neither exists it throws an . + + + + + Gets a different copyright word when overridden in a derived class. + + + + + Converts the copyright instance to a . + + This instance. + The that contains the copyright. + + + + Returns the copyright as a . + + The that contains the copyright. + + + + When overridden in a derived class, allows to specify a new algorithm to render copyright copyrightYears + as a instance. + + A array of copyrightYears. + A instance with copyright copyrightYears. + + + + Models the heading part of an help text. + You can assign it where you assign any instance. + + + + + Initializes a new instance of the class + specifying program name. + + The name of the program. + Thrown when parameter is null or empty string. + + + + Initializes a new instance of the class + specifying program name and version. + + The name of the program. + The version of the program. + Thrown when parameter is null or empty string. + + + + Gets the default heading instance. + The title is retrieved from , + or the assembly short name if its not defined. + The version is retrieved from , + or the assembly version if its not defined. + + + + + Converts the heading to a . + + This instance. + The that contains the heading. + + + + Returns the heading as a . + + The that contains the heading. + + + + Writes out a string and a new line using the program name specified in the constructor + and parameter. + + The message to write. + The target derived type. + Thrown when parameter is null or empty string. + Thrown when parameter is null. + + + + Writes out a string and a new line using the program name specified in the constructor + and parameter to standard output stream. + + The message to write. + Thrown when parameter is null or empty string. + + + + Writes out a string and a new line using the program name specified in the constructor + and parameter to standard error stream. + + The message to write. + Thrown when parameter is null or empty string. + + + + Provides data for the FormatOptionHelpText event. + + + + + Initializes a new instance of the class. + + Option to format. + + + + Gets the option to format. + + + + + Provides base properties for creating an attribute, used to define multiple lines of text. + + + + + Initializes a new instance of the class. Used in derived type + using one line of text. + + The first line of text. + + + + Initializes a new instance of the class. Used in type + using two lines of text. + + The first line of text. + The second line of text. + + + + Initializes a new instance of the class. Used in type + using three lines of text. + + The first line of text. + The second line of text. + The third line of text. + + + + Initializes a new instance of the class. Used in type + using four lines of text. + + The first line of text. + The second line of text. + The third line of text. + The fourth line of text. + + + + Initializes a new instance of the class. Used in type + using five lines of text. + + The first line of text. + The second line of text. + The third line of text. + The fourth line of text. + The fifth line of text. + + + + Gets the all non-blank lines as string. + + A string of all non-blank lines. + + + + Gets the first line of text. + + + + + Gets the second line of text. + + + + + Gets third line of text. + + + + + Gets the fourth line of text. + + + + + Gets the fifth line of text. + + + + + Returns the last line with text. Preserves blank lines if user intended by skipping a line. + + The last index of line of the non-blank line. + + The string array to process. + + + + Models a multiline assembly license text. + + + + + Initializes a new instance of the class + with one line of text. + + First line of license text. + + + + Initializes a new instance of the class + with two lines of text. + + First line of license text. + Second line of license text. + + + + Initializes a new instance of the class + with three lines of text. + + First line of license text. + Second line of license text. + Third line of license text. + + + + Initializes a new instance of the class + with four lines of text. + + First line of license text. + Second line of license text. + Third line of license text. + Fourth line of license text. + + + + Initializes a new instance of the class + with five lines of text. + + First line of license text. + Second line of license text. + Third line of license text. + Fourth line of license text. + Fifth line of license text. + + + + Models a multiline assembly usage text. + + + + + Initializes a new instance of the class + with one line of text. + + First line of usage text. + + + + Initializes a new instance of the class + with two lines of text. + + First line of usage text. + Second line of usage text. + + + + Initializes a new instance of the class + with three lines of text. + + First line of usage text. + Second line of usage text. + Third line of usage text. + + + + Initializes a new instance of the class + with four lines of text. + + First line of usage text. + Second line of usage text. + Third line of usage text. + Fourth line of usage text. + + + + Initializes a new instance of the class + with five lines of text. + + First line of usage text. + Second line of usage text. + Third line of usage text. + Fourth line of usage text. + Fifth line of usage text. + + + + Indicates the instance method that must be invoked when it becomes necessary show your help screen. + The method signature is an instance method with that accepts and returns a . + + + + + Initializes a new instance of the class. + Although it is possible, it is strongly discouraged redefine the long name for this option + not to disorient your users. + + + + + Initializes a new instance of the class + with the specified long name. Use parameter less constructor instead. + + Help verb option alternative name. + + It's highly not recommended change the way users invoke help. It may create confusion. + + + + + Help verb command do not support short name by design. + + + + + Help verb command like ordinary help option cannot be mandatory by design. + + + + + Models a verb command specification. + + + + + Initializes a new instance of the class. + + The long name of the verb command. + + + + Verb commands do not support short name by design. + + + + + Verb commands cannot be mandatory since are mutually exclusive by design. + + + + + Models a bad parsed option. + + + + + Gets the short name of the option. + + Returns the short name of the option. + + + + Gets the long name of the option. + + Returns the long name of the option. + + + + Provides methods to parse command line arguments. + + + + + Default exit code (1) used by + and overloads. + + + + + Initializes a new instance of the class. + + + + + Initializes a new instance of the class, + configurable with a object. + + The object is used to configure + aspects and behaviors of the parser. + + + + Initializes a new instance of the class, + configurable with using a delegate. + + The delegate used to configure + aspects and behaviors of the parser. + + + + Finalizes an instance of the class. + + + + + Gets the singleton instance created with basic defaults. + + + + + Gets the instance that implements in use. + + + + + Parses a array of command line arguments, setting values in + parameter instance's public fields decorated with appropriate attributes. + + A array of command line arguments. + An instance used to receive values. + Parsing rules are defined using derived types. + True if parsing process succeed. + Thrown if is null. + Thrown if is null. + + + + Parses a array of command line arguments with verb commands, setting values in + parameter instance's public fields decorated with appropriate attributes. + This overload supports verb commands. + + A array of command line arguments. + An instance used to receive values. + Parsing rules are defined using derived types. + Delegate executed to capture verb command name and instance. + True if parsing process succeed. + Thrown if is null. + Thrown if is null. + Thrown if is null. + + + + Parses a array of command line arguments, setting values in + parameter instance's public fields decorated with appropriate attributes. If parsing fails, the method invokes + the delegate, if null exits with . + + A array of command line arguments. + An object's instance used to receive values. + Parsing rules are defined using derived types. + The delegate executed when parsing fails. + True if parsing process succeed. + Thrown if is null. + Thrown if is null. + + + + Parses a array of command line arguments with verb commands, setting values in + parameter instance's public fields decorated with appropriate attributes. If parsing fails, the method invokes + the delegate, if null exits with . + This overload supports verb commands. + + A array of command line arguments. + An instance used to receive values. + Parsing rules are defined using derived types. + Delegate executed to capture verb command name and instance. + The delegate executed when parsing fails. + True if parsing process succeed. + Thrown if is null. + Thrown if is null. + Thrown if is null. + + + + Frees resources owned by the instance. + + + + + This exception is thrown when a generic parsing error occurs. + + + + + Initializes a new instance of the class. The exception is thrown + when something unexpected occurs during the parsing process. + + + + + Initializes a new instance of the class. The exception is thrown + when something unexpected occurs during the parsing process. + + Error message string. + + + + Initializes a new instance of the class. The exception is thrown + when something unexpected occurs during the parsing process. + + Error message string. + Inner exception reference. + + + + Initializes a new instance of the class. The exception is thrown + when something unexpected occurs during the parsing process. + + The object that holds the serialized object data. + The contextual information about the source or destination. + + + + Provides settings for . Once consumed cannot be reused. + + + + + Initializes a new instance of the class. + + + + + Initializes a new instance of the class, + setting the case comparison behavior. + + If set to true, parsing will be case sensitive. + + + + Initializes a new instance of the class, + setting the used for help method output. + + Any instance derived from , + default . Setting this argument to null, will disable help screen. + + + + Initializes a new instance of the class, + setting case comparison and help output options. + + If set to true, parsing will be case sensitive. + Any instance derived from , + default . Setting this argument to null, will disable help screen. + + + + Initializes a new instance of the class, + setting case comparison and mutually exclusive behaviors. + + If set to true, parsing will be case sensitive. + If set to true, enable mutually exclusive behavior. + + + + Initializes a new instance of the class, + setting case comparison, mutually exclusive behavior and help output option. + + If set to true, parsing will be case sensitive. + If set to true, enable mutually exclusive behavior. + Any instance derived from , + default . Setting this argument to null, will disable help screen. + + + + Initializes a new instance of the class, + setting case comparison, mutually exclusive behavior and help output option. + + If set to true, parsing will be case sensitive. + If set to true, enable mutually exclusive behavior. + If set to true, allow the parser to skip unknown argument, otherwise return a parse failure + Any instance derived from , + default . Setting this argument to null, will disable help screen. + + + + Finalizes an instance of the class. + + + + + Gets or sets a value indicating whether perform case sensitive comparisons. + + + + + Gets or sets a value indicating whether set a mutually exclusive behavior. + Default is set to false. + + + + + Gets or sets the used for help method output. + Setting this property to null, will disable help screen. + + + + + Gets or sets a value indicating whether the parser shall move on to the next argument and ignore the given argument if it + encounter an unknown arguments + + + true to allow parsing the arguments with different class options that do not have all the arguments. + + + This allows fragmented version class parsing, useful for project with add-on where add-ons also requires command line arguments but + when these are unknown by the main program at build time. + + + + + Gets or sets the culture used when parsing arguments to typed properties. + + + Default is CurrentCulture of . + + + + + Frees resources owned by the instance. + + + + + Represents the parser state. + + + + + Gets errors occurred during parsing. + + + + + Models a type that records the parser state after parsing. + + + + + Gets a list of parsing errors. + + + Parsing errors. + + + + + Models a parsing error. + + + + + Gets or a the bad parsed option. + + + The bad option. + + + + + Gets or sets a value indicating whether this violates required. + + + true if violates required; otherwise, false. + + + + + Gets or sets a value indicating whether this violates format. + + + true if violates format; otherwise, false. + + + + + Gets or sets a value indicating whether this violates mutual exclusiveness. + + + true if violates mutual exclusiveness; otherwise, false. + + + + diff --git a/DLL/CommandLine.dll b/DLL/CommandLine.dll new file mode 100644 index 0000000..c80da3c Binary files /dev/null and b/DLL/CommandLine.dll differ diff --git a/DLL/Credits.txt b/DLL/Credits.txt new file mode 100644 index 0000000..3fdd1f1 --- /dev/null +++ b/DLL/Credits.txt @@ -0,0 +1,2 @@ +CommandLine.dll +CommandLine.xml: https://commandline.codeplex.com/ \ No newline at end of file diff --git a/README.md b/README.md index 28d902a..91be5a3 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,14 @@ Download chapters from Syosetsu ni Narou - Custom filename (see format.ini for details) - Chapter list generation (nxxxxxx.htm) +**CMD Commands** +- -l, --link URL to be processed +- -s, --start (Default: 1) Stating chapter +- -e, --end Ending chapter +- -f, --format (Default: TXT) File format (HTML | TXT) +- -t, --toc (Default: False) Generates Table of contents +- -h, --help + **Notes:** - If no chapter range is specified it will download everything - If "from" is blank it will start from chapter 1 diff --git a/syosetuDownloader.suo b/syosetuDownloader.suo deleted file mode 100644 index 8251fbe..0000000 Binary files a/syosetuDownloader.suo and /dev/null differ diff --git a/syosetuDownloader/App.xaml.cs b/syosetuDownloader/App.xaml.cs index 96e37f2..722179a 100644 --- a/syosetuDownloader/App.xaml.cs +++ b/syosetuDownloader/App.xaml.cs @@ -4,6 +4,8 @@ using System.Data; using System.Linq; using System.Windows; +using CommandLine; +using HtmlAgilityPack; namespace syosetuDownloader { @@ -12,5 +14,101 @@ namespace syosetuDownloader /// public partial class App : Application { + class Options + { + [Option('l', "link", HelpText = "URL to be processed")] + public string Link { get; set; } + + [Option('s', "start", HelpText = "Stating chapter", DefaultValue = "1")] + public string Start { get; set; } + + [Option('e', "end", HelpText = "Ending chapter")] + public string End { get; set; } + + [Option('f', "format", HelpText = "File format (HTML | TXT)", DefaultValue = "TXT")] + public string Format { get; set; } + + [Option('t', "toc", HelpText = "Generates Table of contents", DefaultValue = false)] + public bool ToC { get; set; } + + [Option('h', "help")] + public bool Help { get; set; } + } + + string GetFilenameFormat() + { + using (System.IO.StreamReader sr = new System.IO.StreamReader("format.ini")) + { + string line; + while ((line = sr.ReadLine()) != null) + { + if (!line.StartsWith(";")) + { + return line; + } + } + } + + return ""; + } + + protected override void OnStartup(StartupEventArgs e) + { + base.OnStartup(e); + + Options o = new Options(); + if (e.Args.Any()) + { + /* do stuff without a GUI */ + Parser.Default.ParseArguments(e.Args, o); + + if (o.Help == true) + { + AttachConsole(-1); + Console.WriteLine(CommandLine.Text.HelpText.AutoBuild(o)); + this.Shutdown(); + return; + } + + Syousetsu.Constants sc = new Syousetsu.Constants(); + HtmlDocument toc = Syousetsu.Methods.GetTableOfContents(o.Link, sc.SyousetsuCookie); + + sc.ChapterTitle.Add(""); + sc.SeriesTitle = Syousetsu.Methods.GetTitle(toc); + sc.Link = o.Link; + sc.Start = o.Start; + sc.End = String.IsNullOrWhiteSpace(o.End) ? Syousetsu.Methods.GetTotalChapters(toc).ToString() : o.End; + sc.SeriesCode = Syousetsu.Methods.GetSeriesCode(o.Link); + sc.FilenameFormat = GetFilenameFormat(); + Syousetsu.Methods.GetAllChapterTitles(sc, toc); + Syousetsu.Constants.FileType fileType = Syousetsu.Constants.FileType.Text; + switch (o.Format.ToUpper()) + { + case "HTML": { fileType = Syousetsu.Constants.FileType.HTML; break; } + case "TXT": { fileType = Syousetsu.Constants.FileType.Text; break; } + default: { fileType = Syousetsu.Constants.FileType.Text; break; } + } + sc.CurrentFileType = fileType; + Syousetsu.Methods.GetAllChapterTitles(sc, toc); + + if (o.ToC == true) + { + Syousetsu.Create.GenerateTableOfContents(sc, toc); + } + + System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); + sw.Start(); + Syousetsu.Methods.AddDownloadJob(sc); + sw.Stop(); + + AttachConsole(-1); + Console.WriteLine(sw.Elapsed); + + this.Shutdown(); + } + } + + [System.Runtime.InteropServices.DllImport("Kernel32.dll")] + public static extern bool AttachConsole(int processId); } } diff --git a/syosetuDownloader/Properties/AssemblyInfo.cs b/syosetuDownloader/Properties/AssemblyInfo.cs index 514c86d..4f9ac85 100644 --- a/syosetuDownloader/Properties/AssemblyInfo.cs +++ b/syosetuDownloader/Properties/AssemblyInfo.cs @@ -51,5 +51,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.2.2")] -[assembly: AssemblyFileVersion("2.2.2")] +[assembly: AssemblyVersion("2.3.0")] +[assembly: AssemblyFileVersion("2.3.0")] diff --git a/syosetuDownloader/Syousetsu.cs b/syosetuDownloader/Syousetsu.cs index 36b95a8..ea65de5 100644 --- a/syosetuDownloader/Syousetsu.cs +++ b/syosetuDownloader/Syousetsu.cs @@ -70,6 +70,44 @@ public static CancellationTokenSource AddDownloadJob(Syousetsu.Constants details return ct; } + public static void AddDownloadJob(Syousetsu.Constants details) + { + int max = Convert.ToInt32(details.End); + + int i = 0; + int upTo = -1; + if (details.Start != String.Empty && details.End == String.Empty)//determine if user don't want to start at chapter 1 + { + i = Convert.ToInt32(details.Start); + } + else if (details.Start == String.Empty && details.End != String.Empty)//determine if user wants to end at a specific chapter + { + i = 1; + upTo = max; + } + else if (details.Start != String.Empty && details.End != String.Empty)//determine if user only wants to download a specifc range + { + i = Convert.ToInt32(details.Start);//get start of the range + upTo = max;//get the end of the range + } + else + { + i = 1;//if both textbox are blank assume user wants to start from the first chapter "http://*.syosetu.com/xxxxxxx/1" until the latest/last one "http://*.syosetu.com/xxxxxxx/*" + } + + for (int ctr = i; ctr <= max; ctr++) + { + string subLink = details.Link + ctr; + string[] chapter = Create.GenerateContents(details, GetPage(subLink, details.SyousetsuCookie), ctr); + Create.SaveFile(details, chapter, ctr); + + if (upTo != -1 && ctr > upTo)//stop loop if the specifed range is reached + { + break; + } + } + } + public static HtmlDocument GetTableOfContents(string link, CookieContainer cookies) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(link); diff --git a/syosetuDownloader/syosetuDownloader.csproj b/syosetuDownloader/syosetuDownloader.csproj index 4681f88..54bfa10 100644 --- a/syosetuDownloader/syosetuDownloader.csproj +++ b/syosetuDownloader/syosetuDownloader.csproj @@ -15,6 +15,21 @@ 512 {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 4 + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true x86 @@ -36,11 +51,17 @@ 4 + + False + ..\DLL\CommandLine.dll + .\HtmlAgilityPack.dll + + @@ -100,6 +121,23 @@ + + + False + Microsoft .NET Framework 4 Client Profile %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + + False + Windows Installer 4.5 + true + +