/* TMPMIX.CPP Temporary panel miscellaneous utility functions */ #include "TmpPanel.hpp" const TCHAR *GetMsg(int MsgId) { return(Info.GetMsg(Info.ModuleNumber,MsgId)); } void InitDialogItems(const MyInitDialogItem *Init,struct FarDialogItem *Item, int ItemsNumber) { int i; struct FarDialogItem *PItem=Item; const MyInitDialogItem *PInit=Init; for (i=0;iType=PInit->Type; PItem->X1=PInit->X1; PItem->Y1=PInit->Y1; PItem->X2=PInit->X2; PItem->Y2=PInit->Y2; PItem->Flags=PInit->Flags; PItem->Focus=0; PItem->History=0; PItem->DefaultButton=0; #ifdef UNICODE PItem->MaxLen=0; #endif #ifndef UNICODE lstrcpy(PItem->Data,PInit->Data!=-1 ? GetMsg(PInit->Data) : ""); #else PItem->PtrData = PInit->Data!=-1 ? GetMsg(PInit->Data) : L""; #endif } } void FreePanelItems(PluginPanelItem *Items, DWORD Total) { if(Items){ for (DWORD I=0;I(Target)); StrBuf Name(lstrlen(p)+1); lstrcpy(Name,p); pathlen=(int)(p-Target); StrBuf Dir(pathlen+1); if (pathlen) memcpy(Dir.Ptr(),Target,pathlen*sizeof(TCHAR)); Dir[pathlen]=_T('\0'); FSF.Trim(Name); FSF.Trim(Dir); FSF.Unquote(Name); FSF.Unquote(Dir); if (*Dir.Ptr()) { #ifndef UNICODE Info.Control(_PANEL_HANDLE,FCTL_SetPanelDir,Dir.Ptr()); #else Info.Control(_PANEL_HANDLE,FCTL_SetPanelDir,0,(LONG_PTR)Dir.Ptr()); #endif } #ifndef UNICODE Info.Control(_PANEL_HANDLE,FCTL_GetPanelInfo,&PInfo); #else Info.Control(_PANEL_HANDLE,FCTL_GetPanelInfo,0,(LONG_PTR)&PInfo); #endif PRI.CurrentItem=PInfo.CurrentItem; PRI.TopPanelItem=PInfo.TopPanelItem; for(int J=0; J < PInfo.ItemsNumber; J++) { #ifndef UNICODE #define FileName PInfo.PanelItems[J].FindData.cFileName #else #define FileName (PPI?PPI->FindData.lpwszFileName:NULL) PluginPanelItem* PPI=(PluginPanelItem*)malloc(Info.Control(_PANEL_HANDLE,FCTL_GETPANELITEM,J,0)); if(PPI) { Info.Control(_PANEL_HANDLE,FCTL_GETPANELITEM,J,(LONG_PTR)PPI); } #endif if(!FSF.LStricmp(Name,FSF.PointToName(FileName))) #undef FileName { PRI.CurrentItem=J; PRI.TopPanelItem=J; #ifdef UNICODE free(PPI); #endif break; } #ifdef UNICODE free(PPI); #endif } #ifndef UNICODE Info.Control(_PANEL_HANDLE,FCTL_RedrawPanel,&PRI); #else Info.Control(_PANEL_HANDLE,FCTL_RedrawPanel,0,(LONG_PTR)&PRI); #endif #undef _PANEL_HANDLE #undef FCTL_SetPanelDir #undef FCTL_GetPanelInfo #undef FCTL_RedrawPanel } void WFD2FFD(WIN32_FIND_DATA &wfd, FAR_FIND_DATA &ffd) { ffd.dwFileAttributes=wfd.dwFileAttributes; ffd.ftCreationTime=wfd.ftCreationTime; ffd.ftLastAccessTime=wfd.ftLastAccessTime; ffd.ftLastWriteTime=wfd.ftLastWriteTime; #ifndef UNICODE ffd.nFileSizeHigh=wfd.nFileSizeHigh; ffd.nFileSizeLow=wfd.nFileSizeLow; #else ffd.nFileSize = wfd.nFileSizeHigh; ffd.nFileSize <<= 32; ffd.nFileSize |= wfd.nFileSizeLow; #endif #ifndef UNICODE ffd.dwReserved0=wfd.dwReserved0; ffd.dwReserved1=wfd.dwReserved1; #else ffd.nPackSize = 0; #endif #ifndef UNICODE lstrcpy(ffd.cFileName,wfd.cFileName); *ffd.cAlternateFileName = 0; #else ffd.lpwszFileName = wcsdup(wfd.cFileName); ffd.lpwszAlternateFileName = NULL; #endif } #ifdef UNICODE wchar_t* FormNtPath(const wchar_t* path, StrBuf& buf) { int l = lstrlen(path); if (l > 4 && path[0] == L'\\' && path[1] == L'\\') { if ((path[2] == L'?' || path[2] == L'.') && path[3] == L'\\') { buf.Grow(l + 1); lstrcpy(buf, path); } else { buf.Grow(6 + l + 1); lstrcpy(buf, L"\\\\?\\UNC\\"); lstrcat(buf, path + 2); } } else { buf.Grow(4 + l + 1); lstrcpy(buf, L"\\\\?\\"); lstrcat(buf, path); } // slash -> backslash for (wchar_t* ch = buf; *ch; ch++) if (*ch == L'/') *ch = L'\\'; return buf; } #endif TCHAR* ExpandEnvStrs(const TCHAR* input, StrBuf& output) { #ifdef UNICODE output.Grow(NT_MAX_PATH); int size = ExpandEnvironmentStrings(input, output, output.Size()); if (size > output.Size()) { output.Grow(size); size = ExpandEnvironmentStrings(input, output, output.Size()); } if ((size == 0) || (size > output.Size())) { output.Grow(lstrlen(input) + 1); lstrcpy(output, input); } #else output.Grow(MAX_PATH); FSF.ExpandEnvironmentStr(input, output, output.Size()); #endif return output; } bool FindListFile(const TCHAR *FileName, StrBuf &output) { StrBuf Path; DWORD dwSize; #ifdef UNICODE StrBuf FullPath; GetFullPath(FileName, FullPath); StrBuf NtPath; FormNtPath(FullPath, NtPath); #else const char* FullPath = FileName; const char* NtPath = FileName; #endif const TCHAR *final=NULL; if (GetFileAttributes(NtPath) != INVALID_FILE_ATTRIBUTES) { #ifdef UNICODE output.Grow(FullPath.Size()); #else output.Grow(lstrlen(FullPath)+1); #endif lstrcpy(output, FullPath); return true; } { const TCHAR *tmp = FSF.PointToName(Info.ModuleName); Path.Grow((int)(tmp-Info.ModuleName+1)); lstrcpyn(Path,Info.ModuleName,(int)(tmp-Info.ModuleName+1)); dwSize=SearchPath(Path,FileName,NULL,0,NULL,NULL); if (dwSize) { final = Path; goto success; } } ExpandEnvStrs(_T("%FARHOME%;%PATH%"),Path); for (TCHAR *str=Path, *p=_tcschr(Path,_T(';')); *str; p=_tcschr(str,_T(';'))) { if (p) *p = 0; FSF.Unquote(str); FSF.Trim(str); if (*str) { dwSize=SearchPath(str,FileName,NULL,0,NULL,NULL); if (dwSize) { final = str; goto success; } } if (p) str = p+1; else break; } return false; success: output.Grow(dwSize); SearchPath(final,FileName,NULL,dwSize,output,NULL); return true; } #ifdef UNICODE wchar_t* GetFullPath(const wchar_t* input, StrBuf& output) { output.Grow(MAX_PATH); int size = FSF.ConvertPath(CPM_FULL, input, output, output.Size()); if (size > output.Size()) { output.Grow(size); FSF.ConvertPath(CPM_FULL, input, output, output.Size()); } return output; } #endif