CString QuoteSpaces(const CString& FilePathName, const int QuoteMode) { CString result = FilePathName; if ((2==QuoteMode) || (CountChars(FilePathName,' ')>0)) { result = QuoteStr(FilePathName); } return result; }
CString JoinPaths(const CString& HeadPath, const CString& TailPath, const char Separator) { CString head_path, tail_path; bool head_quoted = IsQuoted(HeadPath); bool tail_quoted = IsQuoted(TailPath); bool quote_path = head_quoted&&tail_quoted; if (quote_path) head_path = UnquoteStr(HeadPath); else head_path = HeadPath; if (quote_path) tail_path = UnquoteStr(TailPath); else tail_path = TailPath; CString result = head_path; if (!head_path.IsEmpty() && !tail_path.IsEmpty()) { result = CheckLastChar(head_path,Separator); } result += tail_path; if (quote_path) result = QuoteStr(result); return result; }
void FTP::SaveList(FP_SizeItemList* il) { LPCSTR m; if((m=GetOtherPath(Opt.sli.path)) != NULL) { SayOutError(m); return; } strcat(Opt.sli.path,"ftplist.lst"); if(!AskSaveList(&Opt.sli)) return; FILE *f = fopen(Opt.sli.path, Opt.sli.Append ? "a" : "w"); if(!f) { SayOutError(FMSG(MFLErrCReate),FMSG_ERRORTYPE); return; } PluginPanelItem* p; int n; int level; char str[1024+2], BasePath[1024+2], CurrentUrlPath[1024+2]; CurrentUrlPath[0] = 0; _snprintf(BasePath, ARRAYSIZE(BasePath), "%s%s%s%s", Opt.sli.AddPrefix ? "ftp://" : "", Opt.sli.AddPasswordAndUser ? Message("%s:%s@",hConnect->UserName,hConnect->UserPassword) : "", hConnect->hostname, hConnect->CurDir.c_str()); AddEndSlash(BasePath,'/',ARRAYSIZE(BasePath)); if(Opt.sli.ListType == sltTree) fprintf(f,"BASE: \"%s\"\n",BasePath); for(n = 0; n < il->Count(); n++) { p = il->Item(n); if(p->FindData.dwReserved1 == MAX_DWORD) continue; //URLS -------------------------------------- if(Opt.sli.ListType == sltUrlList) { if(IS_FLAG(p->FindData.dwFileAttributes,FILE_ATTRIBUTE_DIRECTORY)) continue; FixFTPSlash(FTP_FILENAME(p)); _snprintf(str,ARRAYSIZE(str),"%s%s",BasePath,FTP_FILENAME(p)); if(Opt.sli.Quote) QuoteStr(str); fprintf(f,"%s\n",str); } else //TREE -------------------------------------- if(Opt.sli.ListType == sltTree) { StrCpy(str, FTP_FILENAME(p), ARRAYSIZE(str)); FixFTPSlash(str); for(m = str,level = 0; (m=strchr(m,'/')) != NULL; m++,level++); fprintf(f,"%*c", level*2+2, ' '); m = strrchr(str,'/'); if(m) m++; else m = str; fprintf(f,"%c%s", IS_FLAG(p->FindData.dwFileAttributes,FILE_ATTRIBUTE_DIRECTORY) ? '/' : ' ', m); if(Opt.sli.Size) { level = Max(1, Opt.sli.RightBound - 10 - level*2 - 2 - 1 - (int)strlen(m)); fprintf(f,"%*c",level,' '); if(IS_FLAG(p->FindData.dwFileAttributes,FILE_ATTRIBUTE_DIRECTORY)) fprintf(f,"<DIR>"); else fprintf(f,"%10I64u", ((__int64)p->FindData.nFileSizeHigh) << 32 | p->FindData.nFileSizeLow); } fprintf(f,"\n"); } else //GROUPS ------------------------------------ if(Opt.sli.ListType == sltGroup) { if(IS_FLAG(p->FindData.dwFileAttributes,FILE_ATTRIBUTE_DIRECTORY)) continue; FixFTPSlash(FTP_FILENAME(p)); _snprintf(str, ARRAYSIZE(str), "%s%s", BasePath, FTP_FILENAME(p)); if(!IS_FLAG(p->FindData.dwFileAttributes,FILE_ATTRIBUTE_DIRECTORY)) *strrchr(str,'/') = 0; if(StrCmp(CurrentUrlPath,str,-1,FALSE) != 0) { StrCpy(CurrentUrlPath, str, ARRAYSIZE(CurrentUrlPath)); fprintf(f,"\n[%s]\n", CurrentUrlPath); } StrCpy(str, FTP_FILENAME(p), ARRAYSIZE(str)); FixFTPSlash(str); m = strrchr(str,'/'); if(m) m++; else m = str; fprintf(f," %s", m); if(Opt.sli.Size) { level = Max(1, Opt.sli.RightBound - 10 - (int)strlen(m) - 1); fprintf(f,"%*c%10I64u", level,' ', ((__int64)p->FindData.nFileSizeHigh) << 32 | p->FindData.nFileSizeLow); } fprintf(f,"\n"); } } fclose(f); LPCSTR itms[] = { FMSG(MFLDoneTitle), FMSG(MFLFile), Opt.sli.path, FMSG(MFLDone), FMSG(MOk) }; FMessage(FMSG_LEFTALIGN,NULL,itms,5,1); }