Universal Data Back-Up
#1
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.
[Image: Button-BOTB.png]
[Image: Save-Point.gif][Image: Button-You-Tube2.png][Image: Button-Sound-Cloud2.png][Image: Button-Audio-Mack2.png]
[Image: LS-Banner.gif]
NEW ALBUM OUT NOW!

Reply }
#2
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*
Reply }
#3
Cool, 1 reply means that I shall post another script, thanks ;)
[Image: Button-BOTB.png]
[Image: Save-Point.gif][Image: Button-You-Tube2.png][Image: Button-Sound-Cloud2.png][Image: Button-Audio-Mack2.png]
[Image: LS-Banner.gif]
NEW ALBUM OUT NOW!

Reply }


Possibly Related Threads…
Thread Author Replies Views Last Post
   Saving Temporary Actors' Data kyonides 1 4,903 09-07-2018, 06:40 AM
Last Post: kyonides
   LILY'S MEGA DATA! DerVVulfman 1 6,894 08-28-2017, 08:07 PM
Last Post: EricandTheCheat
   DerVVulfman's Game Data Sneak DerVVulfman 1 7,472 04-03-2013, 08:42 PM
Last Post: Taylor
   Universal Message System Cancel Choices Fix DerVVulfman 3 10,205 05-23-2012, 03:46 AM
Last Post: Taylor
   Universal Message System ccoa 15 48,655 10-09-2011, 04:33 AM
Last Post: DerVVulfman
   Card Game Data Structure Trickster 5 11,466 12-09-2009, 06:38 PM
Last Post: Trickster
   Loading Data from File Trickster 0 5,209 03-02-2008, 06:04 AM
Last Post: Trickster
   Easy Battle Back Stretching Trickster 0 4,413 03-01-2008, 05:29 AM
Last Post: Trickster



Users browsing this thread: 1 Guest(s)