Ionite
1 year ago
15 changed files with 580 additions and 26 deletions
Binary file not shown.
@ -0,0 +1,88 @@
|
||||
7-Zip |
||||
~~~~~ |
||||
License for use and distribution |
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
||||
|
||||
7-Zip Copyright (C) 1999-2023 Igor Pavlov. |
||||
|
||||
The licenses for 7zz and 7zzs files are: |
||||
|
||||
- The "GNU LGPL" as main license for most of the code |
||||
- The "GNU LGPL" with "unRAR license restriction" for some code |
||||
- The "BSD 3-clause License" for some code |
||||
|
||||
Redistributions in binary form must reproduce related license information from this file. |
||||
|
||||
Note: |
||||
You can use 7-Zip on any computer, including a computer in a commercial |
||||
organization. You don't need to register or pay for 7-Zip. |
||||
|
||||
|
||||
GNU LGPL information |
||||
-------------------- |
||||
|
||||
This library is free software; you can redistribute it and/or |
||||
modify it under the terms of the GNU Lesser General Public |
||||
License as published by the Free Software Foundation; either |
||||
version 2.1 of the License, or (at your option) any later version. |
||||
|
||||
This library is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
Lesser General Public License for more details. |
||||
|
||||
You can receive a copy of the GNU Lesser General Public License from |
||||
http://www.gnu.org/ |
||||
|
||||
|
||||
|
||||
|
||||
BSD 3-clause License |
||||
-------------------- |
||||
|
||||
The "BSD 3-clause License" is used for the code in 7z.dll that implements LZFSE data decompression. |
||||
That code was derived from the code in the "LZFSE compression library" developed by Apple Inc, |
||||
that also uses the "BSD 3-clause License": |
||||
|
||||
---- |
||||
Copyright (c) 2015-2016, Apple Inc. All rights reserved. |
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: |
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. |
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer |
||||
in the documentation and/or other materials provided with the distribution. |
||||
|
||||
3. Neither the name of the copyright holder(s) nor the names of any contributors may be used to endorse or promote products derived |
||||
from this software without specific prior written permission. |
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
||||
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
---- |
||||
|
||||
|
||||
|
||||
|
||||
unRAR license restriction |
||||
------------------------- |
||||
|
||||
The decompression engine for RAR archives was developed using source |
||||
code of unRAR program. |
||||
All copyrights to original unRAR code are owned by Alexander Roshal. |
||||
|
||||
The license for original unRAR code has the following restriction: |
||||
|
||||
The unRAR sources cannot be used to re-create the RAR compression algorithm, |
||||
which is proprietary. Distribution of modified unRAR sources in separate form |
||||
or as a part of other software is permitted, provided that it is clearly |
||||
stated in the documentation and source comments that the code may |
||||
not be used to develop a RAR (WinRAR) compatible archiver. |
||||
|
||||
|
||||
-- |
||||
Igor Pavlov |
@ -0,0 +1,43 @@
|
||||
7-Zip Extra 18.01 |
||||
----------------- |
||||
|
||||
7-Zip Extra is package of extra modules of 7-Zip. |
||||
|
||||
7-Zip Copyright (C) 1999-2018 Igor Pavlov. |
||||
|
||||
7-Zip is free software. Read License.txt for more information about license. |
||||
|
||||
Source code of binaries can be found at: |
||||
http://www.7-zip.org/ |
||||
|
||||
|
||||
7-Zip Extra |
||||
~~~~~~~~~~~ |
||||
License for use and distribution |
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
||||
|
||||
Copyright (C) 1999-2018 Igor Pavlov. |
||||
|
||||
7-Zip Extra files are under the GNU LGPL license. |
||||
|
||||
|
||||
Notes: |
||||
You can use 7-Zip Extra on any computer, including a computer in a commercial |
||||
organization. You don't need to register or pay for 7-Zip. |
||||
|
||||
|
||||
GNU LGPL information |
||||
-------------------- |
||||
|
||||
This library is free software; you can redistribute it and/or |
||||
modify it under the terms of the GNU Lesser General Public |
||||
License as published by the Free Software Foundation; either |
||||
version 2.1 of the License, or (at your option) any later version. |
||||
|
||||
This library is distributed in the hope that it will be useful, |
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||||
Lesser General Public License for more details. |
||||
|
||||
You can receive a copy of the GNU Lesser General Public License from |
||||
http://www.gnu.org/ |
Binary file not shown.
@ -0,0 +1,155 @@
|
||||
using System; |
||||
using System.Diagnostics; |
||||
using System.IO; |
||||
using System.Runtime.Versioning; |
||||
using System.Threading.Tasks; |
||||
using Avalonia; |
||||
using Avalonia.Platform; |
||||
using NLog; |
||||
using StabilityMatrix.Core.Exceptions; |
||||
using StabilityMatrix.Core.Helper; |
||||
using StabilityMatrix.Core.Models.Progress; |
||||
using StabilityMatrix.Core.Processes; |
||||
using StabilityMatrix.Core.Services; |
||||
|
||||
namespace StabilityMatrix.Avalonia.Helpers; |
||||
|
||||
[SupportedOSPlatform("linux")] |
||||
public class UnixPrerequisiteHelper : IPrerequisiteHelper |
||||
{ |
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); |
||||
|
||||
private readonly IDownloadService downloadService; |
||||
private readonly ISettingsManager settingsManager; |
||||
|
||||
private string HomeDir => settingsManager.LibraryDir; |
||||
private string AssetsDir => Path.Combine(HomeDir, "Assets"); |
||||
|
||||
private string PythonDir => Path.Combine(AssetsDir, "Python310"); |
||||
private string PythonDllPath => Path.Combine(PythonDir, "python310.dll"); |
||||
public bool IsPythonInstalled => File.Exists(PythonDllPath); |
||||
|
||||
private string PortableGitInstallDir => Path.Combine(HomeDir, "PortableGit"); |
||||
public string GitBinPath => Path.Combine(PortableGitInstallDir, "bin"); |
||||
|
||||
|
||||
public UnixPrerequisiteHelper(IDownloadService downloadService, ISettingsManager settingsManager) |
||||
{ |
||||
this.downloadService = downloadService; |
||||
this.settingsManager = settingsManager; |
||||
} |
||||
|
||||
public async Task InstallAllIfNecessary(IProgress<ProgressReport>? progress = null) |
||||
{ |
||||
await UnpackResourcesIfNecessary(progress); |
||||
await InstallGitIfNecessary(progress); |
||||
await InstallPythonIfNecessary(progress); |
||||
} |
||||
|
||||
public async Task UnpackResourcesIfNecessary(IProgress<ProgressReport>? progress = null) |
||||
{ |
||||
// Array of (asset_uri, extract_to) |
||||
var assets = new[] |
||||
{ |
||||
(Assets.SevenZipExecutable, AssetsDir), |
||||
(Assets.SevenZipLicense, AssetsDir), |
||||
}; |
||||
|
||||
progress?.Report(new ProgressReport(0, message: "Unpacking resources", isIndeterminate: true)); |
||||
|
||||
foreach (var (assetUri, extractTo) in assets) |
||||
{ |
||||
await Assets.ExtractAsset(assetUri, extractTo); |
||||
} |
||||
|
||||
progress?.Report(new ProgressReport(1, message: "Unpacking resources", isIndeterminate: false)); |
||||
} |
||||
|
||||
public Task InstallGitIfNecessary(IProgress<ProgressReport>? progress = null) |
||||
{ |
||||
return Task.CompletedTask; |
||||
} |
||||
|
||||
public async Task RunGit(string? workingDirectory = null, params string[] args) |
||||
{ |
||||
var result = await ProcessRunner.RunBashCommand("git" + args, workingDirectory ?? ""); |
||||
if (result.ExitCode != 0) |
||||
{ |
||||
throw new ProcessException($"Git command failed with exit code {result.ExitCode}:\n" + |
||||
$"{result.StandardOutput}\n{result.StandardError}"); |
||||
} |
||||
} |
||||
|
||||
public async Task InstallPythonIfNecessary(IProgress<ProgressReport>? progress = null) |
||||
{ |
||||
if (IsPythonInstalled) return; |
||||
|
||||
Directory.CreateDirectory(AssetsDir); |
||||
|
||||
// Download |
||||
var (url, hashSha256) = Assets.PythonDownloadUrl; |
||||
var fileName = Path.GetFileName(url.LocalPath); |
||||
var downloadPath = Path.Combine(AssetsDir, fileName); |
||||
Logger.Info($"Downloading Python from {url.AbsolutePath} to {downloadPath}"); |
||||
try |
||||
{ |
||||
await downloadService.DownloadToFileAsync(url.AbsolutePath, downloadPath, progress); |
||||
|
||||
// Verify hash |
||||
var actualHash = await FileHash.GetSha256Async(downloadPath); |
||||
Logger.Info($"Verifying Python hash: (expected: {hashSha256}, actual: {actualHash})"); |
||||
if (actualHash != hashSha256) |
||||
{ |
||||
throw new Exception($"Python download hash mismatch: expected {hashSha256}, actual {actualHash}"); |
||||
} |
||||
|
||||
// Extract |
||||
Logger.Info($"Extracting Python Zip: {downloadPath} to {PythonDir}"); |
||||
Directory.Delete(PythonDir, true); |
||||
if (progress != null) |
||||
{ |
||||
await ArchiveHelper.Extract7Z(downloadPath, PythonDir, progress); |
||||
} |
||||
else |
||||
{ |
||||
await ArchiveHelper.Extract7Z(downloadPath, PythonDir); |
||||
} |
||||
|
||||
// For Linux, move the inner 'python' folder up to the root PythonDir |
||||
if (Compat.IsLinux) |
||||
{ |
||||
var innerPythonDir = Path.Combine(PythonDir, "python"); |
||||
foreach (var folder in Directory.EnumerateDirectories(innerPythonDir)) |
||||
{ |
||||
var folderName = Path.GetFileName(folder); |
||||
var dest = Path.Combine(PythonDir, folderName); |
||||
Directory.Move(folder, dest); |
||||
} |
||||
Directory.Delete(innerPythonDir); |
||||
} |
||||
} |
||||
finally |
||||
{ |
||||
// Cleanup download file |
||||
File.Delete(downloadPath); |
||||
} |
||||
} |
||||
|
||||
public Task SetupPythonDependencies(string installLocation, string requirementsFileName, |
||||
IProgress<ProgressReport>? progress = null, Action<ProcessOutput>? onConsoleOutput = null) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
public void UpdatePathExtensions() |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
|
||||
[UnsupportedOSPlatform("Linux")] |
||||
[UnsupportedOSPlatform("macOS")] |
||||
public Task InstallVcRedistIfNecessary(IProgress<ProgressReport>? progress = null) |
||||
{ |
||||
throw new PlatformNotSupportedException(); |
||||
} |
||||
} |
Loading…
Reference in new issue