Skip to content

Commit

Permalink
Updated platform (metadata)
Browse files Browse the repository at this point in the history
Check to ensure that the device is fully unlocked
Centralized "Downloaded" folder name.
  • Loading branch information
SuperJMN committed May 11, 2019
1 parent 055c5e1 commit 3b75a5d
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 19 deletions.
1 change: 0 additions & 1 deletion Source/Deployer.Lumia.Gui/Deployer.Lumia.Gui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@
</Compile>
<Compile Include="ViewModels\Locator.cs" />
<Compile Include="ViewModels\MainViewModel.cs" />
<Compile Include="ViewModels\AppPaths.cs" />
<Compile Include="Views\MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
Expand Down
4 changes: 2 additions & 2 deletions Source/Deployer.Lumia.Gui/ViewModels/AdvancedViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ private async Task Restore()

private async Task DeleteDownloaded(IFileSystemOperations fileSystemOperations)
{
if (fileSystemOperations.DirectoryExists(AppPaths.DownloadedFolderName))
if (fileSystemOperations.DirectoryExists(AppPaths.ArtifactDownload))
{
await fileSystemOperations.DeleteDirectory(AppPaths.DownloadedFolderName);
await fileSystemOperations.DeleteDirectory(AppPaths.ArtifactDownload);
await uiServices.Dialog.ShowAlert(this, Resources.Done, Resources.DownloadedFolderDeleted);
}
else
Expand Down
7 changes: 0 additions & 7 deletions Source/Deployer.Lumia.Gui/ViewModels/AppPaths.cs

This file was deleted.

4 changes: 2 additions & 2 deletions Source/Deployer.Lumia.Gui/ViewModels/DeploymentViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ private async Task CleanDownloadedIfNeeded()
return;
}

if (fileSystemOperations.DirectoryExists(AppPaths.DownloadedFolderName))
if (fileSystemOperations.DirectoryExists(AppPaths.ArtifactDownload))
{
Log.Information("Deleting previously downloaded deployment files");
await fileSystemOperations.DeleteDirectory(AppPaths.DownloadedFolderName);
await fileSystemOperations.DeleteDirectory(AppPaths.ArtifactDownload);
}
}

Expand Down
1 change: 1 addition & 0 deletions Source/Deployer.Lumia/PartitionName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ public static class PartitionName
public const string Data = "Data";
public const string Recovery = "Recovery";
public const string Dpp = "DPP";
public const string BackupEfiesp = "BACKUP_EFIESP";
}
}
44 changes: 38 additions & 6 deletions Source/Deployer.Lumia/WoaDeployer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,28 @@ namespace Deployer.Lumia
public class WoaDeployer : IWoaDeployer
{
private readonly ITooling tooling;
private readonly IPhone phone;
private readonly IDeploymentContext context;
private readonly IFileSystemOperations fileSystemOperations;
private readonly IScriptRunner scriptRunner;
private readonly IScriptParser parser;

public WoaDeployer(IScriptRunner scriptRunner, IScriptParser parser, ITooling tooling, IPhone phone,
public WoaDeployer(IScriptRunner scriptRunner, IScriptParser parser, ITooling tooling,
IDeploymentContext context,
IFileSystemOperations fileSystemOperations)
{
this.scriptRunner = scriptRunner;
this.parser = parser;
this.tooling = tooling;
this.phone = phone;
this.context = context;
this.fileSystemOperations = fileSystemOperations;
}

public IPhone Phone => (IPhone) context.Device;

public async Task Deploy()
{
await EnsureFullyUnlocked();

var dict = new Dictionary<(PhoneModel, Variant), string>
{
{(PhoneModel.Talkman, Variant.SingleSim), Path.Combine("Scripts", "Talkman", "SingleSim.txt")},
Expand All @@ -40,15 +42,45 @@ public async Task Deploy()
{(PhoneModel.Cityman, Variant.DualSim), Path.Combine("Scripts", "Cityman", "DualSim.txt")},
};

var phoneModel = await phone.GetModel();
var phoneModel = await Phone.GetModel();
Log.Verbose("{Model} detected", phoneModel);
var path = dict[(phoneModel.Model, phoneModel.Variant)];

await scriptRunner.Run(parser.Parse(File.ReadAllText(path)));
await PatchBootManagerIfNeeded();
await SaveMetadata();
await PreparePhoneDiskForSafeRemoval();
}

private async Task EnsureFullyUnlocked()
{
var backUpEfiEsp = await context.Device.GetOptionalPartition(PartitionName.BackupEfiesp);
if (backUpEfiEsp != null)
{
throw new InvalidOperationException("Your phone isn't fully unlocked! Please, return to WPInternals and complete the unlock process.");
}
}

private async Task SaveMetadata()
{
var dirInfo = new DirectoryInfo("Downloaded");
var metadatas = dirInfo.GetFiles("Info.json", SearchOption.AllDirectories);
foreach (var metadata in metadatas)
{
var windowsVolume = await context.Device.GetWindowsVolume();
if (metadata.Directory != null)
{
var name = metadata.Directory.Name;
var destination = Path.Combine(windowsVolume.Root, "Windows", "Logs", "WOA-Deployer", $"{name}.json");
await fileSystemOperations.Copy(metadata.FullName, destination);
}
else
{
Log.Debug("Cannot write metadata on the phone");
}
}
}

private async Task PatchBootManagerIfNeeded()
{
Log.Debug("Checking if we have to patch WOA's Boot Manager");
Expand All @@ -64,7 +96,7 @@ private async Task PatchBootManagerIfNeeded()
if (buildNumber == 17763)
{
Log.Verbose("Build 17763 detected. Patching Boot Manager.");
var dest = Path.Combine((await phone.GetSystemVolume()).Root, "EFI", "Boot") + Path.DirectorySeparatorChar;
var dest = Path.Combine((await Phone.GetSystemVolume()).Root, "EFI", "Boot") + Path.DirectorySeparatorChar;
await fileSystemOperations.Copy(@"Core\Boot\bootaa64.efi", dest);
Log.Verbose("Boot Manager Patched.");
}
Expand All @@ -76,7 +108,7 @@ private async Task PreparePhoneDiskForSafeRemoval()
{
Log.Information("# Preparing phone for safe removal");
Log.Information("Please wait...");
var disk = await phone.GetDeviceDisk();
var disk = await Phone.GetDeviceDisk();
await disk.Refresh();
}

Expand Down
2 changes: 1 addition & 1 deletion Source/DeployerPlatform

0 comments on commit 3b75a5d

Please sign in to comment.