Class: FixSteamFont

Inherits:
Object
  • Object
show all
Defined in:
lib/fix-steam-font/fix_steam_font.rb

Class Method Summary collapse

Class Method Details

.runObject

Raises:

  • (StandardError)


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/fix-steam-font/fix_steam_font.rb', line 5

def run
  @sections_to_change = [
    #'console_text_error',
    #'console_text',
    'friends_chat_text',
    'friends_chat_text_self',
    'friends_chat_history',
    'friends_chat_event',
    'friends_chat_bright_event',
    'friends_chat_url',
    'friends_chat_name_ingame',
    'friends_chat_self',
    'friends_chat_name',
    'friends_chat_accountid',
    'friends_chat_securitylink'
    ]
  
  # Load configuration.
  @path = SteamPath.new
  
  begin
    @path.load
  rescue Errno::ENOENT => e
    # Config file doesn't exist.
    # Do not implement - user will be prompted for path.
  end
  
  # Prompt user for path to Steam.
  if @path.empty?
    puts "Enter path to Steam:"
    user_path = gets
    
    if user_path.strip.empty?
      puts 'Aborted.'
      exit
    end
    
    @path.save user_path.strip
    raise StandardError, 'Could not write config file.' unless @path.exists?
    
    @path.load
  end
  
  # Load Steam style.
  styles_path = "#{@path}/resource/styles/steam.styles"
  
  raise StandardError, "Could not find steam.styles at:\n#{styles_path}" \
    unless File.exists? styles_path
  
  styles = File.open(styles_path).read
  
  new_styles = ''
  processing_section = false
  
  styles.each_line do |line|
    processing_section = line.strip if @sections_to_change.include? line.strip
    processing_section = false if line.strip == '}'
    
    # Only change font-size inside of the target sections.
    unless processing_section and line.include?('font-size')
      new_styles << line
      next
    end
  
    # The console_text sections behave a little differently.
    # If the first font-size line is changed, Steam regenerates the file.
    # It is the font-size line with [$OSX] that should be changed.
    if processing_section.include? 'console_text'
  
      if line.include? 'OSX]'
        # The spaces before \t are required or Steam will replace
        # the .styles file with the default.
        new_styles << "      \tfont-size=14 [$OSX]\n"
      else
        new_styles << line
      end
  
      next
    end
  
    # Handle all other font-size changes.
    new_styles << "\t\tfont-size=14\n"
  end
  
  # Save the changes.
  File.open(styles_path, 'w') do |file|
    new_styles.each_line {|line| file << line}
  end
  
  puts 'Done.'
end