Skip to content

Commit

Permalink
Добавление поддержки разных архитектур
Browse files Browse the repository at this point in the history
  • Loading branch information
MaKrotos committed Jan 15, 2024
1 parent 3babeae commit 9b5eabd
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 5 deletions.
108 changes: 106 additions & 2 deletions SetupLib/AppUpdater.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
using System.Security.Principal;

Expand Down Expand Up @@ -46,9 +47,24 @@ public async Task<bool> CheckForUpdates()
Console.WriteLine("Версия вашего приложения не ниже, чем последняя версия.");
return false;
}
string architecture;
if (Environment.Is64BitOperatingSystem)
{
architecture = "x64";
}
else if (RuntimeInformation.ProcessArchitecture == Architecture.Arm64)
{
architecture = "ARM64";
}
else
{
architecture = "x86";
}

var msixAsset = release.Assets.FirstOrDefault(asset => asset.Name.EndsWith(".msixbundle"))
?? release.Assets.FirstOrDefault(asset => asset.Name.EndsWith(".msix")) ?? null;
?? release.Assets.FirstOrDefault(asset => asset.Name.Contains(architecture) && asset.Name.EndsWith(".msix")) ?? null;



if (msixAsset != null)
{
Expand Down Expand Up @@ -103,6 +119,8 @@ public async Task DownloadAndOpenFile()

if (isElevated)
{


// Сначала скачиваем и устанавливаем сертификат
using (var response = await httpClient.GetAsync(UriDownload, HttpCompletionOption.ResponseHeadersRead))
using (var streamToReadFrom = await response.Content.ReadAsStreamAsync())
Expand Down Expand Up @@ -158,8 +176,66 @@ public async Task DownloadAndOpenFile()
}
}

// Затем скачиваем файл .msix
if (!IsAppInstalled("WindowsAppRuntime"))
{
// Затем скачиваем файл .msix
using (var response = await httpClient.GetAsync(GetOSArchitectureURI()))
using (var streamToReadFrom = await response.Content.ReadAsStreamAsync())
{
var path = Path.Combine(Path.GetTempPath(), Path.GetFileName(UriDownloadMSIX));
using (var streamToWriteTo = File.Create(path))
{
var totalRead = 0L;
var buffer = new byte[8192];
var isMoreToRead = true;

do
{
var read = await streamToReadFrom.ReadAsync(buffer, 0, buffer.Length);
if (read == 0)
{
isMoreToRead = false;
}
else
{
await streamToWriteTo.WriteAsync(buffer, 0, read);

totalRead += read;
var percentage = totalRead * 100d / response.Content.Headers.ContentLength.Value;

// Вызовите событие
DownloadProgressChanged?.Invoke(this, new DownloadProgressChangedEventArgs
{
TotalBytes = response.Content.Headers.ContentLength.Value,
BytesDownloaded = totalRead,
Percentage = percentage
});
}
} while (isMoreToRead);
}




string command = $"Add-AppxPackage -Path {path}";
ProcessStartInfo startInfo = new ProcessStartInfo()
{
FileName = "powershell.exe",
Arguments = $"-Command \"{command}\"",
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true,
};
Process process = new Process() { StartInfo = startInfo };
process.Start();
string output = process.StandardOutput.ReadToEnd();
process.WaitForExit();

}
}


// Затем скачиваем файл .msix
using (var response = await httpClient.GetAsync(UriDownloadMSIX))
using (var streamToReadFrom = await response.Content.ReadAsStreamAsync())
{
Expand Down Expand Up @@ -239,6 +315,9 @@ public async Task DownloadAndOpenFile()
}
}




static bool IsAppInstalled(string appName)
{
string command = $"if ((Get-AppxPackage).Name -like '*{appName}*') {{ Write-Output \"True\" }} else {{ Write-Output \"False\" }}";
Expand All @@ -257,6 +336,31 @@ static bool IsAppInstalled(string appName)
return output.Contains("True");
}

public static Uri GetOSArchitectureURI()
{
if (RuntimeInformation.ProcessArchitecture == Architecture.Arm64)
{
return new Uri("https://github.com/MaKrotos/VKUI3/releases/download/0.1.0.0/Microsoft.WindowsAppRuntimeARM.1.4.msix");
}

else if (RuntimeInformation.ProcessArchitecture == Architecture.X64)
{
return new Uri("https://github.com/MaKrotos/VKUI3/releases/download/0.1.0.0/Microsoft.WindowsAppRuntimeX64.1.4.msix");
}
else if (RuntimeInformation.ProcessArchitecture == System.Runtime.InteropServices.Architecture.X86)
{
return new Uri("https://github.com/MaKrotos/VKUI3/releases/download/0.1.0.0/Microsoft.WindowsAppRuntimeX86.1.4.msix");
}
else
{
throw new Exception("Неизвестная архитектура");
}
}







}
Expand Down
2 changes: 1 addition & 1 deletion VK UI3/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Identity
Name="FDW.VKM"
Publisher="CN=FDW"
Version="0.1.4.3" />
Version="0.1.4.4" />

<mp:PhoneIdentity PhoneProductId="f1cec595-5648-4d9e-bef5-71ee6b866717" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>

Expand Down
10 changes: 8 additions & 2 deletions VK UI3/VK UI3.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<AppxAutoIncrementPackageRevision>False</AppxAutoIncrementPackageRevision>
<AppxSymbolPackageEnabled>False</AppxSymbolPackageEnabled>
<GenerateTestArtifacts>False</GenerateTestArtifacts>
<AppxBundle>Always</AppxBundle>
<AppxBundle>Never</AppxBundle>
<UseRidGraph>true</UseRidGraph>
<HoursBetweenUpdateChecks>0</HoursBetweenUpdateChecks>
<AppInstallerUri>https://drive.usercontent.google.com/download%3fid=1QcpZrSBN1zjcYvyljUfbdGe_fiikw7G7&amp;export=download&amp;confirm=t&amp;uuid=c2870269-7a32-4320-ab9b-10e02f9b8def</AppInstallerUri>
Expand All @@ -30,6 +30,12 @@
<NoWin32Manifest>true</NoWin32Manifest>
<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
</PropertyGroup>
<ItemGroup>
<Compile Remove="VKs\Friends\**" />
<EmbeddedResource Remove="VKs\Friends\**" />
<None Remove="VKs\Friends\**" />
<Page Remove="VKs\Friends\**" />
</ItemGroup>
<ItemGroup>
<None Remove="Certificate.cer" />
<None Remove="Controllers\ChooseLoginWayControl.xaml" />
Expand Down Expand Up @@ -144,6 +150,6 @@
<CustomAdditionalCompileInputs Remove="Views\LoginWindow\waitPage.xaml" />
</ItemGroup>
<ItemGroup>
<Folder Include="VKs\Friends\" />
<PRIResource Remove="VKs\Friends\**" />
</ItemGroup>
</Project>

0 comments on commit 9b5eabd

Please sign in to comment.