@@ -146,7 +146,7 @@ fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> std::io::Result
146146 let ty = entry. file_type ( ) ?;
147147 let src_path = entry. path ( ) ;
148148 let dst_path = dst. as_ref ( ) . join ( entry. file_name ( ) ) ;
149-
149+
150150 if ty. is_dir ( ) {
151151 copy_dir_all ( & src_path, & dst_path) ?;
152152 } else {
@@ -186,7 +186,7 @@ pub fn backup_snbt_files(
186186 if source. exists ( ) {
187187 if let Some ( file_name) = source. file_name ( ) {
188188 let dest = backup_dir. join ( file_name) ;
189-
189+
190190 if let Err ( e) = fs:: copy ( & source, & dest) {
191191 logger. warning (
192192 & format ! ( "Failed to backup SNBT file {}: {e}" , file_path) ,
@@ -212,7 +212,7 @@ pub fn backup_snbt_files(
212212 & format ! ( "SNBT backup completed: {} files backed up" , backed_up_count) ,
213213 Some ( "BACKUP" ) ,
214214 ) ;
215-
215+
216216 Ok ( ( ) )
217217}
218218
@@ -229,7 +229,7 @@ pub fn backup_resource_pack(
229229 ) ;
230230
231231 let source = Path :: new ( & pack_path) ;
232-
232+
233233 if !source. exists ( ) {
234234 return Err ( format ! ( "Resource pack not found: {}" , pack_path) ) ;
235235 }
@@ -253,7 +253,7 @@ pub fn backup_resource_pack(
253253
254254 // Copy entire resource pack directory
255255 let dest = backup_dir. join ( pack_name) ;
256-
256+
257257 if let Err ( e) = copy_dir_all ( & source, & dest) {
258258 let error_msg = format ! ( "Failed to backup resource pack: {e}" ) ;
259259 logger. error ( & error_msg, Some ( "BACKUP" ) ) ;
@@ -264,7 +264,7 @@ pub fn backup_resource_pack(
264264 & format ! ( "Resource pack backup completed: {}" , dest. display( ) ) ,
265265 Some ( "BACKUP" ) ,
266266 ) ;
267-
267+
268268 Ok ( ( ) )
269269}
270270
@@ -280,33 +280,31 @@ pub struct TranslationSummary {
280280#[ serde( rename_all = "camelCase" ) ]
281281pub struct TranslationEntry {
282282 #[ serde( rename = "type" ) ]
283- pub translation_type : String , // "mod", "quest", "patchouli", "custom"
283+ pub translation_type : String , // "mod", "quest", "patchouli", "custom"
284284 pub name : String ,
285- pub status : String , // "completed" or "failed"
286- pub keys : String , // Format: "translated/total" e.g. "234/234"
285+ pub status : String , // "completed" or "failed"
286+ pub keys : String , // Format: "translated/total" e.g. "234/234"
287287}
288288
289289/// List all translation session directories
290290#[ tauri:: command]
291291pub async fn list_translation_sessions ( minecraft_dir : String ) -> Result < Vec < String > , String > {
292- let logs_path = PathBuf :: from ( & minecraft_dir)
293- . join ( "logs" )
294- . join ( "localizer" ) ;
295-
292+ let logs_path = PathBuf :: from ( & minecraft_dir) . join ( "logs" ) . join ( "localizer" ) ;
293+
296294 if !logs_path. exists ( ) {
297295 return Ok ( Vec :: new ( ) ) ;
298296 }
299-
297+
300298 let mut sessions = Vec :: new ( ) ;
301-
299+
302300 // Read directory entries
303- let entries = fs :: read_dir ( & logs_path )
304- . map_err ( |e| format ! ( "Failed to read logs directory: {}" , e) ) ?;
305-
301+ let entries =
302+ fs :: read_dir ( & logs_path ) . map_err ( |e| format ! ( "Failed to read logs directory: {}" , e) ) ?;
303+
306304 for entry in entries {
307305 let entry = entry. map_err ( |e| format ! ( "Failed to read directory entry: {}" , e) ) ?;
308306 let path = entry. path ( ) ;
309-
307+
310308 // Only include directories that match session ID format
311309 if path. is_dir ( ) {
312310 if let Some ( dir_name) = path. file_name ( ) {
@@ -319,36 +317,39 @@ pub async fn list_translation_sessions(minecraft_dir: String) -> Result<Vec<Stri
319317 }
320318 }
321319 }
322-
320+
323321 // Sort sessions by name (newest first due to timestamp format)
324322 sessions. sort_by ( |a, b| b. cmp ( a) ) ;
325-
323+
326324 Ok ( sessions)
327325}
328326
329327/// Read translation summary for a specific session
330328#[ tauri:: command]
331329pub async fn get_translation_summary (
332330 minecraft_dir : String ,
333- session_id : String
331+ session_id : String ,
334332) -> Result < TranslationSummary , String > {
335333 let summary_path = PathBuf :: from ( & minecraft_dir)
336334 . join ( "logs" )
337335 . join ( "localizer" )
338336 . join ( & session_id)
339337 . join ( "translation_summary.json" ) ;
340-
338+
341339 if !summary_path. exists ( ) {
342- return Err ( format ! ( "Translation summary not found for session: {}" , session_id) ) ;
340+ return Err ( format ! (
341+ "Translation summary not found for session: {}" ,
342+ session_id
343+ ) ) ;
343344 }
344-
345+
345346 // Read and parse the JSON file
346347 let content = fs:: read_to_string ( & summary_path)
347348 . map_err ( |e| format ! ( "Failed to read summary file: {}" , e) ) ?;
348-
349+
349350 let summary: TranslationSummary = serde_json:: from_str ( & content)
350351 . map_err ( |e| format ! ( "Failed to parse summary JSON: {}" , e) ) ?;
351-
352+
352353 Ok ( summary)
353354}
354355
@@ -368,18 +369,18 @@ pub async fn update_translation_summary(
368369 . join ( "logs" )
369370 . join ( "localizer" )
370371 . join ( & session_id) ;
371-
372+
372373 // Ensure session directory exists
373374 fs:: create_dir_all ( & session_dir)
374375 . map_err ( |e| format ! ( "Failed to create session directory: {}" , e) ) ?;
375-
376+
376377 let summary_path = session_dir. join ( "translation_summary.json" ) ;
377-
378+
378379 // Read existing summary or create new one
379380 let mut summary = if summary_path. exists ( ) {
380381 let content = fs:: read_to_string ( & summary_path)
381382 . map_err ( |e| format ! ( "Failed to read existing summary: {}" , e) ) ?;
382-
383+
383384 serde_json:: from_str :: < TranslationSummary > ( & content)
384385 . map_err ( |e| format ! ( "Failed to parse existing summary: {}" , e) ) ?
385386 } else {
@@ -388,23 +389,22 @@ pub async fn update_translation_summary(
388389 translations : Vec :: new ( ) ,
389390 }
390391 } ;
391-
392+
392393 // Add new translation entry
393394 let entry = TranslationEntry {
394395 translation_type,
395396 name,
396397 status,
397398 keys : format ! ( "{}/{}" , translated_keys, total_keys) ,
398399 } ;
399-
400+
400401 summary. translations . push ( entry) ;
401-
402+
402403 // Write updated summary back to file
403404 let json = serde_json:: to_string_pretty ( & summary)
404405 . map_err ( |e| format ! ( "Failed to serialize summary: {}" , e) ) ?;
405-
406- fs:: write ( & summary_path, json)
407- . map_err ( |e| format ! ( "Failed to write summary file: {}" , e) ) ?;
408-
406+
407+ fs:: write ( & summary_path, json) . map_err ( |e| format ! ( "Failed to write summary file: {}" , e) ) ?;
408+
409409 Ok ( ( ) )
410- }
410+ }
0 commit comments