Skip to content
This repository was archived by the owner on Jan 8, 2022. It is now read-only.

Commit 4277f47

Browse files
committed
Fixation de la vida
1 parent b735dab commit 4277f47

File tree

15 files changed

+169
-82
lines changed

15 files changed

+169
-82
lines changed

Source/Deployer.Raspberry/RaspberryPathBuilder.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public async Task<string> Replace(string str)
2222
IDictionary<string, Func<Task<string>>> mappings = new Dictionary<string, Func<Task<string>>>()
2323
{
2424
{ "WindowsARM", async () => (await deviceProviderDevice.GetWindowsVolume()).RootDir.Name},
25+
{ "BOOT", async () => (await deviceProviderDevice.GetBootVolume()).RootDir.Name},
2526
};
2627

2728
var matching = mappings.Keys.FirstOrDefault(s => str.StartsWith(s, StringComparison.OrdinalIgnoreCase));

Source/Deployer.Raspberry/RaspberryPi.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public override Task<Disk> GetDeviceDisk()
2121

2222
public override async Task<Volume> GetBootVolume()
2323
{
24-
return await GetVolume("BOOT");
24+
return await GetVolume("EFIESP");
2525
}
2626

2727
public override async Task RemoveExistingWindowsPartitions()
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1-
DisplayMarkdown "Core\license.md"
2-
UefiDownload
1+
UefiDownload
32
DriversDownload
3+
ZipUnpack "http://ww1.microchip.com/downloads/en//softwarelibrary/obj-lan95xx-windows/lan9500-wdf-v18.12.18.0.zip" "LAN95XX"
4+
ZipUnpack "http://ww1.microchip.com/downloads/en//softwarelibrary/obj-lan78xx-windows/lan7800-wdf-v18.12.14.0.zip" "LAN78XX"
5+
ZipUnpack "https://pi64.win/wp-content/uploads/2019/02/USB.zip" "USB"
6+
DisplayMarkdown "Downloaded\USB\license.md"
47
DeployWindows
5-
InjectDrivers "Downloaded\Drivers"
8+
CopyDirectoryToBoot "Downloaded\UEFI\RELEASE" ""
9+
InjectDrivers "Downloaded\Drivers"
10+
InjectDrivers "Downloaded\LAN95XX\ndis650\arm64"
11+
InjectDrivers "Downloaded\LAN78XX\ndis650\arm64"
12+
InjectDrivers "Downloaded\USB"
Lines changed: 15 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Globalization;
1+
using System.Collections.Generic;
42
using System.IO;
53
using System.IO.Compression;
64
using System.Linq;
@@ -9,27 +7,35 @@
97

108
namespace Deployer.Raspberry.Tasks
119
{
10+
[TaskDescription("Downloading Main Driver Package")]
1211
public class DriversDownload : IDeploymentTask
1312
{
1413
private readonly IGitHubDownloader downloader;
15-
private readonly IFileSystemOperations operations;
14+
private readonly IFileSystemOperations fileSystemOperations;
15+
private const string DownloadFolder = @"Downloaded\Drivers";
1616

17-
public DriversDownload(IGitHubDownloader downloader, IFileSystemOperations operations)
17+
public DriversDownload(IGitHubDownloader downloader, IFileSystemOperations fileSystemOperations)
1818
{
1919
this.downloader = downloader;
20-
this.operations = operations;
20+
this.fileSystemOperations = fileSystemOperations;
2121
}
2222

2323
public async Task Execute()
2424
{
25+
if (fileSystemOperations.DirectoryExists("Drivers"))
26+
{
27+
return;
28+
}
29+
2530
using (var stream = await downloader.OpenZipStream("https://github.com/andreiw/RaspberryPiPkg"))
2631
{
2732
var zipArchive = new ZipArchive(stream, ZipArchiveMode.Read);
2833

2934
var root = zipArchive.Entries.First(x => x.FullName.EndsWith("Drivers/"));
3035

3136
var contents = zipArchive.Entries.Where(x => x.FullName.StartsWith(root.FullName) && !x.FullName.EndsWith("/"));
32-
await ExtractContents(@"Downloaded\Drivers", root, contents);
37+
38+
await ExtractContents(DownloadFolder, root, contents);
3339
}
3440
}
3541

@@ -42,9 +48,9 @@ private async Task ExtractContents(string destination, ZipArchiveEntry baseEntry
4248

4349
var destFile = Path.Combine(destination, filePath.Replace("/", "\\"));
4450
var dir = Path.GetDirectoryName(destFile);
45-
if (!operations.DirectoryExists(dir))
51+
if (!fileSystemOperations.DirectoryExists(dir))
4652
{
47-
operations.CreateDirectory(dir);
53+
fileSystemOperations.CreateDirectory(dir);
4854
}
4955

5056
using (var destStream = File.Open(destFile, FileMode.OpenOrCreate))
@@ -54,46 +60,5 @@ private async Task ExtractContents(string destination, ZipArchiveEntry baseEntry
5460
}
5561
}
5662
}
57-
58-
private ZipArchiveEntry GetMostRecentDirEntry(ZipArchive p)
59-
{
60-
var dirs = from e in p.Entries
61-
where e.FullName.EndsWith("/")
62-
select e;
63-
64-
var splitted = from e in dirs
65-
select new
66-
{
67-
e,
68-
Parts = e.FullName.Split('/'),
69-
};
70-
71-
var parsed = from r in splitted
72-
select new
73-
{
74-
r.e,
75-
Date = FirstParseableOrNull(r.Parts),
76-
};
77-
78-
return parsed.OrderByDescending(x => x.Date).First().e;
79-
}
80-
81-
private DateTime? FirstParseableOrNull(string[] parts)
82-
{
83-
foreach (var part in parts)
84-
{
85-
var candidate = part.Split('-');
86-
if (candidate.Length > 1)
87-
{
88-
var datePart = candidate[0];
89-
if (DateTime.TryParseExact(datePart, "yyyyMMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None, out var date))
90-
{
91-
return date;
92-
}
93-
}
94-
}
95-
96-
return null;
97-
}
9863
}
9964
}

Source/Deployer.Raspberry/Tasks/UefiDownload.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,34 @@
99

1010
namespace Deployer.Raspberry.Tasks
1111
{
12+
[TaskDescription("Downloading UEFI")]
1213
public class UefiDownload : IDeploymentTask
1314
{
1415
private readonly IGitHubDownloader downloader;
15-
private readonly IFileSystemOperations operations;
16+
private readonly IFileSystemOperations fileSystemOperations;
17+
private const string DownloadFolder = @"Downloaded\UEFI";
1618

17-
public UefiDownload(IGitHubDownloader downloader, IFileSystemOperations operations)
19+
public UefiDownload(IGitHubDownloader downloader, IFileSystemOperations fileSystemOperations)
1820
{
1921
this.downloader = downloader;
20-
this.operations = operations;
22+
this.fileSystemOperations = fileSystemOperations;
2123
}
2224

2325
public async Task Execute()
2426
{
27+
if (fileSystemOperations.DirectoryExists(DownloadFolder))
28+
{
29+
return;
30+
}
31+
2532
using (var stream = await downloader.OpenZipStream("https://github.com/andreiw/RaspberryPiPkg"))
2633
{
2734
var zipArchive = new ZipArchive(stream, ZipArchiveMode.Read);
2835

2936
var mostRecentFolderEntry = GetMostRecentDirEntry(zipArchive);
3037

3138
var contents = zipArchive.Entries.Where(x => x.FullName.StartsWith(mostRecentFolderEntry.FullName) && !x.FullName.EndsWith("/"));
32-
await ExtractContents(@"Downloaded\UEFI", mostRecentFolderEntry, contents);
39+
await ExtractContents(DownloadFolder, mostRecentFolderEntry, contents);
3340
}
3441
}
3542

@@ -42,9 +49,9 @@ private async Task ExtractContents(string destination, ZipArchiveEntry baseEntry
4249

4350
var destFile = Path.Combine(destination, filePath.Replace("/", "\\"));
4451
var dir = Path.GetDirectoryName(destFile);
45-
if (!operations.DirectoryExists(dir))
52+
if (!fileSystemOperations.DirectoryExists(dir))
4653
{
47-
operations.CreateDirectory(dir);
54+
fileSystemOperations.CreateDirectory(dir);
4855
}
4956

5057
using (var destStream = File.Open(destFile, FileMode.OpenOrCreate))

Source/Deployer/Execution/Tokenizer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static Tokenizer<LangToken> Create()
2222

2323
public static readonly TextParser<TextSpan> QuotedTextParser =
2424
from leading in Span.EqualToIgnoreCase("\"")
25-
from str in Span.Regex(@"(?:(?!\"").)*")
25+
from str in Span.Regex(@"(?:(?!\"").)*").OptionalOrDefault()
2626
from trailing in Span.EqualToIgnoreCase("\"")
2727
select str;
2828
}

Source/Deployer/Tasks/AzureDevOpsUnpack.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public async Task Execute()
5555
using (var httpClient = new HttpClient())
5656
{
5757
var stream = await httpClient.GetStreamAsync(artifact.Resource.DownloadUrl);
58-
await extractor.ExtractToFolder(stream, folderPath);
58+
await extractor.ExtractFirstChildToFolder(stream, folderPath);
5959
}
6060
}
6161
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System.IO;
2+
using System.Threading.Tasks;
3+
using Deployer.Execution;
4+
using Deployer.FileSystem;
5+
6+
namespace Deployer.Tasks
7+
{
8+
[TaskDescription("Copying directory to BOOT: {0} to {1}")]
9+
public class CopyDirectoryToBoot : IDeploymentTask
10+
{
11+
private readonly string origin;
12+
private readonly string destination;
13+
private readonly IFileSystemOperations fileSystemOperations;
14+
private readonly IDeviceProvider deviceProvider;
15+
16+
public CopyDirectoryToBoot(string origin, string destination, IFileSystemOperations fileSystemOperations, IDeviceProvider deviceProvider)
17+
{
18+
this.origin = origin;
19+
this.destination = destination;
20+
this.fileSystemOperations = fileSystemOperations;
21+
this.deviceProvider = deviceProvider;
22+
}
23+
24+
public async Task Execute()
25+
{
26+
var device = deviceProvider.Device;
27+
28+
var disk = await device.GetDeviceDisk();
29+
var espPart = await disk.GetBootEfiEspPartition();
30+
if (espPart != null)
31+
{
32+
await espPart.SetGptType(PartitionType.Basic);
33+
}
34+
35+
var bootVol = await device.GetBootVolume();
36+
37+
var finalPath = Path.Combine(bootVol.RootDir.Name, destination);
38+
await fileSystemOperations.CopyDirectory(origin, finalPath);
39+
40+
await bootVol.Partition.SetGptType(PartitionType.Esp);
41+
}
42+
}
43+
}

Source/Deployer/Tasks/CopyToBoot.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,28 @@ public class CopyToBoot : IDeploymentTask
1111
private readonly string origin;
1212
private readonly string destination;
1313
private readonly IFileSystemOperations fileSystemOperations;
14-
private readonly IDevice phone;
14+
private readonly IDeviceProvider deviceProvider;
1515

16-
public CopyToBoot(string origin, string destination, IFileSystemOperations fileSystemOperations, IDevice phone)
16+
public CopyToBoot(string origin, string destination, IFileSystemOperations fileSystemOperations, IDeviceProvider deviceProvider)
1717
{
1818
this.origin = origin;
1919
this.destination = destination;
2020
this.fileSystemOperations = fileSystemOperations;
21-
this.phone = phone;
21+
this.deviceProvider = deviceProvider;
2222
}
2323

2424
public async Task Execute()
2525
{
26-
var disk = await phone.GetDeviceDisk();
26+
var device = deviceProvider.Device;
27+
28+
var disk = await device.GetDeviceDisk();
2729
var espPart = await disk.GetBootEfiEspPartition();
2830
if (espPart != null)
2931
{
3032
await espPart.SetGptType(PartitionType.Basic);
3133
}
3234

33-
var bootVol = await phone.GetBootVolume();
35+
var bootVol = await device.GetBootVolume();
3436

3537
var finalPath = Path.Combine(bootVol.RootDir.Name, destination);
3638
await fileSystemOperations.Copy(origin, finalPath);

Source/Deployer/Tasks/GitHubUnpack.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public async Task Execute()
4646
var openZipStream = await downloader.OpenZipStream(downloadUrl);
4747
using (var stream = openZipStream)
4848
{
49-
await extractor.ExtractToFolder(stream, folderPath);
49+
await extractor.ExtractFirstChildToFolder(stream, folderPath);
5050
}
5151
}
5252
}

0 commit comments

Comments
 (0)