SG Automatic Backup

16 de outubro de 2011

SG Automatic Backup é um script feito por Sandgolem que faz backups automáticos do seu projeto no RPG Maker XP. Apesar do fato de que os backups precisam ser confiáveis, o próprio autor adverte para você fazer cópias frequentes e manuais do diretório do seu game, devendo ser as cópias geradas por este script consideradas “quebra galhos” ou pra ter referência sobre as mudanças, etc.

# =begin    <- Erase the # at the start of this line to disable. 
            # You also need to erase the # at the start of the bottom line.
            
#==========================================================================
# ** SG Automatic Backup
#==========================================================================
# sandgolem 
# Version 1
# 26.06.06
#==========================================================================

# DO NOT RELY ON THIS FOR YOUR BACKUPS!
# Make copies of your game directory regularly.

# Thanks MagicMagor for the assistance!

Scene_Title::BackupDirectories = 1

#==========================================================================
#
# To check for updates or find more scripts, visit:
# http://www.gamebaker.com/rmxp/scripts/
#
# To use this script, copy it and insert it in a new section above "Main",
# under the default scripts and the SDK (if using).
#
# SG Settings Control is required and must be above this.
# You must also include the 'fileutils.rb' script:
#       http://www.gamebaker.com/rmxp/scripts/automatic-backup.htm
#
# Have problems? Official topic:
#   http://forums.gamebaker.com/showthread.php?t=10
#
#==========================================================================

begin
  SDK.log('SG Automatic Backup', 'sandgolem', 1, '26.06.06')
  if SDK.state('SG Automatic Backup') != true
    @sg_autobackup_disabled = true
  end
  rescue
end

if !@sg_autobackup_disabled
#--------------------------------------------------------------------------
  
if $sg_disable_scripts
  $sg_disable_scripts += ['Automatic Backup']
end

if $DEBUG

class Scene_Title
  def sg_backup
    if !$sg_backup_shown
      @sg_confirm_window = Window_Command.new(192,['Yes','No'])
      @sg_confirm_window.x = 320
      @sg_confirm_window.y = 190
      @sg_confirm_text = Window_Base.new(128,20,384,174)
      @sg_confirm_text.contents = Bitmap.new(352,142)
      @sg_confirm_text.contents.draw_text(0,0,352,32,'Create backup?',1)
      @sg_confirm_text.contents.draw_text(0,22,352,32,
      'Do NOT rely on these backups.',1)
      @sg_confirm_text.contents.draw_text(0,44,352,32,
      'Copy your game dir regularly.',1)
      @sg_confirm_text.contents.draw_text(0,88,352,32,
      'If you had a RMXP problem, do',1)
      @sg_confirm_text.contents.draw_text(0,110,352,32,
      'not backup until its 100% fixed.',1)
      loop do
        Graphics.update
        Input.update
        sg_backup_update
        if $sg_backup_shown
          break
        end
      end
      @sg_confirm_window.dispose
      @sg_confirm_text.dispose
    end
  end
  
  alias sandgolem_backup_title_continue command_continue
  def command_continue
    sg_backup
    sandgolem_backup_title_continue
  end

  alias sandgolem_backup_title_newgame command_new_game
  def command_new_game
    sg_backup
    sandgolem_backup_title_newgame
  end
  
  def sg_backup_update
    @sg_confirm_window.update
    if Input.trigger?(Input::B)
      $sg_backup_shown = true
    end
    if Input.trigger?(Input::C)
      case @sg_confirm_window.index
      when 0
        sg_create_backup
        $sg_backup_shown = true
      when 1
        $sg_backup_shown = true
      end
    end
  end
  
  def sg_create_backup
    if BackupDirectories > 1
      if FileTest.exist?('backup.sg')
        file = File.open('backup.sg','rb')
        @backup_dir = Marshal.load(file)
        file.close
        if @backup_dir > BackupDirectories
          @backup_dir = 1
        end
      else
        @backup_dir = 1
      end
      backup_dir = 'Backup' + @backup_dir.to_s + '/'
    else
      backup_dir = 'Backup/'
    end
    if !FileTest.directory?(backup_dir)
      FileUtils.mkdir(backup_dir)
    end
    Dir['Data/*.rxdata'].each { |path|
    begin
      @sg_confirm_text.contents.clear
      @sg_confirm_text.contents.draw_text(0,0,352,32,path,1)
      backup = path.clone
      backup.gsub!('Data/',backup_dir)
      FileUtils.cp(path,backup)
    rescue
      p 'Copy of ' + path + ' failed! Please check why before continuing.'
      exit
    end
    Graphics.update }
    if @backup_dir
      @backup_dir += 1
      file = File.open('backup.sg','wb')
      Marshal.dump(@backup_dir,file)
      file.close
    end
  end
end

end

#--------------------------------------------------------------------------
end
# =end


Observação: se você gostou deste post ou ele lhe foi útil de alguma forma, por favor considere apoiar financeiramente a Gaming Room. Fico feliz só de ajudar, mas a contribuição do visitante é muito importante para que este site continua existindo e para que eu possa continuar provendo este tipo de conteúdo e melhorar cada vez mais. Clique aqui e saiba como. Obrigado!

Deixe um comentário

Inscreva-se na nossa newsletter!