* fixed Issue 52: Proper Zipped content root

git-svn-id: http://redmine-dmsf.googlecode.com/svn/trunk/redmine_dmsf@144 5e329b0b-a2ee-ea63-e329-299493fc886d
This commit is contained in:
vit.jonas@gmail.com 2011-06-10 08:09:50 +00:00
parent bf55a59c9a
commit eb19bc0de2
2 changed files with 8 additions and 6 deletions

View File

@ -292,13 +292,13 @@ class DmsfController < ApplicationController
if selected_folders && selected_folders.is_a?(Array) if selected_folders && selected_folders.is_a?(Array)
selected_folders.each do |selected_folder_id| selected_folders.each do |selected_folder_id|
check_project(folder = DmsfFolder.find(selected_folder_id)) check_project(folder = DmsfFolder.find(selected_folder_id))
zip.add_folder(folder) unless folder.nil? zip.add_folder(folder, (@folder.dmsf_path_str unless @folder.nil?)) unless folder.nil?
end end
end end
if selected_files && selected_files.is_a?(Array) if selected_files && selected_files.is_a?(Array)
selected_files.each do |selected_file_id| selected_files.each do |selected_file_id|
check_project(file = DmsfFile.find(selected_file_id)) check_project(file = DmsfFile.find(selected_file_id))
zip.add_file(file) unless file.nil? zip.add_file(file, (@folder.dmsf_path_str unless @folder.nil?)) unless file.nil?
end end
end end

View File

@ -40,8 +40,9 @@ class DmsfZip
@zip.close unless @zip.nil? @zip.close unless @zip.nil?
end end
def add_file(file) def add_file(file, root_path = nil)
string_path = file.folder.nil? ? "" : file.folder.dmsf_path_str + "/" string_path = file.folder.nil? ? "" : file.folder.dmsf_path_str + "/"
string_path = string_path[(root_path.length + 1) .. string_path.length] if root_path
string_path += file.name string_path += file.name
#TODO: somewhat ugly conversion problems handling bellow #TODO: somewhat ugly conversion problems handling bellow
begin begin
@ -58,16 +59,17 @@ class DmsfZip
@file_count += 1 @file_count += 1
end end
def add_folder(folder) def add_folder(folder, root_path = nil)
string_path = folder.dmsf_path_str + "/" string_path = folder.dmsf_path_str + "/"
string_path = string_path[(root_path.length + 1) .. string_path.length] if root_path
#TODO: somewhat ugly conversion problems handling bellow #TODO: somewhat ugly conversion problems handling bellow
begin begin
string_path = Iconv.conv(Setting.plugin_redmine_dmsf["dmsf_zip_encoding"], "utf-8", string_path) string_path = Iconv.conv(Setting.plugin_redmine_dmsf["dmsf_zip_encoding"], "utf-8", string_path)
rescue rescue
end end
@zip_file.put_next_entry(string_path) @zip_file.put_next_entry(string_path)
folder.subfolders.each { |subfolder| self.add_folder(subfolder) } folder.subfolders.each { |subfolder| self.add_folder(subfolder, root_path) }
folder.files.each { |file| self.add_file(file) } folder.files.each { |file| self.add_file(file, root_path) }
end end
end end