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
8396d6d0
Commit
8396d6d0
authored
Nov 07, 2016
by
神楽坂玲奈
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'v3' of github.com:mycard/mycard into v3
parents
f54873eb
3602ddb6
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
140 additions
and
27 deletions
+140
-27
app/download.service.ts
app/download.service.ts
+29
-3
app/install.service.ts
app/install.service.ts
+27
-21
app/lobby.component.ts
app/lobby.component.ts
+70
-1
app/mycard.component.ts
app/mycard.component.ts
+6
-2
app/task.ts
app/task.ts
+7
-0
apps.json
apps.json
+1
-0
No files found.
app/download.service.ts
View file @
8396d6d0
...
@@ -21,12 +21,18 @@ export class DownloadService {
...
@@ -21,12 +21,18 @@ export class DownloadService {
open
=
this
.
aria2
.
open
();
open
=
this
.
aria2
.
open
();
constructor
(
private
ngZone
:
NgZone
,
private
http
:
Http
)
{
constructor
(
private
ngZone
:
NgZone
,
private
http
:
Http
)
{
this
.
aria2
.
onDownloadComplete
=
(
gid
)
=>
{
this
.
aria2
.
onDownloadComplete
=
(
result
)
=>
{
let
app
=
this
.
gidAppMap
.
get
(
gid
.
gid
);
let
app
=
this
.
gidAppMap
.
get
(
result
.
gid
);
if
(
app
)
{
if
(
app
)
{
this
.
appGidMap
.
delete
(
app
);
this
.
appGidMap
.
delete
(
app
);
this
.
gidAppMap
.
delete
(
gid
.
gid
);
this
.
gidAppMap
.
delete
(
result
.
gid
);
this
.
eventEmitter
.
emit
(
app
.
id
,
'
complete
'
);
this
.
eventEmitter
.
emit
(
app
.
id
,
'
complete
'
);
//
}
if
(
this
.
map
.
get
(
result
.
gid
))
{
this
.
map
.
get
(
result
.
gid
).
complete
();
this
.
map
.
delete
(
result
.
gid
);
}
}
}
}
}
}
...
@@ -73,6 +79,26 @@ export class DownloadService {
...
@@ -73,6 +79,26 @@ export class DownloadService {
return
tasks
;
return
tasks
;
}
}
map
:
Map
<
string
,
any
>
=
new
Map
();
async
addMetalink
(
metalink
:
string
,
library
:
string
)
{
let
meta4
=
btoa
(
metalink
);
let
gid
=
(
await
this
.
aria2
.
addMetalink
(
meta4
,
{
dir
:
library
}))[
0
];
return
Observable
.
create
((
observer
)
=>
{
this
.
map
.
set
(
gid
,
observer
);
let
interval
;
this
.
ngZone
.
runOutsideAngular
(()
=>
{
interval
=
setInterval
(
async
()
=>
{
let
status
=
await
this
.
aria2
.
tellStatus
(
gid
);
this
.
map
.
get
(
gid
).
next
(
status
);
},
1000
)
});
return
()
=>
{
clearInterval
(
interval
);
}
});
}
async
addUri
(
app
:
App
,
path
:
string
):
Promise
<
App
>
{
async
addUri
(
app
:
App
,
path
:
string
):
Promise
<
App
>
{
let
id
=
app
.
id
;
let
id
=
app
.
id
;
await
this
.
open
;
await
this
.
open
;
...
...
app/install.service.ts
View file @
8396d6d0
...
@@ -56,6 +56,7 @@ export class InstallService {
...
@@ -56,6 +56,7 @@ export class InstallService {
input
:
<
ReadableStream
>
tarProcess
.
stderr
,
input
:
<
ReadableStream
>
tarProcess
.
stderr
,
});
});
rl
.
on
(
'
line
'
,
(
input
)
=>
{
rl
.
on
(
'
line
'
,
(
input
)
=>
{
console
.
log
(
input
);
});
});
tarProcess
.
on
(
'
exit
'
,
(
code
)
=>
{
tarProcess
.
on
(
'
exit
'
,
(
code
)
=>
{
if
(
code
===
0
)
{
if
(
code
===
0
)
{
...
@@ -119,6 +120,21 @@ export class InstallService {
...
@@ -119,6 +120,21 @@ export class InstallService {
}
}
}
}
async
getChecksumFile
(
app
:
App
):
Promise
<
Map
<
string
,
string
>
>
{
let
checksumMap
:
Map
<
string
,
string
>
=
await
this
.
http
.
get
(
this
.
checksumUri
+
app
.
id
)
.
map
((
response
)
=>
{
let
map
=
new
Map
<
string
,
string
>
();
for
(
let
line
of
response
.
text
().
split
(
'
\n
'
))
{
if
(
line
!==
""
)
{
let
[
checksum
,
filename
]
=
line
.
split
(
'
'
,
2
);
map
.
set
(
filename
,
checksum
);
}
}
return
map
;
}).
toPromise
();
return
checksumMap
;
}
async
doInstall
()
{
async
doInstall
()
{
for
(
let
app
of
this
.
installQueue
.
keys
())
{
for
(
let
app
of
this
.
installQueue
.
keys
())
{
let
depInstalled
=
app
.
findDependencies
()
let
depInstalled
=
app
.
findDependencies
()
...
@@ -126,18 +142,7 @@ export class InstallService {
...
@@ -126,18 +142,7 @@ export class InstallService {
if
(
depInstalled
&&
!
this
.
installingQueue
.
has
(
app
))
{
if
(
depInstalled
&&
!
this
.
installingQueue
.
has
(
app
))
{
this
.
installingQueue
.
add
(
app
);
this
.
installingQueue
.
add
(
app
);
let
options
=
this
.
installQueue
.
get
(
app
);
let
options
=
this
.
installQueue
.
get
(
app
);
let
checksumMap
:
Map
<
string
,
string
>
=
await
this
.
http
.
get
(
`
${
this
.
checksumUri
}${
app
.
id
}
`
)
let
checksumMap
=
await
this
.
getChecksumFile
(
app
);
.
map
((
response
)
=>
{
let
map
=
new
Map
<
string
,
string
>
();
for
(
let
line
of
response
.
text
().
split
(
'
\n
'
))
{
if
(
line
!==
""
)
{
let
[
checksum
,
filename
]
=
line
.
split
(
'
'
,
2
);
map
.
set
(
filename
,
checksum
);
}
}
return
map
;
}).
toPromise
();
let
packagePath
=
path
.
join
(
options
.
installLibrary
,
'
downloading
'
,
`
${
app
.
id
}
.tar.xz`
);
let
packagePath
=
path
.
join
(
options
.
installLibrary
,
'
downloading
'
,
`
${
app
.
id
}
.tar.xz`
);
let
destPath
:
string
;
let
destPath
:
string
;
if
(
app
.
parent
)
{
if
(
app
.
parent
)
{
...
@@ -198,28 +203,29 @@ export class InstallService {
...
@@ -198,28 +203,29 @@ export class InstallService {
})
})
}
}
async
uninstall
(
app
:
App
)
{
async
uninstall
(
app
:
App
,
restore
=
true
)
{
if
(
!
app
.
parent
)
{
if
(
!
app
.
parent
)
{
let
children
=
this
.
appsService
.
findChildren
(
app
);
let
children
=
this
.
appsService
.
findChildren
(
app
);
for
(
let
child
of
children
)
{
for
(
let
child
of
children
)
{
if
(
child
.
isInstalled
())
{
if
(
child
.
isInstalled
())
{
await
this
.
uninstall
(
child
);
await
this
.
uninstall
(
child
);
}
}
}
}
}
}
let
files
=
Array
.
from
(
app
.
local
.
files
.
keys
()).
sort
().
reverse
();
let
files
=
Array
.
from
(
app
.
local
.
files
.
keys
()).
sort
().
reverse
();
console
.
log
(
files
);
for
(
let
file
of
files
)
{
for
(
let
file
of
files
)
{
let
oldFile
=
file
;
let
oldFile
=
file
;
if
(
!
path
.
isAbsolute
(
file
))
{
if
(
!
path
.
isAbsolute
(
file
))
{
oldFile
=
path
.
join
(
app
.
local
.
path
,
file
);
oldFile
=
path
.
join
(
app
.
local
.
path
,
file
);
}
}
await
this
.
deleteFile
(
oldFile
);
if
(
restore
)
{
if
(
app
.
parent
)
{
await
this
.
deleteFile
(
oldFile
);
let
backFile
=
path
.
join
(
app
.
local
.
path
,
"
backup
"
,
file
);
if
(
app
.
parent
)
{
await
new
Promise
((
resolve
,
reject
)
=>
{
let
backFile
=
path
.
join
(
app
.
local
.
path
,
"
backup
"
,
file
);
fs
.
rename
(
backFile
,
oldFile
,
resolve
);
await
new
Promise
((
resolve
,
reject
)
=>
{
});
fs
.
rename
(
backFile
,
oldFile
,
resolve
);
});
}
}
}
}
}
...
...
app/lobby.component.ts
View file @
8396d6d0
...
@@ -6,6 +6,11 @@ import {AppsService} from "./apps.service";
...
@@ -6,6 +6,11 @@ import {AppsService} from "./apps.service";
import
{
LoginService
}
from
"
./login.service
"
;
import
{
LoginService
}
from
"
./login.service
"
;
import
{
App
,
Category
}
from
"
./app
"
;
import
{
App
,
Category
}
from
"
./app
"
;
import
{
DownloadService
}
from
"
./download.service
"
;
import
{
DownloadService
}
from
"
./download.service
"
;
import
{
InstallService
}
from
"
./install.service
"
;
import
{
Http
}
from
"
@angular/http
"
;
import
*
as
path
from
'
path
'
;
import
{
InstallConfig
}
from
"
./install-config
"
;
@
Component
({
@
Component
({
selector
:
'
lobby
'
,
selector
:
'
lobby
'
,
templateUrl
:
'
app/lobby.component.html
'
,
templateUrl
:
'
app/lobby.component.html
'
,
...
@@ -17,7 +22,8 @@ export class LobbyComponent implements OnInit {
...
@@ -17,7 +22,8 @@ export class LobbyComponent implements OnInit {
currentApp
:
App
;
currentApp
:
App
;
private
apps
:
Map
<
string
,
App
>
;
private
apps
:
Map
<
string
,
App
>
;
constructor
(
private
appsService
:
AppsService
,
private
loginService
:
LoginService
,
private
downloadService
:
DownloadService
)
{
constructor
(
private
appsService
:
AppsService
,
private
loginService
:
LoginService
,
private
downloadService
:
DownloadService
,
private
installService
:
InstallService
,
private
http
:
Http
)
{
this
.
candy_url
=
'
./candy/index.html?jid=
'
+
this
.
loginService
.
user
.
username
+
'
@mycard.moe&password=
'
+
this
.
loginService
.
user
.
external_id
+
'
&nickname=
'
+
this
.
loginService
.
user
.
username
+
'
&autojoin=ygopro_china_north@conference.mycard.moe
'
this
.
candy_url
=
'
./candy/index.html?jid=
'
+
this
.
loginService
.
user
.
username
+
'
@mycard.moe&password=
'
+
this
.
loginService
.
user
.
external_id
+
'
&nickname=
'
+
this
.
loginService
.
user
.
username
+
'
&autojoin=ygopro_china_north@conference.mycard.moe
'
}
}
...
@@ -26,7 +32,70 @@ export class LobbyComponent implements OnInit {
...
@@ -26,7 +32,70 @@ export class LobbyComponent implements OnInit {
.
then
((
apps
)
=>
{
.
then
((
apps
)
=>
{
this
.
apps
=
apps
;
this
.
apps
=
apps
;
this
.
currentApp
=
this
.
apps
.
get
(
"
th06
"
);
this
.
currentApp
=
this
.
apps
.
get
(
"
th06
"
);
this
.
updateApp
();
})
})
}
async
updateApp
()
{
let
updateServer
=
"
http://thief.mycard.moe/update/metalinks/
"
;
let
checksumServer
=
"
http://thief.mycard.moe/checksums/
"
;
for
(
let
app
of
this
.
apps
.
values
())
{
if
(
app
.
isInstalled
()
&&
app
.
version
!=
app
.
local
.
version
)
{
let
checksumMap
=
await
this
.
installService
.
getChecksumFile
(
app
);
let
filesMap
=
app
.
local
.
files
;
let
deleteList
=
[];
let
addList
=
[];
let
changeList
=
[];
for
(
let
[
file
,
checksum
]
of
filesMap
)
{
let
t
=
checksumMap
.
get
(
file
);
if
(
!
t
)
{
deleteList
.
push
(
file
);
}
else
if
(
t
!==
checksum
)
{
changeList
.
push
(
file
);
}
}
for
(
let
file
of
checksumMap
.
keys
())
{
if
(
!
filesMap
.
has
(
file
))
{
changeList
.
push
(
file
);
}
}
let
metalink
=
await
this
.
http
.
post
(
updateServer
+
app
.
id
,
changeList
).
map
((
response
)
=>
response
.
text
())
.
toPromise
();
let
meta
=
new
DOMParser
().
parseFromString
(
metalink
,
"
text/xml
"
);
let
filename
=
meta
.
getElementsByTagName
(
'
file
'
)[
0
].
getAttribute
(
'
name
'
);
let
dir
=
path
.
join
(
path
.
dirname
(
app
.
local
.
path
),
"
downloading
"
);
let
a
=
await
this
.
downloadService
.
addMetalink
(
metalink
,
dir
);
await
new
Promise
((
resolve
,
reject
)
=>
{
a
.
subscribe
((
status
)
=>
{
console
.
log
(
status
);
},
(
err
)
=>
{
reject
()
},
()
=>
{
resolve
();
});
});
for
(
let
file
of
deleteList
)
{
await
this
.
installService
.
deleteFile
(
file
);
}
app
.
local
.
version
=
app
.
version
;
app
.
local
.
files
=
checksumMap
;
localStorage
.
setItem
(
app
.
id
,
JSON
.
stringify
(
app
.
local
));
await
this
.
installService
.
extract
(
path
.
join
(
dir
,
filename
),
app
.
local
.
path
);
let
children
=
this
.
appsService
.
findChildren
(
app
);
for
(
let
child
of
children
)
{
if
(
child
.
isInstalled
())
{
await
this
.
installService
.
uninstall
(
child
,
false
);
this
.
installService
.
add
(
child
,
new
InstallConfig
(
child
,
path
.
dirname
((
app
.
local
.
path
))));
await
this
.
installService
.
getComplete
(
child
);
console
.
log
(
"
282828
"
)
}
}
}
}
}
}
chooseApp
(
app
:
App
)
{
chooseApp
(
app
:
App
)
{
...
...
app/mycard.component.ts
View file @
8396d6d0
import
{
Component
,
Renderer
,
ChangeDetectorRef
}
from
"
@angular/core
"
;
import
{
Component
,
Renderer
,
ChangeDetectorRef
,
OnInit
}
from
"
@angular/core
"
;
import
{
TranslateService
}
from
"
ng2-translate
"
;
import
{
TranslateService
}
from
"
ng2-translate
"
;
import
{
remote
}
from
"
electron
"
;
import
{
remote
}
from
"
electron
"
;
import
{
LoginService
}
from
"
./login.service
"
;
import
{
LoginService
}
from
"
./login.service
"
;
...
@@ -11,13 +11,17 @@ import {LoginService} from "./login.service";
...
@@ -11,13 +11,17 @@ import {LoginService} from "./login.service";
})
})
export
class
MyCardComponent
{
export
class
MyCardComponent
implements
OnInit
{
currentPage
:
string
=
"
lobby
"
;
currentPage
:
string
=
"
lobby
"
;
platform
=
process
.
platform
;
platform
=
process
.
platform
;
currentWindow
=
remote
.
getCurrentWindow
();
currentWindow
=
remote
.
getCurrentWindow
();
window
=
window
;
window
=
window
;
ngOnInit
()
{
}
constructor
(
private
renderer
:
Renderer
,
private
translate
:
TranslateService
,
private
loginService
:
LoginService
,
private
ref
:
ChangeDetectorRef
)
{
constructor
(
private
renderer
:
Renderer
,
private
translate
:
TranslateService
,
private
loginService
:
LoginService
,
private
ref
:
ChangeDetectorRef
)
{
renderer
.
listenGlobal
(
'
window
'
,
'
message
'
,
(
event
)
=>
{
renderer
.
listenGlobal
(
'
window
'
,
'
message
'
,
(
event
)
=>
{
console
.
log
(
event
);
console
.
log
(
event
);
...
...
app/task.ts
0 → 100644
View file @
8396d6d0
/**
* Created by weijian on 2016/11/6.
*/
export
class
Task
{
downloadUrl
:
string
;
}
apps.json
View file @
8396d6d0
...
@@ -62,6 +62,7 @@
...
@@ -62,6 +62,7 @@
]
]
},
},
"version"
:
{
"version"
:
{
"win32"
:
"1.09"
,
"darwin"
:
"1.06"
"darwin"
:
"1.06"
},
},
"download"
:
{
"download"
:
{
...
...
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