import { mkdtempSync , removeSync } from "fs-extra" ; import { execFileSync , spawnSync , SpawnSyncReturns } from "child_process" ; import { join as joinPath , sep as pathSep } from "path" ; import { app } from "electron" ; import { path7za } from "7zip-bin" ; import * as pathUnrar from "unrar-binaries" ; import Logger from "../utils/Logger" ; export default class ArchiveConverter { public static async convertToZip ( pathToArchive , output ) { const tempDir = mkdtempSync ( joinPath ( app . getPath ( "temp" ) , "ddmm-archive" ) ) ; Logger . info ( "Archive Converter" , "Converting " + tempDir + " to a zip file" ) ; let extractOut ; if ( ! pathToArchive . endsWith ( ".rar" ) ) { Logger . info ( "Archive Converter" , "Using 7za to convert" ) ; extractOut = execFileSync ( path7za , [ "x" , pathToArchive , "-y" , "-o" + tempDir ] ) ; } else { Logger . info ( "Archive Converter" , "Using unrar to convert" ) ; extractOut = execFileSync ( pathUnrar , [ "x" , "-y" , pathToArchive , tempDir ] ) ; } Logger . debug ( "Archive Converter" , "STDOUT: " + extractOut ) ; Logger . info ( "Archive Converter" , "Recompressing " + tempDir ) ; const compressOut = execFileSync ( path7za , [ "a" , output , "-y" , tempDir + pathSep + "*" ] ) ; Logger . debug ( "Archive Converter" , "STDOUT: " + compressOut ) ; removeSync ( tempDir ) ; } }