OSDN Git Service

Add routines to check for software updates (incomplete).
authors_kawamoto <s_kawamoto@users.sourceforge.jp>
Sun, 20 Apr 2014 12:07:23 +0000 (21:07 +0900)
committers_kawamoto <s_kawamoto@users.sourceforge.jp>
Sun, 20 Apr 2014 12:07:23 +0000 (21:07 +0900)
FFFTP_Eng_Release/FFFTP.exe
Release/FFFTP.exe
main.c
updater.c
updater.h

index c33825c..0050a2b 100644 (file)
Binary files a/FFFTP_Eng_Release/FFFTP.exe and b/FFFTP_Eng_Release/FFFTP.exe differ
index f7bf4bc..7aa4593 100644 (file)
Binary files a/Release/FFFTP.exe and b/Release/FFFTP.exe differ
diff --git a/main.c b/main.c
index 470d1d7..9db97b0 100644 (file)
--- a/main.c
+++ b/main.c
@@ -55,6 +55,9 @@
 #include <htmlhelp.h>\r
 #include "helpid.h"\r
 \r
+// ソフトウェア自動更新\r
+#include "updater.h"\r
+\r
 // UTF-8対応\r
 #undef __MBSWRAPPER_H__\r
 #include "mbswrapper.h"\r
@@ -295,6 +298,8 @@ int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLi
     MSG Msg;\r
        int Ret;\r
        BOOL Sts;\r
+       // ソフトウェア自動更新\r
+       char UpdateDir[FMAX_PATH+1];\r
 \r
        // プロセス保護\r
 #ifdef ENABLE_PROCESS_PROTECTION\r
@@ -362,6 +367,20 @@ int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLi
        }\r
 #endif\r
 \r
+       // ソフトウェア自動更新\r
+       if(GetTokenAfterOption(lpszCmdLine, UpdateDir, "--software-update", "--software-update"))\r
+       {\r
+               if(!StartUpdateProcessAsAdministrator(lpszCmdLine, " --restart"))\r
+               {\r
+                       ApplyUpdates(UpdateDir);\r
+               }\r
+               return 0;\r
+       }\r
+       else if(GetTokenAfterOption(lpszCmdLine, UpdateDir, "--software-cleanup", "--software-cleanup"))\r
+       {\r
+               // TODO: ダウンロードした更新ファイルを削除\r
+       }\r
+\r
        // マルチコアCPUの特定環境下でファイル通信中にクラッシュするバグ対策\r
 #ifdef DISABLE_MULTI_CPUS\r
        SetProcessAffinityMask(GetCurrentProcess(), 1);\r
@@ -2191,6 +2210,21 @@ static int AnalyzeComLine(char *Str, int *AutoConnect, int *CmdOption, char *unc
                                *CmdOption |= OPT_SJIS_NAME;\r
                        else if((strcmp(&Tmp[1], "u8n") == 0) || (strcmp(&Tmp[1], "-utf8name") == 0))\r
                                *CmdOption |= OPT_UTF8N_NAME;\r
+                       // ソフトウェア自動更新\r
+                       else if(strcmp(Tmp, "--software-update") == 0)\r
+                       {\r
+                               if((Str = GetToken(Str, Tmp)) == NULL)\r
+                               {\r
+                                       Ret = -1;\r
+                               }\r
+                       }\r
+                       else if(strcmp(Tmp, "--software-cleanup") == 0)\r
+                       {\r
+                               if((Str = GetToken(Str, Tmp)) == NULL)\r
+                               {\r
+                                       Ret = -1;\r
+                               }\r
+                       }\r
                        else\r
                        {\r
                                SetTaskMsg(MSGJPN180, Tmp);\r
index 40c362d..815996b 100644 (file)
--- a/updater.c
+++ b/updater.c
@@ -2,6 +2,7 @@
 // Copyright (C) 2014 Suguru Kawamoto\r
 // ソフトウェア自動更新\r
 \r
+#include <tchar.h>\r
 #include <ws2tcpip.h>\r
 #include <windows.h>\r
 #include <mmsystem.h>\r
@@ -12,6 +13,7 @@ typedef SOCKADDR_STORAGE *PSOCKADDR_STORAGE, FAR *LPSOCKADDR_STORAGE;
 #include "updater.h"\r
 #include "socketwrapper.h"\r
 #include "protectprocess.h"\r
+#include "mbswrapper.h"\r
 \r
 typedef struct\r
 {\r
@@ -56,7 +58,7 @@ BOOL DownloadFileViaHTTP(void* pOut, DWORD Length, DWORD* pLength, LPCWSTR UserA
 }\r
 \r
 // FFFTPの更新情報を確認\r
-BOOL CheckForUpdates()\r
+BOOL CheckForUpdates(BOOL bDownload, LPCTSTR DownloadDir)\r
 {\r
        BOOL bResult;\r
        DWORD Length;\r
@@ -80,6 +82,9 @@ BOOL CheckForUpdates()
                                                if(memcmp(&Hash, &UpdateHash.ListHash, 64) == 0)\r
                                                {\r
                                                        // TODO: 更新情報を解析\r
+                                                       bResult = TRUE;\r
+                                                       if(bDownload)\r
+                                                               bResult = PrepareUpdates(&Buf1, Length, DownloadDir);\r
                                                }\r
                                        }\r
                                }\r
@@ -89,12 +94,67 @@ BOOL CheckForUpdates()
        return bResult;\r
 }\r
 \r
-// 別のプロセスでFFFTPを更新\r
-BOOL StartUpdateProcess()\r
+// 更新するファイルをダウンロード\r
+BOOL PrepareUpdates(void* pList, DWORD ListLength, LPCTSTR DownloadDir)\r
 {\r
        BOOL bResult;\r
        bResult = FALSE;\r
-       // TODO: CreateProcess()\r
+       // TODO: 更新情報を解析\r
+       // TODO: 更新するファイルをダウンロード\r
+       return bResult;\r
+}\r
+\r
+// FFFTPを更新\r
+BOOL ApplyUpdates(LPCTSTR DestinationDir)\r
+{\r
+       BOOL bResult;\r
+       bResult = FALSE;\r
+       // TODO:\r
+       return bResult;\r
+}\r
+\r
+// 更新用のプロセスを起動\r
+BOOL StartUpdateProcess(LPCTSTR Path, LPCTSTR CommandLine)\r
+{\r
+       BOOL bResult;\r
+       bResult = FALSE;\r
+       if(ShellExecute(NULL, "open", Path, CommandLine, NULL, SW_SHOW) > (HINSTANCE)32)\r
+               bResult = TRUE;\r
+       return bResult;\r
+}\r
+\r
+// 更新用のプロセスを管理者権限で起動\r
+// Windows XP以前など起動できない場合は現在のプロセスで処理を続行\r
+BOOL StartUpdateProcessAsAdministrator(LPCTSTR CommandLine, LPCTSTR Keyword)\r
+{\r
+       BOOL bResult;\r
+       TCHAR* NewCommandLine;\r
+       TCHAR Path[MAX_PATH];\r
+       SHELLEXECUTEINFO Info;\r
+       bResult = FALSE;\r
+       if(_tcslen(CommandLine) < _tcslen(Keyword) || _tcscmp(CommandLine + _tcslen(CommandLine) - _tcslen(Keyword), Keyword) != 0)\r
+       {\r
+               if(NewCommandLine = (TCHAR*)malloc(sizeof(TCHAR) * (_tcslen(CommandLine) + _tcslen(Keyword) + 1)))\r
+               {\r
+                       _tcscpy(NewCommandLine, CommandLine);\r
+                       _tcscat(NewCommandLine, Keyword);\r
+                       GetModuleFileName(NULL, Path, MAX_PATH);\r
+                       memset(&Info, 0, sizeof(SHELLEXECUTEINFO));\r
+                       Info.cbSize = sizeof(SHELLEXECUTEINFO);\r
+                       Info.fMask = SEE_MASK_NOCLOSEPROCESS;\r
+                       Info.lpVerb = "runas";\r
+                       Info.lpFile = Path;\r
+                       Info.lpParameters = NewCommandLine;\r
+                       Info.nShow = SW_SHOW;\r
+                       if(ShellExecuteEx(&Info))\r
+                       {\r
+                               WaitForSingleObject(Info.hProcess, INFINITE);\r
+                               CloseHandle(Info.hProcess);\r
+                               bResult = TRUE;\r
+                       }\r
+                       free(NewCommandLine);\r
+               }\r
+       }\r
        return bResult;\r
 }\r
 \r
index 029141c..deecaac 100644 (file)
--- a/updater.h
+++ b/updater.h
        "-----END PUBLIC KEY-----\n"\r
 #define UPDATE_SIGNATURE "\x4C\x2A\x8E\x57\xAB\x75\x0C\xB5\xDA\x5F\xFE\xB9\x57\x9A\x1B\xA2\x7A\x61\x32\xF8\xFA\x4B\x61\xE2\xBA\x20\x9C\x37\xD5\x0A\xDC\x94\x10\x4D\x02\x30\x9B\xCD\x01\x9B\xB8\x73\x1E\xDB\xFD\xD7\x45\xCA\xE0\x8E\xF9\xB0\x1F\xB4\x0D\xD8\xFB\xE8\x41\x48\xE7\xF5\xE8\x64"\r
 \r
-BOOL CheckForUpdates();\r
-BOOL StartUpdateProcess();\r
+BOOL CheckForUpdates(BOOL bDownload, LPCTSTR DownloadDir);\r
+BOOL PrepareUpdates(void* pList, DWORD ListLength, LPCTSTR DownloadDir);\r
+BOOL ApplyUpdates(LPCTSTR DestinationDir);\r
+BOOL StartUpdateProcess(LPCTSTR CommandLine, LPCTSTR Keyword);\r
+BOOL StartUpdateProcessAsAdministrator(LPCTSTR CommandLine, LPCTSTR Keyword);\r
 \r
 #endif\r
 \r