Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
moecube
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
JoyJ
moecube
Commits
6a33d0bc
Commit
6a33d0bc
authored
Dec 02, 2016
by
wudizhanche1000
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
下载速度显示。
parent
ab762033
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
96 additions
and
58 deletions
+96
-58
app/app.ts
app/app.ts
+14
-8
app/apps.service.ts
app/apps.service.ts
+18
-3
app/download.service.ts
app/download.service.ts
+11
-1
app/install.service.ts
app/install.service.ts
+53
-46
No files found.
app/app.ts
View file @
6a33d0bc
...
@@ -30,7 +30,19 @@ export interface Action {
...
@@ -30,7 +30,19 @@ export interface Action {
export
class
AppStatus
{
export
class
AppStatus
{
progress
:
number
;
progress
:
number
;
total
:
number
;
total
:
number
;
status
:
string
;
private
_status
:
string
;
get
status
():
string
{
return
this
.
_status
}
set
status
(
status
:
string
)
{
this
.
progress
=
0
;
this
.
total
=
0
;
this
.
progressMessage
=
''
;
this
.
_status
=
status
;
}
progressMessage
:
string
;
}
}
export
class
App
{
export
class
App
{
id
:
string
;
id
:
string
;
...
@@ -94,13 +106,7 @@ export class App {
...
@@ -94,13 +106,7 @@ export class App {
}
}
progressMessage
():
string
|
undefined
{
progressMessage
():
string
|
undefined
{
if
(
this
.
isDownloading
())
{
return
this
.
status
.
progressMessage
;
return
'
1M/s
'
}
else
if
(
this
.
isInstalling
())
{
return
'
マニュアル/index.html
'
}
else
if
(
this
.
isWaiting
())
{
return
'
wine, Neko Project II
'
}
}
}
constructor
(
app
:
any
)
{
constructor
(
app
:
any
)
{
...
...
app/apps.service.ts
View file @
6a33d0bc
...
@@ -120,7 +120,7 @@ export class AppsService {
...
@@ -120,7 +120,7 @@ export class AppsService {
const
addDownloadTask
=
async
(
app
:
App
,
dir
:
string
)
=>
{
const
addDownloadTask
=
async
(
app
:
App
,
dir
:
string
)
=>
{
let
metalinkUrl
=
app
.
download
;
let
metalinkUrl
=
app
.
download
;
if
(
app
.
id
===
"
ygopro
"
)
{
if
(
app
.
id
===
"
ygopro
"
)
{
metalinkUrl
=
"
https://thief.mycard.moe/metalinks/ygopro-
"
+
process
.
platform
+
"
.meta4
"
;
metalinkUrl
=
"
https://thief.mycard.moe/metalinks/ygopro-
"
+
process
.
platform
+
"
.meta4
"
;
}
}
let
metalink
=
await
this
.
http
.
get
(
metalinkUrl
).
map
((
response
)
=>
{
let
metalink
=
await
this
.
http
.
get
(
metalinkUrl
).
map
((
response
)
=>
{
return
response
.
text
()
return
response
.
text
()
...
@@ -130,8 +130,24 @@ export class AppsService {
...
@@ -130,8 +130,24 @@ export class AppsService {
let
observable
=
this
.
downloadService
.
downloadProgress
(
downloadId
);
let
observable
=
this
.
downloadService
.
downloadProgress
(
downloadId
);
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
observable
.
subscribe
((
task
)
=>
{
observable
.
subscribe
((
task
)
=>
{
if
(
task
.
totalLength
)
{
app
.
status
.
total
=
task
.
totalLength
;
}
else
{
app
.
status
.
total
=
0
;
}
app
.
status
.
progress
=
task
.
completedLength
;
app
.
status
.
progress
=
task
.
completedLength
;
app
.
status
.
total
=
task
.
totalLength
;
console
.
log
(
task
);
if
(
task
.
downloadSpeed
)
{
let
currentSpeed
=
parseInt
(
task
.
downloadSpeed
);
const
speedUnit
=
[
"
Byte/s
"
,
"
KB/s
"
,
"
MB/s
"
,
"
GB/s
"
,
"
TB/s
"
];
let
currentUnit
=
Math
.
floor
(
Math
.
log
(
currentSpeed
)
/
Math
.
log
(
1024
));
console
.
log
(
currentSpeed
,
currentUnit
);
app
.
status
.
progressMessage
=
(
currentSpeed
/
1024
**
currentUnit
).
toFixed
(
1
)
+
"
"
+
speedUnit
[
currentUnit
];
}
else
{
app
.
status
.
progressMessage
=
''
;
}
this
.
ref
.
tick
();
this
.
ref
.
tick
();
},
(
error
)
=>
{
},
(
error
)
=>
{
reject
(
error
);
reject
(
error
);
...
@@ -146,7 +162,6 @@ export class AppsService {
...
@@ -146,7 +162,6 @@ export class AppsService {
let
apps
:
App
[]
=
[];
let
apps
:
App
[]
=
[];
let
dependencies
=
app
.
findDependencies
();
let
dependencies
=
app
.
findDependencies
();
apps
.
push
(...
dependencies
,
app
);
apps
.
push
(...
dependencies
,
app
);
console
.
log
(
apps
);
let
downloadPath
=
path
.
join
(
option
.
installLibrary
,
'
downloading
'
);
let
downloadPath
=
path
.
join
(
option
.
installLibrary
,
'
downloading
'
);
let
tasks
:
Promise
<
any
>
[]
=
[];
let
tasks
:
Promise
<
any
>
[]
=
[];
for
(
let
a
of
apps
)
{
for
(
let
a
of
apps
)
{
...
...
app/download.service.ts
View file @
6a33d0bc
...
@@ -73,21 +73,31 @@ export class DownloadService {
...
@@ -73,21 +73,31 @@ export class DownloadService {
let
status
=
''
;
let
status
=
''
;
let
completedLength
=
0
;
let
completedLength
=
0
;
let
totalLength
=
0
;
let
totalLength
=
0
;
let
downloadSpeed
=
0
;
let
gidList
=
this
.
map
.
get
(
id
)
!
;
let
gidList
=
this
.
map
.
get
(
id
)
!
;
this
.
updateEmitter
.
subscribe
((
value
:
string
)
=>
{
this
.
updateEmitter
.
subscribe
((
value
:
string
)
=>
{
let
statusList
=
new
Array
(
gidList
.
length
);
let
statusList
=
new
Array
(
gidList
.
length
);
let
newCompletedLength
=
0
;
let
newCompletedLength
=
0
;
let
newTotalLength
=
0
;
let
newTotalLength
=
0
;
let
newDownloadSpeed
=
0
;
for
(
let
[
index
,
gid
]
of
gidList
.
entries
())
{
for
(
let
[
index
,
gid
]
of
gidList
.
entries
())
{
let
task
=
this
.
taskList
.
get
(
gid
)
!
;
let
task
=
this
.
taskList
.
get
(
gid
)
!
;
statusList
[
index
]
=
task
.
status
;
statusList
[
index
]
=
task
.
status
;
newCompletedLength
+=
parseInt
(
task
.
completedLength
);
newCompletedLength
+=
parseInt
(
task
.
completedLength
);
newTotalLength
+=
parseInt
(
task
.
totalLength
);
newTotalLength
+=
parseInt
(
task
.
totalLength
);
newDownloadSpeed
+=
parseInt
(
task
.
downloadSpeed
);
}
}
if
(
newCompletedLength
!==
completedLength
||
newTotalLength
!==
totalLength
)
{
if
(
newCompletedLength
!==
completedLength
||
newTotalLength
!==
totalLength
)
{
completedLength
=
newCompletedLength
;
completedLength
=
newCompletedLength
;
totalLength
=
newTotalLength
;
totalLength
=
newTotalLength
;
observer
.
next
({
status
:
status
,
completedLength
:
completedLength
,
totalLength
:
totalLength
});
downloadSpeed
=
newDownloadSpeed
;
observer
.
next
({
status
:
status
,
completedLength
:
completedLength
,
totalLength
:
totalLength
,
downloadSpeed
:
downloadSpeed
});
}
}
status
=
statusList
.
reduce
((
value
,
current
)
=>
{
status
=
statusList
.
reduce
((
value
,
current
)
=>
{
if
(
value
===
"
complete
"
&&
current
===
"
complete
"
)
{
if
(
value
===
"
complete
"
&&
current
===
"
complete
"
)
{
...
...
app/install.service.ts
View file @
6a33d0bc
...
@@ -84,55 +84,63 @@ export class InstallService {
...
@@ -84,55 +84,63 @@ export class InstallService {
this
.
installingId
=
id
;
this
.
installingId
=
id
;
try
{
try
{
let
app
=
task
.
app
;
let
app
=
task
.
app
;
let
option
=
task
.
option
;
let
dependencies
=
app
.
findDependencies
();
// if (!app.isInstalled()) {
let
readyForInstall
=
dependencies
.
every
((
dependency
)
=>
{
let
checksumFile
=
await
this
.
getChecksumFile
(
app
);
return
dependency
.
isReady
();
console
.
log
(
checksumFile
);
});
if
(
app
.
parent
)
{
if
(
readyForInstall
)
{
let
conflictFiles
=
new
Set
<
string
>
();
let
option
=
task
.
option
;
let
parentFilesMap
=
app
.
parent
.
local
!
.
files
;
// if (!app.isInstalled()) {
for
(
let
key
of
checksumFile
.
keys
())
{
let
checksumFile
=
await
this
.
getChecksumFile
(
app
);
if
(
parentFilesMap
.
has
(
key
))
{
if
(
app
.
parent
)
{
conflictFiles
.
add
(
key
);
let
conflictFiles
=
new
Set
<
string
>
();
let
parentFilesMap
=
app
.
parent
.
local
!
.
files
;
for
(
let
key
of
checksumFile
.
keys
())
{
if
(
parentFilesMap
.
has
(
key
))
{
conflictFiles
.
add
(
key
);
}
}
if
(
conflictFiles
.
size
>
0
)
{
let
backupPath
=
path
.
join
(
option
.
installLibrary
,
"
backup
"
,
app
.
parent
.
id
);
this
.
backupFiles
(
option
.
installDir
,
backupPath
,
conflictFiles
);
}
}
}
}
if
(
conflictFiles
.
size
>
0
)
{
let
allFiles
=
new
Set
(
checksumFile
.
keys
());
let
backupPath
=
path
.
join
(
option
.
installLibrary
,
"
backup
"
,
app
.
parent
.
id
);
app
.
status
.
status
=
"
installing
"
;
this
.
backupFiles
(
option
.
installDir
,
backupPath
,
conflictFiles
);
app
.
status
.
total
=
allFiles
.
size
;
app
.
status
.
progress
=
0
;
// let timeNow = new Date().getTime();
for
(
let
file
of
option
.
downloadFiles
)
{
await
this
.
createDirectory
(
option
.
installDir
);
let
interval
=
setInterval
(()
=>
{
},
500
);
await
new
Promise
((
resolve
,
reject
)
=>
{
this
.
extract
(
file
,
option
.
installDir
).
subscribe
(
(
lastItem
:
string
)
=>
{
app
.
status
.
progress
+=
1
;
app
.
status
.
progressMessage
=
lastItem
;
// if (new Date().getTime() - timeNow > 500) {
// timeNow = new Date().getTime();
// }
},
(
error
)
=>
{
reject
(
error
);
},
()
=>
{
resolve
();
});
});
clearInterval
(
interval
);
}
}
await
this
.
postInstall
(
app
,
option
.
installDir
);
let
local
=
new
AppLocal
();
local
.
path
=
option
.
installDir
;
local
.
files
=
checksumFile
;
local
.
version
=
app
.
version
;
app
.
local
=
local
;
this
.
saveAppLocal
(
app
);
app
.
status
.
status
=
"
ready
"
;
}
}
let
allFiles
=
new
Set
(
checksumFile
.
keys
());
app
.
status
.
status
=
"
installing
"
;
app
.
status
.
total
=
allFiles
.
size
;
app
.
status
.
progress
=
0
;
let
timeNow
=
new
Date
().
getTime
();
for
(
let
file
of
option
.
downloadFiles
)
{
await
this
.
createDirectory
(
option
.
installDir
);
await
new
Promise
((
resolve
,
reject
)
=>
{
this
.
extract
(
file
,
option
.
installDir
).
subscribe
(
(
lastItem
:
string
)
=>
{
console
.
log
(
app
.
status
.
progress
,
app
.
status
.
total
,
lastItem
);
app
.
status
.
progress
+=
1
;
if
(
new
Date
().
getTime
()
-
timeNow
>
500
)
{
timeNow
=
new
Date
().
getTime
();
this
.
ref
.
tick
();
}
},
(
error
)
=>
{
reject
(
error
);
},
()
=>
{
resolve
();
});
});
}
let
local
=
new
AppLocal
();
local
.
path
=
option
.
installDir
;
local
.
files
=
checksumFile
;
local
.
version
=
app
.
version
;
app
.
local
=
local
;
this
.
saveAppLocal
(
app
);
app
.
status
.
status
=
"
ready
"
;
// }
// }
}
catch
(
e
)
{
}
catch
(
e
)
{
throw
e
;
throw
e
;
...
@@ -168,7 +176,6 @@ export class InstallService {
...
@@ -168,7 +176,6 @@ export class InstallService {
input
:
<
ReadableStream
>
tarProcess
.
stderr
,
input
:
<
ReadableStream
>
tarProcess
.
stderr
,
});
});
rl
.
on
(
'
line
'
,
(
input
:
string
)
=>
{
rl
.
on
(
'
line
'
,
(
input
:
string
)
=>
{
console
.
log
(
input
.
split
(
"
"
,
2
));
observer
.
next
(
input
.
split
(
"
"
,
2
)[
1
]);
observer
.
next
(
input
.
split
(
"
"
,
2
)[
1
]);
});
});
tarProcess
.
on
(
'
exit
'
,
(
code
)
=>
{
tarProcess
.
on
(
'
exit
'
,
(
code
)
=>
{
...
...
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