2
2
3
3
import fs from 'fs' ;
4
4
import fsext from 'fs-extra' ;
5
- import path from 'path' ;
6
5
import del from 'del' ;
6
+ import electron from 'electron' ;
7
+ import * as Utils from 'utils' ;
7
8
9
+ let cwd = Utils . getCwd ( ) ;
8
10
9
11
import BlAddonDB from 'bl_add-on_db' ;
10
12
const builder = new BlAddonDB ( ) ;
@@ -15,17 +17,15 @@ const taskMgr = new TaskMgr();
15
17
import Logger from 'logger' ;
16
18
const logger = new Logger ( ) ;
17
19
import * as BlAddon from 'bl-addon' ;
18
- import * as Utils from 'utils' ;
19
20
20
21
21
- var DB_DIR = path . resolve ( '. /db') ;
22
- var API_VERSION_FILE = path . resolve ( '. /db/version') ;
23
- var GITHUB_ADDONS_DB = path . resolve ( '. /db/add-on_list.db') ;
24
- var INSTALLED_ADDONS_DB = path . resolve ( '. /db/installed_add-on_list.db') ;
25
- var CONFIG_FILE_PATH = path . resolve ( '. /config/config.json') ;
22
+ var DB_DIR = cwd + ' /db';
23
+ var API_VERSION_FILE = cwd + ' /db/version';
24
+ var GITHUB_ADDONS_DB = cwd + ' /db/add-on_list.db';
25
+ var INSTALLED_ADDONS_DB = cwd + ' /db/installed_add-on_list.db';
26
+ var CONFIG_FILE_PATH = cwd + ' /config/config.json';
26
27
var BL_INFO_UNDEF = "626c5f696e666f5f@UNDEF" ;
27
28
28
-
29
29
var config = null ;
30
30
var app = angular . module ( 'blAddonMgr' , [ ] )
31
31
@@ -120,6 +120,7 @@ app.controller('MainController', function ($scope, $timeout) {
120
120
}
121
121
122
122
$scope . blVerList = checker . getInstalledBlVers ( ) ;
123
+ //$scope.blVerList.push('Custom');
123
124
$scope . addonCategories = [
124
125
{ id : 1 , name : 'All' , value : 'All' } ,
125
126
{ id : 2 , name : '3D View' , value : '3D View' } ,
@@ -146,6 +147,7 @@ app.controller('MainController', function ($scope, $timeout) {
146
147
{ id : 2 , name : 'GitHub' , value : 'github' } ,
147
148
{ id : 3 , name : 'Update' , value : 'update' }
148
149
] ;
150
+ $scope . customAddonDirList = [ ] ;
149
151
150
152
$scope . githubAddons = loadGitHubAddonDB ( ) ;
151
153
$scope . installedAddons = loadInstalledAddonsDB ( ) ;
@@ -256,6 +258,37 @@ app.controller('MainController', function ($scope, $timeout) {
256
258
return $scope . addonStatus [ key ] [ 'status' ] [ $scope . blVerSelect ] ;
257
259
} ;
258
260
261
+ $scope . targetIsCustomDir = ( ) => {
262
+ return $scope . blVerSelect === 'Custom' ;
263
+ } ;
264
+
265
+ $scope . customAddonDir = "" ;
266
+
267
+ $scope . openCustomAddonDir = ( ) => {
268
+ const remote = electron . remote ;
269
+ const dialog = remote . dialog ;
270
+ dialog . showOpenDialog ( null , {
271
+ properties : [ 'openDirectory' ] ,
272
+ title : 'Select Custom Add-on Folder' ,
273
+ defaultPath : '.'
274
+ } , ( folderName ) => {
275
+ $scope . customAddonDir = folderName ;
276
+ redrawApp ( ) ;
277
+ } ) ;
278
+ } ;
279
+
280
+ $scope . addCustomAddonDir = ( ) => {
281
+ let total = $scope . customAddonDirList . length ;
282
+ let dir = $scope . customAddonDir ;
283
+ if ( ! Utils . isDirectory ( dir ) ) { return ; }
284
+ console . log ( dir ) ;
285
+ $scope . customAddonDirList . push ( {
286
+ id : total ,
287
+ dir : dir
288
+ } ) ;
289
+ consle . log ( $scope . customAddonDirList ) ;
290
+ } ;
291
+
259
292
function onAddonSelectorChanged ( ) {
260
293
// collect filter condition
261
294
var activeList = $scope . addonLists [ $scope . addonListActive ] [ 'value' ] ;
@@ -320,7 +353,8 @@ app.controller('MainController', function ($scope, $timeout) {
320
353
}
321
354
main . repoList = addons ;
322
355
323
- async function installAddon ( repo , cb ) {
356
+
357
+ async function installAddon ( key , repo , cb ) {
324
358
try {
325
359
logger . category ( 'app' ) . info ( "Downloding add-on '" + repo [ 'bl_info' ] [ 'name' ] + "' from " + repo [ 'download_url' ] ) ;
326
360
let target = checker . getAddonPath ( $scope . blVerSelect ) ;
@@ -338,34 +372,53 @@ app.controller('MainController', function ($scope, $timeout) {
338
372
const extract = await Utils . extractZipFile ( downloadTo , target , true ) ;
339
373
340
374
let extractedPath = target + checker . getPathSeparator ( ) + repo [ 'repo_name' ] + '-master' ;
341
- let srcPath = repo [ 'src_dir' ] + "/" + repo [ 'src_main' ] ;
342
- let sp = srcPath . split ( "/" ) ;
343
- let copiedFile = "" ;
344
- let targetName = sp [ sp . length - 1 ] ;
375
+ let srcPath = extractedPath + repo [ 'src_dir' ] + '/' + repo [ 'src_main' ] ;
376
+ let sp = srcPath . split ( / [ \/ \\ ] / ) ;
377
+ let copingFiles = [ ] ;
378
+ let isPackage = false ;
379
+ // Package
380
+ if ( sp [ sp . length - 1 ] == "__init__.py" ) {
381
+ isPackage = true ;
382
+ }
383
+ // Module
384
+ else {
385
+ isPackage = false ;
386
+ }
345
387
advanceProgressAndUpdate ( ) ;
346
388
advanceProgressAndUpdate ( ) ;
389
+ let basePath = "" ;
347
390
for ( let i = 0 ; i < sp . length - 1 ; ++ i ) {
348
- copiedFile += sp [ i ] + checker . getPathSeparator ( ) ;
391
+ basePath += sp [ i ] + checker . getPathSeparator ( ) ;
349
392
}
350
- // File
351
- if ( targetName != "__init__.py" ) {
352
- copiedFile += targetName ;
393
+ if ( isPackage ) {
394
+ let list = fs . readdirSync ( basePath ) ;
395
+ for ( let i = 0 ; i < list . length ; ++ i ) {
396
+ copingFiles . push ( { 'path' : basePath + list [ i ] , 'filename' : list [ i ] } ) ;
397
+ }
353
398
}
354
- // Directory
355
399
else {
356
- targetName = sp [ sp . length - 2 ] ;
400
+ let modPath = basePath + checker . getPathSeparator ( ) + sp [ sp . length - 1 ] ;
401
+ copingFiles . push ( { 'path' : modPath , 'filename' : sp [ sp . length - 1 ] } ) ;
357
402
}
358
- let source = extractedPath + copiedFile ;
359
403
// copy add-on to add-on directory
360
- fsext . copySync ( source , target + checker . getPathSeparator ( ) + targetName ) ;
404
+ let targetDir = target ;
405
+ if ( isPackage ) {
406
+ targetDir = target + checker . getPathSeparator ( ) + key ;
407
+ fs . mkdirSync ( targetDir ) ;
408
+ }
409
+ for ( let i = 0 ; i < copingFiles . length ; ++ i ) {
410
+ let source = copingFiles [ i ] [ 'path' ] ;
411
+ let target = targetDir + checker . getPathSeparator ( ) + copingFiles [ i ] [ 'filename' ] ;
412
+ fsext . copySync ( source , target ) ;
413
+ }
361
414
advanceProgressAndUpdate ( ) ;
362
415
// delete garbage data
363
416
del . sync ( [ extractedPath ] , { force : true } ) ;
364
417
365
418
cb ( ) ;
366
419
}
367
420
catch ( e ) {
368
- logger . category ( 'app' ) . err ( e ) ;
421
+ logger . category ( 'app' ) . error ( e ) ;
369
422
}
370
423
}
371
424
@@ -378,12 +431,20 @@ app.controller('MainController', function ($scope, $timeout) {
378
431
logger . category ( 'app' ) . info ( "Deleted '" + deleteFrom + "'" ) ;
379
432
}
380
433
434
+ function onLnBtnClicked ( $event ) {
435
+ let repoIndex = $ ( $event . target ) . data ( 'repo-index' ) ;
436
+ let repo = $scope . addonStatus [ main . repoList [ repoIndex ] ] [ 'github' ] ;
437
+ let url = repo [ 'url' ] ;
438
+ electron . shell . openExternal ( url ) ;
439
+ }
440
+
381
441
function onDlBtnClicked ( $event ) {
382
442
setTaskAndUpdate ( 'INSTALL' ) ;
383
443
let repoIndex = $ ( $event . target ) . data ( 'repo-index' ) ;
384
444
let repo = $scope . addonStatus [ main . repoList [ repoIndex ] ] [ 'github' ] ;
445
+ let key = main . repoList [ repoIndex ] ;
385
446
$scope . isOpsLocked = true ;
386
- installAddon ( repo , ( ) => {
447
+ installAddon ( key , repo , ( ) => {
387
448
try {
388
449
advanceProgressAndUpdate ( ) ;
389
450
updateInstalledAddonDB ( ) ;
@@ -419,14 +480,15 @@ app.controller('MainController', function ($scope, $timeout) {
419
480
let repoIndex = $ ( $event . target ) . data ( 'repo-index' ) ;
420
481
let repoInstalled = $scope . addonStatus [ main . repoList [ repoIndex ] ] [ 'installed' ] [ blVer ] ;
421
482
let repoGitHub = $scope . addonStatus [ main . repoList [ repoIndex ] ] [ 'github' ] ;
483
+ let key = main . repoList [ repoIndex ] ;
422
484
$scope . isOpsLocked = true ;
423
485
try {
424
486
removeAddon ( repoInstalled ) ;
425
487
}
426
488
catch ( e ) {
427
489
logger . category ( 'app' ) . err ( e ) ;
428
490
}
429
- installAddon ( repoGitHub , ( ) => {
491
+ installAddon ( key , repoGitHub , ( ) => {
430
492
try {
431
493
advanceProgressAndUpdate ( ) ;
432
494
updateInstalledAddonDB ( ) ;
@@ -440,6 +502,8 @@ app.controller('MainController', function ($scope, $timeout) {
440
502
} ) ;
441
503
}
442
504
505
+ // "Link" button
506
+ $scope . onLnBtnClicked = onLnBtnClicked ;
443
507
// "Download" button
444
508
$scope . onDlBtnClicked = onDlBtnClicked ;
445
509
// "Remove" button
0 commit comments