Commit a20ada6d authored by wudizhanche1000's avatar wudizhanche1000

自选路径

parent 14eeca64
......@@ -94,8 +94,9 @@
<p i18n>即将开始安装 {{currentApp.name}}</p>
<h4 i18n>安装位置</h4>
<div class="form-group">
<select class="form-control" name="installPath" [(ngModel)]="installOption.installLibrary" title="path">
<select class="form-control" name="installPath" (change)="selectLibrary()" [(ngModel)]="installOption.installLibrary" title="path">
<option *ngFor="let library of libraries" value="{{library}}"> {{library}}</option>
<option *ngFor="let library of availableLibraries" value="create_{{library}}">在 {{library}}\ 盘新建 MyCard 库</option>
</select></div>
<h4 i18n>快捷方式</h4>
<div class="checkbox">
......
......@@ -6,7 +6,9 @@ import {App} from "./app";
import {DownloadService} from "./download.service";
import {clipboard, remote} from "electron";
import * as path from "path";
import * as fs from 'fs';
import {InstallService} from "./install.service";
import mkdirp = require("mkdirp");
declare const Notification: any;
declare const $: any;
......@@ -23,7 +25,7 @@ export class AppDetailComponent implements OnInit {
platform = process.platform;
installOption: InstallOption;
availableLibraries: string[] = [];
references: App[];
referencesInstall: {[id: string]: boolean};
......@@ -32,7 +34,41 @@ export class AppDetailComponent implements OnInit {
private ref: ChangeDetectorRef) {
}
// public File[] listRoots() {
// int ds = listRoots0();
// int n = 0;
// for (int i = 0; i < 26; i++) {
// if (((ds >> i) & 1) != 0) {
// if (!access((char)('A' + i) + ":" + slash))
// ds &= ~(1 << i);
// else
// n++;
// }
// }
// File[] fs = new File[n];
// int j = 0;
// char slash = this.slash;
// for (int i = 0; i < 26; i++) {
// if (((ds >> i) & 1) != 0)
// fs[j++] = new File((char)('A' + i) + ":" + slash);
// }
// return fs;
// }
ngOnInit() {
let volume = 'A';
for (let i = 0; i < 26; i++) {
new Promise((resolve, reject) => {
let currentVolume = String.fromCharCode(volume.charCodeAt(0) + i) + ":";
fs.access(currentVolume, (err) => {
if (!err) {
//判断是否已经存在Library
if (this.libraries.every((library) => !library.startsWith(currentVolume))) {
this.availableLibraries.push(currentVolume);
}
}
})
})
}
}
updateInstallOption(app: App) {
......@@ -92,6 +128,23 @@ export class AppDetailComponent implements OnInit {
}
}
async selectLibrary() {
if (this.installOption.installLibrary.startsWith('create_')) {
let volume = this.installOption.installLibrary.slice(7);
let library = path.join(volume, "MyCardLibrary");
try {
await this.installService.createDirectory(library);
this.installOption.installLibrary = library;
this.settingsService.addLibrary(library, true);
} catch (e) {
this.installOption.installLibrary = this.settingsService.getDefaultLibrary().path;
alert("无法创建指定目录");
}
} else {
this.settingsService.setDefaultLibrary({path: this.installOption.installLibrary, "default": true})
}
}
selectDir() {
let dir = remote.dialog.showOpenDialog({properties: ['openFile', 'openDirectory']});
console.log(dir);
......
......@@ -36,6 +36,28 @@ export class SettingsService {
return this.libraries;
}
addLibrary(libraryPath: string, isDefault: boolean) {
let libraries = this.getLibraries();
if (isDefault) {
libraries.forEach((l) => {
l.default = false;
});
}
libraries.push({"default": isDefault, path: libraryPath});
this.libraries = libraries;
localStorage.setItem(SettingsService.SETTING_LIBRARY, JSON.stringify(libraries));
}
setDefaultLibrary(library: Library) {
let libraries = this.getLibraries();
libraries.forEach((l) => {
l.default = library.path == l.path;
});
this.libraries = libraries;
localStorage.setItem(SettingsService.SETTING_LIBRARY, JSON.stringify(libraries));
}
getDefaultLibrary(): Library {
if (!this.libraries) {
this.getLibraries()
......
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