mirror of
https://github.com/tauri-apps/nsis-tauri-utils.git
synced 2026-01-31 00:45:23 +01:00
feat: add nsis-string plugin (#43)
This commit is contained in:
@@ -63,6 +63,16 @@
|
||||
"name": "${ pkg.pkg }.dll"
|
||||
}
|
||||
]
|
||||
},
|
||||
"nsis_string": {
|
||||
"path": "./crates/nsis-string",
|
||||
"manager": "rust",
|
||||
"assets": [
|
||||
{
|
||||
"path": "target/i686-pc-windows-msvc/release/${ pkg.pkg }.dll",
|
||||
"name": "${ pkg.pkg }.dll"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
5
.changes/nsis-string.md
Normal file
5
.changes/nsis-string.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"nsis_string": "minor"
|
||||
---
|
||||
|
||||
Initial Release
|
||||
@@ -6,6 +6,7 @@ A collection of NSIS plugins written in rust.
|
||||
| -------------------------------------------------- | ------------------------------------------------------------------------ |
|
||||
| [nsis-process](./crates/nsis-process/) | Find and Kill processes, and run program as unelevated user |
|
||||
| [nsis-semvercompare](./crates/nsis-semvercompare/) | Compare two semantic versions |
|
||||
| [nsis-string](./crates/nsis-string/) | String manipulation |
|
||||
| [nsis-tauri-utils](./crates/nsis-tauri-utils/) | A collection of all the above plugins into a single DLL for smaller size |
|
||||
|
||||
## License
|
||||
|
||||
@@ -93,7 +93,7 @@ fn KillProcess() -> Result<(), Error> {
|
||||
|
||||
let processes = get_processes(&name);
|
||||
|
||||
if !processes.is_empty() && processes.into_iter().map(kill).all(|b| b) {
|
||||
if !processes.is_empty() && processes.into_iter().all(kill) {
|
||||
push(ZERO)
|
||||
} else {
|
||||
push(ONE)
|
||||
@@ -119,10 +119,9 @@ fn KillProcessCurrentUser() -> Result<(), Error> {
|
||||
processes
|
||||
.into_iter()
|
||||
.filter(|pid| belongs_to_user(user_sid, *pid))
|
||||
.map(kill)
|
||||
.all(|b| b)
|
||||
.all(kill)
|
||||
} else {
|
||||
processes.into_iter().map(kill).all(|b| b)
|
||||
processes.into_iter().all(kill)
|
||||
};
|
||||
|
||||
if success {
|
||||
@@ -388,7 +387,7 @@ mod tests {
|
||||
let processes = get_processes("something_that_doesnt_exist.exe");
|
||||
// TODO: maybe find some way to spawn a dummy process we can kill here?
|
||||
// This will return true on empty iterators so it's basically no-op right now
|
||||
assert!(processes.into_iter().map(kill).all(|b| b));
|
||||
assert!(processes.into_iter().all(kill));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
14
crates/nsis-string/CHANGELOG.md
Normal file
14
crates/nsis-string/CHANGELOG.md
Normal file
@@ -0,0 +1,14 @@
|
||||
# Changelog
|
||||
|
||||
## \[0.3.0]
|
||||
|
||||
- [`5423579`](https://www.github.com/tauri-apps/nsis-tauri-utils/commit/5423579860016c4f3074831eda03096ee4854e73)([#26](https://www.github.com/tauri-apps/nsis-tauri-utils/pull/26)) Reduce the DLL size by using `no_std` and without static msvcrt.
|
||||
|
||||
## \[0.2.0]
|
||||
|
||||
- [`33ea4bc`](https://www.github.com/tauri-apps/nsis-tauri-utils/commit/33ea4bcf2a573461ebc5181ef2921d8746005049)([#17](https://www.github.com/tauri-apps/nsis-tauri-utils/pull/17)) Statically link CRT.
|
||||
|
||||
## \[0.1.0]
|
||||
|
||||
- Initial Release.
|
||||
- [000d632](https://www.github.com/tauri-apps/nsis-tauri-utils/commit/000d6326333f862741f1514de34542316445951e) ci: setup CI/CD and covector ([#2](https://www.github.com/tauri-apps/nsis-tauri-utils/pull/2)) on 2023-01-21
|
||||
16
crates/nsis-string/Cargo.toml
Normal file
16
crates/nsis-string/Cargo.toml
Normal file
@@ -0,0 +1,16 @@
|
||||
[package]
|
||||
name = "nsis-string"
|
||||
version = "0.0.0"
|
||||
authors = { workspace = true }
|
||||
edition = { workspace = true }
|
||||
license = { workspace = true }
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[features]
|
||||
test = []
|
||||
|
||||
[dependencies]
|
||||
nsis-plugin-api = { workspace = true }
|
||||
windows-sys = { workspace = true }
|
||||
5
crates/nsis-string/build.rs
Normal file
5
crates/nsis-string/build.rs
Normal file
@@ -0,0 +1,5 @@
|
||||
fn main() {
|
||||
if std::env::var("CARGO_FEATURE_TEST").as_deref() != Ok("1") {
|
||||
println!("cargo::rustc-link-arg=/ENTRY:DllMain")
|
||||
}
|
||||
}
|
||||
24
crates/nsis-string/src/lib.rs
Normal file
24
crates/nsis-string/src/lib.rs
Normal file
@@ -0,0 +1,24 @@
|
||||
#![no_std]
|
||||
|
||||
use nsis_plugin_api::*;
|
||||
|
||||
nsis_plugin!();
|
||||
|
||||
/// Replaces all occurrences of a substring in a string with another substring.
|
||||
///
|
||||
/// Returns the modified string.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// This function always expects 3 strings on the stack ($string, $search, $replace) and will panic otherwise.
|
||||
#[nsis_fn]
|
||||
fn Replace() -> Result<(), Error> {
|
||||
let string = popstr()?;
|
||||
let search = popstr()?;
|
||||
let replace = popstr()?;
|
||||
|
||||
let result = string.replace(&search, &replace);
|
||||
pushstr(&result)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user