Create mod subdirectories for each game

This commit is contained in:
Tyler Hallada 2022-09-03 14:29:50 -04:00
parent 14be03cd3d
commit e96d760a1c
2 changed files with 8 additions and 5 deletions

View File

@ -11,8 +11,8 @@ mkdir -p plugins_data
if [ -n "$last_update_time" ]; then
./target/release/mod-mapper -e cells/edits.json &>> logs/modmapper.log
./target/release/mod-mapper -c cells &>> logs/modmapper.log
./target/release/mod-mapper -s mods/skyrimspecialedition_mod_search_index.json -g skyrimspecialedition &>> logs/modmapper.log
./target/release/mod-mapper -s mods/skyrim_mod_search_index.json -g skyrim &>> logs/modmapper.log
./target/release/mod-mapper -s mods/skyrimspecialedition/mod_search_index.json -g skyrimspecialedition &>> logs/modmapper.log
./target/release/mod-mapper -s mods/skyrim/mod_search_index.json -g skyrim &>> logs/modmapper.log
./target/release/mod-mapper -M mods/mod_cell_counts.json &>> logs/modmapper.log
./target/release/mod-mapper -G mods/games.json &>> logs/modmapper.log
./target/release/mod-mapper -m mods -u "$last_update_time" &>> logs/modmapper.log
@ -21,8 +21,8 @@ if [ -n "$last_update_time" ]; then
else
./target/release/mod-mapper -e cells/edits.json &>> logs/modmapper.log
./target/release/mod-mapper -c cells &>> logs/modmapper.log
./target/release/mod-mapper -s mods/skyrimspecialedition_mod_search_index.json -g skyrimspecialedition &>> logs/modmapper.log
./target/release/mod-mapper -s mods/skyrim_mod_search_index.json -g skyrim &>> logs/modmapper.log
./target/release/mod-mapper -s mods/skyrimspecialedition/mod_search_index.json -g skyrimspecialedition &>> logs/modmapper.log
./target/release/mod-mapper -s mods/skyrim/mod_search_index.json -g skyrim &>> logs/modmapper.log
./target/release/mod-mapper -M mods/mod_cell_counts.json &>> logs/modmapper.log
./target/release/mod-mapper -G mods/games.json &>> logs/modmapper.log
./target/release/mod-mapper -m mods &>> logs/modmapper.log

View File

@ -1,16 +1,19 @@
use anyhow::Result;
use chrono::NaiveDateTime;
use std::collections::HashMap;
use std::fs::File;
use std::io::Write;
use std::path::Path;
use tracing::info;
use crate::models::game;
use crate::models::game_mod;
pub async fn dump_mod_data(pool: &sqlx::Pool<sqlx::Postgres>, dir: &str, updated_after: Option<NaiveDateTime>) -> Result<()> {
let mut page = 1;
let page_size = 20;
let mut last_id = None;
let game_id_to_name: HashMap<_, _> = game::get_all(&pool).await?.into_iter().map(|game| (game.id, game.name)).collect();
loop {
let mods =
game_mod::batched_get_with_cells_and_files(&pool, page_size, last_id, "Skyrim.esm", 1, updated_after).await?;
@ -18,7 +21,7 @@ pub async fn dump_mod_data(pool: &sqlx::Pool<sqlx::Postgres>, dir: &str, updated
break;
}
for mod_with_cells in mods {
let path = Path::new(&dir);
let path = Path::new(&dir).join(game_id_to_name.get(&mod_with_cells.game_id).expect("valid mod.game_id"));
std::fs::create_dir_all(&path)?;
let path = path.join(format!("{}.json", mod_with_cells.nexus_mod_id));
info!(page = page, nexus_mod_id = mod_with_cells.nexus_mod_id, "dumping mod data to {}", path.display());