Skip to content

Commit

Permalink
Add DAT path to logs (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
InoUno authored Nov 14, 2023
1 parent 2b782f8 commit f7e88ff
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 23 deletions.
2 changes: 1 addition & 1 deletion client/src/bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
4 changes: 3 additions & 1 deletion client/src/components/Logs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@ function Logs() {
<table>
<thead>
<tr>
<th>DAT</th>
<th>Name</th>
<th>Message</th>
<th>DAT path</th>
</tr>
</thead>
<tbody>
{logsToShow().map((log) =>
<tr>
<td>{log.descriptor}</td>
<td>{log.message}</td>
<td><span class="font-mono text-xs">{log.datPath}</span></td>
</tr>
)}
</tbody>
Expand Down
15 changes: 11 additions & 4 deletions client/src/store/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { createStore } from "solid-js/store";
export interface Log {
descriptor: string,
message: string,
datPath: string,
isError?: boolean,
}

Expand All @@ -21,18 +22,24 @@ 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;
}

let log: Log = {
descriptor,
message: message!,
message: message || "",
datPath: datPath || "",
isError
};
setLogs(logs.length, log);
Expand Down
18 changes: 15 additions & 3 deletions crates/dats/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ pub struct ZoneName {
pub file_name: String,
}

#[derive(Debug, Clone)]
pub struct ExtractedDat<T> {
pub dat: T,
pub path: PathBuf,
}

impl DatContext {
fn insert_into_id_map(
id_map: &mut HashMap<DatId, DatPath>,
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -178,8 +184,14 @@ impl DatContext {
.map_err(|err| DatError::DatLoadFailed(id.clone(), err))
}

pub fn get_data_from_dat<T: DatFormat>(&self, id: &Dat<T>) -> Result<T, DatError> {
T::from_path(&self.get_dat_path(id)?).map_err(|err| DatError::DatLoadFailed(id.into(), err))
pub fn get_data_from_dat<T: DatFormat>(
&self,
id: &Dat<T>,
) -> Result<ExtractedDat<T>, 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<T: DatFormat>(&self, id: &Dat<T>) -> Result<(), DatError> {
Expand Down
10 changes: 5 additions & 5 deletions crates/processor/src/converters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl DatUsage for DatToYamlConverter {
fn use_dat<T: DatFormat + Serialize + for<'b> serde::Deserialize<'b>>(
self,
dat: Dat<T>,
) -> Result<()> {
) -> Result<PathBuf> {
let data = self.dat_context.get_data_from_dat(&dat)?;

fs::create_dir_all(&self.raw_data_path.parent().unwrap())?;
Expand All @@ -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)
}
}

Expand All @@ -48,7 +48,7 @@ impl DatUsage for YamlToDatConverter {
fn use_dat<T: DatFormat + Serialize + for<'a> serde::Deserialize<'a>>(
self,
dat: Dat<T>,
) -> Result<()> {
) -> Result<PathBuf> {
let relative_dat_path = dat.get_relative_dat_path(&self.dat_context)?;
let dat_path = self.dat_root_path.join(relative_dat_path);

Expand All @@ -67,6 +67,6 @@ impl DatUsage for YamlToDatConverter {

dat_file.write_all(&data.to_bytes()?)?;

Ok(())
Ok(dat_path)
}
}
8 changes: 4 additions & 4 deletions crates/processor/src/dat_descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ pub trait DatUsage {
fn use_dat<T: DatFormat + Serialize + for<'a> serde::Deserialize<'a>>(
self,
dat: Dat<T>,
) -> Result<()>;
) -> Result<PathBuf>;
}

impl DatDescriptor {
pub fn dat_to_yaml(
&self,
dat_context: Arc<DatContext>,
raw_data_root_path: PathBuf,
) -> Result<()> {
) -> Result<PathBuf> {
let data_path = raw_data_root_path.join(self.get_relative_path(&dat_context)? + ".yml");
self.convert_with(DatToYamlConverter {
dat_context,
Expand All @@ -103,7 +103,7 @@ impl DatDescriptor {
dat_context: Arc<DatContext>,
raw_data_root_path: PathBuf,
dat_root_path: PathBuf,
) -> Result<()> {
) -> Result<PathBuf> {
let raw_data_path = raw_data_root_path.join(self.get_relative_path(&dat_context)? + ".yml");
self.convert_with(YamlToDatConverter {
dat_context,
Expand Down Expand Up @@ -295,7 +295,7 @@ impl DatDescriptor {
}
}

fn convert_with<T: DatUsage>(self, converter: T) -> Result<()> {
fn convert_with<T: DatUsage>(self, converter: T) -> Result<PathBuf> {
match self {
DatDescriptor::DataMenu => converter.use_dat(DatIdMapping::get().data_menu.clone()),

Expand Down
10 changes: 5 additions & 5 deletions crates/processor/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub enum DatProcessorOutputKind {
#[derive(Debug, Clone, specta::Type, Serialize, Deserialize)]
pub enum DatProcessingState {
Working,
Finished,
Finished(PathBuf),
Error(String),
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit f7e88ff

Please sign in to comment.