diff --git a/src/Rune.csproj b/src/Rune.csproj index 6caf745..7c34747 100644 --- a/src/Rune.csproj +++ b/src/Rune.csproj @@ -7,7 +7,7 @@ Rune.CLI resource\icon.ico - 0.70.618-beta + 0.70.619-beta true x64 diff --git a/src/cmd/InstallCommand.cs b/src/cmd/InstallCommand.cs index ba8a8b6..6ab80fd 100644 --- a/src/cmd/InstallCommand.cs +++ b/src/cmd/InstallCommand.cs @@ -3,11 +3,14 @@ using System; using System.Drawing; using System.IO; + using System.IO.Compression; + using System.Linq; using System.Threading.Tasks; using Ancient.ProjectSystem; using cli; using etc; using Internal; + using MoreLinq; public class InstallCommand : RuneCommand, IWithProject { @@ -42,6 +45,11 @@ internal override CommandLineApplication Setup() public async Task Execute(string package, CommandOption registryOption) { + if (package == "vm") + return await InstallVMBinaries(); + if (package == "acc" || package == "compiler") + return await InstallCompilerBinaries(); + var registry = registryOption.HasValue() ? registryOption.Value() : @@ -85,5 +93,52 @@ public async Task Execute(string package, CommandOption registryOption) } return await Success(); } + + private async Task InstallCompilerBinaries() + { + try + { + if (Dirs.CompilerFolder.EnumerateFiles().Any()) + Console.WriteLine($"Detected already installed compiler, reinstall...".Color(Color.Orange)); + + + if (Dirs.CompilerFolder.EnumerateFiles().Any()) + _ = Dirs.CompilerFolder.EnumerateFiles().Pipe(x => x.Delete()).ToArray(); + + var result = await Appx.By(AppxType.acc) + .DownloadAsync(); + Console.Write($"{":open_file_folder:".Emoji()} Extract files"); + await RuneTask.Fire(() => + ZipFile.ExtractToDirectory(result.FullName, Dirs.CompilerFolder.FullName)); + } + catch (Exception e) + { + Console.WriteLine(e); + } + return await Success(); + } + private async Task InstallVMBinaries() + { + try + { + if (Dirs.CompilerFolder.EnumerateFiles().Any()) + Console.WriteLine($"Detected already installed vm, reinstall...".Color(Color.Orange)); + + + if (Dirs.CompilerFolder.EnumerateFiles().Any()) + _ = Dirs.CompilerFolder.EnumerateFiles().Pipe(x => x.Delete()).ToArray(); + + var result = await Appx.By(AppxType.acc) + .DownloadAsync(); + Console.Write($"{":open_file_folder:".Emoji()} Extract files"); + await RuneTask.Fire(() => + ZipFile.ExtractToDirectory(result.FullName, Dirs.CompilerFolder.FullName)); + } + catch (Exception e) + { + Console.WriteLine(e); + } + return await Success(); + } } } \ No newline at end of file diff --git a/src/cmd/VMCommand.cs b/src/cmd/VMCommand.cs index f1659a8..a06bcbc 100644 --- a/src/cmd/VMCommand.cs +++ b/src/cmd/VMCommand.cs @@ -1,17 +1,15 @@ namespace rune.cmd { - using System; using System.Collections.Generic; using System.ComponentModel; using System.IO; - using System.IO.Compression; using System.Linq; using System.Threading.Tasks; using cli; using etc; using etc.ExternalCommand; using Internal; - using MoreLinq; + using static System.Console; public class VMCommand : RuneCommand, IWithProject { @@ -24,8 +22,6 @@ internal override CommandLineApplication Setup() Description = "Execute project in Ancient VM" }; - app.Command("install", InstallVM); - app.HelpOption("-h|--help"); var dotnetBuild = new BuildCommand(); var vm = new VMCommand(); @@ -42,71 +38,7 @@ internal override CommandLineApplication Setup() }); return app; } - - internal void InstallACC(CommandLineApplication app) - { - app.Description = $"Install latest ancient compiler."; - var force = app.Option("-f|--force", "Force install binaries?", CommandOptionType.BoolValue); - - bool isForce() => force.HasValue() && force.BoolValue != null && force.BoolValue.Value; - app.OnExecute(async () => - { - try - { - if (!isForce() && Dirs.CompilerFolder.EnumerateFiles().Any()) - return await Fail($"{":x:".Emoji()} {"Already".Nier(2)} installed. Try rune vm install compiler --force"); - - - if (Dirs.CompilerFolder.EnumerateFiles().Any()) - _ = Dirs.CompilerFolder.EnumerateFiles().Pipe(x => x.Delete()).ToArray(); - - var result = await Appx.By(AppxType.acc) - .DownloadAsync(); - Console.Write($"{":open_file_folder:".Emoji()} Extract files"); - await RuneTask.Fire(() => - ZipFile.ExtractToDirectory(result.FullName, Dirs.CompilerFolder.FullName)); - } - catch (Exception e) - { - Console.WriteLine(e); - } - return await Success(); - }); - } - - internal void InstallVM(CommandLineApplication app) - { - app.Description = $"Install latest ancient VM."; - var force = app.Option("-f|--force", "Force install binaries?", CommandOptionType.BoolValue); - - bool isForce() => force.HasValue() && force.BoolValue != null && force.BoolValue.Value; - app.Command("compiler", InstallACC); - app.OnExecute(async () => - { - try - { - if (!isForce() && Dirs.VMFolder.EnumerateFiles().Any()) - return await Fail($"{":x:".Emoji()} {"Already".Nier(2)} installed. Try rune vm install --force"); - - - if (Dirs.VMFolder.EnumerateFiles().Any()) - _ = Dirs.VMFolder.EnumerateFiles().Pipe(x => x.Delete()).ToArray(); - - var result = await Appx.By(AppxType.vm) - .DownloadAsync(); - Console.Write($"{":open_file_folder:".Emoji()} Extract files"); - await RuneTask.Fire(() => - ZipFile.ExtractToDirectory(result.FullName, Dirs.VMFolder.FullName)); - } - catch (Exception e) - { - Console.WriteLine(e); - } - return await Success(); - }); - } - - + internal async Task Execute(CommandOption isDebug, CommandOption keepMemory, CommandOption fastWrite, CommandOption isInteractive) { var dir = Directory.GetCurrentDirectory(); @@ -114,7 +46,7 @@ internal async Task Execute(CommandOption isDebug, CommandOption keepMemory return await Fail(); if (!Dirs.Bin.VM.Exists) - return await Fail($"VM is not installed. Try 'rune vm install'"); + return await Fail($"VM is not installed. Try 'rune install vm'"); var vm_bin = Dirs.Bin.VM.FullName; @@ -148,16 +80,11 @@ internal async Task Execute(CommandOption isDebug, CommandOption keepMemory .Wait() .ExitCode(); } - catch (Win32Exception e) + catch (Win32Exception e) // AccessDenied on linux { - Console.WriteLine($"{":x:".Emoji()} {e.Message}"); - Console.WriteLine($"{"TODO"} try fix..."); - await OS.FireAsync($"chmod +x \"{vm_bin}\""); + WriteLine($"{":x:".Emoji()} {e.Message}"); + return await Fail($"Run [chmod +x \"{vm_bin}\"] for resolve this problem."); } - return result - .Start() - .Wait() - .ExitCode(); } } } \ No newline at end of file