Advertisement
Demonicskyers

Auto Font Install

Sep 8th, 2013
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.22 KB | None | 0 0
  1. #==============================================================================
  2. # ** Auto Font Install
  3. #------------------------------------------------------------------------------
  4. # Wachunga
  5. # Version 1.1
  6. # 2006-05-26
  7. #------------------------------------------------------------------------------
  8. =begin
  9.  
  10.   Automatically installs one or more fonts so the player doesn't have to. It
  11.   only does this the first time the game is run and the process is quite
  12.   transparent (notification to the player is optional).
  13.  
  14.   Thanks to MagicMagor for the pointer to one of the Win32 functions.
  15.  
  16.   FEATURES
  17.   - handles installation of fonts so players don't have to
  18.   - supports multiple fonts
  19.   - process is quite transparent
  20.  
  21.   SETUP
  22.   Create a Fonts folder in the game directory and place all fonts to be
  23.   installed within. Then update the Filenames and Names constants below,
  24.   adding an element to both arrays for each font.
  25.  
  26.   This script only installs the fonts on the player's computer. You'll
  27.   still have to refer to them as necessary within the game,
  28.   e.g. by setting a new default as follows (in main):
  29.   Font.default_name = [Fonts::Names[0], 'MS PGothic']
  30.  
  31.   This script uses the SDK, available from:
  32.   http://www.hbgames.org/forums/showthread.php?t=1802
  33.  
  34.   (To remove this dependency, just delete the three SDK-labeled lines,
  35.   including the 'end' at the bottom of the script.)
  36.  
  37.   This script also requires the free FileUtils module by Minero Aoki, which
  38.   is included in the standard Ruby distribution but for some reason not
  39.   available in RMXP. Download and place it in your scripts subdirectory:
  40.   http://s88387243.onlinehome.us/rmxp/auto_font_install/fileutils.rb
  41.  
  42.   Note: if player does not have the rights to install fonts on their machine,
  43.   this probably won't work -- but then they wouldn't be able to do it manually
  44.   either. :)
  45.  
  46. =end
  47.   module Fonts
  48.     # filenames of fonts to be in stalled
  49.     Filenames = ['4MINI.TTF']
  50.    
  51.     # names (not filenames) of fonts to be installed
  52.     Names = ['4Mini']
  53.  
  54.     # whether to notify player (via pop-up message) that fonts were installed
  55.     Notify = true
  56.    
  57.     # location of fonts (relative to game folder)
  58.     Source = 'Fonts/'
  59.    
  60.     # location of fonts after installation
  61.     Dest = ENV['SystemRoot'] + '\Fonts\\'
  62.   end
  63.  
  64.   class Scene_Title
  65.    
  66.     AFR = Win32API.new('gdi32', 'AddFontResource', ['P'], 'L')
  67.     WPS = Win32API.new('kernel32', 'WriteProfileString', ['P'] * 3, 'L')
  68.     SM = Win32API.new('user32', 'SendMessage', ['L'] * 4, 'L')
  69.     WM_FONTCHANGE = 0x001D
  70.     HWND_BROADCAST = 0xffff
  71.  
  72.     alias wachunga_autofontinstall_st_main main
  73.     def main
  74.       success = []
  75.       for i in 0...Fonts::Filenames.size
  76.         f = Fonts::Filenames[i]
  77.         # check if already installed...
  78.         if not FileTest.exists?(Fonts::Dest + f)
  79.           # check to ensure font is in specified location...
  80.           if FileTest.exists?(Fonts::Source + f)
  81.             require Dir.getwd + '/Data/fileutils.rb'
  82.             # copy file to fonts folder
  83.             FileUtils.cp(Fonts::Source + f, Fonts::Dest + f)
  84.             # add font resource
  85.             AFR.call(Fonts::Dest + f)
  86.             # add entry to win.ini/registry
  87.             WPS.call('Fonts', Fonts::Names[i] + ' (TrueType)', f)
  88.             SM.call(HWND_BROADCAST,WM_FONTCHANGE,0,0)
  89.             if FileTest.exists?(Fonts::Dest + f)
  90.               success.push(Fonts::Names[i])
  91.             else
  92.               print "Auto Font Install:\n\nFailed to install " +
  93.                 Fonts::Names[i] + '.'
  94.             end
  95.           else
  96.             print "Auto Font Install:\n\nFont " + f + " not found."
  97.           end
  98.         end
  99.       end
  100.       if success != [] # one or more fonts successfully installed
  101.         if Fonts::Notify
  102.           fonts = ''
  103.           success.each do |f|
  104.             fonts << f << ', '
  105.           end
  106.           print "Auto Font Install:\n\nSucessfully installed " + fonts[0..-3] +
  107.             '.'
  108.         end
  109.         # new fonts aren't recognized in RMXP until the program is
  110.         # restarted, so this is (unfortunately) necessary
  111.         a = Thread.new { system('Game') }
  112.         exit
  113.       end
  114.       wachunga_autofontinstall_st_main
  115.     end
  116.   end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement