Skip to content

Commit e473e17

Browse files
committed
feat: Cleanup
1 parent 5637a8c commit e473e17

File tree

8 files changed

+35
-49
lines changed

8 files changed

+35
-49
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ MigrationBackup/
381381
FodyWeavers.xsd
382382

383383
# VS Code files for those working on multiple tools
384-
.vscode/*
384+
.vscode/
385385
!.vscode/settings.json
386386
!.vscode/tasks.json
387387
!.vscode/launch.json

Nickvision.FlatpakGenerator/FlatpakSourcesGenerator.cs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,25 @@ public class FlatpakSourcesGenerator
1818
static FlatpakSourcesGenerator()
1919
{
2020
HttpClient = new HttpClient();
21-
JsonSerializerOptions = new JsonSerializerOptions()
21+
JsonSerializerOptions = new JsonSerializerOptions
2222
{
2323
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
2424
WriteIndented = true
2525
};
2626
}
27-
27+
2828
public async Task<bool> CheckRuntimeAsync(string runtime, bool runAsUser)
2929
{
30-
using var process = new Process()
30+
using var process = new Process
3131
{
32-
StartInfo = new ProcessStartInfo()
32+
StartInfo = new ProcessStartInfo
3333
{
3434
FileName = "flatpak",
3535
ArgumentList =
3636
{
3737
"list",
3838
"--runtime",
39-
"--columns=application,branch",
39+
"--columns=application,branch"
4040
},
4141
UseShellExecute = false,
4242
RedirectStandardOutput = true,
@@ -68,16 +68,12 @@ public async Task<bool> CheckRuntimeAsync(string runtime, bool runAsUser)
6868
return false;
6969
}
7070

71-
public async Task<List<NugetSource>> GenerateSourcesAsync(string input,
72-
int dotnetVersion,
73-
string? temp,
74-
bool selfContained,
75-
bool runAsUser)
71+
public async Task<List<NugetSource>> GenerateSourcesAsync(string input, int dotnetVersion, string? temp, bool selfContained, bool runAsUser)
7672
{
7773
input = input.Replace("~", Environment.GetFolderPath(Environment.SpecialFolder.UserProfile));
7874
temp = Path.Combine(temp?.Replace("~", Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)) ?? Directory.GetCurrentDirectory(), "nuget-temp");
7975
Directory.CreateDirectory(temp);
80-
if(string.IsNullOrEmpty(input) || !File.Exists(input) || Path.GetExtension(input) != ".csproj")
76+
if (string.IsNullOrEmpty(input) || !File.Exists(input) || Path.GetExtension(input) != ".csproj")
8177
{
8278
Console.Error.WriteLine("[Error] Invalid input csproj file path");
8379
return [];
@@ -90,9 +86,9 @@ public async Task<List<NugetSource>> GenerateSourcesAsync(string input,
9086
{
9187
return [];
9288
}
93-
using var process = new Process()
89+
using var process = new Process
9490
{
95-
StartInfo = new ProcessStartInfo()
91+
StartInfo = new ProcessStartInfo
9692
{
9793
FileName = "flatpak",
9894
ArgumentList =
@@ -131,7 +127,7 @@ public async Task<List<NugetSource>> GenerateSourcesAsync(string input,
131127
return [];
132128
}
133129
var sources = new List<NugetSource>();
134-
foreach(var file in Directory.GetFiles(temp, "*.nupkg.sha512", SearchOption.AllDirectories))
130+
foreach (var file in Directory.GetFiles(temp, "*.nupkg.sha512", SearchOption.AllDirectories))
135131
{
136132
using var reader = new StreamReader(file);
137133
var hash = Convert.ToHexString(Convert.FromBase64String(await reader.ReadToEndAsync())).ToLower();
@@ -151,7 +147,8 @@ public async Task<List<NugetSource>> GenerateSourcesAsync(string input,
151147
Directory.Delete(temp, true);
152148
if (selfContained)
153149
{
154-
foreach (var extra in new[]{
150+
foreach (var extra in new[]
151+
{
155152
"microsoft.aspnetcore.app.runtime.linux-arm",
156153
"microsoft.aspnetcore.app.runtime.linux-arm64",
157154
"microsoft.aspnetcore.app.runtime.linux-x64",
@@ -197,7 +194,7 @@ public async Task<List<NugetSource>> GenerateSourcesAsync(string input,
197194
}
198195
var filename = $"{name}.{latestEntry.Version}.nupkg";
199196
Console.WriteLine($"[Found] {name}");
200-
return new NugetSource()
197+
return new NugetSource
201198
{
202199
Url = $"https://api.nuget.org/v3-flatcontainer/{name}/{latestEntry.Version}/{filename}",
203200
Sha512 = Convert.ToHexString(Convert.FromBase64String(latestEntry.PackageHash)).ToLower(),
@@ -213,7 +210,7 @@ public async Task WriteSourcesFileAsync(List<NugetSource> sources, string? outpu
213210
{
214211
output = "nuget-sources.json";
215212
}
216-
else if(!string.IsNullOrEmpty(output) && Path.GetExtension(output) != ".json")
213+
else if (!string.IsNullOrEmpty(output) && Path.GetExtension(output) != ".json")
217214
{
218215
output += ".json";
219216
}

Nickvision.FlatpakGenerator/NugetCatalog.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ namespace Nickvision.FlatpakGenerator;
55

66
public class NugetCatalog
77
{
8-
[JsonPropertyName("@id")]
9-
public string Url { get; set; }
108
public int Count { get; set; }
119
[JsonPropertyName("items")]
1210
public List<NugetCatalogPage> Pages { get; set; }
11+
[JsonPropertyName("@id")]
12+
public string Url { get; set; }
1313

1414
public NugetCatalog()
1515
{

Nickvision.FlatpakGenerator/NugetCatalogEntry.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ namespace Nickvision.FlatpakGenerator;
44

55
public class NugetCatalogEntry
66
{
7+
public string PackageHash { get; set; }
8+
public string PackageHashAlgorithm { get; set; }
79
[JsonPropertyName("@id")]
810
public string Url { get; set; }
9-
public string PackageHashAlgorithm { get; set; }
10-
public string PackageHash { get; set; }
1111
public string Version { get; set; }
12-
12+
1313
public NugetCatalogEntry()
1414
{
1515
Url = string.Empty;

Nickvision.FlatpakGenerator/NugetCatalogPackage.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ namespace Nickvision.FlatpakGenerator;
44

55
public class NugetCatalogPackage
66
{
7+
public NugetCatalogEntry CatalogEntry { get; set; }
78
[JsonPropertyName("@id")]
89
public string Url { get; set; }
9-
public NugetCatalogEntry CatalogEntry { get; set; }
10-
10+
1111
public NugetCatalogPackage()
1212
{
1313
Url = string.Empty;

Nickvision.FlatpakGenerator/NugetCatalogPage.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ namespace Nickvision.FlatpakGenerator;
55

66
public class NugetCatalogPage
77
{
8-
[JsonPropertyName("@id")]
9-
public string Url { get; set; }
108
public int Count { get; set; }
119
[JsonPropertyName("items")]
1210
public List<NugetCatalogPackage> Packages { get; set; }
13-
11+
[JsonPropertyName("@id")]
12+
public string Url { get; set; }
13+
1414
public NugetCatalogPage()
1515
{
1616
Url = string.Empty;

Nickvision.FlatpakGenerator/NugetSource.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ namespace Nickvision.FlatpakGenerator;
44

55
public class NugetSource
66
{
7-
public required string Url { get; set; }
8-
public required string Sha512 { get; set; }
97
[JsonPropertyName("dest")]
108
public required string Destination { get; set; }
119
[JsonPropertyName("dest-filename")]
1210
public required string DestinationFileName { get; set; }
13-
11+
public required string Sha512 { get; set; }
12+
public required string Url { get; set; }
13+
1414
public string Type => "file";
1515
}

Nickvision.FlatpakGenerator/Program.cs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.CommandLine;
4-
using System.IO;
53
using System.Threading.Tasks;
64

75
namespace Nickvision.FlatpakGenerator;
86

97
public class Program
108
{
11-
private static FlatpakSourcesGenerator _generator;
12-
9+
private static readonly FlatpakSourcesGenerator _generator;
10+
1311
static Program()
1412
{
1513
_generator = new FlatpakSourcesGenerator();
1614
}
17-
15+
1816
public static async Task<int> Main(string[] args)
1917
{
2018
if (Environment.OSVersion.Platform != PlatformID.Unix)
@@ -105,25 +103,16 @@ public static async Task<int> Main(string[] args)
105103
};
106104
checkCommand.SetAction(async x =>
107105
{
108-
await _generator.CheckRuntimeAsync(
109-
"org.freedesktop.Sdk//24.08",
110-
x.GetValue<bool>("--run-as-user"));
111-
await _generator.CheckRuntimeAsync(
112-
$"org.freedesktop.Sdk.Extension.dotnet{x.GetRequiredValue<int>("--dotnet")}//24.08",
113-
x.GetValue<bool>("--run-as-user"));
106+
await _generator.CheckRuntimeAsync("org.freedesktop.Sdk//24.08", x.GetValue<bool>("--run-as-user"));
107+
await _generator.CheckRuntimeAsync($"org.freedesktop.Sdk.Extension.dotnet{x.GetRequiredValue<int>("--dotnet")}//24.08", x.GetValue<bool>("--run-as-user"));
114108
});
115109
generateCommand.SetAction(async x =>
116110
{
117-
var sources = await _generator.GenerateSourcesAsync(
118-
x.GetRequiredValue<string>("--input"),
119-
x.GetRequiredValue<int>("--dotnet"),
120-
x.GetValue<string>("--temp"),
121-
x.GetValue<bool>("--self-contained"),
122-
x.GetValue<bool>("--run-as-user"));
111+
var sources = await _generator.GenerateSourcesAsync(x.GetRequiredValue<string>("--input"), x.GetRequiredValue<int>("--dotnet"), x.GetValue<string>("--temp"), x.GetValue<bool>("--self-contained"), x.GetValue<bool>("--run-as-user"));
123112
await _generator.WriteSourcesFileAsync(sources, x.GetValue<string>("--output"));
124113
});
125114
rootCommand.Subcommands.Add(checkCommand);
126115
rootCommand.Subcommands.Add(generateCommand);
127116
return await rootCommand.Parse(args).InvokeAsync();
128117
}
129-
}
118+
}

0 commit comments

Comments
 (0)