OSDN Git Service

The (experimental) command line version does not compile; empty MainView_resizeToFit...
[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 yrange = (year > 2008 ? "2008-#{year}" : "2008")
25
26 def modify_file(name, &block)
27   ary = IO.readlines(name)
28   modified = false
29   ary.each_with_index { |s, i|
30     s = block.call(s)
31     if s
32       ary[i] = s
33       modified = true
34     end
35   }
36   if modified
37     File.rename(name, name + "~")
38     open(name, "wb") { |fp|
39       ary.each { |s| fp.write(s) }
40     }
41   end
42 end
43
44 #  Modify Info.plist
45 nm = "xcode-build/Info.plist"
46 version = false
47 modify_file(nm) { |s|
48   if version
49     version = false
50     "\t<string>#{verstr}</string>\n"
51   else
52     version = (s =~ /\bCFBundleVersion\b/)
53     nil
54   end
55 }
56
57 #  Modify InfoPlist.strings
58 Dir["xcode-build/*.lproj/InfoPlist.strings"].each { |nm|
59   modify_file(nm) { |s|
60     s = s.kconv(Kconv::UTF8, Kconv::UTF16)
61     if s =~ /Copyright/ && s.sub!(/Toshi Nagata, [-0-9]+/, "Toshi Nagata, #{yrange}")
62       s = s.kconv(Kconv::UTF16, Kconv::UTF8)
63     else
64       nil
65     end
66   }
67 }
68
69 #  Modify Molby.iss
70 modify_file("msw-build/molby.iss") { |s|
71   if s =~ /AppVerName/ && s.sub!(/\(.*\)*/, "(#{verstr})")
72     s
73   else
74     nil
75   end
76 }
77
78 #  Modify MyVersion.c
79 modify_file("wxSources/MyVersion.c") { |s|
80   if s =~ /Version/ && s.sub!(/\".*\"/, "\"#{verstr}\"")
81     s
82   else
83     nil
84   end
85 }
86
87 #  Modify doc_source.html
88 modify_file("Documents/src/doc_source.html") { |s|
89   if s =~ /Version/ && s.sub!(/[Vv][-.0-9 A-Za-z_]*/, "Version #{ver} #{build}")
90     s
91   else
92     nil
93   end
94 }
95
96 #  Modify README
97 modify_file("README") { |s|
98   if s =~ /        Version/ && s.sub!(/[Vv][-.0-9 A-Za-z_]*/, "Version #{ver} #{build}")
99     s
100   else
101     nil
102   end
103 }