Skip to content

Commit

Permalink
dep: move from encoding to encoding_rs
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackhr-arch committed Sep 15, 2024
1 parent 091e407 commit e7c6fa1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 81 deletions.
65 changes: 5 additions & 60 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ features = ["crossterm"]
optional = true

[target.'cfg(windows)'.dependencies]
encoding = { version = "^0.2.33" }
encoding_rs = "0.8.34"

[dependencies.log4rs]
version = "^1.3.0"
Expand Down
26 changes: 6 additions & 20 deletions src/clash/ipc/ipc_windows.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use encoding::{all::GBK, DecoderTrap, Encoding};
use std::process::{Command, Output};

use std::io::Result;
Expand Down Expand Up @@ -94,25 +93,12 @@ pub fn is_system_proxy_enabled() -> Result<bool> {

pub(super) fn string_process_output(output: Output) -> Result<String> {
let stdout_vec: Vec<u8> = output.stdout;
use std::io::{Error, ErrorKind};

let stdout_str = GBK
.decode(&stdout_vec, DecoderTrap::Strict)
.map_err(|err| {
Error::new(
ErrorKind::InvalidData,
format!("Failed to decode stdout: {err}"),
)
})?;

let stderr_str = GBK
.decode(&output.stderr, DecoderTrap::Strict)
.map_err(|err| {
Error::new(
ErrorKind::InvalidData,
format!("Failed to decode stderr: {err}"),
)
})?;

let (stdout_str, _encoding, _contain_bad_char) =
encoding_rs::Encoding::decode(encoding_rs::GBK, &stdout_vec);

let (stderr_str, _encoding, _contain_bad_char) =
encoding_rs::Encoding::decode(encoding_rs::GBK, &stdout_vec);

let result_str = format!(
r#"
Expand Down

0 comments on commit e7c6fa1

Please sign in to comment.