
file panel autorefreshing?
Moderators: Hacker, petermad, Stefan2, white
- SanskritFritz
- Power Member
- Posts: 3693
- Joined: 2003-07-24, 09:25 UTC
- Location: Budapest, Hungary
-
- Junior Member
- Posts: 9
- Joined: 2005-03-12, 18:56 UTC
My $0.02
Hi Christian.ghisler(Author) wrote:I decided against auto-refreshing for two reasons:
1. Performance - constant refreshing e.g. while a file is downloaded can eat quite a lot of performance
2. Sorting: New entries would either (as in explorer) appear at the end of the list, so the sort order would become wrong, or in the middle, making file selection problematic.
I would agree with you on point 1 if you were thinking about a "polling directory" solution, that would be quite inefficient. But there are at least a couple of techniques quite efficient to accomplish this, the best one is using the ReadDirectoryChangesW API.
I know that you wrote TC using Delphi, so I searched for a working example of using this API in Delphi, you can find it here: DirMon.
This API can work in Synchronous or Asynchronous mode, so the implementation is all up to your personal preference.
Regarding point 2 (sorting), you could make it an option, like I found in other File Managers.
Hope to see this in your to-do list, it would be a nice feature.

Keep up with your great work on TC.
/* Alessandro, #117041 */
Glasses ?
2raytc
Hello !
K R
Claude
Clo

- From the Help (and Tutorial) :I don't even see a refresh command in the TC commands list.
cm_RereadSource=540;Reread source
Refreshes the content of the current directory (especially useful in the network).

Claude
Clo
#31505 Traducteur Français de T•C French translator Aide en Français Tutoriels Français English Tutorials
Re: Glasses ?
Thank you.Clo wrote:2raytc
Hello !
- From the Help (and Tutorial) :I don't even see a refresh command in the TC commands list.cm_RereadSource=540;Reread source
Refreshes the content of the current directory (especially useful in the network).K R
Claude
Clo
I searched for Refresh.

- ghisler(Author)
- Site Admin
- Posts: 50830
- Joined: 2003-02-04, 09:46 UTC
- Location: Switzerland
- Contact:
I'm aware of this API, but for example while downloading a file it fires almost all the time when writing to the file. If you do this in the background transfer manager, the file list would update all the time, making work quite a pain...I would agree with you on point 1 if you were thinking about a "polling directory" solution, that would be quite inefficient. But there are at least a couple of techniques quite efficient to accomplish this, the best one is using the ReadDirectoryChangesW API.
Author of Total Commander
https://www.ghisler.com
https://www.ghisler.com
- SanskritFritz
- Power Member
- Posts: 3693
- Joined: 2003-07-24, 09:25 UTC
- Location: Budapest, Hungary
This is a problem, that can be solved with a simple switch. Turn on autorefresh when needed, but keep it turned off mostly. You could implement it in such a way, that when I navigate away from the folder I turned autorefresh on, it would be automatically switched off. How is that for security?ghisler(Author) wrote:I'm aware of this API, but for example while downloading a file it fires almost all the time when writing to the file. If you do this in the background transfer manager, the file list would update all the time, making work quite a pain...
I switched to Linux, bye and thanks for all the fish!
-
- Junior Member
- Posts: 9
- Joined: 2005-03-12, 18:56 UTC
We're almost there...
Let's analyse the API:ghisler(Author) wrote:I'm aware of this API, but for example while downloading a file it fires almost all the time when writing to the file. If you do this in the background transfer manager, the file list would update all the time, making work quite a pain...
Code: Select all
BOOL ReadDirectoryChangesW(
HANDLE hDirectory,
LPVOID lpBuffer,
DWORD nBufferLength,
BOOL bWatchSubtree,
DWORD dwNotifyFilter,
LPDWORD lpBytesReturned,
LPOVERLAPPED lpOverlapped,
LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine
);
You said the event would get fired too many times while a process is writing to the file (a download), but that would be the case only if you used FILE_NOTIFY_CHANGE_LAST_WRITE or FILE_NOTIFY_CHANGE_SIZE as filter values, which is not correct for our scope.dwNotifyFilter
[in] The filter criteria that the function checks to determine if the wait operation has completed. This parameter can be one or more of the following values:
- FILE_NOTIFY_CHANGE_FILE_NAME
Any file name change in the watched directory or subtree causes a change notification wait operation to return. Changes include renaming, creating, or deleting a file.
FILE_NOTIFY_CHANGE_DIR_NAME
Any directory-name change in the watched directory or subtree causes a change notification wait operation to return. Changes include creating or deleting a directory.
FILE_NOTIFY_CHANGE_ATTRIBUTES
Any attribute change in the watched directory or subtree causes a change notification wait operation to return.
FILE_NOTIFY_CHANGE_SIZE
Any file-size change in the watched directory or subtree causes a change notification wait operation to return. The operating system detects a change in file size only when the file is written to the disk. For operating systems that use extensive caching, detection occurs only when the cache is sufficiently flushed.
FILE_NOTIFY_CHANGE_LAST_WRITE
Any change to the last write-time of files in the watched directory or subtree causes a change notification wait operation to return. The operating system detects a change to the last write-time only when the file is written to the disk. For operating systems that use extensive caching, detection occurs only when the cache is sufficiently flushed.
FILE_NOTIFY_CHANGE_LAST_ACCESS
Any change to the last access time of files in the watched directory or subtree causes a change notification wait operation to return.
FILE_NOTIFY_CHANGE_CREATION
Any change to the creation time of files in the watched directory or subtree causes a change notification wait operation to return.
FILE_NOTIFY_CHANGE_SECURITY
Any security-descriptor change in the watched directory or subtree causes a change notification wait operation to return.
The only thing that interests us is the creation|deletion|rename of a file|directory, only in these cases we expect the event to be fired; this can be accomplished by using FILE_NOTIFY_CHANGE_FILE_NAME|FILE_NOTIFY_CHANGE_DIR_NAME (bitwise OR) as values of the dwNotifyFilter.
So, to sum it all up, if a users sets the AutoRefresh option to true, TC would call the API to monitor the directories that are currently viewed in the two panels and if the user also set AutoRefreshSort to true it would also automatically sort everything.
BTW, this is already done when copying a file within TC, the directory gets refreshed and sorted automatically. I personally don't like the automatic sort, I'd love to see it governed by an AutoRefreshSort parameter, that would be really perfect IMHO.
Let's see if I've convinced you on this topic Christian...

/* Alessandro, #117041 */
- ghisler(Author)
- Site Admin
- Posts: 50830
- Joined: 2003-02-04, 09:46 UTC
- Location: Switzerland
- Contact:
Hmm, if I don't react to FILE_NOTIFY_CHANGE_LAST_WRITE or FILE_NOTIFY_CHANGE_SIZE, I wouldn't notice all file changes! So on a new download, a 0 byte file would appear in the list, but remain 0 byte then! Is this such a good idea?
Author of Total Commander
https://www.ghisler.com
https://www.ghisler.com
- SanskritFritz
- Power Member
- Posts: 3693
- Joined: 2003-07-24, 09:25 UTC
- Location: Budapest, Hungary
Please, this is not so complicated. If I turn autorefresh on, i do it precisely with that goal in mind: i want to see the files changing. The moment i have enough of that, i will deliberately turn autorefresh off. A very simple approach imho. Please consider my idea in my previous post here.
I switched to Linux, bye and thanks for all the fish!
Christian,
Would it perhaps be possible to react to filesize change for instance only every 20 seconds or so? Or, as always, the best approach is probably "configurable".
Roman
Would it perhaps be possible to react to filesize change for instance only every 20 seconds or so? Or, as always, the best approach is probably "configurable".

Roman
Mal angenommen, du drückst Strg+F, wählst die FTP-Verbindung (mit gespeichertem Passwort), klickst aber nicht auf Verbinden, sondern fällst tot um.
-
- Junior Member
- Posts: 9
- Joined: 2005-03-12, 18:56 UTC
Well, I tried the API during a download and the event LAST_WRITE doesn't get fired too many times (2-3 times in a second)...it's decently designed, doing the monitoring in a dedicated thread won't be an issue.ghisler(Author) wrote:Hmm, if I don't react to FILE_NOTIFY_CHANGE_LAST_WRITE or FILE_NOTIFY_CHANGE_SIZE, I wouldn't notice all file changes! So on a new download, a 0 byte file would appear in the list, but remain 0 byte then! Is this such a good idea?
If you want to optimise you could do the monitoring in a separate thread and refresh the panels only every X seconds (where X is a user setting) (or every X events) like I think explorer does, I noticed that when you copy a file in a dir the explorer window doesn't react immediately other times it seems immediate, I think it depends if you do it when the internal timer expires.
Anyway I think you can find the right balance, have you already tried handling all the events? Have you noticed performance issues?
@SanskritFritz:
I personally wouldn't like it that way, but that's my personal opinion, I think we could find the right solution and with a couple of user settings everyone could configure it to his personal habits.

/* Alessandro, #117041 */
- SanskritFritz
- Power Member
- Posts: 3693
- Joined: 2003-07-24, 09:25 UTC
- Location: Budapest, Hungary
I totally agreeAlessandro Del Prete wrote:@SanskritFritz:
I personally wouldn't like it that way, but that's my personal opinion, I think we could find the right solution and with a couple of user settings everyone could configure it to his personal habits.

I switched to Linux, bye and thanks for all the fish!
- ghisler(Author)
- Site Admin
- Posts: 50830
- Joined: 2003-02-04, 09:46 UTC
- Location: Switzerland
- Contact:
I will make some experiments with the function, maybe I can find a solution which is acceptable...
Author of Total Commander
https://www.ghisler.com
https://www.ghisler.com