Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
mycard
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
syntax_j
mycard
Commits
b99d8788
Commit
b99d8788
authored
Sep 12, 2016
by
h3remi7
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add tar install
parent
00440da2
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
161 additions
and
8 deletions
+161
-8
app/app-detail.component.html
app/app-detail.component.html
+6
-0
app/app-detail.component.ts
app/app-detail.component.ts
+2
-2
app/app-local.ts
app/app-local.ts
+1
-0
app/apps.service.ts
app/apps.service.ts
+152
-6
No files found.
app/app-detail.component.html
View file @
b99d8788
...
@@ -7,6 +7,8 @@
...
@@ -7,6 +7,8 @@
<button
type=
"button"
class=
"btn btn-secondary"
>
正版代购
</button>
<button
type=
"button"
class=
"btn btn-secondary"
>
正版代购
</button>
</div>
</div>
<div
*ngIf=
"appsService.getDownloadInfo(routingService.app)"
>
<div
*ngIf=
"appsService.getDownloadInfo(routingService.app)"
>
<div
*ngIf=
"appsService.getDownloadInfo(routingService.app).status === 'install'"
>
正在安装...
</div>
<div
*ngIf=
"appsService.getDownloadInfo(routingService.app).status === 'wait'"
>
等待安装...
</div>
<progress
*ngIf=
"appsService.getDownloadInfo(routingService.app).status === 'active'"
<progress
*ngIf=
"appsService.getDownloadInfo(routingService.app).status === 'active'"
class=
"progress progress-striped progress-animated"
class=
"progress progress-striped progress-animated"
value=
"{{appsService.getDownloadInfo(routingService.app).progress}}"
max=
"100"
>
value=
"{{appsService.getDownloadInfo(routingService.app).progress}}"
max=
"100"
>
...
@@ -67,6 +69,8 @@
...
@@ -67,6 +69,8 @@
<td
*ngIf=
"!checkInstall(mod.id)"
>
<td
*ngIf=
"!checkInstall(mod.id)"
>
<button
*ngIf=
"!appsService.getDownloadInfo(mod.id)"
(click)=
"install(mod.id)"
type=
"button"
class=
"btn btn-primary btn-sm"
>
安装
</button>
<button
*ngIf=
"!appsService.getDownloadInfo(mod.id)"
(click)=
"install(mod.id)"
type=
"button"
class=
"btn btn-primary btn-sm"
>
安装
</button>
<progress
*ngIf=
"appsService.getDownloadInfo(mod.id) && appsService.getDownloadInfo(mod.id).status === 'active'"
class=
"progress progress-striped progress-animated"
value=
"{{appsService.getDownloadInfo(mod.id).progress}}"
max=
"100"
></progress>
<progress
*ngIf=
"appsService.getDownloadInfo(mod.id) && appsService.getDownloadInfo(mod.id).status === 'active'"
class=
"progress progress-striped progress-animated"
value=
"{{appsService.getDownloadInfo(mod.id).progress}}"
max=
"100"
></progress>
<div
*ngIf=
"appsService.getDownloadInfo(mod.id) && appsService.getDownloadInfo(mod.id).status === 'wait'"
>
等待安装...
</div>
<div
*ngIf=
"appsService.getDownloadInfo(mod.id) && appsService.getDownloadInfo(mod.id).status === 'install'"
>
正在安装...
</div>
</td>
</td>
</tr>
</tr>
</tbody>
</tbody>
...
@@ -77,7 +81,9 @@
...
@@ -77,7 +81,9 @@
<pre
class=
"debug"
>
<pre
class=
"debug"
>
{{appsService.downloadsInfo | json}}
{{appsService.downloadsInfo | json}}
{{appsService.installConfig | json}}
{{appsService.installConfig | json}}
{{appsService.tarQueue | json}}
</pre>
</pre>
<button
(click)=
"appsService.doTar()"
>
DOTAR
</button>
<!-- Modal -->
<!-- Modal -->
<div
class=
"modal fade"
id=
"install-modal"
tabindex=
"-1"
role=
"dialog"
aria-labelledby=
"myModalLabel"
<div
class=
"modal fade"
id=
"install-modal"
tabindex=
"-1"
role=
"dialog"
aria-labelledby=
"myModalLabel"
...
...
app/app-detail.component.ts
View file @
b99d8788
...
@@ -4,6 +4,7 @@ import { RoutingService } from './routing.service'
...
@@ -4,6 +4,7 @@ import { RoutingService } from './routing.service'
import
{
App
}
from
"
./app
"
;
import
{
App
}
from
"
./app
"
;
declare
var
process
;
declare
var
process
;
declare
var
$
;
@
Component
({
@
Component
({
selector
:
'
app-detail
'
,
selector
:
'
app-detail
'
,
...
@@ -124,8 +125,7 @@ export class AppDetailComponent {
...
@@ -124,8 +125,7 @@ export class AppDetailComponent {
}
}
}
}
//TODO tar file
$
(
"
#install-modal
"
).
modal
(
"
hide
"
);
}
}
...
...
app/app-local.ts
View file @
b99d8788
...
@@ -4,4 +4,5 @@
...
@@ -4,4 +4,5 @@
export
class
AppLocal
{
export
class
AppLocal
{
path
:
string
;
path
:
string
;
version
:
string
;
version
:
string
;
files
:
string
[];
}
}
app/apps.service.ts
View file @
b99d8788
...
@@ -31,11 +31,16 @@ export class AppsService {
...
@@ -31,11 +31,16 @@ export class AppsService {
}
}
os
=
window
[
'
System
'
].
_nodeRequire
(
'
os
'
);
fs
=
window
[
'
System
'
].
_nodeRequire
(
'
fs
'
);
fs
=
window
[
'
System
'
].
_nodeRequire
(
'
fs
'
);
path
=
window
[
'
System
'
].
_nodeRequire
(
'
path
'
);
path
=
window
[
'
System
'
].
_nodeRequire
(
'
path
'
);
mkdirp
=
window
[
'
System
'
].
_nodeRequire
(
'
mkdirp
'
);
mkdirp
=
window
[
'
System
'
].
_nodeRequire
(
'
mkdirp
'
);
electron
=
window
[
'
System
'
].
_nodeRequire
(
'
electron
'
);
electron
=
window
[
'
System
'
].
_nodeRequire
(
'
electron
'
);
Aria2
=
window
[
'
System
'
].
_nodeRequire
(
'
aria2
'
);
Aria2
=
window
[
'
System
'
].
_nodeRequire
(
'
aria2
'
);
spawn
=
window
[
'
System
'
].
_nodeRequire
(
'
child_process
'
);
execFile
=
window
[
'
System
'
].
_nodeRequire
(
'
child_process
'
).
execFile
;
//localStorage = window['localStorage'];
data
:
App
[];
data
:
App
[];
...
@@ -70,6 +75,12 @@ export class AppsService {
...
@@ -70,6 +75,12 @@ export class AppsService {
}
else
{
}
else
{
this
.
downloadsInfo
[
index
].
status
=
"
wait
"
;
this
.
downloadsInfo
[
index
].
status
=
"
wait
"
;
let
tarObj
=
{
id
:
this
.
downloadsInfo
[
index
].
id
,
xzFile
:
res
.
files
[
0
].
path
,
installDir
:
this
.
installConfig
.
installDir
};
this
.
tarPush
(
tarObj
);
}
}
}
else
{
}
else
{
console
.
log
(
"
cannot found download info!
"
);
console
.
log
(
"
cannot found download info!
"
);
...
@@ -115,7 +126,23 @@ export class AppsService {
...
@@ -115,7 +126,23 @@ export class AppsService {
getApps
(
callback
)
{
getApps
(
callback
)
{
this
.
http
.
get
(
'
./apps.json
'
)
this
.
http
.
get
(
'
./apps.json
'
)
.
map
(
response
=>
{
.
map
(
response
=>
{
return
response
.
json
()
let
apps
=
response
.
json
();
let
localAppData
=
JSON
.
parse
(
localStorage
.
getItem
(
"
localAppData
"
));
console
.
log
(
"
app:
"
,
apps
);
console
.
log
(
"
store:
"
,
localAppData
);
apps
=
apps
.
map
((
app
)
=>
{
if
(
localAppData
)
{
localAppData
.
map
((
v
)
=>
{
if
(
v
.
id
==
app
.
id
)
{
app
.
local
=
v
.
local
;
}
});
}
return
app
;
});
return
apps
;
})
})
.
subscribe
((
data
)
=>
{
.
subscribe
((
data
)
=>
{
this
.
data
=
data
;
this
.
data
=
data
;
...
@@ -140,8 +167,6 @@ export class AppsService {
...
@@ -140,8 +167,6 @@ export class AppsService {
download
(
id
,
uri
)
{
download
(
id
,
uri
)
{
//console.log(id);
//console.log(id);
//console.log(uri);
//console.log(uri);
let
tmp_gid
;
let
i
=
this
.
downloadsInfo
.
findIndex
((
v
)
=>
{
return
v
.
id
==
id
});
//console.log(i);
//console.log(i);
if
(
this
.
downloadsInfo
.
findIndex
((
v
)
=>
{
return
v
.
id
==
id
})
!==
-
1
)
{
if
(
this
.
downloadsInfo
.
findIndex
((
v
)
=>
{
return
v
.
id
==
id
})
!==
-
1
)
{
console
.
log
(
"
this app downloading
"
)
console
.
log
(
"
this app downloading
"
)
...
@@ -182,7 +207,7 @@ export class AppsService {
...
@@ -182,7 +207,7 @@ export class AppsService {
}
}
let
tmp
=
{
let
tmp
=
{
installDir
:
__dirname
,
installDir
:
this
.
path
.
join
(
this
.
electron
.
remote
.
app
.
getPath
(
'
appData
'
),
'
mycard
'
)
,
shortcut
:
{
shortcut
:
{
desktop
:
false
,
desktop
:
false
,
application
:
false
application
:
false
...
@@ -190,11 +215,132 @@ export class AppsService {
...
@@ -190,11 +215,132 @@ export class AppsService {
mods
:
mods
mods
:
mods
};
};
//console.log(tmp);
//console.log(tmp);
this
.
installConfig
=
tmp
;
this
.
installConfig
=
tmp
;
return
tmp
;
return
tmp
;
}
}
// tar
tarQueue
=
[];
isExtracting
=
false
;
tarPush
(
tarObj
)
{
this
.
tarQueue
.
push
(
tarObj
);
if
(
this
.
tarQueue
.
length
>
0
&&
!
this
.
isExtracting
)
{
this
.
doTar
();
}
}
doTar
()
{
let
tarPath
;
switch
(
process
.
platform
)
{
case
'
win32
'
:
tarPath
=
this
.
path
.
join
(
process
.
execPath
,
'
..
'
,
'
..
'
,
'
tar.exe
'
);
break
;
case
'
darwin
'
:
tarPath
=
'
bsdtar
'
;
// for debug
break
;
default
:
throw
'
unsupported platform
'
;
}
let
opt
=
{
};
let
tarObj
;
if
(
this
.
tarQueue
.
length
>
0
)
{
tarObj
=
this
.
tarQueue
[
0
];
}
else
{
console
.
log
(
"
Empty Queue!
"
);
return
;
}
this
.
isExtracting
=
true
;
console
.
log
(
"
Start tar
"
+
tarObj
.
id
);
let
downLoadsInfoIndex
=
this
.
downloadsInfo
.
findIndex
((
v
)
=>
{
return
v
.
id
==
tarObj
.
id
});
if
(
downLoadsInfoIndex
!==
-
1
)
{
this
.
downloadsInfo
[
downLoadsInfoIndex
].
status
=
"
install
"
;
}
else
{
console
.
log
(
"
cannot found download info!
"
);
}
let
xzFile
=
tarObj
.
xzFile
;
let
installDir
=
this
.
path
.
join
(
tarObj
.
installDir
,
tarObj
.
id
);
if
(
!
this
.
fs
.
existsSync
(
installDir
))
{
console
.
log
(
'
app dir not exists
'
);
this
.
mkdirp
(
installDir
,
(
err
)
=>
{
if
(
err
)
{
console
.
error
(
err
)
}
else
{
console
.
log
(
'
create app dir
'
);
}
});
}
let
tar
=
this
.
execFile
(
tarPath
,
[
'
xvf
'
,
xzFile
,
'
-C
'
,
installDir
],
opt
,
(
err
,
stdout
,
stderr
)
=>
{
if
(
err
)
{
throw
err
;
}
let
re
=
/^x
\s(
.*
)
/
;
let
logArr
=
stderr
.
toString
().
trim
().
split
(
this
.
os
.
EOL
);
logArr
=
logArr
.
map
((
v
)
=>
{
if
(
v
.
match
(
re
))
{
return
v
.
match
(
re
)[
1
];
}
else
{
console
.
log
(
"
no match
"
);
return
v
;
}
});
let
appLocal
=
{
id
:
tarObj
.
id
,
local
:
{
path
:
installDir
,
version
:
"
0.1
"
,
files
:
logArr
}
};
let
localAppData
=
JSON
.
parse
(
localStorage
.
getItem
(
"
localAppData
"
));
if
(
!
localAppData
||
!
Array
.
isArray
(
localAppData
))
{
localAppData
=
[];
}
let
index
=
localAppData
.
findIndex
((
v
)
=>
{
return
v
.
id
==
tarObj
.
id
;
});
if
(
index
===
-
1
)
{
localAppData
.
push
(
appLocal
);
}
else
{
localAppData
[
index
]
=
appLocal
;
}
localStorage
.
setItem
(
"
localAppData
"
,
JSON
.
stringify
(
localAppData
));
let
tmp
=
this
.
tarQueue
.
shift
();
this
.
isExtracting
=
false
;
this
.
downloadsInfo
[
downLoadsInfoIndex
].
status
=
"
complete
"
;
this
.
data
=
this
.
data
.
map
((
app
)
=>
{
if
(
app
.
id
==
tarObj
.
id
)
{
app
.
local
=
appLocal
.
local
;
}
return
app
;
});
console
.
log
(
tmp
);
console
.
log
(
"
this app complete!
"
);
console
.
log
(
localAppData
);
this
.
doTar
();
});
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment