Revision: 9008 https://osdn.net/projects/ttssh2/scm/svn/commits/9008 Author: zmatsuo Date: 2020-11-02 00:38:17 +0900 (Mon, 02 Nov 2020) Log Message: ----------- 送受信ファイル名変換を行う関数を追加 - 内部ではファイル名はUTF-8 - 送受信ファイル名はANSIまたはUTF-8になると思われる - 送信用ファイル名変換 - GetSendFilename() - 受信用ファイル名変換 - GetRecieveFilename() Modified Paths: -------------- branches/proto_unicode/teraterm/common/ttlib.h branches/proto_unicode/teraterm/common/ttlib_static_cpp.cpp branches/proto_unicode/teraterm/ttpfile/bplus.c branches/proto_unicode/teraterm/ttpfile/filesys_io.h branches/proto_unicode/teraterm/ttpfile/filesys_win32.cpp branches/proto_unicode/teraterm/ttpfile/kermit.c branches/proto_unicode/teraterm/ttpfile/quickvan.c branches/proto_unicode/teraterm/ttpfile/xmodem.c branches/proto_unicode/teraterm/ttpfile/ymodem.c branches/proto_unicode/teraterm/ttpfile/zmodem.c -------------- next part -------------- Modified: branches/proto_unicode/teraterm/common/ttlib.h =================================================================== --- branches/proto_unicode/teraterm/common/ttlib.h 2020-11-01 15:38:00 UTC (rev 9007) +++ branches/proto_unicode/teraterm/common/ttlib.h 2020-11-01 15:38:17 UTC (rev 9008) @@ -42,6 +42,7 @@ #endif BOOL GetFileNamePos(const char *PathName, int *DirLen, int *FNPos); +BOOL GetFileNamePosU8(const char *PathName, int *DirLen, int *FNPos); DllExport BOOL ExtractFileName(PCHAR PathName, PCHAR FileName, int destlen); DllExport BOOL ExtractDirName(PCHAR PathName, PCHAR DirName); void FitFileName(PCHAR FileName, int destlen, const char *DefExt); Modified: branches/proto_unicode/teraterm/common/ttlib_static_cpp.cpp =================================================================== --- branches/proto_unicode/teraterm/common/ttlib_static_cpp.cpp 2020-11-01 15:38:00 UTC (rev 9007) +++ branches/proto_unicode/teraterm/common/ttlib_static_cpp.cpp 2020-11-01 15:38:17 UTC (rev 9008) @@ -625,3 +625,57 @@ } } } + +/** + * \x83t\x83@\x83C\x83\x8B\x96\xBC(\x83p\x83X\x96\xBC)\x82\xF0\x89\xF0\x90͂\xB7\x82\xE9 + * GetFileNamePos() \x82\xCC UTF-8\x94\xC5 + * + * @param[in] PathName \x83t\x83@\x83C\x83\x8B\x96\xBC\x81A\x83t\x83\x8B\x83p\x83X + * @param[out] DirLen \x96\x96\x94\xF6\x82̃X\x83\x89\x83b\x83V\x83\x85\x82\xF0\x8A܂ރf\x83B\x83\x8C\x83N\x83g\x83\x8A\x83p\x83X\x92\xB7 + * NULL\x82̂Ƃ\xAB\x92l\x82\xF0\x95Ԃ\xB3\x82Ȃ\xA2 + * @param[out] FNPos \x83t\x83@\x83C\x83\x8B\x96\xBC\x82ւ\xCCindex + * &PathName[FNPos] \x82\xAA\x83t\x83@\x83C\x83\x8B\x96\xBC + * NULL\x82̂Ƃ\xAB\x92l\x82\xF0\x95Ԃ\xB3\x82Ȃ\xA2 + * @retval FALSE PathName\x82\xAA\x95s\x90\xB3 + */ +BOOL GetFileNamePosU8(const char *PathName, int *DirLen, int *FNPos) +{ + BYTE b; + const char *Ptr; + const char *DirPtr; + const char *FNPtr; + const char *PtrOld; + + if (DirLen != NULL) *DirLen = 0; + if (FNPos != NULL) *FNPos = 0; + + if (PathName==NULL) + return FALSE; + + if ((strlen(PathName)>=2) && (PathName[1]==':')) + Ptr = &PathName[2]; + else + Ptr = PathName; + if (Ptr[0]=='\\' || Ptr[0]=='/') + Ptr++; + + DirPtr = Ptr; + FNPtr = Ptr; + while (Ptr[0]!=0) { + b = Ptr[0]; + PtrOld = Ptr; + Ptr++; + switch (b) { + case ':': + return FALSE; + case '/': /* FALLTHROUGH */ + case '\\': + DirPtr = PtrOld; + FNPtr = Ptr; + break; + } + } + if (DirLen != NULL) *DirLen = DirPtr-PathName; + if (FNPos != NULL) *FNPos = FNPtr-PathName; + return TRUE; +} Modified: branches/proto_unicode/teraterm/ttpfile/bplus.c =================================================================== --- branches/proto_unicode/teraterm/ttpfile/bplus.c 2020-11-01 15:38:00 UTC (rev 9007) +++ branches/proto_unicode/teraterm/ttpfile/bplus.c 2020-11-01 15:38:17 UTC (rev 9008) @@ -579,8 +579,8 @@ BYTE b; // char Temp[HostNameMaxLength + 1]; // 81(yutaka) char Temp[81]; // 81(yutaka) - int FnPos; TFileIO *fileio = fv->file; + char *filename; switch (bv->PktIn[2]) { case 'C': /* Close */ @@ -616,9 +616,10 @@ } Temp[j] = 0; - strncpy_s(fv->FullName, _countof(fv->FullName), fv->RecievePath, _TRUNCATE); - GetFileNamePos(Temp,NULL,&FnPos); - strncat_s(fv->FullName, _countof(fv->FullName), &(Temp[FnPos]), _TRUNCATE); + filename = fileio->GetRecieveFilename(fileio, fv->RecievePath, FALSE, Temp, !fv->OverWrite); + strncpy_s(fv->FullName, _countof(fv->FullName), filename, _TRUNCATE); + free(filename); + /* file open */ if (! FTCreateFile(fv)) { @@ -663,10 +664,9 @@ } Temp[j] = 0; - GetFileNamePos(Temp,NULL,&FnPos); - FitFileName(&(Temp[FnPos]),sizeof(Temp) - FnPos,NULL); - strncpy_s(fv->FullName, _countof(fv->FullName), fv->RecievePath, _TRUNCATE); - strncat_s(fv->FullName, _countof(fv->FullName), &(Temp[FnPos]), _TRUNCATE); + filename = fileio->GetRecieveFilename(fileio, Temp, FALSE, fv->RecievePath, !fv->OverWrite); + strncpy_s(fv->FullName, _countof(fv->FullName), filename, _TRUNCATE); + free(filename); /* file open */ if (! BPOpenFileToBeSent(fv)) Modified: branches/proto_unicode/teraterm/ttpfile/filesys_io.h =================================================================== --- branches/proto_unicode/teraterm/ttpfile/filesys_io.h 2020-11-01 15:38:00 UTC (rev 9007) +++ branches/proto_unicode/teraterm/ttpfile/filesys_io.h 2020-11-01 15:38:17 UTC (rev 9008) @@ -31,6 +31,7 @@ #include <sys/types.h> // for struct utimbuf #include <sys/stat.h> #include <sys/utime.h> +#include <windows.h> // for BOOL typedef struct FileIO { // file I/O, Filename related functions @@ -45,6 +46,9 @@ size_t (*GetFSize)(struct FileIO *fv, const char *filename); int (*utime)(struct FileIO *fv, const char *filename, struct _utimbuf* const _Time); int (*stat)(struct FileIO *fv, const char *filename, struct _stati64* _Stat); + char *(*GetSendFilename)(struct FileIO *fv, const char *fullname, BOOL utf8, BOOL space, BOOL upper); + char *(*GetRecieveFilename)(struct FileIO *fv, const char* filename, BOOL utf8, const char *path, BOOL unique); + long (*GetFMtime)(struct FileIO *fv, const char *fullname); // BOOL (*SetFilenameEncodeUTF8)(struct FileIO *fv, BOOL utf8); // Modified: branches/proto_unicode/teraterm/ttpfile/filesys_win32.cpp =================================================================== --- branches/proto_unicode/teraterm/ttpfile/filesys_win32.cpp 2020-11-01 15:38:00 UTC (rev 9007) +++ branches/proto_unicode/teraterm/ttpfile/filesys_win32.cpp 2020-11-01 15:38:17 UTC (rev 9008) @@ -27,8 +27,10 @@ */ #include <windows.h> +#include <stdio.h> #include <sys/stat.h> #include <sys/utime.h> +#include <assert.h> #include "filesys_io.h" #include "filesys_win32.h" @@ -36,16 +38,17 @@ #include "tttypes.h" #include "layer_for_unicode.h" #include "codeconv.h" +#include "ftlib.h" typedef struct FileIOWin32 { HANDLE FileHandle; - BOOL utf32; + BOOL utf8; } TFileIOWin32; static wc GetFilenameW(TFileIOWin32 *data, const char *filename) { wc filenameW; - if (data->utf32) { + if (data->utf8) { filenameW = wc::fromUtf8(filename); } else { @@ -89,8 +92,9 @@ TFileIOWin32 *data = (TFileIOWin32 *)fv->data; HANDLE hFile = data->FileHandle; DWORD NumberOfBytesRead; - BOOL Result = ReadFile(hFile, buf, (UINT)bytes, &NumberOfBytesRead, NULL); - if (Result == FALSE) { + BOOL result = ReadFile(hFile, buf, (UINT)bytes, &NumberOfBytesRead, NULL); + assert(result != 0); + if (result == 0) { return 0; } return NumberOfBytesRead; @@ -103,7 +107,8 @@ DWORD NumberOfBytesWritten; UINT length = (UINT)bytes; BOOL result = WriteFile(hFile, buf, length, &NumberOfBytesWritten, NULL); - if (result == FALSE) { + assert(result != 0); + if (result == 0) { return 0; } return NumberOfBytesWritten; @@ -170,6 +175,194 @@ return _wutime(filenameW, _Time); } +// replace ' ' by '_' in FName +static void FTConvFName(PCHAR FName) +{ + int i; + + i = 0; + while (FName[i]!=0) + { + if (FName[i]==' ') + FName[i] = '_'; + i++; + } +} + +/** + * \x91\x97\x90M\x97p\x83t\x83@\x83C\x83\x8B\x96\xBC\x8D쐬 + * fullname(fullpath)\x82\xA9\x82\xE7\x83t\x83@\x83C\x83\x8B\x96\xBC\x82\xF0\x8E\xE6\x82\xE8\x8Fo\x82\xB5\x82ĕK\x97v\x82ȕϊ\xB7\x82\xF0\x8Ds\x82\xA4 + * Windows\x83t\x83@\x83C\x83\x8B\x96\xBC\x82\xA9\x82瑗\x90M\x82ɓK\x82\xB5\x82\xBD\x83t\x83@\x83C\x83\x8B\x96\xBC\x82ɕϊ\xB7\x82\xB7\x82\xE9 + * + * @param[in] fullname Tera Term\x82\xAA\x91\x97\x90M\x82\xB7\x82\xE9\x83t\x83@\x83C\x83\x8B UTF8(\x82ƂȂ\xE9\x97\\x92\xE8) + * @param[in] utf8 \x8Fo\x97̓t\x83@\x83C\x83\x8B\x96\xBC\x82̃G\x83\x93\x83R\x81[\x83h + * TRUE\x82̂Ƃ\xAB\x81AUTF-8 + * FALSE\x82̂Ƃ\xAB\x81AANSI + * @retval \x83t\x83@\x83C\x83\x8B\x96\xBC (UTF-8 or ANSI) + * \x95s\x97v\x82ɂȂ\xC1\x82\xBD\x82\xE7 free() \x82\xB7\x82\xE9 + */ +static char *GetSendFilename(TFileIO *fv, const char *fullname, BOOL utf8, BOOL space, BOOL upper) +{ + TFileIOWin32 *data = (TFileIOWin32 *)fv->data; + int FnPos; + char *filename; + if (data->utf8) { + GetFileNamePosU8(fullname, NULL, &FnPos); + if (utf8) { + // UTF8 -> UTF8 + filename = _strdup(fullname + FnPos); + } + else { + // UTF8 -> ANSI + filename = ToCharU8(fullname + FnPos); + } + } + else { + GetFileNamePos(fullname, NULL, &FnPos); + if (utf8) { + // ANSI -> UTF8 + filename = ToU8A(fullname + FnPos); + } + else { + // ANSI -> ANSI + filename = _strdup(fullname + FnPos); + } + } + if (space) { + // replace ' ' by '_' in filename + FTConvFName(filename); + } + if (upper) { + _strupr(filename); + } + return filename; +} + +static char *CreateFilenameWithNumber(const char *fullpath, int n) +{ + int FnPos; + char Num[11]; + + size_t len = strlen(fullpath) + sizeof(Num); + char *new_name = (char *)malloc(len); + +// GetFileNamePos(fullpath, NULL, &FnPos); + GetFileNamePosU8(fullpath, NULL, &FnPos); + + _snprintf_s(Num,sizeof(Num),_TRUNCATE,"%u",n); + size_t num_len = strlen(Num); + + const char *filename = &fullpath[FnPos]; + size_t filename_len = strlen(filename); + const char *ext = strrchr(filename, '.'); + if (ext == NULL) { + // \x8Ag\x92\xA3\x8Eq\x82Ȃ\xB5 + char *d = new_name; + memcpy(d, fullpath, FnPos + filename_len); + d += FnPos + filename_len; + memcpy(d, Num, num_len); + d += num_len; + *d = 0; + } + else { + // \x8Ag\x92\xA3\x8Eq\x82\xA0\x82\xE8 + size_t ext_len = strlen(ext); + size_t base_len = filename_len - ext_len; + + char *d = new_name; + memcpy(d, fullpath, FnPos + base_len); + d += FnPos + base_len; + memcpy(d, Num, num_len); + d += num_len; + memcpy(d, ext, ext_len); + d += ext_len; + *d = 0; + } + return new_name; +} + +static char *CreateUniqueFilename(const char *fullpath) +{ + int i = 1; + while(1) { + char *filename = CreateFilenameWithNumber(fullpath, i); + if (!DoesFileExist(filename)) { + return filename; + } + free(filename); + i++; + } +} + +/** + * \x8E\xF3\x90M\x97p\x83t\x83@\x83C\x83\x8B\x96\xBC\x8D쐬 + * fullname\x82\xA9\x82\xE7\x95K\x97v\x82ȕϊ\xB7\x82\xF0\x8Ds\x82\xA4 + * \x91\x97\x82\xE7\x82\xEA\x82Ă\xAB\x82\xBD\x83t\x83@\x83C\x83\x8B\x96\xBC\x82\xAAANSI\x82\xA9UTF8\x82\xA9\x82\xCD + * \x92ʐM\x90\xE6\x82\xE2\x83v\x83\x8D\x83g\x83R\x83\x8B\x82ɂ\xE6\x82\xE9\x82Ǝv\x82\xED\x82\xEA\x82\xE9 + * \x8E\xF3\x90M\x82\xB5\x82\xBD\x83t\x83@\x83C\x83\x8B\x96\xBC\x82\xA9\x82\xE7Windows\x82ɓK\x82\xB5\x82\xBD\x83t\x83@\x83C\x83\x8B\x96\xBC\x82ɕϊ\xB7\x82\xB7\x82\xE9 + * + * @param[in] filename \x92ʐM\x82ő\x97\x82\xE7\x82\xEA\x82Ă\xAB\x82\xBD\x83t\x83@\x83C\x83\x8B\x96\xBC, \x93\xFC\x97̓t\x83@\x83C\x83\x8B\x96\xBC + * @param[in] utf8 \x93\xFC\x97̓t\x83@\x83C\x83\x8B\x96\xBC\x82̃G\x83\x93\x83R\x81[\x83h + * TRUE\x82̂Ƃ\xAB\x81AUTF-8 + * FALSE\x82̂Ƃ\xAB\x81AANSI + * @param[in] path \x8E\xF3\x90M\x83t\x83H\x83\x8B\x83_ \x83t\x83@\x83C\x83\x8B\x96\xBC\x82̑O\x82ɕt\x89\xC1\x82\xB3\x82\xEA\x82\xE9 UTF-8 + * NULL\x82̂Ƃ\xAB\x95t\x89\xC1\x82\xB3\x82\xEA\x82Ȃ\xA2 + * @param[in] unique TRUE\x82̂Ƃ\xAB + * \x83t\x83@\x83C\x83\x8B\x82\xAA\x91\xB6\x8D݂\xB5\x82\xBD\x82Ƃ\xAB\x83t\x83@\x83C\x83\x8B\x96\xBC\x82̌\xE3\x82\xEB\x82ɐ\x94\x8E\x9A\x82\xF0\x92lj\xC1\x82\xB7\x82\xE9 + * @retval \x83t\x83@\x83C\x83\x8B\x96\xBC UTF-8 + * \x95s\x97v\x82ɂȂ\xC1\x82\xBD\x82\xE7 free() \x82\xB7\x82\xE9 + */ +static char* GetRecieveFilename(struct FileIO* fv, const char* filename, BOOL utf8, const char *path, BOOL unique) +{ + char* new_name; + if (utf8) { + // UTF8 -> UTF8 + int FnPos; + GetFileNamePosU8(filename, NULL, &FnPos); + new_name = _strdup(&filename[FnPos]); + } + else { + // ANSI -> UTF8 + int FnPos; + GetFileNamePos(filename, NULL, &FnPos); + new_name = ToU8A(&filename[FnPos]); + } + size_t len = strlen(new_name) + 1; + FitFileName(new_name, len, NULL); + replaceInvalidFileNameChar(new_name, '_'); + + // to fullpath + char *full; + if (path == NULL) { + full = new_name; + } + else { + size_t full_len = len + strlen(path); + full = (char *)malloc(full_len); + strcpy(full, path); + strcat(full, new_name); + } + + // to unique + if (unique) { + char *filename = CreateUniqueFilename(full); + free(full); + full = filename; + } + + return full; +} + +static long GetFMtime(TFileIO *fv, const char *FName) +{ + struct _stat st; + + if (_stat(FName,&st)==-1) { + return 0; + } + return (long)st.st_mtime; +} + static void FileSysDestroy(TFileIO *fv) { TFileIOWin32 *data = (TFileIOWin32 *)fv->data; @@ -186,7 +379,7 @@ return NULL; } data->FileHandle = INVALID_HANDLE_VALUE; - data->utf32 = FALSE; + data->utf8 = TRUE; TFileIO *fv = (TFileIO *)calloc(sizeof(TFileIO), 1); if (fv == NULL) { free(data); @@ -203,5 +396,8 @@ fv->utime = __utime; fv->stat = __stat; fv->FileSysDestroy = FileSysDestroy; + fv->GetSendFilename = GetSendFilename; + fv->GetRecieveFilename = GetRecieveFilename; + fv->GetFMtime = GetFMtime; return fv; } Modified: branches/proto_unicode/teraterm/ttpfile/kermit.c =================================================================== --- branches/proto_unicode/teraterm/ttpfile/kermit.c 2020-11-01 15:38:00 UTC (rev 9007) +++ branches/proto_unicode/teraterm/ttpfile/kermit.c 2020-11-01 15:38:17 UTC (rev 9008) @@ -1048,7 +1048,7 @@ TFileIO *file = fv->file; struct _stati64 st; BOOL r; - int FnPos; + char *filename; if (! GetNextFname(fv)) { @@ -1094,12 +1094,12 @@ SetDlgTime(fv->HWin, IDC_PROTOELAPSEDTIME, fv->StartTime, fv->ByteCount); KmtIncPacketNum(kv); - GetFileNamePos(fv->FullName, NULL, &FnPos); - strncpy_s(&(kv->PktOut[4]),sizeof(kv->PktOut)-4,&(fv->FullName[FnPos]),_TRUNCATE); // put FName - FTConvFName(&(kv->PktOut[4])); // replace ' ' by '_' in FName + filename = file->GetSendFilename(file, kv->FullName, FALSE, TRUE, FALSE); + strncpy_s(&(kv->PktOut[4]),sizeof(kv->PktOut)-4, filename,_TRUNCATE); // put FName KmtMakePacket(fv,kv,(BYTE)(kv->PktNum-kv->PktNumOffset),(BYTE)'F', - strlen(&(fv->FullName[FnPos]))); + strlen(filename)); KmtSendPacket(fv,kv,cv); + free(filename); kv->RepeatCount = 0; kv->NextByteFlag = FALSE; @@ -1150,19 +1150,23 @@ static void KmtSendReceiveInit(PFileVarProto fv, PKmtVar kv, PComVar cv) { - int FnPos; + TFileIO *file = fv->file; + char *filename; + const size_t filename_len_max = kv->KmtYour.MAXL - kv->KmtMy.CHKT - 4; + kv->PktNum = 0; kv->PktNumOffset = 0; - GetFileNamePos(fv->FullName, NULL, &FnPos); - if ((signed int)strlen(&(fv->FullName[FnPos])) >= - kv->KmtYour.MAXL - kv->KmtMy.CHKT - 4) - fv->FullName[FnPos +kv->KmtYour.MAXL-kv->KmtMy.CHKT-4] = 0; + filename = file->GetRecieveFilename(file, fv->FullName, FALSE, NULL, FALSE); + if (strlen(filename) >= filename_len_max) { + filename[filename_len_max] = 0; + } - strncpy_s(&(kv->PktOut[4]),sizeof(kv->PktOut)-4,&(fv->FullName[FnPos]),_TRUNCATE); + strncpy_s(&(kv->PktOut[4]),sizeof(kv->PktOut)-4,filename,_TRUNCATE); KmtMakePacket(fv,kv,(BYTE)(kv->PktNum-kv->PktNumOffset),(BYTE)'R', - strlen(&(fv->FullName[FnPos]))); + strlen(filename)); KmtSendPacket(fv,kv,cv); + free(filename); kv->KmtState = GetInit; } @@ -1431,15 +1435,16 @@ if ((kv->KmtState==ReceiveFile) || (kv->KmtState==GetInit)) { - int FnPos; + TFileIO *file = fv->file; + char *filename; kv->KmtMode = IdKmtReceive; Len = sizeof(FNBuff); KmtDecode(fv,kv,FNBuff,&Len); FNBuff[Len] = 0; - GetFileNamePos(FNBuff,NULL,&FnPos); - strncpy_s(fv->FullName, _countof(fv->FullName), fv->RecievePath, _TRUNCATE); - strncat_s(fv->FullName, _countof(fv->FullName), &FNBuff[FnPos], _TRUNCATE); + filename = file->GetRecieveFilename(file, FNBuff, FALSE, fv->RecievePath, !fv->OverWrite); + strncpy_s(fv->FullName, _countof(fv->FullName), filename, _TRUNCATE); + free(filename); /* file open */ if (! FTCreateFile(fv)) return FALSE; kv->KmtState = ReceiveData; Modified: branches/proto_unicode/teraterm/ttpfile/quickvan.c =================================================================== --- branches/proto_unicode/teraterm/ttpfile/quickvan.c 2020-11-01 15:38:00 UTC (rev 9007) +++ branches/proto_unicode/teraterm/ttpfile/quickvan.c 2020-11-01 15:38:17 UTC (rev 9008) @@ -418,9 +418,11 @@ static BOOL QVParseVFILE(PFileVarProto fv, PQVVar qv) { - int i, j; + TFileIO *file = fv->file; + int i; WORD w; BYTE b; + char *filename; if ((qv->QVState != QV_RecvInit2) && (qv->QVState != QV_RecvNext)) @@ -427,9 +429,9 @@ return TRUE; /* file name */ - GetFileNamePos(&(qv->PktIn[5]),&i,&j); - strncpy_s(fv->FullName, _countof(fv->FullName), fv->RecievePath, _TRUNCATE); - strncat_s(fv->FullName, _countof(fv->FullName), &(qv->PktIn[5+j]), _TRUNCATE); + filename = file->GetRecieveFilename(file, &(qv->PktIn[5]), FALSE, fv->RecievePath, !fv->OverWrite); + strncpy_s(fv->FullName, _countof(fv->FullName), filename, _TRUNCATE); + free(filename); /* file open */ if (! FTCreateFile(fv)) return FALSE; /* file size */ @@ -828,10 +830,9 @@ int i, j; struct stat stbuf; struct tm tmbuf; - char fullname_upper[MAX_PATH]; BOOL r; - int FnPos; TFileIO *file = fv->file; + char *filename; if (! GetNextFname(fv)) { @@ -867,15 +868,13 @@ i = 3; QVPutNum2(qv,qv->FileNum,&i); /* file name */ - fv->SetDlgProtoFileName(fv, fv->FullName); - GetFileNamePos(fv->FullName, NULL, &FnPos); - strncpy_s(fullname_upper, _countof(fullname_upper), &(fv->FullName[FnPos]), _TRUNCATE); - _strupr_s(fullname_upper, sizeof(fullname_upper)); - FTConvFName(fullname_upper); // replace ' ' by '_' in FName - strncpy_s(&(qv->PktOut[i]),sizeof(qv->PktOut)-i,fullname_upper,_TRUNCATE); + fv->SetDlgProtoFileName(fv, qv->FullName); + filename = file->GetSendFilename(file, qv->FullName, FALSE, TRUE, TRUE); + strncpy_s(&(qv->PktOut[i]),sizeof(qv->PktOut)-i,filename,_TRUNCATE); i = strlen(&(qv->PktOut[i])) + i; qv->PktOut[i] = 0; i++; + free(filename); /* file size */ _snprintf_s(&(qv->PktOut[i]),sizeof(qv->PktOut)-i,_TRUNCATE,"%u",fv->FileSize); i = strlen(&(qv->PktOut[i])) + i; Modified: branches/proto_unicode/teraterm/ttpfile/xmodem.c =================================================================== --- branches/proto_unicode/teraterm/ttpfile/xmodem.c 2020-11-01 15:38:00 UTC (rev 9007) +++ branches/proto_unicode/teraterm/ttpfile/xmodem.c 2020-11-01 15:38:17 UTC (rev 9008) @@ -281,13 +281,13 @@ // \x83t\x83@\x83C\x83\x8B\x91\x97\x90M\x8AJ\x8En\x91O\x82ɁA"rx \x83t\x83@\x83C\x83\x8B\x96\xBC"\x82\xF0\x8E\xA9\x93\xAE\x93I\x82ɌĂяo\x82\xB7\x81B(2007.12.20 yutaka) if (ts->XModemRcvCommand[0] != '\0') { + TFileIO *file = fv->file; char inistr[MAX_PATH + 10]; - int i, j; - GetFileNamePos(fv->FullName,&i,&j); + char *filename = file->GetSendFilename(file, xv->FullName, FALSE, TRUE, FALSE); _snprintf_s(inistr, sizeof(inistr), _TRUNCATE, "%s %s\015", - ts->XModemRcvCommand, &(fv->FullName[j])); - FTConvFName(inistr + strlen(ts->XModemRcvCommand) + 1); + ts->XModemRcvCommand, filename); XWrite(fv, xv, cv, inistr, strlen(inistr)); + free(filename); } FTSetTimeOut(fv, xv->TOutVLong); Modified: branches/proto_unicode/teraterm/ttpfile/ymodem.c =================================================================== --- branches/proto_unicode/teraterm/ttpfile/ymodem.c 2020-11-01 15:38:00 UTC (rev 9007) +++ branches/proto_unicode/teraterm/ttpfile/ymodem.c 2020-11-01 15:38:17 UTC (rev 9008) @@ -618,6 +618,7 @@ int ret; BYTE *p; char *name, *nameend; + char *filename; p = (BYTE *)malloc(yv->__DataLen + 1); memset(p, 0, yv->__DataLen + 1); @@ -624,8 +625,9 @@ memcpy(p, &(yv->PktIn[3]), yv->__DataLen); name = p; - strncpy_s(fv->FullName, _countof(fv->FullName), fv->RecievePath, _TRUNCATE); - strncat_s(fv->FullName, _countof(fv->FullName), name, _TRUNCATE); + filename = file->GetRecieveFilename(file, name, FALSE, fv->RecievePath, !fv->OverWrite); + strncpy_s(fv->FullName, _countof(fv->FullName), filename, _TRUNCATE); + free(filename); if (!FTCreateFile(fv)) { free(p); return FALSE; @@ -906,7 +908,8 @@ size_t idx; // TODO: remove magic number. BYTE buf[1024 + 10]; - int FnPos; + TFileIO *file = fv->file; + char *filename; // 128 bytes for the first packet. current_packet_size = SOH_DATALEN; @@ -914,10 +917,11 @@ yv->PktOut[0] = SOH; // Timestamp. - fv->FileMtime = GetFMtime(fv->FullName); + fv->FileMtime = file->GetFMtime(file, fv->FullName); - GetFileNamePos(fv->FullName, NULL, &FnPos); - ret = _snprintf_s(buf, sizeof(buf), _TRUNCATE, "%s", &(fv->FullName[FnPos])); + filename = file->GetSendFilename(file, yv->FullName, FALSE, FALSE, FALSE); + ret = _snprintf_s(buf, sizeof(buf), _TRUNCATE, "%s", filename); + free(filename); // NULL-terminated string. buf[ret] = 0x00; Modified: branches/proto_unicode/teraterm/ttpfile/zmodem.c =================================================================== --- branches/proto_unicode/teraterm/ttpfile/zmodem.c 2020-11-01 15:38:00 UTC (rev 9007) +++ branches/proto_unicode/teraterm/ttpfile/zmodem.c 2020-11-01 15:38:17 UTC (rev 9008) @@ -560,8 +560,8 @@ static void ZSendFileDat(PFileVarProto fv, PZVar zv) { int i, j; - int FNPos; TFileIO *file = fv->file; + char *filename; if (!fv->FileOpen) { ZSendCancel(zv); @@ -570,9 +570,8 @@ SetDlgItemText(fv->HWin, IDC_PROTOFNAME, fv->FullName); /* file name */ - GetFileNamePos(fv->FullName, NULL, &FNPos); - strncpy_s(zv->PktOut, sizeof(zv->PktOut), &(fv->FullName[FNPos]), _TRUNCATE); - FTConvFName(zv->PktOut); // replace ' ' by '_' in FName + filename = file->GetSendFilename(file, zv->FullName, FALSE, TRUE, FALSE); + strncpy_s(zv->PktOut, sizeof(zv->PktOut), filename, _TRUNCATE); zv->PktOutCount = strlen(zv->PktOut); zv->CRC = 0; for (i = 0; i <= zv->PktOutCount - 1; i++) @@ -622,7 +621,8 @@ add_sendbuf("%s: ZFILE: ZF0=%x ZF1=%x ZF2=%x file=%s size=%lu", __FUNCTION__, zv->TxHdr[ZF0], zv->TxHdr[ZF1],zv->TxHdr[ZF2], - &(fv->FullName[FNPos]), fv->FileSize); + filename, fv->FileSize); + free(filename); } static void ZSendDataHdr(PZVar zv) @@ -1046,7 +1046,8 @@ long modtime; int mode; int ret; - int FnPos; + TFileIO* file = fv->file; + char *filename; if ((zv->ZState != Z_RecvInit) && (zv->ZState != Z_RecvInit2)) return FALSE; @@ -1057,9 +1058,9 @@ /* file name */ zv->PktIn[zv->PktInPtr] = 0; /* for safety */ - GetFileNamePos(zv->PktIn, NULL, &FnPos); - strncpy_s(fv->FullName, _countof(fv->FullName), fv->RecievePath, _TRUNCATE); - strncat_s(fv->FullName, _countof(fv->FullName), &(zv->PktIn[FnPos]), _TRUNCATE); + filename = file->GetRecieveFilename(file, zv->PktIn, FALSE, fv->RecievePath, !fv->OverWrite); + strncpy_s(fv->FullName, _countof(fv->FullName), filename, _TRUNCATE); + free(filename); /* file open */ if (!FTCreateFile(fv)) return FALSE;