@@ -7,8 +7,8 @@ import { BrowserWindow, shell, WebContents } from 'electron';
7
7
import fs from 'fs' ;
8
8
import path from 'path' ;
9
9
import upath from 'upath' ;
10
- import zlib from 'zlib' ;
11
10
11
+ import { legacyOutputFileEnding } from '../../Frontend/shared-constants' ;
12
12
import { AllowedFrontendChannels } from '../../shared/ipc-channels' ;
13
13
import {
14
14
ExportArgsType ,
@@ -33,10 +33,7 @@ import {
33
33
} from '../errorHandling/errorHandling' ;
34
34
import { loadInputAndOutputFromFilePath } from '../input/importFromFile' ;
35
35
import { serializeAttributions } from '../input/parseInputData' ;
36
- import {
37
- convertOwaspToOpossum ,
38
- convertScancodeToOpossum ,
39
- } from '../opossum-file/convertToOpossum' ;
36
+ import { convertToOpossum } from '../opossum-file/opossum-file' ;
40
37
import { writeCsvToFile } from '../output/writeCsvToFile' ;
41
38
import { writeSpdxFile } from '../output/writeSpdxFile' ;
42
39
import { GlobalBackendState , OpossumOutputFile } from '../types/types' ;
@@ -54,10 +51,6 @@ import {
54
51
} from './globalBackendState' ;
55
52
import logger from './logger' ;
56
53
57
- const outputFileEnding = '_attributions.json' ;
58
- const jsonGzipFileExtension = '.json.gz' ;
59
- const jsonFileExtension = '.json' ;
60
-
61
54
export function getSaveFileListener (
62
55
mainWindow : BrowserWindow ,
63
56
) : ( _ : unknown , args : SaveFileArgs ) => Promise < void > {
@@ -213,27 +206,8 @@ export function getImportFileConvertAndLoadListener(
213
206
throw new Error ( 'Output directory does not exist' ) ;
214
207
}
215
208
216
- logger . info ( 'Converting .json to .opossum format' ) ;
217
-
218
- if ( resourceFilePath . endsWith ( outputFileEnding ) ) {
219
- resourceFilePath = tryToGetInputFileFromOutputFile ( resourceFilePath ) ;
220
- }
221
-
222
- switch ( fileType ) {
223
- case FileType . LEGACY_OPOSSUM :
224
- await writeOpossumFile ( {
225
- path : opossumFilePath ,
226
- input : getInputJson ( resourceFilePath ) ,
227
- output : getOutputJson ( resourceFilePath ) ,
228
- } ) ;
229
- break ;
230
- case FileType . SCANCODE_JSON :
231
- await convertScancodeToOpossum ( resourceFilePath , opossumFilePath ) ;
232
- break ;
233
- case FileType . OWASP_JSON :
234
- await convertOwaspToOpossum ( resourceFilePath , opossumFilePath ) ;
235
- break ;
236
- }
209
+ logger . info ( 'Converting input file to .opossum format' ) ;
210
+ await convertToOpossum ( resourceFilePath , opossumFilePath , fileType ) ;
237
211
238
212
logger . info ( 'Updating global backend state' ) ;
239
213
initializeGlobalBackendState ( opossumFilePath , true ) ;
@@ -255,7 +229,7 @@ function initializeGlobalBackendState(
255
229
resourceFilePath : isOpossumFormat ? undefined : filePath ,
256
230
attributionFilePath : isOpossumFormat
257
231
? undefined
258
- : getFilePathWithAppendix ( filePath , outputFileEnding ) ,
232
+ : getFilePathWithAppendix ( filePath , legacyOutputFileEnding ) ,
259
233
opossumFilePath : isOpossumFormat ? filePath : undefined ,
260
234
followUpFilePath : getFilePathWithAppendix ( filePath , '_follow_up.csv' ) ,
261
235
compactBomFilePath : getFilePathWithAppendix (
@@ -316,17 +290,6 @@ function formatBaseURL(baseURL: string): string {
316
290
return `file://${ baseURL } /{path}` ;
317
291
}
318
292
319
- function tryToGetInputFileFromOutputFile ( filePath : string ) : string {
320
- const outputFilePattern = `(${ outputFileEnding } )$` ;
321
- const outputFileRegex = new RegExp ( outputFilePattern ) ;
322
-
323
- return fs . existsSync ( filePath . replace ( outputFileRegex , jsonFileExtension ) )
324
- ? filePath . replace ( outputFileRegex , jsonFileExtension )
325
- : fs . existsSync ( filePath . replace ( outputFileRegex , jsonGzipFileExtension ) )
326
- ? filePath . replace ( outputFileRegex , jsonGzipFileExtension )
327
- : filePath ;
328
- }
329
-
330
293
export async function openFile (
331
294
mainWindow : BrowserWindow ,
332
295
filePath : string ,
@@ -545,31 +508,3 @@ export function setLoadingState(
545
508
isLoading,
546
509
} ) ;
547
510
}
548
-
549
- function getInputJson ( resourceFilePath : string ) : string {
550
- let inputJson : string ;
551
- if ( resourceFilePath . endsWith ( jsonGzipFileExtension ) ) {
552
- const file = fs . readFileSync ( resourceFilePath ) ;
553
- inputJson = zlib . gunzipSync ( file ) . toString ( ) ;
554
- } else {
555
- inputJson = fs . readFileSync ( resourceFilePath , {
556
- encoding : 'utf-8' ,
557
- } ) ;
558
- }
559
-
560
- return inputJson ;
561
- }
562
-
563
- function getOutputJson ( resourceFilePath : string ) : string | undefined {
564
- const expectedAssociatedAttributionFilePath = getFilePathWithAppendix (
565
- resourceFilePath ,
566
- outputFileEnding ,
567
- ) ;
568
- if ( fs . existsSync ( expectedAssociatedAttributionFilePath ) ) {
569
- return fs . readFileSync ( expectedAssociatedAttributionFilePath , {
570
- encoding : 'utf-8' ,
571
- } ) ;
572
- }
573
-
574
- return undefined ;
575
- }
0 commit comments