OSDN Git Service

Prepare for release of 1.98f.
[ffftp/ffftp.git] / ftpproc.c
index af6e2b0..94ad8a2 100644 (file)
--- a/ftpproc.c
+++ b/ftpproc.c
@@ -71,7 +71,7 @@ static INT_PTR CALLBACK MirrorNotifyCallBack(HWND hDlg, UINT iMessage, WPARAM wP
 static INT_PTR CALLBACK MirrorDispListCallBack(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam);\r
 static void CountMirrorFiles(HWND hDlg, TRANSPACKET *Pkt);\r
 static int AskMirrorNoTrn(char *Fname, int Mode);\r
-static int AskUpLoadFileAttr(char *Fname);\r
+static int AskUploadFileAttr(char *Fname);\r
 // 64ビット対応\r
 //static BOOL CALLBACK UpDownAsDialogCallBack(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam);\r
 static INT_PTR CALLBACK UpDownAsDialogCallBack(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam);\r
@@ -108,6 +108,8 @@ extern SIZE MirrorDlgSize;
 extern int VaxSemicolon;\r
 extern int DebugConsole;\r
 extern int CancelFlg;\r
+// ディレクトリ自動作成\r
+extern int MakeAllDir;\r
 \r
 /*===== ローカルなワーク =====*/\r
 \r
@@ -136,11 +138,50 @@ static double FileSize;           /* ファイル総容量 */
 *              なし\r
 *----------------------------------------------------------------------------*/\r
 \r
-void DownLoadProc(int ChName, int ForceFile, int All)\r
+// ディレクトリ自動作成\r
+// ローカル側のパスから必要なフォルダを作成\r
+int MakeDirFromLocalPath(char* LocalFile, char* Old)\r
+{\r
+       TRANSPACKET Pkt;\r
+       char* pDelimiter;\r
+       char* pNext;\r
+       char* Cat;\r
+       int Len;\r
+       int Make;\r
+       pDelimiter = LocalFile;\r
+       Make = NO;\r
+       while(pNext = strchr(pDelimiter, '\\'))\r
+       {\r
+               Len = pNext - LocalFile;\r
+               strncpy(Pkt.LocalFile, LocalFile, Len);\r
+               Pkt.LocalFile[Len] = '\0';\r
+               if(strncmp(LocalFile, Old, Len + 1) != 0)\r
+               {\r
+                       Cat = Pkt.LocalFile + (pDelimiter - LocalFile);\r
+                       if(FnameCnv == FNAME_LOWER)\r
+                               _mbslwr(Cat);\r
+                       else if(FnameCnv == FNAME_UPPER)\r
+                               _mbsupr(Cat);\r
+                       ReplaceAll(Pkt.LocalFile, '/', '\\');\r
+\r
+                       strcpy(Pkt.Cmd, "MKD ");\r
+                       strcpy(Pkt.RemoteFile, "");\r
+                       AddTransFileList(&Pkt);\r
+\r
+                       Make = YES;\r
+               }\r
+               pDelimiter = pNext + 1;\r
+       }\r
+       return Make;\r
+}\r
+\r
+void DownloadProc(int ChName, int ForceFile, int All)\r
 {\r
        FILELIST *FileListBase;\r
        FILELIST *Pos;\r
        TRANSPACKET Pkt;\r
+       // ディレクトリ自動作成\r
+       char Tmp[FMAX_PATH+1];\r
 \r
        // 同時接続対応\r
        CancelFlg = NO;\r
@@ -244,11 +285,19 @@ void DownLoadProc(int ChName, int ForceFile, int All)
                                Pkt.KanjiCodeDesired = AskLocalKanjiCode();\r
                                Pkt.KanaCnv = AskHostKanaCnv();\r
 \r
+                               // ディレクトリ自動作成\r
+                               strcpy(Tmp, Pkt.LocalFile);\r
                                Pkt.Mode = CheckLocalFile(&Pkt);        /* Pkt.ExistSize がセットされる */\r
                                if(Pkt.Mode == EXIST_ABORT)\r
                                        break;\r
                                else if(Pkt.Mode != EXIST_IGNORE)\r
+                               // ディレクトリ自動作成\r
+//                                     AddTransFileList(&Pkt);\r
+                               {\r
+                                       if(MakeAllDir == YES)\r
+                                               MakeDirFromLocalPath(Pkt.LocalFile, Tmp);\r
                                        AddTransFileList(&Pkt);\r
+                               }\r
                        }\r
                        Pos = Pos->Next;\r
                }\r
@@ -265,6 +314,9 @@ void DownLoadProc(int ChName, int ForceFile, int All)
 //             strcpy(Pkt.Cmd, "GOQUIT");\r
 //             AddTransFileList(&Pkt);\r
 \r
+               // バグ対策\r
+               AddNullTransFileList();\r
+\r
                GoForwardTransWindow();\r
 //             KeepTransferDialog(NO);\r
 \r
@@ -283,9 +335,11 @@ void DownLoadProc(int ChName, int ForceFile, int All)
 *              なし\r
 *----------------------------------------------------------------------------*/\r
 \r
-void DirectDownLoadProc(char *Fname)\r
+void DirectDownloadProc(char *Fname)\r
 {\r
        TRANSPACKET Pkt;\r
+       // ディレクトリ自動作成\r
+       char Tmp[FMAX_PATH+1];\r
 \r
        // 同時接続対応\r
        CancelFlg = NO;\r
@@ -351,9 +405,17 @@ void DirectDownLoadProc(char *Fname)
                                Pkt.KanjiCodeDesired = AskLocalKanjiCode();\r
                                Pkt.KanaCnv = AskHostKanaCnv();\r
 \r
+                               // ディレクトリ自動作成\r
+                               strcpy(Tmp, Pkt.LocalFile);\r
                                Pkt.Mode = CheckLocalFile(&Pkt);        /* Pkt.ExistSize がセットされる */\r
                                if((Pkt.Mode != EXIST_ABORT) && (Pkt.Mode != EXIST_IGNORE))\r
+                               // ディレクトリ自動作成\r
+//                                     AddTransFileList(&Pkt);\r
+                               {\r
+                                       if(MakeAllDir == YES)\r
+                                               MakeDirFromLocalPath(Pkt.LocalFile, Tmp);\r
                                        AddTransFileList(&Pkt);\r
+                               }\r
                        }\r
                }\r
 \r
@@ -368,6 +430,9 @@ void DirectDownLoadProc(char *Fname)
 //             strcpy(Pkt.Cmd, "GOQUIT");\r
 //             AddTransFileList(&Pkt);\r
 \r
+               // バグ対策\r
+               AddNullTransFileList();\r
+\r
                GoForwardTransWindow();\r
 //             KeepTransferDialog(NO);\r
 \r
@@ -386,7 +451,7 @@ void DirectDownLoadProc(char *Fname)
 *              なし\r
 *----------------------------------------------------------------------------*/\r
 \r
-void InputDownLoadProc(void)\r
+void InputDownloadProc(void)\r
 {\r
        char Path[FMAX_PATH+1];\r
        int Tmp;\r
@@ -396,7 +461,7 @@ void InputDownLoadProc(void)
        strcpy(Path, "");\r
        if(InputDialogBox(downname_dlg, GetMainHwnd(), NULL, Path, FMAX_PATH, &Tmp, IDH_HELP_TOPIC_0000001) == YES)\r
        {\r
-               DirectDownLoadProc(Path);\r
+               DirectDownloadProc(Path);\r
        }\r
 \r
 //     EnableUserOpe();\r
@@ -638,6 +703,9 @@ void MirrorDownloadProc(int Notify)
                        else\r
                                EraseTmpTransFileList(&Base);\r
 \r
+                       // バグ対策\r
+                       AddNullTransFileList();\r
+\r
                        DeleteFileList(&LocalListBase);\r
                        DeleteFileList(&RemoteListBase);\r
 \r
@@ -890,7 +958,70 @@ static INT_PTR CALLBACK DownExistDialogCallBack(HWND hDlg, UINT iMessage, WPARAM
 *              なし\r
 *----------------------------------------------------------------------------*/\r
 \r
-void UpLoadListProc(int ChName, int All)\r
+// ディレクトリ自動作成\r
+// リモート側のパスから必要なディレクトリを作成\r
+int MakeDirFromRemotePath(char* RemoteFile, char* Old, int FirstAdd)\r
+{\r
+       TRANSPACKET Pkt;\r
+       TRANSPACKET Pkt1;\r
+       char* pDelimiter;\r
+       char* pNext;\r
+       char* Cat;\r
+       int Len;\r
+       int Make;\r
+       pDelimiter = RemoteFile;\r
+       Make = NO;\r
+       while(pNext = strchr(pDelimiter, '/'))\r
+       {\r
+               Len = pNext - RemoteFile;\r
+               strncpy(Pkt.RemoteFile, RemoteFile, Len);\r
+               Pkt.RemoteFile[Len] = '\0';\r
+               if(strncmp(RemoteFile, Old, Len + 1) != 0)\r
+               {\r
+                       Cat = Pkt.RemoteFile + (pDelimiter - RemoteFile);\r
+                       if(FnameCnv == FNAME_LOWER)\r
+                               _mbslwr(Cat);\r
+                       else if(FnameCnv == FNAME_UPPER)\r
+                               _mbsupr(Cat);\r
+#if defined(HAVE_TANDEM)\r
+                       Pkt.FileCode = 0;\r
+                       Pkt.PriExt = DEF_PRIEXT;\r
+                       Pkt.SecExt = DEF_SECEXT;\r
+                       Pkt.MaxExt = DEF_MAXEXT;\r
+#endif\r
+                       ReplaceAll(Pkt.RemoteFile, '\\', '/');\r
+\r
+                       if(AskHostType() == HTYPE_ACOS)\r
+                       {\r
+                               strcpy(Pkt.RemoteFile, "'");\r
+                               strcat(Pkt.RemoteFile, AskHostLsName());\r
+                               strcat(Pkt.RemoteFile, "(");\r
+                               strcat(Pkt.RemoteFile, Cat);\r
+                               strcat(Pkt.RemoteFile, ")");\r
+                               strcat(Pkt.RemoteFile, "'");\r
+                       }\r
+                       else if(AskHostType() == HTYPE_ACOS_4)\r
+                               strcpy(Pkt.RemoteFile, Cat);\r
+\r
+                       if((FirstAdd == YES) && (AskNoFullPathMode() == YES))\r
+                       {\r
+                               strcpy(Pkt1.Cmd, "SETCUR");\r
+                               AskRemoteCurDir(Pkt1.RemoteFile, FMAX_PATH);\r
+                               AddTransFileList(&Pkt1);\r
+                       }\r
+                       FirstAdd = NO;\r
+                       strcpy(Pkt.Cmd, "MKD ");\r
+                       strcpy(Pkt.LocalFile, "");\r
+                       AddTransFileList(&Pkt);\r
+\r
+                       Make = YES;\r
+               }\r
+               pDelimiter = pNext + 1;\r
+       }\r
+       return Make;\r
+}\r
+\r
+void UploadListProc(int ChName, int All)\r
 {\r
        FILELIST *FileListBase;\r
        FILELIST *Pos;\r
@@ -961,6 +1092,16 @@ void UpLoadListProc(int ChName, int All)
                                else\r
                                        break;\r
                        }\r
+                       // バグ修正\r
+                       AskRemoteCurDir(Tmp, FMAX_PATH);\r
+                       SetSlashTail(Tmp);\r
+                       if(strncmp(Pkt.RemoteFile, Tmp, strlen(Tmp)) != 0)\r
+                       {\r
+                               if((Cat = strrchr(Pkt.RemoteFile, '/')) != NULL)\r
+                                       Cat++;\r
+                               else\r
+                                       Cat = Pkt.RemoteFile;\r
+                       }\r
                        ReplaceAll(Pkt.RemoteFile, '\\', '/');\r
 \r
                        if(AskHostType() == HTYPE_ACOS)\r
@@ -1019,7 +1160,7 @@ void UpLoadListProc(int ChName, int All)
                                Pkt.Type = AskTransferTypeAssoc(Pkt.LocalFile, AskTransferType());\r
                                Pkt.Size = 0;\r
                                Pkt.Time = Pos->Time;\r
-                               Pkt.Attr = AskUpLoadFileAttr(Pkt.RemoteFile);\r
+                               Pkt.Attr = AskUploadFileAttr(Pkt.RemoteFile);\r
                                Pkt.KanjiCode = AskHostKanjiCode();\r
                                // UTF-8対応\r
                                Pkt.KanjiCodeDesired = AskLocalKanjiCode();\r
@@ -1029,11 +1170,19 @@ void UpLoadListProc(int ChName, int All)
                                        CalcExtentSize(&Pkt, Pos->Size);\r
                                }\r
 #endif\r
+                               // ディレクトリ自動作成\r
+                               strcpy(Tmp, Pkt.RemoteFile);\r
                                Pkt.Mode = CheckRemoteFile(&Pkt, RemoteList);\r
                                if(Pkt.Mode == EXIST_ABORT)\r
                                        break;\r
                                else if(Pkt.Mode != EXIST_IGNORE)\r
                                {\r
+                                       // ディレクトリ自動作成\r
+                                       if(MakeAllDir == YES)\r
+                                       {\r
+                                               if(MakeDirFromRemotePath(Pkt.RemoteFile, Tmp, FirstAdd) == YES)\r
+                                                       FirstAdd = NO;\r
+                                       }\r
                                        if((FirstAdd == YES) && (AskNoFullPathMode() == YES))\r
                                        {\r
                                                strcpy(Pkt1.Cmd, "SETCUR");\r
@@ -1063,6 +1212,9 @@ void UpLoadListProc(int ChName, int All)
 //             strcpy(Pkt.Cmd, "GOQUIT");\r
 //             AddTransFileList(&Pkt);\r
 \r
+               // バグ対策\r
+               AddNullTransFileList();\r
+\r
                GoForwardTransWindow();\r
 \r
                EnableUserOpe();\r
@@ -1080,7 +1232,7 @@ void UpLoadListProc(int ChName, int All)
 *              なし\r
 *----------------------------------------------------------------------------*/\r
 \r
-void UpLoadDragProc(WPARAM wParam)\r
+void UploadDragProc(WPARAM wParam)\r
 {\r
        FILELIST *FileListBase;\r
        FILELIST *Pos;\r
@@ -1186,7 +1338,7 @@ void UpLoadDragProc(WPARAM wParam)
                                Pkt.Type = AskTransferTypeAssoc(Pkt.LocalFile, AskTransferType());\r
                                Pkt.Size = 0;\r
                                Pkt.Time = Pos->Time;\r
-                               Pkt.Attr = AskUpLoadFileAttr(Pkt.RemoteFile);\r
+                               Pkt.Attr = AskUploadFileAttr(Pkt.RemoteFile);\r
                                Pkt.KanjiCode = AskHostKanjiCode();\r
                                // UTF-8対応\r
                                Pkt.KanjiCodeDesired = AskLocalKanjiCode();\r
@@ -1197,11 +1349,19 @@ void UpLoadDragProc(WPARAM wParam)
                                        CalcExtentSize(&Pkt, Pos->Size);\r
                                }\r
 #endif\r
+                               // ディレクトリ自動作成\r
+                               strcpy(Tmp, Pkt.RemoteFile);\r
                                Pkt.Mode = CheckRemoteFile(&Pkt, RemoteList);\r
                                if(Pkt.Mode == EXIST_ABORT)\r
                                        break;\r
                                else if(Pkt.Mode != EXIST_IGNORE)\r
                                {\r
+                                       // ディレクトリ自動作成\r
+                                       if(MakeAllDir == YES)\r
+                                       {\r
+                                               if(MakeDirFromRemotePath(Pkt.RemoteFile, Tmp, FirstAdd) == YES)\r
+                                                       FirstAdd = NO;\r
+                                       }\r
                                        if((FirstAdd == YES) && (AskNoFullPathMode() == YES))\r
                                        {\r
                                                strcpy(Pkt1.Cmd, "SETCUR");\r
@@ -1231,6 +1391,9 @@ void UpLoadDragProc(WPARAM wParam)
 //             strcpy(Pkt.Cmd, "GOQUIT");\r
 //             AddTransFileList(&Pkt);\r
 \r
+               // バグ対策\r
+               AddNullTransFileList();\r
+\r
                GoForwardTransWindow();\r
 \r
                EnableUserOpe();\r
@@ -1464,7 +1627,7 @@ void MirrorUploadProc(int Notify)
                                                Pkt.Type = AskTransferTypeAssoc(Pkt.LocalFile, AskTransferType());\r
                                                Pkt.Size = 0;\r
                                                Pkt.Time = LocalPos->Time;\r
-                                               Pkt.Attr = AskUpLoadFileAttr(Pkt.RemoteFile);\r
+                                               Pkt.Attr = AskUploadFileAttr(Pkt.RemoteFile);\r
                                                Pkt.KanjiCode = AskHostKanjiCode();\r
                                                // UTF-8対応\r
                                                Pkt.KanjiCodeDesired = AskLocalKanjiCode();\r
@@ -1506,6 +1669,9 @@ void MirrorUploadProc(int Notify)
                        else\r
                                EraseTmpTransFileList(&Base);\r
 \r
+                       // バグ対策\r
+                       AddNullTransFileList();\r
+\r
                        DeleteFileList(&LocalListBase);\r
                        DeleteFileList(&RemoteListBase);\r
 \r
@@ -1837,7 +2003,7 @@ static int AskMirrorNoTrn(char *Fname, int Mode)
 *              int 属性 (-1=設定なし)\r
 *----------------------------------------------------------------------------*/\r
 \r
-static int AskUpLoadFileAttr(char *Fname)\r
+static int AskUploadFileAttr(char *Fname)\r
 {\r
        int Ret;\r
        int Sts;\r
@@ -3527,7 +3693,7 @@ void NoopProc(void)
        CancelCheckWork = NO;\r
        if(AskConnecting() == YES && AskUserOpeDisabled() == NO)\r
        {\r
-               if(AskReuseCmdSkt() == NO || AskShareProh() == YES)\r
+               if(AskReuseCmdSkt() == NO || AskShareProh() == YES || AskTransferNow() == NO)\r
                {\r
                        DisableUserOpe();\r
                        DoDirListCmdSkt("", "", 999, &CancelCheckWork);\r