2018-03-24 01:24:28 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2018-03-24 02:24:52 +00:00
|
|
|
"regexp"
|
2018-03-24 01:24:28 +00:00
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
type clientTag struct {
|
|
|
|
AppName string
|
|
|
|
Version string
|
|
|
|
}
|
|
|
|
|
2018-03-24 02:24:52 +00:00
|
|
|
var (
|
|
|
|
rx_bestNumberPart = regexp.MustCompile(`[0-9\.]+`)
|
|
|
|
)
|
|
|
|
|
2018-03-24 01:24:28 +00:00
|
|
|
func parseVersion(ver string) clientTag {
|
2018-03-24 02:16:22 +00:00
|
|
|
// Try our best to turn the supplied text into a structured version
|
2018-03-24 01:24:28 +00:00
|
|
|
ret := clientTag{
|
|
|
|
AppName: APP_NAME,
|
|
|
|
Version: APP_VERSION,
|
|
|
|
}
|
|
|
|
|
2018-03-24 02:16:22 +00:00
|
|
|
// Special case: Some clients use a structured version AppName:Version:Metadata
|
|
|
|
// If we check for that, we can support clients with spaces in the name
|
|
|
|
if cParts := strings.Split(ver, ":"); len(cParts) == 3 {
|
|
|
|
ret.AppName = cParts[0]
|
|
|
|
ret.Version = cParts[1]
|
|
|
|
|
2018-03-24 02:36:41 +00:00
|
|
|
} else if ver == "Atomic - An IRC client for Android https://indrora.github.io/Atomic" {
|
|
|
|
ret.AppName = "Atomic"
|
|
|
|
ret.Version = "2.1" // Abandonware. Last available version
|
|
|
|
|
|
|
|
} else if ver == "Yaaic - Yet Another Android IRC Client - http://www.yaaic.org" {
|
|
|
|
ret.AppName = "Yaaic"
|
|
|
|
ret.Version = "1.1" // Abandonware. Last available version
|
|
|
|
|
2018-03-24 02:16:22 +00:00
|
|
|
} else {
|
|
|
|
|
|
|
|
// Special cases all failed, time for heuristics
|
|
|
|
// Turn colons to spaces; keep the first word, and the the first word containing digits
|
|
|
|
ver = strings.Trim(strings.Replace(ver, ":", " ", -1), " ")
|
2018-03-24 01:24:28 +00:00
|
|
|
|
2018-03-24 02:16:22 +00:00
|
|
|
words := strings.Split(ver, " ")
|
2018-03-24 01:24:28 +00:00
|
|
|
|
2018-03-24 02:16:22 +00:00
|
|
|
for _, word := range words[1:] {
|
|
|
|
if strings.ContainsAny(word, "0123456789") {
|
|
|
|
ret.AppName = words[0]
|
|
|
|
ret.Version = strings.Replace(word, "(", "", -1) // AndroIRC
|
|
|
|
break
|
|
|
|
}
|
2018-03-24 01:24:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-24 02:24:52 +00:00
|
|
|
// We only support digits, periods, and hyphens in the number part
|
|
|
|
// This removes the leading v from mIRC and the trailing deb** from irssi
|
|
|
|
if submatch := rx_bestNumberPart.FindStringSubmatch(ret.Version); len(submatch) == 1 {
|
|
|
|
ret.Version = submatch[0]
|
2018-03-24 01:24:28 +00:00
|
|
|
}
|
|
|
|
|
2018-03-24 02:16:22 +00:00
|
|
|
// Special case: "Relay" means "HoloIRC"
|
|
|
|
if ret.AppName == "Relay" && ret.Version == "1.0" && strings.Contains(ver, "Android") {
|
|
|
|
ret.AppName = "HoloIRC"
|
|
|
|
ret.Version = "4"
|
|
|
|
}
|
|
|
|
|
2018-03-24 01:24:28 +00:00
|
|
|
return ret
|
|
|
|
}
|