1
// TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2013-2018 - 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"
23 CVersioncheckParser::CVersioncheckParser()
24 : m_versioncheckfile(true, true)
28 CVersioncheckParser::~CVersioncheckParser()
32 static const wchar_t *escapes
= L
"ntb\"\\";
33 static const wchar_t *escaped
= L
"\n\t\b\"\\";
34 static CString
GetConfigValue(const wchar_t* ptr
)
41 CStrBuf
working(value
, (int)min(wcslen(ptr
), (size_t)UINT16_MAX
));
42 wchar_t* fixed
= working
;
49 else if (*ptr
!= L
'\\')
51 if (!quoted
&& (*ptr
== L
'#' || *ptr
== L
';'))
57 /* backslash, check the next char */
59 const wchar_t* esc
= wcschr(escapes
, *ptr
);
61 *fixed
++ = escaped
[esc
- escapes
];
73 CString
CVersioncheckParser::GetStringValue(const CString
& section
, const CString
& entry
)
75 return GetConfigValue(m_versioncheckfile
.GetValue(section
, entry
));
78 bool CVersioncheckParser::Load(const CString
& filename
, CString
& err
)
80 m_versioncheckfile
.LoadFile(filename
);
82 m_version
.version
= GetStringValue(L
"tortoisegit", L
"version");
83 if (m_version
.version
.IsEmpty())
85 err
= L
"Invalid version check file.";
88 unsigned __int64 version
= 0;
89 CString vertemp
= m_version
.version
;
90 m_version
.major
= _ttoi(vertemp
);
91 vertemp
= vertemp
.Mid(vertemp
.Find(L
'.') + 1);
92 m_version
.minor
= _ttoi(vertemp
);
93 vertemp
= vertemp
.Mid(vertemp
.Find(L
'.') + 1);
94 m_version
.micro
= _ttoi(vertemp
);
95 vertemp
= vertemp
.Mid(vertemp
.Find(L
'.') + 1);
96 m_version
.build
= _ttoi(vertemp
);
97 version
= m_version
.major
;
99 version
+= m_version
.minor
;
101 version
+= m_version
.micro
;
103 version
+= m_version
.build
;
107 err
= L
"Invalid version check file.";
111 // another versionstring for the filename can be provided
112 // this is needed for preview releases
113 m_version
.version_for_filename
= GetStringValue(L
"tortoisegit", L
"versionstring");
114 if (m_version
.version_for_filename
.IsEmpty())
115 m_version
.version_for_filename
= m_version
.version
;
120 CVersioncheckParser::Version
CVersioncheckParser::GetTortoiseGitVersion()
125 CString
CVersioncheckParser::GetTortoiseGitInfoText()
127 return GetStringValue(L
"tortoisegit", L
"infotext");;
130 CString
CVersioncheckParser::GetTortoiseGitInfoTextURL()
132 return GetStringValue(L
"tortoisegit", L
"infotexturl");;
135 CString
CVersioncheckParser::GetTortoiseGitIssuesURL()
137 CString issueurl
= GetStringValue(L
"tortoisegit", L
"issuesurl");
138 auto section
= m_versioncheckfile
.GetSection(L
"TortoiseGit");
139 if (issueurl
.IsEmpty() && section
&& section
->find(L
"issuesurl") == section
->cend())
140 issueurl
= L
"https://tortoisegit.org/issue/%BUGID%";
144 CString
CVersioncheckParser::GetTortoiseGitChangelogURL()
146 CString changelogurl
= GetStringValue(L
"tortoisegit", L
"changelogurl");
147 if (changelogurl
.IsEmpty())
148 changelogurl
= L
"https://versioncheck.tortoisegit.org/changelog.txt";
152 CString
CVersioncheckParser::GetTortoiseGitBaseURL()
154 CString baseurl
= GetStringValue(L
"tortoisegit", L
"baseurl");
155 if (baseurl
.IsEmpty())
156 baseurl
.Format(L
"http://updater.download.tortoisegit.org/tgit/%s/", (LPCTSTR
)m_version
.version_for_filename
);
160 bool CVersioncheckParser::GetTortoiseGitIsHotfix()
162 return m_versioncheckfile
.GetBoolValue(L
"tortoisegit", L
"hotfix", false);
165 static inline CString
x86x64()
174 CString
CVersioncheckParser::GetTortoiseGitMainfilename()
176 CString mainfilenametemplate
= GetStringValue(L
"tortoisegit", L
"mainfilename");
177 if (mainfilenametemplate
.IsEmpty())
178 mainfilenametemplate
= L
"TortoiseGit-%1!s!-%2!s!bit.msi";
179 CString mainfilename
;
180 mainfilename
.FormatMessage(mainfilenametemplate
, (LPCTSTR
)m_version
.version_for_filename
, (LPCTSTR
)x86x64());
184 CString
CVersioncheckParser::GetTortoiseGitLanguagepackFilenameTemplate()
186 CString languagepackfilenametemplate
= GetStringValue(L
"tortoisegit", L
"languagepackfilename");
187 if (languagepackfilenametemplate
.IsEmpty())
188 languagepackfilenametemplate
= L
"TortoiseGit-LanguagePack-%1!s!-%2!s!bit-%3!s!.msi";
189 return languagepackfilenametemplate
;
192 CVersioncheckParser::LANGPACK_VECTOR
CVersioncheckParser::GetTortoiseGitLanguagePacks()
194 CString languagepackfilenametemplate
= GetTortoiseGitLanguagepackFilenameTemplate();
197 CSimpleIni::TNamesDepend values
;
198 m_versioncheckfile
.GetAllValues(L
"tortoisegit", L
"langs", values
);
199 for (const auto& value
: values
)
201 CString langs
= GetConfigValue(value
.pItem
);
204 int nextTokenPos
= langs
.Find(L
";", 5); // be extensible for the future
205 if (nextTokenPos
> 0)
206 langs
= langs
.Left(nextTokenPos
);
207 pack
.m_LangCode
= langs
.Mid(5);
208 pack
.m_PackName
= L
"TortoiseGit Language Pack " + pack
.m_LangCode
;
210 pack
.m_LocaleID
= _tstoi(langs
.Left(4));
211 TCHAR buf
[MAX_PATH
] = { 0 };
212 GetLocaleInfo(pack
.m_LocaleID
, LOCALE_SNATIVELANGNAME
, buf
, _countof(buf
));
213 pack
.m_LangName
= buf
;
214 GetLocaleInfo(pack
.m_LocaleID
, LOCALE_SNATIVECTRYNAME
, buf
, _countof(buf
));
217 pack
.m_LangName
+= L
" (";
218 pack
.m_LangName
+= buf
;
219 pack
.m_LangName
+= L
')';
222 pack
.m_filename
.FormatMessage(languagepackfilenametemplate
, (LPCTSTR
)m_version
.version_for_filename
, (LPCTSTR
)x86x64(), (LPCTSTR
)pack
.m_LangCode
, pack
.m_LocaleID
);