Code cleanup

This commit is contained in:
Caelan Sayler
2024-01-04 16:27:14 +00:00
parent aa96f3d8c1
commit 2e7ffeb883
68 changed files with 216 additions and 549 deletions

View File

@@ -13,8 +13,7 @@ public partial class App : Application
public override void OnFrameworkInitializationCompleted() public override void OnFrameworkInitializationCompleted()
{ {
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) {
{
desktop.MainWindow = new MainWindow(); desktop.MainWindow = new MainWindow();
} }

View File

@@ -1,8 +1,6 @@
using System; using System;
using System.IO;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Linq;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Threading; using Avalonia.Threading;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;

View File

@@ -1,5 +1,5 @@
using Avalonia; using System;
using System; using Avalonia;
using Velopack; using Velopack;
namespace AvaloniaCrossPlat; namespace AvaloniaCrossPlat;

View File

@@ -1,6 +1,5 @@
using System.Net; using System.Net;
using System.Text; using System.Text;
using System.Text.RegularExpressions;
using Amazon; using Amazon;
using Amazon.S3; using Amazon.S3;
using Amazon.S3.Model; using Amazon.S3.Model;

View File

@@ -1,11 +1,5 @@
using System; using Microsoft.Extensions.Logging;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Velopack.Sources; using Velopack.Sources;
using Velopack.Packaging;
namespace Velopack.Deployment; namespace Velopack.Deployment;

View File

@@ -1,5 +1,4 @@
using System.Text; using System.Text.RegularExpressions;
using System.Text.RegularExpressions;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using NuGet.Versioning; using NuGet.Versioning;

View File

@@ -1,6 +1,4 @@
using System.Text; using Microsoft.Extensions.Logging;
using System.Text.RegularExpressions;
using Microsoft.Extensions.Logging;
using NuGet.Versioning; using NuGet.Versioning;
namespace Velopack.Packaging.OSX.Commands; namespace Velopack.Packaging.OSX.Commands;

View File

@@ -1,5 +1,4 @@
using System; using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Runtime.Versioning; using System.Runtime.Versioning;

View File

@@ -1,7 +1,4 @@
using System.Drawing; using Microsoft.Extensions.Logging;
using System.Text;
using Microsoft.Extensions.Logging;
using Velopack.NuGet;
namespace Velopack.Packaging.Windows.Commands; namespace Velopack.Packaging.Windows.Commands;

View File

@@ -1,5 +1,4 @@
using System.Diagnostics; using System.Diagnostics;
using System.Text;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using NuGet.Versioning; using NuGet.Versioning;
using Velopack.NuGet; using Velopack.NuGet;

View File

@@ -1,7 +1,6 @@
using System.ComponentModel; using System.ComponentModel;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Runtime.Versioning; using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;

View File

@@ -1,10 +1,4 @@
using System; namespace Velopack.Packaging.Commands
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Velopack.Packaging.Commands
{ {
public class DeltaGenOptions public class DeltaGenOptions
{ {

View File

@@ -1,9 +1,4 @@
using System; using Microsoft.Extensions.Logging;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Velopack.Compression; using Velopack.Compression;
namespace Velopack.Packaging.Commands namespace Velopack.Packaging.Commands

View File

@@ -1,10 +1,4 @@
using System; namespace Velopack.Packaging.Commands
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Velopack.Packaging.Commands
{ {
public class DeltaPatchOptions public class DeltaPatchOptions
{ {

View File

@@ -1,7 +1,7 @@
using System.Text; using System.IO.MemoryMappedFiles;
using Velopack.Compression; using System.Text;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System.IO.MemoryMappedFiles; using Velopack.Compression;
namespace Velopack.Packaging; namespace Velopack.Packaging;
@@ -31,7 +31,7 @@ public class DeltaPackageBuilder
legacyBsdiff = true; legacyBsdiff = true;
} }
} }
if (basePackage.Version >= newPackage.Version) { if (basePackage.Version >= newPackage.Version) {
var message = String.Format( var message = String.Format(
"Cannot create a delta package based on version {0} as it is a later or equal to the base version {1}", "Cannot create a delta package based on version {0} as it is a later or equal to the base version {1}",

View File

@@ -1,10 +1,6 @@
using System.ComponentModel; using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace Velopack.Packaging; namespace Velopack.Packaging;

View File

@@ -1,9 +1,4 @@
using System; using Microsoft.Extensions.Logging;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
namespace Velopack.Packaging namespace Velopack.Packaging
{ {

View File

@@ -161,8 +161,7 @@ public class Markdown
/// <summary> /// <summary>
/// use ">" for HTML output, or " />" for XHTML output /// use ">" for HTML output, or " />" for XHTML output
/// </summary> /// </summary>
public string EmptyElementSuffix public string EmptyElementSuffix {
{
get { return _emptyElementSuffix; } get { return _emptyElementSuffix; }
set { _emptyElementSuffix = value; } set { _emptyElementSuffix = value; }
} }
@@ -172,8 +171,7 @@ public class Markdown
/// when false, email addresses will never be auto-linked /// when false, email addresses will never be auto-linked
/// WARNING: this is a significant deviation from the markdown spec /// WARNING: this is a significant deviation from the markdown spec
/// </summary> /// </summary>
public bool LinkEmails public bool LinkEmails {
{
get { return _linkEmails; } get { return _linkEmails; }
set { _linkEmails = value; } set { _linkEmails = value; }
} }
@@ -183,8 +181,7 @@ public class Markdown
/// when true, bold and italic require non-word characters on either side /// when true, bold and italic require non-word characters on either side
/// WARNING: this is a significant deviation from the markdown spec /// WARNING: this is a significant deviation from the markdown spec
/// </summary> /// </summary>
public bool StrictBoldItalic public bool StrictBoldItalic {
{
get { return _strictBoldItalic; } get { return _strictBoldItalic; }
set { _strictBoldItalic = value; } set { _strictBoldItalic = value; }
} }
@@ -194,8 +191,7 @@ public class Markdown
/// when true, RETURN becomes a literal newline /// when true, RETURN becomes a literal newline
/// WARNING: this is a significant deviation from the markdown spec /// WARNING: this is a significant deviation from the markdown spec
/// </summary> /// </summary>
public bool AutoNewLines public bool AutoNewLines {
{
get { return _autoNewlines; } get { return _autoNewlines; }
set { _autoNewlines = value; } set { _autoNewlines = value; }
} }
@@ -205,8 +201,7 @@ public class Markdown
/// when true, (most) bare plain URLs are auto-hyperlinked /// when true, (most) bare plain URLs are auto-hyperlinked
/// WARNING: this is a significant deviation from the markdown spec /// WARNING: this is a significant deviation from the markdown spec
/// </summary> /// </summary>
public bool AutoHyperlink public bool AutoHyperlink {
{
get { return _autoHyperlink; } get { return _autoHyperlink; }
set { _autoHyperlink = value; } set { _autoHyperlink = value; }
} }
@@ -216,8 +211,7 @@ public class Markdown
/// when true, problematic URL characters like [, ], (, and so forth will be encoded /// when true, problematic URL characters like [, ], (, and so forth will be encoded
/// WARNING: this is a significant deviation from the markdown spec /// WARNING: this is a significant deviation from the markdown spec
/// </summary> /// </summary>
public bool EncodeProblemUrlCharacters public bool EncodeProblemUrlCharacters {
{
get { return _encodeProblemUrlCharacters; } get { return _encodeProblemUrlCharacters; }
set { _encodeProblemUrlCharacters = value; } set { _encodeProblemUrlCharacters = value; }
} }
@@ -276,8 +270,7 @@ public class Markdown
string backslashPattern = ""; string backslashPattern = "";
foreach (char c in @"\`*_{}[]()>#+-.!/") foreach (char c in @"\`*_{}[]()>#+-.!/") {
{
string key = c.ToString(); string key = c.ToString();
string hash = GetHashKey(key, isHtmlBlock: false); string hash = GetHashKey(key, isHtmlBlock: false);
_escapeTable.Add(key, hash); _escapeTable.Add(key, hash);
@@ -293,8 +286,7 @@ public class Markdown
/// current version of MarkdownSharp; /// current version of MarkdownSharp;
/// see http://code.google.com/p/markdownsharp/ for the latest code or to contribute /// see http://code.google.com/p/markdownsharp/ for the latest code or to contribute
/// </summary> /// </summary>
public string Version public string Version {
{
get { return _version; } get { return _version; }
} }
@@ -391,20 +383,15 @@ public class Markdown
// split on two or more newlines // split on two or more newlines
string[] grafs = _newlinesMultiple.Split(_newlinesLeadingTrailing.Replace(text, "")); string[] grafs = _newlinesMultiple.Split(_newlinesLeadingTrailing.Replace(text, ""));
for (int i = 0; i < grafs.Length; i++) for (int i = 0; i < grafs.Length; i++) {
{ if (grafs[i].StartsWith("\x1AH")) {
if (grafs[i].StartsWith("\x1AH"))
{
// unhashify HTML blocks // unhashify HTML blocks
if (unhash) if (unhash) {
{
int sanityCheck = 50; // just for safety, guard against an infinite loop int sanityCheck = 50; // just for safety, guard against an infinite loop
bool keepGoing = true; // as long as replacements where made, keep going bool keepGoing = true; // as long as replacements where made, keep going
while (keepGoing && sanityCheck > 0) while (keepGoing && sanityCheck > 0) {
{
keepGoing = false; keepGoing = false;
grafs[i] = _htmlBlockHash.Replace(grafs[i], match => grafs[i] = _htmlBlockHash.Replace(grafs[i], match => {
{
keepGoing = true; keepGoing = true;
return _htmlBlocks[match.Value]; return _htmlBlocks[match.Value];
}); });
@@ -417,9 +404,7 @@ public class Markdown
// with the input that caused it. // with the input that caused it.
}*/ }*/
} }
} } else {
else
{
// do span level processing inside the block, then wrap result in <p> tags // do span level processing inside the block, then wrap result in <p> tags
grafs[i] = _leadingWhitespace.Replace(RunSpanGamut(grafs[i]), "<p>") + "</p>"; grafs[i] = _leadingWhitespace.Replace(RunSpanGamut(grafs[i]), "<p>") + "</p>";
} }
@@ -700,7 +685,7 @@ public class Markdown
private static string GetHashKey(string s, bool isHtmlBlock) private static string GetHashKey(string s, bool isHtmlBlock)
{ {
var delim = isHtmlBlock ? 'H' : 'E'; var delim = isHtmlBlock ? 'H' : 'E';
return "\x1A" + delim + Math.Abs(s.GetHashCode()).ToString() + delim; return "\x1A" + delim + Math.Abs(s.GetHashCode()).ToString() + delim;
} }
private static Regex _htmlTokens = new Regex(@" private static Regex _htmlTokens = new Regex(@"
@@ -726,8 +711,7 @@ public class Markdown
// this regex is derived from the _tokenize() subroutine in Brad Choate's MTRegex plugin. // this regex is derived from the _tokenize() subroutine in Brad Choate's MTRegex plugin.
// http://www.bradchoate.com/past/mtregex.php // http://www.bradchoate.com/past/mtregex.php
foreach (Match m in _htmlTokens.Matches(text)) foreach (Match m in _htmlTokens.Matches(text)) {
{
tagStart = m.Index; tagStart = m.Index;
if (pos < tagStart) if (pos < tagStart)
@@ -824,24 +808,21 @@ public class Markdown
if (linkID == "") if (linkID == "")
linkID = linkText.ToLowerInvariant(); linkID = linkText.ToLowerInvariant();
if (_urls.ContainsKey(linkID)) if (_urls.ContainsKey(linkID)) {
{
string url = _urls[linkID]; string url = _urls[linkID];
url = EncodeProblemUrlChars(url); url = EncodeProblemUrlChars(url);
url = EscapeBoldItalic(url); url = EscapeBoldItalic(url);
result = "<a href=\"" + url + "\""; result = "<a href=\"" + url + "\"";
if (_titles.ContainsKey(linkID)) if (_titles.ContainsKey(linkID)) {
{
string title = AttributeEncode(_titles[linkID]); string title = AttributeEncode(_titles[linkID]);
title = AttributeEncode(EscapeBoldItalic(title)); title = AttributeEncode(EscapeBoldItalic(title));
result += " title=\"" + title + "\""; result += " title=\"" + title + "\"";
} }
result += ">" + linkText + "</a>"; result += ">" + linkText + "</a>";
} } else
else
result = wholeMatch; result = wholeMatch;
return result; return result;
@@ -855,24 +836,21 @@ public class Markdown
string result; string result;
if (_urls.ContainsKey(linkID)) if (_urls.ContainsKey(linkID)) {
{
string url = _urls[linkID]; string url = _urls[linkID];
url = EncodeProblemUrlChars(url); url = EncodeProblemUrlChars(url);
url = EscapeBoldItalic(url); url = EscapeBoldItalic(url);
result = "<a href=\"" + url + "\""; result = "<a href=\"" + url + "\"";
if (_titles.ContainsKey(linkID)) if (_titles.ContainsKey(linkID)) {
{
string title = AttributeEncode(_titles[linkID]); string title = AttributeEncode(_titles[linkID]);
title = EscapeBoldItalic(title); title = EscapeBoldItalic(title);
result += " title=\"" + title + "\""; result += " title=\"" + title + "\"";
} }
result += ">" + linkText + "</a>"; result += ">" + linkText + "</a>";
} } else
else
result = wholeMatch; result = wholeMatch;
return result; return result;
@@ -893,8 +871,7 @@ public class Markdown
result = string.Format("<a href=\"{0}\"", url); result = string.Format("<a href=\"{0}\"", url);
if (!String.IsNullOrEmpty(title)) if (!String.IsNullOrEmpty(title)) {
{
title = AttributeEncode(title); title = AttributeEncode(title);
title = EscapeBoldItalic(title); title = EscapeBoldItalic(title);
result += string.Format(" title=\"{0}\"", title); result += string.Format(" title=\"{0}\"", title);
@@ -978,8 +955,7 @@ public class Markdown
if (linkID == "") if (linkID == "")
linkID = altText.ToLowerInvariant(); linkID = altText.ToLowerInvariant();
if (_urls.ContainsKey(linkID)) if (_urls.ContainsKey(linkID)) {
{
string url = _urls[linkID]; string url = _urls[linkID];
string title = null; string title = null;
@@ -987,9 +963,7 @@ public class Markdown
title = _titles[linkID]; title = _titles[linkID];
return ImageTag(url, altText, title); return ImageTag(url, altText, title);
} } else {
else
{
// If there's no such link ID, leave intact: // If there's no such link ID, leave intact:
return wholeMatch; return wholeMatch;
} }
@@ -1013,8 +987,7 @@ public class Markdown
url = EncodeProblemUrlChars(url); url = EncodeProblemUrlChars(url);
url = EscapeBoldItalic(url); url = EscapeBoldItalic(url);
var result = string.Format("<img src=\"{0}\" alt=\"{1}\"", url, altText); var result = string.Format("<img src=\"{0}\" alt=\"{1}\"", url, altText);
if (!String.IsNullOrEmpty(title)) if (!String.IsNullOrEmpty(title)) {
{
title = AttributeEncode(EscapeBoldItalic(title)); title = AttributeEncode(EscapeBoldItalic(title));
result += string.Format(" title=\"{0}\"", title); result += string.Format(" title=\"{0}\"", title);
} }
@@ -1146,17 +1119,16 @@ public class Markdown
private MatchEvaluator GetListEvaluator(bool isInsideParagraphlessListItem = false) private MatchEvaluator GetListEvaluator(bool isInsideParagraphlessListItem = false)
{ {
return new MatchEvaluator(match => return new MatchEvaluator(match => {
{ string list = match.Groups[1].Value;
string list = match.Groups[1].Value; string listType = Regex.IsMatch(match.Groups[3].Value, _markerUL) ? "ul" : "ol";
string listType = Regex.IsMatch(match.Groups[3].Value, _markerUL) ? "ul" : "ol"; string result;
string result;
result = ProcessListItems(list, listType == "ul" ? _markerUL : _markerOL, isInsideParagraphlessListItem); result = ProcessListItems(list, listType == "ul" ? _markerUL : _markerOL, isInsideParagraphlessListItem);
result = string.Format("<{0}>\n{1}</{0}>\n", listType, result); result = string.Format("<{0}>\n{1}</{0}>\n", listType, result);
return result; return result;
}); });
} }
/// <summary> /// <summary>
@@ -1201,8 +1173,7 @@ public class Markdown
bool lastItemHadADoubleNewline = false; bool lastItemHadADoubleNewline = false;
// has to be a closure, so subsequent invocations can share the bool // has to be a closure, so subsequent invocations can share the bool
MatchEvaluator ListItemEvaluator = (Match match) => MatchEvaluator ListItemEvaluator = (Match match) => {
{
string item = match.Groups[3].Value; string item = match.Groups[3].Value;
bool endsWithDoubleNewline = item.EndsWith("\n\n"); bool endsWithDoubleNewline = item.EndsWith("\n\n");
@@ -1211,8 +1182,7 @@ public class Markdown
if (containsDoubleNewline || lastItemHadADoubleNewline) if (containsDoubleNewline || lastItemHadADoubleNewline)
// we could correct any bad indentation here.. // we could correct any bad indentation here..
item = RunBlockGamut(Outdent(item) + "\n", unhash: false); item = RunBlockGamut(Outdent(item) + "\n", unhash: false);
else else {
{
// recursion for sub-lists // recursion for sub-lists
item = DoLists(Outdent(item), isInsideParagraphlessListItem: true); item = DoLists(Outdent(item), isInsideParagraphlessListItem: true);
item = item.TrimEnd('\n'); item = item.TrimEnd('\n');
@@ -1327,13 +1297,10 @@ public class Markdown
{ {
// <strong> must go first, then <em> // <strong> must go first, then <em>
if (_strictBoldItalic) if (_strictBoldItalic) {
{
text = _strictBold.Replace(text, "$1<strong>$3</strong>"); text = _strictBold.Replace(text, "$1<strong>$3</strong>");
text = _strictItalic.Replace(text, "$1<em>$3</em>"); text = _strictItalic.Replace(text, "$1<em>$3</em>");
} } else {
else
{
text = _bold.Replace(text, "<strong>$2</strong>"); text = _bold.Replace(text, "<strong>$2</strong>");
text = _italic.Replace(text, "<em>$2</em>"); text = _italic.Replace(text, "<em>$2</em>");
} }
@@ -1418,30 +1385,23 @@ public class Markdown
if (!link.EndsWith(")")) if (!link.EndsWith(")"))
return "<" + protocol + link + ">"; return "<" + protocol + link + ">";
var level = 0; var level = 0;
foreach (Match c in Regex.Matches(link, "[()]")) foreach (Match c in Regex.Matches(link, "[()]")) {
{ if (c.Value == "(") {
if (c.Value == "(")
{
if (level <= 0) if (level <= 0)
level = 1; level = 1;
else else
level++; level++;
} } else {
else
{
level--; level--;
} }
} }
var tail = ""; var tail = "";
if (level < 0) if (level < 0) {
{
link = Regex.Replace(link, @"\){1," + (-level) + "}$", m => { tail = m.Value; return ""; }); link = Regex.Replace(link, @"\){1," + (-level) + "}$", m => { tail = m.Value; return ""; });
} }
if (tail.Length > 0) if (tail.Length > 0) {
{
var lastChar = link[link.Length - 1]; var lastChar = link[link.Length - 1];
if (!_endCharRegex.IsMatch(lastChar.ToString())) if (!_endCharRegex.IsMatch(lastChar.ToString())) {
{
tail = lastChar + tail; tail = lastChar + tail;
link = link.Substring(0, link.Length - 1); link = link.Substring(0, link.Length - 1);
} }
@@ -1458,8 +1418,7 @@ public class Markdown
private string DoAutoLinks(string text) private string DoAutoLinks(string text)
{ {
if (_autoHyperlink) if (_autoHyperlink) {
{
// fixup arbitrary URLs by adding Markdown < > so they get linked as well // fixup arbitrary URLs by adding Markdown < > so they get linked as well
// note that at this point, all other URL in the text are already hyperlinked as <a href=""></a> // note that at this point, all other URL in the text are already hyperlinked as <a href=""></a>
// *except* for the <http://www.foo.com> case // *except* for the <http://www.foo.com> case
@@ -1469,8 +1428,7 @@ public class Markdown
// Hyperlinks: <http://foo.com> // Hyperlinks: <http://foo.com>
text = Regex.Replace(text, "<((https?|ftp):[^'\">\\s]+)>", new MatchEvaluator(HyperlinkEvaluator)); text = Regex.Replace(text, "<((https?|ftp):[^'\">\\s]+)>", new MatchEvaluator(HyperlinkEvaluator));
if (_linkEmails) if (_linkEmails) {
{
// Email addresses: <address@domain.foo> // Email addresses: <address@domain.foo>
string pattern = string pattern =
@"< @"<
@@ -1548,15 +1506,14 @@ public class Markdown
var sb = new StringBuilder(addr.Length * 5); var sb = new StringBuilder(addr.Length * 5);
var rand = new Random(); var rand = new Random();
int r; int r;
foreach (char c in addr) foreach (char c in addr) {
{
r = rand.Next(1, 100); r = rand.Next(1, 100);
if ((r > 90 || c == ':') && c != '@') if ((r > 90 || c == ':') && c != '@')
sb.Append(c); // m sb.Append(c); // m
else if (r < 45) else if (r < 45)
sb.AppendFormat("&#x{0:x};", (int)c); // &#x6D sb.AppendFormat("&#x{0:x};", (int) c); // &#x6D
else else
sb.AppendFormat("&#{0};", (int)c); // &#109 sb.AppendFormat("&#{0};", (int) c); // &#109
} }
return sb.ToString(); return sb.ToString();
} }
@@ -1572,20 +1529,19 @@ public class Markdown
} }
private string EncodeCodeEvaluator(Match match) private string EncodeCodeEvaluator(Match match)
{ {
switch (match.Value) switch (match.Value) {
{ // Encode all ampersands; HTML entities are not
// Encode all ampersands; HTML entities are not // entities within a Markdown code span.
// entities within a Markdown code span. case "&":
case "&": return "&amp;";
return "&amp;"; // Do the angle bracket song and dance
// Do the angle bracket song and dance case "<":
case "<": return "&lt;";
return "&lt;"; case ">":
case ">": return "&gt;";
return "&gt;"; // escape characters that are magic in Markdown
// escape characters that are magic in Markdown default:
default: return _escapeTable[match.Value];
return _escapeTable[match.Value];
} }
} }
@@ -1660,15 +1616,14 @@ public class Markdown
bool encode; bool encode;
char c; char c;
for (int i = 0; i < url.Length; i++) for (int i = 0; i < url.Length; i++) {
{
c = url[i]; c = url[i];
encode = Array.IndexOf(_problemUrlChars, c) != -1; encode = Array.IndexOf(_problemUrlChars, c) != -1;
if (encode && c == ':' && i < url.Length - 1) if (encode && c == ':' && i < url.Length - 1)
encode = !(url[i + 1] == '/') && !(url[i + 1] >= '0' && url[i + 1] <= '9'); encode = !(url[i + 1] == '/') && !(url[i + 1] >= '0' && url[i + 1] <= '9');
if (encode) if (encode)
sb.Append("%" + String.Format("{0:x}", (byte)c)); sb.Append("%" + String.Format("{0:x}", (byte) c));
else else
sb.Append(c); sb.Append(c);
} }
@@ -1691,12 +1646,10 @@ public class Markdown
// now, rebuild text from the tokens // now, rebuild text from the tokens
var sb = new StringBuilder(text.Length); var sb = new StringBuilder(text.Length);
foreach (var token in tokens) foreach (var token in tokens) {
{
string value = token.Value; string value = token.Value;
if (token.Type == TokenType.Tag) if (token.Type == TokenType.Tag) {
{
value = value.Replace(@"\", _escapeTable[@"\"]); value = value.Replace(@"\", _escapeTable[@"\"]);
if (_autoHyperlink && value.StartsWith("<!")) // escape slashes in comments to prevent autolinking there -- http://meta.stackoverflow.com/questions/95987/html-comment-containing-url-breaks-if-followed-by-another-html-comment if (_autoHyperlink && value.StartsWith("<!")) // escape slashes in comments to prevent autolinking there -- http://meta.stackoverflow.com/questions/95987/html-comment-containing-url-breaks-if-followed-by-another-html-comment
@@ -1724,34 +1677,31 @@ public class Markdown
var line = new StringBuilder(); var line = new StringBuilder();
bool valid = false; bool valid = false;
for (int i = 0; i < text.Length; i++) for (int i = 0; i < text.Length; i++) {
{ switch (text[i]) {
switch (text[i]) case '\n':
{ if (valid) output.Append(line);
case '\n': output.Append('\n');
line.Length = 0; valid = false;
break;
case '\r':
if ((i < text.Length - 1) && (text[i + 1] != '\n')) {
if (valid) output.Append(line); if (valid) output.Append(line);
output.Append('\n'); output.Append('\n');
line.Length = 0; valid = false; line.Length = 0; valid = false;
break; }
case '\r': break;
if ((i < text.Length - 1) && (text[i + 1] != '\n')) case '\t':
{ int width = (_tabWidth - line.Length % _tabWidth);
if (valid) output.Append(line); for (int k = 0; k < width; k++)
output.Append('\n'); line.Append(' ');
line.Length = 0; valid = false; break;
} case '\x1A':
break; break;
case '\t': default:
int width = (_tabWidth - line.Length % _tabWidth); if (!valid && text[i] != ' ') valid = true;
for (int k = 0; k < width; k++) line.Append(text[i]);
line.Append(' '); break;
break;
case '\x1A':
break;
default:
if (!valid && text[i] != ' ') valid = true;
line.Append(text[i]);
break;
} }
} }

View File

@@ -1,8 +1,8 @@
using Microsoft.Extensions.Logging; using System.Diagnostics.CodeAnalysis;
using Microsoft.Extensions.Logging;
using INugetLogger = NuGet.Common.ILogger; using INugetLogger = NuGet.Common.ILogger;
using NugetLogLevel = NuGet.Common.LogLevel;
using INugetLogMessage = NuGet.Common.ILogMessage; using INugetLogMessage = NuGet.Common.ILogMessage;
using System.Diagnostics.CodeAnalysis; using NugetLogLevel = NuGet.Common.LogLevel;
namespace Velopack.Packaging; namespace Velopack.Packaging;

View File

@@ -1,10 +1,4 @@
using System; using Microsoft.Extensions.Logging;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using NuGet.Versioning; using NuGet.Versioning;
using Velopack.Sources; using Velopack.Sources;

View File

@@ -1,5 +1,4 @@
using System.IO.Compression; using System.IO.Compression;
using System.Linq;
using System.Text; using System.Text;
using System.Xml; using System.Xml;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;

View File

@@ -1,10 +1,4 @@
using System; using Velopack.Packaging;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Octokit;
using Velopack.Packaging;
namespace Velopack.Vpk.Commands namespace Velopack.Vpk.Commands
{ {

View File

@@ -1,11 +1,4 @@
using System; namespace Velopack.Vpk.Commands
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Velopack.Packaging;
namespace Velopack.Vpk.Commands
{ {
public class DeltaPatchCommand : BaseCommand public class DeltaPatchCommand : BaseCommand
{ {

View File

@@ -1,7 +1,4 @@
using Microsoft.Extensions.Logging; namespace Velopack.Vpk.Commands;
using Velopack.Deployment;
namespace Velopack.Vpk.Commands;
public class GitHubUploadCommand : GitHubBaseCommand public class GitHubUploadCommand : GitHubBaseCommand
{ {

View File

@@ -1,5 +1,4 @@
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using NuGet.Common;
using NuGet.Versioning; using NuGet.Versioning;
using Velopack.NuGet; using Velopack.NuGet;
using Velopack.Windows; using Velopack.Windows;

View File

@@ -1,7 +1,4 @@
 namespace Velopack.Vpk.Commands;
using Velopack.Packaging;
namespace Velopack.Vpk.Commands;
public class WindowsSigningCommand : PlatformCommand public class WindowsSigningCommand : PlatformCommand
{ {

View File

@@ -1,9 +1,4 @@
using System; using Velopack.Packaging;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Velopack.Packaging;
namespace Velopack.Vpk.Commands namespace Velopack.Vpk.Commands
{ {

View File

@@ -1,10 +1,4 @@
using System; namespace Velopack.Vpk.Commands
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Velopack.Vpk.Commands
{ {
public abstract class PlatformCommand : OutputCommand public abstract class PlatformCommand : OutputCommand
{ {

View File

@@ -1,9 +1,9 @@
using System.Runtime.Versioning; using System.Runtime.Versioning;
using Velopack.Vpk.Commands;
using Velopack.Deployment; using Velopack.Deployment;
using Velopack.Packaging.Commands; using Velopack.Packaging.Commands;
using Velopack.Packaging.OSX.Commands; using Velopack.Packaging.OSX.Commands;
using Velopack.Packaging.Windows.Commands; using Velopack.Packaging.Windows.Commands;
using Velopack.Vpk.Commands;
namespace Velopack.Vpk.Compat; namespace Velopack.Vpk.Compat;

View File

@@ -1,5 +1,4 @@
using System.Runtime.Versioning; using Velopack.Vpk.Commands;
using Velopack.Vpk.Commands;
namespace Velopack.Vpk.Compat; namespace Velopack.Vpk.Compat;

View File

@@ -1,12 +1,10 @@
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Configuration;
using Serilog.Events;
using Serilog;
using Microsoft.Extensions.Configuration;
using Velopack.Vpk.Commands;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Velopack.Vpk.Updates; using Microsoft.Extensions.Hosting;
using Serilog;
using Serilog.Events;
using Velopack.Vpk.Commands;
using Velopack.Vpk.Compat; using Velopack.Vpk.Compat;
using System.CommandLine.Help;
namespace Velopack.Vpk; namespace Velopack.Vpk;
@@ -18,7 +16,7 @@ public class Program
private static RunnerFactory Runner { get; set; } private static RunnerFactory Runner { get; set; }
public static readonly string INTRO public static readonly string INTRO
= $"Velopack CLI {VelopackRuntimeInfo.VelopackDisplayVersion} for creating and distributing releases."; = $"Velopack CLI {VelopackRuntimeInfo.VelopackDisplayVersion} for creating and distributing releases.";
public static async Task<int> Main(string[] args) public static async Task<int> Main(string[] args)

View File

@@ -1,5 +1,4 @@
using System.Threading; using System.Threading;
using Velopack.Packaging;
namespace Velopack.Vpk.Updates; namespace Velopack.Vpk.Updates;

View File

@@ -52,14 +52,10 @@ namespace Velopack.Compression
// solve it, just buys us more space. The solution is to rewrite Split // solve it, just buys us more space. The solution is to rewrite Split
// using iteration instead of recursion, but that's Hard(tm). // using iteration instead of recursion, but that's Hard(tm).
var ex = default(Exception); var ex = default(Exception);
var t = new Thread(() => var t = new Thread(() => {
{ try {
try
{
CreateInternal(oldData, newData, output); CreateInternal(oldData, newData, output);
} } catch (Exception exc) {
catch (Exception exc)
{
ex = exc; ex = exc;
} }
}, 40 * 1048576); }, 40 * 1048576);
@@ -112,8 +108,7 @@ namespace Velopack.Compression
int eblen = 0; int eblen = 0;
using (WrappingStream wrappingStream = new WrappingStream(output, Ownership.None)) using (WrappingStream wrappingStream = new WrappingStream(output, Ownership.None))
using (var bz2Stream = new BZip2Stream(wrappingStream, CompressionMode.Compress, true)) using (var bz2Stream = new BZip2Stream(wrappingStream, CompressionMode.Compress, true)) {
{
// compute the differences, writing ctrl as we go // compute the differences, writing ctrl as we go
int scan = 0; int scan = 0;
int pos = 0; int pos = 0;
@@ -121,16 +116,13 @@ namespace Velopack.Compression
int lastscan = 0; int lastscan = 0;
int lastpos = 0; int lastpos = 0;
int lastoffset = 0; int lastoffset = 0;
while (scan < newData.Length) while (scan < newData.Length) {
{
int oldscore = 0; int oldscore = 0;
for (int scsc = scan += len; scan < newData.Length; scan++) for (int scsc = scan += len; scan < newData.Length; scan++) {
{
len = Search(I, oldData, newData, scan, 0, oldData.Length, out pos); len = Search(I, oldData, newData, scan, 0, oldData.Length, out pos);
for (; scsc < scan + len; scsc++) for (; scsc < scan + len; scsc++) {
{
if ((scsc + lastoffset < oldData.Length) && (oldData[scsc + lastoffset] == newData[scsc])) if ((scsc + lastoffset < oldData.Length) && (oldData[scsc + lastoffset] == newData[scsc]))
oldscore++; oldscore++;
} }
@@ -142,54 +134,45 @@ namespace Velopack.Compression
oldscore--; oldscore--;
} }
if (len != oldscore || scan == newData.Length) if (len != oldscore || scan == newData.Length) {
{
int s = 0; int s = 0;
int sf = 0; int sf = 0;
int lenf = 0; int lenf = 0;
for (int i = 0; (lastscan + i < scan) && (lastpos + i < oldData.Length); ) for (int i = 0; (lastscan + i < scan) && (lastpos + i < oldData.Length);) {
{
if (oldData[lastpos + i] == newData[lastscan + i]) if (oldData[lastpos + i] == newData[lastscan + i])
s++; s++;
i++; i++;
if (s * 2 - i > sf * 2 - lenf) if (s * 2 - i > sf * 2 - lenf) {
{
sf = s; sf = s;
lenf = i; lenf = i;
} }
} }
int lenb = 0; int lenb = 0;
if (scan < newData.Length) if (scan < newData.Length) {
{
s = 0; s = 0;
int sb = 0; int sb = 0;
for (int i = 1; (scan >= lastscan + i) && (pos >= i); i++) for (int i = 1; (scan >= lastscan + i) && (pos >= i); i++) {
{
if (oldData[pos - i] == newData[scan - i]) if (oldData[pos - i] == newData[scan - i])
s++; s++;
if (s * 2 - i > sb * 2 - lenb) if (s * 2 - i > sb * 2 - lenb) {
{
sb = s; sb = s;
lenb = i; lenb = i;
} }
} }
} }
if (lastscan + lenf > scan - lenb) if (lastscan + lenf > scan - lenb) {
{
int overlap = (lastscan + lenf) - (scan - lenb); int overlap = (lastscan + lenf) - (scan - lenb);
s = 0; s = 0;
int ss = 0; int ss = 0;
int lens = 0; int lens = 0;
for (int i = 0; i < overlap; i++) for (int i = 0; i < overlap; i++) {
{
if (newData[lastscan + lenf - overlap + i] == oldData[lastpos + lenf - overlap + i]) if (newData[lastscan + lenf - overlap + i] == oldData[lastpos + lenf - overlap + i])
s++; s++;
if (newData[scan - lenb + i] == oldData[pos - lenb + i]) if (newData[scan - lenb + i] == oldData[pos - lenb + i])
s--; s--;
if (s > ss) if (s > ss) {
{
ss = s; ss = s;
lens = i + 1; lens = i + 1;
} }
@@ -200,7 +183,7 @@ namespace Velopack.Compression
} }
for (int i = 0; i < lenf; i++) for (int i = 0; i < lenf; i++)
db[dblen + i] = (byte)(newData[lastscan + i] - oldData[lastpos + i]); db[dblen + i] = (byte) (newData[lastscan + i] - oldData[lastpos + i]);
for (int i = 0; i < (scan - lenb) - (lastscan + lenf); i++) for (int i = 0; i < (scan - lenb) - (lastscan + lenf); i++)
eb[eblen + i] = newData[lastscan + lenf + i]; eb[eblen + i] = newData[lastscan + lenf + i];
@@ -230,8 +213,7 @@ namespace Velopack.Compression
// write compressed diff data // write compressed diff data
using (WrappingStream wrappingStream = new WrappingStream(output, Ownership.None)) using (WrappingStream wrappingStream = new WrappingStream(output, Ownership.None))
using (var bz2Stream = new BZip2Stream(wrappingStream, CompressionMode.Compress, true)) using (var bz2Stream = new BZip2Stream(wrappingStream, CompressionMode.Compress, true)) {
{
bz2Stream.Write(db, 0, dblen); bz2Stream.Write(db, 0, dblen);
} }
@@ -240,11 +222,9 @@ namespace Velopack.Compression
WriteInt64(diffEndPosition - controlEndPosition, header, 16); WriteInt64(diffEndPosition - controlEndPosition, header, 16);
// write compressed extra data, if any // write compressed extra data, if any
if (eblen > 0) if (eblen > 0) {
{
using (WrappingStream wrappingStream = new WrappingStream(output, Ownership.None)) using (WrappingStream wrappingStream = new WrappingStream(output, Ownership.None))
using (var bz2Stream = new BZip2Stream(wrappingStream, CompressionMode.Compress, true)) using (var bz2Stream = new BZip2Stream(wrappingStream, CompressionMode.Compress, true)) {
{
bz2Stream.Write(eb, 0, eblen); bz2Stream.Write(eb, 0, eblen);
} }
} }
@@ -290,8 +270,7 @@ namespace Velopack.Compression
*/ */
// read header // read header
long controlLength, diffLength, newSize; long controlLength, diffLength, newSize;
using (Stream patchStream = openPatchStream()) using (Stream patchStream = openPatchStream()) {
{
// check patch stream capabilities // check patch stream capabilities
if (!patchStream.CanRead) if (!patchStream.CanRead)
throw new ArgumentException("Patch stream must be readable.", "openPatchStream"); throw new ArgumentException("Patch stream must be readable.", "openPatchStream");
@@ -321,8 +300,7 @@ namespace Velopack.Compression
// prepare to read three parts of the patch in parallel // prepare to read three parts of the patch in parallel
using (Stream compressedControlStream = openPatchStream()) using (Stream compressedControlStream = openPatchStream())
using (Stream compressedDiffStream = openPatchStream()) using (Stream compressedDiffStream = openPatchStream())
using (Stream compressedExtraStream = openPatchStream()) using (Stream compressedExtraStream = openPatchStream()) {
{
// seek to the start of each part // seek to the start of each part
compressedControlStream.Seek(c_headerSize, SeekOrigin.Current); compressedControlStream.Seek(c_headerSize, SeekOrigin.Current);
compressedDiffStream.Seek(c_headerSize + controlLength, SeekOrigin.Current); compressedDiffStream.Seek(c_headerSize + controlLength, SeekOrigin.Current);
@@ -334,18 +312,15 @@ namespace Velopack.Compression
// decompress each part (to read it) // decompress each part (to read it)
using (var controlStream = new BZip2Stream(compressedControlStream, CompressionMode.Decompress, true)) using (var controlStream = new BZip2Stream(compressedControlStream, CompressionMode.Decompress, true))
using (var diffStream = new BZip2Stream(compressedDiffStream, CompressionMode.Decompress, true)) using (var diffStream = new BZip2Stream(compressedDiffStream, CompressionMode.Decompress, true))
using (var extraStream = hasExtraData ? new BZip2Stream(compressedExtraStream, CompressionMode.Decompress, true) : null) using (var extraStream = hasExtraData ? new BZip2Stream(compressedExtraStream, CompressionMode.Decompress, true) : null) {
{
long[] control = new long[3]; long[] control = new long[3];
byte[] buffer = new byte[8]; byte[] buffer = new byte[8];
int oldPosition = 0; int oldPosition = 0;
int newPosition = 0; int newPosition = 0;
while (newPosition < newSize) while (newPosition < newSize) {
{
// read control data // read control data
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++) {
{
controlStream.ReadExactly(buffer, 0, 8); controlStream.ReadExactly(buffer, 0, 8);
control[i] = ReadInt64(buffer, 0); control[i] = ReadInt64(buffer, 0);
} }
@@ -357,16 +332,15 @@ namespace Velopack.Compression
// seek old file to the position that the new data is diffed against // seek old file to the position that the new data is diffed against
input.Position = oldPosition; input.Position = oldPosition;
int bytesToCopy = (int)control[0]; int bytesToCopy = (int) control[0];
while (bytesToCopy > 0) while (bytesToCopy > 0) {
{
int actualBytesToCopy = Math.Min(bytesToCopy, c_bufferSize); int actualBytesToCopy = Math.Min(bytesToCopy, c_bufferSize);
// read diff string // read diff string
diffStream.ReadExactly(newData, 0, actualBytesToCopy); diffStream.ReadExactly(newData, 0, actualBytesToCopy);
// add old data to diff string // add old data to diff string
int availableInputBytes = Math.Min(actualBytesToCopy, (int)(input.Length - input.Position)); int availableInputBytes = Math.Min(actualBytesToCopy, (int) (input.Length - input.Position));
input.ReadExactly(oldData, 0, availableInputBytes); input.ReadExactly(oldData, 0, availableInputBytes);
for (int index = 0; index < availableInputBytes; index++) for (int index = 0; index < availableInputBytes; index++)
@@ -385,9 +359,8 @@ namespace Velopack.Compression
throw new InvalidOperationException("Corrupt patch."); throw new InvalidOperationException("Corrupt patch.");
// read extra string // read extra string
bytesToCopy = (int)control[1]; bytesToCopy = (int) control[1];
while (bytesToCopy > 0) while (bytesToCopy > 0) {
{
int actualBytesToCopy = Math.Min(bytesToCopy, c_bufferSize); int actualBytesToCopy = Math.Min(bytesToCopy, c_bufferSize);
extraStream.ReadExactly(newData, 0, actualBytesToCopy); extraStream.ReadExactly(newData, 0, actualBytesToCopy);
@@ -398,7 +371,7 @@ namespace Velopack.Compression
} }
// adjust position // adjust position
oldPosition = (int)(oldPosition + control[2]); oldPosition = (int) (oldPosition + control[2]);
} }
} }
} }
@@ -406,8 +379,7 @@ namespace Velopack.Compression
private static int CompareBytes(byte[] left, int leftOffset, byte[] right, int rightOffset) private static int CompareBytes(byte[] left, int leftOffset, byte[] right, int rightOffset)
{ {
for (int index = 0; index < left.Length - leftOffset && index < right.Length - rightOffset; index++) for (int index = 0; index < left.Length - leftOffset && index < right.Length - rightOffset; index++) {
{
int diff = left[index + leftOffset] - right[index + rightOffset]; int diff = left[index + leftOffset] - right[index + rightOffset];
if (diff != 0) if (diff != 0)
return diff; return diff;
@@ -418,8 +390,7 @@ namespace Velopack.Compression
private static int MatchLength(byte[] oldData, int oldOffset, byte[] newData, int newOffset) private static int MatchLength(byte[] oldData, int oldOffset, byte[] newData, int newOffset)
{ {
int i; int i;
for (i = 0; i < oldData.Length - oldOffset && i < newData.Length - newOffset; i++) for (i = 0; i < oldData.Length - oldOffset && i < newData.Length - newOffset; i++) {
{
if (oldData[i + oldOffset] != newData[i + newOffset]) if (oldData[i + oldOffset] != newData[i + newOffset])
break; break;
} }
@@ -428,24 +399,18 @@ namespace Velopack.Compression
private static int Search(int[] I, byte[] oldData, byte[] newData, int newOffset, int start, int end, out int pos) private static int Search(int[] I, byte[] oldData, byte[] newData, int newOffset, int start, int end, out int pos)
{ {
if (end - start < 2) if (end - start < 2) {
{
int startLength = MatchLength(oldData, I[start], newData, newOffset); int startLength = MatchLength(oldData, I[start], newData, newOffset);
int endLength = MatchLength(oldData, I[end], newData, newOffset); int endLength = MatchLength(oldData, I[end], newData, newOffset);
if (startLength > endLength) if (startLength > endLength) {
{
pos = I[start]; pos = I[start];
return startLength; return startLength;
} } else {
else
{
pos = I[end]; pos = I[end];
return endLength; return endLength;
} }
} } else {
else
{
int midPoint = start + (end - start) / 2; int midPoint = start + (end - start) / 2;
return CompareBytes(oldData, I[midPoint], newData, newOffset) < 0 ? return CompareBytes(oldData, I[midPoint], newData, newOffset) < 0 ?
Search(I, oldData, newData, newOffset, midPoint, end, out pos) : Search(I, oldData, newData, newOffset, midPoint, end, out pos) :
@@ -455,22 +420,17 @@ namespace Velopack.Compression
private static void Split(int[] I, int[] v, int start, int len, int h) private static void Split(int[] I, int[] v, int start, int len, int h)
{ {
if (len < 16) if (len < 16) {
{
int j; int j;
for (int k = start; k < start + len; k += j) for (int k = start; k < start + len; k += j) {
{
j = 1; j = 1;
int x = v[I[k] + h]; int x = v[I[k] + h];
for (int i = 1; k + i < start + len; i++) for (int i = 1; k + i < start + len; i++) {
{ if (v[I[k + i] + h] < x) {
if (v[I[k + i] + h] < x)
{
x = v[I[k + i] + h]; x = v[I[k + i] + h];
j = 0; j = 0;
} }
if (v[I[k + i] + h] == x) if (v[I[k + i] + h] == x) {
{
Swap(ref I[k + j], ref I[k + i]); Swap(ref I[k + j], ref I[k + i]);
j++; j++;
} }
@@ -480,14 +440,11 @@ namespace Velopack.Compression
if (j == 1) if (j == 1)
I[k] = -1; I[k] = -1;
} }
} } else {
else
{
int x = v[I[start + len / 2] + h]; int x = v[I[start + len / 2] + h];
int jj = 0; int jj = 0;
int kk = 0; int kk = 0;
for (int i2 = start; i2 < start + len; i2++) for (int i2 = start; i2 < start + len; i2++) {
{
if (v[I[i2] + h] < x) if (v[I[i2] + h] < x)
jj++; jj++;
if (v[I[i2] + h] == x) if (v[I[i2] + h] == x)
@@ -499,32 +456,22 @@ namespace Velopack.Compression
int i = start; int i = start;
int j = 0; int j = 0;
int k = 0; int k = 0;
while (i < jj) while (i < jj) {
{ if (v[I[i] + h] < x) {
if (v[I[i] + h] < x)
{
i++; i++;
} } else if (v[I[i] + h] == x) {
else if (v[I[i] + h] == x)
{
Swap(ref I[i], ref I[jj + j]); Swap(ref I[i], ref I[jj + j]);
j++; j++;
} } else {
else
{
Swap(ref I[i], ref I[kk + k]); Swap(ref I[i], ref I[kk + k]);
k++; k++;
} }
} }
while (jj + j < kk) while (jj + j < kk) {
{ if (v[I[jj + j] + h] == x) {
if (v[I[jj + j] + h] == x)
{
j++; j++;
} } else {
else
{
Swap(ref I[jj + j], ref I[kk + k]); Swap(ref I[jj + j], ref I[kk + k]);
k++; k++;
} }
@@ -563,26 +510,20 @@ namespace Velopack.Compression
for (int i = 0; i < oldData.Length; i++) for (int i = 0; i < oldData.Length; i++)
v[i] = buckets[oldData[i]]; v[i] = buckets[oldData[i]];
for (int i = 1; i < 256; i++) for (int i = 1; i < 256; i++) {
{
if (buckets[i] == buckets[i - 1] + 1) if (buckets[i] == buckets[i - 1] + 1)
I[buckets[i]] = -1; I[buckets[i]] = -1;
} }
I[0] = -1; I[0] = -1;
for (int h = 1; I[0] != -(oldData.Length + 1); h += h) for (int h = 1; I[0] != -(oldData.Length + 1); h += h) {
{
int len = 0; int len = 0;
int i = 0; int i = 0;
while (i < oldData.Length + 1) while (i < oldData.Length + 1) {
{ if (I[i] < 0) {
if (I[i] < 0)
{
len -= I[i]; len -= I[i];
i -= I[i]; i -= I[i];
} } else {
else
{
if (len != 0) if (len != 0)
I[i - len] = -len; I[i - len] = -len;
len = v[I[i]] + 1 - i; len = v[I[i]] + 1 - i;
@@ -613,8 +554,7 @@ namespace Velopack.Compression
{ {
long value = buf[offset + 7] & 0x7F; long value = buf[offset + 7] & 0x7F;
for (int index = 6; index >= 0; index--) for (int index = 6; index >= 0; index--) {
{
value *= 256; value *= 256;
value += buf[offset + index]; value += buf[offset + index];
} }
@@ -629,9 +569,8 @@ namespace Velopack.Compression
{ {
long valueToWrite = value < 0 ? -value : value; long valueToWrite = value < 0 ? -value : value;
for (int byteIndex = 0; byteIndex < 8; byteIndex++) for (int byteIndex = 0; byteIndex < 8; byteIndex++) {
{ buf[offset + byteIndex] = (byte) (valueToWrite % 256);
buf[offset + byteIndex] = (byte)(valueToWrite % 256);
valueToWrite -= buf[offset + byteIndex]; valueToWrite -= buf[offset + byteIndex];
valueToWrite /= 256; valueToWrite /= 256;
} }
@@ -672,8 +611,7 @@ namespace Velopack.Compression
/// Gets a value indicating whether the current stream supports reading. /// Gets a value indicating whether the current stream supports reading.
/// </summary> /// </summary>
/// <returns><c>true</c> if the stream supports reading; otherwise, <c>false</c>.</returns> /// <returns><c>true</c> if the stream supports reading; otherwise, <c>false</c>.</returns>
public override bool CanRead public override bool CanRead {
{
get { return m_streamBase == null ? false : m_streamBase.CanRead; } get { return m_streamBase == null ? false : m_streamBase.CanRead; }
} }
@@ -681,8 +619,7 @@ namespace Velopack.Compression
/// Gets a value indicating whether the current stream supports seeking. /// Gets a value indicating whether the current stream supports seeking.
/// </summary> /// </summary>
/// <returns><c>true</c> if the stream supports seeking; otherwise, <c>false</c>.</returns> /// <returns><c>true</c> if the stream supports seeking; otherwise, <c>false</c>.</returns>
public override bool CanSeek public override bool CanSeek {
{
get { return m_streamBase == null ? false : m_streamBase.CanSeek; } get { return m_streamBase == null ? false : m_streamBase.CanSeek; }
} }
@@ -690,24 +627,21 @@ namespace Velopack.Compression
/// Gets a value indicating whether the current stream supports writing. /// Gets a value indicating whether the current stream supports writing.
/// </summary> /// </summary>
/// <returns><c>true</c> if the stream supports writing; otherwise, <c>false</c>.</returns> /// <returns><c>true</c> if the stream supports writing; otherwise, <c>false</c>.</returns>
public override bool CanWrite public override bool CanWrite {
{
get { return m_streamBase == null ? false : m_streamBase.CanWrite; } get { return m_streamBase == null ? false : m_streamBase.CanWrite; }
} }
/// <summary> /// <summary>
/// Gets the length in bytes of the stream. /// Gets the length in bytes of the stream.
/// </summary> /// </summary>
public override long Length public override long Length {
{
get { ThrowIfDisposed(); return m_streamBase.Length; } get { ThrowIfDisposed(); return m_streamBase.Length; }
} }
/// <summary> /// <summary>
/// Gets or sets the position within the current stream. /// Gets or sets the position within the current stream.
/// </summary> /// </summary>
public override long Position public override long Position {
{
get { ThrowIfDisposed(); return m_streamBase.Position; } get { ThrowIfDisposed(); return m_streamBase.Position; }
set { ThrowIfDisposed(); m_streamBase.Position = value; } set { ThrowIfDisposed(); m_streamBase.Position = value; }
} }
@@ -821,8 +755,7 @@ namespace Velopack.Compression
/// Gets the wrapped stream. /// Gets the wrapped stream.
/// </summary> /// </summary>
/// <value>The wrapped stream.</value> /// <value>The wrapped stream.</value>
protected Stream WrappedStream protected Stream WrappedStream {
{
get { return m_streamBase; } get { return m_streamBase; }
} }
@@ -832,18 +765,14 @@ namespace Velopack.Compression
/// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param> /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
try try {
{
// doesn't close the base stream, but just prevents access to it through this WrappingStream // doesn't close the base stream, but just prevents access to it through this WrappingStream
if (disposing) if (disposing) {
{
if (m_streamBase != null && m_ownership == Ownership.Owns) if (m_streamBase != null && m_ownership == Ownership.Owns)
m_streamBase.Dispose(); m_streamBase.Dispose();
m_streamBase = null; m_streamBase = null;
} }
} } finally {
finally
{
base.Dispose(disposing); base.Dispose(disposing);
} }
} }
@@ -916,8 +845,7 @@ namespace Velopack.Compression
if (count < 0 || buffer.Length - offset < count) if (count < 0 || buffer.Length - offset < count)
throw new ArgumentOutOfRangeException("count"); throw new ArgumentOutOfRangeException("count");
while (count > 0) while (count > 0) {
{
// read data // read data
int bytesRead = stream.Read(buffer, offset, count); int bytesRead = stream.Read(buffer, offset, count);

View File

@@ -7,7 +7,6 @@ using System.Linq;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Velopack.Locators;
// https://dev.to/emrahsungu/how-to-compare-two-files-using-net-really-really-fast-2pd9 // https://dev.to/emrahsungu/how-to-compare-two-files-using-net-really-really-fast-2pd9
// https://github.com/SnowflakePowered/vcdiff // https://github.com/SnowflakePowered/vcdiff

View File

@@ -4,7 +4,6 @@ using System.Diagnostics;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace Velopack namespace Velopack

View File

@@ -10,7 +10,6 @@ using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Velopack.NuGet;
namespace Velopack namespace Velopack
{ {

View File

@@ -1,9 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using NuGet.Versioning; using NuGet.Versioning;

View File

@@ -1,6 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;

View File

@@ -1,7 +1,6 @@
using System; using System;
using System.IO; using System.IO;
using System.Runtime.Versioning; using System.Runtime.Versioning;
using System.Text.RegularExpressions;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using NuGet.Versioning; using NuGet.Versioning;
using Velopack.NuGet; using Velopack.NuGet;

View File

@@ -4,10 +4,6 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.IO.Compression; using System.IO.Compression;
using System.Linq; using System.Linq;
using System.Runtime.Versioning;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
namespace Velopack.NuGet namespace Velopack.NuGet
{ {

View File

@@ -1,8 +1,5 @@
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
using System; using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace Velopack.NuGet namespace Velopack.NuGet
{ {

View File

@@ -9,7 +9,6 @@ using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using NuGet.Versioning; using NuGet.Versioning;
using Velopack.NuGet;
namespace Velopack namespace Velopack
{ {
@@ -185,7 +184,7 @@ namespace Velopack
if (filename.IndexOfAny(new[] { '\"', '/', '\\', '<', '>', '|', '\0' }) > -1) { if (filename.IndexOfAny(new[] { '\"', '/', '\\', '<', '>', '|', '\0' }) > -1) {
throw new Exception("Filename can either be an absolute HTTP[s] URL, *or* a file name"); throw new Exception("Filename can either be an absolute HTTP[s] URL, *or* a file name");
} }
long size = Int64.Parse(m.Groups[3].Value); long size = Int64.Parse(m.Groups[3].Value);
return new ReleaseEntry(m.Groups[1].Value, filename, size, baseUrl, query, stagingPercentage); return new ReleaseEntry(m.Groups[1].Value, filename, size, baseUrl, query, stagingPercentage);
} }

View File

@@ -1,5 +1,4 @@
using System; using System;
using System.CodeDom;
using System.IO; using System.IO;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using NuGet.Versioning; using NuGet.Versioning;

View File

@@ -1,9 +1,4 @@
using System; namespace Velopack
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
namespace Velopack
{ {
/// <summary> /// <summary>
/// Holds information about the current version and pending updates, such as how many there are, and access to release notes. /// Holds information about the current version and pending updates, such as how many there are, and access to release notes.

View File

@@ -1,10 +1,7 @@
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.Versioning; using System.Runtime.Versioning;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Logging.Abstractions;
using NuGet.Versioning; using NuGet.Versioning;

View File

@@ -5,7 +5,6 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.Versioning; using System.Runtime.Versioning;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Win32; using Microsoft.Win32;

View File

@@ -1,8 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.Versioning;
using NuGet.Versioning;
namespace Velopack.Windows namespace Velopack.Windows
{ {

View File

@@ -3,7 +3,6 @@ using System.Diagnostics;
using System.IO; using System.IO;
using System.Reflection; using System.Reflection;
using Squirrel; using Squirrel;
using Squirrel.SimpleSplat;
[assembly: AssemblyMetadata("SquirrelAwareVersion", "1")] [assembly: AssemblyMetadata("SquirrelAwareVersion", "1")]

View File

@@ -1,8 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LegacyTestApp namespace LegacyTestApp
{ {

View File

@@ -1,6 +1,5 @@
#pragma warning disable CA1416 // Validate platform compatibility #pragma warning disable CA1416 // Validate platform compatibility
using System.Diagnostics; using System.Diagnostics;
using System.Reflection.Metadata;
using Velopack; using Velopack;
using Velopack.Locators; using Velopack.Locators;

View File

@@ -1,5 +1,4 @@
using System.Threading; using Xunit.Sdk;
using Xunit.Sdk;
namespace Velopack.CommandLine.Tests; namespace Velopack.CommandLine.Tests;

View File

@@ -1,8 +1,4 @@
using System.IO; using Xunit.Sdk;
using System.Reflection;
using Velopack.Packaging;
using Xunit.Abstractions;
using Xunit.Sdk;
[assembly: TestFramework("Velopack.Packaging.Tests.TestsInit", "Velopack.Packaging.Tests")] [assembly: TestFramework("Velopack.Packaging.Tests.TestsInit", "Velopack.Packaging.Tests")]

View File

@@ -1,7 +1,6 @@
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Xunit;
[assembly: ComVisible(false)] [assembly: ComVisible(false)]
[assembly: CollectionBehavior(MaxParallelThreads=1, DisableTestParallelization=true)] [assembly: CollectionBehavior(MaxParallelThreads = 1, DisableTestParallelization = true)]
[assembly: AssemblyMetadata("SquirrelAwareVersion", "1")] [assembly: AssemblyMetadata("SquirrelAwareVersion", "1")]

View File

@@ -1,17 +1,11 @@
 using System.Diagnostics;
using System;
using System.Data.Common;
using System.Diagnostics;
using System.Globalization; using System.Globalization;
using System.IO;
using System.Runtime.Versioning; using System.Runtime.Versioning;
using System.Text; using System.Text;
using System.Xml.Linq; using System.Xml.Linq;
using Microsoft.Extensions.Logging;
using Microsoft.Win32; using Microsoft.Win32;
using NuGet.Packaging; using NuGet.Packaging;
using Velopack.Compression; using Velopack.Compression;
using Velopack.Packaging;
using Velopack.Packaging.Commands; using Velopack.Packaging.Commands;
using Velopack.Packaging.Windows.Commands; using Velopack.Packaging.Windows.Commands;
using Velopack.Windows; using Velopack.Windows;

View File

@@ -1,13 +1,5 @@
using System; using System.Xml;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml;
using Velopack;
using Velopack.NuGet; using Velopack.NuGet;
using Velopack.Tests.TestHelpers;
using Xunit;
namespace Velopack.Tests namespace Velopack.Tests
{ {

View File

@@ -1,14 +1,6 @@
using System; using System.Diagnostics.Contracts;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using NuGet;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using System.Threading.Tasks; using System.Text.RegularExpressions;
using System.Collections.Concurrent;
namespace Velopack.Tests.OldSquirrel namespace Velopack.Tests.OldSquirrel
{ {

View File

@@ -1,9 +1,4 @@
using System; using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace Velopack.Tests.OldSquirrel namespace Velopack.Tests.OldSquirrel
{ {

View File

@@ -1,7 +1,4 @@
 using System.Globalization;
using System;
using System.ComponentModel;
using System.Globalization;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
namespace Velopack.Tests.OldSquirrel namespace Velopack.Tests.OldSquirrel

View File

@@ -1,10 +1,4 @@
using System; namespace Velopack.Tests.OldSquirrel
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Velopack.Tests.OldSquirrel
{ {
internal static class Utility internal static class Utility
{ {

View File

@@ -1,11 +1,5 @@
using System; using System.Text;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using NuGet.Versioning; using NuGet.Versioning;
using Velopack.Tests.TestHelpers;
using Xunit;
using OldReleaseEntry = Velopack.Tests.OldSquirrel.ReleaseEntry; using OldReleaseEntry = Velopack.Tests.OldSquirrel.ReleaseEntry;
using OldSemanticVersion = Velopack.Tests.OldSquirrel.SemanticVersion; using OldSemanticVersion = Velopack.Tests.OldSquirrel.SemanticVersion;

View File

@@ -1,8 +1,4 @@
using System; using Velopack.Windows;
using System.Net.Http;
using System.Threading.Tasks;
using Xunit;
using Velopack.Windows;
namespace Velopack.Tests namespace Velopack.Tests
{ {

View File

@@ -1,8 +1,5 @@
using System; using System.Collections;
using System.Collections;
using System.Globalization; using System.Globalization;
using System.IO;
using Xunit;
namespace Velopack.Tests.TestHelpers namespace Velopack.Tests.TestHelpers
{ {

View File

@@ -1,7 +1,4 @@
using System; using System.Text;
using System.IO;
using System.Text;
using System.Threading.Tasks;
namespace Velopack.Tests namespace Velopack.Tests
{ {

View File

@@ -1,8 +1,4 @@
using System; using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Velopack.Sources; using Velopack.Sources;
namespace Velopack.Tests.TestHelpers namespace Velopack.Tests.TestHelpers
@@ -47,7 +43,7 @@ namespace Velopack.Tests.TestHelpers
var rel = _releases.FirstOrDefault(r => url.EndsWith(r.OriginalFilename)); var rel = _releases.FirstOrDefault(r => url.EndsWith(r.OriginalFilename));
if (rel == null) if (rel == null)
throw new Exception("Fake release not found: " + url); throw new Exception("Fake release not found: " + url);
var filePath = PathHelper.GetFixture(rel.OriginalFilename); var filePath = PathHelper.GetFixture(rel.OriginalFilename);
if (!File.Exists(filePath)) { if (!File.Exists(filePath)) {
throw new NotSupportedException("FakeFixtureRepository doesn't have: " + rel.OriginalFilename); throw new NotSupportedException("FakeFixtureRepository doesn't have: " + rel.OriginalFilename);

View File

@@ -1,9 +1,5 @@
using System; using System.Net;
using System.IO;
using System.Net;
using System.Text; using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Velopack.Tests namespace Velopack.Tests
{ {

View File

@@ -1,10 +1,4 @@
using System; using System.Text;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using NuGet.Versioning; using NuGet.Versioning;
using Velopack.Locators; using Velopack.Locators;
using Velopack.Sources; using Velopack.Sources;
@@ -28,7 +22,7 @@ namespace Velopack.Tests
using var _1 = Utility.GetTempDirectory(out var tempPath); using var _1 = Utility.GetTempDirectory(out var tempPath);
string releasesSuffix = VelopackRuntimeInfo.IsOSX ? "-osx" : ""; string releasesSuffix = VelopackRuntimeInfo.IsOSX ? "-osx" : "";
File.WriteAllText(Path.Combine(tempPath, "RELEASES" + releasesSuffix), """ File.WriteAllText(Path.Combine(tempPath, "RELEASES" + releasesSuffix), """
3a2eadd15dd984e4559f2b4d790ec8badaeb6a39 MyCoolApp-1.1.0.nupkg 1040561 3a2eadd15dd984e4559f2b4d790ec8badaeb6a39 MyCoolApp-1.1.0.nupkg 1040561
94689fede03fed7ab59c24337673a27837f0c3ec MyCoolApp-1.0.0.nupkg 1004502 94689fede03fed7ab59c24337673a27837f0c3ec MyCoolApp-1.0.0.nupkg 1004502

View File

@@ -1,17 +1,8 @@
using System; using System.Diagnostics;
using System.Diagnostics; using System.Runtime.Versioning;
using System.IO;
using System.Linq;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text; using System.Text;
using Velopack;
using Velopack.Tests.TestHelpers;
using Xunit;
using Velopack.Windows; using Velopack.Windows;
using System.Collections.Generic;
using Xunit.Abstractions;
using System.Threading.Tasks;
using System.Runtime.Versioning;
namespace Velopack.Tests namespace Velopack.Tests
{ {
@@ -30,7 +21,7 @@ namespace Velopack.Tests
[InlineData("/file", "\\file")] [InlineData("/file", "\\file")]
[InlineData("/file/", "\\file")] [InlineData("/file/", "\\file")]
[InlineData("one\\two\\..\\file", "one\\file")] [InlineData("one\\two\\..\\file", "one\\file")]
[InlineData("C:/AnApp/file/", "C:\\AnApp\\file")] [InlineData("C:/AnApp/file/", "C:\\AnApp\\file")]
public void PathIsNormalized(string input, string expected) public void PathIsNormalized(string input, string expected)
{ {
Skip.IfNot(VelopackRuntimeInfo.IsWindows); Skip.IfNot(VelopackRuntimeInfo.IsWindows);

View File

@@ -1,14 +1,7 @@
using System; using System.IO.Packaging;
using System.Collections.Generic;
using System.IO;
using System.IO.Packaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NuGet.Versioning; using NuGet.Versioning;
using Velopack.NuGet; using Velopack.NuGet;
using Velopack.Tests.TestHelpers; using Velopack.Tests.TestHelpers;
using Xunit;
using ZipPackage = Velopack.NuGet.ZipPackage; using ZipPackage = Velopack.NuGet.ZipPackage;
namespace Velopack.Tests namespace Velopack.Tests