Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
axiangcoding committed Jul 1, 2024
1 parent 8363deb commit eebb7e3
Show file tree
Hide file tree
Showing 9 changed files with 516 additions and 14 deletions.
49 changes: 49 additions & 0 deletions src-tauri/Cargo.lock

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

1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ tauri = { version = "1", features = [
"dialog-open",
"shell-open",
] }
tokio = { version = "1", features = ["full"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
sevenz-rust = "0.6.0"
Expand Down
10 changes: 7 additions & 3 deletions src-tauri/src/commands/wt_ext_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,27 @@ pub struct CmdResult {
}

#[tauri::command]
pub fn exec_wt_ext_cli(
state: tauri::State<WrappedState>,
pub async fn exec_wt_ext_cli(
state: tauri::State<'_, WrappedState>,
args: Vec<String>,
) -> Result<CmdResult, RetCode> {
let wt_ext_cli_path = get_wt_ext_cli_path(state)?;
debug!("args: {:?}", args);
let output = std::process::Command::new(wt_ext_cli_path)

let output = tokio::process::Command::new(wt_ext_cli_path)
.args(args)
.output()
.await
.map_err(|e| {
error!("Failed to execute command: {}", e);
RetCode::WTExtCliCommandFailed
})?;

let stdout = String::from_utf8(output.stdout).unwrap();
let stderr = String::from_utf8(output.stderr).unwrap();
debug!("stdout: {}", stdout);
debug!("stderr: {}", stderr);

Ok(CmdResult {
code: output.status.code().unwrap(),
stdout: Some(stdout),
Expand Down
11 changes: 11 additions & 0 deletions src/components/wt_ext_cli_cmd_card/HelpCmd.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ const cmdOutput = ref<CmdResult>({} as any);
const args = ref(["help"]);
async function exec() {
loading.value = true;
cmdOutput.value = await invoke("exec_wt_ext_cli", { args: args.value });
loading.value = false;
}
async function cleanOutput() {
cmdOutput.value = {} as any;
}
const loading = ref(false);
</script>

<template>
Expand Down Expand Up @@ -54,6 +58,13 @@ async function cleanOutput() {
v-if="cmdOutput.code != null && cmdOutput.code != 0"
>执行失败
</v-chip>
<v-progress-linear
v-if="loading"
color="primary"
indeterminate
striped
height="10"
></v-progress-linear>
</v-list-item>
<v-list-item>
<v-list-item-title>内容输出</v-list-item-title>
Expand Down
171 changes: 171 additions & 0 deletions src/components/wt_ext_cli_cmd_card/UnpackDxpAndGrpCmd.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
<script setup lang="ts">
import { invoke } from "@tauri-apps/api";
import { ref } from "vue";
import { CmdResult } from "../../schema";
import { open } from "@tauri-apps/api/dialog";
const cmdOutput = ref<CmdResult>({} as any);
const cmdArgs = ref<{
inputDir: string;
outputDir: string;
keepSuffix: boolean;
help: boolean;
}>({} as any);
async function exec() {
let args = ["unpack_dxp_and_grp"];
if (cmdArgs.value.inputDir) {
args.push("--input_dir", cmdArgs.value.inputDir);
}
if (cmdArgs.value.outputDir) {
args.push("--output_dir", cmdArgs.value.outputDir);
}
if (cmdArgs.value.keepSuffix) {
args.push("--keep_suffix");
}
if (cmdArgs.value.help) {
args.push("--help");
}
loading.value = true;
cmdOutput.value = await invoke("exec_wt_ext_cli", { args: args });
loading.value = false;
}
async function cleanOutput() {
cmdOutput.value = {} as any;
}
async function selectPath() {
let selectedPath = await open({
directory: true,
multiple: false,
});
return selectedPath;
}
async function selectInputDir() {
let selectedPath = await selectPath();
if (selectedPath != null) {
if (typeof selectedPath == "string") {
cmdArgs.value.inputDir = selectedPath;
} else {
cmdArgs.value.inputDir = selectedPath[0];
}
}
}
async function selectOutputDir() {
let selectedPath = await selectPath();
if (selectedPath != null) {
if (typeof selectedPath == "string") {
cmdArgs.value.outputDir = selectedPath;
} else {
cmdArgs.value.outputDir = selectedPath[0];
}
}
}
async function showOutputDir() {
await invoke("show_folder", { path: cmdArgs.value.outputDir });
}
const loading = ref(false);
</script>

<template>
<v-list>
<v-list-item>
<v-list-item-title>命令</v-list-item-title>
<v-chip color="primary">wt-ext-cli unpack_dxp_and_grp</v-chip>
</v-list-item>
<v-list-item>
<v-list-item-title>说明</v-list-item-title>
将文件夹和子文件夹中的 DXP 和 GRP 文件解压为文本格式文件
</v-list-item>
<v-list-item>
<v-list-item-title>参数</v-list-item-title>
<v-container>
<v-row dense>
<v-col cols="6">
<v-text-field
label="输入目录。内含 DXP/GRP 文件的文件夹"
append-inner-icon="mdi-folder"
v-model="cmdArgs.inputDir"
@click:append-inner="selectInputDir"
clearable
>
</v-text-field>
</v-col>
<v-col cols="6">
<v-text-field
label="输出目录。创建的目标文件夹将包含新文件,并保留文件结构"
append-inner-icon="mdi-folder"
v-model="cmdArgs.outputDir"
@click:append-inner="selectOutputDir"
clearable
>
</v-text-field>
</v-col>
<v-col cols="6">
<v-switch
v-model="cmdArgs.keepSuffix"
label="最终 DXP/GRP 中的路径和名称后是否保留后缀"
color="primary"
></v-switch>
</v-col>
<v-col cols="6">
<v-switch
v-model="cmdArgs.help"
label="展示帮助信息"
color="primary"
></v-switch>
</v-col>
</v-row>
</v-container>
</v-list-item>
</v-list>
<div class="d-flex ga-2">
<v-btn color="primary" @click="exec">执行命令</v-btn>
<v-btn color="warning" @click="cleanOutput"> 清空输出</v-btn>
<v-btn color="info" @click="showOutputDir" :disabled="!cmdArgs.outputDir">
打开输出目录
</v-btn>
</div>

<v-divider class="my-3"></v-divider>

<v-list>
<v-list-item>
<v-list-item-title>执行结果</v-list-item-title>
<v-chip
variant="elevated"
color="success"
v-if="cmdOutput.code != null && cmdOutput.code == 0"
>
执行成功
</v-chip>
<v-chip
variant="elevated"
color="error"
v-if="cmdOutput.code != null && cmdOutput.code != 0"
>执行失败
</v-chip>
<v-progress-linear
v-if="loading"
color="primary"
indeterminate
striped
height="10"
></v-progress-linear>
</v-list-item>
<v-list-item>
<v-list-item-title>内容输出</v-list-item-title>
<v-code class="console-box border-success">
{{ cmdOutput.stdout ? cmdOutput.stdout : cmdOutput.stderr }}
</v-code>
</v-list-item>
</v-list>
</template>

<style scoped></style>
22 changes: 15 additions & 7 deletions src/components/wt_ext_cli_cmd_card/UnpackRawBlkCmd.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ async function exec() {
if (cmdArgs.value.help) {
args.push("--help");
}
loading.value = true;
cmdOutput.value = await invoke("exec_wt_ext_cli", { args: args });
loading.value = false;
}
async function cleanOutput() {
Expand Down Expand Up @@ -76,6 +77,8 @@ async function selectOutputDir() {
async function showOutputDir() {
await invoke("show_folder", { path: cmdArgs.value.outputDir });
}
const loading = ref(false);
</script>

<template>
Expand All @@ -89,16 +92,15 @@ async function showOutputDir() {
解压一个文件夹中的原始/二进制 blk 文件为解包格式
</v-list-item>
<v-list-item>
<v-list-item-title> 参数 </v-list-item-title>
<v-list-item-title>参数</v-list-item-title>
<v-container>
<v-row dense>
<v-col cols="6">
<v-text-field
label="需要解包的二进制 blk 文件"
append-inner-icon="mdi-file"
label="输入文件。需要解包的二进制 blk 文件"
append-inner-icon="mdi-folder"
v-model="cmdArgs.inputDir"
@click:append-inner="selectInputDir"
readonly
clearable
>
</v-text-field>
Expand All @@ -109,15 +111,14 @@ async function showOutputDir() {
append-inner-icon="mdi-folder"
v-model="cmdArgs.outputDir"
@click:append-inner="selectOutputDir"
readonly
clearable
>
</v-text-field>
</v-col>
<v-col cols="6">
<v-select
clearable
label="输出格式可以是[Json、BlkText] 默认是Json"
label="输出格式可以是[Json、BlkText] 默认是Json"
:items="['Json', 'BlkText']"
v-model="cmdArgs.format"
></v-select>
Expand Down Expand Up @@ -159,6 +160,13 @@ async function showOutputDir() {
v-if="cmdOutput.code != null && cmdOutput.code != 0"
>执行失败
</v-chip>
<v-progress-linear
v-if="loading"
color="primary"
indeterminate
striped
height="10"
></v-progress-linear>
</v-list-item>
<v-list-item>
<v-list-item-title>内容输出</v-list-item-title>
Expand Down
Loading

0 comments on commit eebb7e3

Please sign in to comment.