From f7e88ff90c58fe4becd02d3032ede3424ef2e875 Mon Sep 17 00:00:00 2001 From: InoUno Date: Tue, 14 Nov 2023 17:46:39 +0100 Subject: [PATCH] Add DAT path to logs (#7) --- client/src/bindings.ts | 2 +- client/src/components/Logs.tsx | 4 +++- client/src/store/logs.ts | 15 +++++++++++---- crates/dats/src/context.rs | 18 +++++++++++++++--- crates/processor/src/converters.rs | 10 +++++----- crates/processor/src/dat_descriptor.rs | 8 ++++---- crates/processor/src/processor.rs | 10 +++++----- 7 files changed, 44 insertions(+), 23 deletions(-) diff --git a/client/src/bindings.ts b/client/src/bindings.ts index 349dcb1..3064ee3 100644 --- a/client/src/bindings.ts +++ b/client/src/bindings.ts @@ -66,6 +66,6 @@ export type DatProcessorOutputKind = "Dat" | "Yaml" export type DatDescriptor = { type: "DataMenu" } | { type: "AbilityNames" } | { type: "AbilityDescriptions" } | { type: "AreaNames" } | { type: "AreaNamesAlt" } | { type: "CharacterSelect" } | { type: "ChatFilterTypes" } | { type: "DayNames" } | { type: "Directions" } | { type: "EquipmentLocations" } | { type: "ErrorMessages" } | { type: "IngameMessages1" } | { type: "IngameMessages2" } | { type: "JobNames" } | { type: "KeyItems" } | { type: "MenuItemsDescription" } | { type: "MenuItemsText" } | { type: "MoonPhases" } | { type: "PolMessages" } | { type: "RaceNames" } | { type: "RegionNames" } | { type: "SpellNames" } | { type: "SpellDescriptions" } | { type: "StatusInfo" } | { type: "StatusNames" } | { type: "TimeAndPronouns" } | { type: "Titles" } | { type: "Misc1" } | { type: "Misc2" } | { type: "WeatherTypes" } | { type: "Armor" } | { type: "Armor2" } | { type: "Currency" } | { type: "GeneralItems" } | { type: "GeneralItems2" } | { type: "PuppetItems" } | { type: "UsableItems" } | { type: "Weapons" } | { type: "VouchersAndSlips" } | { type: "Monipulator" } | { type: "Instincts" } | { type: "MonsterSkillNames" } | { type: "StatusNamesDialog" } | { type: "EmoteMessages" } | { type: "SystemMessages1" } | { type: "SystemMessages2" } | { type: "SystemMessages3" } | { type: "SystemMessages4" } | { type: "UnityDialogs" } | { type: "EntityNames"; index: number } | { type: "Dialog"; index: number } | { type: "Dialog2"; index: number } export type ZoneInfo = { id: number; name: string } export type FileNotification = { dat_descriptor: DatDescriptor; is_delete: boolean } -export type DatProcessingState = "Working" | "Finished" | { Error: string } +export type DatProcessingState = "Working" | { Finished: string } | { Error: string } export type PersistenceData = { ffxi_path: string | null; recent_projects: string[] } export type DatProcessorMessage = { dat_descriptor: DatDescriptor; output_kind: DatProcessorOutputKind; state: DatProcessingState } diff --git a/client/src/components/Logs.tsx b/client/src/components/Logs.tsx index 07fe0be..0f0698d 100644 --- a/client/src/components/Logs.tsx +++ b/client/src/components/Logs.tsx @@ -28,8 +28,9 @@ function Logs() { - + + @@ -37,6 +38,7 @@ function Logs() { + )} diff --git a/client/src/store/logs.ts b/client/src/store/logs.ts index 15475d0..e0a7f92 100644 --- a/client/src/store/logs.ts +++ b/client/src/store/logs.ts @@ -5,6 +5,7 @@ import { createStore } from "solid-js/store"; export interface Log { descriptor: string, message: string, + datPath: string, isError?: boolean, } @@ -21,10 +22,15 @@ export function createLogsStore() { descriptor += ` (${payload.dat_descriptor.index})`; } - let message; + let message, datPath; let isError; - if (payload.state == "Finished") { - message = "Success"; + if ("Finished" in payload.state) { + if (payload.output_kind == "Dat") { + message = "Finished generation"; + } else { + message = "Finished export"; + } + datPath = payload.state.Finished; } else if ("Error" in payload.state) { message = payload.state.Error; isError = true; @@ -32,7 +38,8 @@ export function createLogsStore() { let log: Log = { descriptor, - message: message!, + message: message || "", + datPath: datPath || "", isError }; setLogs(logs.length, log); diff --git a/crates/dats/src/context.rs b/crates/dats/src/context.rs index 55c8175..f33c615 100644 --- a/crates/dats/src/context.rs +++ b/crates/dats/src/context.rs @@ -29,6 +29,12 @@ pub struct ZoneName { pub file_name: String, } +#[derive(Debug, Clone)] +pub struct ExtractedDat { + pub dat: T, + pub path: PathBuf, +} + impl DatContext { fn insert_into_id_map( id_map: &mut HashMap, @@ -136,7 +142,7 @@ impl DatContext { let zone_data = result.get_data_from_dat(&DatIdMapping::get().area_names)?; let mut previous_names = HashSet::new(); - for (zone_id, (_, zone_string_list)) in zone_data.lists.into_iter().enumerate() { + for (zone_id, (_, zone_string_list)) in zone_data.dat.lists.into_iter().enumerate() { let display_content = zone_string_list .content .first() @@ -178,8 +184,14 @@ impl DatContext { .map_err(|err| DatError::DatLoadFailed(id.clone(), err)) } - pub fn get_data_from_dat(&self, id: &Dat) -> Result { - T::from_path(&self.get_dat_path(id)?).map_err(|err| DatError::DatLoadFailed(id.into(), err)) + pub fn get_data_from_dat( + &self, + id: &Dat, + ) -> Result, DatError> { + let path = self.get_dat_path(id)?; + T::from_path(&path) + .map(|dat| ExtractedDat { dat, path }) + .map_err(|err| DatError::DatLoadFailed(id.into(), err)) } pub fn check_dat(&self, id: &Dat) -> Result<(), DatError> { diff --git a/crates/processor/src/converters.rs b/crates/processor/src/converters.rs index 705b4f4..21453d9 100644 --- a/crates/processor/src/converters.rs +++ b/crates/processor/src/converters.rs @@ -20,7 +20,7 @@ impl DatUsage for DatToYamlConverter { fn use_dat serde::Deserialize<'b>>( self, dat: Dat, - ) -> Result<()> { + ) -> Result { let data = self.dat_context.get_data_from_dat(&dat)?; fs::create_dir_all(&self.raw_data_path.parent().unwrap())?; @@ -32,9 +32,9 @@ impl DatUsage for DatToYamlConverter { ) })?; - serde_yaml::to_writer(BufWriter::new(file), &data)?; + serde_yaml::to_writer(BufWriter::new(file), &data.dat)?; - Ok(()) + Ok(data.path) } } @@ -48,7 +48,7 @@ impl DatUsage for YamlToDatConverter { fn use_dat serde::Deserialize<'a>>( self, dat: Dat, - ) -> Result<()> { + ) -> Result { let relative_dat_path = dat.get_relative_dat_path(&self.dat_context)?; let dat_path = self.dat_root_path.join(relative_dat_path); @@ -67,6 +67,6 @@ impl DatUsage for YamlToDatConverter { dat_file.write_all(&data.to_bytes()?)?; - Ok(()) + Ok(dat_path) } } diff --git a/crates/processor/src/dat_descriptor.rs b/crates/processor/src/dat_descriptor.rs index 9d3cbf2..46fbd0f 100644 --- a/crates/processor/src/dat_descriptor.rs +++ b/crates/processor/src/dat_descriptor.rs @@ -82,7 +82,7 @@ pub trait DatUsage { fn use_dat serde::Deserialize<'a>>( self, dat: Dat, - ) -> Result<()>; + ) -> Result; } impl DatDescriptor { @@ -90,7 +90,7 @@ impl DatDescriptor { &self, dat_context: Arc, raw_data_root_path: PathBuf, - ) -> Result<()> { + ) -> Result { let data_path = raw_data_root_path.join(self.get_relative_path(&dat_context)? + ".yml"); self.convert_with(DatToYamlConverter { dat_context, @@ -103,7 +103,7 @@ impl DatDescriptor { dat_context: Arc, raw_data_root_path: PathBuf, dat_root_path: PathBuf, - ) -> Result<()> { + ) -> Result { let raw_data_path = raw_data_root_path.join(self.get_relative_path(&dat_context)? + ".yml"); self.convert_with(YamlToDatConverter { dat_context, @@ -295,7 +295,7 @@ impl DatDescriptor { } } - fn convert_with(self, converter: T) -> Result<()> { + fn convert_with(self, converter: T) -> Result { match self { DatDescriptor::DataMenu => converter.use_dat(DatIdMapping::get().data_menu.clone()), diff --git a/crates/processor/src/processor.rs b/crates/processor/src/processor.rs index 9c65c03..5140fa8 100644 --- a/crates/processor/src/processor.rs +++ b/crates/processor/src/processor.rs @@ -30,7 +30,7 @@ pub enum DatProcessorOutputKind { #[derive(Debug, Clone, specta::Type, Serialize, Deserialize)] pub enum DatProcessingState { Working, - Finished, + Finished(PathBuf), Error(String), } @@ -65,10 +65,10 @@ impl DatProcessor { self.pool.lock().unwrap().execute(move || { let res = dat_descriptor .dat_to_yaml(dat_context, raw_data_root_path) - .map(|_| DatProcessorMessage { + .map(|path| DatProcessorMessage { dat_descriptor, output_kind: DatProcessorOutputKind::Yaml, - state: DatProcessingState::Finished, + state: DatProcessingState::Finished(path), }) .unwrap_or_else(|err| DatProcessorMessage { dat_descriptor, @@ -102,10 +102,10 @@ impl DatProcessor { self.pool.lock().unwrap().execute(move || { let res = dat_descriptor .yaml_to_dat(dat_context, raw_data_root_path, dat_root_path) - .map(|_| DatProcessorMessage { + .map(|path| DatProcessorMessage { dat_descriptor, output_kind: DatProcessorOutputKind::Dat, - state: DatProcessingState::Finished, + state: DatProcessingState::Finished(path), }) .unwrap_or_else(|err| DatProcessorMessage { dat_descriptor,
DATName MessageDAT path
{log.descriptor} {log.message}{log.datPath}