| View previous topic :: View next topic |
| Author |
Message |
milo1012 Junior Member

Joined: 02 Feb 2012 Posts: 60
|
Posted: Sun Feb 05, 2012 1:51 pm Post subject: |
|
|
| umbra wrote: | So it's no wonder it emulates Notepad as much as possible.  |
Of course it is...but the exact behavior of Windows Notepad in terms of file handling is not documented and can only be observed.
What I mean is that every Program approaches that different...programming file handling in MFC in Visual Studio is completely different than in .Net, JAVA or things like MinGW.
So propably, if you don't follow file handling recommendations from Microsoft or it's just your goal to be able to do it anyway then you end up like this: we have a lot of programs that allow writing locked files and many that don't. |
|
| Back to top |
|
 |
MVV Power Member


Joined: 03 Aug 2008 Posts: 4599 Location: Russian Federation
|
Posted: Sun Feb 05, 2012 11:38 pm Post subject: |
|
|
Well, I've tested it with WordPad, it doesn't allow to save file. Maybe it checks it somehow.
It is strange but I can't save a file using standard Notepad if it was opened by following sample code:
| Code: | HANDLE hfile=CreateFile(L"D:\\testfile.txt", GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
HANDLE hmap=CreateFileMapping(hfile, 0, PAGE_READWRITE, 0, 0, 0);
MessageBox(0, L"1", L"2", 0);
CloseHandle(hmap);
CloseHandle(hfile); |
BTW, it works correctly even with FILE_SHARE_READ|FILE_SHARE_WRITE sharing flags! Notepad is unable to save file until I click a button in a message box. _________________ VirtualPanel plugin: Temporary panel for TC (forum)
TOTALCMD.NET: TCFS2, NTLinks, CopyTree, AskParam, ConPaste, Sudo… |
|
| Back to top |
|
 |
ghisler(Author) Site Admin


Joined: 04 Feb 2003 Posts: 24702 Location: Switzerland
|
Posted: Mon Feb 06, 2012 10:36 am Post subject: |
|
|
I'm opening the file with GENERIC_READ access and sharing flags set to
FILE_SHARE_READ | FILE_SHARE_WRITE. This is done so I can also compare files which are currently open in some other program. If I used only FILE_SHARE_READ, I couldn't open e.g. active database files. _________________ Author of Total Commander
http://www.ghisler.com |
|
| Back to top |
|
 |
MVV Power Member


Joined: 03 Aug 2008 Posts: 4599 Location: Russian Federation
|
|
| Back to top |
|
 |
ghisler(Author) Site Admin


Joined: 04 Feb 2003 Posts: 24702 Location: Switzerland
|
Posted: Thu Feb 09, 2012 9:25 am Post subject: |
|
|
Your sugestion to try with FILE_SHARE_READ first is good. Btw, the problem isn't about editing the file with TC, but with an external editor. _________________ Author of Total Commander
http://www.ghisler.com |
|
| Back to top |
|
 |
MVV Power Member


Joined: 03 Aug 2008 Posts: 4599 Location: Russian Federation
|
|
| Back to top |
|
 |
ghisler(Author) Site Admin


Joined: 04 Feb 2003 Posts: 24702 Location: Switzerland
|
Posted: Fri Feb 10, 2012 5:31 am Post subject: |
|
|
OK, try beta 19. _________________ Author of Total Commander
http://www.ghisler.com |
|
| Back to top |
|
 |
MVV Power Member


Joined: 03 Aug 2008 Posts: 4599 Location: Russian Federation
|
|
| Back to top |
|
 |
umbra Power Member

Joined: 14 Jan 2012 Posts: 675
|
Posted: Fri Feb 10, 2012 6:51 am Post subject: |
|
|
In beta 19, if some file is larger than 1 MiB it's locked.
However the help says:
| Quote: | Files up to 2 MB will be loaded completely into memory, so the originals will remain editable. Larger files will only be mapped to memory, i.e. they remain locked during the comparison.
|
Are those 2 MiB a typo or I'm missing something? _________________ Windows 7 Pro x64, Windows 8 Pro x64 |
|
| Back to top |
|
 |
ghisler(Author) Site Admin


Joined: 04 Feb 2003 Posts: 24702 Location: Switzerland
|
Posted: Fri Feb 10, 2012 7:25 am Post subject: |
|
|
It's badly explained, the 2 MB is the memory it may take when both files are loaded into memory. _________________ Author of Total Commander
http://www.ghisler.com |
|
| Back to top |
|
 |
|