OSDN Git Service

Remove \'build xxxxxxxx\' string from the version description.
[molby/Molby.git] / update_version.rb
1 #!/usr/bin/ruby
2
3 require 'kconv'
4
5 #  Get the version string
6 #  version = "X.X.X"
7 #  date = "yyyymmdd"
8 version = nil
9 date = nil
10 eval IO.read("Version")
11 ver = version
12 t = Time.now
13 year = t.year
14 month = t.month
15 day = t.day
16 d = sprintf("%04d%02d%02d", year, month, day)
17 # exit 0 if date == d
18 File.open("Version", "w") { |fp|
19   fp.print "version = \"#{version}\"\n"
20   fp.print "date = \"#{d}\"\n"
21 }
22 build = "build " + d
23 # verstr = "v#{ver} #{build}"
24 verstr = "v#{ver}"
25 yrange = (year > 2008 ? "2008-#{year}" : "2008")
26
27 def modify_file(name, &block)
28   ary = IO.readlines(name)
29   modified = false
30   ary.each_with_index { |s, i|
31     s = block.call(s)
32     if s
33       ary[i] = s
34       modified = true
35     end
36   }
37   if modified
38     File.rename(name, name + "~")
39     open(name, "wb") { |fp|
40       ary.each { |s| fp.write(s) }
41     }
42   end
43 end
44
45 #  Modify Info.plist
46 nm = "xcode-build/Info.plist"
47 version = false
48 modify_file(nm) { |s|
49   if version
50     version = false
51     "\t<string>#{verstr}</string>\n"
52   else
53     version = (s =~ /\bCFBundleVersion\b/)
54     nil
55   end
56 }
57
58 #  Modify InfoPlist.strings
59 Dir["xcode-build/*.lproj/InfoPlist.strings"].each { |nm|
60   modify_file(nm) { |s|
61     s = s.kconv(Kconv::UTF8, Kconv::UTF16)
62     if s =~ /Copyright/ && s.sub!(/Toshi Nagata, [-0-9]+/, "Toshi Nagata, #{yrange}")
63       s = s.kconv(Kconv::UTF16, Kconv::UTF8)
64     else
65       nil
66     end
67   }
68 }
69
70 #  Modify Molby.iss
71 modify_file("msw-build/molby.iss") { |s|
72   if s =~ /AppVerName/ && s.sub!(/\(.*\)*/, "(#{verstr})")
73     s
74   else
75     nil
76   end
77 }
78
79 #  Modify MyVersion.c
80 modify_file("wxSources/MyVersion.c") { |s|
81   if s =~ /Version/ && s.sub!(/\".*\"/, "\"#{verstr}\"")
82     s
83   else
84     nil
85   end
86 }
87
88 #  Modify doc_source.html
89 modify_file("Documents/src/doc_source.html") { |s|
90   if s =~ /Version/ && s.sub!(/[Vv][-.0-9 A-Za-z_]*/, "Version #{ver}")
91     s
92   else
93     nil
94   end
95 }
96
97 #  Modify README
98 modify_file("README") { |s|
99   if s =~ /        Version/ && s.sub!(/[Vv][-.0-9 A-Za-z_]*/, "Version #{ver}")
100     s
101   else
102     nil
103   end
104 }