OSDN Git Service

Add Check Software Updater support
authorFrank Li <lznuaa@gmail.com>
Sun, 6 Sep 2009 07:53:51 +0000 (15:53 +0800)
committerFrank Li <lznuaa@gmail.com>
Sun, 6 Sep 2009 07:53:51 +0000 (15:53 +0800)
Signed-off-by: Frank Li <lznuaa@gmail.com>
src/Resources/TortoiseProcENG.rc
src/TortoiseProc/CheckForUpdatesDlg.cpp
src/TortoiseProc/CheckForUpdatesDlg.h
src/TortoiseProc/Commands/Command.cpp
src/TortoiseProc/TortoiseProc.cpp
src/TortoiseProc/TortoiseProc.vcproj
src/TortoiseProc/resource.h
src/Utils/TempFile.cpp
src/Utils/Utils.vcproj

index 4bce52a..7c2f754 100644 (file)
Binary files a/src/Resources/TortoiseProcENG.rc and b/src/Resources/TortoiseProcENG.rc differ
index 79bbefa..7a9488f 100644 (file)
@@ -18,6 +18,7 @@
 //\r
 #include "stdafx.h"\r
 #include "TortoiseProc.h"\r
+#include "CommonResource.h"\r
 #include "..\version.h"\r
 #include "MessageBox.h"\r
 #include ".\checkforupdatesdlg.h"\r
@@ -32,7 +33,8 @@ CCheckForUpdatesDlg::CCheckForUpdatesDlg(CWnd* pParent /*=NULL*/)
        , m_bShowInfo(FALSE)\r
        , m_bVisible(FALSE)\r
 {\r
-       m_sUpdateDownloadLink = _T("http://tortoisesvn.tigris.org");\r
+       m_sUpdateDownloadLink = _T("http://code.google.com/p/tortoisegit/downloads");\r
+       m_sUpdateChangeLogLink = _T("http://code.google.com/p/tortoisegit/wiki/ReleaseNotes");\r
 }\r
 \r
 CCheckForUpdatesDlg::~CCheckForUpdatesDlg()\r
@@ -43,6 +45,7 @@ void CCheckForUpdatesDlg::DoDataExchange(CDataExchange* pDX)
 {\r
        CStandAloneDialog::DoDataExchange(pDX);\r
        DDX_Control(pDX, IDC_LINK, m_link);\r
+       DDX_Control(pDX, IDC_LINK_CHANGE_LOG, m_ChangeLogLink);\r
 }\r
 \r
 \r
@@ -105,8 +108,9 @@ UINT CCheckForUpdatesDlg::CheckThread()
        {\r
                sCheckURL = checkurlmachine;\r
                if (sCheckURL.IsEmpty())\r
-                       sCheckURL = _T("http://tortoisesvn.tigris.org/version.txt");\r
+                       sCheckURL = _T("http://code.google.com/p/tortoisegit/downloads/list");\r
        }\r
+       CoInitialize(NULL);\r
        HRESULT res = URLDownloadToFile(NULL, sCheckURL, tempfile, 0, NULL);\r
        if (res == S_OK)\r
        {\r
@@ -114,16 +118,54 @@ UINT CCheckForUpdatesDlg::CheckThread()
                {\r
                        CStdioFile file(tempfile, CFile::modeRead | CFile::shareDenyWrite);\r
                        CString ver;\r
-                       if (file.ReadString(ver))\r
+                       int major,minor,micro,build;\r
+                       major=minor=micro=build=0;\r
+                       unsigned __int64 version=0;\r
+\r
+                       if(file.GetLength()>100)\r
+                       {\r
+                               while(file.ReadString(ver))\r
+                               {\r
+                                       int start;\r
+                                       while( (start=ver.Find(_T("TortoiseGit-"))) > 0 )\r
+                                       {\r
+                                               ver = ver.Mid(start+CString(_T("TortoiseGit-")).GetLength());\r
+                                               int x1,x2,x3,x4;\r
+                                               x1=_ttoi(ver)&0xFFFF;\r
+                                               ver = ver.Mid(ver.Find('.')+1);\r
+                                               x2=_ttoi(ver)&0xFFFF;\r
+                                               ver = ver.Mid(ver.Find('.')+1);\r
+                                               x3=_ttoi(ver)&0xFFFF;\r
+                                               ver = ver.Mid(ver.Find('.')+1);\r
+                                               x4=_ttoi(ver)&0xFFFF;\r
+                                               \r
+                                               unsigned __int64 newversion;\r
+                                               newversion = (x1<<48) + (x2<<32) + (x3<<16)+x4;\r
+                                               if(newversion>version)\r
+                                               {\r
+                                                       major=x1;\r
+                                                       minor=x2;\r
+                                                       micro=x3;\r
+                                                       build=x4;\r
+                                                       version = newversion;\r
+                                               }\r
+                                       }\r
+                               }\r
+\r
+                       }else if (file.ReadString(ver))\r
                        {\r
                                CString vertemp = ver;\r
-                               int major = _ttoi(vertemp);\r
+                               major = _ttoi(vertemp);\r
                                vertemp = vertemp.Mid(vertemp.Find('.')+1);\r
-                               int minor = _ttoi(vertemp);\r
+                               minor = _ttoi(vertemp);\r
                                vertemp = vertemp.Mid(vertemp.Find('.')+1);\r
-                               int micro = _ttoi(vertemp);\r
+                               micro = _ttoi(vertemp);\r
                                vertemp = vertemp.Mid(vertemp.Find('.')+1);\r
-                               int build = _ttoi(vertemp);\r
+                               build = _ttoi(vertemp);\r
+                               version = (major<<48) + (minor<<32) + (micro<<16)+build;\r
+                       }\r
+\r
+                       {\r
                                BOOL bNewer = FALSE;\r
                                if (major > TSVN_VERMAJOR)\r
                                        bNewer = TRUE;\r
@@ -134,14 +176,15 @@ UINT CCheckForUpdatesDlg::CheckThread()
                                else if ((build > TSVN_VERBUILD)&&(micro == TSVN_VERMICRO)&&(minor == TSVN_VERMINOR)&&(major == TSVN_VERMAJOR))\r
                                        bNewer = TRUE;\r
 \r
-                               if (_ttoi(ver)!=0)\r
+                               if (version != 0)\r
                                {\r
+                                       ver.Format(_T("%d.%d.%d.%d"),major,minor,micro,build);\r
                                        temp.Format(IDS_CHECKNEWER_CURRENTVERSION, (LPCTSTR)ver);\r
                                        SetDlgItemText(IDC_CURRENTVERSION, temp);\r
                                        temp.Format(_T("%d.%d.%d.%d"), TSVN_VERMAJOR, TSVN_VERMINOR, TSVN_VERMICRO, TSVN_VERBUILD);\r
                                }\r
 \r
-                               if (_ttoi(ver)==0)\r
+                               if (version == 0)\r
                                {\r
                                        temp.LoadString(IDS_CHECKNEWER_NETERROR);\r
                                        SetDlgItemText(IDC_CHECKRESULT, temp);\r
@@ -180,6 +223,8 @@ UINT CCheckForUpdatesDlg::CheckThread()
        }\r
        else\r
        {\r
+               // Try to cache web page;\r
+\r
                temp.LoadString(IDS_CHECKNEWER_NETERROR);\r
                SetDlgItemText(IDC_CHECKRESULT, temp);\r
        }\r
@@ -188,6 +233,11 @@ UINT CCheckForUpdatesDlg::CheckThread()
                m_link.ShowWindow(SW_SHOW);\r
                m_link.SetURL(m_sUpdateDownloadLink);\r
        }\r
+       if (!m_sUpdateDownloadLink.IsEmpty())\r
+       {\r
+               m_ChangeLogLink.ShowWindow(SW_SHOW);\r
+               m_ChangeLogLink.SetURL(m_sUpdateChangeLogLink);\r
+       }\r
 \r
        DeleteFile(tempfile);\r
        m_bThreadRunning = FALSE;\r
index 715c72d..4c085c9 100644 (file)
@@ -59,6 +59,8 @@ public:
 \r
 private:\r
        CString         m_sUpdateDownloadLink;                  ///< Where to send a user looking to download a update\r
+       CString         m_sUpdateChangeLogLink;                 ///< Where to send a user looking to change log\r
        CHyperLink      m_link;\r
+       CHyperLink      m_ChangeLogLink;\r
 };\r
 \r
index 17ce1ae..3e15b96 100644 (file)
@@ -65,6 +65,7 @@
 #include "SVNDCommitCommand.h"\r
 #include "SVNRebaseCommand.h"\r
 #include "SyncCommand.h"\r
+#include "UpdateCheckCommand.h"\r
 \r
 #if 0\r
 \r
 \r
 #include "UnIgnoreCommand.h"\r
 #include "UnLockCommand.h"\r
-#include "UpdateCheckCommand.h"\r
+\r
 #include "UpdateCommand.h"\r
 #include "UrlDiffCommand.h"\r
 #endif\r
@@ -383,6 +384,9 @@ Command * CommandServer::GetCommand(const CString& sCmd)
                return new SVNRebaseCommand;\r
        case cmdSync:\r
                return new SyncCommand;\r
+       case cmdUpdateCheck:\r
+               return new UpdateCheckCommand;\r
+\r
 #if 0\r
 \r
        \r
@@ -434,8 +438,6 @@ Command * CommandServer::GetCommand(const CString& sCmd)
                return new UnLockCommand;\r
        case cmdUpdate:\r
                return new UpdateCommand;\r
-       case cmdUpdateCheck:\r
-               return new UpdateCheckCommand;\r
        case cmdUrlDiff:\r
                return new UrlDiffCommand;\r
 #endif\r
index f1e4158..7ffad03 100644 (file)
@@ -363,7 +363,7 @@ Click Yes to open setting dialog to setup MSysGit Path"),
                                        GetModuleFileName(NULL, com, MAX_PATH);\r
                                        _tcscat_s(com, MAX_PATH+100, _T(" /command:updatecheck"));\r
 \r
-                                       //CAppUtils::LaunchApplication(com, 0, false);\r
+                                       CAppUtils::LaunchApplication(com, 0, false);\r
                                }\r
                        }\r
                }\r
index 599812f..d03b238 100644 (file)
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath="..\Resources\copy.ico"\r
+                               RelativePath=".\copy.ico"\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath=".\copy.ico"\r
+                               RelativePath="..\Resources\copy.ico"\r
                                >\r
                        </File>\r
                        <File\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath=".\explorer.ico"\r
+                               RelativePath="..\Resources\explorer.ico"\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath="..\Resources\explorer.ico"\r
+                               RelativePath=".\explorer.ico"\r
                                >\r
                        </File>\r
                        <File\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath="..\Resources\newfolder.ico"\r
+                               RelativePath=".\newfolder.ico"\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath=".\newfolder.ico"\r
+                               RelativePath="..\Resources\newfolder.ico"\r
                                >\r
                        </File>\r
                        <File\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath="..\Resources\refresh.ico"\r
+                               RelativePath=".\refresh.ico"\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath=".\refresh.ico"\r
+                               RelativePath="..\Resources\refresh.ico"\r
                                >\r
                        </File>\r
                        <File\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath=".\save.ico"\r
+                               RelativePath="..\Resources\save.ico"\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath="..\Resources\save.ico"\r
+                               RelativePath=".\save.ico"\r
                                >\r
                        </File>\r
                        <File\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath="..\Resources\up.ico"\r
+                               RelativePath=".\up.ico"\r
                                >\r
                        </File>\r
                        <File\r
-                               RelativePath=".\up.ico"\r
+                               RelativePath="..\Resources\up.ico"\r
                                >\r
                        </File>\r
                        <File\r
                                        >\r
                                </File>\r
                        </Filter>\r
+                       <Filter\r
+                               Name="UpdateCheck"\r
+                               >\r
+                               <File\r
+                                       RelativePath=".\CheckForUpdatesDlg.cpp"\r
+                                       >\r
+                               </File>\r
+                               <File\r
+                                       RelativePath=".\CheckForUpdatesDlg.h"\r
+                                       >\r
+                               </File>\r
+                               <File\r
+                                       RelativePath=".\Commands\UpdateCheckCommand.cpp"\r
+                                       >\r
+                               </File>\r
+                               <File\r
+                                       RelativePath=".\Commands\UpdateCheckCommand.h"\r
+                                       >\r
+                               </File>\r
+                       </Filter>\r
                </Filter>\r
                <Filter\r
                        Name="Utility Dialogs"\r
index 7f209b6..0f3afc8 100644 (file)
Binary files a/src/TortoiseProc/resource.h and b/src/TortoiseProc/resource.h differ
index bbfdfe6..d223bb4 100644 (file)
@@ -19,6 +19,7 @@
 #include "StdAfx.h"\r
 #include "Registry.h"\r
 #include "TempFile.h"\r
+#include "TGitPath.h"\r
 \r
 CTempFiles::CTempFiles(void)\r
 {\r
@@ -35,31 +36,31 @@ CTempFiles& CTempFiles::Instance()
        return instance;\r
 }\r
 \r
-CTSVNPath CTempFiles::GetTempFilePath(bool bRemoveAtEnd, const CTSVNPath& path /* = CTSVNPath() */, const SVNRev revision /* = SVNRev() */)\r
+CTGitPath CTempFiles::GetTempFilePath(bool bRemoveAtEnd, const CTGitPath& path /* = CTGitPath() */, const GitRev revision /* = GitRev() */)\r
 {\r
        DWORD len = ::GetTempPath(0, NULL);\r
        TCHAR * temppath = new TCHAR[len+1];\r
        TCHAR * tempF = new TCHAR[len+50];\r
        ::GetTempPath (len+1, temppath);\r
-       CTSVNPath tempfile;\r
+       CTGitPath tempfile;\r
        CString possibletempfile;\r
        if (path.IsEmpty())\r
        {\r
-               ::GetTempFileName (temppath, TEXT("svn"), 0, tempF);\r
-               tempfile = CTSVNPath(tempF);\r
+               ::GetTempFileName (temppath, TEXT("git"), 0, tempF);\r
+               tempfile = CTGitPath(tempF);\r
        }\r
        else\r
        {\r
                int i=0;\r
                do\r
                {\r
-                       if (revision.IsValid())\r
+                       if (!revision.m_CommitHash.IsEmpty())\r
                        {\r
-                               possibletempfile.Format(_T("%s%s-rev%s.svn%3.3x.tmp%s"), temppath, (LPCTSTR)path.GetFileOrDirectoryName(), (LPCTSTR)revision.ToString(), i, (LPCTSTR)path.GetFileExtension());\r
+                               possibletempfile.Format(_T("%s%s-rev%s.git%3.3x.tmp%s"), temppath, (LPCTSTR)path.GetFileOrDirectoryName(), (LPCTSTR)revision.m_CommitHash.Left(7), i, (LPCTSTR)path.GetFileExtension());\r
                        }\r
                        else\r
                        {\r
-                               possibletempfile.Format(_T("%s%s.svn%3.3x.tmp%s"), temppath, (LPCTSTR)path.GetFileOrDirectoryName(), i, (LPCTSTR)path.GetFileExtension());\r
+                               possibletempfile.Format(_T("%s%s.git%3.3x.tmp%s"), temppath, (LPCTSTR)path.GetFileOrDirectoryName(), i, (LPCTSTR)path.GetFileExtension());\r
                        }\r
                        tempfile.SetFromWin(possibletempfile);\r
                        i++;\r
index d85f21b..8ccb98e 100644 (file)
                                >\r
                        </File>\r
                        <File\r
+                               RelativePath=".\TempFile.cpp"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\TempFile.h"\r
+                               >\r
+                       </File>\r
+                       <File\r
                                RelativePath=".\UnicodeUtils.cpp"\r
                                >\r
                        </File>\r