@@ -8,15 +8,15 @@ use anyhow::{anyhow, Context, Result};
88use indicatif:: { ProgressBar , ProgressIterator , ProgressStyle } ;
99use pathdiff:: diff_paths;
1010use rpackwiz:: model:: {
11- DownloadMode , HashFormat , Mod , ModDownload , ModUpdate , Pack , PackFile , PackIndex ,
11+ DownloadMode , HashFormat , Mod , ModDownload , ModUpdate , Pack , PackFile , PackIndex , Side ,
1212} ;
1313use serde:: de:: DeserializeOwned ;
1414use tokio:: { fs:: File , io:: AsyncWriteExt } ;
1515use walkdir:: WalkDir ;
1616
1717use crate :: {
1818 app:: { AddonType , App , CacheStrategy , Prefix , ProgressPrefix , Resolvable , ResolvedFile } ,
19- model:: Downloadable ,
19+ model:: { ClientSideMod , Downloadable } ,
2020 util:: env:: try_get_url,
2121} ;
2222
@@ -97,7 +97,16 @@ impl PackwizInterop<'_> {
9797 let dl = self . dl_from_mod ( & modpw) . await ?;
9898 let dl_name = dl. to_short_string ( ) ;
9999
100- self . 0 . add_addon ( AddonType :: Mod , dl) ?;
100+ if modpw. side == Side :: Client {
101+ self . 0 . server . clientsidemods . push ( ClientSideMod {
102+ dl,
103+ desc : modpw. option . description . clone ( ) . unwrap_or_default ( ) ,
104+ optional : modpw. option . optional ,
105+ } ) ;
106+ } else {
107+ self . 0 . add_addon ( AddonType :: Mod , dl) ?;
108+ }
109+
101110 self . 0 . notify ( Prefix :: Imported , dl_name) ;
102111 } else {
103112 // TODO: ???
@@ -300,32 +309,57 @@ impl PackwizInterop<'_> {
300309 . with_prefix ( ProgressPrefix :: Exporting ) ;
301310
302311 tokio:: fs:: create_dir_all ( output_dir. join ( "mods" ) ) . await ?;
303- for dl in self . 0 . server . mods . iter ( ) . progress_with ( pb. clone ( ) ) {
304- pb. set_message ( dl. to_short_string ( ) ) ;
305312
306- let m = self . to_mod ( dl) . await ?;
313+ for dl in & self . 0 . server . mods {
314+ self . write_mod_file ( dl, Side :: Both , false , None , output_dir, files_list, & pb)
315+ . await ?;
316+ }
317+
318+ for csm in & self . 0 . server . clientsidemods {
319+ let desc = if csm. desc . is_empty ( ) { None } else { Some ( csm. desc . as_str ( ) ) } ;
320+ self . write_mod_file ( & csm. dl , Side :: Client , csm. optional , desc, output_dir, files_list, & pb)
321+ . await ?;
322+ }
323+
324+ Ok ( ( ) )
325+ }
326+
327+ #[ allow( clippy:: too_many_arguments) ]
328+ async fn write_mod_file (
329+ & self ,
330+ dl : & Downloadable ,
331+ side : Side ,
332+ optional : bool ,
333+ desc : Option < & str > ,
334+ output_dir : & Path ,
335+ files_list : & mut Vec < PackFile > ,
336+ pb : & ProgressBar ,
337+ ) -> Result < ( ) > {
338+ pb. set_message ( dl. to_short_string ( ) ) ;
307339
308- let filename = format ! ( "{}.pw.toml" , m. name) ;
309- let path = output_dir. join ( "mods" ) . join ( & filename) ;
340+ let mut m = self . to_mod ( dl) . await ?;
341+ m. side = side;
342+ m. option . optional = optional;
343+ m. option . description = desc. map ( str:: to_owned) ;
310344
311- let mut f = File :: create ( path) . await ?;
345+ let filename = format ! ( "{}.pw.toml" , m. name) ;
346+ let path = output_dir. join ( "mods" ) . join ( & filename) ;
312347
313- let content = toml:: to_string_pretty ( & m) ?;
314- let hash = App :: hash_sha256 ( & content) ;
348+ let content = toml:: to_string_pretty ( & m) ?;
349+ let hash = App :: hash_sha256 ( & content) ;
315350
316- f . write_all ( content. as_bytes ( ) ) . await ?;
351+ File :: create ( path ) . await ? . write_all ( content. as_bytes ( ) ) . await ?;
317352
318- self . 0 . notify ( Prefix :: Exported , format ! ( "mods/{filename}" ) ) ;
353+ self . 0 . notify ( Prefix :: Exported , format ! ( "mods/{filename}" ) ) ;
319354
320- files_list. push ( PackFile {
321- file : format ! ( "mods/{filename}" ) ,
322- hash,
323- metafile : true ,
324- alias : None ,
325- hash_format : None ,
326- preserve : false ,
327- } ) ;
328- }
355+ files_list. push ( PackFile {
356+ file : format ! ( "mods/{filename}" ) ,
357+ hash,
358+ metafile : true ,
359+ alias : None ,
360+ hash_format : None ,
361+ preserve : false ,
362+ } ) ;
329363
330364 Ok ( ( ) )
331365 }
0 commit comments