设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 2226|回复: 6
打印 上一主题 下一主题

[已经解决] 读取图块数据失败

[复制链接]

Lv1.梦旅人

梦石
0
星屑
50
在线时间
84 小时
注册时间
2014-5-1
帖子
34
跳转到指定楼层
1
发表于 2014-5-30 14:24:53 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
本帖最后由 绅士没有错 于 2014-5-30 14:45 编辑

我欲哭无泪啊,游戏做了好久了,今天开始做游戏的时候电脑卡了一下,等快不卡的时候然后我按了保存项目,
然后重新打开游戏工程就这样了,我也没删什么东西啊。。。点开始游戏说脚本啥的出错{:2_261:}

Lv3.寻梦者 (版主)

…あたしは天使なんかじゃないわ

梦石
0
星屑
2208
在线时间
4033 小时
注册时间
2010-10-4
帖子
10779

开拓者贵宾

2
发表于 2014-5-30 14:35:16 | 只看该作者
无解,你看隔壁也有一个和你一样悲剧的
https://rpg.blue/forum.php?mod=viewthread&tid=366271
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
84 小时
注册时间
2014-5-1
帖子
34
3
 楼主| 发表于 2014-5-30 14:39:47 | 只看该作者
taroxd 发表于 2014-5-30 14:35
无解,你看隔壁也有一个和你一样悲剧的
https://rpg.blue/forum.php?mod=viewthread&tid=366271 ...

啊啊啊悲剧了orz……

点评

如果数据重要记得备份哦...  发表于 2014-5-30 14:40
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
60
在线时间
214 小时
注册时间
2014-1-23
帖子
197
4
发表于 2014-5-30 16:25:46 | 只看该作者
有原稿的话放上来看看还能不能治……
还有骚年啊,2L说的对……切记至少要做一个云端备份……
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
375 小时
注册时间
2013-10-1
帖子
77
5
发表于 2014-5-30 18:38:29 | 只看该作者
又是data损坏。。今天见到俩了。。。= =
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
12555
在线时间
1444 小时
注册时间
2012-7-24
帖子
1302
6
发表于 2014-5-30 18:52:02 | 只看该作者
没办法了,希望楼主不要灰心,重头来过

欢迎大家加我
回复 支持 反对

使用道具 举报

Lv3.寻梦者

唯一的信徒

梦石
0
星屑
1665
在线时间
1357 小时
注册时间
2013-1-29
帖子
1637
7
发表于 2014-5-31 03:18:22 | 只看该作者
本帖最后由 LBQ 于 2014-5-31 03:19 编辑

用git+github定期进行备份吧
当然我也经历过所以写了个脚本:http://urpgs.com/forum.php?mod=viewthread&tid=1824

说白了就是file utils..
RUBY 代码复制
  1. #fileutils.rb   [plain text]
  2. #
  3. # = fileutils.rb
  4. #
  5. # Copyright (c) 2000-2003 Minero Aoki <[email][email protected][/email]>
  6. #
  7. # This program is free software.
  8. # You can distribute/modify this program under the same terms of ruby.
  9. #
  10. # == module FileUtils
  11. #
  12. # Namespace for several file utility methods for copying, moving, removing, etc.
  13. #
  14. # === Module Functions
  15. #
  16. #   cd( dir, options )
  17. #   cd( dir, options ) {|dir| .... }
  18. #   pwd()
  19. #   mkdir( dir, options )
  20. #   mkdir_p( dir, options )
  21. #   rmdir( dir, options )
  22. #   ln( old, new, options )
  23. #   ln( list, destdir, options )
  24. #   ln_s( old, new, options )
  25. #   ln_s( list, destdir, options )
  26. #   ln_sf( src, dest, options )
  27. #   cp( src, dest, options )
  28. #   cp( list, dir, options )
  29. #   cp_r( src, dest, options )
  30. #   cp_r( list, dir, options )
  31. #   mv( src, dest, options )
  32. #   mv( list, dir, options )
  33. #   rm( list, options )
  34. #   rm_r( list, options )
  35. #   rm_rf( list, options )
  36. #   install( src, dest, mode = <src's>, options )
  37. #   chmod( mode, list, options )
  38. #   touch( list, options )
  39. #
  40. # The <tt>options</tt> parameter is a hash of options, taken from the list
  41. # +:force+, +:noop+, +:preserve+, and +:verbose+.  +:noop+ means that no changes
  42. # are made.  The other two are obvious.  Each method documents the options that
  43. # it honours.
  44. #
  45. # All methods that have the concept of a "source" file or directory can take
  46. # either one file or a list of files in that argument.  See the method
  47. # documentation for examples.
  48. #
  49. # There are some `low level' methods, which does not accept any option:
  50. #
  51. #   uptodate?( file, cmp_list )
  52. #   copy_file( srcfilename, destfilename )
  53. #   copy_stream( srcstream, deststream )
  54. #   compare_file( file_a, file_b )
  55. #   compare_stream( stream_a, stream_b )
  56. #
  57. # == module FileUtils::Verbose
  58. #
  59. # This module has all methods of FileUtils module, but it outputs messages
  60. # before acting.  This equates to passing the +:verbose+ flag to methods in
  61. # FileUtils.
  62. #
  63. # == module FileUtils::NoWrite
  64. #
  65. # This module has all methods of FileUtils module, but never changes
  66. # files/directories.  This equates to passing the +:noop+ flag to methods in
  67. # FileUtils.
  68. #
  69.  
  70.  
  71. module FileUtils
  72.  
  73.   # All methods are module_function.
  74.  
  75.   #
  76.   # Options: (none)
  77.   #
  78.   # Returns the name of the current directory.
  79.   #
  80.   def pwd
  81.     Dir.pwd
  82.   end
  83.  
  84.   alias getwd pwd
  85.  
  86.   #
  87.   # Options: noop verbose
  88.   #
  89.   # Changes the current directory to the directory +dir+.
  90.   #
  91.   # If this method is called with block, resumes to the old
  92.   # working directory after the block execution finished.
  93.   #
  94.   #   FileUtils.cd('/', :verbose => true)   # chdir and report it
  95.   #
  96.   def cd( dir, options = {}, &block ) # :yield: dir
  97.     fu_check_options options, :noop, :verbose
  98.     fu_output_message "cd #{dir}" if options[:verbose]
  99.     Dir.chdir(dir, &block) unless options[:noop]
  100.     fu_output_message 'cd -' if options[:verbose] and block
  101.   end
  102.  
  103.   alias chdir cd
  104.  
  105.  
  106.   #
  107.   # Options: (none)
  108.   #
  109.   # Returns true if +newer+ is newer than all +old_list+.
  110.   # Non-existent files are older than any file.
  111.   #
  112.   #   FileUtils.uptodate?('hello.o', %w(hello.c hello.h)) or \
  113.   #       system 'make hello.o'
  114.   #
  115.   def uptodate?( new, old_list, options = nil )
  116.     raise ArgumentError, 'uptodate? does not accept any option' if options
  117.  
  118.     return false unless FileTest.exist?(new)
  119.     new_time = File.mtime(new)
  120.     old_list.each do |old|
  121.       if FileTest.exist?(old)
  122.         return false unless new_time > File.mtime(old)
  123.       end
  124.     end
  125.     true
  126.   end
  127.  
  128.  
  129.   #
  130.   # Options: mode noop verbose
  131.   #
  132.   # Creates one or more directories.
  133.   #
  134.   #   FileUtils.mkdir 'test'
  135.   #   FileUtils.mkdir %w( tmp data )
  136.   #   FileUtils.mkdir 'notexist', :noop => true  # Does not really create.
  137.   #   FileUtils.mkdir 'tmp', :mode => 0700
  138.   #
  139.   def mkdir( list, options = {} )
  140.     fu_check_options options, :mode, :noop, :verbose
  141.     list = fu_list(list)
  142.     fu_output_message "mkdir #{options[:mode] ? ('-m %03o ' % options[:mode]) : ''}#{list.join ' '}" if options[:verbose]
  143.     return if options[:noop]
  144.  
  145.     mode = options[:mode] || (0777 & ~File.umask)
  146.     list.each do |dir|
  147.       Dir.mkdir dir, mode
  148.     end
  149.   end
  150.  
  151.   #
  152.   # Options: mode noop verbose
  153.   #
  154.   # Creates a directory and all its parent directories.
  155.   # For example,
  156.   #
  157.   #   FileUtils.mkdir_p '/usr/local/lib/ruby'
  158.   #
  159.   # causes to make following directories, if it does not exist.
  160.   #     * /usr
  161.   #     * /usr/local
  162.   #     * /usr/local/lib
  163.   #     * /usr/local/lib/ruby
  164.   #
  165.   # You can pass several directories at a time in a list.
  166.   #
  167.   def mkdir_p( list, options = {} )
  168.     fu_check_options options, :mode, :noop, :verbose
  169.     list = fu_list(list)
  170.     fu_output_message "mkdir -p #{options[:mode] ? ('-m %03o ' % options[:mode]) : ''}#{list.join ' '}" if options[:verbose]
  171.     return *list if options[:noop]
  172.  
  173.     mode = options[:mode] || (0777 & ~File.umask)
  174.     list.map {|n| File.expand_path(n) }.each do |dir|
  175.       stack = []
  176.       until FileTest.directory?(dir)
  177.         stack.push dir
  178.         dir = File.dirname(dir)
  179.       end
  180.       stack.reverse_each do |n|
  181.         Dir.mkdir n, mode
  182.       end
  183.     end
  184.  
  185.     return *list
  186.   end
  187.  
  188.   alias mkpath    mkdir_p
  189.   alias makedirs  mkdir_p
  190.  
  191.  
  192.   #
  193.   # Options: noop, verbose
  194.   #
  195.   # Removes one or more directories.
  196.   #
  197.   #   FileUtils.rmdir 'somedir'
  198.   #   FileUtils.rmdir %w(somedir anydir otherdir)
  199.   #   # Does not really remove directory; outputs message.
  200.   #   FileUtils.rmdir 'somedir', :verbose => true, :noop => true
  201.   #
  202.   def rmdir( list, options = {} )
  203.     fu_check_options options, :noop, :verbose
  204.     list = fu_list(list)
  205.     fu_output_message "rmdir #{list.join ' '}" if options[:verbose]
  206.     return if options[:noop]
  207.  
  208.     list.each do |dir|
  209.       Dir.rmdir dir
  210.     end
  211.   end
  212.  
  213.  
  214.   #
  215.   # Options: force noop verbose
  216.   #
  217.   # <b><tt>ln( old, new, options = {} )</tt></b>
  218.   #
  219.   # Creates a hard link +new+ which points to +old+.
  220.   # If +new+ already exists and it is a directory, creates a symbolic link +new/old+.
  221.   # If +new+ already exists and it is not a directory, raises Errno::EEXIST.
  222.   # But if :force option is set, overwrite +new+.
  223.   #
  224.   #   FileUtils.ln 'gcc', 'cc', :verbose => true
  225.   #   FileUtils.ln '/usr/bin/emacs21', '/usr/bin/emacs'
  226.   #
  227.   # <b><tt>ln( list, destdir, options = {} )</tt></b>
  228.   #
  229.   # Creates several hard links in a directory, with each one pointing to the
  230.   # item in +list+.  If +destdir+ is not a directory, raises Errno::ENOTDIR.
  231.   #
  232.   #   include FileUtils
  233.   #   cd '/bin'
  234.   #   ln %w(cp mv mkdir), '/usr/bin'   # Now /usr/bin/cp and /bin/cp are linked.
  235.   #
  236.   def ln( src, dest, options = {} )
  237.     fu_check_options options, :force, :noop, :verbose
  238.     fu_output_message "ln#{options[:force] ? ' -f' : ''} #{[src,dest].flatten.join ' '}" if options[:verbose]
  239.     return if options[:noop]
  240.  
  241.     fu_each_src_dest(src, dest) do |s,d|
  242.       remove_file d, true if options[:force]
  243.       File.link s, d
  244.     end
  245.   end
  246.  
  247.   alias link ln
  248.  
  249.   #
  250.   # Options: force noop verbose
  251.   #
  252.   # <b><tt>ln_s( old, new, options = {} )</tt></b>
  253.   #
  254.   # Creates a symbolic link +new+ which points to +old+.  If +new+ already
  255.   # exists and it is a directory, creates a symbolic link +new/old+.  If +new+
  256.   # already exists and it is not a directory, raises Errno::EEXIST.  But if
  257.   # :force option is set, overwrite +new+.
  258.   #
  259.   #   FileUtils.ln_s '/usr/bin/ruby', '/usr/local/bin/ruby'
  260.   #   FileUtils.ln_s 'verylongsourcefilename.c', 'c', :force => true
  261.   #
  262.   # <b><tt>ln_s( list, destdir, options = {} )</tt></b>
  263.   #
  264.   # Creates several symbolic links in a directory, with each one pointing to the
  265.   # item in +list+.  If +destdir+ is not a directory, raises Errno::ENOTDIR.
  266.   #
  267.   # If +destdir+ is not a directory, raises Errno::ENOTDIR.
  268.   #
  269.   #   FileUtils.ln_s Dir.glob('bin/*.rb'), '/home/aamine/bin'
  270.   #
  271.   def ln_s( src, dest, options = {} )
  272.     fu_check_options options, :force, :noop, :verbose
  273.     fu_output_message "ln -s#{options[:force] ? 'f' : ''} #{[src,dest].flatten.join ' '}" if options[:verbose]
  274.     return if options[:noop]
  275.  
  276.     fu_each_src_dest(src, dest) do |s,d|
  277.       remove_file d, true if options[:force]
  278.       File.symlink s, d
  279.     end
  280.   end
  281.  
  282.   alias symlink ln_s
  283.  
  284.   #
  285.   # Options: noop verbose
  286.   #
  287.   # Same as
  288.   #   #ln_s(src, dest, :force)
  289.   #
  290.   def ln_sf( src, dest, options = {} )
  291.     fu_check_options options, :noop, :verbose
  292.     options = options.dup
  293.     options[:force] = true
  294.     ln_s src, dest, options
  295.   end
  296.  
  297.  
  298.   #
  299.   # Options: preserve noop verbose
  300.   #
  301.   # Copies a file +src+ to +dest+. If +dest+ is a directory, copies
  302.   # +src+ to +dest/src+.
  303.   #
  304.   # If +src+ is a list of files, then +dest+ must be a directory.
  305.   #
  306.   #   FileUtils.cp 'eval.c', 'eval.c.org'
  307.   #   FileUtils.cp %w(cgi.rb complex.rb date.rb), '/usr/lib/ruby/1.6'
  308.   #   FileUtils.cp %w(cgi.rb complex.rb date.rb), '/usr/lib/ruby/1.6', :verbose => true
  309.   #
  310.   def cp( src, dest, options = {} )
  311.     fu_check_options options, :preserve, :noop, :verbose
  312.     fu_output_message "cp#{options[:preserve] ? ' -p' : ''} #{[src,dest].flatten.join ' '}" if options[:verbose]
  313.     return if options[:noop]
  314.  
  315.     fu_each_src_dest(src, dest) do |s,d|
  316.       fu_preserve_attr(options[:preserve], s, d) {
  317.           copy_file s, d
  318.       }
  319.     end
  320.   end
  321.  
  322.   alias copy cp
  323.  
  324.   #
  325.   # Options: preserve noop verbose
  326.   #
  327.   # Copies +src+ to +dest+. If +src+ is a directory, this method copies
  328.   # all its contents recursively. If +dest+ is a directory, copies
  329.   # +src+ to +dest/src+.
  330.   #
  331.   # +src+ can be a list of files.
  332.   #
  333.   #   # Installing ruby library "mylib" under the site_ruby
  334.   #   FileUtils.rm_r site_ruby + '/mylib', :force
  335.   #   FileUtils.cp_r 'lib/', site_ruby + '/mylib'
  336.   #
  337.   #   # Examples of copying several files to target directory.
  338.   #   FileUtils.cp_r %w(mail.rb field.rb debug/), site_ruby + '/tmail'
  339.   #   FileUtils.cp_r Dir.glob('*.rb'), '/home/aamine/lib/ruby', :noop, :verbose
  340.   #
  341.   def cp_r( src, dest, options = {} )
  342.     fu_check_options options, :preserve, :noop, :verbose
  343.     fu_output_message "cp -r#{options[:preserve] ? 'p' : ''} #{[src,dest].flatten.join ' '}" if options[:verbose]
  344.     return if options[:noop]
  345.  
  346.     fu_each_src_dest(src, dest) do |s,d|
  347.       if FileTest.directory?(s)
  348.         fu_copy_dir s, d, '.', options[:preserve]
  349.       else
  350.         fu_p_copy s, d, options[:preserve]
  351.       end
  352.     end
  353.   end
  354.  
  355.   def fu_copy_dir( src, dest, rel, preserve ) #:nodoc:
  356.     fu_preserve_attr(preserve, "#{src}/#{rel}", "#{dest}/#{rel}") {|s,d|
  357.         dir = File.expand_path(d)   # to remove '/./'
  358.         Dir.mkdir dir unless FileTest.directory? dir
  359.     }
  360.     Dir.entries("#{src}/#{rel}").each do |fname|
  361.       if FileTest.directory? File.join(src,rel,fname)
  362.         next if /\A\.\.?\z/ === fname
  363.         fu_copy_dir src, dest, "#{rel}/#{fname}", preserve
  364.       else
  365.         fu_p_copy File.join(src,rel,fname), File.join(dest,rel,fname), preserve
  366.       end
  367.     end
  368.   end
  369.   private :fu_copy_dir
  370.  
  371.   def fu_p_copy( src, dest, really ) #:nodoc:
  372.     fu_preserve_attr(really, src, dest) {
  373.         copy_file src, dest
  374.     }
  375.   end
  376.   private :fu_p_copy
  377.  
  378.   def fu_preserve_attr( really, src, dest ) #:nodoc:
  379.     unless really
  380.       yield src, dest
  381.       return
  382.     end
  383.  
  384.     st = File.stat(src)
  385.     yield src, dest
  386.     File.utime st.atime, st.mtime, dest
  387.     begin
  388.       File.chown st.uid, st.gid, dest
  389.     rescue Errno::EPERM
  390.       File.chmod st.mode & 01777, dest   # clear setuid/setgid
  391.     else
  392.       File.chmod st.mode, dest
  393.     end
  394.   end
  395.   private :fu_preserve_attr
  396.  
  397.   #
  398.   # Copies file +src+ to +dest+.
  399.   # Both of +src+ and +dest+ must be a filename.
  400.   #
  401.   def copy_file( src, dest )
  402.     File.open(src,  'rb') {|r|
  403.     File.open(dest, "w"){}
  404.     File.open(dest, 'w+') {|w|
  405.         copy_stream r, w
  406.     } }
  407.   end
  408.  
  409.   #
  410.   # Copies stream +src+ to +dest+.
  411.   # Both of +src+ and +dest+ must be a IO.
  412.   #
  413.   def copy_stream( src, dest )
  414.     bsize = fu_stream_blksize(src, dest)
  415.     begin
  416.       while true
  417.         dest.syswrite src.sysread(bsize)
  418.       end
  419.     rescue EOFError
  420.     end
  421.   end
  422.  
  423.   #
  424.   # Options: noop verbose
  425.   #
  426.   # Moves file(s) +src+ to +dest+.  If +file+ and +dest+ exist on the different
  427.   # disk partition, the file is copied instead.
  428.   #
  429.   #   FileUtils.mv 'badname.rb', 'goodname.rb'
  430.   #   FileUtils.mv 'stuff.rb', 'lib/ruby', :force => true
  431.   #
  432.   #   FileUtils.mv %w(junk.txt dust.txt), '/home/aamine/.trash/'
  433.   #   FileUtils.mv Dir.glob('test*.rb'), 'test', :noop, :verbose => true
  434.   #
  435.   def mv( src, dest, options = {} )
  436.     fu_check_options options, :noop, :verbose
  437.     fu_output_message "mv #{[src,dest].flatten.join ' '}" if options[:verbose]
  438.     return if options[:noop]
  439.  
  440.     fu_each_src_dest(src, dest) do |s,d|
  441.       if cannot_overwrite_file? and FileTest.file?(d)
  442.         File.unlink d
  443.       end
  444.  
  445.       begin
  446.         File.rename s, d
  447.       rescue
  448.         if FileTest.symlink?(s)
  449.           File.symlink File.readlink(s), dest
  450.           File.unlink s
  451.         else
  452.           st = File.stat(s)
  453.           copy_file s, d
  454.           File.unlink s
  455.           File.utime st.atime, st.mtime, d
  456.           begin
  457.             File.chown st.uid, st.gid, d
  458.           rescue
  459.             # ignore
  460.           end
  461.         end
  462.       end
  463.     end
  464.   end
  465.  
  466.   alias move mv
  467.  
  468.   def cannot_overwrite_file? #:nodoc:
  469.     /djgpp|cygwin|mswin32/ === RUBY_PLATFORM
  470.   end
  471.   private :cannot_overwrite_file?
  472.  
  473.  
  474.   #
  475.   # Options: force noop verbose
  476.   #
  477.   # Remove file(s) specified in +list+.  This method cannot remove directories.
  478.   # All errors are ignored when the :force option is set.
  479.   #
  480.   #   FileUtils.rm %w( junk.txt dust.txt )
  481.   #   FileUtils.rm Dir.glob('*.so')
  482.   #   FileUtils.rm 'NotExistFile', :force => true   # never raises exception
  483.   #
  484.   def rm( list, options = {} )
  485.     fu_check_options options, :force, :noop, :verbose
  486.     list = fu_list(list)
  487.     fu_output_message "rm#{options[:force] ? ' -f' : ''} #{list.join ' '}" if options[:verbose]
  488.     return if options[:noop]
  489.  
  490.     list.each do |fname|
  491.       remove_file fname, options[:force]
  492.     end
  493.   end
  494.  
  495.   alias remove rm
  496.  
  497.   #
  498.   # Options: noop verbose
  499.   #
  500.   # Same as
  501.   #   #rm(list, :force)
  502.   #
  503.   def rm_f( list, options = {} )
  504.     fu_check_options options, :noop, :verbose
  505.     options = options.dup
  506.     options[:force] = true
  507.     rm list, options
  508.   end
  509.  
  510.   alias safe_unlink rm_f
  511.  
  512.   #
  513.   # Options: force noop verbose
  514.   #
  515.   # remove files +list+[0] +list+[1]... If +list+[n] is a directory,
  516.   # removes its all contents recursively. This method ignores
  517.   # StandardError when :force option is set.
  518.   #
  519.   #   FileUtils.rm_r Dir.glob('/tmp/*')
  520.   #   FileUtils.rm_r '/', :force => true          #  :-)
  521.   #
  522.   def rm_r( list, options = {} )
  523.     fu_check_options options, :force, :noop, :verbose
  524.     list = fu_list(list)
  525.     fu_output_message "rm -r#{options[:force] ? 'f' : ''} #{list.join ' '}" if options[:verbose]
  526.     return if options[:noop]
  527.  
  528.     list.each do |fname|
  529.       begin
  530.         st = File.lstat(fname)
  531.       rescue
  532.         next if options[:force]
  533.         raise
  534.       end
  535.       if    st.symlink?   then remove_file fname, options[:force]
  536.       elsif st.directory? then remove_dir fname, options[:force]
  537.       else                     remove_file fname, options[:force]
  538.       end
  539.     end
  540.   end
  541.  
  542.   #
  543.   # Options: noop verbose
  544.   #
  545.   # Same as
  546.   #   #rm_r(list, :force => true)
  547.   #
  548.   def rm_rf( list, options = {} )
  549.     fu_check_options options, :noop, :verbose
  550.     options = options.dup
  551.     options[:force] = true
  552.     rm_r list, options
  553.   end
  554.  
  555.   alias rmtree rm_rf
  556.  
  557.   def remove_file( fname, force = false ) #:nodoc:
  558.     first_time_p = true
  559.     begin
  560.       File.unlink fname
  561.     rescue Errno::ENOENT
  562.       raise unless force
  563.     rescue
  564.       if first_time_p
  565.         # try once more for Windows
  566.         first_time_p = false
  567.         File.chmod 0777, fname
  568.         retry
  569.       end
  570.       raise
  571.     end
  572.   end
  573.  
  574.   def remove_dir( dir, force = false ) #:nodoc:
  575.     Dir.foreach(dir) do |file|
  576.       next if /\A\.\.?\z/ === file
  577.       path = "#{dir}/#{file}"
  578.       if FileTest.directory? path
  579.         remove_dir path, force
  580.       else
  581.         remove_file path, force
  582.       end
  583.     end
  584.     begin
  585.       Dir.rmdir dir
  586.     rescue Errno::ENOENT
  587.       raise unless force
  588.     end
  589.   end
  590.  
  591.  
  592.   #
  593.   # Returns true if the contents of a file A and a file B are identical.
  594.   #
  595.   #   FileUtils.compare_file('somefile', 'somefile')  #=> true
  596.   #   FileUtils.compare_file('/bin/cp', '/bin/mv')    #=> maybe false
  597.   #
  598.   def compare_file( a, b )
  599.     return false unless File.size(a) == File.size(b)
  600.     File.open(a, 'rb') {|fa|
  601.     File.open(b, 'rb') {|fb|
  602.         return compare_stream(fa, fb)
  603.     } }
  604.   end
  605.  
  606.   alias identical? compare_file
  607.   alias cmp compare_file
  608.  
  609.   #
  610.   # Returns true if the contents of a stream +a+ and +b+ are identical.
  611.   #
  612.   def compare_stream( a, b )
  613.     bsize = fu_stream_blksize(a, b)
  614.     sa = sb = nil
  615.     while sa == sb
  616.       sa = a.read(bsize)
  617.       sb = b.read(bsize)
  618.       unless sa and sb
  619.         if sa.nil? and sb.nil?
  620.           return true
  621.         end
  622.       end
  623.     end
  624.     false
  625.   end
  626.  
  627.  
  628.   #
  629.   # Options: mode noop verbose
  630.   #
  631.   # If +src+ is not same as +dest+, copies it and changes the permission
  632.   # mode to +mode+.  If +dest+ is a directory, destination is +dest+/+src+.
  633.   #
  634.   #   FileUtils.install 'ruby', '/usr/local/bin/ruby', :mode => 0755, :verbose => true
  635.   #   FileUtils.install 'lib.rb', '/usr/local/lib/ruby/site_ruby', :verbose => true
  636.   #
  637.   def install( src, dest, options = {} )
  638.     fu_check_options options, :mode, :preserve, :noop, :verbose
  639.     fu_output_message "install -c#{options[:preserve] && ' -p'}#{options[:mode] ? (' -m 0%o' % options[:mode]) : ''} #{[src,dest].flatten.join ' '}" if options[:verbose]
  640.     return if options[:noop]
  641.  
  642.     fu_each_src_dest(src, dest) do |s,d|
  643.       unless FileTest.exist?(d) and compare_file(s,d)
  644.         fu_preserve_attr(options[:preserve], s, d) {
  645.           remove_file d, true
  646.           copy_file s, d
  647.         }
  648.         File.chmod options[:mode], d if options[:mode]
  649.       end
  650.     end
  651.   end
  652.  
  653.  
  654.   #
  655.   # Options: noop verbose
  656.   #
  657.   # Changes permission bits on the named files (in +list+) to the bit pattern
  658.   # represented by +mode+.
  659.   #
  660.   #   FileUtils.chmod 0755, 'somecommand'
  661.   #   FileUtils.chmod 0644, %w(my.rb your.rb his.rb her.rb)
  662.   #   FileUtils.chmod 0755, '/usr/bin/ruby', :verbose => true
  663.   #
  664.   def chmod( mode, list, options = {} )
  665.     fu_check_options options, :noop, :verbose
  666.     list = fu_list(list)
  667.     fu_output_message sprintf('chmod %o %s', mode, list.join(' ')) if options[:verbose]
  668.     return if options[:noop]
  669.     File.chmod mode, *list
  670.   end
  671.  
  672.  
  673.   #
  674.   # Options: noop verbose
  675.   #
  676.   # Updates modification time (mtime) and access time (atime) of file(s) in
  677.   # +list+.  Files are created if they don't exist.
  678.   #
  679.   #   FileUtils.touch 'timestamp'
  680.   #   FileUtils.touch Dir.glob('*.c');  system 'make'
  681.   #
  682.   def touch( list, options = {} )
  683.     fu_check_options options, :noop, :verbose
  684.     list = fu_list(list)
  685.     fu_output_message "touch #{list.join ' '}" if options[:verbose]
  686.     return if options[:noop]
  687.  
  688.     t = Time.now
  689.     list.each do |fname|
  690.       begin
  691.         File.utime(t, t, fname)
  692.       rescue Errno::ENOENT
  693.         File.open(fname, 'a') {
  694.             ;
  695.         }
  696.       end
  697.     end
  698.   end
  699.  
  700.   private
  701.  
  702.   def fu_check_options( options, *optdecl )
  703.     h = options.dup
  704.     optdecl.each do |name|
  705.       h.delete name
  706.     end
  707.     raise ArgumentError, "no such option: #{h.keys.join(' ')}" unless h.empty?
  708.   end
  709.  
  710.   def fu_list( arg )
  711.     Array === arg ? arg : [arg]
  712.   end
  713.  
  714.   def fu_each_src_dest( src, dest )
  715.     unless Array === src
  716.       yield src, fu_dest_filename(src, dest)
  717.     else
  718.       dir = dest
  719.       # FileTest.directory? dir or raise ArgumentError, "must be dir: #{dir}"
  720.       dir += (dir[-1,1] == '/') ? '' : '/'
  721.       src.each do |fname|
  722.         yield fname, dir + File.basename(fname)
  723.       end
  724.     end
  725.   end
  726.  
  727.   def fu_dest_filename( src, dest )
  728.     if FileTest.directory? dest
  729.       (dest[-1,1] == '/' ? dest : dest + '/') + File.basename(src)
  730.     else
  731.       dest
  732.     end
  733.   end
  734.  
  735.   def fu_stream_blksize( *streams )
  736.     streams.each do |s|
  737.       next unless s.respond_to?(:stat)
  738.       size = s.stat.blksize
  739.       return size unless size.nil? or size.zero?
  740.     end
  741.     1024
  742.   end
  743.  
  744.   @fileutils_output = $stderr
  745.   @fileutils_label  = ''
  746.  
  747.   def fu_output_message( msg )
  748.     @fileutils_output ||= $stderr
  749.     @fileutils_label  ||= ''
  750.     @fileutils_output.puts @fileutils_label + msg
  751.   end
  752.  
  753.   def fu_update_option( args, new )
  754.     if Hash === args.last
  755.       args.last.update new
  756.     else
  757.       args.push new
  758.     end
  759.     args
  760.   end
  761.  
  762.  
  763.   extend self
  764.  
  765.  
  766.   OPT_TABLE = {
  767.     'pwd'          => %w(),
  768.     'cd'           => %w( noop verbose ),
  769.     'chdir'        => %w( noop verbose ),
  770.     'chmod'        => %w( noop verbose ),
  771.     'copy'         => %w( preserve noop verbose ),
  772.     'cp'           => %w( preserve noop verbose ),
  773.     'cp_r'         => %w( preserve noop verbose ),
  774.     'install'      => %w( mode noop verbose ),
  775.     'link'         => %w( force noop verbose ),
  776.     'ln'           => %w( force noop verbose ),
  777.     'ln_s'         => %w( force noop verbose ),
  778.     'ln_sf'        => %w( noop verbose ),
  779.     'makedirs'     => %w( noop verbose ),
  780.     'mkdir'        => %w( mode noop verbose ),
  781.     'mkdir_p'      => %w( mode noop verbose ),
  782.     'mkpath'       => %w( noop verbose ),
  783.     'move'         => %w( noop verbose ),
  784.     'mv'           => %w( noop verbose ),
  785.     'remove'       => %w( force noop verbose ),
  786.     'rm'           => %w( force noop verbose ),
  787.     'rm_f'         => %w( noop verbose ),
  788.     'rm_r'         => %w( force noop verbose ),
  789.     'rm_rf'        => %w( noop verbose ),
  790.     'rmtree'       => %w( noop verbose ),
  791.     'rmdir'        => %w( noop verbose ),
  792.     'safe_unlink'  => %w( noop verbose ),
  793.     'symlink'      => %w( force noop verbose ),
  794.     'touch'        => %w( noop verbose )
  795.   }
  796.  
  797.  
  798.   #
  799.   # This module has all methods of FileUtils module, but it outputs messages
  800.   # before acting.  This equates to passing the +:verbose+ flag to methods in
  801.   # FileUtils.
  802.   #
  803.   module Verbose
  804.  
  805.     include FileUtils
  806.  
  807.     @fileutils_output  = $stderr
  808.     @fileutils_label   = ''
  809.     @fileutils_verbose = true
  810.  
  811.     FileUtils::OPT_TABLE.each do |name, opts|
  812.       next unless opts.include?('verbose')
  813.       module_eval(<<-EOS, __FILE__, __LINE__ + 1)
  814.         def #{name}( *args )
  815.           @fileutils_verbose = true unless defined?(@fileutils_verbose)
  816.           super(*fu_update_option(args, :verbose => @fileutils_verbose))
  817.         end
  818.       EOS
  819.     end
  820.  
  821.     extend self
  822.  
  823.   end
  824.  
  825.  
  826.   #
  827.   # This module has all methods of FileUtils module, but never changes
  828.   # files/directories.  This equates to passing the +:noop+ flag to methods in
  829.   # FileUtils.
  830.   #
  831.   module NoWrite
  832.  
  833.     include FileUtils
  834.  
  835.     @fileutils_output  = $stderr
  836.     @fileutils_label   = ''
  837.     @fileutils_nowrite = true
  838.  
  839.     FileUtils::OPT_TABLE.each do |name, opts|
  840.       next unless opts.include? 'noop'
  841.       module_eval(<<-EOS, __FILE__, __LINE__ + 1)
  842.         def #{name}( *args )
  843.           unless defined?(@fileutils_nowrite)
  844.             @fileutils_nowrite ||= true
  845.           end
  846.           super(*fu_update_option(args, :noop => true))
  847.         end
  848.       EOS
  849.     end
  850.  
  851.     extend self
  852.   
  853.   end
  854.  
  855. end
  856.  
  857.  
  858. # Documentation comments:
  859. #  - Some RDoc markup used here doesn't work (namely, +file1+, +:noop+,
  860. #    +dir/file+).  I consider this a bug and expect that these will be valid in
  861. #    the near future.
  862. FileUtils.mkdir_p "Data_BK"
  863. FileUtils.cp_r(Dir['Data/*'] - Dir['Data/Map*'],'Data_BK')

评分

参与人数 1星屑 +132 收起 理由
taroxd + 132 windows不是人人都玩git的吧……

查看全部评分

『我只是一个正在潜心修炼的渣乐师罢了』
Dear Time\(^o^)/~


假如上面的图片挂了的话麻烦各位去发个帖 @ 一下 orzFly 让他修复 deartime
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-9-25 21:18

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表