1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2013-2016 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "VersioncheckParser.h"
21 #include "UnicodeUtils.h"
24 CVersioncheckParser::CVersioncheckParser()
25 : m_versioncheckfile(true)
29 CVersioncheckParser::~CVersioncheckParser()
33 bool CVersioncheckParser::Load(const CString
& filename
, CString
& err
)
35 git_config_add_file_ondisk(m_versioncheckfile
, CUnicodeUtils::GetUTF8(filename
), GIT_CONFIG_LEVEL_GLOBAL
, 0);
37 if (m_versioncheckfile
.GetString(L
"tortoisegit.version", m_version
.version
))
39 err
= L
"Could not parse version check file: " + g_Git
.GetLibGit2LastErr();
43 unsigned __int64 version
= 0;
44 CString vertemp
= m_version
.version
;
45 m_version
.major
= _ttoi(vertemp
);
46 vertemp
= vertemp
.Mid(vertemp
.Find(L
'.') + 1);
47 m_version
.minor
= _ttoi(vertemp
);
48 vertemp
= vertemp
.Mid(vertemp
.Find(L
'.') + 1);
49 m_version
.micro
= _ttoi(vertemp
);
50 vertemp
= vertemp
.Mid(vertemp
.Find(L
'.') + 1);
51 m_version
.build
= _ttoi(vertemp
);
52 version
= m_version
.major
;
54 version
+= m_version
.minor
;
56 version
+= m_version
.micro
;
58 version
+= m_version
.build
;
63 // another versionstring for the filename can be provided
64 // this is needed for preview releases
65 m_versioncheckfile
.GetString(L
"tortoisegit.versionstring", m_version
.version_for_filename
);
66 if (m_version
.version_for_filename
.IsEmpty())
67 m_version
.version_for_filename
= m_version
.version
;
72 CVersioncheckParser::Version
CVersioncheckParser::GetTortoiseGitVersion()
77 CString
CVersioncheckParser::GetTortoiseGitInfoText()
80 m_versioncheckfile
.GetString(L
"tortoisegit.infotext", infotext
);
84 CString
CVersioncheckParser::GetTortoiseGitInfoTextURL()
87 m_versioncheckfile
.GetString(L
"tortoisegit.infotexturl", infotexturl
);
91 CString
CVersioncheckParser::GetTortoiseGitIssuesURL()
94 if (m_versioncheckfile
.GetString(L
"tortoisegit.issuesurl", issueurl
))
95 issueurl
= L
"https://tortoisegit.org/issue/%BUGID%";
99 CString
CVersioncheckParser::GetTortoiseGitChangelogURL()
101 CString changelogurl
;
102 m_versioncheckfile
.GetString(L
"tortoisegit.changelogurl", changelogurl
);
103 if (changelogurl
.IsEmpty())
104 changelogurl
= L
"https://versioncheck.tortoisegit.org/changelog.txt";
108 CString
CVersioncheckParser::GetTortoiseGitBaseURL()
111 m_versioncheckfile
.GetString(L
"tortoisegit.baseurl", baseurl
);
112 if (baseurl
.IsEmpty())
113 baseurl
.Format(L
"http://updater.download.tortoisegit.org/tgit/%s/", (LPCTSTR
)m_version
.version_for_filename
);
117 bool CVersioncheckParser::GetTortoiseGitIsHotfix()
119 bool ishotfix
= false;
120 m_versioncheckfile
.GetBool(L
"tortoisegit.hotfix", ishotfix
);
124 static inline CString
x86x64()
133 CString
CVersioncheckParser::GetTortoiseGitMainfilename()
135 CString mainfilenametemplate
;
136 m_versioncheckfile
.GetString(L
"tortoisegit.mainfilename", mainfilenametemplate
);
137 if (mainfilenametemplate
.IsEmpty())
138 mainfilenametemplate
= L
"TortoiseGit-%1!s!-%2!s!bit.msi";
139 CString mainfilename
;
140 mainfilename
.FormatMessage(mainfilenametemplate
, (LPCTSTR
)m_version
.version_for_filename
, (LPCTSTR
)x86x64());
144 CString
CVersioncheckParser::GetTortoiseGitLanguagepackFilenameTemplate()
146 CString languagepackfilenametemplate
;
147 m_versioncheckfile
.GetString(L
"tortoisegit.languagepackfilename", languagepackfilenametemplate
);
148 if (languagepackfilenametemplate
.IsEmpty())
149 languagepackfilenametemplate
= L
"TortoiseGit-LanguagePack-%1!s!-%2!s!bit-%3!s!.msi";
150 return languagepackfilenametemplate
;
153 CVersioncheckParser::LANGPACK_VECTOR
CVersioncheckParser::GetTortoiseGitLanguagePacks()
155 CString languagepackfilenametemplate
= GetTortoiseGitLanguagepackFilenameTemplate();
157 git_config_get_multivar_foreach(m_versioncheckfile
, "tortoisegit.langs", nullptr, [](const git_config_entry
* configentry
, void* payload
) -> int
159 LANGPACK_VECTOR
* languagePacks
= (LANGPACK_VECTOR
*)payload
;
160 CString langs
= CUnicodeUtils::GetUnicode(configentry
->value
);
164 int nextTokenPos
= langs
.Find(L
";", 5); // be extensible for the future
165 if (nextTokenPos
> 0)
166 langs
= langs
.Left(nextTokenPos
);
167 pack
.m_LangCode
= langs
.Mid(5);
168 pack
.m_PackName
= L
"TortoiseGit Language Pack " + pack
.m_LangCode
;
170 pack
.m_LocaleID
= _tstoi(langs
.Mid(0, 4));
171 TCHAR buf
[MAX_PATH
] = { 0 };
172 GetLocaleInfo(pack
.m_LocaleID
, LOCALE_SNATIVELANGNAME
, buf
, _countof(buf
));
173 pack
.m_LangName
= buf
;
174 GetLocaleInfo(pack
.m_LocaleID
, LOCALE_SNATIVECTRYNAME
, buf
, _countof(buf
));
177 pack
.m_LangName
+= L
" (";
178 pack
.m_LangName
+= buf
;
179 pack
.m_LangName
+= L
')';
182 languagePacks
->push_back(pack
);
187 for (auto& pack
: vec
)
188 pack
.m_filename
.FormatMessage(languagepackfilenametemplate
, (LPCTSTR
)m_version
.version_for_filename
, (LPCTSTR
)x86x64(), (LPCTSTR
)pack
.m_LangCode
, pack
.m_LocaleID
);