Compare commits

...
12 changed files with 373 additions and 25 deletions

No files matched your search

+8
View File
@@ -258,6 +258,14 @@ Warning і початковий фокус на No.
рядок. Команда з меню оновлює панель і зберігає папку, курсор та
актуальні позначки. Для LAN, FTP, SFTP, UNC та архівів контекстне меню
показує доступні команди Files.
- **Ctrl+A** або **F9 → Files → Properties** показує властивості поточного
файла чи папки. У локальній панелі можна змінити прапорці **Read-only**,
**Hidden**, **System**, **Archive** та **Not indexed**. **Save** застосовує
лише змінені прапорці й перечитує панель. Помилка Windows з’являється
окремим повідомленням. Прапорці папки застосовуються лише до самої папки.
У LAN, FTP, SFTP, UNC та архіві команда **Properties** також є в
контекстному меню й показує доступні метадані без редагування.
Для SFTP власник відображається як числовий UID, якщо сервер його надає.
- **F8 Delete** у нижньому рядку клавіш викликає той самий діалог видалення,
що й клавіша F8.
- У нижньому рядку, як у FAR, позначення клавіш сірі на чорному тлі,
+22
View File
@@ -588,3 +588,25 @@ BEGIN
CONTROL "&Save", IDOK, "Button", BS_OWNERDRAW | WS_TABSTOP, 270, 183, 60, 17
CONTROL "&Cancel", IDCANCEL, "Button", BS_OWNERDRAW | WS_TABSTOP, 336, 183, 67, 17
END
125 DIALOGEX 0, 0, 360, 178
STYLE DS_SETFONT | DS_CENTER | WS_POPUP
CAPTION "Properties"
FONT 10, "Consolas"
BEGIN
LTEXT "", 580, 16, 15, 328, 13, SS_ENDELLIPSIS | SS_NOPREFIX
LTEXT "", 581, 16, 32, 328, 12, SS_ENDELLIPSIS | SS_NOPREFIX
LTEXT "", 582, 16, 45, 328, 12, SS_ENDELLIPSIS | SS_NOPREFIX
LTEXT "", 583, 16, 58, 328, 12, SS_ENDELLIPSIS | SS_NOPREFIX
LTEXT "", 584, 16, 71, 328, 12, SS_ENDELLIPSIS | SS_NOPREFIX
LTEXT "", 585, 16, 84, 328, 12, SS_ENDELLIPSIS | SS_NOPREFIX
LTEXT "", 586, 16, 99, 328, 12, SS_ENDELLIPSIS | SS_NOPREFIX
AUTOCHECKBOX "&Read-only", 587, 16, 114, 106, 13
AUTOCHECKBOX "&Hidden", 588, 128, 114, 106, 13
AUTOCHECKBOX "S&ystem", 589, 240, 114, 104, 13
AUTOCHECKBOX "&Archive", 590, 16, 128, 106, 13
AUTOCHECKBOX "Not &indexed", 591, 128, 128, 106, 13
LTEXT "", 592, 10, 146, 1, 1, NOT WS_VISIBLE
CONTROL "&Save", IDOK, "Button", BS_OWNERDRAW | WS_TABSTOP, 95, 153, 80, 17
CONTROL "&Cancel", IDCANCEL, "Button", BS_OWNERDRAW | WS_TABSTOP, 185, 153, 80, 17
END
+17 -7
View File
@@ -37,6 +37,13 @@ constexpr std::int64_t archiveEpochOffset=11644473600, archiveTicksPerSecond=100
constexpr char unsafePath[]="The archive contains an unsafe or conflicting path.";
constexpr char encryptedArchive[]="This archive requires a password. Password-protected entries cannot be opened in Files.";
uint64_t archiveTime(bool present,int64_t seconds,long nanos)
{
if(!present || seconds < -archiveEpochOffset || seconds>=INT64_MAX/archiveTicksPerSecond-archiveEpochOffset)
return 0;
return static_cast<uint64_t>((seconds+archiveEpochOffset)*archiveTicksPerSecond+nanos/100);
}
struct ArchiveFileHandle
{
HANDLE value=INVALID_HANDLE_VALUE;
@@ -100,11 +107,15 @@ std::pair<fs::path,ArchiveEntry> decodeEntry(archive_entry *entry)
const auto size=archive_entry_size(entry);
if(size<0 || (!folder && !archive_entry_size_is_set(entry)))
throw std::runtime_error("The archive entry has an invalid size.");
const int64_t seconds=archive_entry_mtime(entry);
const auto modified=archive_entry_mtime_is_set(entry) && seconds>=-archiveEpochOffset &&
seconds<(INT64_MAX/archiveTicksPerSecond-archiveEpochOffset)?
static_cast<uint64_t>((seconds+archiveEpochOffset)*archiveTicksPerSecond+archive_entry_mtime_nsec(entry)/100):0;
return {relative,{static_cast<uint64_t>(size),modified,folder,archive_entry_is_encrypted(entry)!=0}};
ArchiveEntry metadata{
static_cast<uint64_t>(size),
archiveTime(archive_entry_mtime_is_set(entry),archive_entry_mtime(entry),archive_entry_mtime_nsec(entry)),
folder,archive_entry_is_encrypted(entry)!=0};
metadata.created=archiveTime(archive_entry_birthtime_is_set(entry),archive_entry_birthtime(entry),
archive_entry_birthtime_nsec(entry));
metadata.accessed=archiveTime(archive_entry_atime_is_set(entry),archive_entry_atime(entry),archive_entry_atime_nsec(entry));
if(const auto *owner=archive_entry_uname_w(entry)) metadata.owner=owner;
return {relative,std::move(metadata)};
}
void registerEntry(ArchiveEntries &entries,const fs::path &path,const ArchiveEntry &entry)
@@ -240,8 +251,7 @@ uint64_t archiveFileSize(const BY_HANDLE_FILE_INFORMATION &info)
bool sameArchiveFile(const BY_HANDLE_FILE_INFORMATION &left,const BY_HANDLE_FILE_INFORMATION &right)
{
return left.dwVolumeSerialNumber==right.dwVolumeSerialNumber && left.nFileIndexHigh==right.nFileIndexHigh &&
left.nFileIndexLow==right.nFileIndexLow && archiveFileSize(left)==archiveFileSize(right) &&
return sameFileIdentity(left,right) && archiveFileSize(left)==archiveFileSize(right) &&
CompareFileTime(&left.ftLastWriteTime,&right.ftLastWriteTime)==0;
}
+3
View File
@@ -5,6 +5,7 @@
#include <functional>
#include <map>
#include <stop_token>
#include <string>
#include <vector>
namespace ks::files
@@ -18,6 +19,8 @@ struct ArchiveEntry
{
uint64_t size{}, modified{};
bool directory{}, encrypted{}, implicit{};
uint64_t created{}, accessed{};
std::wstring owner{};
};
using ArchiveEntries=std::map<std::filesystem::path,ArchiveEntry,ArchiveNameOrder>;
+4 -2
View File
@@ -92,7 +92,7 @@ void showFilesPanelContext(Panel &panel,LRESULT row,POINT screen)
const auto owner=GetParent(panel.list);
ContextPopup popup;
if(!popup.handle) return;
constexpr UINT openItem=1,findItems=2,newProfile=3;
constexpr UINT openItem=1,findItems=2,newProfile=3,properties=4;
const auto add=[&](UINT id,const wchar_t *label){AppendMenuW(popup.handle,MF_STRING,id,label);};
if(transferProfileList(panel))
{
@@ -119,6 +119,7 @@ void showFilesPanelContext(Panel &panel,LRESULT row,POINT screen)
if(!panel.archive && (panel.ftp || canCopy) && remoteSearchActionAvailable(114))
add(114,panel.ftp?L"Rename":L"Move");
if(!panel.archive && remoteSearchActionAvailable(117)) add(117,L"Delete");
if(panelItemPropertiesAvailable(panel)) add(properties,L"Properties");
}
else if(!panel.findOrigin && !panel.archive && !panel.directory.empty()) add(115,L"Make folder");
if(!panel.archive && !panel.directory.empty()) add(findItems,L"Find files");
@@ -129,6 +130,7 @@ void showFilesPanelContext(Panel &panel,LRESULT row,POINT screen)
if(command==openItem) enter(panel);
else if(command==findItems) findPanelFiles(owner,panel);
else if(command==newProfile) editTransferProfile(panel,true);
else if(command==properties) showPanelItemProperties(owner,panel);
else if(command) SendMessageW(owner,WM_COMMAND,MAKEWPARAM(command,BN_CLICKED),0);
}
@@ -175,7 +177,7 @@ void showPanelContextMenu(HWND list,LPARAM position)
const auto directory=panel.directory;
const auto item=row==LB_ERR?fs::path{}:panel.rows[row];
const bool shell=!panel.peer && !panel.ftp && !panel.archive && !directory.empty() &&
!directory.root_name().native().starts_with(L"\\\\");
!windowsNetworkPath(directory);
const auto result=shell?showShellPanelMenu(owner,directory,item,screen):ShellPanelMenuResult::unavailable;
if(result==ShellPanelMenuResult::unavailable) showFilesPanelContext(panel,row,screen);
else if(result==ShellPanelMenuResult::rename)
+3
View File
@@ -57,7 +57,10 @@ std::unique_ptr<Panel::ScanResult> scanFileMatches(const Panel::ScanRequest &req
matchesFileMask(name,request.find->mask) &&
result->metadata.emplace(path,FolderEntryMetadata{
entry.attributes,entry.size,entry.modified}).second)
{
result->files.push_back(path);
if(entry.transfer) result->columnMetadata[path].transfer=entry.transfer;
}
return true;
})) break;
}
+10 -10
View File
@@ -330,17 +330,17 @@ DWORD listFtpDirectory(FtpSession &session,const fs::path &directory,const FileV
const auto name=session.decodeName(entry.cFileName);
if(name.empty() || name==L"." || name==L".." || name.find_first_of(L"/\\:\r\n")!=name.npos)
continue;
ULARGE_INTEGER modified{}, size{};
FILETIME utc{};
if(LocalFileTimeToFileTime(&entry.ftLastWriteTime,&utc))
const auto ftpTime=[](const FILETIME &local) -> uint64_t
{
modified.HighPart=utc.dwHighDateTime;
modified.LowPart=utc.dwLowDateTime;
}
size.HighPart=entry.nFileSizeHigh;
size.LowPart=entry.nFileSizeLow;
if(!visit(directory/name,{entry.dwFileAttributes,size.QuadPart,modified.QuadPart}))
return ERROR_CANCELLED;
FILETIME utc{};
if((!local.dwLowDateTime && !local.dwHighDateTime) || !LocalFileTimeToFileTime(&local,&utc)) return 0;
return (uint64_t(utc.dwHighDateTime)<<32)|utc.dwLowDateTime;
};
FileInfo info{entry.dwFileAttributes,(uint64_t(entry.nFileSizeHigh)<<32)|entry.nFileSizeLow,
ftpTime(entry.ftLastWriteTime)};
const TransferItemMetadata details{ftpTime(entry.ftCreationTime),ftpTime(entry.ftLastAccessTime)};
if(details.created || details.accessed) info.transfer=details;
if(!visit(directory/name,info)) return ERROR_CANCELLED;
} while(!stop.stop_requested() && InternetFindNextFileA(search.value,&entry));
return stop.stop_requested()?ERROR_CANCELLED:GetLastError();
}
+43 -1
View File
@@ -39,6 +39,7 @@
#include "files_compare_text.h"
#include "files_image_decode.h"
#include "files_win32_directory.h"
#include "files_win32_replace.h"
#include "files_command_completion.h"
#include "files_text_window.h"
#include "files_menu_navigation.h"
@@ -67,11 +68,18 @@ using ks::lan::filePath;
using ks::lan::checkFileReply;
using ks::files::validFileName;
struct TransferItemMetadata
{
uint64_t created{}, accessed{};
std::optional<uint32_t> owner, permissions;
};
struct FileInfo
{
DWORD attributes;
uint64_t size, modified;
std::optional<uint64_t> allocated{};
std::optional<TransferItemMetadata> transfer{};
};
FileInfo fileInfo(const Json &row)
{
@@ -383,6 +391,20 @@ fs::path folderPathWithoutSeparator(fs::path path)
return path;
}
bool windowsNetworkPath(const fs::path &path)
{
std::wstring_view name=path.native();
if(name.starts_with(L"\\\\?\\"))
{
name.remove_prefix(4);
if(name.size()>=4 && CompareStringOrdinal(name.data(),4,L"UNC\\",4,TRUE)==CSTR_EQUAL) return true;
return name.size()>=3 && name[1]==L':' && name[2]==L'\\' &&
GetDriveTypeW(std::wstring(name.substr(0,3)).c_str())==DRIVE_REMOTE;
}
return name.starts_with(L"\\\\") || name.starts_with(L"//") ||
GetDriveTypeW(path.root_path().c_str())==DRIVE_REMOTE;
}
fs::path panelParentPath(const fs::path &directory,bool local)
{
if(!directory.has_relative_path()) return {};
@@ -504,6 +526,7 @@ struct ColumnMetadata
std::wstring owner;
std::optional<uint64_t> allocated;
std::optional<DWORD> links;
std::optional<TransferItemMetadata> transfer;
};
using ColumnMetadataMap=std::map<fs::path,ColumnMetadata>;
@@ -2881,6 +2904,7 @@ std::unique_ptr<Panel::ScanResult> scanDirectory(const Panel::ScanRequest &reque
error=ftp.list(directory.empty()?ftpInitialDirectory:directory,[&](const fs::path &path,const FileInfo &info)
{
if(!metadata.emplace(path,FolderEntryMetadata{info.attributes,info.size,info.modified}).second) return true;
if(info.transfer) columnMetadata[path].transfer=info.transfer;
(info.attributes&FILE_ATTRIBUTE_DIRECTORY?folders:files).push_back(path);
entriesRead.store(folders.size()+files.size(),std::memory_order_relaxed);
return !stop.stop_requested();
@@ -3806,6 +3830,9 @@ bool driveSourceRow(LRESULT row)
row==sftpDriveRow() || row==smbDriveRow() || row==recentDriveRow());
}
bool panelItemPropertiesAvailable(const Panel &panel);
void showPanelItemProperties(HWND owner,Panel &panel);
bool selectablePickerRow(LRESULT row)
{
if(row<0) return false;
@@ -3853,6 +3880,7 @@ void selectDrive()
else if(menuIndex==2 && row==13) openSelectedText(panels[active],false,false,true);
else if(menuIndex==2 && row==14) ks::files::showAllViewerBookmarks(owner,textWindowDialogs());
else if(menuIndex==1 && row==4) createArchive(owner,panels[active]);
else if(menuIndex==1 && row==5) showPanelItemProperties(owner,panels[active]);
else
{
const int command=menuIndex==1?113+static_cast<int>(row):110+static_cast<int>(row);
@@ -7609,6 +7637,7 @@ void openOrCreateText(HWND owner,const Panel &panel)
void editTransferProfile(Panel &panel,bool create);
#include "files_drag_drop.inl"
#include "files_properties.inl"
#include "files_context_menu.inl"
LRESULT CALLBACK panelKeys(HWND window, UINT message, WPARAM wp, LPARAM lp, UINT_PTR, DWORD_PTR)
@@ -7901,7 +7930,8 @@ void openMenu(HWND window, int index)
if(detailedPanel(panel)) rows.push_back(L" Columns…");
}
}
else if(index==1) rows={L"Copy\tF5",L"Move\tF6",L"Make folder\tF7",L"Exit\tF10",L"Pack files…\tAlt+F5"};
else if(index==1) rows={L"Copy\tF5",L"Move\tF6",L"Make folder\tF7",L"Exit\tF10",L"Pack files…\tAlt+F5",
L"Properties…\tCtrl+A"};
else if(index==2)
{
rows={L"Refresh panel\tCtrl+R",L"View\tF3",L"Edit\tF4",L"Folder shortcuts",
@@ -7923,6 +7953,12 @@ void openMenu(HWND window, int index)
commandActions.push_back(1);
}
commandActions.push_back(3);
if(panelItemPropertiesAvailable(panel)) commandActions.push_back(5);
}
else if(index==1)
{
commandActions={0,1,2,3,4};
if(panelItemPropertiesAvailable(panel)) commandActions.push_back(5);
}
else if(index==2)
{
@@ -9230,6 +9266,12 @@ int WINAPI wWinMain(HINSTANCE instance, HINSTANCE, PWSTR, int show)
if(!(message.lParam & (1LL<<30))) copyFullPanelPath(window,panels[active]);
continue;
}
if(ctrl && !shift && message.wParam=='A' && !terminalVisible && commandLineAvailable(window) &&
(!GetWindowTextLengthW(terminalInput) || panelFocused) && panelItemPropertiesAvailable(panels[active]))
{
if(!(message.lParam&(1LL<<30))) showPanelItemProperties(window,panels[active]);
continue;
}
if(shift && !ctrl && message.wParam==VK_F4 && !terminalVisible)
{
if(!(message.lParam & (1LL<<30)) && commandLineAvailable(window))
+244
View File
@@ -0,0 +1,244 @@
constexpr int propertiesName=580, propertiesFirstDetail=581, propertiesOtherFlags=586;
constexpr int propertiesFirstFlag=587, propertiesDivider=592;
constexpr DWORD propertyOpenFlags=FILE_FLAG_BACKUP_SEMANTICS|FILE_FLAG_OPEN_REPARSE_POINT;
constexpr DWORD editablePropertyFlags[]{
FILE_ATTRIBUTE_READONLY,FILE_ATTRIBUTE_HIDDEN,FILE_ATTRIBUTE_SYSTEM,FILE_ATTRIBUTE_ARCHIVE,
FILE_ATTRIBUTE_NOT_CONTENT_INDEXED};
struct FilePropertyFlag
{
DWORD flag;
const wchar_t *name;
};
std::wstring propertyFlagNames(DWORD flags)
{
constexpr FilePropertyFlag names[]{
{FILE_ATTRIBUTE_READONLY,L"Read-only"},{FILE_ATTRIBUTE_HIDDEN,L"Hidden"},
{FILE_ATTRIBUTE_SYSTEM,L"System"},{FILE_ATTRIBUTE_DIRECTORY,L"Directory"},
{FILE_ATTRIBUTE_ARCHIVE,L"Archive"},{FILE_ATTRIBUTE_NORMAL,L"Normal"},
{FILE_ATTRIBUTE_TEMPORARY,L"Temporary"},{FILE_ATTRIBUTE_SPARSE_FILE,L"Sparse"},
{FILE_ATTRIBUTE_REPARSE_POINT,L"Reparse point"},{FILE_ATTRIBUTE_COMPRESSED,L"Compressed"},
{FILE_ATTRIBUTE_OFFLINE,L"Offline"},{FILE_ATTRIBUTE_NOT_CONTENT_INDEXED,L"Not indexed"},
{FILE_ATTRIBUTE_ENCRYPTED,L"Encrypted"},{FILE_ATTRIBUTE_INTEGRITY_STREAM,L"Integrity stream"},
{FILE_ATTRIBUTE_NO_SCRUB_DATA,L"No scrub"},{FILE_ATTRIBUTE_PINNED,L"Pinned"},
{FILE_ATTRIBUTE_UNPINNED,L"Unpinned"}};
std::wstring text;
const auto append=[&](std::wstring_view name)
{
if(!text.empty()) text+=L", ";
text+=name;
};
for(const auto &[flag,name]:names)
if(flags&flag)
{
append(name);
flags&=~flag;
}
if(flags)
{
wchar_t number[16]{};
swprintf_s(number,L"0x%08lX",static_cast<unsigned long>(flags));
append(number);
}
return text.empty()?L"—":text;
}
std::wstring propertyDate(uint64_t ticks)
{
const auto time=localFileTime(ticks);
if(!time) return L"—";
wchar_t label[32]{};
swprintf_s(label,L"%04u-%02u-%02u %02u:%02u:%02u",unsigned(time->wYear),unsigned(time->wMonth),
unsigned(time->wDay),unsigned(time->wHour),unsigned(time->wMinute),unsigned(time->wSecond));
return label;
}
struct ItemProperties
{
std::wstring name, owner;
uint64_t created{}, modified{}, accessed{}, changed{};
DWORD flags{}, requested{};
std::vector<std::wstring> details(bool includeMissing) const
{
std::vector<std::wstring> rows;
if(includeMissing || !owner.empty()) rows.push_back(L"Owner "+(owner.empty()?L"—":owner));
const auto date=[&](const wchar_t *label,uint64_t value)
{
if(includeMissing || value) rows.push_back(label+propertyDate(value));
};
date(L"Created ",created);
date(L"Modified ",modified);
date(L"Accessed ",accessed);
date(L"Changed ",changed);
return rows;
}
};
INT_PTR CALLBACK itemPropertiesDialog(HWND dialog,UINT message,WPARAM wp,LPARAM lp)
{
if(message==WM_INITDIALOG)
{
auto &properties=*reinterpret_cast<ItemProperties*>(lp);
SetWindowLongPtrW(dialog,DWLP_USER,lp);
prepareTextDialog(dialog);
layoutDialogContent(dialog,propertiesName);
SetDlgItemTextW(dialog,propertiesName,properties.name.c_str());
const auto details=properties.details(true);
for(size_t index=0;index<details.size();++index)
SetDlgItemTextW(dialog,propertiesFirstDetail+static_cast<int>(index),details[index].c_str());
auto other=properties.flags&~FILE_ATTRIBUTE_NORMAL;
for(size_t index=0;index<std::size(editablePropertyFlags);++index)
{
const auto flag=editablePropertyFlags[index];
const auto id=propertiesFirstFlag+static_cast<int>(index);
installFarCheckbox(GetDlgItem(dialog,id),FarCheckboxSurface::gray);
CheckDlgButton(dialog,id,(properties.flags&flag)?BST_CHECKED:BST_UNCHECKED);
other&=~flag;
}
SetDlgItemTextW(dialog,propertiesOtherFlags,(L"Other flags "+propertyFlagNames(other)).c_str());
layoutDialogButtons(dialog,propertiesDivider,{IDOK,IDCANCEL});
return TRUE;
}
if(message==WM_COMMAND && LOWORD(wp)==IDOK)
{
auto &properties=*reinterpret_cast<ItemProperties*>(GetWindowLongPtrW(dialog,DWLP_USER));
for(size_t index=0;index<std::size(editablePropertyFlags);++index)
if(IsDlgButtonChecked(dialog,propertiesFirstFlag+static_cast<int>(index))==BST_CHECKED)
properties.requested|=editablePropertyFlags[index];
FilesModalDialog::finish(dialog,IDOK);
return TRUE;
}
if(message==WM_CLOSE || (message==WM_COMMAND && LOWORD(wp)==IDCANCEL))
{
FilesModalDialog::finish(dialog,IDCANCEL);
return TRUE;
}
return paintCopyDialog(dialog,message,wp,lp,L" Properties ",false,{propertiesDivider});
}
void showReadOnlyProperties(HWND owner,const ItemProperties &properties,const std::wstring &attributes)
{
auto text=properties.name+L"\r\n\r\n";
for(const auto &line:properties.details(false)) text+=line+L"\r\n";
text+=attributes;
showFilesNotice(owner,text.c_str(),L"Properties",{.tone=FilesNoticeTone::neutral});
}
bool panelItemPropertiesAvailable(const Panel &panel)
{
const auto row=currentPanelRow(panel);
return row!=LB_ERR && panel.sizes[row]!=L"Up" && !transferProfileList(panel);
}
void showSourceItemProperties(HWND owner,const Panel &panel,const fs::path &path,ItemProperties properties)
{
const auto found=panel.metadata.find(path);
if(found==panel.metadata.end()) return;
const auto &entry=found->second;
properties.modified=entry.modified;
if(panel.peer)
{
showReadOnlyProperties(owner,properties,L"Attributes "+propertyFlagNames(entry.attributes));
return;
}
auto attributes=(entry.attributes&FILE_ATTRIBUTE_DIRECTORY)?std::wstring(L"Folder"):
(entry.attributes&FILE_ATTRIBUTE_REPARSE_POINT)?std::wstring(L"Special file"):std::wstring(L"File");
if(panel.archive && panel.archive->entries)
{
const auto &members=*panel.archive->entries;
if(const auto member=members.find(path.lexically_relative(panel.archive->file));member!=members.end())
{
properties.owner=member->second.owner;
properties.created=member->second.created;
properties.accessed=member->second.accessed;
if(member->second.encrypted) attributes+=L", Encrypted";
}
}
else if(const auto extra=panel.columnMetadata.find(path);
extra!=panel.columnMetadata.end() && extra->second.transfer)
{
const auto &details=*extra->second.transfer;
properties.created=details.created;
properties.accessed=details.accessed;
if(details.owner) properties.owner=L"UID "+std::to_wstring(*details.owner);
if(details.permissions)
{
wchar_t mode[12]{};
swprintf_s(mode,L"%04o",static_cast<unsigned>(*details.permissions));
attributes+=std::wstring(L"\r\nPermissions ")+mode;
}
}
if(panel.ftp && panel.ftp->protocol==TransferProtocol::ftp)
{
const auto flags=entry.attributes&~(FILE_ATTRIBUTE_NORMAL|FILE_ATTRIBUTE_DIRECTORY);
if(flags) attributes+=L"\r\nAttributes "+propertyFlagNames(flags);
}
showReadOnlyProperties(owner,properties,L"Type "+attributes);
}
DWORD changeItemProperties(const fs::path &path,HANDLE original,const ItemProperties &properties)
{
DWORD editable{};
for(const auto flag:editablePropertyFlags) editable|=flag;
const DWORD changed=(properties.flags^properties.requested)&editable;
if(!changed) return ERROR_SUCCESS;
const Handle file{CreateFileW(path.c_str(),FILE_READ_ATTRIBUTES|FILE_WRITE_ATTRIBUTES,columnFileShare,nullptr,
OPEN_EXISTING,propertyOpenFlags,nullptr)};
if(file.value==INVALID_HANDLE_VALUE) return GetLastError();
BY_HANDLE_FILE_INFORMATION before{},current{};
if(!GetFileInformationByHandle(original,&before) || !GetFileInformationByHandle(file.value,&current))
return GetLastError();
if(!ks::files::sameFileIdentity(before,current)) return ERROR_FILE_INVALID;
FILE_BASIC_INFO latest{};
if(!GetFileInformationByHandleEx(file.value,FileBasicInfo,&latest,sizeof(latest))) return GetLastError();
if(!((latest.FileAttributes^properties.requested)&changed)) return ERROR_SUCCESS;
FILE_BASIC_INFO update{};
update.FileAttributes=(latest.FileAttributes&~(changed|FILE_ATTRIBUTE_NORMAL))|(properties.requested&changed);
if(!update.FileAttributes) update.FileAttributes=FILE_ATTRIBUTE_NORMAL;
if(!SetFileInformationByHandle(file.value,FileBasicInfo,&update,sizeof(update))) return GetLastError();
return ERROR_SUCCESS;
}
void showPanelItemProperties(HWND owner,Panel &panel)
{
if(!panelItemPropertiesAvailable(panel)) return;
const auto path=panel.rows[currentPanelRow(panel)];
ItemProperties properties{path.filename().native()};
if(panel.ftp || panel.peer || panel.archive)
{
showSourceItemProperties(owner,panel,path,std::move(properties));
return;
}
const Handle file{CreateFileW(path.c_str(),FILE_READ_ATTRIBUTES,columnFileShare,nullptr,OPEN_EXISTING,
propertyOpenFlags,nullptr)};
FILE_BASIC_INFO info{};
if(file.value==INVALID_HANDLE_VALUE || !GetFileInformationByHandleEx(file.value,FileBasicInfo,&info,sizeof(info)))
{
const auto error=GetLastError();
refreshPanel(panel);
showFileOperationError(owner,L"Could not read properties",fileError({static_cast<int>(error),std::system_category()}));
return;
}
std::map<std::wstring,std::wstring> owners;
properties.owner=localOwnerName(path,owners);
properties.created=info.CreationTime.QuadPart;
properties.modified=info.LastWriteTime.QuadPart;
properties.accessed=info.LastAccessTime.QuadPart;
properties.changed=info.ChangeTime.QuadPart;
properties.flags=info.FileAttributes;
if(windowsNetworkPath(path))
{
showReadOnlyProperties(owner,properties,L"Attributes "+propertyFlagNames(properties.flags));
return;
}
if(FilesModalDialog::run(GetModuleHandleW(nullptr),MAKEINTRESOURCEW(125),owner,itemPropertiesDialog,
reinterpret_cast<LPARAM>(&properties))!=IDOK) return;
const auto error=changeItemProperties(path,file.value,properties);
refreshPanel(panel);
if(error!=ERROR_SUCCESS)
showFileOperationError(owner,L"Could not save attributes",error==ERROR_FILE_INVALID?
L"The item was replaced while the properties were open.":
fileError({static_cast<int>(error),std::system_category()}));
}
+12 -3
View File
@@ -354,9 +354,18 @@ public:
else if(!LIBSSH2_SFTP_S_ISREG(attrs.permissions)) attributes=FILE_ATTRIBUTE_REPARSE_POINT;
if(!(attrs.permissions&0222)) attributes|=FILE_ATTRIBUTE_READONLY;
}
const auto modified=(attrs.flags&LIBSSH2_SFTP_ATTR_ACMODTIME)?
(uint64_t(attrs.mtime)+11644473600ULL)*10000000ULL:0;
if(!visit(directory/child,{attributes,attrs.filesize,modified})) return ERROR_CANCELLED;
const auto sftpTime=[](unsigned long seconds){return (uint64_t(seconds)+11644473600ULL)*10000000ULL;};
FileInfo info{attributes,attrs.filesize,0};
TransferItemMetadata details;
if(attrs.flags&LIBSSH2_SFTP_ATTR_ACMODTIME)
{
info.modified=sftpTime(attrs.mtime);
details.accessed=sftpTime(attrs.atime);
}
if(attrs.flags&LIBSSH2_SFTP_ATTR_UIDGID) details.owner=attrs.uid;
if(attrs.flags&LIBSSH2_SFTP_ATTR_PERMISSIONS) details.permissions=attrs.permissions&07777;
if(details.accessed || details.owner || details.permissions) info.transfer=details;
if(!visit(directory/child,info)) return ERROR_CANCELLED;
}
return ERROR_CANCELLED;
}
+1 -2
View File
@@ -87,8 +87,7 @@ bool sameFile(HANDLE a, HANDLE b)
BY_HANDLE_FILE_INFORMATION first{}, second{};
if (!GetFileInformationByHandle(a, &first) || !GetFileInformationByHandle(b, &second))
fail("Check file identity");
return first.dwVolumeSerialNumber == second.dwVolumeSerialNumber &&
first.nFileIndexHigh == second.nFileIndexHigh && first.nFileIndexLow == second.nFileIndexLow;
return sameFileIdentity(first,second);
}
std::filesystem::path temporaryPath(const std::filesystem::path &directory)
+6
View File
@@ -7,6 +7,12 @@
namespace ks::files
{
inline bool sameFileIdentity(const BY_HANDLE_FILE_INFORMATION &left,const BY_HANDLE_FILE_INFORMATION &right)
{
return left.dwVolumeSerialNumber==right.dwVolumeSerialNumber && left.nFileIndexHigh==right.nFileIndexHigh &&
left.nFileIndexLow==right.nFileIndexLow;
}
inline DWORD replaceFileWithBackup(const std::filesystem::path &original,const std::filesystem::path &replacement,
const std::filesystem::path &backup)
{