working on extracting of updates

This commit is contained in:
printempw 2016-11-25 13:13:26 +08:00
parent 9b6c18cd6b
commit 3811f7d704
5 changed files with 66 additions and 17 deletions

1
.gitignore vendored
View File

@ -2,6 +2,7 @@
.sass-cache
vendor/*
storage/textures/*
storage/update_cache/*
node_modules/*
resources/assets/src/bower_components/*
koala-config.json

View File

@ -5,6 +5,7 @@ namespace App\Http\Controllers;
use Arr;
use Log;
use Utils;
use ZipArchive;
use App\Services\Storage;
use Illuminate\Http\Request;
@ -140,7 +141,43 @@ class UpdateController extends Controller
break;
case 'extract':
//
if (!file_exists($tmp_path)) exit('No file available');
$extract_dir = storage_path("update_cache/{$this->latestVersion}");
$zip = new ZipArchive();
$res = $zip->open($tmp_path);
if ($res === true) {
Log::info("[ZipArchive] Extracting file $tmp_path");
try {
$zip->extractTo($extract_dir);
} catch (\Exception $e) {
exit('发生错误:'.$e->getMessage());
}
} else {
exit('更新包解压缩失败。错误代码:'.$res);
}
$zip->close();
if (Storage::copyDir($extract_dir, base_path()) !== true) {
Storage::removeDir(storage_path('update_cache'));
exit('无法覆盖文件。');
} else {
Log::info("[Extracter] Covering files");
Storage::removeDir(storage_path('update_cache'));
Log::info("[Extracter] Cleaning cache");
}
return json('更新完成', 0);
break;
default:

View File

@ -70,7 +70,7 @@ class Storage
$size = 0;
while($filename = @readdir($resource)) {
if ($filename != "." && $filename != "..") {
$path = $dir.$filename;
$path = "$dir/$filename";
if (is_dir($path)) {
// recursion
self::removeDir($path."/");
@ -96,7 +96,7 @@ class Storage
$size = 0;
while($filename = @readdir($resource)) {
if ($filename != "." && $filename != "..") {
$path = $dir.$filename;
$path = "$dir/$filename";
if (is_dir($path)) {
// recursion
$size += self::getDirSize($path);
@ -121,7 +121,7 @@ class Storage
$resource = opendir($dir);
while($filename = readdir($resource)) {
if ($filename != "." && $filename != "..") {
$path = $dir.$filename;
$path = "$dir/$filename";
if (is_dir($path)) {
// recursion
$file_num = self::getFileNum($path, $file_num);

View File

@ -2,7 +2,7 @@
* @Author: printempw
* @Date: 2016-07-22 14:02:44
* @Last Modified by: printempw
* @Last Modified time: 2016-11-25 12:45:28
* @Last Modified time: 2016-11-25 13:10:36
*/
'use strict';
@ -353,17 +353,33 @@ function downloadUpdates() {
var interval_id = window.setInterval(function() {
$('#imported-progress').html(progress);
$('.progress-bar').css('width', progress+'%').attr('aria-valuenow', progress);
if (progress == 100) {
clearInterval(interval_id);
$('#modal-start-download').modal('toggle');
toastr.success('正在解压更新包');
console.log("Start extracting");
$.ajax({
url: './update/download?action=extract',
type: 'POST',
dataType: 'json'
})
.done(function(json) {
console.log("Files covered");
$('#modal-start-download').modal('toggle');
swal({
type: 'success',
html: json.msg
}).then(function() {
window.location = "../";
});
})
.fail(showAjaxError);
swal({
type: 'success',
html: '下载完成!'
}).then(function(new_name) {
//
});
} else {
$.ajax({
url: './update/download?action=get-file-size',
@ -372,9 +388,6 @@ function downloadUpdates() {
.done(function(json) {
progress = (json.size / file_size * 100).toFixed(2);
$('#imported-progress').html(progress);
$('.progress-bar').css('width', progress+'%').attr('aria-valuenow', progress);
console.log("Progress: "+progress);
})
.fail(showAjaxError);

View File

@ -1,2 +0,0 @@
*
!.gitignore