1
1
import archiver from 'archiver' ;
2
2
import { app , shell } from 'electron' ;
3
3
import extract from 'extract-zip' ;
4
+ import { hashElement } from 'folder-hash' ;
4
5
import { createWriteStream } from 'fs' ;
5
- import { existsSync , copyFile } from 'node:fs' ;
6
+ import { copyFile , existsSync } from 'node:fs' ;
6
7
import fsPromises from 'node:fs/promises' ;
7
8
import path from 'node:path' ;
8
- import { hashElement } from 'folder-hash' ;
9
9
import process from 'process' ;
10
- import fs from 'fs' ;
11
10
12
11
import { DownloadedEntry , Version } from '../../types/ipc' ;
13
12
import { getAuthToken } from './authentication' ;
@@ -53,31 +52,31 @@ function setDownloadedVersion(
53
52
store . set ( 'downloadedAssetVersions' , newDownloads ) ;
54
53
}
55
54
56
- export async function getFolderHash ( filePath : string ) : Promise < string > {
55
+ export async function getFolderHash ( filePath : string ) : Promise < string > {
57
56
return hashElement ( filePath )
58
- . then ( hash => {
59
- return hash [ 'hash' ] . toString ( )
60
- } )
61
- . catch ( error => {
62
- console . error ( 'hashing failed:' , error ) ;
63
- } ) ;
57
+ . then ( ( hash ) => {
58
+ return hash [ 'hash' ] . toString ( ) ;
59
+ } )
60
+ . catch ( ( error ) => {
61
+ console . error ( 'hashing failed:' , error ) ;
62
+ } ) ;
64
63
}
65
64
66
65
export async function ifFilesChanged ( asset_id : string ) : Promise < boolean > {
67
- // compare current with saved hash
68
- const downloads = await getDownloadedVersions ( )
69
- const saved_asset = downloads . find ( ( a ) => asset_id === a . asset_id )
66
+ // compare current with saved hash
67
+ const downloads = await getDownloadedVersions ( ) ;
68
+ const saved_asset = downloads . find ( ( a ) => asset_id === a . asset_id ) ;
70
69
if ( saved_asset === undefined ) {
71
- return true
70
+ return true ;
72
71
}
73
- const saved_hash = saved_asset . folderHash
72
+ const saved_hash = saved_asset . folderHash ;
74
73
75
74
// what is the current hash
76
- const folderName = saved_asset . folderName
75
+ const folderName = saved_asset . folderName ;
77
76
const folderPath = path . join ( getDownloadFolder ( ) , folderName ) ;
78
- const current_hash = await getFolderHash ( folderPath )
79
-
80
- return ( current_hash !== saved_hash )
77
+ const current_hash = await getFolderHash ( folderPath ) ;
78
+
79
+ return current_hash !== saved_hash ;
81
80
}
82
81
83
82
/**
@@ -100,7 +99,7 @@ export async function createInitialVersion({
100
99
console . log ( 'adding to store' ) ;
101
100
102
101
// hash new folder
103
- const folderHash = await getFolderHash ( folderPath )
102
+ const folderHash = await getFolderHash ( folderPath ) ;
104
103
setDownloadedVersion ( asset_id , { semver : null , folderName, folderHash } ) ;
105
104
}
106
105
@@ -190,7 +189,7 @@ export async function commitChanges(asset_id: string, message: string, is_major:
190
189
}
191
190
192
191
// Update saved hash
193
- const folderHash = await getFolderHash ( sourceFolder )
192
+ const folderHash = await getFolderHash ( sourceFolder ) ;
194
193
195
194
// Update store with currently downloaded version
196
195
const { semver } = result . data as Version ;
@@ -244,7 +243,7 @@ export async function downloadVersion({ asset_id, semver }: { asset_id: string;
244
243
// previously had semver in here but probably not necessary
245
244
// const folderName = `${asset_name}_${semver}_${asset_id.substring(0, 8)}/`;
246
245
const folderName = `${ asset_name } _${ asset_id . substring ( 0 , 8 ) } /` ;
247
- const folderPath = path . join ( getDownloadFolder ( ) , folderName )
246
+ const folderPath = path . join ( getDownloadFolder ( ) , folderName ) ;
248
247
249
248
// remove old copy of folder
250
249
await fsPromises . rm ( path . join ( getDownloadFolder ( ) , folderName ) , { force : true , recursive : true } ) ;
@@ -253,7 +252,7 @@ export async function downloadVersion({ asset_id, semver }: { asset_id: string;
253
252
console . log ( 'removing zip file...' ) ;
254
253
await fsPromises . rm ( zipFilePath ) ;
255
254
256
- const folderHash = await getFolderHash ( folderPath )
255
+ const folderHash = await getFolderHash ( folderPath ) ;
257
256
console . log ( 'marking as stored!' ) ;
258
257
setDownloadedVersion ( asset_id , { semver, folderName, folderHash } ) ;
259
258
@@ -281,10 +280,13 @@ export async function unsyncAsset(asset_id: string) {
281
280
}
282
281
283
282
function getCommandLine ( ) {
284
- switch ( process . platform ) {
285
- case 'darwin' : return 'open ' ;
286
- case 'win32' : return 'start ' ;
287
- default : return 'xdg-open' ;
283
+ switch ( process . platform ) {
284
+ case 'darwin' :
285
+ return 'open ' ;
286
+ case 'win32' :
287
+ return 'start ' ;
288
+ default :
289
+ return 'xdg-open' ;
288
290
}
289
291
}
290
292
@@ -304,48 +306,52 @@ export async function openHoudini(asset_id: string) {
304
306
if ( ! process . env . HFS ) return ;
305
307
const houdiniCmd = path . join ( process . env . HFS , '/bin/houdini' ) ;
306
308
307
- const { spawn, exec } = require ( " child_process" ) ;
309
+ const { spawn, exec } = require ( ' child_process' ) ;
308
310
309
311
// If there's an existing Houdini file, open it.
310
312
const destination = path . join ( downloadsFullpath , `${ assetName } .hipnc` ) ;
311
313
if ( existsSync ( destination ) ) {
312
314
exec ( getCommandLine ( ) + destination ) ;
313
315
console . log ( `Launching the existing Houdini file for ${ asset_id } ...` ) ;
314
- }
316
+ }
315
317
// Otherwise, load asset in a new template.
316
318
else {
317
319
const existsUsdOld = existsSync ( path . join ( downloadsFullpath , 'root.usda' ) ) ;
318
320
const existsUsdNew = existsSync ( path . join ( downloadsFullpath , `${ assetName } .usda` ) ) ;
319
- const houdiniTemplate = ( ! existsUsdOld && ! existsUsdNew ) ? 'CreateNew.hipnc' : 'Update.hipnc' ;
321
+ const houdiniTemplate = ! existsUsdOld && ! existsUsdNew ? 'CreateNew.hipnc' : 'Update.hipnc' ;
320
322
const templateFullpath = path . join ( process . cwd ( ) , `${ houdini_src } ${ houdiniTemplate } ` ) ;
321
-
323
+
322
324
// Copy template to asset's folder so we don't always edit on the same file
323
325
copyFile ( templateFullpath , destination , ( err ) => {
324
326
if ( err ) throw err ;
325
327
console . log ( `${ houdiniTemplate } was copied to ${ destination } ` ) ;
326
328
} ) ;
327
-
329
+
328
330
const pythonScript = path . join ( process . cwd ( ) , `${ houdini_src } /launchTemplate.py` ) ;
329
-
331
+
330
332
// Launch houdini with a python session attached
331
- const bat = spawn ( houdiniCmd , [
332
- destination , // Argument for cmd to carry out the specified file
333
- pythonScript , // Path to your script
334
- "-a" , // First argument
335
- assetName , // n-th argument
336
- "-o" ,
337
- downloadsFullpath ,
338
- "-n" ,
339
- downloadsFullpath
340
- ] , {
341
- shell : true ,
342
- } ) ;
343
-
344
- bat . stdout . on ( "data" , ( data ) => {
333
+ const bat = spawn (
334
+ houdiniCmd ,
335
+ [
336
+ destination , // Argument for cmd to carry out the specified file
337
+ pythonScript , // Path to your script
338
+ '-a' , // First argument
339
+ assetName , // n-th argument
340
+ '-o' ,
341
+ downloadsFullpath ,
342
+ '-n' ,
343
+ downloadsFullpath ,
344
+ ] ,
345
+ {
346
+ shell : true ,
347
+ } ,
348
+ ) ;
349
+
350
+ bat . stdout . on ( 'data' , ( data ) => {
345
351
console . log ( data . toString ( ) ) ;
346
352
} ) ;
347
-
348
- bat . stderr . on ( " data" , ( err ) => {
353
+
354
+ bat . stderr . on ( ' data' , ( err ) => {
349
355
console . log ( err . toString ( ) ) ;
350
356
} ) ;
351
357
}
@@ -366,40 +372,42 @@ export async function quietRenderHoudini(asset_id: string) {
366
372
if ( ! process . env . HFS ) return ;
367
373
const houdiniHython = path . join ( process . env . HFS , '/bin/hython' ) ;
368
374
369
- const { spawn } = require ( " child_process" ) ;
375
+ const { spawn } = require ( ' child_process' ) ;
370
376
371
377
const pythonScript = path . join ( process . cwd ( ) , `${ houdini_src } /quietRender.py` ) ;
372
-
378
+
373
379
// locate the asset USD file based on different asset structures
374
380
const usdNewFullpath = path . join ( downloadsFullpath , 'root.usda' ) ;
375
381
const usdOldFullpath = path . join ( downloadsFullpath , `${ assetName } .usda` ) ;
376
382
let assetFullpath ;
377
383
if ( existsSync ( usdOldFullpath ) ) {
378
384
assetFullpath = usdOldFullpath ;
379
- }
380
- else if ( existsSync ( usdNewFullpath ) ) {
385
+ } else if ( existsSync ( usdNewFullpath ) ) {
381
386
assetFullpath = usdNewFullpath ;
382
- }
383
- else {
384
- console . log ( "No correct asset USD to render!" ) ;
387
+ } else {
388
+ console . log ( 'No correct asset USD to render!' ) ;
385
389
return ;
386
390
}
387
-
388
- const bat = spawn ( houdiniHython , [
389
- pythonScript , // Argument for cmd to carry out the specified file
390
- "-a" , // First argument
391
- assetFullpath , // n-th argument
392
- "-o" ,
393
- downloadsFullpath
394
- ] , {
395
- shell : true ,
396
- } ) ;
397
-
398
- bat . stdout . on ( "data" , ( data ) => {
391
+
392
+ const bat = spawn (
393
+ houdiniHython ,
394
+ [
395
+ pythonScript , // Argument for cmd to carry out the specified file
396
+ '-a' , // First argument
397
+ assetFullpath , // n-th argument
398
+ '-o' ,
399
+ downloadsFullpath ,
400
+ ] ,
401
+ {
402
+ shell : true ,
403
+ } ,
404
+ ) ;
405
+
406
+ bat . stdout . on ( 'data' , ( data ) => {
399
407
console . log ( data . toString ( ) ) ;
400
408
} ) ;
401
-
402
- bat . stderr . on ( " data" , ( err ) => {
409
+
410
+ bat . stderr . on ( ' data' , ( err ) => {
403
411
console . log ( err . toString ( ) ) ;
404
412
} ) ;
405
413
}
0 commit comments