From 9ef3849fe327d189858a15691fb9ad7fba4ad784 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Fri, 9 Jan 2015 15:59:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A6=82=E6=9E=9C=E7=BC=BA=E5=B0=91=E6=9F=90?= =?UTF-8?q?=E4=B8=80=E9=99=84=E4=BB=B6=E3=80=82=E5=9C=A8=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E5=90=8E=E7=9A=84=E6=96=87=E4=BB=B6=E5=A2=9E=E5=8A=A0=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E8=AF=B4=E6=98=8E=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/zipdown_controller.rb | 21 ++++++++++++++------- config/locales/zh.yml | 1 + 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app/controllers/zipdown_controller.rb b/app/controllers/zipdown_controller.rb index 982e43b7b..12637e2fb 100644 --- a/app/controllers/zipdown_controller.rb +++ b/app/controllers/zipdown_controller.rb @@ -75,16 +75,21 @@ class ZipdownController < ApplicationController def zip_homework_by_user(homeattach) homeworks_attach_path = [] + not_exist_file = [] # 需要将所有homework.attachments遍历加入zip # 并且返回zip路径 homeattach.attachments.each do |attach| - homeworks_attach_path << attach.diskfile if File.exist?(attach.diskfile) + if File.exist?(attach.diskfile) + homeworks_attach_path << attach.diskfile + else + not_exist_file << attach.filename + end end - zipping("#{homeattach.user.lastname}#{homeattach.user.firstname}_#{((homeattach.user.user_extensions.nil? || homeattach.user.user_extensions.student_id.nil?) ? "" : homeattach.user.user_extensions.student_id)}_#{Time.now.to_i.to_s}.zip", homeworks_attach_path, OUTPUT_FOLDER, true) + zipping("#{homeattach.user.lastname}#{homeattach.user.firstname}_#{((homeattach.user.user_extensions.nil? || homeattach.user.user_extensions.student_id.nil?) ? "" : homeattach.user.user_extensions.student_id)}_#{Time.now.to_i.to_s}.zip", homeworks_attach_path, OUTPUT_FOLDER, true, not_exist_file) end - def zipping(zip_name_refer, files_paths, output_path, is_attachment=false) + def zipping(zip_name_refer, files_paths, output_path, is_attachment=false, not_exist_file=[]) # 输入待打包的文件列表,已经打包文件定位到ouput_path ic = Iconv.new('GBK//IGNORE', 'UTF-8//IGNORE') input_filename = files_paths @@ -101,9 +106,11 @@ class ZipdownController < ApplicationController zipfile.add(rename_file, filename) end - #zipfile.get_output_stream('ReadMe') do |os| - # os.write 'Homeworks' - #end + unless not_exist_file.empty? + zipfile.get_output_stream('FILE_LOST.txt') do |os| + os.write l(:label_file_lost) + not_exist_file.join(',').to_s + end + end end zipfile_name rescue Errno => e @@ -119,4 +126,4 @@ class ZipdownController < ApplicationController attach = Attachment.find_by_disk_filename(name) attach.filename end -end +end \ No newline at end of file diff --git a/config/locales/zh.yml b/config/locales/zh.yml index 62f0e0bc4..327cceda4 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -2239,4 +2239,5 @@ zh: label_course_prompt: 课程: label_contain_resource: 已包含资源: label_quote_resource_failed: ",此资源引用失败! " + label_file_lost: 以下文件在服务器丢失: