-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
474 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
$target = $args[0] | ||
$downloadUrl = "https://mirrors.tuna.tsinghua.edu.cn/msys2/distrib/msys2-x86_64-latest.sfx.exe" | ||
$mirror = 'sed -i "s#https\?://mirror.msys2.org/#https://mirrors.tuna.tsinghua.edu.cn/msys2/#g" /etc/pacman.d/mirrorlist*' | ||
|
||
$installer = "$($env:TEMP)\msys2.exe" | ||
|
||
|
||
if (!(Test-Path $installer -PathType Leaf)) { | ||
Write-Host "Download file to $($installer)" | ||
Invoke-WebRequest -Uri $downloadUrl -OutFile $installer | ||
} | ||
|
||
& $installer "-y", "-o$($target)" | ||
|
||
$msys2 = "$($target)/msys64/usr/bin/bash.exe" | ||
|
||
& $msys2 "-l", "-c", $mirror | ||
& $msys2 "-l", "-c", "pacman --noconfirm -S mingw-w64-ucrt-x86_64-clang-tools-extra mingw-w64-ucrt-x86_64-gcc" | ||
|
||
Write-Host "Tools were installed to $($target)/msys64/ucrt64/bin" | ||
|
||
$report = @{ | ||
'gcc' = "$($target)\msys64\ucrt64\bin\g++.exe" | ||
'clangd' = "$($target)\msys64\ucrt64\bin\clangd.exe" | ||
} | ||
|
||
# $report | ConvertTo-Json | Out-File "$($target)/msys2.json" -Encoding UTF8NoBOM | ||
$reportJson = $report | ConvertTo-Json | ||
[IO.File]::WriteAllLines("$($target)\msys2.json", $reportJson) | ||
Remove-Item $installer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
use std::{ | ||
io::Stderr, | ||
process::{Command, Stdio}, | ||
}; | ||
|
||
use tauri::Runtime; | ||
use tokio::{ | ||
io::{AsyncBufReadExt, BufReader}, | ||
sync::Mutex, | ||
}; | ||
|
||
use crate::{util::console, RESOURCE_DIR}; | ||
|
||
#[derive(Default)] | ||
pub struct PwshScriptState { | ||
s: Mutex<()>, | ||
} | ||
|
||
#[tauri::command] | ||
pub async fn execuate_pwsh_script<R: Runtime>( | ||
app: tauri::AppHandle<R>, | ||
window: tauri::Window<R>, | ||
state: tauri::State<'_, PwshScriptState>, | ||
name: String, | ||
) -> Result<String, String> { | ||
if !cfg!(windows) { | ||
return Err(String::from("Installer only work on windows")); | ||
} | ||
let _guard = state.s.lock().await; | ||
|
||
let script_file = app | ||
.path_resolver() | ||
.resolve_resource(format!("sidecar/{}.ps1", &name)) | ||
.unwrap(); | ||
let script_file = dunce::canonicalize(script_file).unwrap(); | ||
log::info!("execuate script {:?}", &script_file.to_str()); | ||
let mut cmd = Command::new(which::which("powershell").unwrap()); | ||
|
||
let target = RESOURCE_DIR.get().unwrap(); | ||
cmd.arg(&script_file.to_str().unwrap()); | ||
cmd.arg(target.to_str().unwrap()); | ||
console::hide_new_console(&mut cmd); | ||
|
||
let mut cmd = tokio::process::Command::from(cmd); | ||
cmd.stdout(Stdio::piped()); | ||
cmd.stderr(Stdio::piped()); | ||
cmd.stdin(Stdio::piped()); | ||
let mut proc = cmd.spawn().unwrap(); | ||
let mut stdout = BufReader::new( | ||
proc.stdout | ||
.take() | ||
.ok_or(String::from("Fail to open stdout"))?, | ||
) | ||
.lines(); | ||
let mut stderr = BufReader::new( | ||
proc.stderr | ||
.take() | ||
.ok_or(String::from("Fail to open stderr"))?, | ||
) | ||
.lines(); | ||
|
||
let mut stdout_eof = false; | ||
let mut stderr_eof = false; | ||
let result = loop { | ||
tokio::select! { | ||
Ok(data) = stdout.next_line(), if !stdout_eof => { | ||
if let Some(line) = data { | ||
window.emit("install_message", line).map_err(|e| e.to_string())?; | ||
}else{ | ||
stdout_eof = true | ||
} | ||
} | ||
Ok(data) = stderr.next_line(), if !stderr_eof => { | ||
if let Some(line) = data{ | ||
window.emit("install_message", line).map_err(|e| e.to_string())?; | ||
}else{ | ||
stderr_eof = true; | ||
} | ||
} | ||
else => { | ||
break proc.wait().await.map_err(|e|e.to_string())?; | ||
} | ||
} | ||
}; | ||
|
||
if result.success() { | ||
let report = target.join(format!("{}.json", name)); | ||
let content = tokio::fs::read_to_string(report) | ||
.await | ||
.map_err(|e| e.to_string())?; | ||
Ok(content) | ||
} else { | ||
if let Some(code) = result.code() { | ||
Err(format!("Process exit with code {}", code)) | ||
} else { | ||
Err(String::from("Process exit with terminal signal")) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.