#============================================================================== # ■ Project.back_up #------------------------------------------------------------------------------ # 製作:春日屋/春日 # URL :http://if.usj.to/hosizora/kasugaya/ # Ver :1.01 # 更新:2007/07/06 # #  プロジェクトファイルを指定したフォルダにバックアップします。 # 以下の設定項目を設定してください。 # # ※当スクリプトの使用は自己責任で。 #============================================================================== class Project #-------------------------------------------------------------------------- # ● バックアップ実行 #-------------------------------------------------------------------------- def Project.back_up # ☆仕様 -------------------------------------------------------- # プロジェクトフォルダ内に"拡張子を持たないファイル"または # "拡張子のついたフォルダ"が存在する場合エラーが発生します。 # 注意してください。 # ☆設定項目 ---------------------------------------------------- # バックアップ先のフォルダを絶対パスで指定します。 # 例)@path = "E:/RPGXP/Project1" @path = "G:/RPGXP/バックアップファイル/Sov project" # このスクリプト起動オプションを設定します。 # 0で常に無効、1で常に有効、 # 2で起動時にAltキーを押しているときだけ有効になります。 @use_this = 2 # 設定項目終わり ------------------------------------------------ @message = "" if @use_this != 0 Input.update if @use_this == 2 && !Input.press?(Input::ALT) return end if @path =~ /[A-Z]:\// prj = Project.new return if !@use_this # ドライブチェック if prj.drive_exist?(@path) folder, file = prj.glob # ディレクトリ作成 for direc in folder prj.make_directory(sprintf("%s/%s", @path, direc)) end # フォルダ内ファイルを順にfileへ for _file in file # すでにファイルが存在するとき # ファイルコピー prj.copy(_file, @path) end @message = "バックアップを完了しました" else @message = @path.split(/[\/\\]/)[0] + "/ドライブに書き込みできません" end else @message = "パスが正しくありません" end print @message end end #-------------------------------------------------------------------------- # ● ドライブの書き込み可能チェック #-------------------------------------------------------------------------- def drive_exist?(path) path = path.split(/[\/\\]/) path[0] << "/" # ドライブが存在しないとき if !FileTest.writable?(path[0]) return false end return true end #-------------------------------------------------------------------------- # ● リスト作成 #-------------------------------------------------------------------------- def glob # ディレクトリ/ファイル分別 def _direc?(list) i = 0 list2 = [] while list[i] if list[i] =~ /\./ # ファイルならばリストから削除 if list[i].split(/[\/\\]/)[-1] != "RGSS102J.dll" list2 << list[i] end list.delete_at(i) redo end i += 1 end return list, list2 end # ここから処理開始 n = 0 folder, file = _direc?(Dir.glob("*")) while folder[n] direc = Dir.glob(folder[n]+"/*") n += 1 folder[n, 0], file[0, 0] = _direc?(direc) end return folder, file end #-------------------------------------------------------------------------- # ● ディレクトリ作成 #-------------------------------------------------------------------------- def make_directory(path) # pathに指定したディレクトリを浅い階層から順に作る path = path.split(/[\/\\]/) buffer = path.shift + "/" # リスト取得 while path.size > 0 Dir.chdir(buffer){ if !Dir.glob("*").include?(path[0]) Dir.mkdir(path[0]) end } buffer << path.shift + "/" end end #-------------------------------------------------------------------------- # ● ファイルコピー #-------------------------------------------------------------------------- def copy(file, path) # 転送先ファイル File.open(path+"/"+file, "wb"){|file2| # 転送元ファイル File.open(file, "rb"){|file1| while data = file1.read(4096) file2.write(data) end } } end end # 実行 if $DEBUG Project.back_up end