From 445b80fb373f0ca6f5a9a26147f06cda7ba9b3c3 Mon Sep 17 00:00:00 2001 From: Sven Strickroth Date: Sun, 28 Dec 2014 16:13:56 +0100 Subject: [PATCH] Switch to a ini/git config style version check file Signed-off-by: Sven Strickroth --- doc/source/en/TortoiseGit/tgit_app_admins.xml | 27 +-- src/TortoiseProc/CheckForUpdatesDlg.cpp | 275 +++++++++++++------------- src/TortoiseProc/CheckForUpdatesDlg.h | 4 +- 3 files changed, 153 insertions(+), 153 deletions(-) diff --git a/doc/source/en/TortoiseGit/tgit_app_admins.xml b/doc/source/en/TortoiseGit/tgit_app_admins.xml index 8efdfce23..3d13229c2 100644 --- a/doc/source/en/TortoiseGit/tgit_app_admins.xml +++ b/doc/source/en/TortoiseGit/tgit_app_admins.xml @@ -95,28 +95,29 @@ The check for the digital signature of the version.txt file is omitted if the location is overridden in registry. That text file must have the following format: -X.X.X.X -A new version of TortoiseGit is available for you to download! -http://192.168.2.1/downloads/TortoiseGit/info.htm -http://192.168.2.1/downloads/TortoiseGit/TortoiseGit-1.4.1.6000-changelog.txt -http://192.168.2.1/downloads/TortoiseGit/ -1029;cs -1031;de +[TortoiseGit] +version=X.X.X.X +infotext=A new version of TortoiseGit is available for you to download! +infotexturl=http://192.168.2.1/downloads/TortoiseGit/info.htm +changelogurl=http://192.168.2.1/downloads/TortoiseGit/TortoiseGit-1.4.1.6000-changelog.txt +baseurl=http://192.168.2.1/downloads/TortoiseGit/ +langs="1029;cs" +langs="1031;de" - The first line in that file is the version string. You must make sure that + The version line in that file is the version string. You must make sure that it matches the exact version string of the TortoiseGit installation package. - The second line is a custom text, shown in the upgrade dialog. You can write + The infotext line is a custom text, shown in the upgrade dialog. You can write there whatever you want (can also be left empty). Just note that the space in the upgrade dialog is limited. Too long messages will get truncated! - The third line is the URL which is opened when + The infotexturl line is the URL which is opened when when the user clicks on the (custom) message label in the upgrade dialog. The URL is opened with the default web browser, so if you specify a web page, that page is opened and shown to the user. - The fourth line contains the URL to the Changelog or release notes which are displayed in the upgrade dialog (if empty it defaults to https://versioncheck.tortoisegit.org/changelog.txt) - The fifth line is used to override the base path to the installation packages (if empty it defaults to http://updater.download.tortoisegit.org/tgit/X.X.X.X/). + The changelogurl line contains the URL to the Changelog or release notes which are displayed in the upgrade dialog (if empty it defaults to https://versioncheck.tortoisegit.org/changelog.txt) + The baseurl line is used to override the base path to the installation packages (if empty it defaults to http://updater.download.tortoisegit.org/tgit/X.X.X.X/). The filenames are generated as follows: TortoiseGit-(version)-(32|64)bit.msi for the main installer and TortoiseGit-LanguagePack-(version)-(32|64)bit-(cs|de|...).msi for the language packs. - Starting from this line, one can advertise language packs (one per line: Four digit country code;ISO Country code). + Using langs lines, one can advertise language packs (Syntax of one line: Four digit country code;ISO Country code). Clicking on Download downloads the selected files as well as their digital signature files (filename.asc) to FOLDERID_Downloads (Vista or later) or diff --git a/src/TortoiseProc/CheckForUpdatesDlg.cpp b/src/TortoiseProc/CheckForUpdatesDlg.cpp index ec16db79d..8de40c291 100644 --- a/src/TortoiseProc/CheckForUpdatesDlg.cpp +++ b/src/TortoiseProc/CheckForUpdatesDlg.cpp @@ -209,6 +209,8 @@ UINT CCheckForUpdatesDlg::CheckThread() if (!official) SetDlgItemText(IDC_SOURCE, _T("Using (unofficial) release channel: ") + sCheckURL); + CString ver; + CAutoConfig versioncheck(true); CString errorText; BOOL ret = m_updateDownloader->DownloadFile(sCheckURL, tempfile, false); if (!ret && official) @@ -230,145 +232,130 @@ UINT CCheckForUpdatesDlg::CheckThread() errorText.LoadString(IDS_OFFLINEMODE); // offline mode enabled else errorText.Format(IDS_CHECKNEWER_NETERROR_FORMAT, ret); + SetDlgItemText(IDC_CHECKRESULT, errorText); + goto finish; } - if (!ret) - { - try - { - CStdioFile file(tempfile, CFile::modeRead | CFile::shareDenyWrite); - CString ver; - unsigned int major,minor,micro,build; - major=minor=micro=build=0; - unsigned __int64 version=0; - - if (file.ReadString(ver)) - { - CString vertemp = ver; - // another versionstring for the filename can be provided after a semicolon - // this is needed for preview releases - int differentFilenamePos = vertemp.Find(_T(";")); - if (differentFilenamePos > 0) - { - vertemp = vertemp.Left(differentFilenamePos); - ver = ver.Mid(differentFilenamePos + 1); - } - major = _ttoi(vertemp); - vertemp = vertemp.Mid(vertemp.Find('.')+1); - minor = _ttoi(vertemp); - vertemp = vertemp.Mid(vertemp.Find('.')+1); - micro = _ttoi(vertemp); - vertemp = vertemp.Mid(vertemp.Find('.')+1); - build = _ttoi(vertemp); - version = major; - version <<= 16; - version += minor; - version <<= 16; - version += micro; - version <<= 16; - version += build; - } + git_config_add_file_ondisk(versioncheck, CUnicodeUtils::GetUTF8(tempfile), GIT_CONFIG_LEVEL_GLOBAL, 0); - { - BOOL bNewer = FALSE; - if (m_bForce) - bNewer = TRUE; - if (major > TGIT_VERMAJOR) - bNewer = TRUE; - else if ((minor > TGIT_VERMINOR)&&(major == TGIT_VERMAJOR)) - bNewer = TRUE; - else if ((micro > TGIT_VERMICRO)&&(minor == TGIT_VERMINOR)&&(major == TGIT_VERMAJOR)) - bNewer = TRUE; - else if ((build > TGIT_VERBUILD)&&(micro == TGIT_VERMICRO)&&(minor == TGIT_VERMINOR)&&(major == TGIT_VERMAJOR)) - bNewer = TRUE; - - if (version != 0) - { - CString version; - version.Format(_T("%u.%u.%u.%u"),major,minor,micro,build); - if (version != ver) - version += _T(" (") + ver + _T(")"); - temp.Format(IDS_CHECKNEWER_CURRENTVERSION, (LPCTSTR)version); - SetDlgItemText(IDC_CURRENTVERSION, temp); - } + unsigned int major, minor, micro, build; + major = minor = micro = build = 0; + unsigned __int64 version = 0; - if (version == 0) - { - temp.LoadString(IDS_CHECKNEWER_NETERROR); - SetDlgItemText(IDC_CHECKRESULT, temp); - } - else if (bNewer) - { - if(file.ReadString(temp) && !temp.IsEmpty()) - { // Read the next line, it could contain a message for the user - CString tempLink; - if(file.ReadString(tempLink) && !tempLink.IsEmpty()) - { // Read another line to find out the download link-URL, if any - m_sUpdateDownloadLink = tempLink; - } - } - else - { - temp.LoadString(IDS_CHECKNEWER_NEWERVERSIONAVAILABLE); - CString tempLink; - file.ReadString(tempLink); - } - SetDlgItemText(IDC_CHECKRESULT, temp); - m_bShowInfo = TRUE; - - FillChangelog(file, official); - FillDownloads(file, ver); - - // Show download controls - RECT rectWindow, rectProgress, rectGroupDownloads, rectOKButton; - GetWindowRect(&rectWindow); - m_progress.GetWindowRect(&rectProgress); - GetDlgItem(IDC_GROUP_DOWNLOADS)->GetWindowRect(&rectGroupDownloads); - GetDlgItem(IDOK)->GetWindowRect(&rectOKButton); - LONG bottomDistance = rectWindow.bottom - rectOKButton.bottom; - OffsetRect(&rectOKButton, 0, (rectGroupDownloads.bottom + (rectGroupDownloads.bottom - rectProgress.bottom)) - rectOKButton.top); - rectWindow.bottom = rectOKButton.bottom + bottomDistance; - MoveWindow(&rectWindow); - ::MapWindowPoints(NULL, GetSafeHwnd(), (LPPOINT)&rectOKButton, 2); - GetDlgItem(IDOK)->MoveWindow(&rectOKButton); - m_ctrlFiles.ShowWindow(SW_SHOW); - GetDlgItem(IDC_GROUP_DOWNLOADS)->ShowWindow(SW_SHOW); - CenterWindow(); - } - else if(m_bShowInfo) - { - temp.LoadString(IDS_CHECKNEWER_YOURUPTODATE); - SetDlgItemText(IDC_CHECKRESULT, temp); - file.ReadString(temp); - file.ReadString(temp); - FillChangelog(file, official); - } - } - } - catch (CException * e) + if (!versioncheck.GetString(_T("tortoisegit.version"), ver)) + { + CString vertemp = ver; + major = _ttoi(vertemp); + vertemp = vertemp.Mid(vertemp.Find('.') + 1); + minor = _ttoi(vertemp); + vertemp = vertemp.Mid(vertemp.Find('.') + 1); + micro = _ttoi(vertemp); + vertemp = vertemp.Mid(vertemp.Find('.') + 1); + build = _ttoi(vertemp); + version = major; + version <<= 16; + version += minor; + version <<= 16; + version += micro; + version <<= 16; + version += build; + + if (version == 0) { - e->Delete(); temp.LoadString(IDS_CHECKNEWER_NETERROR); SetDlgItemText(IDC_CHECKRESULT, temp); + goto finish; } + + // another versionstring for the filename can be provided + // this is needed for preview releases + vertemp.Empty(); + versioncheck.GetString(_T("tortoisegit.versionstring"), vertemp); + if (!vertemp.IsEmpty()) + ver = vertemp; } else { + errorText = _T("Could not parse version check file: ") + g_Git.GetLibGit2LastErr(); SetDlgItemText(IDC_CHECKRESULT, errorText); + DeleteUrlCacheEntry(sCheckURL); + goto finish; } + + { + BOOL bNewer = FALSE; + if (m_bForce) + bNewer = TRUE; + else if (major > TGIT_VERMAJOR) + bNewer = TRUE; + else if ((minor > TGIT_VERMINOR) && (major == TGIT_VERMAJOR)) + bNewer = TRUE; + else if ((micro > TGIT_VERMICRO) && (minor == TGIT_VERMINOR) && (major == TGIT_VERMAJOR)) + bNewer = TRUE; + else if ((build > TGIT_VERBUILD) && (micro == TGIT_VERMICRO) && (minor == TGIT_VERMINOR) && (major == TGIT_VERMAJOR)) + bNewer = TRUE; + + CString versionstr; + versionstr.Format(_T("%u.%u.%u.%u"), major, minor, micro, build); + if (versionstr != ver) + versionstr += _T(" (") + ver + _T(")"); + temp.Format(IDS_CHECKNEWER_CURRENTVERSION, (LPCTSTR)versionstr); + SetDlgItemText(IDC_CURRENTVERSION, temp); + + if (bNewer) + { + versioncheck.GetString(_T("tortoisegit.infotext"), temp); + if (!temp.IsEmpty()) + { + CString tempLink; + versioncheck.GetString(_T("tortoisegit.infotexturl"), tempLink); + if (!tempLink.IsEmpty()) // find out the download link-URL, if any + m_sUpdateDownloadLink = tempLink; + } + else + temp.LoadString(IDS_CHECKNEWER_NEWERVERSIONAVAILABLE); + SetDlgItemText(IDC_CHECKRESULT, temp); + + FillChangelog(versioncheck, official); + FillDownloads(versioncheck, ver); + + // Show download controls + RECT rectWindow, rectProgress, rectGroupDownloads, rectOKButton; + GetWindowRect(&rectWindow); + m_progress.GetWindowRect(&rectProgress); + GetDlgItem(IDC_GROUP_DOWNLOADS)->GetWindowRect(&rectGroupDownloads); + GetDlgItem(IDOK)->GetWindowRect(&rectOKButton); + LONG bottomDistance = rectWindow.bottom - rectOKButton.bottom; + OffsetRect(&rectOKButton, 0, (rectGroupDownloads.bottom + (rectGroupDownloads.bottom - rectProgress.bottom)) - rectOKButton.top); + rectWindow.bottom = rectOKButton.bottom + bottomDistance; + MoveWindow(&rectWindow); + ::MapWindowPoints(NULL, GetSafeHwnd(), (LPPOINT)&rectOKButton, 2); + GetDlgItem(IDOK)->MoveWindow(&rectOKButton); + m_ctrlFiles.ShowWindow(SW_SHOW); + GetDlgItem(IDC_GROUP_DOWNLOADS)->ShowWindow(SW_SHOW); + CenterWindow(); + m_bShowInfo = TRUE; + } + else if (m_bShowInfo) + { + temp.LoadString(IDS_CHECKNEWER_YOURUPTODATE); + SetDlgItemText(IDC_CHECKRESULT, temp); + FillChangelog(versioncheck, official); + } + } + +finish: if (!m_sUpdateDownloadLink.IsEmpty()) { m_link.ShowWindow(SW_SHOW); m_link.SetURL(m_sUpdateDownloadLink); } - -finish: m_bThreadRunning = FALSE; DialogEnableWindow(IDOK, TRUE); return 0; } -void CCheckForUpdatesDlg::FillDownloads(CStdioFile &file, CString version) +void CCheckForUpdatesDlg::FillDownloads(CAutoConfig& versioncheck, const CString version) { #if WIN64 const CString x86x64 = _T("64"); @@ -376,7 +363,8 @@ void CCheckForUpdatesDlg::FillDownloads(CStdioFile &file, CString version) const CString x86x64 = _T("32"); #endif - if (!file.ReadString(m_sFilesURL) || m_sFilesURL.IsEmpty()) + versioncheck.GetString(_T("tortoisegit.baseurl"), m_sFilesURL); + if (m_sFilesURL.IsEmpty()) m_sFilesURL.Format(_T("http://updater.download.tortoisegit.org/tgit/%s/"), version); m_ctrlFiles.InsertItem(0, _T("TortoiseGit")); @@ -385,7 +373,19 @@ void CCheckForUpdatesDlg::FillDownloads(CStdioFile &file, CString version) m_ctrlFiles.SetItemData(0, (DWORD_PTR)(new CUpdateListCtrl::Entry(filename, CUpdateListCtrl::STATUS_NONE))); m_ctrlFiles.SetCheck(0 , TRUE); - std::vector m_installedLangs; + struct LangPack + { + CString m_PackName; + CString m_LangName; + DWORD m_LocaleID; + CString m_LangCode; + bool m_Installed; + }; + struct LanguagePacks + { + std::vector availableLangs; + std::vector installedLangs; + } languagePacks; { // set up the language selecting combobox CString path = CPathUtils::GetAppParentDirectory(); @@ -406,27 +406,23 @@ void CCheckForUpdatesDlg::FillDownloads(CStdioFile &file, CString version) if ((sLoc.Left(2) == L"32") && (sLoc.GetLength() > 5)) continue; DWORD loc = _tstoi(filename.Mid(12)); - m_installedLangs.push_back(loc); + languagePacks.installedLangs.push_back(loc); } } } - struct LangPack - { - CString m_PackName; - CString m_LangName; - DWORD m_LocaleID; - CString m_LangCode; - bool m_Installed; - }; - std::vector availableLangs; - CString langs; - while (file.ReadString(langs) && !langs.IsEmpty()) + git_config_get_multivar_foreach(versioncheck, "tortoisegit.langs", nullptr, [](const git_config_entry* configentry, void* payload) -> int { + LanguagePacks* languagePacks = (LanguagePacks*)payload; + CString langs = CUnicodeUtils::GetUnicode(configentry->value); + + int nextTokenPos = langs.Find(_T(";"), 5); // be extensible for the future + if (nextTokenPos > 0) + langs = langs.Left(nextTokenPos); CString sLang = _T("TortoiseGit Language Pack ") + langs.Mid(5); DWORD loc = _tstoi(langs.Mid(0, 4)); - TCHAR buf[MAX_PATH] = {0}; + TCHAR buf[MAX_PATH] = { 0 }; GetLocaleInfo(loc, LOCALE_SNATIVELANGNAME, buf, _countof(buf)); CString sLang2(buf); GetLocaleInfo(loc, LOCALE_SNATIVECTRYNAME, buf, _countof(buf)); @@ -437,15 +433,17 @@ void CCheckForUpdatesDlg::FillDownloads(CStdioFile &file, CString version) sLang2 += _T(")"); } - bool installed = std::find(m_installedLangs.begin(), m_installedLangs.end(), loc) != m_installedLangs.end(); + bool installed = std::find(languagePacks->installedLangs.begin(), languagePacks->installedLangs.end(), loc) != languagePacks->installedLangs.end(); LangPack pack = { sLang, sLang2, loc, langs.Mid(5), installed }; - availableLangs.push_back(pack); - } - std::stable_sort(availableLangs.begin(), availableLangs.end(), [&](const LangPack& a, const LangPack& b) -> int + languagePacks->availableLangs.push_back(pack); + + return 0; + }, &languagePacks); + std::stable_sort(languagePacks.availableLangs.begin(), languagePacks.availableLangs.end(), [&](const LangPack& a, const LangPack& b) -> int { return (a.m_Installed && !b.m_Installed) ? 1 : (!a.m_Installed && b.m_Installed) ? 0 : (a.m_PackName.Compare(b.m_PackName) < 0); }); - for (auto langs : availableLangs) + for (auto langs : languagePacks.availableLangs) { int pos = m_ctrlFiles.InsertItem(m_ctrlFiles.GetItemCount(), langs.m_PackName); m_ctrlFiles.SetItemText(pos, 1, langs.m_LangName); @@ -460,10 +458,11 @@ void CCheckForUpdatesDlg::FillDownloads(CStdioFile &file, CString version) DialogEnableWindow(IDC_BUTTON_UPDATE, TRUE); } -void CCheckForUpdatesDlg::FillChangelog(CStdioFile &file, bool official) +void CCheckForUpdatesDlg::FillChangelog(CAutoConfig& versioncheck, bool official) { CString sChangelogURL; - if (!file.ReadString(sChangelogURL) || sChangelogURL.IsEmpty()) + versioncheck.GetString(_T("TortoiseGit.changelogurl"), sChangelogURL); + if (sChangelogURL.IsEmpty()) sChangelogURL = _T("https://versioncheck.tortoisegit.org/changelog.txt"); CString tempchangelogfile = CTempFiles::Instance().GetTempFilePath(true).GetWinPathString(); diff --git a/src/TortoiseProc/CheckForUpdatesDlg.h b/src/TortoiseProc/CheckForUpdatesDlg.h index 9d5568d73..8074a1605 100644 --- a/src/TortoiseProc/CheckForUpdatesDlg.h +++ b/src/TortoiseProc/CheckForUpdatesDlg.h @@ -89,7 +89,7 @@ private: CString GetDownloadsDirectory(); CMenuButton m_ctrlUpdate; BOOL VerifySignature(CString fileName); - void FillDownloads(CStdioFile &file, CString version); + void FillDownloads(CAutoConfig& versionfile, const CString version); CSciEdit m_cLogMessage; - void FillChangelog(CStdioFile &file, bool official); + void FillChangelog(CAutoConfig& versionfile, bool official); }; -- 2.11.4.GIT