Revert previous commit, was incorrect
[amarok.git] / release_scripts / revert_custom_icons.rb
blobaa911b49bb555942494cf6075ca9e370f0a66535
1  ###########################################################################
2  #   Copyright (C) 2007 by Mark Kretschmann <markey@web.de>                #
3  #                                                                         #
4  #   This program is free software; you can redistribute it and/or modify  #
5  #   it under the terms of the GNU General Public License as published by  #
6  #   the Free Software Foundation; either version 2 of the License, or     #
7  #   (at your option) any later version.                                   #
8  #                                                                         #
9  #   This program is distributed in the hope that it will be useful,       #
10  #   but WITHOUT ANY WARRANTY; without even the implied warranty of        #
11  #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         #
12  #   GNU General Public License for more details.                          #
13  #                                                                         #
14  #   You should have received a copy of the GNU General Public License     #
15  #   along with this program; if not, write to the                         #
16  #   Free Software Foundation, Inc.,                                       #
17  #   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.          #
18  ###########################################################################
19  #
20  #   Small tool for reverting all instances of Amarok::icon("foo") back 
21  #   to the original oxygen icon names.
22  #
23  ###########################################################################
25 require 'strscan'
27 def search_cpp(folder)
28   @cpp_files += Dir["#{folder}/*.cpp"]
29   Dir.foreach(folder) do |x|
30     next if x[0, 1] == "."
31     search_cpp("#{folder}/#{x}") if FileTest.directory?("#{folder}/#{x}")
32   end
33 end
35 def fix_file(path)
36   file = File.new(path, File::RDWR)
37   str = file.read
38   str_output = str.dup
39   scanner = StringScanner.new(str)
40   modified = false
41   loop do
42     scanner.scan(/(.*?)(Amarok::icon\( *?)(".*?")( *?\))/m)
43     break if scanner[3].nil? 
44     modified = true
45     name = scanner[3]
46     whole_match = scanner[2] + scanner[3] + scanner[4]
47     new_name = @name_table[name]
48     new_name = name if new_name == nil
49     str_output.sub!(whole_match, new_name)
50   end
51   if modified
52     file.rewind
53     file.truncate(0)
54     file << str_output
55   end
56 end
58 # Make sure the current working directory is amarok
59 unless Dir::getwd().split( "/" ).last() == "amarok"
60     print "ERROR: This script must be started from the amarok/ folder. Aborting.\n\n"
61     exit(1)
62 end
64 file = File.new("src/iconloader.cpp", File::RDONLY)
65 str = file.read 
66 @name_table = Hash.new
68 str.each_line do |line|
69   if line.include?('iconMap["')
70     reg = /(".*?")(.*)(".*?")/
71     a = reg.match(line)[1]
72     b = reg.match(line)[3]
73     @name_table[a] = b
74   end
75 end
77 @cpp_files = []
78 search_cpp("src")
80 i = 0
81 @cpp_files.each do |x|
82   puts("Processing " + x)
83   puts("#{(100.0 / @cpp_files.length * i).to_i} %")
84   fix_file(x)
85   i = i + 1
86 end
88 puts
89 puts("Done.")