OSDN Git Service

Handling of version numbers in update_version.rb was incomplete. Fixed.
[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) rescue return
29   modified = false
30   ary.each_with_index { |s, i|
31     s1 = block.call(s.dup)
32     if s1 && s1 != s
33       ary[i] = s1
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     File.delete(name + "~")
43   end
44 end
45
46 #  Modify Info.plist
47 nm = "xcode-build/Info.plist"
48 version = false
49 modify_file(nm) { |s|
50   if version
51     version = false
52     "\t<string>#{verstr}</string>\n"
53   else
54     version = (s =~ /\bCFBundleVersion\b/)
55     nil
56   end
57 }
58
59 #  Modify InfoPlist.strings
60 Dir["xcode-build/*.lproj/InfoPlist.strings"].each { |nm|
61   modify_file(nm) { |s|
62     s = s.kconv(Kconv::UTF8, Kconv::UTF16)
63     if s =~ /Copyright/ && s.sub!(/Toshi Nagata, [-0-9]+/, "Toshi Nagata, #{yrange}")
64       s = s.kconv(Kconv::UTF16, Kconv::UTF8)
65     else
66       nil
67     end
68   }
69 }
70
71 #  Modify Molby.iss
72 modify_file("msw-build/molby.iss") { |s|
73   if s =~ /AppVerName/ && s.sub!(/\(.*\)*/, "(#{verstr})")
74     s
75   else
76     nil
77   end
78 }
79
80 #  Modify MyVersion.c
81 modify_file("wxSources/MyVersion.c") { |s|
82   if s =~ /Version/ && s.sub!(/\".*\"/, "\"#{verstr}\"")
83     s
84   elsif s =~ /Copyright/ && s =~ /Toshi Nagata/ && s.sub!(/\d\d\d\d(-\d\d\d\d)?/, yrange)
85     s
86   else
87     nil
88   end
89 }
90
91 #  Modify doc_source.html
92 modify_file("Documents/src/doc_source.html") { |s|
93   if s =~ /Version/ && s =~ /<!-- version -->/ && s.sub!(/[Vv][-.0-9 A-Za-z_]*/, "Version #{ver}")
94     s
95   elsif s =~ /<!-- copyright -->/ && s.sub!(/\d\d\d\d(-\d\d\d\d)?/, yrange)
96     s
97   else 
98     nil
99   end
100 }
101
102 #  Modify README
103 modify_file("README") { |s|
104   if s =~ /        Version/ && s.sub!(/[Vv][-.0-9 A-Za-z_]*/, "Version #{ver}")
105     s
106   elsif s =~ /       Copyright/ && s =~ /Toshi Nagata/ && s.sub!(/\d\d\d\d(-\d\d\d\d)?/, yrange)
107     s
108   else
109     nil
110   end
111 }