Skip to content

Commit

Permalink
Add --single-file option to app cast generator
Browse files Browse the repository at this point in the history
  • Loading branch information
Deadpikle committed Sep 22, 2024
1 parent b714a94 commit 9bf29e0
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ _Missing some option you'd like to see? File an issue on this repo or add it you
* `-e`/`--ext`: When looking for files to add to the app cast, use the given extension(s) when looking for files. Defaults to `exe`. Example use: `-e exe,msi`
* `-b`/`--binaries`: File path to directory that should be searched through when looking for files to add to the app cast. Defaults to `.`. Example use: `-b my/build/directory`
* `-r`/`--search-binary-subdirectories`: True to search the binary directory recursively for binaries; false to only search the top directory. Defaults to `false`. Example use: `-r`.
* `--single-file`: Single file to add to app cast - if set, `--binaries`, `--ext`, etc. are all ignored. Helpful to use if your output file has no extension (e.g. is a unix executable). Example use: `--single-file path/to/my/file`
* `-f`/`--file-extract-version`: Whether or not to extract the version of the file from the file's name rather than the file (e.g. dll) itself. Defaults to `false`. Use when your files that will be downloaded by NetSparkleUpdater will have the version number in the file name, e.g. "My App 1.3.2-alpha1.exe". Note that this only searches the last four directory items/folders. Example use: `-f true`
* `--file-version`: Use to set the version for a binary going into an app cast. Note that this version can only be set once, so when generating an app cast, make sure you either: A) have only one binary in your app cast | B) Utilize the `--reparse-existing` parameter so that old items get picked up. If the generator finds 2 binaries without any known version and `--file-version` is set, then an error will be emitted. Example use: `--file-version 1.3.2`
* `-o`/`--os`: Operating system that the app cast items belong to. String must include one of the following: `windows`, `mac`, `linux`. Defaults to `windows`. Example use: `-o macos-arm64`; `-o windows-x64`
Expand Down
39 changes: 32 additions & 7 deletions src/NetSparkle.Tools.AppCastGenerator/AppCastMaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -442,15 +442,33 @@ public string GetPathToAppCastOutput(string desiredOutputDirectory, string sourc
/// </summary>
/// <param name="sourceBinaryDirectory"></param>
/// <returns>items, product name</returns>
public (List<AppCastItem>?, string?) LoadAppCastItemsAndProductName(string sourceBinaryDirectory, bool useExistingAppCastItems, string outputAppCastFileName)
public (List<AppCastItem>?, string?) LoadAppCastItemsAndProductName(string sourceBinaryDirectory, bool useExistingAppCastItems, string outputAppCastFileName, string singleFileToAddToAppCast)
{
var items = new List<AppCastItem>();
var dirFileSearches = GetSearchExtensionsFromString(_opts.Extensions ?? "");
var binaries = FindBinaries(sourceBinaryDirectory, dirFileSearches, _opts.SearchBinarySubDirectories);
if (!binaries.Any())

var binaries = new List<string>();
if (string.IsNullOrWhiteSpace(singleFileToAddToAppCast))
{
Console.WriteLine($"No files founds matching extensions -- {string.Join(",", dirFileSearches)} -- in {sourceBinaryDirectory}", Color.Yellow);
return (null, null);
binaries = FindBinaries(sourceBinaryDirectory, dirFileSearches, _opts.SearchBinarySubDirectories).ToList();
if (!binaries.Any())
{
Console.WriteLine($"No files founds matching extensions -- {string.Join(",", dirFileSearches)} -- in {sourceBinaryDirectory}", Color.Yellow);
return (null, null);
}
}
else
{
if (File.Exists(singleFileToAddToAppCast))
{
Console.WriteLine($"Using single file at path {singleFileToAddToAppCast}");
binaries.Add(singleFileToAddToAppCast);
}
else
{
Console.WriteLine($"No file found at path {singleFileToAddToAppCast}", Color.Yellow);
return (null, null);
}
}

if (_opts.OperatingSystem != null && !string.IsNullOrWhiteSpace(_opts.OperatingSystem) &&
Expand All @@ -463,8 +481,15 @@ public string GetPathToAppCastOutput(string desiredOutputDirectory, string sourc

Console.WriteLine();
Console.WriteLine($"Operating System: {_opts.OperatingSystem}", Color.LightBlue);
Console.WriteLine($"Searching: {sourceBinaryDirectory}", Color.LightBlue);
Console.WriteLine($"Found {binaries.Count()} {string.Join(",", dirFileSearches)} files(s)", Color.LightBlue);
if (string.IsNullOrWhiteSpace(singleFileToAddToAppCast))
{
Console.WriteLine($"Searching: {sourceBinaryDirectory}", Color.LightBlue);
Console.WriteLine($"Found {binaries.Count()} {string.Join(",", dirFileSearches)} files(s)", Color.LightBlue);
}
else
{
Console.WriteLine($"Found {binaries.Count()} file at {singleFileToAddToAppCast}", Color.LightBlue);
}
Console.WriteLine();

try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@
</PropertyGroup>
<PropertyGroup>
<PostBuildEvent />
<AssemblyVersion>2.7.1.0</AssemblyVersion>
<FileVersion>2.7.1.0</FileVersion>
<AssemblyVersion>2.8.0.0</AssemblyVersion>
<FileVersion>2.8.0.0</FileVersion>
<PackageId>NetSparkleUpdater.Tools.AppCastGenerator</PackageId>
<Version>2.7.1</Version>
<Version>2.8.0</Version>
<Authors>Deadpikle</Authors>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand Down
3 changes: 3 additions & 0 deletions src/NetSparkle.Tools.AppCastGenerator/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public class Options
[Option('r', "search-binary-subdirectories", SetName = "local", Required = false, HelpText = "Search subdirectories of --binaries for binaries", Default = false)]
public bool SearchBinarySubDirectories { get; set; }

[Option("single-file", SetName = "local", Required = false, HelpText = "Single file to add to app cast - if set, --binaries, --ext, etc. are all ignored", Default = null)]
public string? FileToAddToAppCast { get; set; }

[Option('f', "file-extract-version", SetName = "local", Required = false, HelpText = "Determine the version from the file path. Tries each string in between directory separators that contains a version number starting from the end of the path. Only searches the last four directory items (incl. the file name) and does not search 'above' the binary directory (-b option). See unit tests for what is parseable.", Default = false)]
public bool FileExtractVersion { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion src/NetSparkle.Tools.AppCastGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ static void Run(Options opts)
Console.WriteLine("Creating {0}", outputDirName);
Directory.CreateDirectory(outputDirName);
}
var (items, productName) = generator.LoadAppCastItemsAndProductName(opts.SourceBinaryDirectory ?? ".", opts.ReparseExistingAppCast, appCastFileName);
var (items, productName) = generator.LoadAppCastItemsAndProductName(opts.SourceBinaryDirectory ?? ".", opts.ReparseExistingAppCast, appCastFileName, opts.FileToAddToAppCast ?? "");
if (items != null)
{
generator.SerializeItemsToFile(items, productName ?? "", appCastFileName);
Expand Down

0 comments on commit 9bf29e0

Please sign in to comment.