Commit 30324532 authored by 神楽坂玲奈's avatar 神楽坂玲奈

ygopro import

parent 4c7f61d6
......@@ -18,9 +18,7 @@ import {InstallOption} from "./install-option";
import {ComparableSet} from "./shared/ComparableSet";
import {Observable, Observer} from "rxjs/Rx";
import Timer = NodeJS.Timer;
// import mkdirp = require("mkdirp");
import ReadableStream = NodeJS.ReadableStream;
const Aria2 = require('aria2');
const sudo = require('electron-sudo');
const Logger = {
......@@ -45,6 +43,8 @@ interface Connection {
connection: WebSocket, address: string | null
}
declare const System: any;
@Injectable()
export class AppsService {
......@@ -141,18 +141,44 @@ export class AppsService {
}
}
async migrate_v2_ygopro() {
// 导入萌卡 v2 的 YGOPRO
if (this.apps.get('ygopro')!.isInstalled()) {
let app = this.apps.get('ygopro')!;
if (app.isInstalled() || localStorage.getItem('migrate_v2_ygopro')) {
return
}
try {
const legacy_ygopro_path = require(path.join(remote.app.getPath('appData'), 'mycard', 'db.json')).local.ygopro.path;
const legacy_ygopro_path = System._nodeRequire(path.join(remote.app.getPath('appData'), 'mycard', 'db.json')).local.ygopro.path;
if (legacy_ygopro_path) {
// TODO: 导入YGOPRO
// 示例: "C:\\Users\\a915329096\\AppData\\Roaming\\mycard\\apps\\ygopro"
// 不带任何reference,如果同盘符已有库,安装到那个库里,否则在那个盘符建个库。
let library: string | undefined;
if (process.platform == 'win32') {
let volume = legacy_ygopro_path.split(':')[0].toUpperCase();
for (let _library of this.settingsService.getLibraries()) {
if (_library.path.split(':')[0].toUpperCase() == volume) {
library = _library.path
}
}
try {
let library = path.join(volume + ':', "MyCardLibrary");
await this.createDirectory(library);
this.settingsService.addLibrary(library, true);
} catch (error) {
}
}
if (!library) {
library = this.settingsService.getDefaultLibrary().path;
}
let option = new InstallOption(app, library, false, false);
console.log('migrate ygopro', legacy_ygopro_path, library);
await this.importApp(app, legacy_ygopro_path, option);
localStorage.setItem('migrate_v2_ygopro', "true")
}
} catch (error) {
}
}
......
......@@ -30,7 +30,6 @@ export class LobbyComponent implements OnInit {
async ngOnInit() {
this.apps = await this.appsService.loadApps();
await this.appsService.migrate();
for (let app of this.apps.values()) {
this.appsService.update(app);
}
......@@ -53,6 +52,7 @@ export class LobbyComponent implements OnInit {
params.set('autojoin', this.currentApp.conference + '@conference.mycard.moe');
}
this.candy_url = url;
await this.appsService.migrate();
}
chooseApp(app: App) {
......
......@@ -5,7 +5,7 @@ import {Injectable} from "@angular/core";
import {remote} from "electron";
import * as path from "path";
interface Library {
export interface Library {
"default": boolean,path: string
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment