Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pizzart committed Oct 10, 2023
1 parent 231b34b commit 236d1b2
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 34 deletions.
6 changes: 3 additions & 3 deletions bff-gui/src-tauri/src/bitmap.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::io::{BufReader, Cursor};
use std::path::Path;

use base64::{engine::general_purpose, Engine as _};
use base64::engine::general_purpose;
use base64::Engine as _;
use bff::class::bitmap::Bitmap;
use bff::names::Name;

Expand All @@ -10,7 +10,7 @@ use crate::traits::Export;
use crate::{DataType, PreviewData};

impl Export for Box<Bitmap> {
fn export(&self, _export_path: &Path, _name: Name) -> BffGuiResult<PreviewData> {
fn export(&self, _name: Name) -> BffGuiResult<PreviewData> {
match **self {
Bitmap::BitmapV1_381_67_09PC(ref bitmap) => {
let buf = BufReader::new(Cursor::new(&bitmap.body.data));
Expand Down
21 changes: 6 additions & 15 deletions bff-gui/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use std::io::{BufReader, Write};
use std::path::{Path, PathBuf};
use std::sync::Mutex;

use base64::{engine::general_purpose, Engine as _};
use base64::engine::general_purpose;
use base64::Engine as _;
use bff::bigfile::resource::Resource;
use bff::bigfile::BigFile;
use bff::class::user_define::UserDefine;
Expand Down Expand Up @@ -139,7 +140,6 @@ fn extract_bigfile(path: &str, state: tauri::State<AppState>) -> Result<BigFileD
#[tauri::command]
fn parse_resource(
resource_name: Name,
temp_path: &Path,
state: tauri::State<AppState>,
) -> BffGuiResult<ResourcePreview> {
let mut state_guard = state.0.lock().unwrap();
Expand All @@ -155,18 +155,9 @@ fn parse_resource(

let class = resource.try_into_version_platform(version.clone(), platform)?;
let data = match class {
Class::Bitmap(ref bitmap) => {
let new_path = temp_path.join(format!("{}.png", resource.name));
Some(bitmap.export(&new_path, resource_name)?)
}
Class::Sound(ref sound) => {
let new_path = temp_path.join(format!("{}.wav", resource.name));
Some(sound.export(&new_path, resource_name)?)
}
Class::Mesh(ref mesh) => {
let new_path = temp_path.join(format!("{}.dae", resource.name));
Some(mesh.export(&new_path, resource_name)?)
}
Class::Bitmap(ref bitmap) => Some(bitmap.export(resource_name)?),
Class::Sound(ref sound) => Some(sound.export(resource_name)?),
Class::Mesh(ref mesh) => Some(mesh.export(resource_name)?),
Class::UserDefine(ref userdefine) => match **userdefine {
UserDefine::UserDefineV1_291_03_06PC(ref userdefine) => Some(PreviewData {
is_base64: false,
Expand Down Expand Up @@ -248,7 +239,7 @@ fn export_preview(path: &Path, name: Name, state: tauri::State<AppState>) -> Bff
true => &binding,
false => preview_data.data.as_bytes(),
};
File::create(path)?.write(written_data)?;
File::create(path)?.write_all(written_data)?;
Ok(())
}

Expand Down
3 changes: 1 addition & 2 deletions bff-gui/src-tauri/src/mesh.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::io::Cursor;
use std::path::Path;
use std::str::from_utf8;

use bff::class::mesh::{v1_291_03_06_pc, Mesh};
Expand Down Expand Up @@ -123,7 +122,7 @@ struct SimpleMesh {
}

impl Export for Box<Mesh> {
fn export(&self, export_path: &Path, name: Name) -> BffGuiResult<PreviewData> {
fn export(&self, name: Name) -> BffGuiResult<PreviewData> {
match **self {
Mesh::MeshV1_291_03_06PC(ref mesh) => {
let buffers: Vec<SimpleMesh> = mesh
Expand Down
6 changes: 3 additions & 3 deletions bff-gui/src-tauri/src/sound.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::io::Cursor;
use std::path::Path;

use base64::{engine::general_purpose, Engine as _};
use base64::engine::general_purpose;
use base64::Engine as _;
use bff::class::sound::Sound;
use bff::names::Name;

Expand All @@ -10,7 +10,7 @@ use crate::traits::Export;
use crate::{DataType, PreviewData};

impl Export for Box<Sound> {
fn export(&self, _export_path: &Path, _name: Name) -> BffGuiResult<PreviewData> {
fn export(&self, _name: Name) -> BffGuiResult<PreviewData> {
match **self {
Sound::SoundV1_291_03_06PC(ref sound) => {
let spec = hound::WavSpec {
Expand Down
7 changes: 3 additions & 4 deletions bff-gui/src-tauri/src/traits.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use std::path::Path;

use bff::names::Name;

use crate::{error::BffGuiResult, PreviewData};
use crate::error::BffGuiResult;
use crate::PreviewData;

pub trait Export {
fn export(&self, export_path: &Path, name: Name) -> BffGuiResult<PreviewData>;
fn export(&self, name: Name) -> BffGuiResult<PreviewData>;
}
7 changes: 1 addition & 6 deletions bff-gui/src/functions/preview.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { invoke } from "@tauri-apps/api";
import { tempdir } from "@tauri-apps/api/os";
import { BigFileData, ResourcePreview, ViewTab } from "../types/types";
import { ResourcePreview, ViewTab } from "../types/types";
import { message } from "@tauri-apps/api/dialog";

export async function updateView(
Expand All @@ -10,16 +9,12 @@ export async function updateView(
>,
setOpenTab: React.Dispatch<React.SetStateAction<ViewTab>>
) {
let temp_dir = await tempdir();
invoke("parse_resource", {
resourceName: resourceName,
tempPath: temp_dir,
})
.then((preview) => {
console.log(preview);
let resourcePreview = preview as ResourcePreview;
setPreviewObject(resourcePreview);
// if (resourcePreview.error !== null) setOpenTab(PreviewTab.Error);
if (resourcePreview.preview_data !== null) setOpenTab(ViewTab.Preview);
else setOpenTab(ViewTab.Data);
})
Expand Down
1 change: 0 additions & 1 deletion bff-gui/src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,4 @@ export enum Submenu {
export enum ViewTab {
Data,
Preview,
Error,
}

0 comments on commit 236d1b2

Please sign in to comment.