Raspberry PI に Redmine インストール(3)

Redmine にテーマの適用をしてみる。

  • テーマの入手 — Redmine用語解説 に紹介されている farend_fancy テーマを適用する。
    日本語環境向けテーマの farend_basic にアイコン表示など変更を行ったテーマ。
    • Download ZIPリンクのURLを確認して wget で Raspberry PI にダウンロード。
      wget -O farend_fancy.zip https://github.com/farend/redmine_theme_farend_fancy/archive/master.zip
    • zipファイルを展開
      unzip farend_fancy.zip
    • Redmine のthemes ディレクトリに移動させる
      sudo mv redmine_theme_farend_fancy-master /usr/share/redmine/public/themes/farend_fancy
    • Redmine にブラウザアクセスして管理者でログイン。
      管理>設定>表示 でテーマを「farend_fancy」に変更して保存すると適用される。
      redmine_theme1.jpg redmine_theme2.jpg
  • redmine_dmsf プラグインを適用…しようとしたら、
    今インストールしている Redmine のバージョン(1.4.4)が低くて対応していなかった。/(^o^)\ナンテコッタイ
    (DMSFプラグインの対応バージョンは Redmine 2.3以降)
  • 仕方がないので、とりあえず別環境で構築したときに見つけた DMSF プラグインの不具合修正についてだけメモ。
    • アップロードしたファイルを複数まとめてzipファイルでダウンロードする機能があるが、
      日本語Windows環境だと中身のファイルが文字化けしてしまう不具合がある。(DMSF ver 1.4.9 時点)
    • これはDMSFプラグインでzipファイル生成時にファイル名をutf-8で扱っているのに対し、
      日本語Windows環境だとファイル名の文字コードを Shift_JIS で扱っているため。
      (なので、ファイルやフォルダに日本語名称を使っていなければ問題はない)
      参考: Windows - 日本語を含むZIPファイルを文字化けせず解凍する方法 - Qiita
    • DSMF プラグインの一部ソースファイルを修正することで改善する。

      app/controllers/dmsf_controller.rb ※変更箇所一部抜粋
  def zip_entries(zip, selected_folders, selected_files)
+   # set encoding by UserAgent  2014/12/17 by windmesser.cc
+   # Windows in Japanese => sjis , else => utf-8
+   encoding = "utf-8"
+   encoding = "sjis" if request.env["HTTP_USER_AGENT"] =~ /Windows/ && request.env["HTTP_ACCEPT_LANGUAGE"] =~ /^ja/
    
    if selected_folders && selected_folders.is_a?(Array)
      selected_folders.each do |selected_folder_id|        
        folder = DmsfFolder.visible.find_by_id selected_folder_id
        if folder
+         # add param encoding  2014/12/17 by windmesser.cc
-          zip.add_folder(folder, (@folder.dmsf_path_str if @folder))
+         zip.add_folder(folder, (@folder.dmsf_path_str if @folder), encoding)
        else
          raise FileNotFound
        end
      end
    end
    if selected_files && selected_files.is_a?(Array)
      selected_files.each do |selected_file_id|        
        file = DmsfFile.visible.find_by_id selected_file_id
        if file && file.last_revision && File.exists?(file.last_revision.disk_file)
+         # add param encoding  2014/12/17 by windmesser.cc
-         zip.add_file(file, (@folder.dmsf_path_str if @folder)) if file
+         zip.add_file(file, (@folder.dmsf_path_str if @folder), encoding) if file
        else
          raise FileNotFound
        end        
      end
    end
    max_files = Setting.plugin_redmine_dmsf['dmsf_max_file_download'].to_i
    if max_files > 0 && zip.files.length > max_files
      raise ZipMaxFilesError, zip.files.length
    end    
    zip
  end

lib/dmsf_zip.rb ※変更箇所一部抜粋

  # This program is distributed in the hope that it will be useful,
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  # GNU General Public License for more details.
  #
  # You should have received a copy of the GNU General Public License
  # along with this program; if not, write to the Free Software
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

  require 'zip'
+ require 'kconv'    # add lib 2014/12/17 by windmesser.cc

  class DmsfZip
  :

+ # set encoding by UserAgent  2014/12/17 by windmesser.cc
+ # add param encoding
- def add_file(file, root_path = nil)
+ def add_file(file, root_path = nil, encoding = "utf8")
    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   
    
+   # add start 2014/12/17 by windmesser.cc
+   if encoding == "sjis"
+   	string_path = string_path.tosjis()
+   end
+   # add end
    
    @zip_file.put_next_entry(string_path)
     File.open(file.last_revision.disk_file, 'rb') do |f|      
      while (buffer = f.read(8192))
        @zip_file.write(buffer)
      end
    end
    @files << file
  end

+ # set encoding by UserAgent  2014/12/17 by windmesser.cc
+ # add param encoding
- def add_folder(folder, root_path = nil)
+ def add_folder(folder, root_path = nil, encoding = "utf8")
    string_path = "#{folder.dmsf_path_str}/"
    string_path = string_path[(root_path.length + 1) .. string_path.length] if root_path    
    
+   # add start 2014/12/17 by windmesser.cc
+   if encoding == "sjis"
+   	string_path = string_path.tosjis()
+   end
+   # add end
    
    @zip_file.put_next_entry(string_path)
    
+   # add param encoding
-   folder.subfolders.visible.each { |subfolder|self.add_folder(subfolder, root_path) }
-   folder.files.visible.each { |file| self.add_file(file, root_path) }
+   folder.subfolders.visible.each { |subfolder| self.add_folder(subfolder, root_path, encoding) }
+   folder.files.visible.each { |file| self.add_file(file, root_path, encoding) }
  end