Class: FXMapperSettings
- Inherits:
-
Hash
- Object
- Hash
- FXMapperSettings
- Defined in:
- lib/IFMapper/FXMapperSettings.rb
Overview
This class contains the applicatio and map’s settings
Defined Under Namespace
Classes: UnknownParameter
Constant Summary collapse
- LOCALE_USER_DEFAULT =
0x400
- LOCALE_SLANGUAGE =
0x1001
- FORMAT_MESSAGE_FROM_SYSTEM =
0x00001000
- FORMAT_MESSAGE_ARGUMENT_ARRAY =
0x00002000
- FormatMessage =
Win32API.new("kernel32","FormatMessage","LPLLPLP","L")
- GetLastError =
Win32API.new("kernel32","GetLastError",[],"L")
- GetLocaleInfo =
Win32API.new('Kernel32.dll', 'GetLocaleInfo', %w{l l p i}, 'i')
- LANGUAGES =
{ /English/ => 'en', /Spanish/ => 'es', # todo1 /German/ => 'de', /Italian/ => 'it', /French/ => 'fr', /Japanese/ => 'ja', /Chinese/ => 'ch', /Korean/ => 'ko', /Arabic/ => 'ar', /Hebrew/ => 'he', }
Instance Method Summary collapse
-
#home ⇒ Object
Return the home location.
-
#initialize ⇒ FXMapperSettings
constructor
Restore user preferences.
-
#write ⇒ Object
Write out the preferences to disk.
Constructor Details
#initialize ⇒ FXMapperSettings
Restore user preferences
Result:
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/IFMapper/FXMapperSettings.rb', line 97 def initialize has_yaml = true begin require 'yaml' f = home + '/.ifmapper' self.replace( YAML.load_file(f) ) rescue LoadError has_yaml = false rescue end if RUBY_PLATFORM =~ /mswin/ lcid = LOCALE_USER_DEFAULT lctype = LOCALE_SLANGUAGE slanguage = '\0' * 256 len = 256 ret = GetLocaleInfo.call lcid, lctype, slanguage, len if ret == 0 error_code = GetLastError.call msg = " " * 255 FormatMessage.call( FORMAT_MESSAGE_FROM_SYSTEM + FORMAT_MESSAGE_ARGUMENT_ARRAY, '', error_code, 0, msg, 255, '' ) msg.gsub!(/\000/, '') msg.strip! $stderr.puts msg end language = 'en' LANGUAGES.each { |re, locale| if slanguage =~ re language = locale break end } else locale = ENV['LC_ALL'] || ENV['LC_CTYPE'] || 'en_US' language = locale[0,2] end while ARGV.size > 0 param = ARGV.shift case param when /^-l(anguage)?$/ language = ARGV.shift language = language[0,2].downcase self['Language'] = language when /.*\.(?:map|ifm|gmp|t|t3m|inf|trizbort)$/ self['Map'] = param else $stderr.puts "Unknown parameter '#{param}'." exit(1) end end defaults = { # Language 'Language' => language, # Colors 'BG Color' => 'dark grey', 'Arrow Color' => 'black', 'Box BG Color' => 'white', 'Box Darkness Color' => 'grey', 'Box Border Color' => 'black', 'Box Number Color' => 'grey', # Fonts 'Font Text' => 'Times', 'Font Objects' => 'Times', # Creation options 'Create on Connection' => true, 'Edit on Creation' => false, 'Automatic Connection' => true, # Display options 'Use Room Cursor' => false, 'Paths as Curves' => true, # Location options 'Location Tasks' => true, 'Location Description' => true, 'Location Numbers' => true, # Grid options 'Grid Boxes' => true, 'Grid Straight Connections' => true, 'Grid Diagonal Connections' => false, # Map options 'Map' => nil } self.replace( defaults.merge(self) ) language = self['Language'] begin require "IFMapper/locales/#{language}/Messages.rb" rescue LoadError $stderr.puts "Language '#{language}' was not found. Using English." require "IFMapper/locales/en/Messages.rb" end unless has_yaml $stderr.puts ERR_NO_YAML end end |
Instance Method Details
#home ⇒ Object
Return the home location
Result: home location for user
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/IFMapper/FXMapperSettings.rb', line 31 def home if ENV['HOME'] homedir = File.('~') # Ahh... you have to love windows... elsif ENV['USERPROFILE'] homedir = ENV['USERPROFILE'] elsif ENV['HOMEDRIVE'] and ENV['HOMEPATH'] homedir = ENV['HOMEDRIVE'] + ENV['HOMEPATH'] else homedir = '.' end return homedir end |
#write ⇒ Object
Write out the preferences to disk.
Result: none
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/IFMapper/FXMapperSettings.rb', line 51 def write begin file = home + '/.ifmapper' f = File.open(file, 'w') f.puts YAML.dump(self) f.close rescue => e $stderr.puts "Preferences not saved:" $stderr.puts e end end |