Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 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
   DoubleX RMMZ Dynamic Data DoubleX 1 2,893 09-22-2020, 03:10 PM
Last Post: DoubleX
   Saving Temporary Actors' Data kyonides 1 4,286 09-07-2018, 06:40 AM
Last Post: kyonides
   LILY'S MEGA DATA! DerVVulfman 2 6,094 08-29-2017, 03:16 AM
Last Post: DerVVulfman
   DoubleX RMMV Dynamic Data DoubleX 5 8,182 01-29-2016, 01:40 AM
Last Post: DoubleX
   DoubleX RMVXA Dynamic Data DoubleX 2 5,705 11-12-2015, 01:54 AM
Last Post: DoubleX
   DerVVulfman's Game Data Sneak DerVVulfman 2 6,662 04-04-2013, 03:50 AM
Last Post: DerVVulfman
   Universal Message System Cancel Choices Fix DerVVulfman 3 8,997 05-23-2012, 03:46 AM
Last Post: Taylor
   The Self Data Suite! PK8 1 9,845 05-19-2012, 10:11 AM
Last Post: PK8
   Universal Message System ccoa 15 44,644 10-09-2011, 04:33 AM
Last Post: DerVVulfman
   Universal Message System VX ccoa 2 8,961 03-10-2010, 07:01 PM
Last Post: DerVVulfman



Users browsing this thread: