Fixed issue #3089: Show parent SHA1 on cherry picking a merge commit
[TortoiseGit.git] / src / TortoiseProc / VersioncheckParser.cpp
blob1d75ae6f5152c9b615523c2f6ad118d65741fbda
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.
19 #include "stdafx.h"
20 #include "VersioncheckParser.h"
21 #include "UnicodeUtils.h"
22 #include "Git.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();
40 return false;
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;
53 version <<= 16;
54 version += m_version.minor;
55 version <<= 16;
56 version += m_version.micro;
57 version <<= 16;
58 version += m_version.build;
60 if (version == 0)
61 return false;
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;
69 return true;
72 CVersioncheckParser::Version CVersioncheckParser::GetTortoiseGitVersion()
74 return m_version;
77 CString CVersioncheckParser::GetTortoiseGitInfoText()
79 CString infotext;
80 m_versioncheckfile.GetString(L"tortoisegit.infotext", infotext);
81 return infotext;
84 CString CVersioncheckParser::GetTortoiseGitInfoTextURL()
86 CString infotexturl;
87 m_versioncheckfile.GetString(L"tortoisegit.infotexturl", infotexturl);
88 return infotexturl;
91 CString CVersioncheckParser::GetTortoiseGitIssuesURL()
93 CString issueurl;
94 if (m_versioncheckfile.GetString(L"tortoisegit.issuesurl", issueurl))
95 issueurl = L"https://tortoisegit.org/issue/%BUGID%";
96 return issueurl;
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";
105 return changelogurl;
108 CString CVersioncheckParser::GetTortoiseGitBaseURL()
110 CString baseurl;
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);
114 return baseurl;
117 bool CVersioncheckParser::GetTortoiseGitIsHotfix()
119 bool ishotfix = false;
120 m_versioncheckfile.GetBool(L"tortoisegit.hotfix", ishotfix);
121 return ishotfix;
124 static inline CString x86x64()
126 #if WIN64
127 return L"64";
128 #else
129 return L"32";
130 #endif
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());
141 return mainfilename;
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();
156 LANGPACK_VECTOR vec;
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);
162 LanguagePack pack;
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));
175 if (buf[0])
177 pack.m_LangName += L" (";
178 pack.m_LangName += buf;
179 pack.m_LangName += L')';
182 languagePacks->push_back(pack);
184 return 0;
185 }, &vec);
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);
190 return vec;