Skip to content

Commit

Permalink
Add confirmation dialog to battle video backup
Browse files Browse the repository at this point in the history
  • Loading branch information
Cu3PO42 committed Aug 7, 2015
1 parent 8e065a6 commit ec1392d
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 17 deletions.
20 changes: 7 additions & 13 deletions app/elements/bv-dumper/bv-dumper.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
</style>
<link rel="import" type="css" href="../../styles/paper-material.css">
<template>
<paper-dialog id="dialog" entry-animation="scale-up-animation" exit-animation="fade-out-animation">
<div>{{dialogMessage}}</div>
<div class="buttons">
<paper-button dialog-confirm>Ok</paper-button>
</div>
</paper-dialog>
<paper-material elevation="1">
<file-input id="input" path="{{path}}" options="[[fileOptions]]"></file-input>
<div class="horizontal">
Expand All @@ -25,24 +31,12 @@
<paper-radio-button name="enemyTeam" disabled="{{not(enemyDumpable)}}">Enemy Team</paper-radio-button>
</paper-radio-group>
<div>
<paper-icon-button icon="icons:backup"></paper-icon-button>
<paper-icon-button icon="icons:backup" on-tap="backup"></paper-icon-button>
<paper-tooltip>Backup Save</paper-tooltip>
</div>
</div>
</paper-material>
<pkm-list id="results" format-string="{{format.format}}" format-header="{{format.header}}" format-name="{{format.name}}" file-name="{{path}}"></pkm-list>
<paper-dialog id="dialogInvalid" entry-animation="scale-up-animation" exit-animation="fade-out-animation">
<div>Sorry, but this is not a valid battle video!</div>
<div class="buttons">
<paper-button dialog-confirm>Ok</paper-button>
</div>
</paper-dialog>
<paper-dialog id="dialogNokey" entry-animation="scale-up-animation" exit-animation="fade-out-animation">
<div>You have to break for this video first!</div>
<div class="buttons">
<paper-button dialog-confirm>Ok</paper-button>
</div>
</paper-dialog>
</template>
<script src="bv-dumper.js"></script>
</dom-module>
34 changes: 32 additions & 2 deletions app/elements/bv-dumper/bv-dumper.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@ var __metadata = (this && this.__metadata) || function (k, v) {
/// <reference path="../../../typings/node/node.d.ts"/>
var IpcClient = require("electron-ipc-tunnel/client");
var fs = require("fs");
var path = require("path-extra");
(function () {
function mkdirOptional(path) {
if (!fs.existsSync(path))
fs.mkdirSync(path);
}
var backupDirectory = path.join(path.homedir(), "Documents", "KeySAVe", "backup");
mkdirOptional(path.join(path.homedir(), "Documents", "KeySAVe"));
mkdirOptional(backupDirectory);
var BvDumper = (function (_super) {
__extends(BvDumper, _super);
function BvDumper() {
Expand All @@ -42,7 +50,8 @@ var fs = require("fs");
});
this.ipcClient.on("dump-bv-nokey", function () {
_this.path = "";
_this.$.dialogNokey.toggle();
_this.dialogMessage = "You have to break for this video first!";
_this.$.dialog.toggle();
});
}
BvDumper.prototype.pathChanged = function (newValue, oldValue) {
Expand All @@ -51,7 +60,8 @@ var fs = require("fs");
fs.stat(newValue, function (err, stats) {
if (err !== null || stats.size !== 28256) {
_this.path = oldValue;
_this.$.dialogInvalid.toggle();
_this.dialogMessage = "Sorry, but this is not a valid battle video!";
_this.$.dialog.toggle();
}
else {
_this.ipcClient.send("dump-bv", _this.path);
Expand All @@ -64,6 +74,22 @@ var fs = require("fs");
BvDumper.prototype.not = function (val) {
return !val;
};
BvDumper.prototype.backup = function () {
var _this = this;
if (this.path)
fs.createReadStream(this.path).pipe(fs.createWriteStream(path.join(backupDirectory, path.basename(this.path))).on("error", function () {
_this.dialogMessage = "Couldn't backup battle video.";
_this.$.dialog.toggle();
}))
.on("error", function () {
_this.dialogMessage = "Couldn't backup battle video.";
_this.$.dialog.toggle();
})
.on("finish", function () {
_this.dialogMessage = "Battle video backupped!";
_this.$.dialog.toggle();
});
};
__decorate([
property({ type: String }),
__metadata('design:type', String)
Expand All @@ -84,6 +110,10 @@ var fs = require("fs");
property({ type: Object }),
__metadata('design:type', Object)
], BvDumper.prototype, "fileOptions");
__decorate([
property({ type: String }),
__metadata('design:type', String)
], BvDumper.prototype, "dialogMessage");
Object.defineProperty(BvDumper.prototype, "pathChanged",
__decorate([
observe("path"),
Expand Down
35 changes: 33 additions & 2 deletions app/elements/bv-dumper/bv-dumper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@
/// <reference path="../../../typings/node/node.d.ts"/>
import IpcClient = require("electron-ipc-tunnel/client");
import fs = require("fs");
import path = require("path-extra");

(() => {
function mkdirOptional(path) {
if (!fs.existsSync(path))
fs.mkdirSync(path);
}

var backupDirectory = path.join(path.homedir(), "Documents", "KeySAVe", "backup");
mkdirOptional(path.join(path.homedir(), "Documents", "KeySAVe"));
mkdirOptional(backupDirectory);

@component("bv-dumper")
class BvDumper extends polymer.Base {
@property({type: String})
Expand All @@ -21,6 +31,9 @@ class BvDumper extends polymer.Base {
@property({type: Object})
fileOptions: GitHubElectron.Dialog.OpenDialogOptions;

@property({type: String})
dialogMessage: string;

ipcClient: IpcClient;
myTeam: any[];
enemyTeam: any[];
Expand All @@ -46,7 +59,8 @@ class BvDumper extends polymer.Base {

this.ipcClient.on("dump-bv-nokey", () => {
this.path = "";
this.$.dialogNokey.toggle();
this.dialogMessage = "You have to break for this video first!";
this.$.dialog.toggle();
});
}

Expand All @@ -56,7 +70,8 @@ class BvDumper extends polymer.Base {
fs.stat(newValue, (err, stats) => {
if (err !== null || stats.size !== 28256) {
this.path = oldValue;
this.$.dialogInvalid.toggle();
this.dialogMessage = "Sorry, but this is not a valid battle video!";
this.$.dialog.toggle();
} else {
this.ipcClient.send("dump-bv", this.path);
}
Expand All @@ -71,6 +86,22 @@ class BvDumper extends polymer.Base {
not(val) {
return !val;
}

backup() {
if (this.path)
fs.createReadStream(this.path).pipe(<NodeJS.WritableStream>fs.createWriteStream(path.join(backupDirectory, path.basename(this.path))).on("error", () => {
this.dialogMessage = "Couldn't backup battle video."
this.$.dialog.toggle();
}))
.on("error", () => {
this.dialogMessage = "Couldn't backup battle video."
this.$.dialog.toggle();
})
.on("finish", () => {
this.dialogMessage = "Battle video backupped!"
this.$.dialog.toggle();
});
}
}
polymer.createElement(BvDumper);
})()

0 comments on commit ec1392d

Please sign in to comment.