-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_version.rb
139 lines (128 loc) · 3.01 KB
/
update_version.rb
1
2
3
4
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/usr/bin/ruby
require 'kconv'
# Get the version string
# version = "X.X.X"
version = nil
date = nil
eval IO.read("Version")
ver = version
t = Time.now
year = t.year
month = t.month
day = t.day
d = sprintf("%04d%02d%02d", year, month, day)
# exit 0 if date == d
#File.open("Version", "w") { |fp|
# fp.print "version = \"#{version}\"\n"
# fp.print "date = \"#{d}\"\n"
#}
build = "build " + d
# verstr = "v#{ver} #{build}"
verstr = "v#{ver}"
yrange = (year > 2008 ? "2008-#{year}" : "2008")
def modify_file(name, &block)
ary = IO.readlines(name) rescue return
modified = false
ary.each_with_index { |s, i|
s1 = block.call(s.dup)
if s1 && s1 != s
ary[i] = s1
modified = true
end
}
if modified
File.rename(name, name + "~")
open(name, "wb") { |fp|
ary.each { |s| fp.write(s) }
}
File.delete(name + "~")
end
end
# Modify Info.plist
nm = "build-xcode/Molby-Info.plist"
version = false
modify_file(nm) { |s|
if s =~ /Copyright/
s.sub(/[-0-9]+ Toshi Nagata/, "#{yrange} Toshi Nagata")
elsif s =~ /Version \d+\.\d+/
"\t<string>Version #{ver}</string>\n"
elsif version
version = false
"\t<string>#{verstr}</string>\n"
else
version = (s =~ /\bCFBundleVersion\b/)
nil
end
}
# Modify_MacLegacy Info.plist
nm = "build-xcode/Molby_MacLegacy-Info.plist"
version = false
modify_file(nm) { |s|
if s =~ /Copyright/
s.sub(/[-0-9]+ Toshi Nagata/, "#{yrange} Toshi Nagata")
elsif s =~ /Version \d+\.\d+/
"\t<string>Version #{ver}</string>\n"
elsif version
version = false
"\t<string>#{verstr}</string>\n"
else
version = (s =~ /\bCFBundleVersion\b/)
nil
end
}
# Modify InfoPlist.strings
Dir["xcode-build/*.lproj/InfoPlist.strings"].each { |nm|
modify_file(nm) { |s|
s = s.kconv(Kconv::UTF8, Kconv::UTF16)
if s =~ /Copyright/ && s.sub!(/Toshi Nagata, [-0-9]+/, "Toshi Nagata, #{yrange}")
s = s.kconv(Kconv::UTF16, Kconv::UTF8)
else
nil
end
}
}
# Modify Molby.iss
modify_file("build-win/molby64.iss") { |s|
if s =~ /AppVerName/ && s.sub!(/\(.*\)*/, "(#{verstr})")
s
else
nil
end
}
modify_file("build-win32/molby32.iss") { |s|
if s =~ /AppVerName/ && s.sub!(/\(.*\)*/, "(#{verstr})")
s
else
nil
end
}
# Modify MyVersion.c
modify_file("wxSources/MyVersion.c") { |s|
if s =~ /Version/ && s.sub!(/\".*\"/, "\"#{verstr}\"")
s
elsif s =~ /Copyright/ && s =~ /Toshi Nagata/ && s.sub!(/\d\d\d\d(-\d\d\d\d)?/, yrange)
s
else
nil
end
}
# Modify doc_source.html
modify_file("Document_Sources/src/doc_source.html") { |s|
if s =~ /Version/ && s =~ /<!-- version -->/ && s.sub!(/[Vv][-.0-9 A-Za-z_]*/, "Version #{ver}")
s
elsif s =~ /<!-- copyright -->/ && s.sub!(/\d\d\d\d(-\d\d\d\d)?/, yrange)
s
else
nil
end
}
# Modify README
modify_file("README") { |s|
if s =~ / Version/ && s.sub!(/[Vv][-.0-9 A-Za-z_]*/, "Version #{ver}")
s
elsif s =~ / Copyright/ && s =~ /Toshi Nagata/ && s.sub!(/\d\d\d\d(-\d\d\d\d)?/, yrange)
s
else
nil
end
}