Universal Data Back-Up - Kain Nobel -  04-16-2009
 
 
Universal Data Back-Up 
Version: 3.0 
 
Introduction 
 
Ever go to open your RPG Maker XP/VX project, just to find *gasp* an Unexpected File Format error!? This system does regular back-ups of all the files in the specified Data folder, and re-writes them to a backup directory. Not only that, but this script is universal meaning it'll, in theory, work in any standard Ruby library just as well as it does with RGSS/RGSS2. 
 
 
Features 
Saves all data in specified data directory. 
Writes all data to specified backup directory. 
Doesn't just read default RM Maker files. 
Writes file as it origionally was, with same data extension. 
 
Script 
 
Code: #===============================================================================  
# ** DataBackUp 
#=============================================================================== 
 
module DataBackUp 
  #----------------------------------------------------------------------------- 
  # * Directory where all origional data to be backed up is. 
  #----------------------------------------------------------------------------- 
  RB_Dir  = "Data" 
  #----------------------------------------------------------------------------- 
  # * Directory where all backup folders/files will be created. 
  #----------------------------------------------------------------------------- 
  WB_Dir  = "Data/Versions" 
  #----------------------------------------------------------------------------- 
  # * Maximum number of backup data directories allowed. 
  #----------------------------------------------------------------------------- 
  Maximum = 1 
  #----------------------------------------------------------------------------- 
  # * Time Format for sub-directories which versioned backups are stored. 
  #----------------------------------------------------------------------------- 
  TimeF   = "%m-%d-%Y @ %I-%M%p" 
  #----------------------------------------------------------------------------- 
  # * DataBackUp.create 
  #----------------------------------------------------------------------------- 
  def self.create 
    self.data_purge 
    self.data_load 
    self.data_save 
  end 
  #----------------------------------------------------------------------------- 
  # * DataBackUp.data_purge 
  #----------------------------------------------------------------------------- 
  def self.data_purge 
    unless FileTest.directory?(WB_Dir) 
      Dir.mkdir(WB_Dir) 
    end 
    dir = Dir.entries(WB_Dir) 
    dir.delete('.') 
    dir.delete('..') 
    return if dir.size < Maximum || Maximum < 1 
    for i in 0...(dir.size - (Maximum - 1)) 
      entries = Dir.entries("#{WB_Dir}/#{dir[i]}") 
      entries.delete('.') 
      entries.delete('..') 
      entries.each {|f| File.delete("#{WB_Dir}/#{dir[i]}/#{f}")} 
      Dir.delete("#{WB_Dir}/#{dir[i]}") 
    end 
  end 
  #----------------------------------------------------------------------------- 
  # * DataBackUp.data_load 
  #----------------------------------------------------------------------------- 
  def self.data_load 
    @data = Hash.new 
    dir   = Dir.new(RB_Dir).entries 
    dir.delete(".") 
    dir.delete("..") 
    dir.each {|f| 
    if FileTest.file?("#{RB_Dir}/#{f}") 
      file = File.open("#{RB_Dir}/#{f}", "rb") 
      @data[f] = Marshal.load(file) 
      file.close 
    end} 
  end 
  #----------------------------------------------------------------------------- 
  # * DataBackUp.data_save 
  #----------------------------------------------------------------------------- 
  def self.data_save 
    if Maximum < 1 
      @data = nil 
      return 
    end 
    time = Time.new 
    dir  = time.strftime("#{WB_Dir}/#{TimeF}") 
    return if FileTest.directory?(dir) 
    Dir.mkdir(dir) 
    @data.each_key {|f| 
    file = File.open("#{dir}/#{f}", "wb") 
    Marshal.dump(@data[f], file) 
    file.close} 
    @data = nil 
  end 
end 
 
DataBackUp.create
  
Instructions 
 
Place anywhere above 'main' 
 
Compatibility 
 
Ruby/RGSS/RGSS2 compatible. 
 
Credits and Thanks 
 
Dargor, this is just a highly revamped/re-written version of his origional script. 
 
Author's Notes 
 
If you used this to help develop your project, please credit me! Also, please PM me @ www.rmxp.org where I'm most active if you encounter any problems. 
 
Terms and Conditions 
 
This is free for everybody to use, please do not redistribute without my permission.
 
 
 
Universal Data Back-Up - MicKo -  04-19-2009
 
 
Okay, I was waiting to see if it worked to say "thanks" and all. 
 
Since it does, thanks, this is really awesome. I hope I won't need this, but I still prefer using it. *moooooore credits*
 
 
 
Universal Data Back-Up - Kain Nobel -  04-19-2009
 
 
Cool, 1 reply means that I shall post another script, thanks ;)
 
 
 
 |