Skip to main content

rpfm_ipc/
messages.rs

1//---------------------------------------------------------------------------//
2// Copyright (c) 2017-2026 Ismael Gutiérrez González. All rights reserved.
3//
4// This file is part of the Rusted PackFile Manager (RPFM) project,
5// which can be found here: https://github.com/Frodo45127/rpfm.
6//
7// This file is licensed under the MIT license, which can be found here:
8// https://github.com/Frodo45127/rpfm/blob/master/LICENSE.
9//---------------------------------------------------------------------------//
10
11//! # IPC Messages Module
12//!
13//! This module defines the core IPC protocol structures used for communication between the RPFM
14//! frontend and backend server.
15//!
16//! ## Overview
17//!
18//! The protocol is built around three main types:
19//!
20//! - [`Message<T>`]: A generic wrapper that adds request-response correlation via unique IDs.
21//! - [`Command`]: An enum defining all actions the frontend can request from the server.
22//! - [`Response`]: An enum defining all possible results the server can return.
23//!
24//! ## Message Correlation
25//!
26//! Every message includes a unique `id` field that allows the frontend to match responses to their
27//! original requests. This enables:
28//!
29//! - **Asynchronous communication**: Multiple requests can be in flight simultaneously.
30//! - **Non-blocking UI**: The frontend doesn't need to wait for responses before sending new requests.
31//! - **Error handling**: Responses can be matched back to the context that initiated them.
32//!
33//! ## Command Categories
34//!
35//! Commands are organized into logical groups:
36//!
37//! - **PackFile Operations**: Open, save, close, and modify PackFiles.
38//! - **PackedFile Operations**: Create, delete, extract, rename, and decode individual files.
39//! - **Dependency Operations**: Query and manage game dependencies.
40//! - **Search Operations**: Global search and reference lookups.
41//! - **Schema Operations**: Load, save, and update table schemas.
42//! - **Settings Operations**: Get and set application settings.
43//! - **Update Operations**: Check for and apply updates to schemas, translations, etc.
44//! - **Diagnostics**: Run diagnostic checks on PackFiles.
45//! - **Navigation**: Go-to-definition and reference search features.
46//!
47//! ## Response Types
48//!
49//! Responses are typically named after the types they contain (e.g., `Response::Bool(bool)`,
50//! `Response::String(String)`). For complex operations, specialized responses like
51//! `Response::DBRFileInfo` or `Response::ContainerInfoVecRFileInfo` carry domain-specific data.
52//!
53//! Each [`Command`] variant's documentation specifies which [`Response`] variant(s) it returns.
54
55use serde::{Serialize, Deserialize};
56
57use std::collections::{BTreeMap, HashMap, HashSet};
58use std::fmt::Debug;
59use std::path::PathBuf;
60
61use rpfm_extensions::dependencies::TableReferences;
62use rpfm_extensions::diagnostics::Diagnostics;
63use rpfm_extensions::optimizer::OptimizerOptions;
64use rpfm_extensions::search::{GlobalSearch, MatchHolder};
65use rpfm_extensions::translator::PackTranslation;
66
67use rpfm_lib::compression::CompressionFormat;
68use rpfm_lib::files::{
69    anim_fragment_battle::AnimFragmentBattle, anims_table::AnimsTable, atlas::Atlas, audio::Audio,
70    bmd::Bmd, db::DB, esf::ESF, group_formations::GroupFormations, image::Image, loc::Loc,
71    matched_combat::MatchedCombat, pack::PackSettings, portrait_settings::PortraitSettings,
72    rigidmodel::RigidModel, text::Text, uic::UIC, unit_variant::UnitVariant,
73    video::SupportedFormats, ContainerPath, RFile, RFileDecoded,
74};
75use rpfm_lib::games::pfh_file_type::PFHFileType;
76use rpfm_lib::integrations::git::GitResponse;
77use rpfm_lib::notes::Note;
78use rpfm_lib::schema::{Definition, DefinitionPatch, Field, Schema};
79
80use crate::helpers::*;
81use crate::settings_keys::SettingsSnapshot;
82
83//-------------------------------------------------------------------------------//
84//                              Enums & Structs
85//-------------------------------------------------------------------------------//
86
87/// This struct is a wrapper for all messages (commands and responses) sent between the UI and the server.
88///
89/// It includes a unique ID to correlate responses with their original requests.
90#[derive(Debug, Serialize, Deserialize)]
91pub struct Message<T: Debug> {
92    pub id: u64,
93    pub data: T,
94}
95
96/// This enum represents the current operational mode for a pack.
97///
98/// A pack can either be in normal mode or in MyMod mode, which links it to
99/// a specific game folder and mod name for import/export operations.
100#[derive(Debug, Default, Clone, Serialize, Deserialize)]
101pub enum OperationalMode {
102
103    /// MyMod mode enabled. Contains the game folder name (e.g. "warhammer_2") and the MyMod pack name.
104    MyMod(String, String),
105
106    /// Normal mode - no MyMod association.
107    #[default]
108    Normal,
109}
110
111
112#[derive(Debug, Clone, Serialize, Deserialize)]
113pub struct CeoEntryData {
114    pub name: String,
115    pub option: String,
116    pub element: String,
117    pub gender: String,
118    pub traits: Vec<(String, String)>, // (uuid, internal_key)
119    pub expanded: bool,
120}
121
122/// This enum defines the commands (messages) you can send to the background thread in order to execute actions.
123///
124/// Each command should include the data needed for his own execution. For a more detailed explanation, check the
125/// docs of each command.
126#[derive(Debug, Serialize, Deserialize)]
127pub enum Command {
128
129    /// Close the background thread. Do not use this command directly.
130    ///
131    /// Response: None (breaks the loop).
132    Exit,
133
134    /// Signal that the client is intentionally disconnecting.
135    ///
136    /// This allows the server to immediately clean up the session's resources instead of
137    /// waiting for the timeout. If this was the last active session, the server will also
138    /// shut down.
139    ///
140    /// Response: [`Response::Success`] (sent before cleanup begins).
141    ClientDisconnecting,
142
143    //-----------------------------------------------------------------------//
144    // PackFile Operations
145    //-----------------------------------------------------------------------//
146
147    /// Closes a specific open Pack identified by its pack key.
148    ///
149    /// Response: [`Response::Success`].
150    ClosePack(String),
151
152    /// Closes all currently open Packs.
153    ///
154    /// Response: [`Response::Success`].
155    CloseAllPacks,
156
157    /// Clean a specific open Pack from corrupted/undecoded files and try to save it to disk.
158    /// First field is the pack key, second is the destination path.
159    ///
160    /// Only use this command if your Pack is not save-able otherwise.
161    ///
162    /// Response:
163    /// - [`Response::ContainerInfo`] on success.
164    /// - [`Response::Error`] on failure.
165    CleanAndSavePackAs(String, PathBuf),
166
167    /// List all currently open packs with their keys and metadata.
168    ///
169    /// Response: [`Response::VecStringContainerInfo`].
170    ListOpenPacks,
171
172    /// Creates a new empty Pack.
173    ///
174    /// Response: [`Response::String`] with the assigned pack key.
175    NewPack,
176
177    /// Save a specific open Pack to disk. The field is the pack key.
178    ///
179    /// Response:
180    /// - [`Response::ContainerInfo`] on success.
181    /// - [`Response::Error`] on failure.
182    SavePack(String),
183
184    /// Save a specific open Pack to a new path.
185    /// First field is the pack key, second is the destination path.
186    ///
187    /// Response:
188    /// - [`Response::ContainerInfo`] on success.
189    /// - [`Response::Error`] on failure.
190    SavePackAs(String, PathBuf),
191
192    /// Get the data used to build the `TreeView` for a specific pack.
193    /// The field is the pack key.
194    ///
195    /// Response:
196    /// - [`Response::ContainerInfoVecRFileInfo`].
197    GetPackFileDataForTreeView(String),
198
199    /// Open one or more `PackFiles` and merge them. Requires the paths of the `PackFiles`].
200    ///
201    /// Response:
202    /// - [`Response::StringContainerInfo`] (pack_key, info) on success.
203    /// - [`Response::Error`] on failure.
204    OpenPackFiles(Vec<PathBuf>),
205
206    /// Open all the CA PackFiles for the selected game as one merged PackFile.
207    ///
208    /// Response:
209    /// - [`Response::StringContainerInfo`] (pack_key, info) on success.
210    /// - [`Response::Error`] on failure.
211    LoadAllCAPackFiles,
212
213    /// Get the `RFileInfo` of one or more `PackedFiles` from a specific pack.
214    /// First field is the pack key, second is the list of file paths.
215    ///
216    /// Response: [`Response::VecRFileInfo`].
217    GetPackedFilesInfo(String, Vec<String>),
218
219    /// Perform a `Global Search` on a specific pack. Requires the pack key and search configuration.
220    ///
221    /// Response:
222    /// - [`Response::GlobalSearchVecRFileInfo`] on success.
223    /// - [`Response::Error`] if no schema.
224    GlobalSearch(String, GlobalSearch),
225
226    /// Change the `Game Selected`]. Contains the game key and whether to rebuild dependencies.
227    ///
228    /// Response:
229    /// - [`Response::CompressionFormatDependenciesInfo`] on success.
230    /// - [`Response::Error`] if game not supported.
231    SetGameSelected(String, bool),
232
233    /// Get the currently selected game key.
234    ///
235    /// Response: [`Response::String`].
236    GetGameSelected,
237
238    /// Change the `Type` of a specific open Pack.
239    /// First field is the pack key, second is the new type.
240    ///
241    /// Response: [`Response::Success`].
242    SetPackFileType(String, PFHFileType),
243
244    /// Generate the dependencies cache for the selected game.
245    ///
246    /// Response:
247    /// - [`Response::DependenciesInfo`] on success.
248    /// - [`Response::Error`] on failure.
249    GenerateDependenciesCache,
250
251    /// Update the currently loaded Schema with data from the game's Assembly Kit.
252    ///
253    /// Response:
254    /// - [`Response::Success`] on success.
255    /// - [`Response::Error`] on failure.
256    UpdateCurrentSchemaFromAssKit,
257
258    /// Trigger an optimization pass over a specific open Pack.
259    /// First field is the pack key, second is the optimizer options.
260    ///
261    /// Response:
262    /// - [`Response::HashSetStringHashSetString`] (deleted paths, added paths) on success.
263    /// - [`Response::Error`] on failure.
264    OptimizePackFile(String, OptimizerOptions),
265
266    /// Patch the SiegeAI of a Siege Map for Warhammer games in a specific pack.
267    /// The field is the pack key.
268    ///
269    /// Response:
270    /// - [`Response::StringVecContainerPath`] on success.
271    /// - [`Response::Error`] on failure.
272    PatchSiegeAI(String),
273
274    /// Change the `Index Includes Timestamp` flag in a specific open Pack.
275    /// First field is the pack key, second is the flag value.
276    ///
277    /// Response: [`Response::Success`].
278    ChangeIndexIncludesTimestamp(String, bool),
279
280    /// Change the compression format of a specific open Pack.
281    /// First field is the pack key, second is the compression format.
282    ///
283    /// Response:
284    /// - [`Response::CompressionFormat`] (the actual format set, may differ if unsupported).
285    ChangeCompressionFormat(String, CompressionFormat),
286
287    /// Get the current path of a specific open Pack.
288    /// The field is the pack key.
289    ///
290    /// Response: [`Response::PathBuf`].
291    GetPackFilePath(String),
292
293    /// Get the info of a single `PackedFile` from a specific pack.
294    /// First field is the pack key, second is the file path.
295    ///
296    /// Response: [`Response::OptionRFileInfo`].
297    GetRFileInfo(String, String),
298
299    //-----------------------------------------------------------------------//
300    // Update Commands
301    //-----------------------------------------------------------------------//
302
303    /// Check if there is an RPFM update available.
304    ///
305    /// Response:
306    /// - [`Response::APIResponse`] on success.
307    /// - [`Response::Error`] on failure.
308    CheckUpdates,
309
310    /// Check if there is a Schema update available.
311    ///
312    /// Response:
313    /// - [`Response::APIResponseGit`] on success.
314    /// - [`Response::Error`] on failure.
315    CheckSchemaUpdates,
316
317    /// Update the schemas from the remote repository.
318    ///
319    /// Response:
320    /// - [`Response::Success`] on success.
321    /// - [`Response::Error`] on failure.
322    UpdateSchemas,
323
324    /// Check if there is a Dependency Database loaded in memory.
325    /// Pass true to ensure dependencies were built with the AssKit.
326    ///
327    /// Response: [`Response::Bool`].
328    IsThereADependencyDatabase(bool),
329
330    //-----------------------------------------------------------------------//
331    // PackedFile Operations
332    //-----------------------------------------------------------------------//
333
334    /// Create a new `PackedFile` inside a specific open Pack.
335    /// First field is the pack key, then path and NewFile info.
336    ///
337    /// Response:
338    /// - [`Response::Success`] on success.
339    /// - [`Response::Error`] on failure.
340    NewPackedFile(String, String, NewFile),
341
342    /// Add one or more Files to a specific open Pack.
343    /// First field is the pack key, then source filesystem paths, destination container paths, optional paths to ignore.
344    ///
345    /// Response:
346    /// - [`Response::VecContainerPathOptionString`] (added paths, optional error message).
347    AddPackedFiles(String, Vec<PathBuf>, Vec<ContainerPath>, Option<Vec<PathBuf>>),
348
349    /// Decode a PackedFile to be shown on the UI.
350    /// First field is the pack key, then the path of the file and its data source.
351    ///
352    /// Response:
353    /// - [`Response::AnimFragmentBattleRFileInfo`] for AnimFragmentBattle files.
354    /// - [`Response::AnimPackRFileInfo`] for AnimPack files.
355    /// - [`Response::AnimsTableRFileInfo`] for AnimsTable files.
356    /// - [`Response::AtlasRFileInfo`] for Atlas files.
357    /// - [`Response::AudioRFileInfo`] for Audio files.
358    /// - [`Response::BmdRFileInfo`] for BMD files.
359    /// - [`Response::DBRFileInfo`] for DB table files.
360    /// - [`Response::ESFRFileInfo`] for ESF files.
361    /// - [`Response::GroupFormationsRFileInfo`] for GroupFormations files.
362    /// - [`Response::ImageRFileInfo`] for Image files.
363    /// - [`Response::LocRFileInfo`] for Loc files.
364    /// - [`Response::MatchedCombatRFileInfo`] for MatchedCombat files.
365    /// - [`Response::PortraitSettingsRFileInfo`] for PortraitSettings files.
366    /// - [`Response::RigidModelRFileInfo`] for RigidModel files.
367    /// - [`Response::TextRFileInfo`] for Text files.
368    /// - [`Response::UICRFileInfo`] for UIC files.
369    /// - [`Response::UnitVariantRFileInfo`] for UnitVariant files.
370    /// - [`Response::VideoInfoRFileInfo`] for Video files.
371    /// - [`Response::VMDRFileInfo`] for VMD files.
372    /// - [`Response::WSModelRFileInfo`] for WSModel files.
373    /// - [`Response::Text`] for pack notes.
374    /// - [`Response::Unknown`] for unsupported types.
375    /// - [`Response::Error`] on failure.
376    DecodePackedFile(String, String, DataSource),
377
378    /// Save an edited `PackedFile` back to a specific Pack.
379    /// First field is the pack key, then path and decoded file data.
380    ///
381    /// Response: [`Response::Success`].
382    SavePackedFileFromView(String, String, RFileDecoded),
383
384    /// Add PackedFiles from one open pack into another.
385    /// First field is the target pack key, second is the source pack key, third is the paths to copy.
386    ///
387    /// Response:
388    /// - [`Response::VecContainerPath`] on success.
389    /// - [`Response::Error`] if source pack not found.
390    AddPackedFilesFromPackFile(String, String, Vec<ContainerPath>),
391
392    /// Add PackedFiles from a specific pack to an AnimPack, which may live in a different pack.
393    /// Fields are the source pack key, the pack key that owns the AnimPack, the animpack path,
394    /// and the container paths to copy.
395    ///
396    /// Response:
397    /// - [`Response::VecContainerPath`] on success.
398    /// - [`Response::Error`] on failure.
399    AddPackedFilesFromPackFileToAnimpack(String, String, String, Vec<ContainerPath>),
400
401    /// Add PackedFiles from an AnimPack to a specific pack, which may differ from the AnimPack's own.
402    /// Fields are the pack key that owns the AnimPack (only used when the data source is a PackFile),
403    /// the destination pack key, the data source, the animpack path, and the container paths.
404    ///
405    /// Response:
406    /// - [`Response::VecContainerPath`] on success.
407    /// - [`Response::Error`] on failure.
408    AddPackedFilesFromAnimpack(String, String, DataSource, String, Vec<ContainerPath>),
409
410    /// Delete PackedFiles from an AnimPack in a specific pack.
411    /// First field is the pack key, then animpack path and container paths.
412    ///
413    /// Response:
414    /// - [`Response::Success`] on success.
415    /// - [`Response::Error`] on failure.
416    DeleteFromAnimpack(String, String, Vec<ContainerPath>),
417
418    /// Delete one or more PackedFiles from a specific pack.
419    /// First field is the pack key, second is the paths to delete.
420    ///
421    /// Response:
422    /// - [`Response::VecContainerPath`] (deleted paths).
423    DeletePackedFiles(String, Vec<ContainerPath>),
424
425    /// Copy one or more PackedFiles to the internal clipboard.
426    /// The field is a map of pack key to the paths to copy from that pack.
427    /// This stores path references in a server-side clipboard for later pasting.
428    ///
429    /// Response:
430    /// - [`Response::Success`] on success.
431    /// - [`Response::Error`] on failure.
432    CopyPackedFiles(BTreeMap<String, Vec<ContainerPath>>),
433
434    /// Cut one or more PackedFiles to the internal clipboard.
435    /// Same as copy, but the files will be removed from the source pack on paste.
436    /// The field is a map of pack key to the paths to cut from that pack.
437    ///
438    /// Response:
439    /// - [`Response::Success`] on success.
440    /// - [`Response::Error`] on failure.
441    CutPackedFiles(BTreeMap<String, Vec<ContainerPath>>),
442
443    /// Paste PackedFiles from the internal clipboard into a pack.
444    /// First field is the target pack key, second is the destination folder path.
445    ///
446    /// Response:
447    /// - [`Response::VecContainerPathVecContainerPathString`] (added paths, cut-deleted paths, source pack key) on success.
448    /// - [`Response::Error`] on failure.
449    PastePackedFiles(String, String),
450
451    /// Duplicate one or more PackedFiles in-place within the same pack.
452    /// First field is the pack key, second is the paths to duplicate.
453    /// Files are cloned with a numeric suffix added to avoid name collisions.
454    ///
455    /// Response:
456    /// - [`Response::VecContainerPath`] (new duplicated paths) on success.
457    /// - [`Response::Error`] on failure.
458    DuplicatePackedFiles(String, Vec<ContainerPath>),
459
460    /// Extract one or more PackedFiles from a pack.
461    /// First field is the pack key, then paths by data source, extraction path, whether to export tables as TSV.
462    ///
463    /// Response:
464    /// - [`Response::StringVecPathBuf`] on success.
465    /// - [`Response::Error`] on failure.
466    ExtractPackedFiles(String, BTreeMap<DataSource, Vec<ContainerPath>>, PathBuf, bool),
467
468    /// Rename one or more PackedFiles in a specific pack.
469    /// First field is the pack key, second is a Vec with original and new ContainerPaths.
470    ///
471    /// Response:
472    /// - [`Response::VecContainerPathContainerPath`] on success.
473    /// - [`Response::Error`] on failure.
474    RenamePackedFiles(String, Vec<(ContainerPath, ContainerPath)>),
475
476    /// Check if a folder exists in a specific open PackFile.
477    /// First field is the pack key, second is the folder path.
478    ///
479    /// Response: [`Response::Bool`].
480    FolderExists(String, String),
481
482    /// Check if a PackedFile exists in a specific open PackFile.
483    /// First field is the pack key, second is the file path.
484    ///
485    /// Response: [`Response::Bool`].
486    PackedFileExists(String, String),
487
488    //-----------------------------------------------------------------------//
489    // Dependency Commands
490    //-----------------------------------------------------------------------//
491
492    /// Get the table names of all DB files in dependency PackFiles.
493    ///
494    /// Response: [`Response::VecString`].
495    GetTableListFromDependencyPackFile,
496
497    /// Get custom table names (start_pos_, twad_ prefixes) from the schema.
498    ///
499    /// Response:
500    /// - [`Response::VecString`] on success.
501    /// - [`Response::Error`] if no schema.
502    GetCustomTableList,
503
504    /// Get local art set IDs from campaign_character_arts_tables in a specific pack.
505    /// The field is the pack key.
506    ///
507    /// Response: [`Response::HashSetString`].
508    LocalArtSetIds(String),
509
510    /// Get art set IDs from dependencies' campaign_character_arts_tables.
511    ///
512    /// Response: [`Response::HashSetString`].
513    DependenciesArtSetIds,
514
515    /// Get the version of a table from the dependency database.
516    ///
517    /// Response:
518    /// - [`Response::I32`] on success.
519    /// - [`Response::Error`] if not found or dependencies not loaded.
520    GetTableVersionFromDependencyPackFile(String),
521
522    /// Get the definition of a table from the dependency database.
523    ///
524    /// Response:
525    /// - [`Response::Definition`] on success.
526    /// - [`Response::Error`] if not found.
527    GetTableDefinitionFromDependencyPackFile(String),
528
529    /// Merge multiple compatible tables into one in a specific pack.
530    /// First field is the pack key, then paths to merge, merged file path, delete source flag.
531    ///
532    /// Response:
533    /// - [`Response::String`] (merged path) on success.
534    /// - [`Response::Error`] on failure.
535    MergeFiles(String, Vec<ContainerPath>, String, bool),
536
537    /// Update a table to a newer version in a specific pack.
538    /// First field is the pack key, second is the container path.
539    ///
540    /// Response:
541    /// - [`Response::I32I32VecStringVecString`] (old_version, new_version, deleted_fields, added_fields) on success.
542    /// - [`Response::Error`] on failure.
543    UpdateTable(String, ContainerPath),
544
545    //-----------------------------------------------------------------------//
546    // Search Commands
547    //-----------------------------------------------------------------------//
548
549    /// Replace specific matches in a Global Search on a specific pack.
550    /// First field is the pack key, then search config and match holders.
551    ///
552    /// Response:
553    /// - [`Response::GlobalSearchVecRFileInfo`] on success.
554    /// - [`Response::Error`] if no schema.
555    GlobalSearchReplaceMatches(String, GlobalSearch, Vec<MatchHolder>),
556
557    /// Replace all matches in a Global Search on a specific pack.
558    /// First field is the pack key, second is the search config.
559    ///
560    /// Response:
561    /// - [`Response::GlobalSearchVecRFileInfo`] on success.
562    /// - [`Response::Error`] if no schema.
563    GlobalSearchReplaceAll(String, GlobalSearch),
564
565    /// Get reference data for columns in a definition from a specific pack.
566    /// First field is the pack key, then table name, definition, force flag.
567    ///
568    /// Response: [`Response::HashMapI32TableReferences`].
569    GetReferenceDataFromDefinition(String, String, Definition, bool),
570
571    /// Get the list of PackFiles marked as dependencies of a specific pack.
572    /// The field is the pack key.
573    ///
574    /// Response: [`Response::VecBoolString`].
575    GetDependencyPackFilesList(String),
576
577    /// Set the list of PackFiles marked as dependencies of a specific pack.
578    /// First field is the pack key, second is the dependency list.
579    ///
580    /// Response: [`Response::Success`].
581    SetDependencyPackFilesList(String, Vec<(bool, String)>),
582
583    /// Get PackedFiles from all known sources (PackFile, GameFiles, ParentFiles).
584    /// Requires: paths to get, whether to lowercase paths.
585    ///
586    /// Response: [`Response::HashMapDataSourceHashMapStringRFile`].
587    GetRFilesFromAllSources(Vec<ContainerPath>, bool),
588
589    //-----------------------------------------------------------------------//
590    // Video Commands
591    //-----------------------------------------------------------------------//
592
593    /// Change the format of a ca_vp8 video PackedFile in a specific pack.
594    /// First field is the pack key, then file path and format.
595    ///
596    /// Response:
597    /// - [`Response::Success`] on success.
598    /// - [`Response::Error`] on failure.
599    SetVideoFormat(String, String, SupportedFormats),
600
601    //-----------------------------------------------------------------------//
602    // Schema Commands
603    //-----------------------------------------------------------------------//
604
605    /// Save the provided schema to disk.
606    ///
607    /// Response:
608    /// - [`Response::Success`] on success.
609    /// - [`Response::Error`] on failure.
610    SaveSchema(Schema),
611
612    /// Encode and clean the cache for the provided paths in a specific pack.
613    /// First field is the pack key, second is the paths to clean.
614    ///
615    /// Response: [`Response::Success`].
616    CleanCache(String, Vec<ContainerPath>),
617
618    //-----------------------------------------------------------------------//
619    // TSV Commands
620    //-----------------------------------------------------------------------//
621
622    /// Export a table as TSV from a specific pack.
623    /// First field is the pack key, then internal path, destination path, data source.
624    ///
625    /// Response:
626    /// - [`Response::Success`] on success.
627    /// - [`Response::Error`] on failure.
628    ExportTSV(String, String, PathBuf, DataSource),
629
630    /// Import a TSV as a table into a specific pack.
631    /// First field is the pack key, then internal path, source TSV path.
632    ///
633    /// Response:
634    /// - [`Response::RFileDecoded`] on success.
635    /// - [`Response::Error`] on failure.
636    ImportTSV(String, String, PathBuf),
637
638    //-----------------------------------------------------------------------//
639    // External Program Commands
640    //-----------------------------------------------------------------------//
641
642    /// Open the folder containing a specific open PackFile in the file manager.
643    /// The field is the pack key.
644    ///
645    /// Response:
646    /// - [`Response::Success`] on success.
647    /// - [`Response::Error`] if pack doesn't exist on disk.
648    OpenContainingFolder(String),
649
650    /// Open a PackedFile in an external program.
651    /// First field is the pack key, then data source and container path.
652    ///
653    /// Response:
654    /// - [`Response::PathBuf`] (extracted path) on success.
655    /// - [`Response::Error`] on failure.
656    OpenPackedFileInExternalProgram(String, DataSource, ContainerPath),
657
658    /// Save a PackedFile from an external program to a specific pack.
659    /// First field is the pack key, then internal path, external file path.
660    ///
661    /// Response:
662    /// - [`Response::Success`] on success.
663    /// - [`Response::Error`] on failure.
664    SavePackedFileFromExternalView(String, String, PathBuf),
665
666    //-----------------------------------------------------------------------//
667    // Program Update Commands
668    //-----------------------------------------------------------------------//
669
670    /// Update the program to the latest version available.
671    ///
672    /// Response:
673    /// - [`Response::Success`] on success.
674    /// - [`Response::Error`] on failure.
675    UpdateMainProgram,
676
677    /// Trigger an autosave to a backup for a specific pack.
678    /// The field is the pack key.
679    ///
680    /// Response: [`Response::Success`].
681    TriggerBackupAutosave(String),
682
683    //-----------------------------------------------------------------------//
684    // Diagnostics Commands
685    //-----------------------------------------------------------------------//
686
687    /// Trigger a full diagnostics check over all open Packs.
688    /// First field is ignored diagnostics, then check AK-only references.
689    ///
690    /// Response: [`Response::Diagnostics`].
691    DiagnosticsCheck(Vec<String>, bool),
692
693    /// Trigger a partial diagnostics update over all open packs.
694    /// First field is existing diagnostics, then paths to check, check AK-only references.
695    ///
696    /// Response: [`Response::Diagnostics`].
697    DiagnosticsUpdate(Diagnostics, Vec<ContainerPath>, bool),
698
699    //-----------------------------------------------------------------------//
700    // Pack Settings Commands
701    //-----------------------------------------------------------------------//
702
703    /// Get the settings of a specific open PackFile.
704    /// The field is the pack key.
705    ///
706    /// Response: [`Response::PackSettings`].
707    GetPackSettings(String),
708
709    /// Set the settings of a specific open PackFile.
710    /// First field is the pack key, second is the settings.
711    ///
712    /// Response: [`Response::Success`].
713    SetPackSettings(String, PackSettings),
714
715    //-----------------------------------------------------------------------//
716    // Debug Commands
717    //-----------------------------------------------------------------------//
718
719    /// Export missing table definitions from a specific pack to a file (for debugging).
720    /// The field is the pack key.
721    ///
722    /// Response: [`Response::Success`].
723    GetMissingDefinitions(String),
724
725    //-----------------------------------------------------------------------//
726    // Dependencies Commands
727    //-----------------------------------------------------------------------//
728
729    /// Rebuild the dependencies.
730    /// Pass true to rebuild all dependencies, false for mod-specific only.
731    ///
732    /// Response:
733    /// - [`Response::DependenciesInfo`] on success.
734    /// - [`Response::Error`] if no schema.
735    RebuildDependencies(bool),
736
737    //-----------------------------------------------------------------------//
738    // Cascade Edition Commands
739    //-----------------------------------------------------------------------//
740
741    /// Trigger a cascade edition on all referenced data in a specific pack.
742    /// First field is the pack key, then table name, definition, list of (field, old_value, new_value).
743    ///
744    /// Response: [`Response::VecContainerPathVecRFileInfo`].
745    CascadeEdition(String, String, Definition, Vec<(Field, String, String)>),
746
747    //-----------------------------------------------------------------------//
748    // Navigation Commands
749    //-----------------------------------------------------------------------//
750
751    /// Go to the definition of a reference in a specific pack.
752    /// First field is the pack key, then table, column, values to search.
753    ///
754    /// Response:
755    /// - [`Response::DataSourceStringUsizeUsize`] on success.
756    /// - [`Response::Error`] if not found.
757    GoToDefinition(String, String, String, Vec<String>),
758
759    /// Get the source data of a loc key from a specific pack.
760    /// First field is the pack key, second is the loc key.
761    ///
762    /// Response: [`Response::OptionStringStringVecString`].
763    GetSourceDataFromLocKey(String, String),
764
765    /// Go to a loc key's location in a specific pack.
766    /// First field is the pack key, second is the loc key to search.
767    ///
768    /// Response:
769    /// - [`Response::DataSourceStringUsizeUsize`] on success.
770    /// - [`Response::Error`] if not found.
771    GoToLoc(String, String),
772
773    /// Find all references to a value in a specific pack.
774    /// First field is the pack key, then map of table -> columns to search, value to search.
775    ///
776    /// Response: [`Response::VecDataSourceStringStringStringUsizeUsize`].
777    SearchReferences(String, HashMap<String, Vec<String>>, String),
778
779    /// Get the name of a specific open PackFile.
780    /// The field is the pack key.
781    ///
782    /// Response: [`Response::String`].
783    GetPackFileName(String),
784
785    /// Get the raw binary data of a PackedFile from a specific pack.
786    /// First field is the pack key, second is the file path.
787    ///
788    /// Response:
789    /// - [`Response::VecU8`] on success.
790    /// - [`Response::Error`] on failure.
791    GetPackedFileRawData(String, String),
792
793    /// Import files from dependencies into a specific open PackFile.
794    /// First field is the pack key, second is the paths by data source.
795    ///
796    /// Response:
797    /// - [`Response::VecContainerPathVecString`] (added paths, failed paths).
798    /// - [`Response::Error`] on failure.
799    ImportDependenciesToOpenPackFile(String, BTreeMap<DataSource, Vec<ContainerPath>>),
800
801    /// Save PackedFiles to a specific PackFile and optionally optimize.
802    /// First field is the pack key, then files to save, whether to optimize.
803    ///
804    /// Response:
805    /// - [`Response::VecContainerPathVecContainerPath`] (added paths, deleted paths) on success.
806    /// - [`Response::Error`] on failure.
807    SavePackedFilesToPackFileAndClean(String, Vec<RFile>, bool),
808
809    /// Get all file names under a path in all dependencies.
810    ///
811    /// Response: [`Response::HashMapDataSourceHashSetContainerPath`].
812    GetPackedFilesNamesStartingWitPathFromAllSources(ContainerPath),
813
814    //-----------------------------------------------------------------------//
815    // Notes Commands
816    //-----------------------------------------------------------------------//
817
818    /// Get all notes under a path in a specific pack.
819    /// First field is the pack key, second is the path.
820    ///
821    /// Response: [`Response::VecNote`].
822    NotesForPath(String, String),
823
824    /// Add a note to a specific pack.
825    /// First field is the pack key, second is the note.
826    ///
827    /// Response: [`Response::Note`].
828    AddNote(String, Note),
829
830    /// Delete a note from a specific pack.
831    /// First field is the pack key, then path and note ID.
832    ///
833    /// Response: [`Response::Success`].
834    DeleteNote(String, String, u64),
835
836    //-----------------------------------------------------------------------//
837    // Schema Patch Commands
838    //-----------------------------------------------------------------------//
839
840    /// Save local schema patches.
841    ///
842    /// Response:
843    /// - [`Response::Success`] on success.
844    /// - [`Response::Error`] on failure.
845    SaveLocalSchemaPatch(HashMap<String, DefinitionPatch>),
846
847    /// Remove local schema patches for a table.
848    ///
849    /// Response:
850    /// - [`Response::Success`] on success.
851    /// - [`Response::Error`] on failure.
852    RemoveLocalSchemaPatchesForTable(String),
853
854    /// Remove local schema patches for a specific field in a table.
855    ///
856    /// Response:
857    /// - [`Response::Success`] on success.
858    /// - [`Response::Error`] on failure.
859    RemoveLocalSchemaPatchesForTableAndField(String, String),
860
861    /// Import a schema patch into the local schema patches.
862    ///
863    /// Response:
864    /// - [`Response::Success`] on success.
865    /// - [`Response::Error`] on failure.
866    ImportSchemaPatch(HashMap<String, DefinitionPatch>),
867
868    //-----------------------------------------------------------------------//
869    // Loc Generation Commands
870    //-----------------------------------------------------------------------//
871
872    /// Generate all missing loc entries for a specific open PackFile.
873    /// The field is the pack key.
874    ///
875    /// Response:
876    /// - [`Response::VecContainerPath`] on success.
877    /// - [`Response::Error`] on failure.
878    GenerateMissingLocData(String),
879
880    //-----------------------------------------------------------------------//
881    // Lua Autogen Commands
882    //-----------------------------------------------------------------------//
883
884    /// Check for updates on the tw_autogen repository.
885    ///
886    /// Response:
887    /// - [`Response::APIResponseGit`] on success.
888    /// - [`Response::Error`] on failure.
889    CheckLuaAutogenUpdates,
890
891    /// Update the tw_autogen repository.
892    ///
893    /// Response:
894    /// - [`Response::Success`] on success.
895    /// - [`Response::Error`] on failure.
896    UpdateLuaAutogen,
897
898    //-----------------------------------------------------------------------//
899    // MyMod Commands
900    //-----------------------------------------------------------------------//
901
902    /// Initialize a MyMod folder.
903    /// Requires: mod name, game key, sublime support, vscode support, git support (gitignore content).
904    ///
905    /// Response:
906    /// - [`Response::PathBuf`] (path to the new pack) on success.
907    /// - [`Response::Error`] on failure.
908    InitializeMyModFolder(String, String, bool, bool, Option<String>),
909
910    /// Live export a specific PackFile to the game folder.
911    /// The field is the pack key.
912    ///
913    /// Response:
914    /// - [`Response::Success`] on success.
915    /// - [`Response::Error`] on failure.
916    LiveExport(String),
917
918    /// Set the operational mode for a specific pack.
919    /// First field is the pack key, second is the new operational mode.
920    ///
921    /// Response: [`Response::Success`].
922    SetPackOperationalMode(String, OperationalMode),
923
924    /// Get the operational mode for a specific pack.
925    /// The field is the pack key.
926    ///
927    /// Response: [`Response::OperationalMode`].
928    GetPackOperationalMode(String),
929
930    //-----------------------------------------------------------------------//
931    // Map Packing Commands
932    //-----------------------------------------------------------------------//
933
934    /// Pack map tiles into a specific PackFile.
935    /// First field is the pack key, then tile map paths, list of (tile path, name).
936    ///
937    /// Response:
938    /// - [`Response::VecContainerPathVecContainerPath`] (added paths, deleted paths) on success.
939    /// - [`Response::Error`] on failure.
940    PackMap(String, Vec<PathBuf>, Vec<(PathBuf, String)>),
941
942    //-----------------------------------------------------------------------//
943    // Diagnostics Ignore Commands
944    //-----------------------------------------------------------------------//
945
946    /// Add a line to a specific pack's ignored diagnostics.
947    /// First field is the pack key, second is the diagnostic line.
948    ///
949    /// Response: [`Response::Success`].
950    AddLineToPackIgnoredDiagnostics(String, String),
951
952    //-----------------------------------------------------------------------//
953    // Empire/Napoleon AK Commands
954    //-----------------------------------------------------------------------//
955
956    /// Check for updates on the old AK files repository.
957    ///
958    /// Response:
959    /// - [`Response::APIResponseGit`] on success.
960    /// - [`Response::Error`] on failure.
961    CheckEmpireAndNapoleonAKUpdates,
962
963    /// Update the old AK files repository.
964    ///
965    /// Response:
966    /// - [`Response::Success`] on success.
967    /// - [`Response::Error`] on failure.
968    UpdateEmpireAndNapoleonAK,
969
970    //-----------------------------------------------------------------------//
971    // Translation Commands
972    //-----------------------------------------------------------------------//
973
974    /// Get pack translation data for a language from a specific pack.
975    /// First field is the pack key, second is the language.
976    ///
977    /// Response:
978    /// - [`Response::PackTranslation`] on success.
979    /// - [`Response::Error`] on failure.
980    GetPackTranslation(String, String),
981
982    /// Check for translation updates.
983    ///
984    /// Response:
985    /// - [`Response::APIResponseGit`] on success.
986    /// - [`Response::Error`] on failure.
987    CheckTranslationsUpdates,
988
989    /// Update the translations repository.
990    ///
991    /// Response:
992    /// - [`Response::Success`] on success.
993    /// - [`Response::Error`] on failure.
994    UpdateTranslations,
995
996    //-----------------------------------------------------------------------//
997    // Starpos Commands
998    //-----------------------------------------------------------------------//
999
1000    /// Build starpos (pre-processing step) for a specific pack.
1001    /// First field is the pack key, then campaign ID, process HLP/SPD data.
1002    ///
1003    /// Response:
1004    /// - [`Response::Success`] on success.
1005    /// - [`Response::Error`] on failure.
1006    BuildStarpos(String, String, bool),
1007
1008    /// Build starpos (post-processing step) for a specific pack.
1009    /// First field is the pack key, then campaign ID, process HLP/SPD data.
1010    ///
1011    /// Response:
1012    /// - [`Response::VecContainerPath`] on success.
1013    /// - [`Response::Error`] on failure.
1014    BuildStarposPost(String, String, bool),
1015
1016    /// Clean up starpos temporary files for a specific pack.
1017    /// First field is the pack key, then campaign ID, process HLP/SPD data.
1018    ///
1019    /// Response:
1020    /// - [`Response::Success`] on success.
1021    /// - [`Response::Error`] on failure.
1022    BuildStarposCleanup(String, String, bool),
1023
1024    /// Get campaign IDs for starpos building from a specific pack.
1025    /// The field is the pack key.
1026    ///
1027    /// Response: [`Response::HashSetString`].
1028    BuildStarposGetCampaingIds(String),
1029
1030    /// Check if victory conditions file exists in a specific pack (required for some games).
1031    /// The field is the pack key.
1032    ///
1033    /// Response:
1034    /// - [`Response::Success`] if exists or not needed.
1035    /// - [`Response::Error`] if missing.
1036    BuildStarposCheckVictoryConditions(String),
1037
1038
1039    //-----------------------------------------------------------------------//
1040    // CEO Commands
1041    //-----------------------------------------------------------------------//
1042
1043    BuildCeo(String, String, String),
1044
1045    /// Import ceo_data.ccd into the open pack after BOB has run.
1046    /// Field is the pack key.
1047    ///
1048    /// Response:
1049    /// - [`Response::VecContainerPath`] on success.
1050    /// - [`Response::Error`] on failure.
1051    BuildCeoPost(String, String),  // pack_key, akit_path
1052
1053    BuildCeoEntries(String, Vec<CeoEntryData>),  // pack_key, entries
1054
1055
1056    GetTraitCeos,
1057
1058    //-----------------------------------------------------------------------//
1059    // Animation Commands
1060    //-----------------------------------------------------------------------//
1061
1062    /// Update animation IDs with offset in a specific pack.
1063    /// First field is the pack key, then starting ID, offset.
1064    ///
1065    /// Response:
1066    /// - [`Response::VecContainerPath`] on success.
1067    /// - [`Response::Error`] on failure.
1068    UpdateAnimIds(String, i32, i32),
1069
1070    /// Get animation paths by skeleton name.
1071    ///
1072    /// Response: [`Response::HashSetString`].
1073    GetAnimPathsBySkeletonName(String),
1074
1075    //-----------------------------------------------------------------------//
1076    // Table Commands
1077    //-----------------------------------------------------------------------//
1078
1079    /// Get tables from dependencies by table name.
1080    ///
1081    /// Response:
1082    /// - [`Response::VecRFile`] on success.
1083    /// - [`Response::Error`] on failure.
1084    GetTablesFromDependencies(String),
1085
1086    /// Get table paths by table name from a specific PackFile.
1087    /// First field is the pack key, second is the table name.
1088    ///
1089    /// Response: [`Response::VecString`].
1090    GetTablesByTableName(String, String),
1091
1092    /// Add keys to the key_deletes table in a specific pack.
1093    /// First field is the pack key, then table file name, key table name, keys to add.
1094    ///
1095    /// Response: [`Response::OptionContainerPath`].
1096    AddKeysToKeyDeletes(String, String, String, HashSet<String>),
1097
1098    //-----------------------------------------------------------------------//
1099    // 3D Export Commands
1100    //-----------------------------------------------------------------------//
1101
1102    /// Export a RigidModel to glTF format.
1103    /// Requires: RigidModel, output path.
1104    ///
1105    /// Response:
1106    /// - [`Response::Success`] on success.
1107    /// - [`Response::Error`] on failure.
1108    ExportRigidToGltf(RigidModel, String),
1109
1110    //-----------------------------------------------------------------------//
1111    // Settings Getter Commands
1112    //-----------------------------------------------------------------------//
1113
1114    /// Get a boolean setting value.
1115    ///
1116    /// Response: [`Response::Bool`].
1117    SettingsGetBool(String),
1118
1119    /// Get an i32 setting value.
1120    ///
1121    /// Response: [`Response::I32`].
1122    SettingsGetI32(String),
1123
1124    /// Get an f32 setting value.
1125    ///
1126    /// Response: [`Response::F32`].
1127    SettingsGetF32(String),
1128
1129    /// Get a string setting value.
1130    ///
1131    /// Response: [`Response::String`].
1132    SettingsGetString(String),
1133
1134    /// Get a PathBuf setting value.
1135    ///
1136    /// Response: [`Response::PathBuf`].
1137    SettingsGetPathBuf(String),
1138
1139    /// Get a `Vec<String>` setting value.
1140    ///
1141    /// Response: [`Response::VecString`].
1142    SettingsGetVecString(String),
1143
1144    /// Get raw data setting value.
1145    ///
1146    /// Response: [`Response::VecU8`].
1147    SettingsGetVecRaw(String),
1148
1149    /// Get all settings at once (for batch loading).
1150    ///
1151    /// This is much more efficient than calling individual SettingsGet* commands
1152    /// when you need multiple settings, as it requires only one IPC round-trip.
1153    ///
1154    /// Response: [`Response::SettingsAll`].
1155    SettingsGetAll,
1156
1157    //-----------------------------------------------------------------------//
1158    // Settings Setter Commands
1159    //-----------------------------------------------------------------------//
1160
1161    /// Set a boolean setting value.
1162    ///
1163    /// Response:
1164    /// - [`Response::Success`] on success.
1165    /// - [`Response::Error`] on failure.
1166    SettingsSetBool(String, bool),
1167
1168    /// Set an i32 setting value.
1169    ///
1170    /// Response:
1171    /// - [`Response::Success`] on success.
1172    /// - [`Response::Error`] on failure.
1173    SettingsSetI32(String, i32),
1174
1175    /// Set an f32 setting value.
1176    ///
1177    /// Response:
1178    /// - [`Response::Success`] on success.
1179    /// - [`Response::Error`] on failure.
1180    SettingsSetF32(String, f32),
1181
1182    /// Set a string setting value.
1183    ///
1184    /// Response:
1185    /// - [`Response::Success`] on success.
1186    /// - [`Response::Error`] on failure.
1187    SettingsSetString(String, String),
1188
1189    /// Set a PathBuf setting value.
1190    ///
1191    /// Response:
1192    /// - [`Response::Success`] on success.
1193    /// - [`Response::Error`] on failure.
1194    SettingsSetPathBuf(String, PathBuf),
1195
1196    /// Set a `Vec<String>` setting value.
1197    ///
1198    /// Response:
1199    /// - [`Response::Success`] on success.
1200    /// - [`Response::Error`] on failure.
1201    SettingsSetVecString(String, Vec<String>),
1202
1203    /// Set raw data setting value.
1204    ///
1205    /// Response:
1206    /// - [`Response::Success`] on success.
1207    /// - [`Response::Error`] on failure.
1208    SettingsSetVecRaw(String, Vec<u8>),
1209
1210    //-----------------------------------------------------------------------//
1211    // Path Commands
1212    //-----------------------------------------------------------------------//
1213
1214    /// Get the config path.
1215    ///
1216    /// Response:
1217    /// - [`Response::PathBuf`] on success.
1218    /// - [`Response::Error`] on failure.
1219    ConfigPath,
1220
1221    /// Get the Assembly Kit path for the current game.
1222    ///
1223    /// Response:
1224    /// - [`Response::PathBuf`] on success.
1225    /// - [`Response::Error`] on failure.
1226    AssemblyKitPath,
1227
1228    /// Get the backup autosave path.
1229    ///
1230    /// Response:
1231    /// - [`Response::PathBuf`] on success.
1232    /// - [`Response::Error`] on failure.
1233    BackupAutosavePath,
1234
1235    /// Get the old AK data path.
1236    ///
1237    /// Response:
1238    /// - [`Response::PathBuf`] on success.
1239    /// - [`Response::Error`] on failure.
1240    OldAkDataPath,
1241
1242    /// Get the schemas path.
1243    ///
1244    /// Response:
1245    /// - [`Response::PathBuf`] on success.
1246    /// - [`Response::Error`] on failure.
1247    SchemasPath,
1248
1249    /// Get the table profiles path.
1250    ///
1251    /// Response:
1252    /// - [`Response::PathBuf`] on success.
1253    /// - [`Response::Error`] on failure.
1254    TableProfilesPath,
1255
1256    /// Get the translations local path.
1257    ///
1258    /// Response:
1259    /// - [`Response::PathBuf`] on success.
1260    /// - [`Response::Error`] on failure.
1261    TranslationsLocalPath,
1262
1263    /// Get the dependencies cache path.
1264    ///
1265    /// Response:
1266    /// - [`Response::PathBuf`] on success.
1267    /// - [`Response::Error`] on failure.
1268    DependenciesCachePath,
1269
1270    /// Clear a config path.
1271    ///
1272    /// Response:
1273    /// - [`Response::Success`] on success.
1274    /// - [`Response::Error`] on failure.
1275    SettingsClearPath(PathBuf),
1276
1277    /// Get the user-configured custom config folder (empty path if RPFM uses the default one).
1278    ///
1279    /// Response:
1280    /// - [`Response::PathBuf`] on success.
1281    /// - [`Response::Error`] on failure.
1282    CustomConfigPath,
1283
1284    /// Set the custom config folder, or clear it when given an empty path. Takes effect on restart.
1285    ///
1286    /// Response:
1287    /// - [`Response::Success`] on success.
1288    /// - [`Response::Error`] on failure.
1289    SetCustomConfigPath(PathBuf),
1290
1291    //-----------------------------------------------------------------------//
1292    // Settings Backup Commands
1293    //-----------------------------------------------------------------------//
1294
1295    /// Backup the current settings to memory.
1296    ///
1297    /// Response: [`Response::Success`].
1298    BackupSettings,
1299
1300    /// Clear settings and reset to defaults.
1301    ///
1302    /// Response:
1303    /// - [`Response::Success`] on success.
1304    /// - [`Response::Error`] on failure.
1305    ClearSettings,
1306
1307    /// Restore settings from the backup.
1308    ///
1309    /// Response: [`Response::Success`].
1310    RestoreBackupSettings,
1311
1312    /// Get the optimizer options.
1313    ///
1314    /// Response: [`Response::OptimizerOptions`].
1315    OptimizerOptions,
1316
1317    //-----------------------------------------------------------------------//
1318    // Schema Query Commands
1319    //-----------------------------------------------------------------------//
1320
1321    /// Check if a schema is loaded.
1322    ///
1323    /// Response: [`Response::Bool`].
1324    IsSchemaLoaded,
1325
1326    /// Get all definitions for a table name.
1327    ///
1328    /// Response:
1329    /// - [`Response::VecDefinition`] on success.
1330    /// - [`Response::Error`] if no schema.
1331    DefinitionsByTableName(String),
1332
1333    /// Get columns that reference a table's definition.
1334    ///
1335    /// Response:
1336    /// - [`Response::HashMapStringHashMapStringVecString`] on success.
1337    /// - [`Response::Error`] if no schema.
1338    ReferencingColumnsForDefinition(String, Definition),
1339
1340    /// Get the current schema.
1341    ///
1342    /// Response:
1343    /// - [`Response::Schema`] on success.
1344    /// - [`Response::Error`] if no schema.
1345    Schema,
1346
1347    /// Get a specific definition by table name and version.
1348    ///
1349    /// Response:
1350    /// - [`Response::Definition`] on success.
1351    /// - [`Response::Error`] if not found or no schema.
1352    DefinitionByTableNameAndVersion(String, i32),
1353
1354    /// Delete a definition by table name and version.
1355    ///
1356    /// Response: [`Response::Success`].
1357    DeleteDefinition(String, i32),
1358
1359    /// Get the processed fields from a definition (bitwise expansion, enum conversion, colour merging applied).
1360    ///
1361    /// Response: [`Response::VecField`].
1362    FieldsProcessed(Definition),
1363
1364    /// List the user plugin scripts available under the config `scripts` folder.
1365    ///
1366    /// Response: [`Response::VecString`] with the absolute path of each script.
1367    GetPluginScripts,
1368
1369    /// Run a plugin script against a selection of files/folders from an open Pack.
1370    ///
1371    /// First field is the pack key, then the absolute path of the script to run, then the
1372    /// selected container paths. The selected files are extracted to a temp folder mirroring
1373    /// their in-pack structure (DB/Loc tables as TSV, everything else as raw binary), the script
1374    /// is run with those file paths as arguments, and their (possibly modified) contents are read
1375    /// back into the Pack afterwards.
1376    ///
1377    /// Response:
1378    /// - [`Response::VecContainerPathOptionString`] (re-imported paths, optional script output/error message).
1379    /// - [`Response::Error`] on failure.
1380    RunPluginScript(String, PathBuf, Vec<ContainerPath>),
1381}
1382
1383/// This enum defines the responses (messages) you can send to the UI thread as result of a command.
1384///
1385/// Each response is named after the types of the items it carries, making them self-documenting.
1386/// For example, `VecString` returns a `Vec<String>`, and `DBRFileInfo` returns a `(DB, RFileInfo)` tuple.
1387#[derive(Debug, Serialize, Deserialize)]
1388pub enum Response {
1389    /// Generic response for situations of success where no data needs to be returned.
1390    Success,
1391
1392    /// Generic response for situations that returned an error, containing the error message.
1393    Error(String),
1394
1395    /// Response sent by the server immediately after a WebSocket connection is established.
1396    /// Contains the session ID that the client is connected to.
1397    SessionConnected(u64),
1398
1399    #[allow(dead_code)]BmdRFileInfo(Box<Bmd>, RFileInfo),
1400    AnimFragmentBattleRFileInfo(AnimFragmentBattle, RFileInfo),
1401    AnimPackRFileInfo(Vec<RFileInfo>, RFileInfo),
1402    AnimsTableRFileInfo(AnimsTable, RFileInfo),
1403    APIResponse(APIResponse),
1404    APIResponseGit(GitResponse),
1405    AtlasRFileInfo(Atlas, RFileInfo),
1406    AudioRFileInfo(Audio, RFileInfo),
1407    Bool(bool),
1408    CompressionFormat(CompressionFormat),
1409    CompressionFormatDependenciesInfo(CompressionFormat, Option<DependenciesInfo>),
1410    ContainerInfo(ContainerInfo),
1411    ContainerInfoVecRFileInfo((ContainerInfo, Vec<RFileInfo>)),
1412    StringContainerInfo(String, ContainerInfo),
1413    DataSourceStringUsizeUsize(DataSource, String, usize, usize),
1414    DBRFileInfo(DB, RFileInfo),
1415    Definition(Definition),
1416    DependenciesInfo(DependenciesInfo),
1417    Diagnostics(Diagnostics),
1418    ESFRFileInfo(ESF, RFileInfo),
1419    F32(f32),
1420    GlobalSearchVecRFileInfo(Box<GlobalSearch>, Vec<RFileInfo>),
1421    GroupFormationsRFileInfo(GroupFormations, RFileInfo),
1422    HashMapDataSourceHashMapStringRFile(HashMap<DataSource, HashMap<String, RFile>>),
1423    HashMapDataSourceHashSetContainerPath(HashMap<DataSource, HashSet<ContainerPath>>),
1424    HashMapI32TableReferences(HashMap<i32, TableReferences>),
1425    HashMapStringHashMapStringVecString(HashMap<String, HashMap<String, Vec<String>>>),
1426    HashSetString(HashSet<String>),
1427    HashSetStringHashSetString(HashSet<String>, HashSet<String>),
1428    I32(i32),
1429    I32I32(i32, i32),
1430    I32I32VecStringVecString(i32, i32, Vec<String>, Vec<String>),
1431    ImageRFileInfo(Image, RFileInfo),
1432    LocRFileInfo(Loc, RFileInfo),
1433    MatchedCombatRFileInfo(MatchedCombat, RFileInfo),
1434    Note(Note),
1435    OperationalMode(OperationalMode),
1436    OptimizerOptions(OptimizerOptions),
1437    OptionContainerPath(Option<ContainerPath>),
1438    OptionRFileInfo(Option<RFileInfo>),
1439    OptionStringStringVecString(Option<(String, String, Vec<String>)>),
1440    PackSettings(PackSettings),
1441    PackTranslation(PackTranslation),
1442    PathBuf(PathBuf),
1443    PortraitSettingsRFileInfo(PortraitSettings, RFileInfo),
1444    RFileDecoded(RFileDecoded),
1445    RigidModelRFileInfo(RigidModel, RFileInfo),
1446    Schema(Schema),
1447    String(String),
1448    StringVecContainerPath(String, Vec<ContainerPath>),
1449    StringVecPathBuf(String, Vec<PathBuf>),
1450    Text(Text),
1451    TextRFileInfo(Text, RFileInfo),
1452    UICRFileInfo(UIC, RFileInfo),
1453    UnitVariantRFileInfo(UnitVariant, RFileInfo),
1454    Unknown,
1455    VecBoolString(Vec<(bool, String)>),
1456    VecContainerPath(Vec<ContainerPath>),
1457    VecContainerPathContainerPath(Vec<(ContainerPath, ContainerPath)>),
1458    VecContainerPathOptionString(Vec<ContainerPath>, Option<String>),
1459    VecContainerPathVecContainerPath(Vec<ContainerPath>, Vec<ContainerPath>),
1460    VecContainerPathBTreeMapStringVecContainerPath(Vec<ContainerPath>, BTreeMap<String, Vec<ContainerPath>>),
1461    VecContainerPathVecContainerPathString(Vec<ContainerPath>, Vec<ContainerPath>, String),
1462    VecContainerPathVecRFileInfo(Vec<ContainerPath>, Vec<RFileInfo>),
1463    VecContainerPathVecString(Vec<ContainerPath>, Vec<String>),
1464    VecDataSourceStringStringStringUsizeUsize(Vec<(DataSource, String, String, String, usize, usize)>),
1465    VecDefinition(Vec<Definition>),
1466    VecField(Vec<Field>),
1467    VecNote(Vec<Note>),
1468    VecRFile(Vec<RFile>),
1469    VecRFileInfo(Vec<RFileInfo>),
1470    VecString(Vec<String>),
1471    VecStringTuples(Vec<(String, String)>),
1472    VecStringContainerInfo(Vec<(String, ContainerInfo)>),
1473    VecU8(Vec<u8>),
1474    VideoInfoRFileInfo(VideoInfo, RFileInfo),
1475    VMDRFileInfo(Text, RFileInfo),
1476    WSModelRFileInfo(Text, RFileInfo),
1477
1478    /// All settings in one response (for batch loading).
1479    SettingsAll(SettingsSnapshot),
1480}