Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backup and restore working for Pro5 #1088

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ body .vertical-centered-box .content {
z-index: -1;
}

.pull-animation,
.push-animation,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this an intended duplication?

.push-animation,
.download-animation {
margin-top: 60px;
Expand All @@ -175,13 +177,15 @@ body .vertical-centered-box .content {
z-index: -1;
}

.pull-animation img,
.push-animation img,
.download-animation img {
max-width: 100%;
height: auto;
display: block;
}

.pull-animation i,
.push-animation i,
.download-animation i {
background-repeat: repeat;
Expand All @@ -193,6 +197,7 @@ body .vertical-centered-box .content {
left: 0;
}

.pull-animation i,
.push-animation i,
.download-animation i {
content: "";
Expand All @@ -209,6 +214,11 @@ body .vertical-centered-box .content {
animation: push-animation 10s linear infinite;
}

.pull-animation i {
background-image: url("../img/arrow-left.png");
animation: pull-animation 10s linear infinite;
}

@keyframes download-animation {
from {
background-position: 0 0;
Expand All @@ -227,6 +237,15 @@ body .vertical-centered-box .content {
}
}

@keyframes pull-animation {
from {
background-position: 900px 0;
}
to {
background-position: 0px 0px;
}
}

lesshat-selector {
-lh-property: 0; }
@-webkit-keyframes rotate{ 0% { -webkit-transform: rotate(0deg);} 100% { -webkit-transform: rotate(360deg);}}
Expand Down
128 changes: 128 additions & 0 deletions src/devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,135 @@ function install(steps) {
.catch(() => {}); // errors can be ignored here, since this is exclusively used for killing the promise chain
}

// AW : Return the total partition size of system+user
function getUserSystemFileSize() {
var fileSize = 0;
return new Promise(function(resolve, reject) {
adb
.getState()
.then(stdout => {
var system = "";
var user = "";
if (stdout == "device") {
system = "/userdata/system-data";
user = "/userdata/user-data";
} else {
system = "/data/system-data";
user = "/data/user-data";
}
adb
.getFileSize(user)
.then(stdout => {
utils.log.debug("Returned userdata FileSize is " + stdout + " Ko");
fileSize = stdout;
global.Backup.usersize = fileSize;
adb
.getFileSize(system)
.then(stdout => {
fileSize = fileSize + stdout;
global.Backup.systemsize = stdout;
utils.log.debug(
"Returned systemdata FileSize is " +
global.Backup.systemsize +
" Ko"
);
utils.log.debug(
"Returned Total FileSize is " + fileSize + " Ko"
);
global.Backup.TotalSize = fileSize; //resolve(fileSize)
resolve();
})
.catch(reject); // system file size error
})
.catch(reject); // user filesize error
})
.catch(reject); // adb state error
});
}

// AW : Return the total used space for system+user data on Ubuntu os only
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// AW : Return the total used space for system+user data on Ubuntu os only
// Return the total used space for system+user data on Ubuntu os only

async function getDeviceUsedSpaceForBackup() {
// Error to handle : No such file or directory
// --output=used: No such file or directory
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this?


var res = await adb.shell("df -hBG / --output=used|tail -n1");
var res2 = await adb.shell("df -hBG /userdata --output=used|tail -n1");
res = parseFloat(res);
res2 = parseFloat(res2);
return res + res2;
Comment on lines +412 to +416
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make this one statement

}

// AW : Check if /data/user-data is present and mount it if not.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// AW : Check if /data/user-data is present and mount it if not.
// Check if /data/user-data is present and mount it if not.

function mountPartToBackup(device) {
utils.log.info("mountPartToBackup");
return new Promise(function(resolve, reject) {
var data_partition = "";
switch (device) {
case "turbo":
data_partition = "/dev/block/sda44";
break;
default:
data_partition = "/data";
break;
}
utils.log.info("device partition: " + data_partition);
adb
.shell("ls /data|grep system-data")
.then(stdout => {
utils.log.info("ls ok");
if (stdout) {
resolve();
} else {
utils.log.info("nothing found");
adb
.shell("mount " + data_partition + " /data")
.then(stdout => {
utils.log.info("mounted");
resolve();
})
.catch(reject); // mount
resolve();
}
})
.catch(e => {
adb
.shell("mount " + data_partition + " /data")
.then(stdout => {
utils.log.info("Partition has been mounted");
resolve();
})
.catch(e => {
reject("Unable to mount partition " + data_partition + " " + e);
}); // mount
//reject("Partition not mounted "+e);
}); //ls
Comment on lines +460 to +462
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove dead comments

});
}

// Check if we can restore the backup (checking available size)
function isBackupRestorable(backup) {
return adb
.getTotalSize("/userdata")
.then(tot => {
utils.log.info(
"Backup size:" +
(backup.config.systemsize + backup.config.usersize) +
", device size:" +
tot
);
if (tot > backup.config.systemsize + backup.config.usersize) return true;
else return false;
})
.catch(err => {
return false;
});
}

module.exports = {
isBackupRestorable: isBackupRestorable,
getDeviceUsedSpaceForBackup: getDeviceUsedSpaceForBackup,
getUserSystemFileSize: getUserSystemFileSize,
mountPartToBackup: mountPartToBackup,
waitForDevice: () => {
adb
.waitForDevice()
Expand Down
5 changes: 5 additions & 0 deletions src/html/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@ html
i.is-under
#push-animation(style='display: none').vertical-centered-box.push-animation.is-under
i.is-under
#pull-animation(style='display: none').vertical-centered-box.pull-animation.is-under
i.is-under
// Views
include views/done
include views/user-action
include views/select-os
include views/not-supported
include views/wait-for-device
include views/working
include views/backup-device
include views/restore-device
include views/backup-restore-done
#progress.progress(hidden='hidden')
footer.footer.is-over
.container
Expand Down
20 changes: 20 additions & 0 deletions src/html/scripts/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,21 @@ const setText = (cat, id, text) => {
$("." + cat + "-" + id).text(text);
};

// AW : Added Pull Animation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// AW : Added Pull Animation
// Added Pull Animation

const animations = {
hideAll: () => {
$("#particles-foreground").hide();
$("#particles-background").hide();
$("#push-animation").hide();
$("#pull-animation").hide();
$("#download-animation").hide();
},
particles: () => {
if (!localStorage.getItem("animationsDisabled")) {
$("#particles-foreground").show();
$("#particles-background").show();
$("#push-animation").hide();
$("#pull-animation").hide();
$("#download-animation").hide();
} else {
animations.hideAll();
Expand All @@ -41,6 +44,7 @@ const animations = {
if (!localStorage.getItem("animationsDisabled")) {
$("#download-animation").show();
$("#push-animation").hide();
$("#pull-animation").hide();
$("#particles-foreground").hide();
$("#particles-background").hide();
} else {
Expand All @@ -49,16 +53,29 @@ const animations = {
},
push: () => {
if (!localStorage.getItem("animationsDisabled")) {
$("#pull-animation").hide();
$("#push-animation").show();
$("#download-animation").hide();
$("#particles-foreground").hide();
$("#particles-background").hide();
} else {
animations.hideAll();
}
},
pull: () => {
if (!localStorage.getItem("animationsDisabled")) {
$("#pull-animation").show();
$("#push-animation").hide();
$("#download-animation").hide();
$("#particles-foreground").hide();
$("#particles-background").hide();
} else {
animations.hideAll();
}
}
};

// AW : Added pull animation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// AW : Added pull animation
// Added pull animation

const views = {
hideAll: () => hideAll("views"),
show: (id, animation) => {
Expand Down Expand Up @@ -87,6 +104,9 @@ const views = {
case "push":
animations.push();
break;
case "pull":
animations.pull();
break;
default:
animations.hideAll();
}
Expand Down
41 changes: 41 additions & 0 deletions src/html/views/backup-device.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#views-backup-device.main.container.views(hidden='hidden')
.row
.col-xs-6
img(style='height: 350px; margin: auto; display: block;', src='../screens/Screen6.jpg')
.col-xs-6(style='height: 100%')
h4.user-install-header#device-name(style='font-weight: bold;') Device Backup
- var backupsize = 0;
span#sizeinfo(style='color:blue;') Refreshing ...
br
br
p
| Please give a name to your backup
form.form-horizontal
.form-group
.col-xs-3
label.control-label Name
.col-xs-9
input#text-backname.form-control.space(type="text", value="")
p
|
|
| This operation will take a while ! Are you sure ?
button#btn-modal-select-device.btn.btn-primary(type='button', style='width: 100%; margin-top: 50px;', onclick="ipcRenderer.send('user:backup:start',(global.BackupName));") Yep, let's go !
button#btn-device.btn.btn-default(type='button', style='width: 100%;margin-top: 50px;', onclick="ipcRenderer.send('restart');") Not now
script.
$("#text-backname").one("change", () => {
global.BackupName=document.getElementById("text-backname").value;
});
ipcRenderer.on("user:backup", (event,backupConfig, installConfig) => {
if (backupConfig<1000)
document.getElementById("sizeinfo").innerHTML = "Please be sure to have at least #[b "+backupConfig.toFixed(2)+" Go] free on your hardrive.";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation

else
document.getElementById("sizeinfo").innerHTML = "Please be sure to have at least #[b "+Math.round(backupConfig)+" Go] free on your hardrive.";
footer.underText.set("Choose a backup name");
//$("#sizeinfo").text("Please be sure to have at least #[b "+backupConfig+" Go] free on your hard-drive.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still needed?

var d = new Date();
var dateback = d.getFullYear() +"-"+ (d.getMonth()+1) + "-" + d.getDate() + "_" +d.getHours() + d.getMinutes();
$("#text-backname").attr("value",installConfig.codename+"_"+dateback);
global.BackupName = installConfig.codename+"_"+dateback;
views.show("backup-device");
});
15 changes: 15 additions & 0 deletions src/html/views/backup-restore-done.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#views-backup-restore-done.main.container.views(hidden='hidden')
.row
.col-xs-6
img(style='height: 350px; margin: auto; display: block;', src='../screens/Screen6.jpg')
.col-xs-6
h4(style='font-weight: bold;') Success!
span#task(style='color:blue;') Status

button.btn.btn-info(type='button', style='width: 100%; margin-top: 20px;', onclick="ipcRenderer.send('restart');") Finish
script.
ipcRenderer.on("user:backuprestore:done", (event, task) => {
document.getElementById("task").innerHTML = "Your "+task+" "+global.BackupName+" is finished !";
views.show("backup-restore-done");
$("#progress").width("0%");
});
Loading